1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/packages/scripts/fzfmenu.sh

44 lines
970 B
Bash
Raw Normal View History

2020-04-10 15:06:15 +02:00
#!/usr/bin/env bash
# fzfmenu - fzf as dmenu replacement
# https://github.com/junegunn/fzf/wiki/Examples#fzf-as-dmenu-replacement
2020-04-10 16:18:20 +02:00
set -efu
2020-04-10 14:53:16 +02:00
2020-04-10 15:06:15 +02:00
input=$(mktemp -u --suffix .fzfmenu.input)
output=$(mktemp -u --suffix .fzfmenu.output)
mkfifo "$input"
mkfifo "$output"
chmod 600 "$input" "$output"
2020-04-10 14:53:16 +02:00
for i in "$@"; do
case $i in
-p)
PROMPT="$2"
shift
shift
break ;;
-l)
# no reason to filter number of lines
shift
shift
break ;;
-i)
# we do this anyway
shift
break ;;
*)
echo "Unknown option $1" >&2
shift ;;
esac
done
2020-04-10 15:06:15 +02:00
# it's better to use st here (starts a lot faster than pretty much everything else)
2020-04-15 00:10:30 +02:00
st -c fzfmenu -n fzfmenu -g 85x10 \
-e dash \
-c "cat $input | fzf --reverse --prompt='${PROMPT+> }' --print-query $* | tee $output" & disown
2020-04-10 15:06:15 +02:00
# handle ctrl+c outside child terminal window
trap 'kill $! 2>/dev/null; rm -f $input $output' EXIT
cat > "$input"
cat "$output"