Initial commit

This commit is contained in:
Andre Henriques 2023-05-19 08:36:32 +01:00
commit 6df5717c67
15 changed files with 634 additions and 0 deletions

149
completions/bun.fish Normal file
View File

@ -0,0 +1,149 @@
# This is terribly complicated
# It's because:
# 1. bun run has to have dynamic completions
# 2. there are global options
# 3. bun {install add remove} gets special options
# 4. I don't know how to write fish completions well
# Contributions very welcome!!
function __fish__get_bun_bins
string split ' ' (bun getcompletes b)
end
function __fish__get_bun_scripts
set -lx SHELL bash
set -lx MAX_DESCRIPTION_LEN 40
string trim (string split '\n' (string split '\t' (bun getcompletes z)))
end
function __fish__get_bun_packages
if test (commandline -ct) != ""
set -lx SHELL fish
string split ' ' (bun getcompletes a (commandline -ct))
end
end
function __history_completions
set -l tokens (commandline --current-process --tokenize)
history --prefix (commandline) | string replace -r \^$tokens[1]\\s\* "" | string replace -r \^$tokens[2]\\s\* "" | string split ' '
end
function __fish__get_bun_bun_js_files
string split ' ' (bun getcompletes j)
end
function bun_fish_is_nth_token --description 'Test if current token is on Nth place' --argument-names n
set -l tokens (commandline -poc)
set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens)
test (count $tokens) -eq "$n"
end
function __bun_command_count --argument-names n
set -l cmds (commandline -poc)
test (count cmds) -eq "$n"
end
function __bun_last_cmd --argument-names n
set -l cmds (commandline -poc)
test "(cmds[-1])" = "$n"
end
set -l bun_install_boolean_flags yarn production optional development no-save dry-run force no-cache silent verbose global
set -l bun_install_boolean_flags_descriptions "Write a yarn.lock file (yarn v1)" "Don't install devDependencies" "Add dependency to optionalDependencies" "Add dependency to devDependencies" "Don't install devDependencies" "Don't install anything" "Always request the latest versions from the registry & reinstall all dependenices" "Ignore manifest cache entirely" "Don't output anything" "Excessively verbose logging" "Use global folder"
set -l bun_builtin_cmds dev create help bun upgrade discord run install remove add
set -l bun_builtin_cmds_without_run dev create help bun upgrade discord install remove add
set -l bun_builtin_cmds_without_bun dev create help upgrade run discord install remove add
set -l bun_builtin_cmds_without_create dev help bun upgrade discord run install remove add
set -l bun_builtin_cmds_without_install create dev help bun upgrade discord run remove add
set -l bun_builtin_cmds_without_remove create dev help bun upgrade discord run install add
set -l bun_builtin_cmds_without_add create dev help bun upgrade discord run remove install
set -l bun_builtin_cmds_without_pm create dev help bun upgrade discord run
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_run; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -a '(__fish__get_bun_scripts)' -d 'script'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_run; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from run" -a '(__fish__get_bun_bins)' -d 'package bin'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_run; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from run" -a '(__fish__get_bun_scripts)' -d 'script'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_run; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from run" -a '(__fish__get_bun_bun_js_files)' -d 'Bun.js'
complete -c bun \
-n "bun_fish_is_nth_token 1; and not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) and __fish_use_subcommand" -a 'run' -f -d 'Run a script or bin'
complete -c bun \
-n "not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) install remove add;" --no-files -s 'u' -l 'origin' -r -d 'Server URL. Rewrites import paths'
complete -c bun \
-n "not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) install remove add;" --no-files -s 'p' -l 'port' -r -d 'Port number to start server from'
complete -c bun \
-n "not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) install remove add;" --no-files -s 'd' -l 'define' -r -d 'Substitute K:V while parsing, e.g. --define process.env.NODE_ENV:\"development\"'
complete -c bun \
-n "not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) install remove add;" --no-files -s 'e' -l 'external' -r -d 'Exclude module from transpilation (can use * wildcards). ex: -e react'
complete -c bun \
-n "not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) install remove add;" --no-files -l 'use' -r -d 'Use a framework (ex: next)'
complete -c bun \
-n "bun_fish_is_nth_token 1; and not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) and __fish_use_subcommand" -a 'dev' -d 'Start dev server'
complete -c bun \
-n "bun_fish_is_nth_token 1; and not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) and __bun_command_count 1 and __fish_use_subcommand" -a 'create' -f -d 'Create a new project'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_create next react; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from create;" -a 'next' -d 'new Next.js project'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_create next react; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from create;" -a 'react' -d 'new React project'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -a 'upgrade' -d 'Upgrade bun to the latest version' -x
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -a '--help' -d 'See all commands and flags' -x
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -l "version" -s "v" -a '--version' -d 'bun\'s version' -x
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_use_subcommand" -a 'discord' -d 'Open bun\'s Discord server' -x
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_bun; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); __fish_use_subcommand" -a 'bun' -d 'Generate a new bundle'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_bun; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from bun" -F -d 'Bundle this'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_create; and not __fish_seen_subcommand_from (__fish__get_bun_bins); and not __fish_seen_subcommand_from (__fish__get_bun_scripts); and __fish_seen_subcommand_from react; or __fish_seen_subcommand_from next" -F -d "Create in directory"
complete -c bun \
-n "bun_fish_is_nth_token 1; and not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) and __bun_command_count 1 and __fish_use_subcommand" -a 'install' -f -d 'Install packages from package.json'
complete -c bun \
-n "bun_fish_is_nth_token 1; and not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) and __bun_command_count 1 and __fish_use_subcommand" -a 'add' -F -d 'Add a package to package.json'
complete -c bun \
-n "bun_fish_is_nth_token 1; and not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) and __bun_command_count 1 and __fish_use_subcommand" -a 'remove' -F -d 'Remove a package from package.json'
complete -c bun \
-n "bun_fish_is_nth_token 1; and not __fish_seen_subcommand_from $bun_builtin_cmds; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) and __bun_command_count 1 and __fish_use_subcommand add remove" -F
for i in (seq (count $bun_install_boolean_flags))
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_pm; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from install add remove;" -l "$bun_install_boolean_flags[$i]" -d "$bun_install_boolean_flags_descriptions[$i]"
end
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_pm; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from install add remove;" -l 'cwd' -d 'Change working directory'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_pm; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from install add remove;" -l 'cache-dir' -d 'Choose a cache directory (default: $HOME/.bun/install/cache)'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_pm; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from add;" -d 'Popular' -a '(__fish__get_bun_packages)'
complete -c bun \
-n "not __fish_seen_subcommand_from $bun_builtin_cmds_without_pm; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts); and __fish_seen_subcommand_from add;" -d 'History' -a '(__history_completions)'
complete -c bun --no-files

