Skip to content

Commit 0cd6d78

Browse files
authored
Merge pull request #22 from DannyBen/fix/zsh
Remove support for arbitrary script test to fix zsh incompatibilities
2 parents 72d0da4 + a84836a commit 0cd6d78

File tree

23 files changed

+66
-128
lines changed

23 files changed

+66
-128
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ these (whichever exists):
217217

218218
You can use the built in completions script tester by running `completely test`.
219219

220-
This command lets you test any completions script, whether it was generated by
221-
completely or not.
220+
This command lets you test completions for your completions script.
222221

223222
In addition, you can set the `COMPLETELY_DEBUG` environment variable to any value
224223
in order to generate scripts with some additional debugging functionality. Run

lib/completely/commands/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def config_path
3636
@config_path ||= args['CONFIG_PATH'] || ENV['COMPLETELY_CONFIG_PATH'] || 'completely.yaml'
3737
end
3838

39-
def script_path
40-
@script_path ||= args['SCRIPT_PATH'] || ENV['COMPLETELY_SCRIPT_PATH'] || "#{config_basename}.bash"
39+
def output_path
40+
@output_path ||= args['OUTPUT_PATH'] || ENV['COMPLETELY_OUTPUT_PATH'] || "#{config_basename}.bash"
4141
end
4242

4343
def config_basename

lib/completely/commands/generate.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ module Commands
55
class Generate < Base
66
help "Generate the bash completion script to a file"
77

8-
usage "completely generate [CONFIG_PATH SCRIPT_PATH --function NAME --wrap NAME]"
8+
usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]"
99
usage "completely generate (-h|--help)"
1010

1111
option_function
1212
option "-w --wrap NAME", "Wrap the completion script inside a function that echos the script. This is useful if you wish to embed it directly in your script"
1313

1414
param_config_path
15-
param "SCRIPT_PATH", "Path to the output bash script. When not provided, the name of the input file will be used with a .bash extension\nCan also be set by an environment variable"
15+
param "OUTPUT_PATH", "Path to the output bash script. When not provided, the name of the input file will be used with a .bash extension\nCan also be set by an environment variable"
1616

1717
environment_config_path
18-
environment "COMPLETELY_SCRIPT_PATH", "Path to the output bash script"
18+
environment "COMPLETELY_OUTPUT_PATH", "Path to the output bash script"
1919
environment_debug
2020

2121
def run
2222
wrap = args['--wrap']
2323
output = wrap ? wrapper_function(wrap) : script
24-
File.write script_path, output
25-
say "Saved !txtpur!#{script_path}"
24+
File.write output_path, output
25+
say "Saved !txtpur!#{output_path}"
2626
syntax_warning unless completions.valid?
2727
end
2828

lib/completely/commands/test.rb

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class Test < Base
99
This command can be used to test that any completion script (either generated by compeltely or not) responds with the right completions.
1010
1111
In order to test on a completely configuration file other than 'completely.yaml', set the COMPLETELY_CONFIG_PATH environemnt variable.
12-
13-
In order to test on an arbitrary completions script, set the COMPLETELY_SCRIPT_PATH and optionally the COMPLETELY_SCRIPT_FUNCTION environment variables.
1412
EOF
1513

1614
usage "completely test COMPLINE"
@@ -19,21 +17,12 @@ class Test < Base
1917
param "COMPLINE", "The command to test completions for. This will be handled as if a TAB was pressed immediately at the end of it, so the last word is considered the active cursor. If you wish to complete for the next word instead, end your command with a space."
2018

2119
environment_config_path
22-
environment "COMPLETELY_SCRIPT_PATH", "Path to a completions script. When set, this script will be tested instead of the completely configuration file"
23-
environment "COMPLETELY_SCRIPT_FUNCTION", "The main completion function to call when using a custom script. If not set, the basename of the script path will be used, prefixed by an underscore"
2420
environment_debug
2521

2622
example %q[completely test "mygit pu"]
2723
example %q[completely test "mygit pull "]
28-
example <<~EOF
29-
COMPLETELY_SCRIPT_PATH=/usr/share/bash-completion/completions/chown \\
30-
completely test "chown --"
31-
EOF
32-
33-
attr_reader :config, :script_path, :script_function
3424

