Module: Sesh::Inferences

Defined in:
lib/sesh/inferences.rb

Defined Under Namespace

Modules: OS

Class Method Summary collapse

Class Method Details

.infer_current_directoryObject



6
7
8
# File 'lib/sesh/inferences.rb', line 6

def self.infer_current_directory
  `printf '%q\n' "${PWD##*/}"`.strip
end

.infer_default_editorObject



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_addrObject



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_directoryObject



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_appObject



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_locationObject



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_paneObject



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_projectObject



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