summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2020-06-16 19:58:40 +0200
committerlassulus <lassulus@lassul.us>2020-06-16 19:58:40 +0200
commitbde301139df5474a72f79122f81feab1d6387a07 (patch)
tree7ac88eb226420a73abb35dfdecd3095c4b03421b /krebs/5pkgs/simple
parent47ea2f1d631516451b4eb920cc799cfd8f006ad6 (diff)
fzfmenu: move to krebs
Diffstat (limited to 'krebs/5pkgs/simple')
-rw-r--r--krebs/5pkgs/simple/fzfmenu/default.nix55
1 files changed, 55 insertions, 0 deletions
diff --git a/krebs/5pkgs/simple/fzfmenu/default.nix b/krebs/5pkgs/simple/fzfmenu/default.nix
new file mode 100644
index 000000000..64e95d233
--- /dev/null
+++ b/krebs/5pkgs/simple/fzfmenu/default.nix
@@ -0,0 +1,55 @@
+{ pkgs, ... }:
+
+pkgs.writeDashBin "fzfmenu" ''
+ set -efu
+ PROMPT=">"
+ for i in "$@"
+ do
+ case $i in
+ -p)
+ PROMPT="$2"
+ shift
+ shift
+ break
+ ;;
+ -l)
+ # no reason to filter number of lines
+ LINES="$2"
+ shift
+ shift
+ break
+ ;;
+ -i)
+ # we do this anyway
+ shift
+ break
+ ;;
+ *)
+ 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 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
+ ${pkgs.coreutils}/bin/tail -1 "$OUTPUT"
+ ${pkgs.coreutils}/bin/rm "$OUTPUT"
+''