completely 0.7.3 → 0.7.5

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: bc1feb2ea4f84471fa2e014aed467122163556f6f92c0ec5ad536065f3789438
4
+ data.tar.gz: 747d77ca9ce9f351bd914656423f92d8501aa2e0b19789f227bbcd1130de7cb2
5
5
  SHA512:
6
- metadata.gz: 5fab1170310c441fded2bdac3770edbaab6ce20100be7b005971371361513926b5492016e4abacf0bceb528824c1f80b30d1874d4bd6d8bb566e4f3ebaebd23e
7
- data.tar.gz: 01cdc71f95b09bc73492c2d65fd70e272505e1d5145d5aabe69a58cdab1a924316f9919951dbbf64243a24c0c435d60ca4e2f559d843716c82e27352f5f4bf1c
6
+ metadata.gz: 9bd666b63af2f8a48a085d7025d39d5980eb93c796193144a29e3c730f80f9c409b99584ffbd6bbbd240819ba3af9013915ff090f04850e9bd09c01d928d056e
7
+ data.tar.gz: b2a6fa4704ba2c6004e4ceb4735a7cc92cfb24bc9e277779562180153102d1983f1716a59a829f2269042f2e02528af1d75de87196c8e86a17a043097e4c0d42
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
 
@@ -167,6 +169,13 @@ mygit:
167
169
  The `2> /dev/null` is used so that if the command is executed in a directory
168
170
  without a git repository, it will still behave as expected.
169
171
 
172
+ ### Completion scope and limitations
173
+
174
+ - Completion words are treated as whitespace-delimited tokens.
175
+ - Literal completion phrases that contain spaces are not supported as a single completion item.
176
+ - Quotes and other special shell characters in literal completion words are not escaped automatically.
177
+ - Dynamic `$(...)` completion commands should output plain whitespace-delimited words.
178
+
170
179
  ### Suggesting flag arguments
171
180
 
172
181
  Adding a `*` wildcard in the middle of a pattern can be useful for suggesting
@@ -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
@@ -49,6 +49,10 @@ module Completely
49
49
  @compgen ||= compgen!
50
50
  end
51
51
 
52
+ def filename_action?
53
+ actions.include?('-A file') || actions.include?('-A directory')
54
+ end
55
+
52
56
  private
53
57
 
54
58
  def compgen!
@@ -60,6 +60,9 @@
60
60
  % patterns.each do |pattern|
61
61
  % next if pattern.empty?
62
62
  <%= pattern.case_string %>)
63
+ % if pattern.filename_action?
64
+ compopt -o filenames 2>/dev/null
65
+ % end
63
66
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen <%= pattern.compgen %> -- "$cur")
64
67
  ;;
65
68
 
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = '0.7.3'
2
+ VERSION = '0.7.5'
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.5
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: []