fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
867946468
master
1function fish_delta 2argparse h/help f/no-functions c/no-completions C/no-config d/no-diff n/new V/vendor= --$argv 3 4if set -q _flag_help 5__fish_print_help fish_delta 6return 0 7end 8 9type -q diff 10or set -l _flag_d --no-diff 11 12set -l vendormode default 13if set -ql _flag_vendor[ 1 ] 14if not contains --$_flag_vendor [ -1 ] default ignore user 15echo "Wrong vendor mode ' $_flag_vendor [ -1 ] '." >&2 16echo "Valid values are: default, ignore, new" >&2 17return 2 18end 19set vendormode$_flag_vendor [ -1 ] 20end 21 22# TODO: Do we want to keep the vendor dirs in here? 23set -l default_function_path 24test " $vendormode " = default&& set -a default_function_path$__fish_vendor_functionsdirs 25 26set -l default_complete_path 27test " $vendormode " = default&& set -a default_complete_path$__fish_vendor_completionsdirs 28 29set -l default_conf_path 30test " $vendormode " = default&& set -a default_conf_path$__fish_vendor_confdirs 31 32set -l user_function_path 33set -l user_complete_path 34set -l user_conf_path$__fish_config_dir /conf.d$__fish_sysconf_dir /conf.d 35test " $vendormode " = user&& set -a user_conf_path$__fish_vendor_confdirs 36 37for dirin $fish_function_path 38if contains --$vendormode ignore default 39contains --$dir $__fish_vendor_functionsdirs 40and continue 41end 42contains --$dir $default_function_path 43or set -a user_function_path$dir 44end 45for dirin $fish_complete_path 46if contains --$vendormode ignore default 47contains --$dir $__fish_vendor_completionsdirs 48and continue 49end 50# We don't care about generated completions. 51# They shouldn't be compared at all. 52contains --$dir $default_complete_path $__fish_cache_dir /generated_completions 53or set -a user_complete_path$dir 54end 55 56set -l vars 57not set -ql _flag_f[ 1 ] 58and set -a vars user_function_path default_function_path 59not set -ql _flag_c[ 1 ] 60and set -a vars user_complete_path default_complete_path 61not set -ql _flag_C[ 1 ] 62and set -a vars user_conf_path default_conf_path 63 64if not set -q vars[ 1 ] 65echo No directories to check!>&2 66return 2 67end 68 69set -l have_diff0 70 71if isatty stdout 72set -f colors"$ ( set_color --reset ) " "$ ( set_color brblue ) " "$ ( set_color bryellow ) " "$ ( set_color green ) " "$ ( set_color red ) " 73set -f pager( __fish_anypager ) 74or set pager cat 75 76if type -q less 77set -l lessopts isRF 78if test ( less --version| string match -r'less (\d+)' )[ 2 ] -lt 530 2> /dev/null 79set lessopts" $lessopts " X 80end 81 82not set -qx LESS 83and set -xf LESS$lessopts 84end 85else 86set -f colors"" "" "" "" "" 87set -f pager cat# cannot use a builtin here 88end 89 90begin 91while set -q vars[ 1 ] 92set -l user_var$$vars [ 1 ] 93set -l default_var$$vars [ 2 ] 94set -l all_changed0 95# We count config files as "changed" compared to /dev/null 96# because they are being run. 97test " $vars [ 1 ] " = user_conf_path 98and set all_changed1 99set -l dir 100test " $vars [ 2 ] " = default_complete_path 101and set dir completions 102test " $vars [ 2 ] " = default_function_path 103and set dir functions 104set -e vars[ ..2] 105set -l files( path filter -rf --$user_var /$argv .fish) 106set -q argv[ 1 ] 107or set files( path filter -rf --$user_var /*) 108set -q files[ 1 ] 109and set have_diff1 110 111for filein $files 112set -l bn( path basename --$file ) 113set -l default_exists false 114if set -q dir[ 1 ] ;and contains $dir /$bn ( status list-files$dir ) 115set default_exists true 116else if test $all_changed = 0 117set -ql _flag_n 118and printf ( _ "%sNew%s: %s\n" ) $colors [ 2 ] $colors [ 1 ] $file 119continue 120end 121if type -q diff 122function __fish_delta_diff -V _flag_d -V colors -V file -a default_file 123# We execute diff twice - once to figure out if it's changed, 124# so we can get nicer output. 125# 126if not diff -q --$file $default_file > /dev/null2>&1 127printf ( _ "%sChanged%s: %s\n" ) $colors [ 3 ] $colors [ 1 ] $file 128not set -ql _flag_d[ 1 ] 129and diff -u --$default_file $file 130else 131printf ( _ "%sUnmodified%s: %s\n" ) $colors [ 4 ] $colors [ 1 ] $file 132end 133end 134if $default_exists 135set -l tmpfile( __fish_mktemp_relative fish-delta) 136status get-file$dir /$bn > $tmpfile 137__fish_delta_diff $tmpfile 138command rm$tmpfile 139else 140__fish_delta_diff /dev/null 141end 142functions --erase __fish_delta_diff 143else 144# Without diff, we can't really tell if the contents are the same. 145printf ( _ "%sPossibly changed%s: %s\n" ) $colors [ 3 ] $colors [ 1 ] $file 146end 147end 148end 149# config.fish is special - it's a single file, not a directory, 150# and it's not precedenced - *both* ~/.config/fish/config.fish and /etc/fish/config.fish 151# are executed. 152if not set -ql _flag_C[ 1 ] ;and begin 153not set -q argv[ 1 ] 154or contains -- config$argv 155end 156for filein ( path filter -rf --$__fish_sysconf_dir /config.fish$__fish_config_dir /config.fish) 157# We count these as "changed" so they show up. 158printf ( _ "%sChanged%s: %s\n" ) $colors [ 3 ] $colors [ 1 ] $file 159not set -ql _flag_d[ 1 ] 160and diff -u -- /dev/null$file 161end 162end 163# Instead of using diff's --color=always, just do the coloring ourselves. 164end | string replace -r --'^(-.*)$' " $colors [ 5 ] \$1 $colors [ 1 ] " | 165string replace -r --'^(\+.*)$' " $colors [ 4 ] \$1 $colors [ 1 ] " | 166$pager 167 168return $have_diff 169end