Skip to content

Instantly share code, notes, and snippets.

@earlonrails
Last active February 19, 2020 02:00
Show Gist options
  • Select an option

  • Save earlonrails/2624352 to your computer and use it in GitHub Desktop.

Select an option

Save earlonrails/2624352 to your computer and use it in GitHub Desktop.

Revisions

  1. earlonrails renamed this gist Jun 6, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. earlonrails revised this gist May 15, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion splat.rb
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@
    script_builder.call(v_pane_open, arg)
    end
    args.each do |arg|
    script_builder.call(go_left_one_pane)
    script_builder.call(go_left_one_pane) unless size == 2
    script_builder.call(h_pane_open, arg)
    end
    else
  3. earlonrails revised this gist Mar 7, 2013. 1 changed file with 47 additions and 27 deletions.
    74 changes: 47 additions & 27 deletions splat.rb
    Original file line number Diff line number Diff line change
    @@ -2,38 +2,58 @@
    require 'shellwords'

    args = ARGV
    num_args = args.size
    pattern = num_args % 2 == 0 ? :grid : :lanes
    size = args.size
    tab_open = 'tell i term application "System Events" to keystroke "t" using {command down}'
    v_pane_open = 'tell i term application "System Events" to keystroke "d" using {command down}'
    h_pane_open = 'tell i term application "System Events" to keystroke "d" using {command down, shift down}'
    go_left_one_pane = 'tell i term application "System Events" to key code 123 using {command down, option down}'
    script_builder = Proc.new do |tell, command|
    script = Shellwords.escape(<<-TEXT
    tell application "iTerm"
    activate
    #{tell}
    tell the front terminal
    activate current session
    tell the current session
    write text "#{command}"
    command_action = nil
    pane_action = <<-TEXT
    tell application "iTerm"
    activate
    #{tell}
    end tell
    end tell
    end tell
    TEXT
    )
    system("osascript -e #{script}")
    TEXT
    if command
    command_action = <<-TEXT
    tell application "iTerm"
    activate
    tell the front terminal
    activate current session
    tell the current session
    write text "#{command}"
    end tell
    end tell
    end tell
    TEXT
    end

    pane_script = Shellwords.escape(pane_action)
    system("osascript -e #{pane_script}")
    if command_action
    command_script = Shellwords.escape(command_action)
    system("osascript -e #{command_script}")
    end
    end
    script_builder.call(tab_open, args[0])
    if num_args > 1
    vertical_panes = num_args / 2
    args[1..-1].each_index do |arg_idx|
    arg = args[arg_idx + 1]
    if ( pattern == :grid && arg_idx < (vertical_panes - 1 ) ) || pattern == :lanes
    script_builder.call(v_pane_open, arg)
    else
    script_builder.call(go_left_one_pane, arg)
    script_builder.call(h_pane_open, arg)
    end
    # script_builder.call(tab_open, args.shift)
    # script_builder.call(v_pane_open, args.shift)
    # script_builder.call(h_pane_open, args.shift)
    # script_builder.call(go_left_one_pane)
    # script_builder.call(h_pane_open, args.shift)
    exit 1 if args.empty?
    pattern = size % 2 == 0 ? :grid : :lanes
    script_builder.call(tab_open, args.shift)
    if ( pattern == :grid )
    args.shift((size / 2) -1 ).each do |arg|
    script_builder.call(v_pane_open, arg)
    end
    end
    args.each do |arg|
    script_builder.call(go_left_one_pane)
    script_builder.call(h_pane_open, arg)
    end
    else
    args.each do |arg|
    script_builder.call(v_pane_open, arg)
    end
    end
  4. earlonrails revised this gist May 7, 2012. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions splat.rb
    Original file line number Diff line number Diff line change
    @@ -28,11 +28,12 @@
    if num_args > 1
    vertical_panes = num_args / 2
    args[1..-1].each_index do |arg_idx|
    arg = args[arg_idx + 1]
    if ( pattern == :grid && arg_idx < (vertical_panes - 1 ) ) || pattern == :lanes
    script_builder.call(v_pane_open, args[arg_idx])
    script_builder.call(v_pane_open, arg)
    else
    script_builder.call(go_left_one_pane, args[arg_idx])
    script_builder.call(h_pane_open, args[arg_idx])
    script_builder.call(go_left_one_pane, arg)
    script_builder.call(h_pane_open, arg)
    end
    end
    end
  5. earlonrails created this gist May 6, 2012.
    8 changes: 8 additions & 0 deletions .bash_profile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # splat will make many terminal tabs with selected hosts connecting
    splat(){
    if [[ $TERM_PROGRAM = iTerm.app ]];then
    ruby ~/Documents/splat.rb "$@"
    else
    echo "Must be using iTerm for that function!"
    fi
    }
    38 changes: 38 additions & 0 deletions splat.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/usr/local/bin/ruby
    require 'shellwords'

    args = ARGV
    num_args = args.size
    pattern = num_args % 2 == 0 ? :grid : :lanes
    tab_open = 'tell i term application "System Events" to keystroke "t" using {command down}'
    v_pane_open = 'tell i term application "System Events" to keystroke "d" using {command down}'
    h_pane_open = 'tell i term application "System Events" to keystroke "d" using {command down, shift down}'
    go_left_one_pane = 'tell i term application "System Events" to key code 123 using {command down, option down}'
    script_builder = Proc.new do |tell, command|
    script = Shellwords.escape(<<-TEXT
    tell application "iTerm"
    activate
    #{tell}
    tell the front terminal
    activate current session
    tell the current session
    write text "#{command}"
    end tell
    end tell
    end tell
    TEXT
    )
    system("osascript -e #{script}")
    end
    script_builder.call(tab_open, args[0])
    if num_args > 1
    vertical_panes = num_args / 2
    args[1..-1].each_index do |arg_idx|
    if ( pattern == :grid && arg_idx < (vertical_panes - 1 ) ) || pattern == :lanes
    script_builder.call(v_pane_open, args[arg_idx])
    else
    script_builder.call(go_left_one_pane, args[arg_idx])
    script_builder.call(h_pane_open, args[arg_idx])
    end
    end
    end