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