From a6062c4cdd2d03f7938d6312bd56c99c8b2b56a8 Mon Sep 17 00:00:00 2001 From: wyahiro Date: Thu, 3 Jan 2019 23:03:22 +0900 Subject: [PATCH 1/8] improved completion for ant --- share/completions/ant.fish | 33 ++++++++ .../__fish_complete_ant_targets.fish | 76 ++++++++++++++++--- .../functions/__fish_filter_ant_targets.fish | 3 - 3 files changed, 97 insertions(+), 15 deletions(-) delete mode 100644 share/functions/__fish_filter_ant_targets.fish diff --git a/share/completions/ant.fish b/share/completions/ant.fish index a5448c4a6..82b82a7a0 100644 --- a/share/completions/ant.fish +++ b/share/completions/ant.fish @@ -1,3 +1,36 @@ +# Apache Ant (1.9.5) completion for Fish Shell. +# completion for ant targets complete -x -c ant -a "(__fish_complete_ant_targets)" +# Script Options: +complete -f -c ant -l help -l h -d 'print help message and ant help' +complete -f -c ant -l noconfig -d 'suppress sourcing of /etc/ant.conf, $HOME/.ant/ant.conf, and $HOME/.antrc configuration files' +complete -f -c ant -l usejikes -d 'enable use of jikes by default, unless set explicitly in configuration files' +complete -f -c ant -l execdebug -d 'print ant exec line generated by this launch script' +# Options: +complete -f -c ant -o help -s h -d 'print help message and exit' +complete -f -c ant -o projecthelp -s p -d 'print project help information and exit' +complete -f -c ant -o version -d 'print the version information and exit' +complete -f -c ant -o diagnostics -d 'print information that might be helpful to diagnose or report problems and exit' +complete -f -c ant -o quiet -s q -d 'be extra quiet' +complete -f -c ant -o silent -s S -d 'print nothing but task outputs and build failures' +complete -f -c ant -o verbose -s v -d 'be extra verbose' +complete -f -c ant -o debug -s d -d 'print debugging information' +complete -f -c ant -o emacs -s e -d 'produce logging information without adornments' +complete -f -c ant -o noinput -d 'do not allow interactive input' +complete -f -c ant -s D -d 'use value for given property like -D=' +complete -f -c ant -o keep-going -s k -d 'execute all targets that do not depend on failed target(s)' +complete -f -c ant -o nouserlib -d 'Run ant without using the jar files from ${user.home}/.ant/lib' +complete -f -c ant -o noclasspath -d 'Run ant without using CLASSPATH' +complete -f -c ant -o autoproxy -d 'Java1.5+: use the OS proxy settings' +complete -r -c ant -o lib -d 'specifies a path to search for jars and classes' +complete -r -c ant -o logfile -s l -d 'use given file for log' +complete -r -c ant -o logger -d 'the class which is to perform logging' +complete -r -c ant -o listener -d 'add an instance of class as a project listener' +complete -r -c ant -o buildfile -o file -s f -d 'use given buildfile' +complete -r -c ant -o propertyfile -d 'load all properties from file with -D properties taking precedence' +complete -r -c ant -o inputhandler -d 'the class which will handle input requests' +complete -r -c ant -o find -s s -d '(s)earch for buildfile towards the root of the filesystem and use it' +complete -r -c ant -o nice -d 'A niceness value for the main thread: 1 (lowest) to 10 (highest); 5 is the default' +complete -r -c ant -o main -d 'override Ant\'s normal entry point' diff --git a/share/functions/__fish_complete_ant_targets.fish b/share/functions/__fish_complete_ant_targets.fish index e93b855c6..f7324006c 100644 --- a/share/functions/__fish_complete_ant_targets.fish +++ b/share/functions/__fish_complete_ant_targets.fish @@ -1,16 +1,68 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml and imported files" - set -l buildfile "build.xml" - if test -f $buildfile - # show ant targets - __fish_filter_ant_targets $buildfile - - # find files with buildfile - set files (sed -n "s/^.*]* file=[\"']\([^\"']*\)[\"'].*\$/\1/p" < $buildfile) - - # iterate through files and display their targets - for file in $files - - __fish_filter_ant_targets $file + function __filter_xml_start_tag -d "Filter xml start-tags in a buildfile" + set -l buildfile $argv[1] # full path to buildfile + set -l tag_pattern $argv[2] # regex pattern for tagname + # regex to filter start-tags ignoring newlines and '>' in attr values + # https://www.debuggex.com/r/wRgxHE1yTIgnjfNz + string join ' ' <$buildfile | string match -ar "<(?:$tag_pattern)(?:[^>\"']*?(?:(?:'[^']*?')|(?:\"[^\"]*\"))?)*?>" + end + function __filter_xml_attr_value -d "Filter xml attr value in a start-tag" + set -l tag $argv[1] # start-tag + set -l attr $argv[2] # attr name + # regex to filter attr values ignoring (single|double) quotes in attr values + # https://www.debuggex.com/r/x7lhtLJSP4msleik + string replace -rf "^.*$attr=((?:'(?:.*?)')|(?:\"(?:.*?)\")).*\$" '$1' $tag | string trim -c='"\'' + end + function __get_buildfile -d "Get a buildfile that will be used by ant" + set -l tokens $argv # tokens from 'commandline -co' + set -l prev $tokens[1] + set -l buildfile "build.xml" + for token in $argv[2..-1] + switch $prev + case -buildfile -file -f + set buildfile (eval echo $token) + end + set prev $token + end + # return last one + echo $buildfile + end + function __parse_ant_targets -d "Parse ant targets in the given build file" + set -l buildfile $argv[1] # full path to buildfile + set -l targets (__filter_xml_start_tag $buildfile 'target|extension-point') + for target in $targets + set -l target_name (__filter_xml_attr_value $target 'name') + if [ $status -eq 0 ] + set -l target_description (__filter_xml_attr_value $target 'description') + if [ $status -eq 0 ] + echo $target_name\t$target_description + else + echo $target_name + end + end end end + function __get_ant_targets -d "Get ant targets recursively" + set -l buildfile $argv[1] # full path to buildfile + __parse_ant_targets $buildfile + + set -l basedir (string split -r -m 1 / $buildfile)[1] + set -l imports (__filter_xml_start_tag $buildfile 'import') + for import in $imports + set -l filepath (__filter_xml_attr_value $import 'file') + # Set basedir if $filepath is not a full path + if string match -rvq '^/.*' $filepath + set filename $basedir/$filepath + end + if [ -f $filepath ] + __get_ant_targets $filepath + end + end + end + + set -l tokens (commandline -co) + set -l buildfile (realpath -eq $buildfile (__get_buildfile $tokens)) + if [ $status -eq 0 ] + __get_ant_targets $buildfile + end end diff --git a/share/functions/__fish_filter_ant_targets.fish b/share/functions/__fish_filter_ant_targets.fish deleted file mode 100644 index 242cdb0bc..000000000 --- a/share/functions/__fish_filter_ant_targets.fish +++ /dev/null @@ -1,3 +0,0 @@ -function __fish_filter_ant_targets -d "Display targets within an ant build.xml file" - sed -n "s/^.*]* name=[\"']\([^\"']*\)[\"'].*\$/\1/p" <$argv[1] -end From 48ed82b3f3590e415a955d4a4e97095a3fd377e3 Mon Sep 17 00:00:00 2001 From: wyahiro Date: Thu, 3 Jan 2019 23:33:21 +0900 Subject: [PATCH 2/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 708f924fc..9a8e0acb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - nothing yet... - Lots of improvements to completions. - fish_clipboard_* now supports wayland by means of [wl-clipboard](https://github.com/bugaevc/wl-clipboard). - + - Improved completion for `ant`. --- # fish 3.0.0 (released December 28, 2018) From 078907ef9dbe7ca3ea4787ebf1f8ceb5771c14ee Mon Sep 17 00:00:00 2001 From: wyahiro Date: Thu, 3 Jan 2019 23:59:56 +0900 Subject: [PATCH 3/8] update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a8e0acb1..c08e1812a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - nothing yet... - Lots of improvements to completions. - fish_clipboard_* now supports wayland by means of [wl-clipboard](https://github.com/bugaevc/wl-clipboard). - - Improved completion for `ant`. + - Improved completion for `ant` (#5475). --- # fish 3.0.0 (released December 28, 2018) From 480e95147cc375df9967568fbeac7f5c32bf0184 Mon Sep 17 00:00:00 2001 From: wyahiro Date: Sun, 13 Jan 2019 21:36:05 +0900 Subject: [PATCH 4/8] use cache file for ant targets --- share/completions/ant.fish | 2 +- .../__fish_complete_ant_targets.fish | 68 ++++++++----------- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/share/completions/ant.fish b/share/completions/ant.fish index 82b82a7a0..7436876cb 100644 --- a/share/completions/ant.fish +++ b/share/completions/ant.fish @@ -1,7 +1,7 @@ # Apache Ant (1.9.5) completion for Fish Shell. # completion for ant targets -complete -x -c ant -a "(__fish_complete_ant_targets)" +complete -x -c ant -a "(__fish_complete_ant_targets (commandline -co))" # Script Options: complete -f -c ant -l help -l h -d 'print help message and ant help' diff --git a/share/functions/__fish_complete_ant_targets.fish b/share/functions/__fish_complete_ant_targets.fish index f7324006c..d3013bb7b 100644 --- a/share/functions/__fish_complete_ant_targets.fish +++ b/share/functions/__fish_complete_ant_targets.fish @@ -1,18 +1,4 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml and imported files" - function __filter_xml_start_tag -d "Filter xml start-tags in a buildfile" - set -l buildfile $argv[1] # full path to buildfile - set -l tag_pattern $argv[2] # regex pattern for tagname - # regex to filter start-tags ignoring newlines and '>' in attr values - # https://www.debuggex.com/r/wRgxHE1yTIgnjfNz - string join ' ' <$buildfile | string match -ar "<(?:$tag_pattern)(?:[^>\"']*?(?:(?:'[^']*?')|(?:\"[^\"]*\"))?)*?>" - end - function __filter_xml_attr_value -d "Filter xml attr value in a start-tag" - set -l tag $argv[1] # start-tag - set -l attr $argv[2] # attr name - # regex to filter attr values ignoring (single|double) quotes in attr values - # https://www.debuggex.com/r/x7lhtLJSP4msleik - string replace -rf "^.*$attr=((?:'(?:.*?)')|(?:\"(?:.*?)\")).*\$" '$1' $tag | string trim -c='"\'' - end function __get_buildfile -d "Get a buildfile that will be used by ant" set -l tokens $argv # tokens from 'commandline -co' set -l prev $tokens[1] @@ -27,42 +13,42 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml an # return last one echo $buildfile end - function __parse_ant_targets -d "Parse ant targets in the given build file" + function __parse_ant_targets_from_projecthelp -d "Parse ant targets from projecthelp" set -l buildfile $argv[1] # full path to buildfile - set -l targets (__filter_xml_start_tag $buildfile 'target|extension-point') + set -l targets (ant -p -debug -f $buildfile 2> /dev/null | string match -r '^\s\S+.*$' $projecthelp) for target in $targets - set -l target_name (__filter_xml_attr_value $target 'name') - if [ $status -eq 0 ] - set -l target_description (__filter_xml_attr_value $target 'description') - if [ $status -eq 0 ] - echo $target_name\t$target_description - else - echo $target_name - end + set -l tokens (string match -r '^\s([[:graph:]]+)(?:\s+([[:print:]]+))?' "$target") + if [ (count $tokens) -ge 3 ] + echo $tokens[2]\t$tokens[3] + else if [ (count $tokens) -ge 2 ] + echo $tokens[2] end end end - function __get_ant_targets -d "Get ant targets recursively" + function __get_ant_targets_from_projecthelp -d "Get ant targets from projecthelp" set -l buildfile $argv[1] # full path to buildfile - __parse_ant_targets $buildfile - set -l basedir (string split -r -m 1 / $buildfile)[1] - set -l imports (__filter_xml_start_tag $buildfile 'import') - for import in $imports - set -l filepath (__filter_xml_attr_value $import 'file') - # Set basedir if $filepath is not a full path - if string match -rvq '^/.*' $filepath - set filename $basedir/$filepath - end - if [ -f $filepath ] - __get_ant_targets $filepath - end + set -l cache_dir + if [ \( -n $__fish_user_data_dir \) -a \( -d $__fish_user_data_dir \) ] + set cache_dir $__fish_user_data_dir/ant_completions + else + set cache_dir "$HOME/.local/share/fish/ant_completions" end + mkdir -p $cache_dir + + set -l cache_file $cache_dir/(string escape --style=var $buildfile) + if [ ! -s $cache_file ] + # generate cache file if empty + __parse_ant_targets_from_projecthelp $buildfile > $cache_file + end + + cat $cache_file end - set -l tokens (commandline -co) - set -l buildfile (realpath -eq $buildfile (__get_buildfile $tokens)) - if [ $status -eq 0 ] - __get_ant_targets $buildfile + set -l tokens $argv + if not set -l buildfile (realpath -eq $buildfile (__get_buildfile $tokens)) + return 1 # return nothing if buildfile does not exist end + + __get_ant_targets_from_projecthelp $buildfile end From 71f15f70ea90c2fc447b2202ff9e242268c50fee Mon Sep 17 00:00:00 2001 From: wyahiro Date: Mon, 14 Jan 2019 13:08:29 +0900 Subject: [PATCH 5/8] Fixed logic for cache file generation --- share/functions/__fish_complete_ant_targets.fish | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/share/functions/__fish_complete_ant_targets.fish b/share/functions/__fish_complete_ant_targets.fish index d3013bb7b..0b50a39da 100644 --- a/share/functions/__fish_complete_ant_targets.fish +++ b/share/functions/__fish_complete_ant_targets.fish @@ -15,8 +15,9 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml an end function __parse_ant_targets_from_projecthelp -d "Parse ant targets from projecthelp" set -l buildfile $argv[1] # full path to buildfile - set -l targets (ant -p -debug -f $buildfile 2> /dev/null | string match -r '^\s\S+.*$' $projecthelp) + set -l targets (ant -p -debug -f $buildfile 2> /dev/null | string match -r '^\s[[:graph:]].*$') for target in $targets + # Use [[:graph:]] and [[:print:]] to ignore ANSI escape code set -l tokens (string match -r '^\s([[:graph:]]+)(?:\s+([[:print:]]+))?' "$target") if [ (count $tokens) -ge 3 ] echo $tokens[2]\t$tokens[3] @@ -28,16 +29,14 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml an function __get_ant_targets_from_projecthelp -d "Get ant targets from projecthelp" set -l buildfile $argv[1] # full path to buildfile - set -l cache_dir - if [ \( -n $__fish_user_data_dir \) -a \( -d $__fish_user_data_dir \) ] - set cache_dir $__fish_user_data_dir/ant_completions - else - set cache_dir "$HOME/.local/share/fish/ant_completions" + if [ \( -z "$XDG_CACHE_HOME" \) -o \( ! -d "$XDG_CACHE_HOME" \) ] + set XDG_CACHE_HOME "$HOME/.cache/" end + set -l cache_dir "$XDG_CACHE_HOME/fish/ant_completions" mkdir -p $cache_dir - set -l cache_file $cache_dir/(string escape --style=var $buildfile) - if [ ! -s $cache_file ] + set -l cache_file $cache_dir/(fish_md5 -s $buildfile) + if [ ! -s "$cache_file" ] # generate cache file if empty __parse_ant_targets_from_projecthelp $buildfile > $cache_file end From 2c52c5285d12a10f6fed243e75c6b013fb7ccb89 Mon Sep 17 00:00:00 2001 From: wyahiro Date: Thu, 17 Jan 2019 16:32:57 +0900 Subject: [PATCH 6/8] Fix fail back value for XDG_CACHE_HOME --- share/functions/__fish_complete_ant_targets.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/functions/__fish_complete_ant_targets.fish b/share/functions/__fish_complete_ant_targets.fish index 0b50a39da..3203b2060 100644 --- a/share/functions/__fish_complete_ant_targets.fish +++ b/share/functions/__fish_complete_ant_targets.fish @@ -30,8 +30,9 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml an set -l buildfile $argv[1] # full path to buildfile if [ \( -z "$XDG_CACHE_HOME" \) -o \( ! -d "$XDG_CACHE_HOME" \) ] - set XDG_CACHE_HOME "$HOME/.cache/" + set XDG_CACHE_HOME "$HOME/.cache" end + set -l cache_dir "$XDG_CACHE_HOME/fish/ant_completions" mkdir -p $cache_dir From 9a7079190d01c4f831d35c3afd4af61a6dbe61ba Mon Sep 17 00:00:00 2001 From: wyahiro Date: Fri, 18 Jan 2019 10:24:14 +0900 Subject: [PATCH 7/8] change validation of buildfile --- share/functions/__fish_complete_ant_targets.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 share/functions/__fish_complete_ant_targets.fish diff --git a/share/functions/__fish_complete_ant_targets.fish b/share/functions/__fish_complete_ant_targets.fish old mode 100644 new mode 100755 index 3203b2060..3c216b044 --- a/share/functions/__fish_complete_ant_targets.fish +++ b/share/functions/__fish_complete_ant_targets.fish @@ -46,7 +46,8 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml an end set -l tokens $argv - if not set -l buildfile (realpath -eq $buildfile (__get_buildfile $tokens)) + set -l buildfile (realpath -eq $buildfile (__get_buildfile $tokens)) + if [ $status -ne 0 ] return 1 # return nothing if buildfile does not exist end From 65d4f1b74e166250cf1b29386e431058971224a3 Mon Sep 17 00:00:00 2001 From: wyahiro Date: Mon, 21 Jan 2019 16:35:48 +0900 Subject: [PATCH 8/8] Format CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36503d94a..5f9070a9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ - fish_clipboard_* now supports wayland by means of [wl-clipboard](https://github.com/bugaevc/wl-clipboard). - mandoc can now be used to format the output from `--help` if nroff is not installed + +======= # fish 3.0.1 ### Fixes and improvements @@ -23,6 +25,7 @@ - exec now behaves properly inside functions (#5449) - while loops now evaluate to the last executed command in the loop body (or zero if the body was empty), matching POSIX semantics. + # fish 3.0.0 (released December 28, 2018) fish 3 is a major release, which introduces some breaking changes alongside improved functionality. Although most existing scripts will continue to work, they should be reviewed against the list contained in the 3.0b1 release notes below.