ajout fisher et plugin sdk

main
Gil Portenseigne 2024-03-12 21:26:35 +01:00
parent d70626808a
commit 30162f283b
4 changed files with 354 additions and 2 deletions

View File

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

View File

@ -0,0 +1,243 @@
# Defines autocompletion for SDKMAN!
# Copyright (c) 2018-2023 Raphael Reitzig
# MIT License (MIT)
# https://github.com/reitzig/sdkman-for-fish
# Guard: SDKMAN! needs to be installed
if not test -f "$SDKMAN_DIR/bin/sdkman-init.sh"
exit 0
end
# # # # # #
# Completion trigger predicates
# # # # # #
# Test if there is no command
function __fish_sdkman_no_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 ]
return 0
end
return 1
end
# Test if the main command matches one of the parameters
function __fish_sdkman_using_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 2 ]
if contains $cmd[2] $argv
return 0
end
end
return 1
end
function __fish_sdkman_specifying_candidate
set cmd (commandline -opc)
if [ (count $cmd) -eq 3 ] # currently, sdk does not support multiple versions
if contains $cmd[2] $argv
return 0
end
end
return 1
end
function __fish_sdkman_command_has_enough_parameters
set cmd (commandline -opc)
if [ (count $cmd) -ge (math $argv[1] + 2) ]; and contains $cmd[2] $argv[2..-1]
return 0
end
return 1
end
# # # # # #
# Data collectors
# # # # # #
function __fish_sdkman_candidates
cat "$HOME"/.sdkman/var/candidates | tr ',' '\n'
end
function __fish_sdkman_candidates_with_versions
set regexpHome (string replace -a '/' '\\/' "$HOME/")
find "$HOME"/.sdkman/candidates/ -mindepth 2 -maxdepth 2 -name '*current' \
| awk -F '/' '{ print $(NF-1) }' \
| sort -u
end
function __fish_sdkman_installed_versions
set cmd (commandline -opc)
if [ -d "$HOME"/.sdkman/candidates/$cmd[3]/current ]
ls -v1 "$HOME"/.sdkman/candidates/$cmd[3] | grep -v current
end
end
# # # # # #
# Completion specification
# # # # # #
# install
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'i install' \
-d 'Install new version'
complete -c sdk -f -n '__fish_sdkman_using_command i install' \
-a "(__fish_sdkman_candidates)"
# TODO complete available versions --> issue #4
complete -c sdk -f -n '__fish_sdkman_specifying_candidate i install' \
-a 'a.b.c' \
-d "version list unavailable"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate i install' \
-a 'x.y.z' \
-d "Specify path to install custom version."
# Implicit: complete files as fourth parameter
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 3 i install'
# block
# uninstall
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'rm uninstall' -d 'Uninstall version'
complete -c sdk -f -n '__fish_sdkman_using_command rm uninstall' \
-a "(__fish_sdkman_candidates_with_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate rm uninstall' \
-a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 rm uninstall'
# block
# list
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'ls list' \
-d 'List versions'
complete -c sdk -f -n '__fish_sdkman_using_command ls list' \
-a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 ls list'
# block
# use
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'u use' \
-d 'Use specific version'
complete -c sdk -f -n '__fish_sdkman_using_command u use' \
-a "(__fish_sdkman_candidates_with_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate u use' \
-a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 u use'
# block
# default
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'd default' \
-d 'Set default version'
complete -c sdk -f -n '__fish_sdkman_using_command d default' \
-a "(__fish_sdkman_candidates_with_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate d default' \
-a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 d default'
# block
# current
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'c current' \
-d 'Display current version'
complete -c sdk -f -n '__fish_sdkman_using_command c current' \
-a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 c current'
# block
# upgrade
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'ug upgrade' \
-d 'Display what is outdated'
complete -c sdk -f -n '__fish_sdkman_using_command ug upgrade' \
-a "(__fish_sdkman_candidates_with_versions)"
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 ug upgrade'
# block
# version
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'v version' \
-d 'Display version'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 v version'
# block
# help
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'help' \
-d 'Display help message'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 h help'
# block
# offline
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'offline' \
-d 'Set offline status'
complete -c sdk -f -n '__fish_sdkman_using_command offline' \
-a 'enable' \
-d 'Make sdk work while offline'
complete -c sdk -f -n '__fish_sdkman_using_command offline' \
-a 'disable' \
-d 'Turn on all features'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 offline'
# block
# selfupdate
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'selfupdate' \
-d 'Update sdk'
complete -c sdk -f -n '__fish_sdkman_using_command selfupdate' \
-a 'force' \
-d 'Force re-install of current version'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 selfupdate'
# block
# update
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'update' \
-d 'Reload the candidate list'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 update'
# block
# flush
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'flush' \
-d 'Clear out archives and temporary storage folders'
complete -c sdk -f -n '__fish_sdkman_using_command flush' \
-a 'temp' \
-d 'Clear out staging work folder'
complete -c sdk -f -n '__fish_sdkman_using_command flush' \
-a 'version' \
-d 'Flush version file'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 flush'
# block
# env
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'e env' \
-d 'Load environment from .sdkmanrc file'
complete -c sdk -f -n '__fish_sdkman_using_command e env' \
-a 'init' \
-d 'Initialize .sdkmanrc file'
complete -c sdk -f -n '__fish_sdkman_using_command e env' \
-a 'install' \
-d 'Install all candidate versions listed in .sdkmanrc'
complete -c sdk -f -n '__fish_sdkman_using_command e env' \
-a 'clear' \
-d 'Unload currently loaded environment'
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 e env'
# block
# home
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'h home' \
-d 'Show installation folder of given candidate'
complete -c sdk -f -n '__fish_sdkman_using_command h home' \
-a "(__fish_sdkman_candidates_with_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate h home' \
-a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 h home'
# block

