completely 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2012c5d2e6bdbdc4105a86bb535bcaacec54623b75ed4a68dfed59d7283b806f
4
- data.tar.gz: 35b022231df795d3820c3c22df622351a83c8c5720becde6ce4cde05cccb5643
3
+ metadata.gz: 6b9ace97a98b6c4feff7f5b755481317583de3330f2fc7be077d161ace8fa5e2
4
+ data.tar.gz: fabc15cb7f3665327ece094530751506febc080c5158282bfee3ab874da8988a
5
5
  SHA512:
6
- metadata.gz: cabb44f5d2e22d3fcaf2dba81c8bcca443f3ae06ce2201023cd7babd2f93792c754e97d1816a649b23139cb0b89d1ed4a23cbe875774cfa6f68bd0f055dfeb68
7
- data.tar.gz: 9c74a483866d9b1b487f721d8ea19ea8523906986992d7df64b2b96945898ba667641c9d849f23ccdb9453635ecf088f1651b7d8346566eb7fd461fa4e76e170
6
+ metadata.gz: 69f420158e1cc0cfae093d9fdd05295467d883c02d0648a1a3caab29787da3f9ad15d599328528910a7282a8518df80b64f1821e128365fdb6c3547a526b55a0
7
+ data.tar.gz: 5e978c0f507474f8a8ae3e5c57111de33098b266ea661f659f1b4b4f7c4838b0e4da448bd55987662ae0e645b5ce542c675198624f638cfeb8999161b2625d42
data/README.md CHANGED
@@ -32,7 +32,13 @@ or with homebrew:
32
32
  ```bash
33
33
  $ brew install brew-gem
34
34
  $ brew gem install completely
35
- ````
35
+ ```
36
+
37
+ or with Docker:
38
+
39
+ ```bash
40
+ $ alias completely='docker run --rm -it --user $(id -u):$(id -g) --volume "$PWD:/app" dannyben/completely'
41
+ ```
36
42
 
37
43
  ## Using the `completely` command line
38
44
 
@@ -91,6 +97,9 @@ Each pattern in this configuration file will be checked against the user's
91
97
  input, and if the input **starts with** a matching pattern, the list that
92
98
  follows it will be suggested as completions.
93
99
 
100
+ Note that the suggested completions will not show flags (string that start with
101
+ a hyphen `-`) unless the input ends with a hyphen.
102
+
94
103
  To generate the bash script, simply run:
95
104
 
96
105
  ```bash
@@ -250,6 +259,17 @@ puts completions.wrapper_function "custom_function_name"
250
259
  p completions.tester.test "mygit status "
251
260
  ```
252
261
 
262
+ ## Completions in ZSH
263
+
264
+ If you are using Oh-My-Zsh, bash completions should already be enabled,
265
+ otherwise, you should enable completion by adding this to your `~/.zshrc`
266
+ (if is it not already there):
267
+
268
+ ```bash
269
+ # Load completion functions
270
+ autoload -Uz +X compinit && compinit
271
+ autoload -Uz +X bashcompinit && bashcompinit
272
+ ```
253
273
 
254
274
  ## Contributing / Support
255
275
 
@@ -5,15 +5,13 @@ module Completely
5
5
  class Test < Base
6
6
  summary "Test completions"
7
7
 
8
- help <<~EOF
9
- This command can be used to test that any completion script (either generated by compeltely or not) responds with the right completions.
8
+ help "This command can be used to test that your completions script responds with the right completions. It works by reading your completely.yaml file, generating a completions script, and generating a temporary testing script."
10
9
 
11
- In order to test on a completely configuration file other than 'completely.yaml', set the COMPLETELY_CONFIG_PATH environemnt variable.
12
- EOF
13
-
14
- usage "completely test COMPLINE"
10
+ usage "completely test [--keep] COMPLINE"
15
11
  usage "completely test (-h|--help)"
16
12
 
13
+ option "-k --keep", "Keep the temporary testing script in the current directory"
14
+
17
15
  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."
18
16
 
19
17
  environment_config_path
@@ -24,6 +22,10 @@ module Completely
24
22
 
25
23
  def run
26
24
  puts tester.test(compline).join "\n"
25
+ if args['--keep']
26
+ File.write 'completely-tester.sh', tester_script
27
+ puts 'saved completely-tester.sh'
28
+ end
27
29
  end
28
30
 
29
31
  private
