Module: Envo::Shell::Bash
Constant Summary collapse
- LIST_SEP =
':'
Instance Method Summary collapse
- #ar_to_list(ar) ⇒ Object
- #cmd_set_env_var(name, value) ⇒ Object
- #cmd_unset_env_var(name) ⇒ Object
- #fix_path(path) ⇒ Object
- #home_var_name ⇒ Object
- #installer ⇒ Object
- #likely_abs_path?(val) ⇒ Boolean
- #likely_list?(val) ⇒ Boolean
- #likely_rel_path?(val) ⇒ Boolean
- #list_to_ar(list) ⇒ Object
- #path_var_name ⇒ Object
Instance Method Details
#ar_to_list(ar) ⇒ Object
50 51 52 |
# File 'lib/envo/shell/bash.rb', line 50 def ar_to_list(ar) ar.join(LIST_SEP) end |
#cmd_set_env_var(name, value) ⇒ Object
54 55 56 57 |
# File 'lib/envo/shell/bash.rb', line 54 def cmd_set_env_var(name, value) escaped = value.to_s.inspect.gsub("'"){ "\\'" } "export #{name}=#{escaped}" end |
#cmd_unset_env_var(name) ⇒ Object
58 59 60 |
# File 'lib/envo/shell/bash.rb', line 58 def cmd_unset_env_var(name) "unset -v #{name}" end |
#fix_path(path) ⇒ Object
23 24 25 |
# File 'lib/envo/shell/bash.rb', line 23 def fix_path(path) path end |
#home_var_name ⇒ Object
13 14 15 |
# File 'lib/envo/shell/bash.rb', line 13 def home_var_name 'HOME' end |
#installer ⇒ Object
6 7 8 |
# File 'lib/envo/shell/bash.rb', line 6 def installer Cli::InstallerBash end |
#likely_abs_path?(val) ⇒ Boolean
17 18 19 |
# File 'lib/envo/shell/bash.rb', line 17 def likely_abs_path?(val) !val.empty? && val[0] == '/' end |
#likely_list?(val) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/envo/shell/bash.rb', line 28 def likely_list?(val) # we have some work # if the value includes our list separtor ":", we need to make sure whether a url:port combination is not a better fit return false if !val.include?(LIST_SEP) sep_cnt = val.count(LIST_SEP) return true if sep_cnt > 2 # match scheme://url return false if val =~ /^\w+\:\/\// return true if sep_cnt == 2 # everything else with 2 separators is a list # match display type strings address:digit.digit return false if val =~ /\:\d.\d$/ # match something:number to be interpreted as addr:port !(val =~ /.*\:\d+$/) end |
#likely_rel_path?(val) ⇒ Boolean
20 21 22 |
# File 'lib/envo/shell/bash.rb', line 20 def likely_rel_path?(val) return !val.empty? && val[0] == '.' end |
#list_to_ar(list) ⇒ Object
47 48 49 |
# File 'lib/envo/shell/bash.rb', line 47 def list_to_ar(list) list.split(LIST_SEP) end |
#path_var_name ⇒ Object
10 11 12 |
# File 'lib/envo/shell/bash.rb', line 10 def path_var_name 'PATH' end |