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

99 lines
2.2 KiB
Nix
Raw Normal View History

2021-10-12 17:36:09 +00:00
{ pkgs, stockholm, ... }@args:
with stockholm.lib;
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 = {
appName = mkOption {
default = "fzfmenu";
type = types.label;
};
defaultPrompt = mkOption {
default = ">";
type = types.str;
};
printQuery = mkOption {
default = true;
type = types.bool;
};
2020-06-16 19:38:32 +00:00
reverse = mkOption {
default = true;
type = types.bool;
};
windowTitle = mkOption {
default = "fzfmenu";
type = types.str;
};
};
};
};
in
2018-11-30 06:48:49 +00:00
2023-07-08 12:49:19 +00:00
pkgs.writers.writeDashBin "fzfmenu" ''
2018-11-30 06:48:49 +00:00
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
2023-02-06 12:00:45 +00:00
exec ${pkgs.alacritty}/bin/alacritty \
--config-file /var/theme/config/alacritty.yaml \
--class ${cfg.appName} \
--title ${shell.escape cfg.windowTitle} \
--command "$0" "$@"
else
exec 0<&''${FZFMENU_INPUT_FD-0}
exec 1>&''${FZFMENU_OUTPUT_FD-1}
fi
PROMPT=${shell.escape cfg.defaultPrompt}
for i in "$@"; do
case $i in
2018-11-30 06:48:49 +00:00
-p)
PROMPT=$2
shift 2
break
;;
2018-12-02 04:47:20 +00:00
-l)
# no reason to filter number of lines
LINES=$2
shift 2
break
;;
2018-12-02 04:47:20 +00:00
-i)
# we do this anyway
shift
break
;;
2018-11-30 06:48:49 +00:00
*)
echo "Unknown option $1" >&2
shift
;;
esac
2018-11-30 06:48:49 +00:00
done
if test -n "''${FZFMENU_FZF_DEFAULT_OPTS-}"; then
FZF_DEFAULT_OPTS=''${FZFMENU_FZF_DEFAULT_OPTS-}
export FZF_DEFAULT_OPTS
fi
${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"} \
${optionalString cfg.printQuery "--print-query"} \
${optionalString cfg.printQuery "| ${pkgs.coreutils}/bin/tail -1"}
2018-11-30 06:48:49 +00:00
''