Skip to content

Commit

Permalink
Sh: load Vim quickfix list with hunks
Browse files Browse the repository at this point in the history
  • Loading branch information
mhinz committed Aug 20, 2019
1 parent 56cc44e commit bcfc1e9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions .shrc
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,20 @@ prpush() {
}

changed() {
local files=($(git diff --name-only --relative "$@" 2>/dev/null))
[[ -n $files ]] && v "${files[@]}"
local files=$(git diff -U0 --no-prefix --relative "$@" 2>/dev/null | quickfix_diff_to_hunk)
[[ -z $files ]] && { echo '¯\_(ツ)_/¯'; return 1; }
v -q <(echo $files)
}

quickfix_diff_to_hunk() {
ruby -ne '
(file = $1; next) if $_ =~ /^\+\+\+ (.*)/;
next if file.nil?;
(linenr = $1; next) if $_ =~ /^@@ .*\+(\d+)/;
next if linenr.nil?;
puts "#{file}:#{linenr}: #{$1}" if $_ =~ /^[+-](.*)/;
linenr = nil
'
}

b() {
Expand Down

0 comments on commit bcfc1e9

Please sign in to comment.