19
completions/nvm.fish Normal file
View File

@ -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
)"

2
conf.d/nix.fish Normal file
View File

@ -0,0 +1,2 @@
if test -e /home/andr3/.nix-profile/etc/profile.d/nix.fish; . /home/andr3/.nix-profile/etc/profile.d/nix.fish; end # added by Nix installer

28
conf.d/nvm.fish Normal file
View File

@ -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 for the first time..." 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
status is-interactive &&
set --query nvm_default_version && ! set --query nvm_current_version &&
nvm use $nvm_default_version >/dev/null

89
config.fish Normal file
View File

@ -0,0 +1,89 @@
set fish_greeting #supress fish_greeting
zoxide init fish | source
# pyenv init - | source
alias config='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
alias da='dragon-drop --and-exit'
alias dat='dragon-drop -t --and-exit'
alias dp='doas pacman'
alias p='pacman'
alias vim='nvim'
alias em="emacs -nw":
alias ls="exa"
alias ll="exa -al"
alias la="exa -a"
alias grep="grep --color=auto"
alias egrep="egrep --color=auto"
alias df="df -h"
alias du="du -h"
alias cat="bat"
function nem
nohup emacs $argv &> /tmp/nohup.em.out & disown
end
alias nemacs="nohup emacs"
alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:armv7-musleabihf'
#alias ledger="ledger -f $HOME/Documents/ledger/ledger.ledger"
set EDITOR "nvim"
set _JAVA_AWT_WM_NONREPARENTING "1"
set JAVA_HOME /usr/lib/jvm/java-8-openjdk
set XDG_CONFIG_HOME "$HOME/.config"
set -g FZF_DEFAULT_COMMAND 'rg --files --follow --ignore-vcs --hidden -g "!{node_modules/*,.git/*}"'
export FZF_DEFAULT_COMMAND='rg --files --follow --ignore-vcs --hidden -g "!{node_modules/*,.git/*}"'
export EDITOR="nvim"
#set -u LD_LIBRARY_PATH $LD_LIBRARY_PATH:"/home/andr3/.build/godot_openvr/demo/addons/godot-openvr/bin/x11/libgodot_openvr.so":"/home/andr3/.steam/steam/steamapps/common/SteamVR/bin/"
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"/home/andr3/.build/godot_openvr/demo/addons/godot-openvr/bin/x11/":"/home/andr3/.steam/steam/steamapps/common/SteamVR/bin/:/home/andr3/.build/tensor/TensorRT-8.5.2.2/lib/"
#export PATH=$PATH:$ANDROID_HOME/tools
#export PATH=$PATH:$ANDROID_HOME/tools/bin
#export PATH=$PATH:$ANDROID_HOME/platform-tools
export NIXPKGS_ALLOW_UNFREE=1
function ssh
if [ $TERM = "xterm-kitty" ]
kitty +kitten ssh $argv
else
/bin/ssh $argv
end
end
function configGit34
git config --local user.email "andr3h3nriqu3s@gmail.com"
git config --local user.name "agh"
end
function configGitOther
git config --local user.email "andr3h3nriqu3s@gmail.com"
git config --local user.name "Andre Henriques"
end
function configGitUni
git config --local user.email "ag01598@surrey.ac.uk"
git config --local user.name "Goncalves Henriques, Andre (UG - Computer Science)"
end
# grim and slurp
function sshot
grim -g "$(slurp)" - | wl-copy
end
source ~/.config/fish/completions/bun.fish
source ~/.config/fish/completions/nvm.fish
source ~/.config/fish/other.fish
# pnpm
set -gx PNPM_HOME "/home/andr3/.local/share/pnpm"
set -gx PATH "$PNPM_HOME" $PATH
# pnpm end
# tabtab source for packages
# uninstall by removing these lines
[ -f ~/.config/tabtab/fish/__tabtab.fish ]; and . ~/.config/tabtab/fish/__tabtab.fish; or true
# nix
alias nshell "nix-shell --run fish"

