2015-05-28 21:19:36 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2015-08-05 07:27:46 +03:00
|
|
|
CMD="clear && $*"
|
2014-08-28 00:45:22 +04:00
|
|
|
|
|
|
|
ITERM_EXISTS=`osascript <<EOF
|
|
|
|
set doesExist to false
|
|
|
|
try
|
|
|
|
do shell script "osascript -e 'exists application \"iTerm\"'"
|
|
|
|
set doesExist to true
|
|
|
|
end try
|
|
|
|
return doesExist
|
|
|
|
EOF`
|
|
|
|
|
2015-05-18 10:11:21 +03:00
|
|
|
function open_iterm () {
|
2014-08-28 00:45:22 +04:00
|
|
|
osascript > /dev/null <<EOF
|
2015-05-18 10:11:21 +03:00
|
|
|
tell application "iTerm"
|
2016-05-28 05:22:46 +03:00
|
|
|
activate
|
|
|
|
try
|
|
|
|
tell the first terminal
|
|
|
|
launch session "Default Session"
|
|
|
|
tell the last session
|
|
|
|
write text "bash -c \"$CMD\""
|
|
|
|
end tell
|
|
|
|
end tell
|
|
|
|
on error
|
|
|
|
tell (make new terminal)
|
|
|
|
launch session "Default Session"
|
|
|
|
tell the last session
|
|
|
|
write text "bash -c \"$CMD\""
|
|
|
|
end tell
|
|
|
|
end tell
|
|
|
|
end try
|
2015-07-23 15:10:40 +03:00
|
|
|
end tell
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function open_iterm2point9 () {
|
|
|
|
osascript > /dev/null <<EOF
|
|
|
|
tell application "iTerm"
|
|
|
|
if version ≥ 2.9 then
|
|
|
|
activate
|
|
|
|
tell current window
|
|
|
|
create tab with default profile
|
|
|
|
tell first session of current tab
|
|
|
|
write text "bash -c \"$CMD\""
|
|
|
|
end tell
|
|
|
|
end tell
|
|
|
|
end if
|
2015-05-18 10:11:21 +03:00
|
|
|
end tell
|
2014-08-28 00:45:22 +04:00
|
|
|
EOF
|
2015-05-18 10:11:21 +03:00
|
|
|
}
|
2014-08-28 00:45:22 +04:00
|
|
|
|
2015-05-18 10:11:21 +03:00
|
|
|
function open_terminal () {
|
|
|
|
osascript > /dev/null <<EOF
|
|
|
|
tell application "Terminal" to activate
|
|
|
|
delay 0.4
|
|
|
|
tell application "System Events" to keystroke "t" using command down
|
|
|
|
tell application "Terminal"
|
2015-05-29 16:44:13 +03:00
|
|
|
do script "bash -c \"$CMD\"" in window 1
|
2015-05-18 10:11:21 +03:00
|
|
|
end tell
|
2014-08-28 00:45:22 +04:00
|
|
|
EOF
|
2015-05-18 10:11:21 +03:00
|
|
|
}
|
2014-08-28 00:45:22 +04:00
|
|
|
|
2015-05-29 16:44:13 +03:00
|
|
|
if [ "$ITERM_EXISTS" == "true" ]; then
|
2015-07-23 15:10:40 +03:00
|
|
|
open_iterm2point9 "$@" || open_iterm "$@" || open_terminal "$@"
|
2015-05-18 10:11:21 +03:00
|
|
|
else
|
2015-05-29 16:44:13 +03:00
|
|
|
open_terminal "$@"
|
2014-08-28 00:45:22 +04:00
|
|
|
fi
|