flocon/dot_config/fish/functions/_fzf_search_git_status.fish
Anthony Rodriguez dc7ee4d021 Add .config/fish/functions/_fzf_configure_bindings_help.fish
Add .config/fish/functions/_fzf_extract_var_info.fish
Add .config/fish/functions/_fzf_preview_changed_file.fish
Add .config/fish/functions/_fzf_preview_file.fish
Add .config/fish/functions/_fzf_report_diff_type.fish
Add .config/fish/functions/_fzf_report_file_type.fish
Add .config/fish/functions/_fzf_search_directory.fish
Add .config/fish/functions/_fzf_search_git_log.fish
Add .config/fish/functions/_fzf_search_git_status.fish
Add .config/fish/functions/_fzf_search_history.fish
Add .config/fish/functions/_fzf_search_processes.fish
Add .config/fish/functions/_fzf_search_variables.fish
Add .config/fish/functions/_fzf_wrapper.fish
Add .config/fish/functions/_nvm_index_update.fish
Add .config/fish/functions/_nvm_list.fish
Add .config/fish/functions/_nvm_version_activate.fish
Add .config/fish/functions/_nvm_version_deactivate.fish
Add .config/fish/functions/fish_greeting.fish
Add .config/fish/functions/fish_mode_prompt.fish
Add .config/fish/functions/fish_title.fish
Add .config/fish/functions/fzf_configure_bindings.fish
Add .config/fish/functions/nvm.fish
2024-06-07 11:48:47 +02:00

41 lines
1.8 KiB
Fish

function _fzf_search_git_status --description "Search the output of git status. Replace the current token with the selected file paths."
if not git rev-parse --git-dir >/dev/null 2>&1
echo '_fzf_search_git_status: Not in a git repository.' >&2
else
set -f preview_cmd '_fzf_preview_changed_file {}'
if set --query fzf_diff_highlighter
set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
end
set -f selected_paths (
# Pass configuration color.status=always to force status to use colors even though output is sent to a pipe
git -c color.status=always status --short |
_fzf_wrapper --ansi \
--multi \
--prompt="Git Status> " \
--query=(commandline --current-token) \
--preview=$preview_cmd \
--nth="2.." \
$fzf_git_status_opts
)
if test $status -eq 0
# git status --short automatically escapes the paths of most files for us so not going to bother trying to handle
# the few edges cases of weird file names that should be extremely rare (e.g. "this;needs;escaping")
set -f cleaned_paths
for path in $selected_paths
if test (string sub --length 1 $path) = R
# path has been renamed and looks like "R LICENSE -> LICENSE.md"
# extract the path to use from after the arrow
set --append cleaned_paths (string split -- "-> " $path)[-1]
else
set --append cleaned_paths (string sub --start=4 $path)
end
end
commandline --current-token --replace -- (string join ' ' $cleaned_paths)
end
end
commandline --function repaint
end