Module: Tabry::Shells::Bash

Defined in:
lib/tabry/shells/bash.rb

Class Method Summary collapse

Class Method Details

.generate(cmd_name, tabry_file_path) ⇒ Object

NOTE! This code uses sh/bash/tabry_bash_core.sh and is described in sh/bash/README.md; see that README for more info



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tabry/shells/bash.rb', line 15

def self.generate(cmd_name, tabry_file_path)
  capitalized_cmd_name = cmd_name.upcase.gsub(/[^a-zA-Z0-9_]/, "_")
  tabry_file = Shellwords.escape(File.expand_path(tabry_file_path))
  path_to_tabry = Shellwords.escape(File.expand_path("#{__dir__}/../../../"))

  core = File.read("#{__dir__}/../../../sh/bash/tabry_bash_core.sh")
  core.gsub! "_tabry_completions_internal()", "_tabry_#{capitalized_cmd_name}_completions_internal()"

  "    # The following Autocomplete is for a Tabry-powered command. It was\n    # generated by the command itself. See the documentation located in\n    # \#{path_to_tabry}/sh/bash/README.md\n    _tabry_\#{capitalized_cmd_name}_completions() {\n      TABRY_IMPORTS_PATH=\#{tabry_file} _tabry_\#{capitalized_cmd_name}_completions_internal \#{path_to_tabry}/bin/tabry-bash\n    }\n    complete -F _tabry_\#{capitalized_cmd_name}_completions \#{Shellwords.escape cmd_name}\n  END_BASH_CODE_TEMPLATE\nend\n" + core