Skip to content

Instantly share code, notes, and snippets.

@dmilanp
Created March 17, 2016 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmilanp/f3f0650b71660eaa6ed0 to your computer and use it in GitHub Desktop.
Save dmilanp/f3f0650b71660eaa6ed0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Assumes iTerm
while getopts ":u:" opt
do
case $opt in
u) user="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" && exit 1 >&2
;;
esac
done
if [ "$user" == "" ]
then
printf "\n\tUsage\n\t./open_shells.sh -u \$YOU host1 host2 .. hostN\n\n\tAssumes your authentication is managed by ~/.ssh/config\n\n"
exit 1
fi
# shift parameters '-u' and its argument
shift
shift
for server in "$@"
do
printf "Server is %s\n" "$server"
osascript \
-e 'tell application "System Events" to tell process "iTerm" to keystroke "t" using command down' \
-e 'tell application "System Events" to tell process "iTerm" to keystroke "ssh '$user'@'$server'"' \
-e 'tell application "System Events" to tell process "iTerm" to keystroke return'
done
# close invoking session
osascript -e 'tell application "iTerm" to terminate the first session of the first terminal'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment