Initial commit

This commit is contained in:
Raphael Reitzig 2018-07-11 02:37:43 +02:00
commit f6eaf49d1f
4 changed files with 192 additions and 0 deletions

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 Raphael Reitzig
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

26
README.md Normal file
View file

@ -0,0 +1,26 @@
# SDKMAN! for fish
Provides auto-completion for [SDKMAN!] and adds installed binaries to the PATH.
## Install
With [fisherman] (install separately):
```
fisher reitzig/sdkman-for-fish
```
## Usage
It's all in the background; you should be able to run `sdk` and binaries installed
with `sdk` as you would expect.
## Acknowledgements
* Completion originally by [Ted Wise](https://github.com/ctwise); see his
[blog post from 2016](http://tedwise.com/2016/02/26/using-sdkman-with-the-fish-shell).
* Binary loading by [Koala Yeung](https://github.com/yookoala);
see [his comment on sdkman/sdkman-cli#294](https://github.com/sdkman/sdkman-cli/issues/294#issuecomment-318252058).
[SDKMAN!]: https://github.com/sdkman/sdkman-cli
[fisherman]: https://github.com/fisherman/fisherman

134
completions/sdkman.fish Normal file
View file

@ -0,0 +1,134 @@
# sdkman autocompletion
function __fish_sdkman_no_command --description 'Test if sdkman has yet to be given the main command'
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 ]
return 0
end
return 1
end
function __fish_sdkman_using_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 2 ]
if [ $argv[1] = $cmd[2] ]
return 0
end
end
return 1
end
function __fish_sdkman_using_subcommand
set cmd (commandline -opc)
set cmd_main $argv[1]
set cmd_sub $argv[2]
if [ (count $cmd) -gt 2 ]
if [ $cmd_main = $cmd[2] ]; and [ $cmd_sub = $cmd[3] ]
return 0
end
end
return 1
end
function __fish_sdkman_specifying_candidate
set cmd (commandline -opc)
if [ (count $cmd) -gt 2 ]
if [ $argv[1] = $cmd[2] ]
return 0
end
end
return 1
end
function __fish_sdkman_candidates
cat ~/.sdkman/var/candidates | tr ',' '\n'
end
function __fish_sdkman_installed_versions
set cmd (commandline -opc)
ls -v1 ~/.sdkman/$cmd[3] | grep -v current
end
# install
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'install' -d 'Install new version'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'i' -d 'Install new version'
complete -c sdk -f -n '__fish_sdkman_using_command install' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_using_command i' -a "(__fish_sdkman_candidates)"
# uninstall
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'uninstall' -d 'Uninstall version'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'rm' -d 'Uninstall version'
complete -c sdk -f -n '__fish_sdkman_using_command uninstall' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_using_command rm' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate uninstall' -a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate rm' -a "(__fish_sdkman_installed_versions)"
# list
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'list' -d 'List versions'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'ls' -d 'List versions'
complete -c sdk -f -n '__fish_sdkman_using_command list' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_using_command ls' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate list' -a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate ls' -a "(__fish_sdkman_installed_versions)"
# use
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'use' -d 'Use specific version'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'u' -d 'Use specific version'
complete -c sdk -f -n '__fish_sdkman_using_command use' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_using_command u' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate use' -a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate u' -a "(__fish_sdkman_installed_versions)"
# default
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'default' -d 'Set default version'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'd' -d 'Set default version'
complete -c sdk -f -n '__fish_sdkman_using_command default' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_using_command d' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate default' -a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate d' -a "(__fish_sdkman_installed_versions)"
# current
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'current' -d 'Display current version'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'c' -d 'Display current version'
complete -c sdk -f -n '__fish_sdkman_using_command current' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_using_command c' -a "(__fish_sdkman_candidates)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate current' -a "(__fish_sdkman_installed_versions)"
complete -c sdk -f -n '__fish_sdkman_specifying_candidate c' -a "(__fish_sdkman_installed_versions)"
# upgrade
# TODO
# version
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'version' -d 'Display version'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'v' -d 'Display version'
complete -c sdk -f -n '__fish_sdkman_using_command version'
complete -c sdk -f -n '__fish_sdkman_using_command v'
# broadcast
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'broadcast' -d 'Display broadcast message'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'b' -d 'Display broadcast message'
complete -c sdk -f -n '__fish_sdkman_using_command broadcast'
complete -c sdk -f -n '__fish_sdkman_using_command b'
# help
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'help' -d 'Display help message'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'h' -d 'Display help message'
complete -c sdk -f -n '__fish_sdkman_using_command help'
complete -c sdk -f -n '__fish_sdkman_using_command h'
# 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 disable'
# selfupdate
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'selfupdate' -d 'Update sdkman'
complete -c sdk -f -n '__fish_sdkman_using_command selfupdate' -a 'force'
# update
# TODO
# flush
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'flush' -d 'Clear out cache'
complete -c sdk -f -n '__fish_sdkman_using_command flush' -a 'candidates broadcast archives temp'

11
conf.d/sdkman.fish Normal file
View file

@ -0,0 +1,11 @@
#!/usr/bin/fish
# sdk command
function sdk
bash -c "source $HOME/.sdkman/bin/sdkman-init.sh && sdk $argv"
end
# add paths
for ITEM in $HOME/.sdkman/candidates/* ;
set -gx PATH $PATH $ITEM/current/bin
end