Module: Sesh::Inferences
- Defined in:
- lib/sesh/inferences.rb
Defined Under Namespace
Modules: OS
Class Method Summary collapse
- .infer_current_directory ⇒ Object
- .infer_default_editor ⇒ Object
- .infer_local_ssh_addr ⇒ Object
- .infer_project_from_current_directory ⇒ Object
- .infer_terminal_app ⇒ Object
- .infer_tmux_location ⇒ Object
- .infer_tmux_pane ⇒ Object
- .infer_tmux_project ⇒ Object
Class Method Details
.infer_current_directory ⇒ Object
6 7 8 |
# File 'lib/sesh/inferences.rb', line 6 def self.infer_current_directory `printf '%q\n' "${PWD##*/}"`.strip end |
.infer_default_editor ⇒ Object
26 27 28 29 |
# File 'lib/sesh/inferences.rb', line 26 def self.infer_default_editor if OS.windows? then 'notepad.exe' else o = `echo $EDITOR`.strip; o = 'vim' unless o.length > 0; o end end |
.infer_local_ssh_addr ⇒ Object
13 14 15 16 17 18 |
# File 'lib/sesh/inferences.rb', line 13 def self.infer_local_ssh_addr inferred_user = `echo $USER`.strip inferred_hostname = `scutil --get LocalHostName`.strip.downcase inferred_hostname += '.local' unless inferred_hostname =~ /\.local$/ "#{inferred_user}@#{inferred_hostname}" end |
.infer_project_from_current_directory ⇒ Object
9 10 11 12 |
# File 'lib/sesh/inferences.rb', line 9 def self.infer_project_from_current_directory inferred_dir = infer_current_directory return inferred_dir if Tmuxinator::Config.exists? inferred_dir end |
.infer_terminal_app ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/sesh/inferences.rb', line 19 def self.infer_terminal_app if OS.mac? output = `osascript -e 'try' -e 'get exists application "iTerm"' -e 'end try'`.strip output.length > 0 ? 'iTerm' : fatal("iTerm 2 is not installed.") # 'Terminal' # TODO: support more platforms end end |
.infer_tmux_location ⇒ Object
40 41 |
# File 'lib/sesh/inferences.rb', line 40 def self.infer_tmux_location; { project: infer_tmux_project, pane: infer_tmux_pane } end |
.infer_tmux_pane ⇒ Object
38 39 |
# File 'lib/sesh/inferences.rb', line 38 def self.infer_tmux_pane return if ( o = `echo $TMUX_PANE`.strip ).nil?; o[1..-1].to_i end |
.infer_tmux_project ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/sesh/inferences.rb', line 30 def self.infer_tmux_project tmux_session_pid = `echo $TMUX | cut -d , -f 2`.strip return if tmux_session_pid.length == 0 tmux_process_line = `ps aux | grep tmux | grep -v grep | grep #{tmux_session_pid}`.strip.lines.first return if tmux_process_line.nil? tmux_process_line.split('-s ')[-1].split(' -n')[0] end |