Class: Pssh::Console
- Inherits:
-
Object
- Object
- Pssh::Console
- Defined in:
- lib/pssh/console.rb
Constant Summary collapse
- COMMANDS =
%w(list block unblock sessions kill-session exit).sort
- BANNER =
<<-BANNER ------------------------------------------------------------------ help\t\tDisplays this help menu. info\t\tDisplays current tmux settings and configuration. list[ sessions]\tShow the currently open sessions. kill-session[s]\tKill either all sessions or a specific by id. --all\t\tKills all the open sessions. 'session id'\tKills only the session specified by the id. exit\t\tCloses all active sessions and exits. ------------------------------------------------------------------ Tip: Use tab-completion for commands and session ids. BANNER
Instance Method Summary collapse
- #completion_proc ⇒ Object
-
#initialize(opts = {}) ⇒ Console
constructor
A new instance of Console.
Constructor Details
#initialize(opts = {}) ⇒ Console
Returns a new instance of Console.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pssh/console.rb', line 18 def initialize(opts = {}) begin puts "[ pssh terminal ]" puts "Service started on port #{Pssh.port}." puts "Share this url for access: #{Pssh.share_url}" puts "Type 'help' for more information." Readline.completion_append_character = " " Readline.completion_proc = completion_proc while command = Readline.readline(Pssh.prompt, true) command.strip! command.gsub!(/\s+/, ' ') case command when 'help' puts BANNER.gsub(/^ {6}/,'') when 'exit' Pssh.socket.kill_all_sessions Kernel.exit! when 'info' puts 'Current Configuration:' if Pssh.pty.path puts "Socket: #{Pssh.pty.path}" puts "(Attach to this socket with `#{Pssh.pty.attach_cmd}`)" else puts 'Connections are made to a vanilla shell.' end when 'list sessions', 'list' Pssh.socket.sessions.each do |k,v| puts v[:user_string] end when /^kill-sessions?\s?(.*)$/ if $1 == '--all' puts 'disconnecting all clients' Pssh.socket.kill_all_sessions else puts "disconnecting #{$1}" if Pssh.socket.sessions.keys.include?($1) Pssh.socket.sessions[$1][:socket].close! else Pssh.socket.sessions.each do |k, sess| if sess[:username] == $1 sess[:socket].close! end end end end end end rescue Exception => e puts e.inspect puts e.backtrace retry end end |
Instance Method Details
#completion_proc ⇒ Object
74 75 76 |
# File 'lib/pssh/console.rb', line 74 def completion_proc @completion_proc ||= proc { |s| (COMMANDS + Pssh.open_sessions.keys + Pssh.open_sessions.values.uniq).grep( /^#{Regexp.escape(s)}/ ) } end |