From 01c1b052ca927a3bb5f4d36a0c6b44b8eaca485d Mon Sep 17 00:00:00 2001 From: Uttarayan Mondal Date: Mon, 21 Nov 2022 16:30:05 +0530 Subject: [PATCH] [fix] Remove some redundant stuff and add stuff for macos --- config/fish/completions/fisher.fish | 7 + config/fish/completions/mctl.fish | 3 - config/fish/completions/nvm.fish | 19 ++ config/fish/conf.d/00brew.fish | 14 ++ config/fish/conf.d/99-ports.fish | 3 + config/fish/conf.d/aliases.fish | 1 - config/fish/conf.d/android-ndk.fish | 3 - config/fish/conf.d/env.fish | 2 - config/fish/conf.d/fzf.fish | 2 + config/fish/conf.d/nvim.fish | 1 + config/fish/conf.d/nvm.fish | 28 +++ config/fish/config.fish | 21 +- config/fish/fish_plugins | 2 + config/fish/fish_variables | 35 ++- config/fish/functions/_nvm_index_update.fish | 16 ++ config/fish/functions/_nvm_list.fish | 11 + .../fish/functions/_nvm_version_activate.fish | 4 + .../functions/_nvm_version_deactivate.fish | 5 + config/fish/functions/android-ndk.fish | 0 config/fish/functions/fisher.fish | 212 ++++++++++++++++++ config/fish/functions/ga.fish | 13 ++ config/fish/functions/nvm.fish | 208 +++++++++++++++++ config/fish/functions/zls.fish | 1 + 23 files changed, 576 insertions(+), 35 deletions(-) create mode 100644 config/fish/completions/fisher.fish delete mode 100644 config/fish/completions/mctl.fish create mode 100644 config/fish/completions/nvm.fish create mode 100644 config/fish/conf.d/00brew.fish create mode 100644 config/fish/conf.d/99-ports.fish delete mode 100644 config/fish/conf.d/aliases.fish delete mode 100644 config/fish/conf.d/android-ndk.fish delete mode 100644 config/fish/conf.d/env.fish create mode 100644 config/fish/conf.d/fzf.fish create mode 100644 config/fish/conf.d/nvim.fish create mode 100644 config/fish/conf.d/nvm.fish create mode 100644 config/fish/fish_plugins create mode 100644 config/fish/functions/_nvm_index_update.fish create mode 100644 config/fish/functions/_nvm_list.fish create mode 100644 config/fish/functions/_nvm_version_activate.fish create mode 100644 config/fish/functions/_nvm_version_deactivate.fish delete mode 100644 config/fish/functions/android-ndk.fish create mode 100644 config/fish/functions/fisher.fish create mode 100644 config/fish/functions/ga.fish create mode 100644 config/fish/functions/nvm.fish create mode 100644 config/fish/functions/zls.fish diff --git a/config/fish/completions/fisher.fish b/config/fish/completions/fisher.fish new file mode 100644 index 00000000..6d23ce49 --- /dev/null +++ b/config/fish/completions/fisher.fish @@ -0,0 +1,7 @@ +complete --command fisher --exclusive --long help --description "Print help" +complete --command fisher --exclusive --long version --description "Print version" +complete --command fisher --exclusive --condition __fish_use_subcommand --arguments install --description "Install plugins" +complete --command fisher --exclusive --condition __fish_use_subcommand --arguments update --description "Update installed plugins" +complete --command fisher --exclusive --condition __fish_use_subcommand --arguments remove --description "Remove installed plugins" +complete --command fisher --exclusive --condition __fish_use_subcommand --arguments list --description "List installed plugins matching regex" +complete --command fisher --exclusive --condition "__fish_seen_subcommand_from update remove" --arguments "(fisher list)" diff --git a/config/fish/completions/mctl.fish b/config/fish/completions/mctl.fish deleted file mode 100644 index dde9b0b2..00000000 --- a/config/fish/completions/mctl.fish +++ /dev/null @@ -1,3 +0,0 @@ -complete -c mctl -n "__fish_use_subcommand" -s p -l player -d 'Specify the player' -r -f -a "both mpd mpris" -complete -c mctl -n "__fish_use_subcommand" -s h -l help -d 'Prints help information' -complete -c mctl -n "__fish_use_subcommand" -s V -l version -d 'Prints version information' diff --git a/config/fish/completions/nvm.fish b/config/fish/completions/nvm.fish new file mode 100644 index 00000000..e94e50c7 --- /dev/null +++ b/config/fish/completions/nvm.fish @@ -0,0 +1,19 @@ +complete --command nvm --exclusive --long version --description "Print version" +complete --command nvm --exclusive --long help --description "Print help" + +complete --command nvm --exclusive --condition __fish_use_subcommand --arguments install --description "Download and activate the specified Node version" +complete --command nvm --exclusive --condition __fish_use_subcommand --arguments use --description "Activate a version in the current shell" +complete --command nvm --exclusive --condition __fish_use_subcommand --arguments list --description "List installed versions" +complete --command nvm --exclusive --condition __fish_use_subcommand --arguments list-remote --description "List versions available to install matching optional regex" +complete --command nvm --exclusive --condition __fish_use_subcommand --arguments current --description "Print the currently-active version" +complete --command nvm --exclusive --condition "__fish_seen_subcommand_from install" --arguments "( + test -e $nvm_data && string split ' ' <$nvm_data/.index +)" +complete --command nvm --exclusive --condition "__fish_seen_subcommand_from use" --arguments "(_nvm_list | string split ' ')" +complete --command nvm --exclusive --condition __fish_use_subcommand --arguments uninstall --description "Uninstall a version" +complete --command nvm --exclusive --condition "__fish_seen_subcommand_from uninstall" --arguments "( + _nvm_list | string split ' ' | string replace system '' +)" +complete --command nvm --exclusive --condition "__fish_seen_subcommand_from use uninstall" --arguments "( + set --query nvm_default_version && echo default +)" diff --git a/config/fish/conf.d/00brew.fish b/config/fish/conf.d/00brew.fish new file mode 100644 index 00000000..ca066738 --- /dev/null +++ b/config/fish/conf.d/00brew.fish @@ -0,0 +1,14 @@ +if [ (uname) = "Darwin" ] + set arch (arch) + if [ "$arch" = "i386" ] + eval /usr/local/Caskroom/miniconda/base/bin/conda "shell.fish" "hook" $argv | source + /usr/local/bin/brew shellenv | source + export PATH="/usr/local/opt/llvm/bin:$PATH" + else + eval /opt/homebrew/Caskroom/miniconda/base/bin/conda "shell.fish" "hook" $argv | source + /opt/homebrew/bin/brew shellenv | source + export PATH="/opt/homebrew/opt/llvm/bin:$PATH" + end + + export XDG_CONFIG_HOME="/Users/fs0c131y/.config" +end diff --git a/config/fish/conf.d/99-ports.fish b/config/fish/conf.d/99-ports.fish new file mode 100644 index 00000000..b08aba0e --- /dev/null +++ b/config/fish/conf.d/99-ports.fish @@ -0,0 +1,3 @@ +if [ (uname) = "Darwin" ] + export PATH="/opt/local/bin:$PATH" +end diff --git a/config/fish/conf.d/aliases.fish b/config/fish/conf.d/aliases.fish deleted file mode 100644 index 5394bf83..00000000 --- a/config/fish/conf.d/aliases.fish +++ /dev/null @@ -1 +0,0 @@ -alias mbsync 'mbsync -c ~/.config/isync/config' diff --git a/config/fish/conf.d/android-ndk.fish b/config/fish/conf.d/android-ndk.fish deleted file mode 100644 index 8f2e5c69..00000000 --- a/config/fish/conf.d/android-ndk.fish +++ /dev/null @@ -1,3 +0,0 @@ -export PATH="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH" -export CC_aarch64_linux_android=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang -export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang diff --git a/config/fish/conf.d/env.fish b/config/fish/conf.d/env.fish deleted file mode 100644 index 95d103ab..00000000 --- a/config/fish/conf.d/env.fish +++ /dev/null @@ -1,2 +0,0 @@ -# GPG -export GPG_TTY=(tty) diff --git a/config/fish/conf.d/fzf.fish b/config/fish/conf.d/fzf.fish new file mode 100644 index 00000000..6100187a --- /dev/null +++ b/config/fish/conf.d/fzf.fish @@ -0,0 +1,2 @@ +# export FZF_DEFAULT_COMMAND="fd --type f --hidden --exclude .git" +export FZF_DEFAULT_COMMAND="fd --type f" diff --git a/config/fish/conf.d/nvim.fish b/config/fish/conf.d/nvim.fish new file mode 100644 index 00000000..2f9c223c --- /dev/null +++ b/config/fish/conf.d/nvim.fish @@ -0,0 +1 @@ +export EDITOR=nvim diff --git a/config/fish/conf.d/nvm.fish b/config/fish/conf.d/nvm.fish new file mode 100644 index 00000000..347c2bd7 --- /dev/null +++ b/config/fish/conf.d/nvm.fish @@ -0,0 +1,28 @@ +function _nvm_install --on-event nvm_install + set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share + set --universal nvm_data $XDG_DATA_HOME/nvm + set --query nvm_mirror || set --universal nvm_mirror https://nodejs.org/dist + + test ! -d $nvm_data && command mkdir -p $nvm_data + echo "Downloading the Node distribution index..." 2>/dev/null + _nvm_index_update $nvm_mirror $nvm_data/.index +end + +function _nvm_update --on-event nvm_update + set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share + set --universal nvm_data $XDG_DATA_HOME/nvm + set --query nvm_mirror || set --universal nvm_mirror https://nodejs.org/dist +end + +function _nvm_uninstall --on-event nvm_uninstall + command rm -rf $nvm_data + + set --query nvm_current_version && _nvm_version_deactivate $nvm_current_version + + set --names | string replace --filter --regex -- "^nvm" "set --erase nvm" | source + functions --erase (functions --all | string match --entire --regex -- "^_nvm_") +end + +if status is-interactive && set --query nvm_default_version && ! set --query nvm_current_version + nvm use $nvm_default_version >/dev/null +end diff --git a/config/fish/config.fish b/config/fish/config.fish index 28959683..e2345753 100644 --- a/config/fish/config.fish +++ b/config/fish/config.fish @@ -1,17 +1,10 @@ -function man - set oldIFS "$IFS" - set IFS "" - set page (/usr/bin/man $argv | col -b) - if ! [ -z "$page" ] - echo "$page" | nvim -R -c 'set ft=man nomod nolist' - - end - - set IFS "$oldIFS" +if status is-interactive + # Commands to run in interactive sessions can go here end +export BROWSER="open" +export DYLD_FALLBACK_LIBRARY_PATH="/Library/Developer/CommandLineTools/usr/lib" +# export DYLD_FALLBACK_LIBRARY_PATH="/Library/Developer/CommandLineTools/usr/lib" +# export FZF_DEFAULT_COMMAND="fd --type f --hidden --exclude .git" +export CARGO_TARGET_DIR="$HOME/.local/share/cargo-target" -function __fish_command_not_found_handler --on-event fish_command_not_found - echo "fish: Unknown command '$argv'" -end - -thefuck --alias | source diff --git a/config/fish/fish_plugins b/config/fish/fish_plugins new file mode 100644 index 00000000..9673b425 --- /dev/null +++ b/config/fish/fish_plugins @@ -0,0 +1,2 @@ +jorgebucaran/fisher +jorgebucaran/nvm.fish diff --git a/config/fish/fish_variables b/config/fish/fish_variables index 65a52684..78986877 100644 --- a/config/fish/fish_variables +++ b/config/fish/fish_variables @@ -1,23 +1,31 @@ # This file contains fish universal variable definitions. # VERSION: 3.0 -SETUVAR __fish_initialized:3100 -SETUVAR _fish_abbr_c:checkmail +SETUVAR AFTERSHOOT_LOG:desktop_rust_backend\x3dtrace +SETUVAR __fish_initialized:3400 SETUVAR _fish_abbr_cat:bat SETUVAR _fish_abbr_cd:z -SETUVAR _fish_abbr_g:git +SETUVAR _fish_abbr_find:gfind +SETUVAR _fish_abbr_gcv:git\x20commit\x20\x2dva +SETUVAR _fish_abbr_gp:git\x20push +SETUVAR _fish_abbr_gpr:git\x20pull\x20\x2d\x2drebase +SETUVAR _fish_abbr_j:joshuto +SETUVAR _fish_abbr_l1:exa\x20\x2d1 SETUVAR _fish_abbr_ll:exa\x20\x2dal SETUVAR _fish_abbr_ls:exa SETUVAR _fish_abbr_m:neomutt -SETUVAR _fish_abbr_n:notmuch -SETUVAR _fish_abbr_nb:newsboat -SETUVAR _fish_abbr_o:xdg\x2dopen -SETUVAR _fish_abbr_p:pacman +SETUVAR _fish_abbr_news:newsboat +SETUVAR _fish_abbr_o:open +SETUVAR _fish_abbr_reru:evcxr SETUVAR _fish_abbr_rpc:patch\x20\x2dp0\x20\x3c\x20\x7e/\x2elocal/share/console\x2ediff -SETUVAR _fish_abbr_s:source\x20venv/bin/activate\x2efish SETUVAR _fish_abbr_sl:exa -SETUVAR _fish_abbr_t:/home/fs0c131y/\x2econfig/tmux/start\x2dtmux +SETUVAR _fish_abbr_sss:sqlite3\x20\x7e/Library/Application\x5c\x20Support/com\x2eaftershoot\x2eaftershoot/database\x2esqlite\x20\x22SELECT +SETUVAR _fish_abbr_t:/Users/fs0c131y/\x2econfig/tmux/start\x2dtmux SETUVAR _fish_abbr_v:nvim -SETUVAR _fish_abbr_yay:paru +SETUVAR _fish_abbr_wget:curl\x20\x2dO +SETUVAR _fish_abbr_zc:fd\x20\x7c\x20xargs\x20zip +SETUVAR _fisher_jorgebucaran_2F_fisher_files:/Users/fs0c131y/\x2econfig/fish/functions/fisher\x2efish\x1e/Users/fs0c131y/\x2econfig/fish/completions/fisher\x2efish +SETUVAR _fisher_jorgebucaran_2F_nvm_2E_fish_files:/Users/fs0c131y/\x2econfig/fish/functions/_nvm_index_update\x2efish\x1e/Users/fs0c131y/\x2econfig/fish/functions/_nvm_list\x2efish\x1e/Users/fs0c131y/\x2econfig/fish/functions/_nvm_version_activate\x2efish\x1e/Users/fs0c131y/\x2econfig/fish/functions/_nvm_version_deactivate\x2efish\x1e/Users/fs0c131y/\x2econfig/fish/functions/nvm\x2efish\x1e/Users/fs0c131y/\x2econfig/fish/conf\x2ed/nvm\x2efish\x1e/Users/fs0c131y/\x2econfig/fish/completions/nvm\x2efish +SETUVAR _fisher_plugins:jorgebucaran/fisher\x1ejorgebucaran/nvm\x2efish SETUVAR fish_color_autosuggestion:555\x1ebrblack SETUVAR fish_color_cancel:\x2dr SETUVAR fish_color_command:005fd7 @@ -40,9 +48,12 @@ SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrbl SETUVAR fish_color_status:red SETUVAR fish_color_user:brgreen SETUVAR fish_color_valid_path:\x2d\x2dunderline -SETUVAR fish_greeting: SETUVAR fish_key_bindings:fish_default_key_bindings SETUVAR fish_pager_color_completion:\x1d SETUVAR fish_pager_color_description:B3A06D\x1eyellow -SETUVAR fish_pager_color_prefix:white\x1e\x2d\x2dbold\x1e\x2d\x2dunderline +SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan +SETUVAR fish_pager_color_selected_background:\x2dr +SETUVAR fish_user_paths:/Users/fs0c131y/\x2ecargo/bin\x1e/Users/fs0c131y/\x2elocal/bin +SETUVAR nvm_data:/Users/fs0c131y/\x2elocal/share/nvm +SETUVAR nvm_mirror:https\x3a//nodejs\x2eorg/dist diff --git a/config/fish/functions/_nvm_index_update.fish b/config/fish/functions/_nvm_index_update.fish new file mode 100644 index 00000000..0ba33058 --- /dev/null +++ b/config/fish/functions/_nvm_index_update.fish @@ -0,0 +1,16 @@ +function _nvm_index_update --argument-names mirror index + if not command curl --location --silent $mirror/index.tab >$index.temp + command rm -f $index.temp + echo "nvm: Can't update index, host unavailable: \"$mirror\"" >&2 + return 1 + end + + command awk -v OFS=\t ' + /v0.9.12/ { exit } # Unsupported + NR > 1 { + print $1 (NR == 2 ? " latest" : $10 != "-" ? " lts/" tolower($10) : "") + } + ' $index.temp >$index + + command rm -f $index.temp +end diff --git a/config/fish/functions/_nvm_list.fish b/config/fish/functions/_nvm_list.fish new file mode 100644 index 00000000..fb5ab0ed --- /dev/null +++ b/config/fish/functions/_nvm_list.fish @@ -0,0 +1,11 @@ +function _nvm_list + set --local versions $nvm_data/* + set --query versions[1] && + string match --entire --regex -- (string match --regex -- "v\d.+" $versions | + string escape --style=regex | + string join "|" + ) <$nvm_data/.index + + command --all node | + string match --quiet --invert --regex -- "^$nvm_data" && echo system +end diff --git a/config/fish/functions/_nvm_version_activate.fish b/config/fish/functions/_nvm_version_activate.fish new file mode 100644 index 00000000..b2aee92a --- /dev/null +++ b/config/fish/functions/_nvm_version_activate.fish @@ -0,0 +1,4 @@ +function _nvm_version_activate --argument-names v + set --global --export nvm_current_version $v + set --prepend PATH $nvm_data/$v/bin +end diff --git a/config/fish/functions/_nvm_version_deactivate.fish b/config/fish/functions/_nvm_version_deactivate.fish new file mode 100644 index 00000000..540f6974 --- /dev/null +++ b/config/fish/functions/_nvm_version_deactivate.fish @@ -0,0 +1,5 @@ +function _nvm_version_deactivate --argument-names v + test "$nvm_current_version" = "$v" && set --erase nvm_current_version + set --local index (contains --index -- $nvm_data/$v/bin $PATH) && + set --erase PATH[$index] +end diff --git a/config/fish/functions/android-ndk.fish b/config/fish/functions/android-ndk.fish deleted file mode 100644 index e69de29b..00000000 diff --git a/config/fish/functions/fisher.fish b/config/fish/functions/fisher.fish new file mode 100644 index 00000000..64074798 --- /dev/null +++ b/config/fish/functions/fisher.fish @@ -0,0 +1,212 @@ +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.3.1 + set --local fish_plugins $__fish_config_dir/fish_plugins + + 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 or --version Print version" + echo " -h or --help Print this help message" + echo "Variables:" + echo " \$fisher_path Plugin installation path. Default: ~/.config/fish" + 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 + + if ! set --query argv[2] + if test "$cmd" != update + echo "fisher: Not enough arguments for command: \"$cmd\"" >&2 && return 1 + else if test ! -e $fish_plugins + echo "fisher: \"$fish_plugins\" file not found: \"$cmd\"" >&2 && return 1 + end + set arg_plugins (string match --regex -- '^[^\s]+$' <$fish_plugins) + end + + for plugin in $arg_plugins + test -e "$plugin" && set plugin (realpath $plugin) + contains -- "$plugin" $new_plugins || set --append new_plugins $plugin + end + + 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 plugin in $old_plugins + contains -- "$plugin" $new_plugins || set --append remove_plugins $plugin + end + end + + set --local pid_list + set --local source_plugins + set --local fetch_plugins $update_plugins $install_plugins + echo (set_color --bold)fisher $cmd version $fisher_version(set_color normal) + + for plugin in $fetch_plugins + set --local source (command mktemp -d) + set --append source_plugins $source + + command mkdir -p $source/{completions,conf.d,functions} + + fish --command " + if test -e $plugin + command cp -Rf $plugin/* $source + else + set temp (command mktemp -d) + set name (string split \@ $plugin) || set name[2] HEAD + set url https://api.github.com/repos/\$name[1]/tarball/\$name[2] + set header 'Accept: application/vnd.github.v3+json' + + echo Fetching (set_color --underline)\$url(set_color normal) + + if curl --silent -L -H \$header \$url | 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 + command rm -rf \$temp + end + + set files $source/* && string match --quiet --regex -- .+\.fish\\\$ \$files + " & + + set --append pid_list (jobs --last --pid) + end + + wait $pid_list 2>/dev/null + + 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 + + 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 + + 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 + end + + command rm -rf $$plugin_files_var + functions --erase (string replace --filter --regex -- '.+/functions/([^/]+)\.fish$' '$1' $$plugin_files_var) + + for name in (string replace --filter --regex -- '.+/completions/([^/]+)\.fish$' '$1' $$plugin_files_var) + complete --erase --command $name + end + + set --erase _fisher_plugins[$index] + set --erase $plugin_files_var + end + end + + if set --query update_plugins[1] || set --query install_plugins[1] + command mkdir -p $fisher_path/{functions,conf.d,completions} + end + + for plugin in $update_plugins $install_plugins + set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] + set --local files $source/{functions,conf.d,completions}/* + + if set --local index (contains --index -- $plugin $install_plugins) + set --local user_files $fisher_path/{functions,conf.d,completions}/* + set --local conflict_files + + for file in (string replace -- $source/ $fisher_path/ $files) + contains -- $file $user_files && set --append conflict_files $file + end + + 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 + + for file in (string replace -- $source/ "" $files) + command cp -Rf $source/$file $fisher_path/$file + end + + set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files + set --query files[1] && set --universal $plugin_files_var (string replace -- $source $fisher_path $files) + + 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 + + for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var) + source $file + if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file) + emit {$name}_$event + end + end + end + + command rm -rf $source_plugins + + set --query _fisher_plugins[1] || set --erase _fisher_plugins + set --query _fisher_plugins && + printf "%s\n" $_fisher_plugins >$fish_plugins || + command rm -f $fish_plugins + + 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 \* + echo "fisher: Unknown command: \"$cmd\"" >&2 && return 1 + end +end + +## Migrations ## +function _fisher_fish_postexec --on-event fish_postexec + if functions --query _fisher_list + fisher update >/dev/null 2>/dev/null + set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share + test -e $XDG_DATA_HOME/fisher && command rm -rf $XDG_DATA_HOME/fisher + functions --erase _fisher_list _fisher_plugin_parse + set --erase fisher_data + end + functions --erase _fisher_fish_postexec +end diff --git a/config/fish/functions/ga.fish b/config/fish/functions/ga.fish new file mode 100644 index 00000000..e11f9319 --- /dev/null +++ b/config/fish/functions/ga.fish @@ -0,0 +1,13 @@ +function ga --argument-names source target --description "Check how much ahead a git branch is from another" + if test -z "$source" + echo "Usage: ga source target" + return 1 + end + if test -z "$target" + set target (git rev-parse --abbrev-ref HEAD) + end + echo "$source"\t"$target" + git rev-list --left-right --count "$source"..."$target" +end + + diff --git a/config/fish/functions/nvm.fish b/config/fish/functions/nvm.fish new file mode 100644 index 00000000..77ec62eb --- /dev/null +++ b/config/fish/functions/nvm.fish @@ -0,0 +1,208 @@ +function nvm --argument-names cmd v --description "Node version manager" + if test -z "$v" && contains -- "$cmd" install use + for file in .nvmrc .node-version + set file (_nvm_find_up $PWD $file) && read v <$file && break + end + if test -z "$v" + echo "nvm: Invalid version or missing \".nvmrc\" file" >&2 + return 1 + end + end + + set --local their_version $v + + switch "$cmd" + case -v --version + echo "nvm, version 2.2.7" + case "" -h --help + echo "Usage: nvm install Download and activate the specified Node version" + echo " nvm install Install version from nearest .nvmrc file" + echo " nvm use Activate a version in the current shell" + echo " nvm use Activate version from nearest .nvmrc file" + echo " nvm list List installed versions" + echo " nvm list-remote List versions available to install" + echo " nvm list-remote List versions matching a given regular expression" + echo " nvm current Print the currently-active version" + echo " nvm uninstall Uninstall a version" + echo "Options:" + echo " -v or --version Print version" + echo " -h or --help Print this help message" + echo "Variables:" + echo " nvm_arch Override architecture, e.g. x64-musl" + echo " nvm_mirror Set the Node download mirror" + echo " nvm_default_version Set the default version for new shells" + case install + _nvm_index_update $nvm_mirror $nvm_data/.index || return + + string match --entire --regex -- (_nvm_version_match $v) <$nvm_data/.index | read v alias + + if ! set --query v[1] + echo "nvm: Invalid version number or alias: \"$their_version\"" >&2 + return 1 + end + + if test ! -e $nvm_data/$v + set --local os (command uname -s | string lower) + set --local ext tar.gz + set --local arch (command uname -m) + + switch $os + case aix + set arch ppc64 + case sunos + case linux + case darwin + case {MSYS_NT,MINGW\*_NT}\* + set os win + set ext zip + case \* + echo "nvm: Unsupported operating system: \"$os\"" >&2 + return 1 + end + + switch $arch + case i\*86 + set arch x86 + case x86_64 + set arch x64 + case arm64 + string match --regex --quiet "v(?\d+)" $v + if test "$os" = darwin -a $major -lt 16 + set arch x64 + end + case armv6 armv6l + set arch armv6l + case armv7 armv7l + set arch armv7l + case armv8 armv8l aarch64 + set arch arm64 + end + + set --query nvm_arch && set arch $nvm_arch + + set --local dir "node-$v-$os-$arch" + set --local url $nvm_mirror/$v/$dir.$ext + + command mkdir -p $nvm_data/$v + + echo -e "Installing Node \x1b[1m$v\x1b[22m $alias" + echo -e "Fetching \x1b[4m$url\x1b[24m\x1b[7m" + + if ! command curl --progress-bar --location $url \ + | command tar --extract --gzip --directory $nvm_data/$v 2>/dev/null + command rm -rf $nvm_data/$v + echo -e "\033[F\33[2K\x1b[0mnvm: Invalid mirror or host unavailable: \"$url\"" >&2 + return 1 + end + + echo -en "\033[F\33[2K\x1b[0m" + + if test "$os" = win + command mv $nvm_data/$v/$dir $nvm_data/$v/bin + else + command mv $nvm_data/$v/$dir/* $nvm_data/$v + command rm -rf $nvm_data/$v/$dir + end + end + + if test $v != "$nvm_current_version" + set --query nvm_current_version && _nvm_version_deactivate $nvm_current_version + _nvm_version_activate $v + end + + printf "Now using Node %s (npm %s) %s\n" (_nvm_node_info) + case use + test $v = default && set v $nvm_default_version + _nvm_list | string match --entire --regex -- (_nvm_version_match $v) | read v __ + + if ! set --query v[1] + echo "nvm: Can't use Node \"$their_version\", version must be installed first" >&2 + return 1 + end + + if test $v != "$nvm_current_version" + set --query nvm_current_version && _nvm_version_deactivate $nvm_current_version + test $v != system && _nvm_version_activate $v + end + + printf "Now using Node %s (npm %s) %s\n" (_nvm_node_info) + case uninstall + if test -z "$v" + echo "nvm: Not enough arguments for command: \"$cmd\"" >&2 + return 1 + end + + test $v = default && test ! -z "$nvm_default_version" && set v $nvm_default_version + + _nvm_list | string match --entire --regex -- (_nvm_version_match $v) | read v __ + + if ! set -q v[1] + echo "nvm: Node version not installed or invalid: \"$their_version\"" >&2 + return 1 + end + + printf "Uninstalling Node %s %s\n" $v (string replace ~ \~ "$nvm_data/$v/bin/node") + + _nvm_version_deactivate $v + + command rm -rf $nvm_data/$v + case current + _nvm_current + case ls list + _nvm_list | _nvm_list_format (_nvm_current) $argv[2] + case lsr {ls,list}-remote + _nvm_index_update $nvm_mirror $nvm_data/.index || return + _nvm_list | command awk ' + FILENAME == "-" && (is_local[$1] = FNR == NR) { next } { + print $0 (is_local[$1] ? " ✓" : "") + } + ' - $nvm_data/.index | _nvm_list_format (_nvm_current) $argv[2] + case \* + echo "nvm: Unknown command or option: \"$cmd\" (see nvm -h)" >&2 + return 1 + end +end + +function _nvm_find_up --argument-names path file + test -e "$path/$file" && echo $path/$file || begin + test "$path" != / || return + _nvm_find_up (command dirname $path) $file + end +end + +function _nvm_version_match --argument-names v + string replace --regex -- '^v?(\d+|\d+\.\d+)$' 'v$1.' $v | + string replace --filter --regex -- '^v?(\d+)' 'v$1' | + string escape --style=regex || + string lower '\b'$v'(?:/\w+)?$' +end + +function _nvm_list_format --argument-names current regex + command awk -v current="$current" -v regex="$regex" ' + $0 ~ regex { + aliases[versions[i++] = $1] = $2 " " $3 + pad = (n = length($1)) > pad ? n : pad + } + END { + if (!i) exit 1 + while (i--) + printf((current == versions[i] ? " ▶ " : " ") "%"pad"s %s\n", + versions[i], aliases[versions[i]]) + } + ' +end + +function _nvm_current + command --search --quiet node || return + set --query nvm_current_version && echo $nvm_current_version || echo system +end + +function _nvm_node_info + set --local npm_path (string replace bin/npm-cli.js "" (realpath (command --search npm))) + test -f $npm_path/package.json || set --local npm_version_default (command npm --version) + command node --eval " + console.log(process.version) + console.log('$npm_version_default' ? '$npm_version_default': require('$npm_path/package.json').version) + console.log(process.execPath.replace(require('os').homedir(), '~')) + " +end diff --git a/config/fish/functions/zls.fish b/config/fish/functions/zls.fish new file mode 100644 index 00000000..cbc1d703 --- /dev/null +++ b/config/fish/functions/zls.fish @@ -0,0 +1 @@ +function list_dir --on-variable PWD; ls -F; end;