Skip to content

Commit d05f406

Browse files
author
Giles Westwood
committed
merge some updates from core project
1 parent 00e05ab commit d05f406

File tree

4 files changed

+153
-50
lines changed

4 files changed

+153
-50
lines changed

asdf/completions/asdf.fish

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,106 +31,111 @@ function __fish_asdf_arg_at -a number
3131
end
3232

3333
function __fish_asdf_list_versions -a plugin
34-
asdf list $plugin 2> /dev/null | sed -e 's/^[[:space:]]*//'
34+
asdf list $plugin 2>/dev/null | string trim | string trim --left --chars '*'
3535
end
3636

3737
function __fish_asdf_list_all -a plugin
38-
asdf list-all $plugin 2> /dev/null
38+
asdf list-all $plugin 2>/dev/null
3939
end
4040

4141
function __fish_asdf_plugin_list
42-
asdf plugin-list 2> /dev/null
42+
asdf plugin-list 2>/dev/null
4343
end
4444

4545
function __fish_asdf_plugin_list_all
46-
asdf plugin-list-all 2> /dev/null
46+
asdf plugin-list-all 2>/dev/null
4747
end
4848

4949
function __fish_asdf_list_shims
50-
ls $asdf_data_dir/shims
50+
path basename $asdf_data_dir/shims/*
5151
end
5252

5353
# update
54-
complete -f -c asdf -n '__fish_asdf_needs_command' -a update -d "Update asdf"
55-
complete -f -c asdf -n '__fish_asdf_using_command update; and __fish_asdf_arg_number 2' -l "head" -d "Updates to master HEAD"
54+
complete -f -c asdf -n __fish_asdf_needs_command -a update -d "Update asdf"
55+
complete -f -c asdf -n '__fish_asdf_using_command update; and __fish_asdf_arg_number 2' -l head -d "Updates to master HEAD"
5656

5757
# plugin-add completion
58-
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-add -d "Add git repo as plugin"
58+
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-add -d "Add git repo as plugin"
5959
complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list_all | grep -v \'*\' | awk \'{ print $1 }\')'
6060
complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 3' -a '(__fish_asdf_plugin_list_all | grep (__fish_asdf_arg_at 3) | awk \'{ print $2 }\')'
6161
complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 4'
6262

6363
# plugin-list completion
64-
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list -d "List installed plugins"
64+
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-list -d "List installed plugins"
6565

6666
# plugin-list-all completion
67-
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list-all -d "List all existing plugins"
67+
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-list-all -d "List all existing plugins"
6868

6969
# plugin-remove completion
70-
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-remove -d "Remove plugin and package versions"
70+
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-remove -d "Remove plugin and package versions"
7171
complete -f -c asdf -n '__fish_asdf_using_command plugin-remove; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
7272

7373
# plugin-update completion
74-
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-update -d "Update plugin"
74+
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-update -d "Update plugin"
7575
complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
7676
complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a --all
7777

7878
# install completion
79-
complete -f -c asdf -n '__fish_asdf_needs_command' -a install -d "Install a specific version of a package"
79+
complete -f -c asdf -n __fish_asdf_needs_command -a install -d "Install a specific version of a package"
8080
complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
8181
complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_all (__fish_asdf_arg_at 3))'
8282

8383
# uninstall completion
84-
complete -f -c asdf -n '__fish_asdf_needs_command' -a uninstall -d "Remove a specific version of a package"
84+
complete -f -c asdf -n __fish_asdf_needs_command -a uninstall -d "Remove a specific version of a package"
8585
complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
8686
complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
8787

8888
# current completion
89-
complete -f -c asdf -n '__fish_asdf_needs_command' -a current -d "Display version set or being used for package"
89+
complete -f -c asdf -n __fish_asdf_needs_command -a current -d "Display version set or being used for package"
9090
complete -f -c asdf -n '__fish_asdf_using_command current; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
9191

9292
# where completion
93-
complete -f -c asdf -n '__fish_asdf_needs_command' -a where -d "Display install path for an installed version"
93+
complete -f -c asdf -n __fish_asdf_needs_command -a where -d "Display install path for an installed version"
9494
complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
9595
complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
9696

9797
# which completion
98-
complete -f -c asdf -n '__fish_asdf_needs_command' -a which -d "Display executable path for a command"
98+
complete -f -c asdf -n __fish_asdf_needs_command -a which -d "Display executable path for a command"
9999
complete -f -c asdf -n '__fish_asdf_using_command which; and __fish_asdf_arg_number 2' -a '(__fish_asdf_list_shims)'
100100

101101
# latest completion
102-
complete -f -c asdf -n '__fish_asdf_needs_command' -a latest -d "Show latest stable version of a package"
102+
complete -f -c asdf -n __fish_asdf_needs_command -a latest -d "Show latest stable version of a package"
103103
complete -f -c asdf -n '__fish_asdf_using_command latest; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
104+
complete -f -c asdf -n '__fish_asdf_using_command latest; and __fish_asdf_arg_number 2' -a --all
104105

105106
# list completion
106-
complete -f -c asdf -n '__fish_asdf_needs_command' -a list -d "List installed versions of a package"
107+
complete -f -c asdf -n __fish_asdf_needs_command -a list -d "List installed versions of a package"
107108
complete -f -c asdf -n '__fish_asdf_using_command list; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
108109

109110
# list-all completion
110-
complete -f -c asdf -n '__fish_asdf_needs_command' -a list-all -d "List all versions of a package"
111+
complete -f -c asdf -n __fish_asdf_needs_command -a list-all -d "List all versions of a package"
111112
complete -f -c asdf -n '__fish_asdf_using_command list-all; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
112113

113114
# reshim completion
114-
complete -f -c asdf -n '__fish_asdf_needs_command' -a reshim -d "Recreate shims for version of a package"
115+
complete -f -c asdf -n __fish_asdf_needs_command -a reshim -d "Recreate shims for version of a package"
115116
complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
116117
complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
117118

119+
# shim-versions completion
120+
complete -f -c asdf -n __fish_asdf_needs_command -a shim-versions -d "List the plugins and versions that provide a command"
121+
complete -f -c asdf -n '__fish_asdf_using_command shim-versions; and __fish_asdf_arg_number 2' -a '(__fish_asdf_list_shims)'
122+
118123
# local completion
119-
complete -f -c asdf -n '__fish_asdf_needs_command' -a local -d "Set local version for a plugin"
124+
complete -f -c asdf -n __fish_asdf_needs_command -a local -d "Set local version for a plugin"
120125
complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
121126
complete -f -c asdf -n '__fish_asdf_using_command local; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
122127

123128
# global completion
124-
complete -f -c asdf -n '__fish_asdf_needs_command' -a global -d "Set global version for a plugin"
129+
complete -f -c asdf -n __fish_asdf_needs_command -a global -d "Set global version for a plugin"
125130
complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
126131
complete -f -c asdf -n '__fish_asdf_using_command global; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
127132

128133
# shell completion
129-
complete -f -c asdf -n '__fish_asdf_needs_command' -a shell -d "Set version for a plugin in current shell session"
134+
complete -f -c asdf -n __fish_asdf_needs_command -a shell -d "Set version for a plugin in current shell session"
130135
complete -f -c asdf -n '__fish_asdf_using_command shell; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
131136
complete -f -c asdf -n '__fish_asdf_using_command shell; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
132137

133138
# misc
134-
complete -f -c asdf -n '__fish_asdf_needs_command' -l "help" -d "Displays help"
135-
complete -f -c asdf -n '__fish_asdf_needs_command' -a "info" -d "Print OS, Shell and ASDF debug information"
136-
complete -f -c asdf -n '__fish_asdf_needs_command' -l "version" -d "Displays asdf version"
139+
complete -f -c asdf -n __fish_asdf_needs_command -l help -d "Displays help"
140+
complete -f -c asdf -n __fish_asdf_needs_command -a info -d "Print OS, Shell and ASDF debug information"
141+
complete -f -c asdf -n __fish_asdf_needs_command -l version -d "Displays asdf version"

lib/asdf.sh

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ sk-asdf-python-venv-activate(){
7979

8080
_sk-asdf-python-test(){
8181
# readlink is need if were in a venv to link to the source python
82-
if python_current=$(grep -q asdf <<< sk-file-readlink $(which python) ) ;then
82+
if python_current=$(grep -q asdf <<< sk-readlink-f $(which python) ) ;then
8383
return 0
8484
else
8585
return 1
@@ -152,23 +152,29 @@ sk-asdf-install-tool-versions(){
152152
if [[ -r .tool-versions ]];then
153153

154154
while read -r line;do
155-
plugin='unset'
155+
156+
# start to filter commend or RUN xxx lines
157+
if $(echo "$line" | grep -q '#');then
158+
if echo "$line" | grep -q 'RUN';then
159+
run_line=$(echo "$line" | awk -F'# RUN ' '{print $2}')
160+
echo "running $run_line"
161+
eval $run_line
162+
continue
163+
else
164+
# skip comments
165+
continue
166+
fi
167+
fi
168+
156169
program=$(echo $line | awk '{print $1}')
157170
version=$(echo $line | awk '{print $2}')
158-
plugin=$(echo $line | awk '{print $3}')
159171
echo $program
160172
echo $version
161-
echo $plugin
162173

163-
if [[ $plugin = 'unset' ]];then
164-
echo "sk-asdf-install $program -p $program -v $version"
165-
sk-asdf-install "$program" -p "$program" -v "$version"
166-
else
167-
echo "sk-asdf-install $program -p $program -v $version -ug $plugin"
168-
sk-asdf-install "$program" -p "$program" -v "$version" -ug "$plugin"
169-
fi
170-
# skip comments and blank lines
171-
done < <(cat .tool-versions | grep -v '#' | grep -ve '^$' )
174+
echo "sk-asdf-install $program -p $program -v $version"
175+
sk-asdf-install "$program" -p "$program" -v "$version"
176+
# skip blank lines
177+
done < <(cat .tool-versions | grep -ve '^$' )
172178

173179
else
174180
echo "Missing .tool-versions file"
@@ -182,10 +188,14 @@ sk-asdf-uninstall-tool-versions(){
182188
if [[ -r .tool-versions ]];then
183189

184190
while read -r line;do
185-
program=$(echo $line | awk -F "=" '{print $1}')
186-
version=$(echo $line | awk -F "=" '{print $2}')
191+
192+
plugin='unset'
193+
program=$(echo $line | awk '{print $1}')
194+
version=$(echo $line | awk '{print $2}')
195+
plugin=$(echo $line | awk '{print $3}')
187196
echo $program
188197
echo $version
198+
echo $plugin
189199

190200
echo "asdf uninstall $program $version"
191201
asdf uninstall "$program" "$version"

0 commit comments

Comments
 (0)