fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes Altmanningercompletions/java_home: fix version completion due to change of osascript default outputc0c9245d9

master
2.3 KiB44 linesraw
1function __fish_complete_macos_java_version
2    set -l json (/usr/libexec/java_home -X|plutil -convert json -o - -)
3    osascript -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
10    set -l cmds (string replace -a -r ' *java_home *' ''  (commandline) )
11    set -l cmds (string replace -r ' *--exec *' \n -- "$cmds")
12
13    # parse the java_home argv to get $JAVA_HOME/bin
14    argparse v/version= a/arch= -- "$cmds[1]"
15    set -l get_java_home /usr/libexec/java_home
16    if test -n "$_flag_v"
17        set get_java_home "$get_java_home -v $_flag_v"
18    end
19    if test -n "$_flag_a"
20        set get_java_home "$get_java_home -a $_flag_a"
21    end
22    set -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
28    set -l binary (string match -r '^.*?(?= )' $cmds[2])
29    if test -f "$java_bin_dir/$binary"
30        complete -C $cmds[2]
31    else
32        command ls $java_bin_dir | string match -r ^"$binary.*"
33    end
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.'