summaryrefslogtreecommitdiff
path: root/plugins/ant/_ant
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2021-12-28 17:15:16 +0100
committerMarc Cornellà <hello@mcornella.com>2021-12-28 17:17:05 +0100
commit364e62155de53c3d977b54953a262d7a256d2cd5 (patch)
tree7e264766dd3201a3baab665b8d2e2e670cef4650 /plugins/ant/_ant
parent56de7c85f34a15a4490f4984e128dba78fcebfd3 (diff)
downloadzsh-364e62155de53c3d977b54953a262d7a256d2cd5.tar.gz
zsh-364e62155de53c3d977b54953a262d7a256d2cd5.tar.bz2
zsh-364e62155de53c3d977b54953a262d7a256d2cd5.zip
refactor(ant): extract completion function
Diffstat (limited to 'plugins/ant/_ant')
-rw-r--r--plugins/ant/_ant22
1 files changed, 22 insertions, 0 deletions
diff --git a/plugins/ant/_ant b/plugins/ant/_ant
new file mode 100644
index 000000000..24a8e3667
--- /dev/null
+++ b/plugins/ant/_ant
@@ -0,0 +1,22 @@
+#compdef ant
+
+_ant_does_target_list_need_generating () {
+ [[ ! -f .ant_targets ]] && return 0
+ [[ build.xml -nt .ant_targets ]] && return 0
+ return 1
+}
+
+_ant () {
+ if [[ ! -f build.xml ]]; then
+ return
+ fi
+
+ if ! _ant_does_target_list_need_generating; then
+ return
+ fi
+
+ ant -p | awk -F " " 'NR > 5 { print lastTarget } { lastTarget = $1 }' >| .ant_targets
+ compadd -- "$(cat .ant_targets)"
+}
+
+_ant "$@"