mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 12:21:19 -03:00
fish_delta: share logic between standalone and installed builds
This commit is contained in:
@@ -110,38 +110,40 @@ function fish_delta
|
||||
|
||||
for file in $files
|
||||
set -l bn (path basename -- $file)
|
||||
set -l def (path filter -rf -- $default_var/$bn)[1]
|
||||
or set -l def (set -q dir[1] && status get-file $dir/$bn &>/dev/null && echo embedded)
|
||||
or begin
|
||||
if test $all_changed = 0
|
||||
set -ql _flag_n
|
||||
and printf (_ "%sNew%s: %s\n") $colors[2] $colors[1] $file
|
||||
continue
|
||||
else
|
||||
set def /dev/null
|
||||
end
|
||||
set -l default_exists false
|
||||
if set -q dir[1]; and contains $dir/$bn (__fish_data_list_files $dir)
|
||||
set default_exists true
|
||||
else if test $all_changed = 0
|
||||
set -ql _flag_n
|
||||
and printf (_ "%sNew%s: %s\n") $colors[2] $colors[1] $file
|
||||
continue
|
||||
end
|
||||
|
||||
if type -q diff
|
||||
# We execute diff twice - once to figure out if it's changed,
|
||||
# so we can get nicer output.
|
||||
#
|
||||
if test "$def" = embedded
|
||||
if not status get-file $dir/$bn | diff -q -- $file - >/dev/null 2>&1
|
||||
function __fish_delta_diff -V _flag_d -V colors -V file -a default_file
|
||||
# We execute diff twice - once to figure out if it's changed,
|
||||
# so we can get nicer output.
|
||||
#
|
||||
if not diff -q -- $file $default_file >/dev/null 2>&1
|
||||
printf (_ "%sChanged%s: %s\n") $colors[3] $colors[1] $file
|
||||
not set -ql _flag_d[1]
|
||||
and status get-file $dir/$bn | diff -u -- - $file
|
||||
continue
|
||||
end
|
||||
else
|
||||
if not diff -q -- $file $def >/dev/null 2>&1
|
||||
printf (_ "%sChanged%s: %s\n") $colors[3] $colors[1] $file
|
||||
not set -ql _flag_d[1]
|
||||
and diff -u -- $def $file
|
||||
continue
|
||||
and diff -u -- $default_file $file
|
||||
else
|
||||
printf (_ "%sUnmodified%s: %s\n") $colors[4] $colors[1] $file
|
||||
end
|
||||
end
|
||||
printf (_ "%sUnmodified%s: %s\n") $colors[4] $colors[1] $file
|
||||
function __fish_delta_diff_maybe_file -a maybe_default_file
|
||||
set -l tmpfile (mktemp)
|
||||
cat $maybe_default_file >$tmpfile
|
||||
__fish_delta_diff $tmpfile
|
||||
command rm $tmpfile
|
||||
end
|
||||
if $default_exists
|
||||
__fish_data_with_file $dir/$bn __fish_delta_diff_maybe_file
|
||||
else
|
||||
__fish_delta_diff /dev/null
|
||||
end
|
||||
functions --erase __fish_delta_diff
|
||||
functions --erase __fish_delta_diff_maybe_file
|
||||
else
|
||||
# Without diff, we can't really tell if the contents are the same.
|
||||
printf (_ "%sPossibly changed%s: %s\n") $colors[3] $colors[1] $file
|
||||
|
||||
Reference in New Issue
Block a user