Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show diff or file content in fzf_search_git_status #124

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions functions/__fzf_preview_changed_file.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function __fzf_preview_changed_file
set git_status (string sub --length 2 $argv[1])

# path has been renamed and looks like "R LICENSE -> LICENSE.md"
# extract the renamed path
if test (string sub --length 1 $git_status) = 'R'
set path (string split -- "-> " $argv[2])[-1]
else
set path $argv[2]
end

switch $status
# Untracked filed
case '\?\?'
bat $path
# Deleted files, show the file content in previous commit
case '?D' 'D?'
git show HEAD:$path
# Other files, show the diff compared to last commit (unstaged & staged changes)
case '*'
git diff --color HEAD $path
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_preview_changed_file {} {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