From 8600374371f91843064441113f4023cda1730877 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Sat, 18 Mar 2023 16:40:57 -0300 Subject: General fish fixes and updates --- .../fish/functions/_fzf_preview_changed_file.fish | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .config/fish/functions/_fzf_preview_changed_file.fish (limited to '.config/fish/functions/_fzf_preview_changed_file.fish') diff --git a/.config/fish/functions/_fzf_preview_changed_file.fish b/.config/fish/functions/_fzf_preview_changed_file.fish new file mode 100644 index 00000000..c6e8c3d9 --- /dev/null +++ b/.config/fish/functions/_fzf_preview_changed_file.fish @@ -0,0 +1,30 @@ +# helper for _fzf_search_git_status +# arg should be a line from git status --short, e.g. +# MM functions/_fzf_preview_changed_file.fish +# D README.md +# R LICENSE.md -> LICENSE +function _fzf_preview_changed_file --description "Show the untracked, staged, and/or unstaged changes in the given file." + set -l path (string split ' ' $argv)[-1] + # first letter of short format shows index, second letter shows working tree + # https://git-scm.com/docs/git-status/2.35.0#_output + set -l index_status (string sub --length 1 $argv) + set -l working_tree_status (string sub --start 2 --length 1 $argv) + + if test $index_status = '?' + _fzf_report_diff_type Untracked + _fzf_preview_file $path + else + # no-prefix because the file is always being compared to itself so is unecessary + set diff_opts --color=always --no-prefix + + if test $index_status != ' ' + _fzf_report_diff_type Staged + git diff --staged $diff_opts -- $path + end + + if test $working_tree_status != ' ' + _fzf_report_diff_type Unstaged + git diff $diff_opts -- $path + end + end +end -- cgit v1.2.3