diff --git a/share/completions/gradle.fish b/share/completions/gradle.fish index 0a63264f5..6a57bb57b 100644 --- a/share/completions/gradle.fish +++ b/share/completions/gradle.fish @@ -37,3 +37,25 @@ complete -c gradle -l continuous -s t -d 'Enable continuous build' complete -c gradle -l no-search-upward -s u -d 'Don\'t search in parent folders for settings file' complete -c gradle -l version -s v -d 'Print version' complete -c gradle -l exclude-task -s x -x -d 'Specify task to be excluded from execution' + +# https://github.com/hanny24/gradle-fish/blob/master/gradle.load +function __cache_or_get_gradle_completion + # Set up cache directory + if test -z $XDG_CACHE_HOME + set XDG_CACHE_HOME $HOME/.cache/ + end + mkdir -m 700 -p $XDG_CACHE_HOME/gradle-completions + + set -l hashed_pwd (fish_md5 -s $PWD) + set -l gradle_cache_file $XDG_CACHE_HOME/gradle-completions/$hashed_pwd + if not test -f $gradle_cache_file; or command test build.gradle -nt $gradle_cache_file + command gradle -q tasks ^/dev/null | string match -r '^[[:alnum:]]+ - .*' | string replace ' - ' \t > $gradle_cache_file + end + cat $gradle_cache_file +end + +function __contains_gradle_build + test -f build.gradle +end + +complete -x -c gradle -n '__contains_gradle_build' -a "(__cache_or_get_gradle_completion)" diff --git a/share/functions/fish_md5.fish b/share/functions/fish_md5.fish new file mode 100644 index 000000000..a157c7c11 --- /dev/null +++ b/share/functions/fish_md5.fish @@ -0,0 +1,28 @@ +function fish_md5 + if type -q md5sum + # GNU systems + if set -q argv[2] + if test $argv[1] = "-s" + echo (echo $argv[2] | md5sum | string split ' ')[1] + else + printf (_ "%s: Too many arguments %s\n") fish_md5 $argv + end + else + echo (md5sum $argv[1] | string split ' ')[1] + end + return 0 + else if type -q md5 + # BSD systems + if set -q argv[2] + if test $argv[1] = "-s" + md5 -s $argv[1] + else + printf (_ "%s: Too many arguments %s\n") fish_md5 $argv + end + else + md5 -q $argv[1] + end + return 0 + end + return 1 +end