Class: KTools::Sh
- Inherits:
-
Object
- Object
- KTools::Sh
- Defined in:
- lib/ktools/sh.rb
Class Method Summary collapse
-
.ell(cmd) ⇒ Object
Secure mode, asks for confirmation.
-
.ell!(cmd) ⇒ Object
Forced mode, won’t ask confirmation.
-
.ell_in!(cmd) ⇒ Object
Forced mode, won’t ask confirmation.
-
.ell_meta(cmd) ⇒ Object
Forced mode, won’t ask confirmation.
-
.ellb!(cmd) ⇒ Object
Forced mode, won’t ask confirmation.
-
.elld!(cmd) ⇒ Object
Forced mode, won’t ask confirmation.
Class Method Details
.ell(cmd) ⇒ Object
Secure mode, asks for confirmation. Shows command. Shows output.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ktools/sh.rb', line 6 def self.ell(cmd) puts "Confirmation required." puts "" puts "Command:" puts cmd puts "" print "Y/n: " if "Y" == STDIN.gets.chomp puts "" puts "Running..." puts `#{cmd}` else puts "" puts "Aborted." end end |
.ell!(cmd) ⇒ Object
Forced mode, won’t ask confirmation. Shows command. Shows output.
27 28 29 30 |
# File 'lib/ktools/sh.rb', line 27 def self.ell!(cmd) puts cmd puts `#{cmd}` end |
.ell_in!(cmd) ⇒ Object
Forced mode, won’t ask confirmation. Shows command. Shows output. Loops into the output.
51 52 53 54 55 56 57 58 |
# File 'lib/ktools/sh.rb', line 51 def self.ell_in!(cmd) puts cmd IO.popen(cmd) do |io| while (line = io.gets) do puts line end end end |
.ell_meta(cmd) ⇒ Object
Forced mode, won’t ask confirmation. It’s the meta-shell, or kt-shell mode. It emulates a shell over Ruby’s $stdin/$stdout.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ktools/sh.rb', line 63 def self.(cmd) $stdout.print 'Press enter...' started = false $stdin.each_line do |line| if started pid = fork { exec line } else started = true pid = fork { exec cmd } end Process.wait pid $stdout.print 'kt:shell$ ' end end |
.ellb!(cmd) ⇒ Object
Forced mode, won’t ask confirmation. Won’t show command. Shows the output.
43 44 45 |
# File 'lib/ktools/sh.rb', line 43 def self.ellb!(cmd) puts `#{cmd}` end |
.elld!(cmd) ⇒ Object
Forced mode, won’t ask confirmation. Won’t show command. Won’t show output. Returns output.
36 37 38 |
# File 'lib/ktools/sh.rb', line 36 def self.elld!(cmd) `#{cmd}` end |