When I use the Terminal application I want to close it using the command exit
if only one Terminal window is open. If more than one window is open, I want to close just the window that executed the exit command.
To achieve this behaviour I use the following function in my .bash_profile
function exit {
if [ $(who | wc -l) -eq 2 ]; then
osascript -e 'tell application "Terminal" to quit'
else
osascript -e 'tell application "Terminal" to close first window'
fi
}
Everything works great but the usage of $(who | wc -l) -eq 2
seems to be a bit hacky. In particular this only works if the machine is used by a single user only. Are there any other ways to do the job?