-
-
Save gaecom/72ae4f4a419a03adc99498f574330ca7 to your computer and use it in GitHub Desktop.
iterm.bash - Launch iTerm from command line
This file contains hidden or 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 $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment