bashly 1.4.0 → 2.0.0.rc2

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bashly/commands/completions.rb +3 -41
  3. data/lib/bashly/completions/README.md +3 -7
  4. data/lib/bashly/completions/bashly-completions.bash +2 -2
  5. data/lib/bashly/completions/completely.yaml +0 -4
  6. data/lib/bashly/concerns/settings_completions.rb +37 -0
  7. data/lib/bashly/config_validator.rb +18 -3
  8. data/lib/bashly/docs/arg.yml +12 -6
  9. data/lib/bashly/docs/command.yml +0 -12
  10. data/lib/bashly/docs/flag.yml +8 -4
  11. data/lib/bashly/libraries/libraries.yml +0 -15
  12. data/lib/bashly/libraries/settings/settings.yml +12 -6
  13. data/lib/bashly/script/argument.rb +17 -0
  14. data/lib/bashly/script/command.rb +1 -2
  15. data/lib/bashly/script/flag.rb +12 -1
  16. data/lib/bashly/script/introspection/commands.rb +5 -0
  17. data/lib/bashly/script/wrapper.rb +1 -1
  18. data/lib/bashly/settings.rb +7 -8
  19. data/lib/bashly/version.rb +1 -1
  20. data/lib/bashly/views/argument/completion.gtx +31 -0
  21. data/lib/bashly/views/argument/completion_filter.gtx +1 -0
  22. data/lib/bashly/views/command/completion_argument_candidates.gtx +12 -0
  23. data/lib/bashly/views/command/completion_argument_filter.gtx +25 -0
  24. data/lib/bashly/views/command/completion_command_candidates.gtx +3 -0
  25. data/lib/bashly/views/command/completion_flag_candidates.gtx +21 -0
  26. data/lib/bashly/views/command/completion_function.gtx +24 -0
  27. data/lib/bashly/views/command/completion_script.gtx +21 -0
  28. data/lib/bashly/views/command/completion_script_bash.gtx +63 -0
  29. data/lib/bashly/views/command/completion_script_zsh.gtx +52 -0
  30. data/lib/bashly/views/command/completion_word_filter.gtx +44 -0
  31. data/lib/bashly/views/command/completions.gtx +81 -0
  32. data/lib/bashly/views/command/inspect_args.gtx +3 -3
  33. data/lib/bashly/views/command/master_script.gtx +7 -4
  34. data/lib/bashly/views/command/start.gtx +12 -3
  35. data/lib/bashly/views/flag/completion.gtx +1 -0
  36. data/lib/bashly/views/flag/completion_filter.gtx +7 -0
  37. data/lib/bashly/views/flag/completion_filter_arg.gtx +10 -0
  38. data/lib/bashly/views/flag/completion_filter_block.gtx +8 -0
  39. data/lib/bashly/views/flag/completion_filter_no_arg.gtx +2 -0
  40. data/lib/bashly/views/flag/completion_value_candidates.gtx +31 -0
  41. data/lib/bashly/watch.rb +22 -50
  42. data/lib/bashly.rb +2 -5
  43. metadata +39 -39
  44. data/lib/bashly/completion_builder.rb +0 -231
  45. data/lib/bashly/concerns/completions.rb +0 -48
  46. data/lib/bashly/libraries/completions/completions_function.rb +0 -37
  47. data/lib/bashly/libraries/completions/completions_script.rb +0 -28
  48. data/lib/bashly/libraries/completions/completions_yaml.rb +0 -26
  49. /data/lib/bashly/views/wrapper/{bash3_bouncer.gtx → bash_version_bouncer.gtx} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eca947512ada2ac873e3b6d399d75b441c97eb1ac4c56f5e1e8c1017fc9389ac
4
- data.tar.gz: f340d79b2f493871f3601c3be689eaf846a4f865eabb34cb3beeaab529ddf2eb
3
+ metadata.gz: 65ab4d9e6acb0f638497f14958c9bebc78219cbb1c677d75b5f9f98506301e4c
4
+ data.tar.gz: fadcbfe0d4dcc48d6081d50f2a76bc57730ebd6e44b7c9a232350e7d072f2d3c
5
5
  SHA512:
