2021-10-12 17:36:09 +00:00
|
|
|
{ pkgs, stockholm, ... }@args:
|
|
|
|
with stockholm.lib;
|
2020-06-16 18:27:59 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
# config cannot be declared in the input attribute set because that would
|
|
|
|
# cause callPackage to inject the wrong config. Instead, get it from ...
|
|
|
|
# via args.
|
|
|
|
config = args.config or {};
|
|
|
|
|
|
|
|
cfg = eval.config;
|
|
|
|
|
|
|
|
eval = evalModules {
|
|
|
|
modules = singleton {
|
|
|
|
_file = toString ./profile.nix;
|
|
|
|
imports = singleton config;
|
|
|
|
options = {
|
2020-06-16 19:38:24 +00:00
|
|
|
appName = mkOption {
|
|
|
|
default = "fzfmenu";
|
|
|
|
type = types.label;
|
|
|
|
};
|
2020-06-16 19:16:25 +00:00
|
|
|
defaultPrompt = mkOption {
|
|
|
|
default = ">";
|
|
|
|
type = types.str;
|
|
|
|
};
|
2020-06-16 19:38:24 +00:00
|
|
|
printQuery = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2020-06-16 18:27:59 +00:00
|
|
|
};
|
2020-06-16 19:38:32 +00:00
|
|
|
reverse = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2020-06-16 18:27:59 +00:00
|
|
|
windowTitle = mkOption {
|
|
|
|
default = "fzfmenu";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
2018-11-30 06:48:49 +00:00
|
|
|
|
|
|
|
pkgs.writeDashBin "fzfmenu" ''
|
|
|
|
set -efu
|
2020-06-16 19:13:00 +00:00
|
|
|
|
|
|
|
# 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
|
2022-09-27 10:31:14 +00:00
|
|
|
exec ${pkgs.rxvt-unicode}/bin/urxvt \
|
2020-06-16 19:13:00 +00:00
|
|
|
-name ${cfg.appName} \
|
|
|
|
-title ${shell.escape cfg.windowTitle} \
|
|
|
|
-e "$0" "$@"
|
|
|
|
else
|
|
|
|
exec 0<&''${FZFMENU_INPUT_FD-0}
|
|
|
|
exec 1>&''${FZFMENU_OUTPUT_FD-1}
|
|
|
|
fi
|
|
|
|
|
2020-06-16 19:16:25 +00:00
|
|
|
PROMPT=${shell.escape cfg.defaultPrompt}
|
2020-06-16 19:13:00 +00:00
|
|
|
for i in "$@"; do
|
|
|
|
case $i in
|
2018-11-30 06:48:49 +00:00
|
|
|
-p)
|
2020-06-16 19:13:00 +00:00
|
|
|
PROMPT=$2
|
|
|
|
shift 2
|
|
|
|
break
|
|
|
|
;;
|
2018-12-02 04:47:20 +00:00
|
|
|
-l)
|
2020-06-16 19:13:00 +00:00
|
|
|
# no reason to filter number of lines
|
|
|
|
LINES=$2
|
|
|
|
shift 2
|
|
|
|
break
|
|
|
|
;;
|
2018-12-02 04:47:20 +00:00
|
|
|
-i)
|
2020-06-16 19:13:00 +00:00
|
|
|
# we do this anyway
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
2018-11-30 06:48:49 +00:00
|
|
|
*)
|
2020-06-16 19:13:00 +00:00
|
|
|
echo "Unknown option $1" >&2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
2018-11-30 06:48:49 +00:00
|
|
|
done
|
2020-06-16 19:13:00 +00:00
|
|
|
|
2020-06-16 19:42:35 +00:00
|
|
|
if test -n "''${FZFMENU_FZF_DEFAULT_OPTS-}"; then
|
|
|
|
FZF_DEFAULT_OPTS=''${FZFMENU_FZF_DEFAULT_OPTS-}
|
2020-06-16 19:19:23 +00:00
|
|
|
export FZF_DEFAULT_OPTS
|
|
|
|
fi
|
|
|
|
|
2020-06-16 19:13:00 +00:00
|
|
|
${pkgs.fzf}/bin/fzf \
|
2020-04-14 17:49:00 +00:00
|
|
|
--history=/dev/null \
|
|
|
|
--prompt="$PROMPT" \
|
2020-06-16 19:38:32 +00:00
|
|
|
${optionalString cfg.reverse "--reverse"} \
|
2020-06-16 19:38:24 +00:00
|
|
|
${optionalString cfg.printQuery "--print-query"} \
|
|
|
|
${optionalString cfg.printQuery "| ${pkgs.coreutils}/bin/tail -1"}
|
2018-11-30 06:48:49 +00:00
|
|
|
''
|