diff --git a/plugins/tab/tab.fish b/plugins/tab/tab.fish index b01c5b900bb744c9546f81b42ce94ad8f7fd2d2d..1e44a0295bd1f48be0d8642994042d6b8b66acbc 100644 --- a/plugins/tab/tab.fish +++ b/plugins/tab/tab.fish @@ -7,17 +7,24 @@ # tab [PATH] Open PATH in a new tab # tab [CMD] Open a new tab and execute CMD # tab [PATH] [CMD] ... You can prolly guess +# +# If you use iTerm and your default session profile isn't "Default Session", +# override it in your config.fish +# +# set -g tab_iterm_profile "MyProfile" function tab -d 'Open the current directory (or any other directory) in a new tab' set -l cmd '' set -l cdto $PWD - if test (count $argv) -gt 0 -a -d $argv[1] - pushd . >/dev/null - cd $argv[1] - set cdto $PWD - set -e argv[1] - popd >/dev/null + if test (count $argv) -gt 0 + if test -d $argv[1] + pushd . >/dev/null + cd $argv[1] + set cdto $PWD + set -e argv[1] + popd >/dev/null + end end if test (count $argv) -gt 0 @@ -27,10 +34,14 @@ function tab -d 'Open the current directory (or any other directory) in a new ta switch $TERM_PROGRAM case 'iTerm.app' + set -l profile 'Default Session' + if set -q tab_iterm_profile + set profile $tab_iterm_profile + end osascript 2>/dev/null -e " tell application \"iTerm\" tell current terminal - launch session \"Default Session\" + launch session \"$profile\" tell the last session write text \"cd \\\"$cdto\\\"$cmd\" end tell