mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 10:01:14 -03:00
Merge remote-tracking branch 'takoyaki/ant_completion' into master
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# Apache Ant (1.9.5) completion for Fish Shell.
|
# Apache Ant (1.9.5) completion for Fish Shell.
|
||||||
|
|
||||||
# completion for ant targets
|
# 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:
|
# Script Options:
|
||||||
complete -f -c ant -l help -l h -d 'print help message and ant help'
|
complete -f -c ant -l help -l h -d 'print help message and ant help'
|
||||||
|
|||||||
67
share/functions/__fish_complete_ant_targets.fish
Normal file → Executable file
67
share/functions/__fish_complete_ant_targets.fish
Normal file → Executable file
@@ -1,18 +1,4 @@
|
|||||||
function __fish_complete_ant_targets -d "Print list of targets from build.xml and imported files"
|
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"
|
function __get_buildfile -d "Get a buildfile that will be used by ant"
|
||||||
set -l tokens $argv # tokens from 'commandline -co'
|
set -l tokens $argv # tokens from 'commandline -co'
|
||||||
set -l prev $tokens[1]
|
set -l prev $tokens[1]
|
||||||
@@ -27,42 +13,43 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml an
|
|||||||
# return last one
|
# return last one
|
||||||
echo $buildfile
|
echo $buildfile
|
||||||
end
|
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 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[[:graph:]].*$')
|
||||||
for target in $targets
|
for target in $targets
|
||||||
set -l target_name (__filter_xml_attr_value $target 'name')
|
# Use [[:graph:]] and [[:print:]] to ignore ANSI escape code
|
||||||
if [ $status -eq 0 ]
|
set -l tokens (string match -r '^\s([[:graph:]]+)(?:\s+([[:print:]]+))?' "$target")
|
||||||
set -l target_description (__filter_xml_attr_value $target 'description')
|
if [ (count $tokens) -ge 3 ]
|
||||||
if [ $status -eq 0 ]
|
echo $tokens[2]\t$tokens[3]
|
||||||
echo $target_name\t$target_description
|
else if [ (count $tokens) -ge 2 ]
|
||||||
else
|
echo $tokens[2]
|
||||||
echo $target_name
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
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
|
set -l buildfile $argv[1] # full path to buildfile
|
||||||
__parse_ant_targets $buildfile
|
|
||||||
|
|
||||||
set -l basedir (string split -r -m 1 / $buildfile)[1]
|
if [ \( -z "$XDG_CACHE_HOME" \) -o \( ! -d "$XDG_CACHE_HOME" \) ]
|
||||||
set -l imports (__filter_xml_start_tag $buildfile 'import')
|
set XDG_CACHE_HOME "$HOME/.cache"
|
||||||
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 cache_dir "$XDG_CACHE_HOME/fish/ant_completions"
|
||||||
|
mkdir -p $cache_dir
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
cat $cache_file
|
||||||
end
|
end
|
||||||
|
|
||||||
set -l tokens (commandline -co)
|
set -l tokens $argv
|
||||||
set -l buildfile (realpath -eq $buildfile (__get_buildfile $tokens))
|
set -l buildfile (realpath -eq $buildfile (__get_buildfile $tokens))
|
||||||
if [ $status -eq 0 ]
|
if [ $status -ne 0 ]
|
||||||
__get_ant_targets $buildfile
|
return 1 # return nothing if buildfile does not exist
|
||||||
end
|
end
|
||||||
|
|
||||||
|
__get_ant_targets_from_projecthelp $buildfile
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user