Class: WB::Shell
- Inherits:
-
Object
- Object
- WB::Shell
- Defined in:
- lib/wb/shell.rb
Class Method Summary collapse
- .append(path) ⇒ Object
- .create_file(path) ⇒ Object
- .getc ⇒ Object
- .mkdir_p_touch(path) ⇒ Object
- .open_file(path, editor: ENV["EDITOR"]) ⇒ Object
- .run(*commands) ⇒ Object
Class Method Details
.append(path) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/wb/shell.rb', line 35 def self.append(path) file = File.open(path, "a") yield file ensure $stdout.puts "Wrote to #{file.path}" file.close end |
.create_file(path) ⇒ Object
22 23 24 25 |
# File 'lib/wb/shell.rb', line 22 def self.create_file(path) mkdir_p_touch(path) path end |
.getc ⇒ Object
31 32 33 |
# File 'lib/wb/shell.rb', line 31 def self.getc $stdin.getc end |
.mkdir_p_touch(path) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/wb/shell.rb', line 12 def self.mkdir_p_touch(path) directories = File.dirname(path) filename = File.basename(path) unless File.exist?(directories) FileUtils.mkdir_p(directories) end FileUtils.touch(path) $stdout.puts "#{path} created" end |
.open_file(path, editor: ENV["EDITOR"]) ⇒ Object
27 28 29 |
# File 'lib/wb/shell.rb', line 27 def self.open_file(path, editor: ENV["EDITOR"]) run(editor, path) end |
.run(*commands) ⇒ Object
7 8 9 10 |
# File 'lib/wb/shell.rb', line 7 def self.run(*commands) $stdout.puts commands.join(" ") system *commands end |