Class: ITermCLI::Terminal::NewSession
- Defined in:
- lib/iterm_cli/terminal/new_session.rb
Constant Summary collapse
- SOURCE =
<<-JS.freeze function run(argv) { var options = JSON.parse(argv[0]); var iTerm = Application("iTerm2"); var window = iTerm.currentWindow(); var tab = iTerm.createTab(window, {withProfile: "Default", command: options.command}); tab.currentSession().name = options.name; } JS
Instance Method Summary collapse
-
#call(command_and_args, options = {}) ⇒ Object
command should be [“command”, “arg”] or [“command arg”].
Methods inherited from Function
Instance Method Details
#call(command_and_args, options = {}) ⇒ Object
command should be [“command”, “arg”] or [“command arg”]
17 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 |
# File 'lib/iterm_cli/terminal/new_session.rb', line 17 def call(command_and_args, = {}) = {name: nil, debug: false}.merge() name = [:name] debug = [:debug] command = join_command(command_and_args) executable = command.shellsplit.first unless which(executable) warn "No such file or directory: #{executable}" exit 1 end name ||= executable.split("/").last script_lines = [] script_lines.concat(set_env_lines) script_lines << "cd #{Dir.pwd.shellescape}" script_lines << command if debug puts script_lines end script_filename = write_script(script_lines.join("\n")) osascript(SOURCE, command: "/bin/sh #{script_filename.shellescape}", name: name) end |