1
fish_plugins Normal file
View File

@ -0,0 +1 @@
jorgebucaran/nvm.fish

40
fish_variables Executable file
View File

@ -0,0 +1,40 @@
# This file contains fish universal variable definitions.
# VERSION: 3.0
SETUVAR --export PYENV_ROOT:/home/andr3/\x2epyenv
SETUVAR __fish_initialized:3400
SETUVAR _fisher_jorgebucaran_2F_nvm_2E_fish_files:\x7e/\x2econfig/fish/functions/_nvm_index_update\x2efish\x1e\x7e/\x2econfig/fish/functions/_nvm_list\x2efish\x1e\x7e/\x2econfig/fish/functions/_nvm_version_activate\x2efish\x1e\x7e/\x2econfig/fish/functions/_nvm_version_deactivate\x2efish\x1e\x7e/\x2econfig/fish/functions/nvm\x2efish\x1e\x7e/\x2econfig/fish/conf\x2ed/nvm\x2efish\x1e\x7e/\x2econfig/fish/completions/nvm\x2efish
SETUVAR _fisher_plugins:jorgebucaran/nvm\x2efish
SETUVAR _fisher_upgraded_to_4_4:\x1d
SETUVAR fish_color_autosuggestion:BD93F9
SETUVAR fish_color_cancel:\x2dr
SETUVAR fish_color_command:F8F8F2
SETUVAR fish_color_comment:6272A4
SETUVAR fish_color_cwd:green
SETUVAR fish_color_cwd_root:red
SETUVAR fish_color_end:50FA7B
SETUVAR fish_color_error:FFB86C
SETUVAR fish_color_escape:00a6b2
SETUVAR fish_color_history_current:\x2d\x2dbold
SETUVAR fish_color_host:normal
SETUVAR fish_color_host_remote:yellow
SETUVAR fish_color_match:\x2d\x2dbackground\x3dbrblue
SETUVAR fish_color_normal:normal
SETUVAR fish_color_operator:00a6b2
SETUVAR fish_color_param:FF79C6
SETUVAR fish_color_quote:F1FA8C
SETUVAR fish_color_redirection:8BE9FD
SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack
SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack
SETUVAR fish_color_status:red
SETUVAR fish_color_user:brgreen
SETUVAR fish_color_valid_path:\x2d\x2dunderline
SETUVAR fish_greeting:\x1d
SETUVAR fish_key_bindings:fish_default_key_bindings
SETUVAR fish_pager_color_completion:normal
SETUVAR fish_pager_color_description:B3A06D\x1eyellow
SETUVAR fish_pager_color_prefix:white\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:/opt/cuda/bin\x1e/home/andr3/\x2epyenv/bin\x1e/home/andr3/\x2enimble/bin\x1e/home/andr3/\x2elocal/bin\x1e/home/andr3/\x2ecargo/bin\x1e/home/andr3/\x2edeno/bin\x1e/home/andr3/scripts/\x3a/usr/local/sbin\x3a/usr/local/bin\x3a/usr/bin\x3a/usr/bin/site_perl\x3a/usr/bin/vendor_perl\x3a/usr/bin/core_perl
SETUVAR nvm_data:/home/andr3/\x2elocal/share/nvm
SETUVAR nvm_mirror:https\x3a//nodejs\x2eorg/dist

View File