6
- metadata.gz: 1fba0f5a53ebd3f4a209a1a4a12b7e132d20b06aba4d9dac4afa199b240f0099e39be1905a4d5db95d37255cebdf62d4c7058131b3b2ee1c2ba54a09d4054de5
7
- data.tar.gz: 688fb3b6a40e18a2d63a1bde4ddbeaa999d13c8f8b1b5487af3cfe4a1487d0fc0154422869138beed62b04cc1bc321902046ec1f805aa2226f3085b5d619e20d
6
+ metadata.gz: a775101849773351872c8f84ce312ec9d5ebc7a460bfed5858de9edf41d524c319e3dd48c424d3be30379ef79ee3e1d1e4bc4efd4b2b5164f641a3c3e47ee03e
7
+ data.tar.gz: 58ebb9d697a27856f7383d0ad69a5de4c06b21766347c769f241c1dcd947f2703bb932abf0733624e9a3fc7f475891076136d0038734cbe0b346a90b89d6192c
@@ -1,55 +1,17 @@
1
- require 'completely'
2
-
3
1
  module Bashly
4
2
  module Commands
5
3
  class Completions < Base
6
- summary 'Install bash completions for bashly itself'
7
- help 'Display the bash completions script or install it directly to your bash completions directory'
4
+ summary 'Display bash completions for bashly itself'
8
5
 
9
- usage 'bashly completions [--install|--uninstall]'
6
+ usage 'bashly completions'
10
7
  usage 'bashly completions (-h|--help)'
11
8
 
12
- option '-i --install', 'Install the completions script to your bash completions directory'
13
- option '-u --uninstall', 'Uninstall the completions script from your bash completions directory'
14
-
15
9
  def run
16
- if args['--install']
17
- install_completions
18
- elsif args['--uninstall']
19
- uninstall_completions
20
- else
21
- puts script
22
- end
23
- end
24
-
25
- def installer
26
- @installer ||= Completely::Installer.new program: 'bashly', script_path: script_path
10
+ puts script
27
11
  end
28
12
 
29
13
  private
30
14
 
31
- def install_completions
32
- success = installer.install force: true
33
- raise Error, "Failed running command:\nnb`#{installer.install_command_string}`" unless success
34
-
35
- say 'Completions installed'
36
- say "Source: m`#{installer.script_path}`"
37
- say "Target: m`#{installer.target_path}`"
38
- say 'Restart your session for the changes to take effect'
39
- end
40
-
41
- def uninstall_completions
42
- success = installer.uninstall
43
- raise Error, "Failed running command:\nnb`#{installer.uninstall_command_string}`" unless success
44
-
45
- say 'Completions uninstalled'
46
- say 'Restart your session for the changes to take effect'
47
- end
48
-
49
- def script_path
50
- @script_path ||= asset('completions/bashly-completions.bash')
51
- end
52
-
53
15
  def script
54
16
  @script ||= asset_content('completions/bashly-completions.bash')
55
17
  end
@@ -15,10 +15,6 @@ Note that for production use, only the `bashly-completions.bash` is used.
15
15
 
16
16
  ## For users
17
17
 
18
- Install completions in one of two ways:
19
-
20
- 1. Run `bashly completions --install`. This will make a best effort to copy
21
- the completions script to your completions directory.
22
- 2. If the above fails, run `bashly completions > out.bash`, then copy the file
23
- manually to your completions directory (or simply get the
24
- `bashly-completions.bash` from this directory).
18
+ Run `bashly completions > out.bash`, then copy the file manually to your
19
+ completions directory (or simply get the `bashly-completions.bash` from this
20
+ directory).
@@ -297,11 +297,11 @@ _bashly_completions() {
297
297
 
298
298
  case "$node_id:$positional_index" in
299
299
  5:0)
300
- while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "colors completions completions_script completions_yaml config help hooks ini lib render_markdown render_markdown_github render_mandoc settings stacktrace strings validations yaml" -- "$cur")
300
+ while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "colors config help hooks ini lib render_markdown render_markdown_github render_mandoc settings stacktrace strings validations yaml" -- "$cur")
301
301
  return
302
302
  ;;
303
303
  6:0)