@@ -32,9 +34,16 @@ module Completely
32
34
  args['COMPLINE']
33
35
  end
34
36
 
37
+ def completions
38
+ @completions ||= Completions.load config_path
39
+ end
40
+
35
41
  def tester
36
- completions = Completions.load config_path
37
- completions.tester
42
+ @tester ||= completions.tester
43
+ end
44
+
45
+ def tester_script
46
+ @tester_script ||= tester.tester_script compline
38
47
  end
39
48
 
40
49
  end
@@ -54,7 +54,7 @@ module Completely
54
54
 
55
55
  def patterns!
56
56
  config.map do |text, completions|
57
- Pattern.new text, completions
57
+ Pattern.new text, completions, pattern_function_name
58
58
  end.sort_by { |pattern| -pattern.length }
59
59
  end
60
60
 
@@ -74,6 +74,10 @@ module Completely
74
74
  @function_name ||= "_#{command}_completions"
75
75
  end
76
76
 
77
+ def pattern_function_name
78
+ @pattern_function_name ||= "#{function_name}_filter"
79
+ end
80
+
77
81
  def pattern_prefixes
78
82
  patterns.map &:prefix
79
83
  end
@@ -1,10 +1,11 @@
1
1
  module Completely
2
2
  class Pattern
3
- attr_reader :text, :completions
3
+ attr_reader :text, :completions, :function_name
4
4
 
5
- def initialize(text, completions)
5
+ def initialize(text, completions, function_name)
6
6
  @text = text
7
7
  @completions = completions || []
8
+ @function_name = function_name
8
9
  end
9
10
 
10
11
  def length
@@ -53,7 +54,7 @@ module Completely
53
54
  def compgen!
54
55
  result = []
55
56
  result << %Q[#{actions.join ' '}] if actions.any?
56
- result << %Q[-W "#{words.join ' '}"] if words.any?
57
+ result << %Q[-W "$(#{function_name} "#{words.join ' '}")"] if words.any?
57
58
  result.any? ? result.join(' ') : nil
58
59
  end
59
60
  end
@@ -4,9 +4,28 @@
4
4
  # completely (https://github.com/dannyben/completely)
5
5
  # Modifying it manually is not recommended
6
6
 
7
+ <%= function_name %>_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
+
7
25
  <%= function_name %>() {
8
26
  local cur=${COMP_WORDS[COMP_CWORD]}
9
- local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
27
+ local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
28
+ local compline="${compwords[*]}"
10
29
 
11
30
  % if ENV['COMPLETELY_DEBUG']
12
31
  if [[ -n "$COMPLETELY_DEBUG" ]]; then
@@ -19,7 +38,7 @@
19
38
  % patterns.each do |pattern|
20
39
  % next if pattern.empty?
21
40
  <%= pattern.case_string %>)
22
- COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur"))
41
+ while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen <%= pattern.compgen %> -- "$cur" )
23
42
  ;;
24
43
 
25
44
  % end
@@ -1,7 +1,14 @@
1
1
  #!/usr/bin/env bash
2
+ if [[ -n $ZSH_VERSION ]]; then
3
+ autoload -U +X bashcompinit && bashcompinit
4
+ autoload -U +X compinit && compinit
5
+ fi
6
+
7
+ # === COMPLETION SCRIPT START ===
8
+
2
9
  <%= script || %Q[source "#{absolute_script_path}"] %>
3
10
 
4
- # END OF COMPLETION SCRIPT
11
+ # === COMPLETION SCRIPT END ===
5
12
 
6
13
  COMP_WORDS=( <%= compline %> )
7
14
  COMP_LINE="<%= compline %>"
@@ -9,4 +16,7 @@ COMP_POINT=${#COMP_LINE}
9
16
  COMP_CWORD=<%= cword %>
10
17
 
11
18
  <%= function_name %>
12
- echo "${COMPREPLY[*]}"
19
+ for suggestion in "${COMPREPLY[@]}"; do
20
+ echo "$suggestion"
21
+ done
22
+
@@ -14,7 +14,7 @@ module Completely
14
14
  f << tester_script(compline)
15
15
  f.flush
16
16
  `bash #{f.path}`
17
- end.split " "
17
+ end.split "\n"
18
18
  end
19
19
 
20
20
  def tester_script(compline)
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-21 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.3.3
83
+ rubygems_version: 3.3.14
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Bash Completions Generator