completely 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d6353c59bdf0d9ea55a2618a06f40b14d844ad7d40827d50f3bb38949b5263f
4
- data.tar.gz: bbdcddef491b55bc6554fdcdf804b48bfddddbe744360bff99a19e9e105f2b2b
3
+ metadata.gz: e03a96457b69bced5091cb3a335f60da59ed7629d836f985f6bef54e89f8d827
4
+ data.tar.gz: fb9fdf6333328841bb45fd65a6428571934602f13d5c7f1b555bc6dc7120c224
5
5
  SHA512:
6
- metadata.gz: 5fab1170310c441fded2bdac3770edbaab6ce20100be7b005971371361513926b5492016e4abacf0bceb528824c1f80b30d1874d4bd6d8bb566e4f3ebaebd23e
7
- data.tar.gz: 01cdc71f95b09bc73492c2d65fd70e272505e1d5145d5aabe69a58cdab1a924316f9919951dbbf64243a24c0c435d60ca4e2f559d843716c82e27352f5f4bf1c
6
+ metadata.gz: b085523a2bb092c928fd6ff908baef5e5e1c0c68775688ea5e1a31ba77e19c09acfd17c19395f513a44eae88c9ab36cb28784e6ddae1afda46053d8de3f79981
7
+ data.tar.gz: '0835d18cf9bf62f98c794368d39173263890856fe15ee601455b272ac5944a311a7bfee3e9eb6b8aa9ea215c2cd4713b7b5eb5e9c2c8cfb89764149064b41273'
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Completely - Bash Completions Generator
2
2
 
3
+ ![repocard](https://repocard.dannyben.com/svg/completely.svg)
4
+
3
5
  Completely is a command line utility and a Ruby library that lets you generate
4
6
  bash completion scripts from simple YAML configuration.
5
7
 
@@ -60,7 +60,7 @@ module Completely
60
60
  end
61
61
 
62
62
  def show(content) = puts content
63
-
63
+
64
64
  def save(content)
65
65
  File.write output_path, content
66
66
  say "Saved m`#{output_path}`"
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module Completely
2
4
  class Installer
3
5
  class << self
@@ -38,18 +40,8 @@ module Completely
38
40
  @script_path = script_path
39
41
  end
40
42
 
41
- def target_directories
42
- @target_directories ||= %W[
43
- /usr/share/bash-completion/completions
44
- /usr/local/etc/bash_completion.d
45
- #{Dir.home}/.local/share/bash-completion/completions
46
- #{Dir.home}/.bash_completion.d
47
- ]
48
- end
49
-
50
43
  def install_command
51
- result = root_user? ? [] : %w[sudo]
52
- result + %W[cp #{script_path} #{target_path}]
44
+ %W[cp #{script_path} #{target_path}]
53
45
  end
54
46
 
55
47
  def install_command_string
@@ -57,8 +49,7 @@ module Completely
57
49
  end
58
50
 
59
51
  def uninstall_command
60
- result = root_user? ? [] : %w[sudo]
61
- result + %w[rm -f] + target_directories.map { |dir| "#{dir}/#{program}" }
52
+ %W[rm -f #{target_path}]
62
53
  end
63
54
 
64
55
  def uninstall_command_string
@@ -70,14 +61,12 @@ module Completely
70
61
  end
71
62
 
72
63
  def install(force: false)
73
- unless completions_path
74
- raise InstallError, 'Cannot determine system completions directory'
75
- end
76
-
77
64
  unless script_exist?
78
65
  raise InstallError, "Cannot find script: m`#{script_path}`"
79
66
  end
80
67
 
68
+ FileUtils.mkdir_p completions_path
69
+
81
70
  if target_exist? && !force
82
71
  raise InstallError, "File exists: m`#{target_path}`"
83
72
  end
@@ -99,22 +88,20 @@ module Completely
99
88
  File.exist? script_path
100
89
  end
101
90
 
102
- def root_user?
103
- Process.uid.zero?
91
+ def completions_path
92
+ @completions_path ||= "#{user_completions_base_dir}/completions"
104
93
  end
105
94
 
106
- def completions_path
107
- @completions_path ||= begin
108
- result = nil
109
- target_directories.each do |target|
110
- if Dir.exist? target
111
- result = target
112
- break
113
- end
114
- end
95
+ def user_completions_base_dir
96
+ @user_completions_base_dir ||= bash_completion_user_dir || "#{data_home}/bash-completion"
97
+ end
115
98
 
116
- result
117
- end
99
+ def bash_completion_user_dir
100
+ ENV['BASH_COMPLETION_USER_DIR']&.split(':')&.find { |entry| !entry.empty? }
101
+ end
102
+
103
+ def data_home
104
+ ENV['XDG_DATA_HOME'] || "#{Dir.home}/.local/share"
118
105
  end
119
106
  end
120
107
  end
@@ -54,8 +54,16 @@ module Completely
54
54
  def compgen!
55
55
  result = []
56
56
  result << actions.join(' ').to_s if actions.any?
57
- result << %[-W "$(#{function_name} "#{words.join ' '}")"] if words.any?
57
+ result << %[-W "$(#{function_name} #{quoted_words.join ' '})"] if words.any?
58
58
  result.any? ? result.join(' ') : nil
59
59
  end
60
+
61
+ def quoted_words
62
+ @quoted_words ||= words.map { |word| %("#{escape_for_double_quotes word}") }
63
+ end
64
+
65
+ def escape_for_double_quotes(word)
66
+ word.gsub(/["\\]/, '\\\\\&')
67
+ end
60
68
  end
61
69
  end
@@ -5,9 +5,10 @@
5
5
  # Modifying it manually is not recommended
6
6
 
7
7
  <%= function_name %>_filter() {
8
- local words="$1"
8
+ local words=("$@")
9
9
  local cur=${COMP_WORDS[COMP_CWORD]}
10
10
  local result=()
11
+ local want_options=0
11
12
 
12
13
  # words the user already typed (excluding the command itself)
13
14
  local used=()
@@ -15,28 +16,26 @@
15
16
  used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
16
17
  fi
17
18
 
18
- if [[ "${cur:0:1}" == "-" ]]; then
19
- # Completing an option: offer everything (including options)
20
- echo "$words"
21
-
22
- else
23
- # Completing a non-option: offer only non-options,
24
- # and don't re-offer ones already used earlier in the line.
25
- for word in $words; do
19
+ # Completing an option: offer everything.
20
+ # Completing a non-option: drop options and already-used words.
21
+ [[ "${cur:0:1}" == "-" ]] && want_options=1
22
+ for word in "${words[@]}"; do
23
+ if ((!want_options)); then
26
24
  [[ "${word:0:1}" == "-" ]] && continue
27
25
 
28
- local seen=0
29
26
  for u in "${used[@]}"; do
30
27
  if [[ "$u" == "$word" ]]; then
31
- seen=1
32
- break
28
+ continue 2
33
29
  fi
34
30
  done
35
- ((!seen)) && result+=("$word")
36
- done
31
+ fi
37
32
 
38
- echo "${result[*]}"
39
- fi
33
+ # compgen -W expects shell-escaped words in one space-delimited string.
34
+ printf -v word '%q' "$word"
35
+ result+=("$word")
36
+ done
37
+
38
+ echo "${result[*]}"
40
39
  }
41
40
 
42
41
  <%= function_name %>() {
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = '0.7.3'
2
+ VERSION = '0.7.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.6.9
91
+ rubygems_version: 4.0.6
92
92
  specification_version: 4
93
93
  summary: Bash Completions Generator
94
94
  test_files: []