iTerm2でタブの複製をしたい
コマンドや移動の履歴まで複製できれば最高だが, ここではカレントディレクトリだけの複製をした. 応用すれば "新しいタブでコマンド実行" などが容易にできる.
it2_newtab.applescript
#!/usr/bin/osascript -- Usage: oscript it2_newtab.applescript profile command on run argv if length of argv < 1 log "Usage: it2_newtab.applescript profile [command]" return end if tell application "iTerm2" tell current window create tab with profile (item 1 of argv) if length of argv >= 2 -- with command tell current session write text (item 2 of argv) end tell end if end tell end tell end run
$ it2_newtab.applescript "Profile Name" "Command"
のように使い,
- 第一引数: 新しいタブで開くiTerm2のプロフィール名
- 第二引数(optional): 起動時に実行されるコマンド
を指定する
パスを通したりエイリアスしたりしておくと便利
~/.zshrc
alias clone='it2_newtab.applescript "In visor" "cd \"`pwd`\"; clear"'
iTerm2のショートカットキーに設定しても便利
無理矢理だが, ^C, clone[Enter] と強制的に入力させるようにした
キーコードは[Key Codes.app](https://itunes.apple.com/jp/app/key-codes/id414568915?mt=12)で調べると良い
AppleScriptで標準エラー出力にいい感じに表示する方法が分からなかったので, よかったら教えてくださいmm