stockholm/krebs/5pkgs/simple/fzfmenu/default.nix

56 lines
1.1 KiB
Nix
Raw Normal View History

2018-11-30 06:48:49 +00:00
{ pkgs, ... }:
pkgs.writeDashBin "fzfmenu" ''
set -efu
PROMPT=">"
for i in "$@"
do
case $i in
-p)
PROMPT="$2"
shift
shift
break
;;
2018-12-02 04:47:20 +00:00
-l)
# no reason to filter number of lines
LINES="$2"
shift
shift
break
;;
-i)
# we do this anyway
shift
break
;;
2018-11-30 06:48:49 +00:00
*)
2018-12-02 04:47:20 +00:00
echo "Unknown option $1" >&2
2018-11-30 06:48:49 +00:00
shift
;;
esac
done
INPUT=$(${pkgs.coreutils}/bin/cat)
OUTPUT="$(${pkgs.coreutils}/bin/mktemp)"
2020-04-14 17:49:00 +00:00
if [ -z ''${TERM+x} ]; then #check if we can print fzf in the shell
${pkgs.rxvt_unicode}/bin/urxvt \
2020-04-14 17:49:00 +00:00
-name fzfmenu -title fzfmenu \
-e ${pkgs.dash}/bin/dash -c \
"echo \"$INPUT\" | ${pkgs.fzf}/bin/fzf \
--history=/dev/null \
--print-query \
--prompt=\"$PROMPT\" \
--reverse \
> \"$OUTPUT\"" 2>/dev/null
else
echo "$INPUT" | ${pkgs.fzf}/bin/fzf \
--history=/dev/null \
--print-query \
--prompt="$PROMPT" \
--reverse \
> "$OUTPUT"
fi
2020-01-11 20:00:57 +00:00
${pkgs.coreutils}/bin/tail -1 "$OUTPUT"
2018-11-30 06:48:49 +00:00
${pkgs.coreutils}/bin/rm "$OUTPUT"
''