Module: Tabry::Shells::Bash
- Defined in:
- lib/tabry/shells/bash.rb
Class Method Summary collapse
-
.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.
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
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tabry/shells/bash.rb', line 6 def self.generate(cmd_name, tabry_file_path) capitalized_cmd_name = cmd_name.upcase.gsub(/[^a-zA-Z0-9_]/, '_') tabry_file = Shellwords.escape(File.(tabry_file_path)) path_to_tabry = Shellwords.escape(File.("#{__dir__}/../../../")) core = File.read("#{__dir__}/../../../sh/bash/tabry_bash_core.sh") core.gsub! "_tabry_completions_internal()", "_tabry_#{capitalized_cmd_name}_completions_internal()" return <<~END + core # The following Autocomplete is for a Tabry-powered command. It was # generated by the command itself. See the documentation located in # #{path_to_tabry}/sh/bash/README.md _tabry_#{capitalized_cmd_name}_completions() { TABRY_IMPORTS_PATH=#{tabry_file} _tabry_#{capitalized_cmd_name}_completions_internal #{path_to_tabry}/bin/tabry-bash } complete -F _tabry_#{capitalized_cmd_name}_completions #{Shellwords.escape cmd_name} END end |