completely 0.4.3 → 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: 207f7cf5e1b259c6cb7e9006f59cbf22b2096456707ef8d42edddbc6b0dc4e4e
4
- data.tar.gz: 51e59317f307d3da3e09f7a30092970607000be5c7a11e4276e378dd0a41bb78
3
+ metadata.gz: 6b9ace97a98b6c4feff7f5b755481317583de3330f2fc7be077d161ace8fa5e2
4
+ data.tar.gz: fabc15cb7f3665327ece094530751506febc080c5158282bfee3ab874da8988a
5
5
  SHA512:
6
- metadata.gz: 4eaaacc3785c367510802ad2945057d1ecc50fbfd8ddbcba08234a80b73c12adbe6157c0fd9726e9eb2a9f043470bccac9fdd45bea767edce94b4b47e0dc6912
7
- data.tar.gz: fc79892cbbe2647aa5647ea68d6fe29ef3b91b0686565e16ce9e6c784157539ab728dce24c4991234c1a1756facca1b0aa019c9654a1fa90b91a7d8476ea3de8
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
@@ -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
- while read; do COMPREPLY+=( "$REPLY" ); done < <( compgen <%= pattern.compgen %> -- "$cur" )
41
+ while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen <%= pattern.compgen %> -- "$cur" )
23
42
  ;;
24
43
 
25
44
  % end
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = "0.4.3"
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.3
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-07-14 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