Last active
October 25, 2024 08:54
-
-
Save vyder/96891b93f515cb4ac559e9132e1c9086 to your computer and use it in GitHub Desktop.
iterm.bash - Launch iTerm from command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Open new iTerm window from the command line | |
# | |
# Usage: | |
# iterm Opens the current directory in a new iTerm window | |
# iterm [PATH] Open PATH in a new iTerm window | |
# iterm [CMD] Open a new iTerm window and execute CMD | |
# iterm [PATH] [CMD] ... You can prob'ly guess | |
# | |
# Example: | |
# iterm ~/Code/HelloWorld ./setup.sh | |
# | |
# References: | |
# iTerm AppleScript Examples: | |
# https://gitlab.com/gnachman/iterm2/wikis/Applescript | |
# | |
# Credit: | |
# Inspired by tab.bash by @bobthecow | |
# link: https://gist.github.com/bobthecow/757788 | |
# | |
# OSX only | |
[ `uname -s` != "Darwin" ] && return | |
function iterm () { | |
local cmd="" | |
local wd="$PWD" | |
local args="$@" | |
if [ -d "$1" ]; then | |
wd="$1" | |
args="${@:2}" | |
fi | |
if [ -n "$args" ]; then | |
# echo $args | |
cmd="; $args" | |
fi | |
osascript &>/dev/null <<EOF | |
tell application "iTerm" | |
activate | |
set term to (make new terminal) | |
tell term | |
launch session "Default Session" | |
tell the last session | |
delay 1 | |
write text "cd $wd$cmd" | |
end | |
end | |
end tell | |
EOF | |
} | |
iterm $@ |
🙌
Is there anything fancy I need to do in advance to get this to work?
Simply iterm.bash .
is not doing anything for me
Unfortunately I don't use this script in my workflow anymore - so I haven't been maintaining it.
Try one of the forks others have created - that might work better for you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 hopefully the updated version helps someone else the way yours helped me!