364e62155de53c3d977b54953a262d7a256d2cd5
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- Marc Cornellà <hello@mcornella.com>
- Date
Message
refactor(ant): extract completion function
Diff
1diff --git a/plugins/ant/README.md b/plugins/ant/README.md
2index 5f88984ac30a7607358d2fa12578d6a1e244d7eb..5712372233ab522f2ccb0b57380aafe57fb68915 100644
3--- a/plugins/ant/README.md
4+++ b/plugins/ant/README.md
5@@ -2,9 +2,9 @@
6
7 This plugin provides completion for [Ant](https://ant.apache.org/).
8
9-To use it add ant to the plugins array in your zshrc file.
10+To use it, add `ant` to the plugins array in your zshrc file:
11
12-```bash
13+```zsh
14 plugins=(... ant)
15 ```
16
17diff --git a/plugins/ant/_ant b/plugins/ant/_ant
18new file mode 100644
19index 0000000000000000000000000000000000000000..24a8e3667e98ead91469073729c72a0c79a65c7d
20--- /dev/null
21+++ b/plugins/ant/_ant
22@@ -0,0 +1,22 @@
23+#compdef ant
24+
25+_ant_does_target_list_need_generating () {
26+ [[ ! -f .ant_targets ]] && return 0
27+ [[ build.xml -nt .ant_targets ]] && return 0
28+ return 1
29+}
30+
31+_ant () {
32+ if [[ ! -f build.xml ]]; then
33+ return
34+ fi
35+
36+ if ! _ant_does_target_list_need_generating; then
37+ return
38+ fi
39+
40+ ant -p | awk -F " " 'NR > 5 { print lastTarget } { lastTarget = $1 }' >| .ant_targets
41+ compadd -- "$(cat .ant_targets)"
42+}
43+
44+_ant "$@"
45diff --git a/plugins/ant/ant.plugin.zsh b/plugins/ant/ant.plugin.zsh
46deleted file mode 100644
47index 0b738c94fc8ff1f0f1683fc7684c6b042100ff7a..0000000000000000000000000000000000000000
48--- a/plugins/ant/ant.plugin.zsh
49+++ /dev/null
50@@ -1,16 +0,0 @@
51-_ant_does_target_list_need_generating () {
52- [ ! -f .ant_targets ] && return 0;
53- [ build.xml -nt .ant_targets ] && return 0;
54- return 1;
55-}
56-
57-_ant () {
58- if [ -f build.xml ]; then
59- if _ant_does_target_list_need_generating; then
60- ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets
61- fi
62- compadd -- `cat .ant_targets`
63- fi
64-}
65-
66-compdef _ant ant