Class: Yap::Shell::Evaluation::ShellExpansions
- Inherits:
-
Object
- Object
- Yap::Shell::Evaluation::ShellExpansions
- Defined in:
- lib/yap/shell/evaluation/shell_expansions.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#world ⇒ Object
readonly
Returns the value of attribute world.
Instance Method Summary collapse
- #expand_aliases_in(input) ⇒ Object
- #expand_variables_in(input) ⇒ Object
- #expand_words_in(input, escape_directory_expansions: true) ⇒ Object
-
#initialize(world:, aliases: Aliases.instance) ⇒ ShellExpansions
constructor
A new instance of ShellExpansions.
Constructor Details
#initialize(world:, aliases: Aliases.instance) ⇒ ShellExpansions
Returns a new instance of ShellExpansions.
6 7 8 9 |
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 6 def initialize(world:, aliases: Aliases.instance) @world = world @aliases = aliases end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
4 5 6 |
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 4 def aliases @aliases end |
#world ⇒ Object (readonly)
Returns the value of attribute world.
4 5 6 |
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 4 def world @world end |
Instance Method Details
#expand_aliases_in(input) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 11 def (input) Treefell['shell'].puts "shell-expansions expand aliases in: #{input.inspect}" head, *tail = input.split(/\s/, 2).first = if aliases.has_key?(head) new_head=aliases.fetch_alias(head) [new_head].concat(tail).join(" ") else input end end |
#expand_variables_in(input) ⇒ Object
34 35 36 37 |
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 34 def (input) Treefell['shell'].puts "shell-expansions expand variables in: #{input.inspect}" (input) end |
#expand_words_in(input, escape_directory_expansions: true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 23 def (input, escape_directory_expansions: true) Treefell['shell'].puts "shell-expansions expand words in: #{input.inspect}" = [input].flatten.inject([]) do |results,str| results << process_expansions( (str), escape_directory_expansions: escape_directory_expansions ) end.flatten end |