If you use ZSH, you can try something like this:
function tab() {
local command="cd \\\"$PWD\\\"; clear; "
(( $# > 0 )) && command="${command}; $*"
}
If you use bash, I'm not sure what the equivalent is. Also, if you use prezto or Oh-My-ZSH, the tab function is already built-in.
UPDATE
Seeing how it works, this should be the complete solution.
local command="cd \\\"$PWD\\\""
(( $# > 0 )) && command="${command}; $*"
the_app=$(
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
[[ "$the_app" == 'iTerm' ]] && {
osascript 2>/dev/null <<EOF
tell application "iTerm"
set current_terminal to current terminal
tell current_terminal
launch session "Default Session"
set current_session to current session
tell current_session
write text "${command}"
end tell
end tell
end tell
EOF
}
It uses the CLI for AppleScript and seems to work just fine for me.
source
share