this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 212 lines 10 kB view raw
1function fisher --argument-names cmd --description "A plugin manager for Fish" 2 set --query fisher_path || set --local fisher_path $__fish_config_dir 3 set --local fisher_version 4.3.1 4 set --local fish_plugins $__fish_config_dir/fish_plugins 5 6 switch "$cmd" 7 case -v --version 8 echo "fisher, version $fisher_version" 9 case "" -h --help 10 echo "Usage: fisher install <plugins...> Install plugins" 11 echo " fisher remove <plugins...> Remove installed plugins" 12 echo " fisher update <plugins...> Update installed plugins" 13 echo " fisher update Update all installed plugins" 14 echo " fisher list [<regex>] List installed plugins matching regex" 15 echo "Options:" 16 echo " -v or --version Print version" 17 echo " -h or --help Print this help message" 18 echo "Variables:" 19 echo " \$fisher_path Plugin installation path. Default: ~/.config/fish" 20 case ls list 21 string match --entire --regex -- "$argv[2]" $_fisher_plugins 22 case install update remove 23 isatty || read --local --null --array stdin && set --append argv $stdin 24 25 set --local install_plugins 26 set --local update_plugins 27 set --local remove_plugins 28 set --local arg_plugins $argv[2..-1] 29 set --local old_plugins $_fisher_plugins 30 set --local new_plugins 31 32 if ! set --query argv[2] 33 if test "$cmd" != update 34 echo "fisher: Not enough arguments for command: \"$cmd\"" >&2 && return 1 35 else if test ! -e $fish_plugins 36 echo "fisher: \"$fish_plugins\" file not found: \"$cmd\"" >&2 && return 1 37 end 38 set arg_plugins (string match --regex -- '^[^\s]+$' <$fish_plugins) 39 end 40 41 for plugin in $arg_plugins 42 test -e "$plugin" && set plugin (realpath $plugin) 43 contains -- "$plugin" $new_plugins || set --append new_plugins $plugin 44 end 45 46 if set --query argv[2] 47 for plugin in $new_plugins 48 if contains -- "$plugin" $old_plugins 49 test "$cmd" = remove && 50 set --append remove_plugins $plugin || 51 set --append update_plugins $plugin 52 else if test "$cmd" = install 53 set --append install_plugins $plugin 54 else 55 echo "fisher: Plugin not installed: \"$plugin\"" >&2 && return 1 56 end 57 end 58 else 59 for plugin in $new_plugins 60 contains -- "$plugin" $old_plugins && 61 set --append update_plugins $plugin || 62 set --append install_plugins $plugin 63 end 64 65 for plugin in $old_plugins 66 contains -- "$plugin" $new_plugins || set --append remove_plugins $plugin 67 end 68 end 69 70 set --local pid_list 71 set --local source_plugins 72 set --local fetch_plugins $update_plugins $install_plugins 73 echo (set_color --bold)fisher $cmd version $fisher_version(set_color normal) 74 75 for plugin in $fetch_plugins 76 set --local source (command mktemp -d) 77 set --append source_plugins $source 78 79 command mkdir -p $source/{completions,conf.d,functions} 80 81 fish --command " 82 if test -e $plugin 83 command cp -Rf $plugin/* $source 84 else 85 set temp (command mktemp -d) 86 set name (string split \@ $plugin) || set name[2] HEAD 87 set url https://api.github.com/repos/\$name[1]/tarball/\$name[2] 88 set header 'Accept: application/vnd.github.v3+json' 89 90 echo Fetching (set_color --underline)\$url(set_color normal) 91 92 if curl --silent -L -H \$header \$url | tar -xzC \$temp -f - 2>/dev/null 93 command cp -Rf \$temp/*/* $source 94 else 95 echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2 96 command rm -rf $source 97 end 98 command rm -rf \$temp 99 end 100 101 set files $source/* && string match --quiet --regex -- .+\.fish\\\$ \$files 102 " & 103 104 set --append pid_list (jobs --last --pid) 105 end 106 107 wait $pid_list 2>/dev/null 108 109 for plugin in $fetch_plugins 110 if set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] && test ! -e $source 111 if set --local index (contains --index -- "$plugin" $install_plugins) 112 set --erase install_plugins[$index] 113 else 114 set --erase update_plugins[(contains --index -- "$plugin" $update_plugins)] 115 end 116 end 117 end 118 119 for plugin in $update_plugins $remove_plugins 120 if set --local index (contains --index -- "$plugin" $_fisher_plugins) 121 set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files 122 123 if contains -- "$plugin" $remove_plugins 124 for name in (string replace --filter --regex -- '.+/conf\.d/([^/]+)\.fish$' '$1' $$plugin_files_var) 125 emit {$name}_uninstall 126 end 127 printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var 128 end 129 130 command rm -rf $$plugin_files_var 131 functions --erase (string replace --filter --regex -- '.+/functions/([^/]+)\.fish$' '$1' $$plugin_files_var) 132 133 for name in (string replace --filter --regex -- '.+/completions/([^/]+)\.fish$' '$1' $$plugin_files_var) 134 complete --erase --command $name 135 end 136 137 set --erase _fisher_plugins[$index] 138 set --erase $plugin_files_var 139 end 140 end 141 142 if set --query update_plugins[1] || set --query install_plugins[1] 143 command mkdir -p $fisher_path/{functions,conf.d,completions} 144 end 145 146 for plugin in $update_plugins $install_plugins 147 set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] 148 set --local files $source/{functions,conf.d,completions}/* 149 150 if set --local index (contains --index -- $plugin $install_plugins) 151 set --local user_files $fisher_path/{functions,conf.d,completions}/* 152 set --local conflict_files 153 154 for file in (string replace -- $source/ $fisher_path/ $files) 155 contains -- $file $user_files && set --append conflict_files $file 156 end 157 158 if set --query conflict_files[1] && set --erase install_plugins[$index] 159 echo -s "fisher: Cannot install \"$plugin\": please remove or move conflicting files first:" \n" "$conflict_files >&2 160 continue 161 end 162 end 163 164 for file in (string replace -- $source/ "" $files) 165 command cp -Rf $source/$file $fisher_path/$file 166 end 167 168 set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files 169 set --query files[1] && set --universal $plugin_files_var (string replace -- $source $fisher_path $files) 170 171 contains -- $plugin $_fisher_plugins || set --universal --append _fisher_plugins $plugin 172 contains -- $plugin $install_plugins && set --local event install || set --local event update 173 174 printf "%s\n" Installing\ (set_color --bold)$plugin(set_color normal) " "$$plugin_files_var 175 176 for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var) 177 source $file 178 if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file) 179 emit {$name}_$event 180 end 181 end 182 end 183 184 command rm -rf $source_plugins 185 186 set --query _fisher_plugins[1] || set --erase _fisher_plugins 187 set --query _fisher_plugins && 188 printf "%s\n" $_fisher_plugins >$fish_plugins || 189 command rm -f $fish_plugins 190 191 set --local total (count $install_plugins) (count $update_plugins) (count $remove_plugins) 192 test "$total" != "0 0 0" && echo (string join ", " ( 193 test $total[1] = 0 || echo "Installed $total[1]") ( 194 test $total[2] = 0 || echo "Updated $total[2]") ( 195 test $total[3] = 0 || echo "Removed $total[3]") 196 ) plugin/s 197 case \* 198 echo "fisher: Unknown command: \"$cmd\"" >&2 && return 1 199 end 200end 201 202## Migrations ## 203function _fisher_fish_postexec --on-event fish_postexec 204 if functions --query _fisher_list 205 fisher update >/dev/null 2>/dev/null 206 set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share 207 test -e $XDG_DATA_HOME/fisher && command rm -rf $XDG_DATA_HOME/fisher 208 functions --erase _fisher_list _fisher_plugin_parse 209 set --erase fisher_data 210 end 211 functions --erase _fisher_fish_postexec 212end