diff --git a/modules/shell/fish/default.nix b/modules/shell/fish/default.nix index c81d49f..bec278a 100644 --- a/modules/shell/fish/default.nix +++ b/modules/shell/fish/default.nix @@ -51,6 +51,10 @@ description = "Open a recent file in Vim"; body = builtins.readFile ./functions/recent.fish; }; + search-and-edit = { + description = "Search and open the relevant file in Vim"; + body = builtins.readFile ./functions/search-and-edit.fish; + }; syncnotes = { description = "Full git commit on notes"; body = builtins.readFile ./functions/syncnotes.fish; diff --git a/modules/shell/fish/functions/fish_user_key_bindings.fish b/modules/shell/fish/functions/fish_user_key_bindings.fish index a083736..3ca0ee0 100644 --- a/modules/shell/fish/functions/fish_user_key_bindings.fish +++ b/modules/shell/fish/functions/fish_user_key_bindings.fish @@ -1,5 +1,7 @@ bind -M insert \co edit bind -M default \co edit +bind -M insert \cs search-and-edit +bind -M default \cs search-and-edit bind -M insert \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute' bind -M default \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute' bind -M insert \ce recent diff --git a/modules/shell/fish/functions/search-and-edit.fish b/modules/shell/fish/functions/search-and-edit.fish new file mode 100644 index 0000000..a9704e3 --- /dev/null +++ b/modules/shell/fish/functions/search-and-edit.fish @@ -0,0 +1,18 @@ +set vimfile ( + rg \ + --color=always \ + --line-number \ + --no-heading \ + --smart-case \ + --iglob !/Library/** \ + --iglob !/System/** \ + --iglob "!Users/$HOME/Library/*" \ + | fzf --ansi \ + --color "hl:-1:underline,hl+:-1:underline:reverse" \ + --delimiter : \ + --preview 'bat --color=always {1} --highlight-line {2}' \ + --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' +) +and set vimfile (echo $vimfile | tr -d '\r') +and commandline -r "vim $vimfile" +and commandline -f execute diff --git a/modules/shell/fzf.nix b/modules/shell/fzf.nix index 2e3d099..f6d4ac4 100644 --- a/modules/shell/fzf.nix +++ b/modules/shell/fzf.nix @@ -9,7 +9,14 @@ projects = { description = "Jump to a project"; body = '' - set projdir (ls ${config.homePath}/dev/personal | fzf) + set projdir ( \ + fd \ + --search-path $HOME \ + --type directory \ + --hidden \ + --exclude ".local/**" \ + "^.git\$" \ + | fzf) and cd ${config.homePath}/dev/personal/$projdir and commandline -f execute '';