module Sesh::Inferences

Public Class Methods

infer_current_directory() click to toggle source
# File lib/sesh/inferences.rb, line 6
def self.infer_current_directory
  `printf '%q\n' "${PWD##*/}"`.strip
end
infer_default_editor() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/sesh/inferences.rb, line 40
def self.infer_tmux_location; {
  project: infer_tmux_project, pane: infer_tmux_pane } end
infer_tmux_pane() click to toggle source
# 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() click to toggle source
# 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