Skip to content

Instantly share code, notes, and snippets.

@crowding
Created September 10, 2012 21:56
Show Gist options
  • Save crowding/3694214 to your computer and use it in GitHub Desktop.
Save crowding/3694214 to your computer and use it in GitHub Desktop.
Bash prompt for ADD types
#put this in your ~/.bash_profile
#
#If a long-running command terminates, ring the bell and float the
#(OSX Terminal) window.
LONG_RUNNING=20 #how long is long? Enough for me to get bored and tab away.
function popup_if_long {
last_command_time=$(HISTTIMEFORMAT="%s " history 1 | awk '{print $2}')
if (( $(date -u +"%s") - $last_command_time > $LONG_RUNNING ))
then
printf "\a"
osascript ~/.raise.applescript $(tty) > /dev/null
fi
}
PROMPT_COMMAND="popup_if_long"
-- this will try and find the Terminal.app window containing a particular tty and raise it above almost all other windows. I would like it to raise the lone window above all others, but I still don't know how to do that. ( http://apple.stackexchange.com/questions/39204/script-to-raise-a-single-window-to-the-front )
on run argv
tell application "System Events"
set foundWin to false
if (name of processes) contains "Terminal" then
tell application "Terminal"
set theTabs to first tab of every window where tty is item 1 of argv
repeat with theTab in theTabs
if class of theTab is tab then
set theWin to (first window whose tabs contains theTab)
set selected tab of theWin to theTab
set frontmost of theWin to true
set foundWin to true
exit repeat
end if
end repeat
end tell
end if
if foundWin then
tell application process "Terminal"
click menu item (name of theWin) of menu of menu bar item "Window" of menu bar 1
end tell
end if
end tell
end run

You ever have the problem where you issue a command, and it lasts longer than a few seconds, so that you tab away to a browser or something, and you lose track of what you were doing?

Put one piece in .bash_profile and another piece in your home directory. When a command takes longer than some threshold, this will beep and try to raise the window (if Terminal.app).

It will also beep on concluding interactive programs like less or an editor, which is kind of annoying but eh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment