summaryrefslogtreecommitdiff
path: root/home-config/fish/functions/_fzf_search_git_status.fish
diff options
context:
space:
mode:
authorRyan Schanzenbacher <ryan@rschanz.org>2024-04-05 11:57:45 -0400
committerRyan Schanzenbacher <ryan@rschanz.org>2024-04-05 11:57:45 -0400
commitb88d77fb2d0d5028a6f5670695dee6bec129501f (patch)
tree2536b0461d297e647cf07157641c9b1223339adf /home-config/fish/functions/_fzf_search_git_status.fish
parent776a7ca55d2d2c3f396de91db1c6c3c5065012cd (diff)
ahhh sloppy fish, still needs fixing, esp with the vars
Diffstat (limited to 'home-config/fish/functions/_fzf_search_git_status.fish')
-rw-r--r--home-config/fish/functions/_fzf_search_git_status.fish41
1 files changed, 41 insertions, 0 deletions
diff --git a/home-config/fish/functions/_fzf_search_git_status.fish b/home-config/fish/functions/_fzf_search_git_status.fish
new file mode 100644
index 0000000..358f88c
--- /dev/null
+++ b/home-config/fish/functions/_fzf_search_git_status.fish
@@ -0,0 +1,41 @@
1function _fzf_search_git_status --description "Search the output of git status. Replace the current token with the selected file paths."
2 if not git rev-parse --git-dir >/dev/null 2>&1
3 echo '_fzf_search_git_status: Not in a git repository.' >&2
4 else
5 set -f preview_cmd '_fzf_preview_changed_file {}'
6 if set --query fzf_diff_highlighter
7 set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
8 end
9
10 set -f selected_paths (
11 # Pass configuration color.status=always to force status to use colors even though output is sent to a pipe
12 git -c color.status=always status --short |
13 _fzf_wrapper --ansi \
14 --multi \
15 --prompt="Git Status> " \
16 --query=(commandline --current-token) \
17 --preview=$preview_cmd \
18 --nth="2.." \
19 $fzf_git_status_opts
20 )
21 if test $status -eq 0
22 # git status --short automatically escapes the paths of most files for us so not going to bother trying to handle
23 # the few edges cases of weird file names that should be extremely rare (e.g. "this;needs;escaping")
24 set -f cleaned_paths
25
26 for path in $selected_paths
27 if test (string sub --length 1 $path) = R
28 # path has been renamed and looks like "R LICENSE -> LICENSE.md"
29 # extract the path to use from after the arrow
30 set --append cleaned_paths (string split -- "-> " $path)[-1]
31 else
32 set --append cleaned_paths (string sub --start=4 $path)
33 end
34 end
35
36 commandline --current-token --replace -- (string join ' ' $cleaned_paths)
37 end
38 end
39
40 commandline --function repaint
41end