304
- while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "arg arg.allowed arg.completions arg.default arg.help arg.name arg.repeatable arg.required arg.validate command command.alias command.args command.catch_all command.commands command.completions command.default command.dependencies command.environment_variables command.examples command.expose command.extensible command.filename command.filters command.flags command.footer command.function command.group command.help command.help_header_override command.name command.private command.variables command.version environment_variable environment_variable.default environment_variable.help environment_variable.name environment_variable.private environment_variable.required environment_variable.validate flag flag.alias flag.allowed flag.arg flag.completions flag.conflicts flag.default flag.help flag.long flag.needs flag.negatable flag.private flag.repeatable flag.required flag.short flag.unique flag.validate variable variable.name variable.value" -- "$cur")
304
+ while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "arg arg.allowed arg.completions arg.default arg.help arg.name arg.repeatable arg.required arg.validate command command.alias command.args command.catch_all command.commands command.default command.dependencies command.environment_variables command.examples command.expose command.extensible command.filename command.filters command.flags command.footer command.function command.group command.help command.help_header_override command.name command.private command.variables command.version environment_variable environment_variable.default environment_variable.help environment_variable.name environment_variable.private environment_variable.required environment_variable.validate flag flag.alias flag.allowed flag.arg flag.completions flag.conflicts flag.default flag.help flag.long flag.needs flag.negatable flag.private flag.repeatable flag.required flag.short flag.unique flag.validate variable variable.name variable.value" -- "$cur")
305
305
  return
306
306
  ;;
307
307
  8:0)
@@ -60,9 +60,6 @@ tokens:
60
60
  path:
61
61
  library:
62
62
  - colors
63
- - completions
64
- - completions_script
65
- - completions_yaml
66
63
  - config
67
64
  - help
68
65
  - hooks
@@ -91,7 +88,6 @@ tokens:
91
88
  - command.args
92
89
  - command.catch_all
93
90
  - command.commands
94
- - command.completions
95
91
  - command.default
96
92
  - command.dependencies
97
93
  - command.environment_variables
@@ -0,0 +1,37 @@
1
+ module Bashly
2
+ module SettingsCompletions
3
+ COMPLETION_SHELLS = %w[bash zsh].freeze
4
+
5
+ def completions
6
+ @completions ||= get :completions
7
+ end
8
+
9
+ def completions?
10
+ completions == 'minimal' || completion_shells.any?
11
+ end
12
+
13
+ def completion_shells
14
+ case completions
15
+ when nil, false, 'minimal' then []
16
+ when 'full' then COMPLETION_SHELLS
17
+ when String then validate_completion_shells completions
18
+ else invalid_completions
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def validate_completion_shells(value)
25
+ shells = value.split(',', -1).map(&:strip)
26
+ valid = shells.any? && (shells - COMPLETION_SHELLS).empty?
27
+ return shells if valid && shells.uniq == shells
28
+
29
+ invalid_completions
30
+ end
31
+
32
+ def invalid_completions
33
+ raise ConfigurationError,
34
+ "completions must be false, minimal, full, or a comma-separated list of: #{COMPLETION_SHELLS.join ', '}"
35
+ end
36
+ end
37
+ end
@@ -2,6 +2,8 @@ module Bashly
2
2
  class ConfigValidator
3
3
  include ValidationHelpers
4
4
 
5
+ COMPLETION_OPTIONS = %w[files directories no-space].freeze
6
+
5
7
  attr_reader :data
6
8
 
7
9
  def initialize(data)
@@ -88,6 +90,20 @@ module Bashly
88
90
  assert [true, false, nil, 'always'].include?(value), "#{key} must be a boolean, or the string 'always'"
89
91
  end
90
92
 
93
+ def assert_completions(key, value)
94
+ return unless value
95
+
96
+ assert_hash key, value, keys: %i[static dynamic options]
97
+ assert_array "#{key}.static", value['static'], of: :string
98
+ assert_array "#{key}.dynamic", value['dynamic'], of: :string
99
+ assert_array "#{key}.options", value['options'], of: :string
100
+
101
+ Array(value['options']).each do |option|
102
+ assert COMPLETION_OPTIONS.include?(option),
103
+ "#{key}.options contains an unknown option: #{option}"
104
+ end
105
+ end
106
+
91
107
  def assert_arg(key, value)
92
108
  assert_hash key, value, keys: Script::Argument.option_keys
