From 2f76e00c94b585e90ac01f042913ff0edcc8678c Mon Sep 17 00:00:00 2001 From: "shinnosuke.suzuki" Date: Sun, 10 Sep 2023 22:26:07 +0900 Subject: [PATCH] fisher 3.x to 4.x upgrade --- .config/fish/completions/asdf.fish | 0 .config/fish/completions/fisher.fish | 1 - .config/fish/completions/ghq.fish | 0 .config/fish/completions/kubectl.fish | 36 +- .config/fish/conf.d/asdf.fish | 10 +- .config/fish/conf.d/ghq_key_bindings.fish | 0 .config/fish/{fishfile => fish_plugins} | 0 .config/fish/fish_variables | 7 + .../functions/__ghq_repository_search.fish | 0 .config/fish/functions/balias.fish | 0 .config/fish/functions/fisher.fish | 591 ++++++------------ .config/fish/functions/peco_kill.fish | 0 .../fish/functions/peco_select_history.fish | 0 13 files changed, 243 insertions(+), 402 deletions(-) mode change 100755 => 100644 .config/fish/completions/asdf.fish delete mode 100755 .config/fish/completions/fisher.fish mode change 100755 => 100644 .config/fish/completions/ghq.fish mode change 100755 => 100644 .config/fish/completions/kubectl.fish mode change 100755 => 100644 .config/fish/conf.d/ghq_key_bindings.fish rename .config/fish/{fishfile => fish_plugins} (100%) mode change 100755 => 100644 mode change 100755 => 100644 .config/fish/functions/__ghq_repository_search.fish mode change 100755 => 100644 .config/fish/functions/balias.fish mode change 100755 => 100644 .config/fish/functions/fisher.fish mode change 100755 => 100644 .config/fish/functions/peco_kill.fish mode change 100755 => 100644 .config/fish/functions/peco_select_history.fish diff --git a/.config/fish/completions/asdf.fish b/.config/fish/completions/asdf.fish old mode 100755 new mode 100644 diff --git a/.config/fish/completions/fisher.fish b/.config/fish/completions/fisher.fish deleted file mode 100755 index 271e314..0000000 --- a/.config/fish/completions/fisher.fish +++ /dev/null @@ -1 +0,0 @@ -fisher complete diff --git a/.config/fish/completions/ghq.fish b/.config/fish/completions/ghq.fish old mode 100755 new mode 100644 diff --git a/.config/fish/completions/kubectl.fish b/.config/fish/completions/kubectl.fish old mode 100755 new mode 100644 index ce82b0d..6b719d5 --- a/.config/fish/completions/kubectl.fish +++ b/.config/fish/completions/kubectl.fish @@ -57,7 +57,15 @@ function __fish_kubectl end end - command kubectl $__fish_kubectl_timeout $context_args $argv + set -l kubeconfig_args + + if set -l kubeconfig_args (__fish_kubectl_get_kubeconfig_flags | string split " ") + for c in $kubeconfig_args + set kubeconfig_args $kubeconfig_args $c + end + end + + command kubectl $__fish_kubectl_timeout $context_args $kubeconfig_args $argv end function __fish_kubectl_get_commands @@ -288,6 +296,32 @@ function __fish_kubectl_get_context_flags return 1 end +function __fish_kubectl_get_kubeconfig_flags + set -l cmd (commandline -opc) + if [ (count $cmd) -eq 0 ] + return 1 + end + + set -l foundKubeconfig 0 + + for c in $cmd + test $foundKubeconfig -eq 1 + set -l out "--kubeconfig" "$c" + and echo $out + and return 0 + + if string match -q -r -- "--kubeconfig=" "$c" + set -l out (string split -- "=" "$c" | string join " ") + and echo $out + and return 0 + else if contains -- "$c" "--kubeconfig" + set foundKubeconfig 1 + end + end + + return 1 +end + function __fish_kubectl_get_ns_flags set -l cmd (commandline -opc) if [ (count $cmd) -eq 0 ] diff --git a/.config/fish/conf.d/asdf.fish b/.config/fish/conf.d/asdf.fish index a62c366..aa24984 100644 --- a/.config/fish/conf.d/asdf.fish +++ b/.config/fish/conf.d/asdf.fish @@ -1,7 +1,11 @@ if test -n "$ASDF_DATA_DIR" -a -d "$ASDF_DATA_DIR" source $ASDF_DATA_DIR/asdf.fish -end - -if test -e ~/.asdf/asdf.fish +else if test -f ~/.asdf/asdf.fish source ~/.asdf/asdf.fish +else if test -f /usr/local/opt/asdf/asdf.fish + source /usr/local/opt/asdf/asdf.fish +else if test -f /opt/homebrew/opt/asdf/asdf.fish + source /opt/homebrew/opt/asdf/asdf.fish +else if test -f /opt/homebrew/opt/asdf/libexec/asdf.fish + source /opt/homebrew/opt/asdf/libexec/asdf.fish end diff --git a/.config/fish/conf.d/ghq_key_bindings.fish b/.config/fish/conf.d/ghq_key_bindings.fish old mode 100755 new mode 100644 diff --git a/.config/fish/fishfile b/.config/fish/fish_plugins old mode 100755 new mode 100644 similarity index 100% rename from .config/fish/fishfile rename to .config/fish/fish_plugins diff --git a/.config/fish/fish_variables b/.config/fish/fish_variables index 663230c..754d3f9 100755 --- a/.config/fish/fish_variables +++ b/.config/fish/fish_variables @@ -1,6 +1,13 @@ # This file contains fish universal variable definitions. # VERSION: 3.0 SETUVAR __fish_initialized:3400 +SETUVAR _fisher_decors_2F_fish_2D_ghq_files:\x7e/\x2econfig/fish/functions/__ghq_repository_search\x2efish\x1e\x7e/\x2econfig/fish/conf\x2ed/ghq_key_bindings\x2efish\x1e\x7e/\x2econfig/fish/completions/ghq\x2efish +SETUVAR _fisher_evanlucas_2F_fish_2D_kubectl_2D_completions_files:\x7e/\x2econfig/fish/completions/kubectl\x2efish +SETUVAR _fisher_oh_2D_my_2D_fish_2F_plugin_2D_balias_files:\x7e/\x2econfig/fish/functions/balias\x2efish +SETUVAR _fisher_oh_2D_my_2D_fish_2F_plugin_2D_peco_files:\x7e/\x2econfig/fish/functions/peco_kill\x2efish\x1e\x7e/\x2econfig/fish/functions/peco_select_history\x2efish +SETUVAR _fisher_plugins:decors/fish\x2dghq\x1eoh\x2dmy\x2dfish/plugin\x2dpeco\x1eoh\x2dmy\x2dfish/plugin\x2dbalias\x1eevanlucas/fish\x2dkubectl\x2dcompletions\x1erstacruz/fish\x2dasdf +SETUVAR _fisher_rstacruz_2F_fish_2D_asdf_files:\x7e/\x2econfig/fish/conf\x2ed/asdf\x2efish\x1e\x7e/\x2econfig/fish/completions/asdf\x2efish +SETUVAR _fisher_upgraded_to_4_4:\x1d SETUVAR fish_color_autosuggestion:555\x1ebrblack SETUVAR fish_color_cancel:\x2dr SETUVAR fish_color_command:005fd7 diff --git a/.config/fish/functions/__ghq_repository_search.fish b/.config/fish/functions/__ghq_repository_search.fish old mode 100755 new mode 100644 diff --git a/.config/fish/functions/balias.fish b/.config/fish/functions/balias.fish old mode 100755 new mode 100644 diff --git a/.config/fish/functions/fisher.fish b/.config/fish/functions/fisher.fish old mode 100755 new mode 100644 index ee3ebd2..b1513d3 --- a/.config/fish/functions/fisher.fish +++ b/.config/fish/functions/fisher.fish @@ -1,443 +1,240 @@ -set -g fisher_version 3.3.0 +function fisher --argument-names cmd --description "A plugin manager for Fish" + set --query fisher_path || set --local fisher_path $__fish_config_dir + set --local fisher_version 4.4.4 + set --local fish_plugins $__fish_config_dir/fish_plugins -function fisher -a cmd -d "fish package manager" - set -q XDG_CACHE_HOME; or set XDG_CACHE_HOME ~/.cache - set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config - set -q XDG_DATA_HOME; or set XDG_DATA_HOME ~/.local/share + switch "$cmd" + case -v --version + echo "fisher, version $fisher_version" + case "" -h --help + echo "Usage: fisher install Install plugins" + echo " fisher remove Remove installed plugins" + echo " fisher update Update installed plugins" + echo " fisher update Update all installed plugins" + echo " fisher list [] List installed plugins matching regex" + echo "Options:" + echo " -v, --version Print version" + echo " -h, --help Print this help message" + echo "Variables:" + echo " \$fisher_path Plugin installation path. Default: $__fish_config_dir" | string replace --regex -- $HOME \~ + case ls list + string match --entire --regex -- "$argv[2]" $_fisher_plugins + case install update remove + isatty || read --local --null --array stdin && set --append argv $stdin + + set --local install_plugins + set --local update_plugins + set --local remove_plugins + set --local arg_plugins $argv[2..-1] + set --local old_plugins $_fisher_plugins + set --local new_plugins + + test -e $fish_plugins && set --local file_plugins (string match --regex -- '^[^\s]+$' <$fish_plugins) + + if ! set --query argv[2] + if test "$cmd" != update + echo "fisher: Not enough arguments for command: \"$cmd\"" >&2 && return 1 + else if ! set --query file_plugins + echo "fisher: \"$fish_plugins\" file not found: \"$cmd\"" >&2 && return 1 + end + set arg_plugins $file_plugins + end - set -g fish_config $XDG_CONFIG_HOME/fish - set -g fisher_cache $XDG_CACHE_HOME/fisher - set -g fisher_data $XDG_DATA_HOME/fisher + for plugin in $arg_plugins + set plugin (test -e "$plugin" && realpath $plugin || string lower -- $plugin) + contains -- "$plugin" $new_plugins || set --append new_plugins $plugin + end - set -q fisher_path; or set -g fisher_path $fish_config - set -g fishfile $fish_config/fishfile + if set --query argv[2] + for plugin in $new_plugins + if contains -- "$plugin" $old_plugins + test "$cmd" = remove && + set --append remove_plugins $plugin || + set --append update_plugins $plugin + else if test "$cmd" = install + set --append install_plugins $plugin + else + echo "fisher: Plugin not installed: \"$plugin\"" >&2 && return 1 + end + end + else + for plugin in $new_plugins + contains -- "$plugin" $old_plugins && + set --append update_plugins $plugin || + set --append install_plugins $plugin + end - for path in {$fish_config,$fisher_path}/{functions,completions,conf.d} $fisher_cache - if test ! -d $path - command mkdir -p $path - end - end + for plugin in $old_plugins + contains -- "$plugin" $new_plugins || set --append remove_plugins $plugin + end + end - if test ! -e $fisher_path/completions/fisher.fish - echo "fisher complete" >$fisher_path/completions/fisher.fish - _fisher_complete - end + set --local pid_list + set --local source_plugins + set --local fetch_plugins $update_plugins $install_plugins + set --local fish_path (status fish-path) - if test -e $fisher_path/conf.d/fisher.fish - switch "$version" - case \*-\* - command rm -f $fisher_path/conf.d/fisher.fish - case 2\* - case \* - command rm -f $fisher_path/conf.d/fisher.fish - end - else - switch "$version" - case \*-\* - case 2\* - echo "fisher copy-user-key-bindings" >$fisher_path/conf.d/fisher.fish - end - end + echo (set_color --bold)fisher $cmd version $fisher_version(set_color normal) - # 2019-10-22: temp code, migrates fishfile from old path back to $fish_config - if test -e "$fisher_path/fishfile"; and test ! -e "$fishfile" - command mv -f "$fisher_path/fishfile" "$fishfile" - end + for plugin in $fetch_plugins + set --local source (command mktemp -d) + set --append source_plugins $source - # 2020-06-23: temp code, migrates fisher data from XDG_CONFIG_HOME to XDG_DATA_HOME - set -l fisher_config $XDG_CONFIG_HOME/fisher - if test -d $fisher_config - echo "migrating local data from $fisher_config to $fisher_data" - command rm -rf $fisher_data - command mv -f $fisher_config $fisher_data - end + command mkdir -p $source/{completions,conf.d,themes,functions} - switch "$cmd" - case {,self-}complete - _fisher_complete - case copy-user-key-bindings - _fisher_copy_user_key_bindings - case ls - set -e argv[1] - if test -s "$fishfile" - set -l file (_fisher_fmt <$fishfile | _fisher_parse -R | command sed "s|@.*||") - _fisher_ls | _fisher_fmt | command awk -v FILE="$file" " - BEGIN { for (n = split(FILE, f); ++i <= n;) file[f[i]] } \$0 in file && /$argv[1]/ - " | command sed "s|^$HOME|~|" - end - case self-update - _fisher_self_update (status -f) - case self-uninstall - _fisher_self_uninstall - case {,-}-v{ersion,} - echo "fisher version $fisher_version" (status -f | command sed "s|^$HOME|~|") - case {,-}-h{elp,} - _fisher_help - case "" - _fisher_commit -- - case add rm - if not isatty - while read -l arg - set argv $argv $arg - end - end + $fish_path --command " + if test -e $plugin + command cp -Rf $plugin/* $source + else + set temp (command mktemp -d) + set repo (string split -- \@ $plugin) || set repo[2] HEAD - if test (count $argv) = 1 - echo "fisher: invalid number of arguments" >&2 - _fisher_help >&2 - return 1 - end + if set path (string replace --regex -- '^(https://)?gitlab.com/' '' \$repo[1]) + set name (string split -- / \$path)[-1] + set url https://gitlab.com/\$path/-/archive/\$repo[2]/\$name-\$repo[2].tar.gz + else + set url https://api.github.com/repos/\$repo[1]/tarball/\$repo[2] + end - _fisher_commit $argv - case \* - echo "fisher: unknown flag or command \"$cmd\"" >&2 - _fisher_help >&2 - return 1 - end -end + echo Fetching (set_color --underline)\$url(set_color normal) -function _fisher_complete - complete -ec fisher - complete -xc fisher -n __fish_use_subcommand -a add -d "Add packages" - complete -xc fisher -n __fish_use_subcommand -a rm -d "Remove packages" - complete -xc fisher -n __fish_use_subcommand -a ls -d "List installed packages matching REGEX" - complete -xc fisher -n __fish_use_subcommand -a --help -d "Show usage help" - complete -xc fisher -n __fish_use_subcommand -a --version -d "$fisher_version" - complete -xc fisher -n __fish_use_subcommand -a self-update -d "Update to the latest version" - for pkg in (fisher ls) - complete -xc fisher -n "__fish_seen_subcommand_from rm" -a $pkg - end -end - -function _fisher_copy_user_key_bindings - if functions -q fish_user_key_bindings - functions -c fish_user_key_bindings fish_user_key_bindings_copy - end - function fish_user_key_bindings - for file in $fisher_path/conf.d/*_key_bindings.fish - source $file >/dev/null 2>/dev/null - end - if functions -q fish_user_key_bindings_copy - fish_user_key_bindings_copy - end - end -end - -function _fisher_ls - for pkg in $fisher_data/*/*/* - command readlink $pkg; or echo $pkg - end -end + if command curl -q --silent -L \$url | command tar -xzC \$temp -f - 2>/dev/null + command cp -Rf \$temp/*/* $source + else + echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2 + command rm -rf $source + end -function _fisher_fmt - command sed "s|^[[:space:]]*||;s|^$fisher_data/||;s|^~|$HOME|;s|^\.\/*|$PWD/|;s|^https*:/*||;s|^github\.com/||;s|/*\$||" -end + command rm -rf \$temp + end -function _fisher_help - echo "usage: fisher add Add packages" - echo " fisher rm Remove packages" - echo " fisher Update all packages" - echo " fisher ls [] List installed packages matching " - echo " fisher --help Show this help" - echo " fisher --version Show the current version" - echo " fisher self-update Update to the latest version" - echo " fisher self-uninstall Uninstall from your system" - echo "examples:" - echo " fisher add jethrokuan/z rafaelrinaldi/pure" - echo " fisher add gitlab.com/foo/bar@v2" - echo " fisher add ~/path/to/local/pkg" - echo " fisher add &2 - command curl -s "$url?nocache" >$file. - - set -l next_version (command awk '$4 ~ /^[0-9]+\.[0-9]+\.[0-9]+$/ { print v=$4 } { exit !v }' <$file.) - switch "$next_version" - case "" $fisher_version - command rm -f $file. - if test -z "$next_version" - echo "fisher: cannot update fisher -- are you offline?" >&2 - return 1 + set --append pid_list (jobs --last --pid) end - echo "fisher is already up-to-date" >&2 - case \* - echo "linking $file" | command sed "s|$HOME|~|" >&2 - command mv -f $file. $file - source $file - echo "updated to fisher $fisher_version -- hooray!" >&2 - _fisher_complete - end -end - -function _fisher_self_uninstall - for pkg in (_fisher_ls) - _fisher_rm $pkg - end - for file in $fisher_cache $fisher_data $fisher_path/{functions,completions,conf.d}/fisher.fish $fishfile - echo "removing $file" - command rm -Rf $file 2>/dev/null - end | command sed "s|$HOME|~|" >&2 + wait $pid_list 2>/dev/null - for name in (set -n | command awk '/^fisher_/') - set -e "$name" - end + for plugin in $fetch_plugins + if set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] && test ! -e $source + if set --local index (contains --index -- "$plugin" $install_plugins) + set --erase install_plugins[$index] + else + set --erase update_plugins[(contains --index -- "$plugin" $update_plugins)] + end + end + end - functions -e (functions -a | command awk '/^_fisher/') fisher - complete -c fisher --erase -end + for plugin in $update_plugins $remove_plugins + if set --local index (contains --index -- "$plugin" $_fisher_plugins) + set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files -function _fisher_commit -a cmd - set -e argv[1] - set -l elapsed (_fisher_now) + if contains -- "$plugin" $remove_plugins + for name in (string replace --filter --regex -- '.+/conf\.d/([^/]+)\.fish$' '$1' $$plugin_files_var) + emit {$name}_uninstall + end + printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~ + set --erase _fisher_plugins[$index] + end - if test ! -e "$fishfile" - command touch $fishfile - echo "created new fishfile in $fishfile" | command sed "s|$HOME|~|" >&2 - end + command rm -rf (string replace -- \~ ~ $$plugin_files_var) - set -l old_pkgs (_fisher_ls | _fisher_fmt) - for pkg in (_fisher_ls) - _fisher_rm $pkg - end - command rm -Rf $fisher_data - command mkdir -p $fisher_data - - set -l next_pkgs (_fisher_fmt <$fishfile | _fisher_parse -R $cmd (printf "%s\n" $argv | _fisher_fmt)) - set -l actual_pkgs (_fisher_fetch $next_pkgs) - set -l updated_pkgs - for pkg in $old_pkgs - if contains -- $pkg $actual_pkgs - set updated_pkgs $updated_pkgs $pkg - end - end + functions --erase (string replace --filter --regex -- '.+/functions/([^/]+)\.fish$' '$1' $$plugin_files_var) - if test -z "$actual_pkgs$updated_pkgs$old_pkgs$next_pkgs" - echo "fisher: nothing to commit -- try adding some packages" >&2 - return 1 - end + for name in (string replace --filter --regex -- '.+/completions/([^/]+)\.fish$' '$1' $$plugin_files_var) + complete --erase --command $name + end - set -l out_pkgs - if test "$cmd" = "rm" - set out_pkgs $next_pkgs - else - for pkg in $next_pkgs - if contains -- (echo $pkg | command sed "s|@.*||") $actual_pkgs - set out_pkgs $out_pkgs $pkg + set --erase $plugin_files_var + end end - end - end - printf "%s\n" (_fisher_fmt <$fishfile | _fisher_parse -W $cmd $out_pkgs | command sed "s|^$HOME|~|") >$fishfile + if set --query update_plugins[1] || set --query install_plugins[1] + command mkdir -p $fisher_path/{functions,themes,conf.d,completions} + end - _fisher_complete + for plugin in $update_plugins $install_plugins + set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] + set --local files $source/{functions,themes,conf.d,completions}/* - command awk -v A=(count $actual_pkgs) -v U=(count $updated_pkgs) -v O=(count $old_pkgs) -v E=(_fisher_now $elapsed) ' - BEGIN { - res = fmt("removed", O - U, fmt("updated", U, fmt("added", A - U))) - printf((res ? res : "done") " in %.2fs\n", E / 1000) - } - function fmt(action, n, s) { - return n ? (s ? s ", " : s) action " " n " package" (n > 1 ? "s" : "") : s - } - ' >&2 -end + if set --local index (contains --index -- $plugin $install_plugins) + set --local user_files $fisher_path/{functions,themes,conf.d,completions}/* + set --local conflict_files -function _fisher_parse -a mode cmd - set -e argv[1..2] - command awk -v FS="[[:space:]]*#+" -v MODE="$mode" -v CMD="$cmd" -v ARGSTR="$argv" ' - BEGIN { - for (n = split(ARGSTR, a, " "); i++ < n;) pkgs[getkey(a[i])] = a[i] - } - !NF { next } { k = getkey($1) } - MODE == "-R" && !(k in pkgs) && ($0 = $1) - MODE == "-W" && (/^#/ || k in pkgs || CMD != "rm") { print pkgs[k] (sub($1, "") ? $0 : "") } - MODE == "-W" || CMD == "rm" { delete pkgs[k] } - END { - for (k in pkgs) { - if (CMD != "rm" || MODE == "-W") print pkgs[k] - else print "fisher: cannot remove \""k"\" -- package is not in fishfile" > "/dev/stderr" - } - } - function getkey(s, a) { - return (split(s, a, /@+|:/) > 2) ? a[2]"/"a[1]"/"a[3] : a[1] - } - ' -end + for file in (string replace -- $source/ $fisher_path/ $files) + contains -- $file $user_files && set --append conflict_files $file + end -function _fisher_fetch - set -l pkg_jobs - set -l out_pkgs - set -l next_pkgs - set -l local_pkgs - set -q fisher_user_api_token; and set -l curl_opts -u $fisher_user_api_token - - for pkg in $argv - switch $pkg - case \~\* /\* - set -l path (echo "$pkg" | command sed "s|^~|$HOME|") - if test -e "$path" - set local_pkgs $local_pkgs $path - else - echo "fisher: cannot add \"$pkg\" -- is this a valid file?" >&2 + if set --query conflict_files[1] && set --erase install_plugins[$index] + echo -s "fisher: Cannot install \"$plugin\": please remove or move conflicting files first:" \n" "$conflict_files >&2 + continue + end end - continue - end - command awk -v PKG="$pkg" -v FS=/ ' - BEGIN { - split(PKG, tmp, /@/) - pkg = split(PKG, _, "/") <= 2 ? "github.com/"tmp[1] : tmp[1] - print pkg "\t" url(pkg, (tmp[2] ? tmp[2] : "main")) "\t" (tmp[2] ? "" : url(pkg, "master")) - } - function url(pkg, tag) { - return \ - pkg ~ /^github/ ? "https://codeload."pkg"/tar.gz/"tag : \ - pkg ~ /^gitlab/ ? "https://"pkg"/-/archive/"tag"/"tmp[split(pkg, tmp, "/")]"-"tag".tar.gz" : \ - pkg ~ /^bitbucket/ ? "https://"pkg"/get/"tag".tar.gz" : pkg - } - ' | read -l pkg url url_fallback - - if test ! -d "$fisher_data/$pkg" - fish -c " - echo fetching $url >&2 - command mkdir -p $fisher_data/$pkg $fisher_cache/(command dirname $pkg) - if command curl $curl_opts -Ss -w \"\" $url 2>&1 | command tar -xzf- -C $fisher_data/$pkg 2>/dev/null - or begin - test ! -z \"$url_fallback\" - and echo fallback $url_fallback >&2 - and command curl $curl_opts -Ss -w \"\" $url_fallback 2>&1 | command tar -xzf- -C $fisher_data/$pkg 2>/dev/null - end - command rm -Rf $fisher_cache/$pkg - command mv -f $fisher_data/$pkg/* $fisher_cache/$pkg - command rm -Rf $fisher_data/$pkg - command cp -Rf {$fisher_cache,$fisher_data}/$pkg - else if test -d \"$fisher_cache/$pkg\" - echo fisher: cannot connect to server -- looking in \"$fisher_cache/$pkg\" | command sed 's|$HOME|~|' >&2 - command cp -Rf $fisher_cache/$pkg $fisher_data/$pkg/.. - else - command rm -Rf $fisher_data/$pkg - echo fisher: cannot add \"$pkg\" -- is this a valid package\? >&2 + for file in (string replace -- $source/ "" $files) + command cp -RLf $source/$file $fisher_path/$file end - " >/dev/null & - set pkg_jobs $pkg_jobs (_fisher_jobs --last) - set next_pkgs $next_pkgs "$fisher_data/$pkg" - end - end - if set -q pkg_jobs[1] - while for job in $pkg_jobs - contains -- $job (_fisher_jobs); and break - end - end - for pkg in $next_pkgs - if test -d "$pkg" - set out_pkgs $out_pkgs $pkg - _fisher_add $pkg - end - end - end + set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files - set -l local_prefix $fisher_data/local/$USER - if test ! -d "$local_prefix" - command mkdir -p $local_prefix - end - for pkg in $local_pkgs - set -l target $local_prefix/(command basename $pkg) - if test ! -L "$target" - command ln -sf $pkg $target - set out_pkgs $out_pkgs $pkg - _fisher_add $pkg --link - end - end + set --query files[1] && set --universal $plugin_files_var (string replace -- $source $fisher_path $files | string replace -- ~ \~) + + contains -- $plugin $_fisher_plugins || set --universal --append _fisher_plugins $plugin + contains -- $plugin $install_plugins && set --local event install || set --local event update + + printf "%s\n" Installing\ (set_color --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~ - if set -q out_pkgs[1] - _fisher_fetch ( - for pkg in $out_pkgs - if test -s "$pkg/fishfile" - _fisher_fmt <$pkg/fishfile | _fisher_parse -R + for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var | string replace -- \~ ~) + source $file + if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file) + emit {$name}_$event + end end - end) - printf "%s\n" $out_pkgs | _fisher_fmt - end -end + end -function _fisher_add -a pkg opts - for src in $pkg/{functions,completions,conf.d}/**.* $pkg/*.fish - set -l target (command basename $src) - switch $src - case $pkg/conf.d\* - set target $fisher_path/conf.d/$target - case $pkg/completions\* - set target $fisher_path/completions/$target - case $pkg/{functions,}\* - switch $target - case uninstall.fish - continue - case {init,key_bindings}.fish - set target $fisher_path/conf.d/(command basename $pkg)\_$target - case \* - set target $fisher_path/functions/$target + command rm -rf $source_plugins + + if set --query _fisher_plugins[1] + set --local commit_plugins + + for plugin in $file_plugins + contains -- (string lower -- $plugin) (string lower -- $_fisher_plugins) && set --append commit_plugins $plugin end - end - echo "linking $target" | command sed "s|$HOME|~|" >&2 - if set -q opts[1] - command ln -sf $src $target - else - command cp -f $src $target - end - switch $target - case \*.fish - source $target >/dev/null 2>/dev/null - end - end -end -function _fisher_rm -a pkg - for src in $pkg/{conf.d,completions,functions}/**.* $pkg/*.fish - set -l target (command basename $src) - set -l filename (command basename $target .fish) - switch $src - case $pkg/conf.d\* - test "$filename.fish" = "$target"; and emit "$filename"_uninstall - set target conf.d/$target - case $pkg/completions\* - test "$filename.fish" = "$target"; and complete -ec $filename - set target completions/$target - case $pkg/{,functions}\* - test "$filename.fish" = "$target"; and functions -e $filename - switch $target - case uninstall.fish - source $src - continue - case {init,key_bindings}.fish - set target conf.d/(command basename $pkg)\_$target - case \* - set target functions/$target + for plugin in $_fisher_plugins + contains -- (string lower -- $plugin) (string lower -- $commit_plugins) || set --append commit_plugins $plugin end - end - command rm -f $fisher_path/$target - end - if not functions -q fish_prompt - source "$__fish_datadir$__fish_data_dir/functions/fish_prompt.fish" - end -end -function _fisher_jobs - jobs $argv | command awk '/^[0-9]+\t/ { print $1 }' -end + printf "%s\n" $commit_plugins >$fish_plugins + else + set --erase _fisher_plugins + command rm -f $fish_plugins + end -function _fisher_now -a elapsed - switch (command uname) - case Darwin \*BSD - command perl -MTime::HiRes -e 'printf("%.0f\n", (Time::HiRes::time() * 1000) - $ARGV[0])' $elapsed + set --local total (count $install_plugins) (count $update_plugins) (count $remove_plugins) + + test "$total" != "0 0 0" && echo (string join ", " ( + test $total[1] = 0 || echo "Installed $total[1]") ( + test $total[2] = 0 || echo "Updated $total[2]") ( + test $total[3] = 0 || echo "Removed $total[3]") + ) plugin/s case \* - math (command date "+%s%3N") - "0$elapsed" + echo "fisher: Unknown command: \"$cmd\"" >&2 && return 1 + end +end + +if ! set --query _fisher_upgraded_to_4_4 + set --universal _fisher_upgraded_to_4_4 + if functions --query _fisher_list + set --query XDG_DATA_HOME[1] || set --local XDG_DATA_HOME ~/.local/share + command rm -rf $XDG_DATA_HOME/fisher + functions --erase _fisher_{list,plugin_parse} + fisher update >/dev/null 2>/dev/null + else + for var in (set --names | string match --entire --regex '^_fisher_.+_files$') + set $var (string replace -- ~ \~ $$var) + end + functions --erase _fisher_fish_postexec end end diff --git a/.config/fish/functions/peco_kill.fish b/.config/fish/functions/peco_kill.fish old mode 100755 new mode 100644 diff --git a/.config/fish/functions/peco_select_history.fish b/.config/fish/functions/peco_select_history.fish old mode 100755 new mode 100644