Class: TarkinSh
Constant Summary
collapse
- SETTINGS_FILE =
"#{Dir.home}/.tarkin_sh"
- HIST_LINES =
how many history lines to save
100
Instance Attribute Summary
Attributes inherited from Cmd
#stdin, #stdout
Instance Method Summary
collapse
Methods inherited from Cmd
#cmdloop, #do_exit, #initialize, #no_help, run, #turn_off_readline
custom_exception_handlers, #define_collect_method, #doc, docs, handle, prompt, #prompt_with, #shortcut, shortcut_table, shortcuts
Constructor Details
This class inherits a constructor from Cmd
Instance Method Details
#complete_cat(args) ⇒ Object
51
52
53
|
# File 'lib/tarkin_sh.rb', line 51
def complete_cat(args)
commands.items(full_dir(@cd)).collect {|x| x[:username]}.select {|x| x.start_with? args}
end
|
#complete_cd(args) ⇒ Object
38
39
40
|
# File 'lib/tarkin_sh.rb', line 38
def complete_cd(args)
commands.dirs(full_dir(@cd)).collect {|x| x[:name]}.select {|x| x.start_with? args}
end
|
#do_cat(args) ⇒ Object
46
47
48
49
50
|
# File 'lib/tarkin_sh.rb', line 46
def do_cat(args)
args[:args].each do |item|
commands.cat(full_dir(item))
end
end
|
#do_cd(args) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/tarkin_sh.rb', line 29
def do_cd(args)
if args[:args].empty?
@cd = '/'
else
dir = args[:args].first
@cd = full_dir dir
end
end
|
#do_find(args) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/tarkin_sh.rb', line 57
def do_find(args)
if args[:args].empty?
commands.ls @cd, false
else
commands.find(args[:args])
end
end
|
#do_help(command = nil) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/tarkin_sh.rb', line 65
def do_help(command = nil)
command = command[:args].first
if command
command = translate_shortcut(command)
docs.include?(command) ? print_help(command) : no_help(command)
else
documented_commands.each {|cmd| print_help cmd}
print_undocumented_commands if undocumented_commands?
end
end
|
#do_ls(args) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/tarkin_sh.rb', line 13
def do_ls(args)
if args[:args].empty?
commands.ls @cd, args[:options].include?('l')
else
args[:args].each do |dir|
commands.ls full_dir(dir), args[:options].include?('l')
end
end
end
|
#do_pwd ⇒ Object
24
25
26
|
# File 'lib/tarkin_sh.rb', line 24
def do_pwd
write @cd
end
|
#do_shell(line) ⇒ Object
Executes a shell, perhaps should only be defined by subclasses.
79
80
81
82
83
84
85
|
# File 'lib/tarkin_sh.rb', line 79
def do_shell(line)
line = line[:original]
shell = ENV['SHELL']
write shell
write "**#{line}**"
line.empty? ? system(shell) : write(%x(#{line}).strip)
end
|