Enhancing the Solaris Shell

Mr. Walter Phillips


Table of Contents
1. Introduction
2. Switch shells
3. Customize your environment
3.1. Adding color to your terminal
3.2. Customizing bash
3.3. Customizing tcsh
3.4. Customizing zsh
4. Conclusion

1. Introduction

Solaris is a really horrible version of unix. It's the kid who sits in the back and does just enough to pass, and nothing more. Fortunately, it has a very good package management system, and many users who have ported GNU tools to it to bring it up to speed. Unfortunately, only system administrators can use it. Lowly users are stuck with a crummy version of Solaris if the sysadmins are lazy. Except that they're NOT! This howto has some modifications to make using the command line more bearable in Solaris.


2. Switch shells

Solaris by default installs bash. While bash can be a nice shell with the help of bash-completion, you can find a lot more desirable features from other shells. For example:

I also noticed that bash does not deal with mapping backspace correctly on the derminal by default, though this is quite easy to fix. Of the possible new shells, I recommend zsh. It is the most powerful and has all of those features. It is, however, less often available than other shells, so tcsh is a good secondary choice, though it only does tab autocompletion of filenames. For the rest of this guide, I will assume that you wish to use one of these two shells. Changing shells is done with the "chsh" command. For example:

Example 1. Output from the command line


mentor.ics.purdue.edu:~>chsh
Old shell: /usr/local/bin/tcsh
New shell [/usr/local/bin/tcsh]:Junk to see the list
Illegal 'loginShell' value: 'Junk to see the list'.
Available shells include "/sbin/sh /sbin/jsh /bin/sh /bin/bash /bin/csh /bin/ksh
/usr/bin/sh /usr/bin/csh /usr/bin/ksh /usr/dt/bin/dtksh /usr/local/bin/tcsh 
/opt/acmaint/etc/message /opt/acmaint/etc/nologin /opt/acmaint-3.5/etc/message 
/opt/acmaint-3.5/etc/nologin"
New shell [/usr/local/bin/tcsh]: /usr/local/bin/tcsh





3. Customize your environment


3.1. Adding color to your terminal

In Solaris, info about color would be stored in a file under /usr/share/lib/terminfo/, normally

/usr/share/lib/terminfo/x/xterm-color

If you can convince your admin to add this file at this location, adding color is easy - just do "set term=xterm-color" and you'll have color. If your admin is afraid that you've built a bomb for him, he can build this file himself using the "tic" utitlity and this file.

Example 2. Making and storing colormap


mkdir ~/.terminfo
setenv TERMINFO ~/.terminfo
tic xterm-color.tic -v

If you're using bash instead of tcsh (or for some reason it doesn't work), replace "setenv TERMINFO ~/.terminfo" with "export TERMINFO=~/.terminfo"

While this makes the system color, many major utilities, such as, for instance, "ls" are not color. Here is the gnu version of "ls" for Sparc-Solaris, which allows color. More on that later.

If your administrator has installed vim, you can use this with color settings. Adding this file as .vimrc will cause most common file types to be loaded with color syntax highlighting:

Example 3. My .vimrc:


:filetype on
autocmd FileType matlab,c,cpp,bash,perl,tcsh call Progiterface()

function Progiterface()
        syn on
        set number linebreak softtabstop=4 cindent
endfunction




3.2. Customizing bash

bash may be customized with set and export, or implicitly. I recommend putting all of these settings in a file called ~/.bash_login, as the ~/.bashrc may not be called by default. Here is my .bash_login file, with enhancements for color, as well as bash completion, as well as the ~/bin directory to put the "ls" script in. Bash completion is allows bash to autocomplete many commands through the tab key, and must be downloaded separately (from here). I saved my completion script as ~/.bash_completion, for this file.

Example 4. My ..bash_login file


PS1="\[\033[35m\]\H\[\033[33m\]:\[\033[36m\]\w\[\033[0m\]>"
alias vi=vim
set path=($path ~/bin )
alias ls="~/bin/ls --color=auto"
if [ $TERM = "xterm" ]
then
 export TERMINFO=~/.terminfo;
 TERM=xterm-color;
fi
[ -z "$BASH_COMPLETION" ] && declare -r BASH_COMPLETION=~/.bash_completion
source ~/.bash_completion


< s

3.3. Customizing tcsh

tcsh may be customized by changing it's environment variables with the "set" and "setenv" commands. On Solaris, I recommend putting all of these settings in a file called ~/.tcshrc, which will automatically be read once for each new terminal. Here is my .tcshrc file, with enhancements to use xterm-color if you have an xterm, as well as adding a history file and setting up a ~/bin directory as part of the path. If you downloaded "ls" in a previous section, this would be a good place to put it.

It also includes my shell prompt.

Example 5. My .tcshrc file


set prompt="%{\033[35m%}%M%u%{\033[33m%}:%{\033[36m%}%~%{\033[0m%}>"
alias vi vim
set history=1000
set savehist=999
set autolist="ambiguous"
set path=($path ~/bin )
alias ls '~/bin/ls --color=auto'
if ($term == "xterm") then
  setenv TERMINFO ~/.terminfo
  set term=xterm-color
endif

3.4. Customizing zsh

Zsh may be customized with the "setopt" or "export" commands. Usually this is done with a .zshrc file (though there are many other ways). Here is my zshrc file, which does everything that the .tcshrc file does, but also includes the ability to ignore hangup signals from the terminal (if you're running a program and get disconnected it won't stop running).

Example 6. My .zshrc file


PS1="$(print '%{\e[35m%}')%n@%m$(print '%{\e[33m%}'):$(print '%{\e[36m%}')%~$(print '%{\e[0m%}')>"
alias ls='ls --color=auto'
alias vi=vim
setopt nohup
HISTSIZE=1000
HISTFILE=~/.zsh_history
SAVEHIST=1000
setopt INC_APPEND_HISTORY
if [[ $term == "xterm' ]] then
        term="xterm-color"
        export TERMINFO=~/.terminfo
fi
<

4. Conclusion

That should be everything you need. If you have noticed any errors or omissions (besides omitting any particular other method of going about this, please Send me an email. This HOWTO is being actively maintained.