93
109
  refute value['allowed'] && value['completions'], "#{key} cannot have both nub`allowed` and nub`completions`"
@@ -101,7 +117,7 @@ module Bashly
101
117
  assert_boolean "#{key}.unique", value['unique']
102
118
 
103
119
  assert_array "#{key}.allowed", value['allowed'], of: :string
104
- assert_array "#{key}.completions", value['completions'], of: :string
120
+ assert_completions "#{key}.completions", value['completions']
105
121
 
106
122
  refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
107
123
 
@@ -137,7 +153,7 @@ module Bashly
137
153
  assert_boolean "#{key}.required", value['required']
138
154
  assert_array "#{key}.allowed", value['allowed'], of: :string
139
155
  assert_array "#{key}.conflicts", value['conflicts'], of: :string
140
- assert_array "#{key}.completions", value['completions'], of: :string
156
+ assert_completions "#{key}.completions", value['completions']
141
157
 
142
158
  assert value['long'].match(/^--[a-zA-Z0-9_-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
143
159
  assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
@@ -236,7 +252,6 @@ module Bashly
236
252
  assert_array "#{key}.args", value['args'], of: :arg
237
253
  assert_array "#{key}.flags", value['flags'], of: :flag
238
254
  assert_array "#{key}.commands", value['commands'], of: :command
239
- assert_array "#{key}.completions", value['completions'], of: :string
240
255
  assert_array "#{key}.filters", value['filters'], of: :string
241
256
  assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
242
257
  assert_array "#{key}.variables", value['variables'], of: :var
@@ -34,15 +34,21 @@ arg.allowed:
34
34
  default: development
35
35
 
36
36
  arg.completions:
37
- help: Specify a list of additional completion suggestions when used in conjunction with `bashly add completions`.
37
+ help: |-
38
+ Configure additional runtime completions.
39
+ `static` contains literal candidates. `dynamic` contains Bash commands that
40
+ print one candidate per line. `options` accepts `files`, `directories`, and
41
+ `no-space`.
38
42
  url: https://bashly.dev/configuration/argument/#completions
39
43
  example: |-
40
44
  args:
41
- - name: path
42
- help: File or directory to process
45
+ - name: branch
46
+ help: Branch to process
43
47
  completions:
44
- - <file>
45
- - <directory>
48
+ static: [main, develop]
49
+ dynamic:
50
+ - git branch --format='%(refname:short)'
51
+ options: [no-space]
46
52
 
47
53
  arg.default:
48
54
  help: Specify the value to apply when not provided by the user.
@@ -102,4 +108,4 @@ arg.validate:
102
108
  example: |-
103
109
  args:
104
110
  - name: path
105
- validate: file_exists
111
+ validate: file_exists
@@ -74,18 +74,6 @@ command.commands:
74
74
  alias: a
75
75
  help: Register a local repository
76
76
 
77
- command.completions:
78
- help: Specify a list of additional completion suggestions when used in conjunction with `bashly add completions`.
79
- url: https://bashly.dev/configuration/command/#completions
80
- example: |-
81
- commands:
82
- - name: view
83
- help: View a directory, system user or a git branch
84
- completions:
85
- - <directory>
86
- - <user>
87
- - $(git branch 2> /dev/null)
88
-
89
77
  command.default:
90
78
  help: Specify that this sub-command will be executed implicitly.
91
79
  url: https://bashly.dev/configuration/command/#default
@@ -58,14 +58,18 @@ flag.arg:
58
58
  help: Specify the user name
59
59
 
60
60
  flag.completions:
61
- help: Specify a list of additional completion suggestions when used in conjunction with `bashly add completions`. Must be accompanied by `arg`.
61
+ help: |-
62
+ Configure additional runtime completions. Must be accompanied by `arg`.
63
+ `static` contains literal candidates. `dynamic` contains Bash commands that
64
+ print one candidate per line. `options` accepts `files`, `directories`, and
65
+ `no-space`.
62
66
  url: https://bashly.dev/configuration/flag/#completions
63
67
  example: |-
64
68
  flags:
65
- - long: --user
66
- arg: username
69
+ - long: --config
70
+ arg: file
67
71
  completions:
68
- - <user>
72
+ options: [files]
69
73
 
70
74
  # Anything in the 'allowed' option is automatically added as a completion.
71
75
  - long: --protocol
@@ -12,21 +12,6 @@ colors:
12
12
 
13
13
  m`$ bashly add hooks`
14
14
 
15
- completions:
16
- help: Generate a bash completions function.
17
- usage: '[PATH]'
18
- handler: Bashly::Libraries::CompletionsFunction
19
-
20
- completions_script:
21
- help: Generate a standalone bash completions script.
22
- usage: '[PATH]'
23
- handler: Bashly::Libraries::CompletionsScript
24
-
25
- completions_yaml:
26
- help: Generate a completions YAML configuration for Completely.
27
- usage: '[PATH]'
28
- handler: Bashly::Libraries::CompletionsYAML
29
-
30
15
  config:
31
16
  help: Add functions for handling INI configuration files to the lib directory.
32
17
  files:
@@ -157,23 +157,28 @@ env: development
157
157
  # - always # render this feature in any environment
158
158
  # - never # do not render this feature
159
159
  enable_header_comment: always
160
- enable_bash3_bouncer: always
160
+ enable_bash_version_bouncer: always
161
161
  enable_view_markers: development
162
162
  enable_inspect_args: development
163
163
  enable_deps_array: always
164
164
  enable_env_var_names_array: always
165
165
  enable_sourcing: development
166
166
 
167
+ # Generate native runtime completions. Supported values:
168
+ # - ~ or false # disable completions (default)
169
+ # - minimal # generate the runtime completion engine without shell adapters
170
+ # - bash or zsh # generate the runtime engine and one shell adapter
171
+ # - bash,zsh # generate the runtime engine and selected shell adapters
172
+ # - full # generate the runtime engine and all available shell adapters
173
+ completions: ~
174
+
167
175
 
168
176
  #-------------------------------------------------------------------------------
169
177
  # DEVELOPER OPTIONS
170
178
  #-------------------------------------------------------------------------------
171
179
 
172
- # When true, use filesystem evented watching instead of polling
173
- watch_evented: false
174
-
175
- # File change detection latency (seconds)
176
- watch_latency: 1.0
180
+ # File change detection polling interval (seconds)
181
+ watch_latency: 2.0
177
182
 
178
183
 
179
184
  #-------------------------------------------------------------------------------
@@ -192,5 +197,6 @@ var_aliases:
192
197
 
193
198
  # Choose different names for some of the internal functions.
194
199
  function_names:
200
+ start: ~
195
201
  run: ~
196
202
  initialize: ~
@@ -23,6 +23,23 @@ module Bashly
23
23
  end
24
24
  end
25
25
 
26
+ def completion_static
27
+ completions&.fetch('static', []) || []
28
+ end
29
+
30
+ def completion_dynamic
31
+ completions&.fetch('dynamic', []) || []
32
+ end
33
+
34
+ def completion_options
35
+ completions&.fetch('options', []) || []
36
+ end
37
+
38
+ def completion?
39
+ allowed&.any? || completion_static.any? ||
40
+ completion_dynamic.any? || completion_options.any?
41
+ end
42
+
26
43
  def label
27
44
  repeatable ? "#{name.upcase}..." : name.upcase
28
45
  end
@@ -1,7 +1,6 @@
1
1
  module Bashly
2
2
  module Script
3
3
  class Command < Base
4
- include Completions::Command
5
4
  include Introspection::Arguments
6
5
  include Introspection::Commands
7
6
  include Introspection::Dependencies
@@ -14,7 +13,7 @@ module Bashly
14
13
  class << self
15
14
  def option_keys
16
15
  @option_keys ||= %i[
17
- alias argfile args catch_all commands completions
16
+ alias argfile args catch_all commands
18
17
  default dependencies environment_variables examples
19
18
  extensible expose filename filters flags
20
19
  footer function group help help_header_override name
@@ -3,7 +3,6 @@ require 'shellwords'
3
3
  module Bashly
4
4
  module Script
5
5
  class Flag < Base
6
- include Completions::Flag
7
6
  include Introspection::Visibility
8
7
  include Introspection::Validate
9
8
 
@@ -44,6 +43,18 @@ module Bashly
44
43
  end
45
44
  end
46
45
 
46
+ def completion_static
47
+ completions&.fetch('static', []) || []
48
+ end
49
+
50
+ def completion_dynamic
51
+ completions&.fetch('dynamic', []) || []
52
+ end
53
+
54
+ def completion_options
55
+ completions&.fetch('options', []) || []
56
+ end
57
+
47
58
  def name
48
59
  long || short
49
60
  end
@@ -41,6 +41,11 @@ module Bashly
41
41
  commands.map(&:name)
42
42
  end
43
43
 
44
+ # Returns command names and aliases that can be offered as completions
45
+ def completion_aliases
46
+ public_commands.flat_map(&:aliases).reject { |name| name.end_with? '*' }
47
+ end
48
+
44
49
  # Returns an array of the Commands
45
50
  def commands
46
51
  return [] unless options['commands']
@@ -46,7 +46,7 @@ module Bashly
46
46
 
47
47
  def default_header
48
48
  result = render 'header'
49
- result += render('bash3_bouncer') unless function_name || !Settings.enabled?(:bash3_bouncer)
49
+ result += render('bash_version_bouncer') unless function_name || !Settings.enabled?(:bash_version_bouncer)
50
50
  result
51
51
  end
52
52
 
@@ -1,15 +1,19 @@
1
1
  module Bashly
2
2
  class Settings
3
+ COMPLETION_SHELLS = SettingsCompletions::COMPLETION_SHELLS
4
+
3
5
  class << self
4
6
  include AssetHelper
7
+ include SettingsCompletions
5
8
 
6
9
  attr_writer(
7
10
  :argfile_var,
8
11
  :commands_dir,
9
12
  :compact_short_flags,
13
+ :completions,
10
14
  :conjoined_flag_args,
11
15
  :config_path,
12
- :enable_bash3_bouncer,
16
+ :enable_bash_version_bouncer,
13
17
  :enable_deps_array,
14
18
  :enable_env_var_names_array,
15
19
  :enable_header_comment,
@@ -29,7 +33,6 @@ module Bashly
29
33
  :target_dir,
30
34
  :usage_colors,
31
35
  :var_aliases,
32
- :watch_evented,
33
36
  :watch_latency,
34
37
  :word_wrap
35
38
  )
@@ -64,8 +67,8 @@ module Bashly
64
67
  (send(:"enable_#{feature}") == 'development' && !production?)
65
68
  end
66
69
 
67
- def enable_bash3_bouncer
68
- @enable_bash3_bouncer ||= get :enable_bash3_bouncer
70
+ def enable_bash_version_bouncer
71
+ @enable_bash_version_bouncer ||= get :enable_bash_version_bouncer
69
72
  end
70
73
 
71
74
  def enable_deps_array
@@ -181,10 +184,6 @@ module Bashly
181
184
  @var_aliases ||= get :var_aliases
182
185
  end
183
186
 
184
- def watch_evented
185
- @watch_evented ||= get :watch_evented
186
- end
187
-
188
187
  def watch_latency
189
188
  @watch_latency ||= get :watch_latency
190
189
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.4.0'
2
+ VERSION = '2.0.0.rc2'
3
3
  end
@@ -0,0 +1,31 @@
1
+ if allowed
2
+ > local -a completion_values=(
3
+ allowed.each do |value|
4
+ > "{{ value }}"
5
+ end
6
+ > )
7
+ if unique
8
+ > local completion_value
9
+ > for completion_value in "${completion_values[@]}"; do
10
+ > if [[ -z "${completion_used_arguments["{{ name }}:$completion_value"]:-}" ]]; then
11
+ > completion_candidates "$completion_current" "$completion_value"
12
+ > fi
13
+ > done
14
+ else
15
+ > completion_candidates "$completion_current" "${completion_values[@]}"
16
+ end
17
+ end
18
+
19
+ if completion_static.any?
20
+ > completion_candidates "$completion_current" {{ completion_static.map { |value| Shellwords.shellescape value }.join ' ' }}
21
+ end
22
+
23
+ completion_dynamic.each do |command|
24
+ > if completion_output="$({ {{ command }}; } 2>/dev/null)"; then
25
+ > completion_dynamic_candidates "$completion_current" "$completion_output"
26
+ > fi
27
+ end
28
+
29
+ if completion_options.any?
30
+ > completion_add_options {{ completion_options.join ' ' }}
31
+ end
@@ -0,0 +1 @@
1
+ > completion_used_arguments["{{ name }}:$1"]=1
@@ -0,0 +1,12 @@
1
+ completion_args = args.each_with_index.select { |arg, _index| arg.completion? }
2
+ if completion_args.any?
3
+ > if [[ $completion_current != -* ]]; then
4
+ > case "$completion_arg_index" in
5
+ completion_args.each do |arg, index|
6
+ > {{ index }})
7
+ = arg.render(:completion).strip.indent 6
8
+ > ;;
9
+ end
10
+ > esac
11
+ > fi
12
+ end
@@ -0,0 +1,25 @@
1
+ if args.any?(&:unique)
2
+ > case "$completion_arg_index" in
3
+ args.each_with_index do |arg, index|
4
+ next unless arg.unique
5
+
6
+ > {{ index }})
7
+ = arg.render(:completion_filter).indent 4
8
+ > ;;
9
+ end
10
+ > esac
11
+ end
12
+
13
+ if args.last.repeatable
14
+ last_arg_index = args.length - 1
15
+ > if [[ $completion_arg_index -lt {{ last_arg_index }} ]]; then
16
+ > completion_arg_index=$((completion_arg_index + 1))
17
+ > fi
18
+ > shift
19
+ else
20
+ > if [[ $completion_arg_index -ge {{ args.length }} ]]; then
21
+ > return
22
+ > fi
23
+ > completion_arg_index=$((completion_arg_index + 1))
24
+ > shift
25
+ end
@@ -0,0 +1,3 @@
1
+ if completion_aliases.any?
2
+ > completion_candidates "$completion_current" {{ completion_aliases.join ' ' }}
3
+ end
@@ -0,0 +1,21 @@
1
+ if fixed_flags? || public_flags.any?
2
+ > if [[ $completion_current == -* ]]; then
3
+ if fixed_flags?
4
+ if short_flag_exist? '-h'
5
+ > completion_flag_candidates --help "$completion_current" --help
6
+ else
7
+ > completion_flag_candidates --help "$completion_current" --help -h
8
+ end
9
+ if root_command?
10
+ if short_flag_exist? '-v'
11
+ > completion_flag_candidates --version "$completion_current" --version
12
+ else
13
+ > completion_flag_candidates --version "$completion_current" --version -v
14
+ end
15
+ end
16
+ end
17
+ public_flags.each do |flag|
18
+ = flag.render(:completion).indent 2
19
+ end
20
+ > fi
21
+ end
@@ -0,0 +1,24 @@
1
+ = view_marker
2
+
3
+ > {{ function_name }}_completion() {
4
+ > local completion_current="$1"
5
+ if args.any?
6
+ > local completion_arg_index=0
7
+ end
8
+ if args.any?(&:unique)
9
+ > local -A completion_used_arguments=()
10
+ end
11
+ if flags.any?(&:unique)
12
+ > local -A completion_used_flag_values=()
13
+ end
14
+ > shift
15
+ >
16
+ = render(:completion_word_filter).indent 2
17
+ = render(:completion_command_candidates).indent 2
18
+ if default_command
19
+ > {{ default_command.function_name }}_completion "$completion_current"
20
+ end
21
+ = render(:completion_flag_candidates).indent 2
22
+ = render(:completion_argument_candidates).indent 2
23
+ > }
24
+ >
@@ -0,0 +1,21 @@
1
+ = view_marker
2
+
3
+ completion_shells = Settings.completion_shells
4
+
5
+ > send_completions() {
6
+ > local completion_shell="${1:-{{ completion_shells.first }}}"
7
+ >
8
+ > case "$completion_shell" in
9
+ completion_shells.each do |shell|
10
+ > {{ shell }}) send_completions_{{ shell }} ;;
11
+ end
12
+ > *)
13
+ > printf 'unsupported shell: %s\n' "$completion_shell" >&2
14
+ > return 1
15
+ > ;;
16
+ > esac
17
+ > }
18
+ >
19
+ completion_shells.each do |shell|
20
+ = render :"completion_script_#{shell}"
21
+ end