fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
c0c9245d9
master
1function __fish_complete_macos_java_version 2set -l json( /usr/libexec/java_home -X| plutil -convert json -o - -) 3osascript -l JavaScript -s o -e"JSON.parse(' $json ').map(e => `\${e.JVMVersion}\t\${e.JVMArch} \${e.JVMName} by \${e.JVMVendor}`).join('\n')" 4end 5 6function __fish_complete_macos_java_home_exec 7# separate the buffer into two parts 8# where the first used to get the JAVA_HOME 9# and the second is the subcommand to complete 10set -l cmds( string replace -a -r' *java_home *' '' ( commandline ) ) 11set -l cmds( string replace -r' *--exec *' \n --" $cmds " ) 12 13# parse the java_home argv to get $JAVA_HOME/bin 14argparse v/version= a/arch= --" $cmds [ 1 ] " 15set -l get_java_home /usr/libexec/java_home 16if test -n " $_flag_v " 17set get_java_home" $get_java_home -v $_flag_v " 18end 19if test -n " $_flag_a " 20set get_java_home" $get_java_home -a $_flag_a " 21end 22set -l java_bin_dir( eval $get_java_home ) "/bin" 23 24# if such $binary in $JAVA_HOME/bin 25# complete the subcommand 26# else 27# complete using $binary as prefix 28set -l binary( string match -r'^.*?(?= )' $cmds [ 2 ]) 29if test -f " $java_bin_dir / $binary " 30complete -C$cmds [ 2 ] 31else 32command ls$java_bin_dir | string match -r ^" $binary .*" 33end 34end 35 36complete -ec java_home 37complete -xc java_home -n"__fish_not_contain_opt -s h exec " -l exec 38complete -xc java_home -n"__fish_contains_opt exec " -a"(__fish_complete_macos_java_home_exec)" 39complete -xc java_home -n"__fish_not_contain_opt -s h exec " -s v -l version -a'(__fish_complete_macos_java_version)' -d'Filter versions (as if JAVA_VERSION had been set in the environment).' 40complete -xc java_home -n"__fish_not_contain_opt -s h exec " -s a -l arch -a"arm64 x86_64" -d'Filter architecture (as if JAVA_ARCH had been set in the environment).' 41complete -xc java_home -n"__fish_not_contain_opt -s h exec " -s h -l help -d'Usage information.' 42complete -fc java_home -n"__fish_not_contain_opt -s h exec " -s F -l failfast -d'Fail when filters return no JVMs, do not continue with default.' 43complete -fc java_home -n"__fish_not_contain_opt -s h exec " -s X -l xml -d'Print full JVM list and additional data as XML plist.' 44complete -fc java_home -n"__fish_not_contain_opt -s h exec " -s V -l verbose -d'Print full JVM list with architectures.'