@ -0,0 +1,12 @@
function _nvm_index_update --argument-names mirror index
command curl --location --silent $mirror/index.tab | command awk -v OFS=\t '
/v0.9.12/ { exit } # Unsupported
NR > 1 {
print $1 (NR == 2 ? " latest" : $10 != "-" ? " lts/" tolower($10) : "")
}
' >$index.temp 2>/dev/null && command mv $index.temp $index && return
command rm -f $index.temp
echo "nvm: Invalid index or unavailable host: \"$mirror\"" >&2
return 1
end

11
functions/_nvm_list.fish Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,23 @@
function fish_prompt --description 'Informative prompt'
#Save the return status of the previous command
set -l last_pipestatus $pipestatus
if test -n "$IN_NIX_SHELL"
printf "%s<nix-shell>%s " (set_color red) (set_color normal)
end
switch "$USER"
case root toor
printf '%s@%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
and set_color $fish_color_cwd_root
or set_color $fish_color_cwd) \
(prompt_pwd) (set_color normal)
case '*'
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) \
(set_color --bold $fish_color_status) $last_pipestatus)
printf '[%s] %s%s@%s %s\f\r%s%s%s > ' (date "+%H:%M:%S") (set_color brblue) \
$USER (prompt_hostname) $pipestatus_string \
(set_color $fish_color_cwd) (pwd | sed "s/^\/home\/$USER/~/") (set_color normal)
end
end

202
functions/nvm.fish Normal file
View File

@ -0,0 +1,202 @@
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
switch "$cmd"
case -v --version
echo "nvm, version 2.2.4"
case "" -h --help
echo "Usage: nvm install <version> Download and activate the specified Node version"
echo " nvm install Install version from nearest .nvmrc file"
echo " nvm use <version> 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 <regex> List versions matching a given regular expression"
echo " nvm current Print the currently-active version"
echo " nvm uninstall <version> Uninstall a version"
echo "Options:"
echo " -v or --version Print version"
echo " -h or --help Print this help message"
echo "Variables:"
echo " nvm_mirror Set mirror for Node binaries"
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: \"$argv[2..-1]\"" >&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
if test "$os" = darwin
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 --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: Node version not installed or invalid: \"$argv[2..-1]\"" >&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: \"$argv[2..-1]\"" >&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

40
functions/rvm.fish Normal file
View File

@ -0,0 +1,40 @@
function rvm --description='Ruby enVironment Manager'
# run RVM and capture the resulting environment
set --local env_file (mktemp -t rvm.fish.XXXXXXXXXX)
# This finds where RVM's root directory is and sources scripts/rvm from within it. Then loads RVM in a clean environment and dumps the environment variables it generates out for us to use.
bash -c 'PATH=$GEM_HOME/bin:$PATH;RVMA=$(which rvm);RVMB=$(whereis rvm | sed "s/rvm://");source $(if test $RVMA;then echo $RVMA | sed "s/\/bin\//\/scripts\//";elif test $RVMB; then echo $RVMB | sed "s/rvm/rvm\/scripts\/rvm/"; else echo ~/.rvm/scripts/rvm; fi); rvm "$@"; status=$?; env > "$0"; exit $status' $env_file $argv
# apply rvm_* and *PATH variables from the captured environment
and eval (grep -E '^rvm|^PATH|^GEM_PATH|^GEM_HOME' $env_file | grep -v '_clr=' | sed '/^[^=]*PATH/s/:/" "/g; s/^/set -xg /; s/=/ "/; s/$/" ;/; s/(//; s/)//')
# needed under fish >= 2.2.0
and set -xg GEM_PATH (echo $GEM_PATH | sed 's/ /:/g')
# clean up
rm -f $env_file
end
function __handle_rvmrc_stuff --on-variable PWD
# Source a .rvmrc file in a directory after changing to it, if it exists.
# To disable this feature, set rvm_project_rvmrc=0 in $HOME/.rvmrc
if test "$rvm_project_rvmrc" != 0
set -l cwd $PWD
while true
if contains $cwd "" $HOME "/"
if test "$rvm_project_rvmrc_default" = 1
rvm default 1>/dev/null 2>&1
end
break
else
if test -e .rvmrc -o -e .ruby-version -o -e .ruby-gemset -o -e Gemfile
eval "rvm reload" > /dev/null
eval "rvm rvmrc load" >/dev/null
break
else
set cwd (dirname "$cwd")
end
end
end
set -e cwd
end
end

9
other.fish Normal file
View File

@ -0,0 +1,9 @@
function nixshp
nix-shell --run "fish" -p $argv
end
alias n14="nixshp nodejs-slim_14 yarn"
alias n14dev="n14 --run 'pnpm dev'"
alias n19="nixshp nodejs-slim_19 yarn"
alias n19dev="n19 --run 'pnpm dev'"