Skip to content

Commit 2f17228

Browse files
committed
- Add completions for bashly itself
1 parent b7030dd commit 2f17228

File tree

4 files changed

+387
-0
lines changed

4 files changed

+387
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# bashly completion -*- shell-script -*-
2+
3+
# This bash completions script was generated by
4+
# completely (https://github.com/dannyben/completely)
5+
# Modifying it manually is not recommended
6+
7+
_bashly_completions_filter() {
8+
local words="$1"
9+
local cur=${COMP_WORDS[COMP_CWORD]}
10+
local result=()
11+
12+
if [[ "${cur:0:1}" == "-" ]]; then
13+
echo "$words"
14+
15+
else
16+
for word in $words; do
17+
[[ "${word:0:1}" != "-" ]] && result+=("$word")
18+
done
19+
20+
echo "${result[*]}"
21+
22+
fi
23+
}
24+
25+
_bashly_completions() {
26+
local cur=${COMP_WORDS[COMP_CWORD]}
27+
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
28+
local compline="${compwords[*]}"
29+
30+
case "$compline" in
31+
'generate'*'--env')
32+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "development production")" -- "$cur" )
33+
;;
34+
35+
'generate'*'-e')
36+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "development production")" -- "$cur" )
37+
;;
38+
39+
'validate'*)
40+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --verbose -v")" -- "$cur" )
41+
;;
42+
43+
'generate'*)
44+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --env --force --quiet --upgrade --watch --wrap -e -f -q -r -u -w")" -- "$cur" )
45+
;;
46+
47+
'preview'*)
48+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h")" -- "$cur" )
49+
;;
50+
51+
'g'*'--env')
52+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "development production")" -- "$cur" )
53+
;;
54+
55+
'shell'*)
56+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h")" -- "$cur" )
57+
;;
58+
59+
'init'*)
60+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --minimal -m")" -- "$cur" )
61+
;;
62+
63+
'g'*'-e')
64+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "development production")" -- "$cur" )
65+
;;
66+
67+
'add'*)
68+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --force --list --source -f -l -s colors completions completions_script completions_yaml config help hooks lib settings strings test validations yaml")" -- "$cur" )
69+
;;
70+
71+
'doc'*)
72+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --index -i arg arg.allowed arg.default arg.help arg.name arg.repeatable arg.required arg.validate command command.alias command.args command.catch_all command.commands command.completions command.default command.dependencies command.environment_variables command.examples command.expose command.extensible command.filename command.filters command.flags command.footer command.function command.group command.help command.name command.private command.version environment_variable environment_variable.default environment_variable.help environment_variable.name environment_variable.private environment_variable.required flag flag.allowed flag.arg flag.completions flag.conflicts flag.default flag.help flag.long flag.private flag.repeatable flag.required flag.short flag.validate")" -- "$cur" )
73+
;;
74+
75+
'i'*)
76+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --minimal -m")" -- "$cur" )
77+
;;
78+
79+
'p'*)
80+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h")" -- "$cur" )
81+
;;
82+
83+
'v'*)
84+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --verbose -v")" -- "$cur" )
85+
;;
86+
87+
'g'*)
88+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --env --force --quiet --upgrade --watch --wrap -e -f -q -r -u -w")" -- "$cur" )
89+
;;
90+
91+
'a'*)
92+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --force --list --source -f -l -s colors completions completions_script completions_yaml config help hooks lib settings strings test validations yaml")" -- "$cur" )
93+
;;
94+
95+
's'*)
96+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h")" -- "$cur" )
97+
;;
98+
99+
*)
100+
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_bashly_completions_filter "--help -h --version -v init preview validate generate add doc shell")" -- "$cur" )
101+
;;
102+
103+
esac
104+
} &&
105+
complete -F _bashly_completions bashly
106+
107+
# ex: filetype=sh
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
bashly:
2+
- --help
3+
- -h
4+
- --version
5+
- -v
6+
- init
7+
- preview
8+
- validate
9+
- generate
10+
- add
11+
- doc
12+
- shell
13+
14+
bashly init: &init
15+
- --help
16+
- -h
17+
- --minimal
18+
- -m
19+
20+
bashly i: *init
21+
22+
bashly preview: &preview
23+
- --help
24+
- -h
25+
26+
bashly p: *preview
27+
28+
bashly validate: &validate
29+
- --help
30+
- -h
31+
- --verbose
32+
- -v
33+
34+
bashly v: *validate
35+
36+
bashly generate: &generate
37+
- --help
38+
- -h
39+
- --env
40+
- --force
41+
- --quiet
42+
- --upgrade
43+
- --watch
44+
- --wrap
45+
- -e
46+
- -f
47+
- -q
48+
- -r
49+
- -u
50+
- -w
51+
52+
bashly g: *generate
53+
54+
bashly generate*--env: &env
55+
- development
56+
- production
57+
58+
bashly generate*-e: *env
59+
bashly g*--env: *env
60+
bashly g*-e: *env
61+
62+
bashly add: &add
63+
- --help
64+
- -h
65+
- --force
66+
- --list
67+
- --source
68+
- -f
69+
- -l
70+
- -s
71+
- colors
72+
- completions
73+
- completions_script
74+
- completions_yaml
75+
- config
76+
- help
77+
- hooks
78+
- lib
79+
- settings
80+
- strings
81+
- test
82+
- validations
83+
- yaml
84+
85+
bashly a: *add
86+
87+
bashly doc: &doc
88+
- --help
89+
- -h
90+
- --index
91+
- -i
92+
- arg
93+
- arg.allowed
94+
- arg.default
95+
- arg.help
96+
- arg.name
97+
- arg.repeatable
98+
- arg.required
99+
- arg.validate
100+
- command
101+
- command.alias
102+
- command.args
103+
- command.catch_all
104+
- command.commands
105+
- command.completions
106+
- command.default
107+
- command.dependencies
108+
- command.environment_variables
109+
- command.examples
110+
- command.expose
111+
- command.extensible
112+
- command.filename
113+
- command.filters
114+
- command.flags
115+
- command.footer
116+
- command.function
117+
- command.group
118+
- command.help
119+
- command.name
120+
- command.private
121+
- command.version
122+
- environment_variable
123+
- environment_variable.default
124+
- environment_variable.help
125+
- environment_variable.name
126+
- environment_variable.private
127+
- environment_variable.required
128+
- flag
129+
- flag.allowed
130+
- flag.arg
131+
- flag.completions
132+
- flag.conflicts
133+
- flag.default
134+
- flag.help
135+
- flag.long
136+
- flag.private
137+
- flag.repeatable
138+
- flag.required
139+
- flag.short
140+
- flag.validate
141+
bashly shell: &shell
142+
- --help
143+
- -h
144+
145+
bashly s: *shell
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
> bashly:
2+
= help_flags
3+
> - --version
4+
> - -v
5+
commands.each do |command|
6+
= "- #{command}"
7+
end
8+
>
9+
> bashly init: &init
10+
= help_flags
11+
> - --minimal
12+
> - -m
13+
>
14+
> bashly i: *init
15+
>
16+
> bashly preview: &preview
17+
= help_flags
18+
>
19+
> bashly p: *preview
20+
>
21+
> bashly validate: &validate
22+
= help_flags
23+
> - --verbose
24+
> - -v
25+
>
26+
> bashly v: *validate
27+
>
28+
> bashly generate: &generate
29+
= help_flags
30+
> - --env
31+
> - --force
32+
> - --quiet
33+
> - --upgrade
34+
> - --watch
35+
> - --wrap
36+
> - -e
37+
> - -f
38+
> - -q
39+
> - -r
40+
> - -u
41+
> - -w
42+
>
43+
> bashly g: *generate
44+
>
45+
> bashly generate*--env: &env
46+
> - development
47+
> - production
48+
>
49+
> bashly generate*-e: *env
50+
> bashly g*--env: *env
51+
> bashly g*-e: *env
52+
>
53+
> bashly add: &add
54+
= help_flags
55+
> - --force
56+
> - --list
57+
> - --source
58+
> - -f
59+
> - -l
60+
> - -s
61+
libs.each do |lib|
62+
= "- #{lib}"
63+
end
64+
65+
>
66+
> bashly a: *add
67+
>
68+
> bashly doc: &doc
69+
= help_flags
70+
> - --index
71+
> - -i
72+
docs.each do |doc|
73+
= "- #{doc}"
74+
end
75+
76+
> bashly shell: &shell
77+
= help_flags
78+
>
79+
> bashly s: *shell
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
require 'bashly'
2+
3+
summary 'Generate bash completions for bashly itself'
4+
5+
action do
6+
completely_yaml_oath = 'support/completions/completely.yaml'
7+
completions_script_path = 'support/completions/bashly-completions.bash'
8+
gtx_path = "#{completely_yaml_oath}.gtx"
9+
template = File.read gtx_path
10+
11+
say "Reading GTX template from m`#{gtx_path}`"
12+
gtx = GTX.new template, filename: gtx_path
13+
completely_yaml = gtx.parse binding
14+
15+
say "Writing completely configuration to m`#{completely_yaml_oath}`"
16+
File.write completely_yaml_oath, completely_yaml
17+
18+
say "Saving completions script to m`#{completions_script_path}`"
19+
completions = Completely::Completions.load completely_yaml_oath
20+
File.write completions_script_path, completions.script
21+
22+
if compdir
23+
say "Copying completions script to m`#{compdir}`"
24+
system %Q[sudo cp "#{completions_script_path}" "#{compdir}/bashly"]
25+
else
26+
say 'r`Cannot find completions directory, not copying'
27+
end
28+
29+
say 'Done (you may need to restart your session)'
30+
end
31+
32+
helpers do
33+
def help_flags = "- --help\n- -h"
34+
35+
def libs = Bashly::LibrarySource.new.config.keys
36+
37+
def commands = Bashly::CLI.runner.commands.keys
38+
39+
def docs
40+
Dir['lib/bashly/docs/*.yml'].each_with_object({}) do |path, hash|
41+
hash.merge!(YAML.load_file(path))
42+
end.keys
43+
end
44+
45+
def compdir
46+
@compdir ||= begin
47+
candidates = [
48+
'/usr/share/bash-completion/completions',
49+
'/usr/local/etc/bash_completion.d'
50+
]
51+
52+
candidates.each { |dir| return dir if Dir.exist? dir }
53+
nil
54+
end
55+
end
56+
end

0 commit comments

Comments
 (0)