···1+### key-bindings.fish ###
2+# ____ ____
3+# / __/___ / __/
4+# / /_/_ / / /_
5+# / __/ / /_/ __/
6+# /_/ /___/_/ key-bindings.fish
7+#
8+# - $FZF_TMUX_OPTS
9+# - $FZF_CTRL_T_COMMAND
10+# - $FZF_CTRL_T_OPTS
11+# - $FZF_CTRL_R_OPTS
12+# - $FZF_ALT_C_COMMAND
13+# - $FZF_ALT_C_OPTS
14+15+status is-interactive; or exit 0
16+17+18+# Key bindings
19+# ------------
20+function fzf_key_bindings
21+22+ function __fzf_defaults
23+ # $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
24+ # $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
25+ test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
26+ echo "--height $FZF_TMUX_HEIGHT --bind=ctrl-z:ignore" $argv[1]
27+ command cat "$FZF_DEFAULT_OPTS_FILE" 2> /dev/null
28+ echo $FZF_DEFAULT_OPTS $argv[2]
29+ end
30+31+ # Store current token in $dir as root for the 'find' command
32+ function fzf-file-widget -d "List files and folders"
33+ set -l commandline (__fzf_parse_commandline)
34+ set -lx dir $commandline[1]
35+ set -l fzf_query $commandline[2]
36+ set -l prefix $commandline[3]
37+38+ test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
39+ begin
40+ set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path --walker-root='$dir'" "$FZF_CTRL_T_OPTS")
41+ set -lx FZF_DEFAULT_COMMAND "$FZF_CTRL_T_COMMAND"
42+ set -lx FZF_DEFAULT_OPTS_FILE ''
43+ eval (__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end
44+ end
45+ if [ -z "$result" ]
46+ commandline -f repaint
47+ return
48+ else
49+ # Remove last token from commandline.
50+ commandline -t ""
51+ end
52+ for i in $result
53+ commandline -it -- $prefix
54+ commandline -it -- (string escape $i)
55+ commandline -it -- ' '
56+ end
57+ commandline -f repaint
58+ end
59+60+ function fzf-history-widget -d "Show command history"
61+ test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
62+ begin
63+ set -l FISH_MAJOR (echo $version | cut -f1 -d.)
64+ set -l FISH_MINOR (echo $version | cut -f2 -d.)
65+66+ # merge history from other sessions before searching
67+ if test -z "$fish_private_mode"
68+ builtin history merge
69+ end
70+71+ # history's -z flag is needed for multi-line support.
72+ # history's -z flag was added in fish 2.4.0, so don't use it for versions
73+ # before 2.4.0.
74+ if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ];
75+ if type -P perl > /dev/null 2>&1
76+ set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
77+ set -lx FZF_DEFAULT_OPTS_FILE ''
78+ builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | command perl -pe 's/^\d*\t//' | read -lz result
79+ and commandline -- $result
80+ else
81+ set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "--scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
82+ set -lx FZF_DEFAULT_OPTS_FILE ''
83+ builtin history -z | eval (__fzfcmd) --read0 --print0 -q '(commandline)' | read -lz result
84+ and commandline -- $result
85+ end
86+ else
87+ builtin history | eval (__fzfcmd) -q '(commandline)' | read -l result
88+ and commandline -- $result
89+ end
90+ end
91+ commandline -f repaint
92+ end
93+94+ function fzf-cd-widget -d "Change directory"
95+ set -l commandline (__fzf_parse_commandline)
96+ set -lx dir $commandline[1]
97+ set -l fzf_query $commandline[2]
98+ set -l prefix $commandline[3]
99+100+ test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
101+ begin
102+ set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path --walker-root='$dir'" "$FZF_ALT_C_OPTS")
103+ set -lx FZF_DEFAULT_OPTS_FILE ''
104+ set -lx FZF_DEFAULT_COMMAND "$FZF_ALT_C_COMMAND"
105+ eval (__fzfcmd)' +m --query "'$fzf_query'"' | read -l result
106+107+ if [ -n "$result" ]
108+ cd -- $result
109+110+ # Remove last token from commandline.
111+ commandline -t ""
112+ commandline -it -- $prefix
113+ end
114+ end
115+116+ commandline -f repaint
117+ end
118+119+ function __fzfcmd
120+ test -n "$FZF_TMUX"; or set FZF_TMUX 0
121+ test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
122+ if [ -n "$FZF_TMUX_OPTS" ]
123+ echo "fzf-tmux $FZF_TMUX_OPTS -- "
124+ else if [ $FZF_TMUX -eq 1 ]
125+ echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "
126+ else
127+ echo "fzf"
128+ end
129+ end
130+131+ bind \cr fzf-history-widget
132+ if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
133+ bind \ct fzf-file-widget
134+ end
135+ if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"
136+ bind \ec fzf-cd-widget
137+ end
138+139+ if bind -M insert > /dev/null 2>&1
140+ bind -M insert \cr fzf-history-widget
141+ if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
142+ bind -M insert \ct fzf-file-widget
143+ end
144+ if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"
145+ bind -M insert \ec fzf-cd-widget
146+ end
147+ end
148+149+ function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'
150+ set -l commandline (commandline -t)
151+152+ # strip -option= from token if present
153+ set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)
154+ set commandline (string replace -- "$prefix" '' $commandline)
155+156+ # eval is used to do shell expansion on paths
157+ eval set commandline $commandline
158+159+ if [ -z $commandline ]
160+ # Default to current directory with no --query
161+ set dir '.'
162+ set fzf_query ''
163+ else
164+ set dir (__fzf_get_dir $commandline)
165+166+ if [ "$dir" = "." -a (string sub -l 1 -- $commandline) != '.' ]
167+ # if $dir is "." but commandline is not a relative path, this means no file path found
168+ set fzf_query $commandline
169+ else
170+ # Also remove trailing slash after dir, to "split" input properly
171+ set fzf_query (string replace -r "^$dir/?" -- '' "$commandline")
172+ end
173+ end
174+175+ echo $dir
176+ echo $fzf_query
177+ echo $prefix
178+ end
179+180+ function __fzf_get_dir -d 'Find the longest existing filepath from input string'
181+ set dir $argv
182+183+ # Strip all trailing slashes. Ignore if $dir is root dir (/)
184+ if [ (string length -- $dir) -gt 1 ]
185+ set dir (string replace -r '/*$' -- '' $dir)
186+ end
187+188+ # Iteratively check if dir exists and strip tail end of path
189+ while [ ! -d "$dir" ]
190+ # If path is absolute, this can keep going until ends up at /
191+ # If path is relative, this can keep going until entire input is consumed, dirname returns "."
192+ set dir (dirname -- "$dir")
193+ end
194+195+ echo $dir
196+ end
197+198+end
199+### end: key-bindings.fish ###
200+fzf_key_bindings
···1+{ config, pkgs, ... }:
2+3+{
4+ # Home Manager needs a bit of information about you and the paths it should
5+ # manage.
6+ home.username = "noah";
7+ home.homeDirectory = "/Users/noah";
8+9+ # This value determines the Home Manager release that your configuration is
10+ # compatible with. This helps avoid breakage when a new Home Manager release
11+ # introduces backwards incompatible changes.
12+ #
13+ # You should not change this value, even if you update Home Manager. If you do
14+ # want to update the value, then make sure to first check the Home Manager
15+ # release notes.
16+ home.stateVersion = "24.11"; # Please read the comment before changing.
17+18+ # The home.packages option allows you to install Nix packages into your
19+ # environment.
20+ home.packages = [
21+ # # Adds the 'hello' command to your environment. It prints a friendly
22+ # # "Hello, world!" when run.
23+ # pkgs.hello
24+25+ # # It is sometimes useful to fine-tune packages, for example, by applying
26+ # # overrides. You can do that directly here, just don't forget the
27+ # # parentheses. Maybe you want to install Nerd Fonts with a limited number of
28+ # # fonts?
29+ # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })
30+31+ # # You can also create simple shell scripts directly inside your
32+ # # configuration. For example, this adds a command 'my-hello' to your
33+ # # environment:
34+ # (pkgs.writeShellScriptBin "my-hello" ''
35+ # echo "Hello, ${config.home.username}!"
36+ # '')
37+ ];
38+39+ # Home Manager is pretty good at managing dotfiles. The primary way to manage
40+ # plain files is through 'home.file'.
41+ home.file = {
42+ # # Building this configuration will create a copy of 'dotfiles/screenrc' in
43+ # # the Nix store. Activating the configuration will then make '~/.screenrc' a
44+ # # symlink to the Nix store copy.
45+ # ".screenrc".source = dotfiles/screenrc;
46+47+ # # You can also set the file content immediately.
48+ # ".gradle/gradle.properties".text = ''
49+ # org.gradle.console=verbose
50+ # org.gradle.daemon.idletimeout=3600000
51+ # '';
52+ };
53+54+ # Home Manager can also manage your environment variables through
55+ # 'home.sessionVariables'. These will be explicitly sourced when using a
56+ # shell provided by Home Manager. If you don't want to manage your shell
57+ # through Home Manager then you have to manually source 'hm-session-vars.sh'
58+ # located at either
59+ #
60+ # ~/.nix-profile/etc/profile.d/hm-session-vars.sh
61+ #
62+ # or
63+ #
64+ # ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh
65+ #
66+ # or
67+ #
68+ # /etc/profiles/per-user/noah/etc/profile.d/hm-session-vars.sh
69+ #
70+ home.sessionVariables = {
71+ # EDITOR = "emacs";
72+ };
73+74+ # Let Home Manager install and manage itself.
75+ programs.home-manager.enable = true;
76+}