Fast User Switching, when enabled, allows users to leave one session open and hop to another user account. Great for training, testing and impressing friends (ok, so maybe it won’t impress your friends, but the thumb trick is getting old). To enable Fast User Switching, open the Accounts System Preference pane and click on Login Options. Then check the box for Show fast user switching menu. By default you’ll then see your user name in the menu bar.
To do this from the command line:
defaults write /Library/Preferences/.GlobalPreferences MultipleSessionEnabled -bool 'YES'
To then disable it from the command line:
defaults write /Library/Preferences/.GlobalPreferences MultipleSessionEnabled -bool 'NO'
What’s really cool though, is once enabled, you can switch users with a script as well, using the command line options available with CGSession, located in the user.menu item at /System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession.
/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -switchToUserID 501
Or to simply go to a login screen:
/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -suspend
As promised in the article on colorizing the terminal
, let’s look at how to customize your bash prompt. First note that text as well as the following can be used in your string.
- a – ASCII bell
- d – date
- e – ASCII escape
- h – LocalHostName
- H – HostName
- j – number of jobs managed by shell
- l – basename of terminal device name
- n – insert a newline
- r – insert a carriage return
- @ – time in 12-hour HH:MM format
- A – time in 24-hour HH:MM format
- t – time in 12-hour HH:MM:SS format
- T – time in 24-hour HH:MM:SS format
- u – current user
- v – include bash version
- V – include bash version & patch level
- w – working directory, w/ $HOME
- W – basename of working directory, w/ $HOME
- ! – history number of command
- # – command number
- $ – # if the UID is 0 or a $
- \ – backslash
- [ – start sequences of non-printing characters
- ] – used to end sequences of non-printing characters
Using the above then, you would indicate the prompt in the .bash_profile and add a new line that starts with PS1 along with the codes you’d like to use in quotes. For example, to show the path followed by a colon (:) and then the LocalHostName you could use the following:
PS1=”h : u $ “
Or to add the time in the beginning of the line:
PS1=”T : h : u $ “
To insert some text, simply place characters inside the quotes. Let’s replace the $ with the word Prompt:
PS1=”T : h : u Prompt “
Now that we’ve done a little customization let’s look at adding some color. Before doing so, consider what color and the codes that can be used per color:
- Black – 0;30
- Blue – 0;34
- Light Green – 1;32
- Green – 0;32
- Light Cyan – 1;36
- Cyan – 0;36
- Light Red – 1;31
- Red – 0;31
- Light Purple – 1;35
- Purple – 0;35
- Light Brown – 1;33
- Brown – 0;33
- Light Blue – 1;34
Once you pick a color then let’s look at adding a little Cyan to your prompt:
export PS1=”e[0;36m ] u@h w $”
Finally, you can add multiple colors, making your prompt a little clown-like. But I am not sure that I’d recommend that (seems a little distracting). One thing I do sometimes is to set the command that I’m typing to a different color. For example, to set it to green if that’s what you’re coming back in from
export PS1=”e[0;36m ] u@h w $ e[0;32m ]”
So customize away and enjoy!
I originally posted this at http://www.318.com/TechJournal
Apple has been slowly winning over a lot of traditional Unix and Linux converts. This new breed of switcher is after a cool shell environment. In Leopard, Apple has upgraded Terminal.app to provide a whole slew of new features that are sure to continue winning new converts. Letâ€™s just take a look at a few of them:
Secure Keyboard Entry – Prevent other applications from detecting keystrokes used in terminal. Enable this using the Terminal menu.
Tabbed Interface – I always have 3 shell windows open. Thatâ€™s how I roll. But with the new tabbed interface (which you can access using the Command-T keystroke) I find that Iâ€™m using two shell windows with 3 tabs each. This gives me the ability to have a man page or process list on one side of my screen while being able to run other commands on the other side. You can fire up 2 shell windows and then open as many tabs as you like.
Export Settings – This isnâ€™t new in Leopard, but what is new in Leopard is that the tabs get exported along with window positions, layouts, themes and backgrounds.
Themes – Glass, Homebrew, Novel, Red Sands – these themes allow you to use prebuilt templates for how you view your shell. These include background, text color, transparency. Can you imagine Steve sitting in his office at Apple dinking around with the Homebrew theme?
Window Groups – A group of windows with a saved location, tabbed layout, shell configuration and settings.
Terminal Inspector – Switch themes on the fly, view running process and increase the columns and rows of a shell environment.
Titles – Set titles for your terminal windows so you can remember what was where.