Module: Yarsh
- Included in:
- Shell
- Defined in:
- lib/yarsh.rb,
lib/yarsh.rb,
lib/yarsh/shell.rb,
lib/yarsh/config.rb,
lib/yarsh/prompt.rb,
lib/yarsh/version.rb,
lib/yarsh/multiline.rb,
lib/yarsh/instance_methods.rb,
lib/yarsh/ansi_color_formatter.rb,
sig/yarsh.rbs
Defined Under Namespace
Modules: InstanceMethods, Multiline, Prompt
Classes: AnsiColorFormatter, Config, Error, ExecOutput, InvalidPromptError, Shell
Constant Summary
collapse
- YARSH_DIR =
'~/.yarsh'
- HISTORY_FILE =
File.join Yarsh::YARSH_DIR, 'history'
- CONFIG_FILE =
File.join Yarsh::YARSH_DIR, 'config'
- VERSION =
'0.2.0'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.console ⇒ Object
86
87
88
89
|
# File 'lib/yarsh.rb', line 86
def self.console
require 'irb'
IRB.start(__FILE__)
end
|
.current_shell ⇒ Object
39
40
41
|
# File 'lib/yarsh.rb', line 39
def self.current_shell
@current_shell
end
|
.current_shell=(shell) ⇒ Object
43
44
45
|
# File 'lib/yarsh.rb', line 43
def self.current_shell=(shell)
@current_shell = shell
end
|
.execute_system_command(command) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/yarsh.rb', line 68
def self.execute_system_command(command)
Open3.popen3(command) do |input, output, error, wait_thread|
output_printer = Thread.new do
output.read.tap { |data| print data }
end
error_printer = Thread.new do
error.read.tap { |data| $stderr.print data }
end
Thread.new do
input.write($stdin.read)
end
output_printer.join
error_printer.join
wait_thread.value
end
end
|
.expand_aliases(input, aliases) ⇒ Object
in a Shell input, find all command matching the keys of aliases and replace them with
the values. Leading and trailing whitespace around the match is preserved.
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/yarsh.rb', line 49
def self.expand_aliases(input, aliases)
return input if aliases.empty?
terms = aliases.keys.map { |k| Regexp.escape(k.to_s) }.join('|')
regex = Regexp.new(/(^| +)(#{terms})(?![A-Za-z0-9_])/)
input.gsub(regex) do |match|
rep = aliases[match.strip]
next match unless rep
match[/\A( +)/, 1].to_s + rep
end
end
|
Instance Method Details
#shell_path?(input) ⇒ Boolean
62
63
64
65
66
|
# File 'lib/yarsh.rb', line 62
def shell_path?(input)
input.match?(%r{\A\.\.?/}) ||
input.match?(%r{\A/}) ||
input.match?(/\A~/)
end
|