View File

@ -0,0 +1,104 @@
#!/usr/bin/fish
# Makes command and binaries from SDKMAN! available in fish.
# Delegates to bash for the `sdk` command.
# Copyright (c) 2018-2023 Raphael Reitzig
# MIT License (MIT)
# https://github.com/reitzig/sdkman-for-fish
# Account for custom install locations
if set -q __sdkman_custom_dir
set -gx SDKMAN_DIR "$__sdkman_custom_dir"
else
# This is the default location:
set -gx SDKMAN_DIR "$HOME/.sdkman"
end
set __fish_sdkman_init "$SDKMAN_DIR/bin/sdkman-init.sh"
# Copied from https://github.com/jorgebucaran/fisher/blob/main/functions/fisher.fish to be consistent:
set --query fisher_path || set --local fisher_path $__fish_config_dir
set __fish_sdkman_noexport_init "$fisher_path/functions/__sdkman-noexport-init.sh"
# Guard: SDKMAN! needs to be installed
if not test -f "$__fish_sdkman_init"
exit 0
end
# Hack for issue #19:
# Create version of sdkman-init that doesn't export any environment variables.
# Refresh if sdkman-init changed.
if begin not test -f "$__fish_sdkman_noexport_init";
or env test "$__fish_sdkman_init" -nt "$__fish_sdkman_noexport_init"
end
mkdir -p (dirname $__fish_sdkman_noexport_init)
sed -E -e 's/^(\s*).*(export|to_path).*$/\1:/g' "$__fish_sdkman_init" \
> "$__fish_sdkman_noexport_init"
end
# Runs the given command in bash, capturing some side effects
# and repeating them on the current fish shell.
# Returns the same status code as the given command.
function __fish_sdkman_run_in_bash
# We need to leave stdin and stdout of sdk free for user interaction.
# So, pipe relevant environment variables (which might have changed)
# through a file.
# But since now getting the exit code of sdk itself is a hassle,
# pipe it as well.
#
# TODO: Can somebody get this to work without the overhead of a file?
set pipe (mktemp)
bash -c "$argv[1];
echo -e \"\$?\" > $pipe;
env | grep -e '^SDKMAN_\|^PATH' >> $pipe;
env | grep -i -E \"^(`echo \${SDKMAN_CANDIDATES_CSV} | sed 's/,/|/g'`)_HOME\" >> $pipe;
echo \"SDKMAN_OFFLINE_MODE=\${SDKMAN_OFFLINE_MODE}\" >> $pipe;
echo \"SDKMAN_ENV=\${SDKMAN_ENV}\" >> $pipe" # it's not an environment variable!
set bashDump (cat $pipe; rm $pipe)
set sdkStatus $bashDump[1]
set bashEnv $bashDump[2..-1]
# If SDKMAN! succeeded, copy relevant environment variables
# to the current shell (they might have changed)
if [ $sdkStatus = 0 ]
for line in $bashEnv
set parts (string split "=" $line)
set var $parts[1]
set value (string join "=" $parts[2..-1])
switch "$var"
case "PATH"
# Special treatment: need fish list instead
# of colon-separated list.
set value (string split : "$value")
end
if test -n value
set -gx $var $value
# Note: This makes SDKMAN_{OFFLINE_MODE,ENV} environment variables.
# That gives it the behaviour we _want_!
end
end
end
return $sdkStatus
end
# If this is a subshell of a(n initialized) fish owned by the same user,
# no initialization necessary.
# Otherwise:
if not set -q SDKMAN_CANDIDATES_DIR; or test (ls -ld "$SDKMAN_CANDIDATES_DIR" | awk '{print $3}') != (whoami)
__fish_sdkman_run_in_bash "source $__fish_sdkman_init"
end
# Set up auto_env
if grep -q "^sdkman_auto_env=true" "$SDKMAN_DIR/etc/config"
function __fish_sdkman_autoenv --on-variable PWD
# Run the (modified) init script, which performs the checks and calls for us!
__fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\""
set -x SDKMAN_OLD_PWD "$PWD" # needed by the Bash implementation
end
end

View File

@ -1,5 +1,3 @@
if status is-interactive if status is-interactive
# Commands to run in interactive sessions can go here # Commands to run in interactive sessions can go here
end end
source .sdkman