LoginSignup
7
7

More than 5 years have passed since last update.

iTerm2でsshコマンド時に新しいウィンドウで開く

Posted at

リモートログインしたターミナルは、ローカル操作との誤操作を防ぐため常に別の新しいウィンドウで開きたい

設定方法

  1. AppleScriptを使って新しいウィンドウを開くスクリプトを作成

    ssh_with_new_window.scpt
    on run argv
    
        -- use space
        set text item delimiters of AppleScript to space
        set cmd to argv as string
    
        -- set profile
        set profile to "ssh" as text
    
        tell application "iTerm"
            activate
            tell (make new terminal)
                launch session profile
                tell the last session
                    write text "/usr/bin/ssh " & cmd
                end tell
            end tell
        end tell
    end run
    
  2. sshコマンドのエイリアスの設定
    alias ssh='osascript ssh_with_new_window.scpt'

使用方法

ssh host_name

iterm.png

プロファイルを指定する

ホストネームに特定のキーワードが含まれていた場合などに、背景色、文字色を変えて気分を切り替えたい場合にお勧め

適当な例

        -- set profile
        if cmd contains "production" then
            set profile to "production" as text
        else if cmd contains "pro" then
            set profile to "production" as text
        else
            set profile to "ssh" as text
        end if

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7