Skip to content

Commit

Permalink
Show diff or file content in fzf_search_git_status
Browse files Browse the repository at this point in the history
  • Loading branch information
ovv committed Feb 14, 2021
1 parent 7c77ed4 commit 505511b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Empty file added foo
Empty file.
13 changes: 13 additions & 0 deletions functions/__fzf_git_diff.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function __fzf_git_diff
switch (string sub --length 2 $argv[1])
# Untracked filed
case '\?\?'
bat $argv[2]
# Deleted files, show the file content in previous commit
case '?D' 'D?'
git show HEAD:$argv[2]
# Other files, show the diff compared to last commit (unstaged & staged changes)
case '*'
git diff --color HEAD $argv[2]
end
end
4 changes: 3 additions & 1 deletion functions/__fzf_search_git_status.fish
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ function __fzf_search_git_status --description "Search the output of git status.
set 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 --ansi --multi --query=(commandline --current-token)
fzf --ansi --multi \
--query=(commandline --current-token) \
--preview="__fzf_git_diff {} {2}"
)
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
Expand Down

0 comments on commit 505511b

Please sign in to comment.