3525
def run
36-
set_vars
3726
puts tester.test(compline).join "\n"
3827
end
3928

@@ -44,26 +33,10 @@ def compline
4433
end
4534

4635
def tester
47-
if config
48-
completions = Completions.load config
49-
completions.tester
50-
else
51-
Tester.new script_path: script_path, function_name: script_function
52-
end
36+
completions = Completions.load config_path
37+
completions.tester
5338
end
5439

55-
def set_vars
56-
if ENV['COMPLETELY_CONFIG_PATH']
57-
@config = ENV['COMPLETELY_CONFIG_PATH']
58-
elsif ENV['COMPLETELY_SCRIPT_PATH']
59-
@script_path = ENV['COMPLETELY_SCRIPT_PATH']
60-
@script_function = ENV['COMPLETELY_SCRIPT_FUNCTION'] || "_#{File.basename(script_path)}"
61-
elsif File.exist? 'completely.yaml'
62-
@config = 'completely.yaml'
63-
else
64-
raise "Please set the proper environment variables or run in a folder with completely.yaml"
65-
end
66-
end
6740
end
6841
end
6942
end

lib/completely/templates/template.erb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
# Modifying it manually is not recommended
66

77
<%= function_name %>() {
8-
local cur compline
9-
_init_completion -s || return
10-
11-
cur=${COMP_WORDS[COMP_CWORD]}
12-
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
8+
local cur=${COMP_WORDS[COMP_CWORD]}
9+
local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
1310

1411
% if ENV['COMPLETELY_DEBUG']
1512
if [[ -n "$COMPLETELY_DEBUG" ]]; then

lib/completely/templates/tester-template.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
# END OF COMPLETION SCRIPT
55

6-
source /usr/share/bash-completion/bash_completion
76
COMP_WORDS=( <%= compline %> )
87
COMP_LINE="<%= compline %>"
98
COMP_POINT=${#COMP_LINE}

spec/approvals/cli/generate/help

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Generate the bash completion script to a file
22

33
Usage:
4-
completely generate [CONFIG_PATH SCRIPT_PATH --function NAME --wrap NAME]
4+
completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]
55
completely generate (-h|--help)
66

77
Options:
@@ -20,7 +20,7 @@ Parameters:
2020
Path to the YAML configuration file [default: completely.yaml]
2121
Can also be set by an environment variable
2222

23-
SCRIPT_PATH
23+
OUTPUT_PATH
2424
Path to the output bash script. When not provided, the name of the input
2525
file will be used with a .bash extension
2626
Can also be set by an environment variable
@@ -29,7 +29,7 @@ Environment Variables:
2929
COMPLETELY_CONFIG_PATH
3030
Path to a completely configuration file [default: completely.yaml]
3131

32-
COMPLETELY_SCRIPT_PATH
32+
COMPLETELY_OUTPUT_PATH
3333
Path to the output bash script
3434

3535
COMPLETELY_DEBUG

spec/approvals/cli/generated-script

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
# Modifying it manually is not recommended
66

77
_mygit_completions() {
8-
local cur compline
9-
_init_completion -s || return
10-
11-
cur=${COMP_WORDS[COMP_CWORD]}
12-
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
8+
local cur=${COMP_WORDS[COMP_CWORD]}
9+
local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
1310

1411
case "$compline" in
1512
'status'*)

spec/approvals/cli/generated-script-alt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
# Modifying it manually is not recommended
66

77
_mycomps() {
8-
local cur compline
9-
_init_completion -s || return
10-
11-
cur=${COMP_WORDS[COMP_CWORD]}
12-
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
8+
local cur=${COMP_WORDS[COMP_CWORD]}
9+
local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
1310

1411
case "$compline" in
1512
'status'*)

spec/approvals/cli/generated-wrapped-script

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ give_comps() {
66
echo $'# Modifying it manually is not recommended'
77
echo $''
88
echo $'_mygit_completions() {'
9-
echo $' local cur compline'
10-
echo $' _init_completion -s || return'
11-
echo $''
12-
echo $' cur=${COMP_WORDS[COMP_CWORD]}'
13-
echo $' compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"'
9+
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
10+
echo $' local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"'
1411
echo $''
1512
echo $' case "$compline" in'
1613
echo $' \'status\'*)'

0 commit comments

Comments
 (0)