Module: Pry::VTermAliases

Defined in:
lib/pry-vterm_aliases.rb,
lib/pry-vterm_aliases/version.rb

Defined Under Namespace

Modules: ObjectExt

Constant Summary collapse

VERSION =
"1.3.0"

Class Method Summary collapse

Class Method Details

.aliasesObject



29
30
31
32
33
34
# File 'lib/pry-vterm_aliases.rb', line 29

def aliases
  @aliases ||= if shell.nil? || shell.empty?
    then {}
    else find_aliases
  end
end

.create_alias(als, desc = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pry-vterm_aliases.rb', line 16

def create_alias(als, desc = nil)
  Pry::Commands.create_command(cmd_regexp(als), listing: ".#{als}") do
    description "alias to: #{Pry::Helpers::Text.bold(desc)}." if desc
    group "Terminal Aliases"

    def process(cmd, extra)
      Pry::VTermAliases.run_alias(
        cmd, extra, output
      )
    end
  end
end

.create_aliasesObject



8
9
10
11
12
13
14
# File 'lib/pry-vterm_aliases.rb', line 8

def create_aliases
  aliases.each do |a, c|
    create_alias(
      a, c
    )
  end
end

.run_alias(cmd, extra, output) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
# File 'lib/pry-vterm_aliases.rb', line 40

def run_alias(cmd, extra, output)
  raise ArgumentError, "unknown alias" unless (cmd = aliases[cmd])
  output.puts(`#{cmd}#{" " + extra if extra}`)
  $?.success?
end

.shellObject



36
37
38
# File 'lib/pry-vterm_aliases.rb', line 36

def shell
  @shell ||= ENV["SHELL"].split("/").last
end