forked from
lass.pds.lassul.us/superconfig
This repository has no description
967 B
38 lines
1#!/usr/bin/env bash
2set -efu
3# Create temporary files for input and output
4TEMP_DIR=$(mktemp -d)
5INPUT_FILE="$TEMP_DIR/input"
6OUTPUT_FILE="$TEMP_DIR/output"
7
8# Save stdin to file
9cat > "$INPUT_FILE"
10
11# Try fzf first with terminal UI - explicitly store exit code
12# This avoids issues with losing the exit code in a pipe
13set +e
14fzf "$@" < "$INPUT_FILE" > "$OUTPUT_FILE" 2>/dev/null
15FZF_EXIT=$?
16set -e
17
18# Handle fzf results based on exit code
19if [ $FZF_EXIT -eq 0 ]; then
20 # Success - output result and exit
21 cat "$OUTPUT_FILE"
22 exit 0
23elif [ $FZF_EXIT -eq 130 ]; then
24 # User pressed Escape - honor the cancellation
25 exit 130
26fi
27
28# If we get here, fzf failed with error (not cancellation)
29
30# Fall back to GUI based on available display environment
31if [ -n "${WAYLAND_DISPLAY:-}" ]; then
32 wofi -d "$@" < "$INPUT_FILE"
33elif [ -n "${DISPLAY:-}" ]; then
34 rofi -dmenu "$@" < "$INPUT_FILE"
35else
36 echo "Error: No suitable display environment available" >&2
37 exit 1
38fi