summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2020-06-16 21:13:00 +0200
committertv <tv@krebsco.de>2020-06-16 21:13:00 +0200
commit59aa9811f3d4b9e4762ec20c5424b42b170bd782 (patch)
tree77302973d806d7b9b98311553c531eb52142e70d /krebs/5pkgs/simple
parentac9d61188407fb6d133a0f0a8912a04f4d860677 (diff)
fzfmenu: DRY and don't create temporary file
Diffstat (limited to 'krebs/5pkgs/simple')
-rw-r--r--krebs/5pkgs/simple/fzfmenu/default.nix80
1 files changed, 39 insertions, 41 deletions
diff --git a/krebs/5pkgs/simple/fzfmenu/default.nix b/krebs/5pkgs/simple/fzfmenu/default.nix
index 1ee55a5ab..6d5e37988 100644
--- a/krebs/5pkgs/simple/fzfmenu/default.nix
+++ b/krebs/5pkgs/simple/fzfmenu/default.nix
@@ -29,55 +29,53 @@ in
pkgs.writeDashBin "fzfmenu" ''
set -efu
+
+ # Spawn terminal if called without one, like e.g. from a window manager.
+ if [ -z ''${TERM+x} ]; then
+ exec 3<&0
+ exec 4>&1
+ export FZFMENU_INPUT_FD=3
+ export FZFMENU_OUTPUT_FD=4
+ exec ${pkgs.rxvt_unicode}/bin/urxvt \
+ -name ${cfg.appName} \
+ -title ${shell.escape cfg.windowTitle} \
+ -e "$0" "$@"
+ else
+ exec 0<&''${FZFMENU_INPUT_FD-0}
+ exec 1>&''${FZFMENU_OUTPUT_FD-1}
+ fi
+
PROMPT=">"
- for i in "$@"
- do
- case $i in
+ for i in "$@"; do
+ case $i in
-p)
- PROMPT="$2"
- shift
- shift
- break
- ;;
+ PROMPT=$2
+ shift 2
+ break
+ ;;
-l)
- # no reason to filter number of lines
- LINES="$2"
- shift
- shift
- break
- ;;
+ # no reason to filter number of lines
+ LINES=$2
+ shift 2
+ break
+ ;;
-i)
- # we do this anyway
- shift
- break
- ;;
+ # we do this anyway
+ shift
+ break
+ ;;
*)
- echo "Unknown option $1" >&2
- shift
- ;;
- esac
+ echo "Unknown option $1" >&2
+ shift
+ ;;
+ esac
done
- INPUT=$(${pkgs.coreutils}/bin/cat)
- OUTPUT="$(${pkgs.coreutils}/bin/mktemp)"
- if [ -z ''${TERM+x} ]; then #check if we can print fzf in the shell
- ${pkgs.rxvt_unicode}/bin/urxvt \
- -name ${cfg.appName} \
- -title ${shell.escape cfg.windowTitle} \
- -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 \
+
+ ${pkgs.fzf}/bin/fzf \
--history=/dev/null \
--print-query \
--prompt="$PROMPT" \
--reverse \
- > "$OUTPUT"
- fi
- ${pkgs.coreutils}/bin/tail -1 "$OUTPUT"
- ${pkgs.coreutils}/bin/rm "$OUTPUT"
+ |
+ ${pkgs.coreutils}/bin/tail -1
''