Class: Yap::Shell::Evaluation::ShellExpansions

Inherits:
Object
  • Object
show all
Defined in:
lib/yap/shell/evaluation/shell_expansions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aliasesObject (readonly)

Returns the value of attribute aliases.



4
5
6
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 4

def aliases
  @aliases
end

#worldObject (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 expand_aliases_in(input)
  Treefell['shell'].puts "shell-expansions expand aliases in: #{input.inspect}"
  head, *tail = input.split(/\s/, 2).first
  expanded = if aliases.has_key?(head)
    new_head=aliases.fetch_alias(head)
    [new_head].concat(tail).join(" ")
  else
    input
  end
  expanded
end

#expand_variables_in(input) ⇒ Object



34
35
36
37
# File 'lib/yap/shell/evaluation/shell_expansions.rb', line 34

def expand_variables_in(input)
  Treefell['shell'].puts "shell-expansions expand variables in: #{input.inspect}"
  env_expand(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 expand_words_in(input, escape_directory_expansions: true)
  Treefell['shell'].puts "shell-expansions expand words in: #{input.inspect}"
  expanded = [input].flatten.inject([]) do |results,str|
    results << process_expansions(
      word_expand(str),
      escape_directory_expansions: escape_directory_expansions
    )
  end.flatten
  expanded
end