Using powerline-shell with csh and older terminal emulators

Its no secret I spend a lot of time customizing my work environment (and more recently my workflow). Apart from the fact that I enjoy it, the other reason is that I suspect my eyes are not going to last forever and I should do whatever I can to make it easier on them. This involves a balance of contrast and brightness. So when I found powerline and then later powerline-shell I could immediately see the advantage it would give me. Instant information about what I need, in sectioned and clearly separated regions.

My previous shell was already colored and segmented, and displayed my username, hostname and full path. It gave me a separation when scrolling up the terminal to see where the command I last entered was, and where stdout started spewing its stuff. However, I decided to up the ante and tried to install powerline on a combo of csh and konsole from Centos5. Pretty darn old version of konsole dating back to 2006, there were a few hiccups but got it to work using the following steps.

  1. Get the powerline fonts from here: Powerline Fonts . You can clone to repo or wget the zip file. Either copy the required fonts into your ~/.fonts directory or use the install script. Make sure you flush the font cache and see if konsole can find your fonts. Now in your konsole settings change the font to a powerlne one, currently I am on Meslo.
  2. Get the powerline shell python scripts from: Powerline Shell . Try to follow the instructions to do the install, but we will need some tweaks for csh.
  3. Make sure your character encoding in konsole is set to utf8. You can do this by going to settings and encoding. Then set these settings as default so that any new konsole window or tab will wake up with these settings (i.e. font and encoding).
  4. We need to slightly tweak the cshell environment. Set the environment variable LC_ALL to the correct locale, for e.g.
     setenv LC_ALL en_US.UTF-8 

    . Make sure this line is in your .cshrc file, otherwise it wont work by setting it once the shell has spawned.

  5. We need to tweak the powerline-shell-base.py to add support for csh style color formatting, this is fairly easy.
    1. Under color_templates list add another entry for csh:
       'csh': '%%{\\e%s%%}' 
    2. Under the arg_parser shell section, in the choices, add an entry for ‘csh’
    3. Under root_indicators add only if you want to:  
       'csh': ' > ' 
  6. Set the prompt in your .cshrc to run this script:
    1.  set prompt = "`~/powerline-shell.py --shell csh`" 
    2.  alias cd 'cd \!*; set prompt = "`~/powerline-shell.py --shell csh`"' 
  7. Profit!!!

powerline

4 thoughts on “Using powerline-shell with csh and older terminal emulators

    • As mentioned in step 5, did you add it to the argument parser?
      i.e. around the line:
      arg_parser.add_argument(‘–shell’, action=’store’, default=’bash’,
      help=’Set this to your shell type’, choices=[‘bash’, ‘zsh’, ‘bare’])
      You need to modify the list to add csh to it i.e. choices=[‘bash’, ‘zsh’, ‘bare’, ‘csh’]

  1. I can successful get the right result, but important thing is pwd content don’t update if I move from current path to another. I find a example which may be disputed in bash, but I don’t konw how to change this script in csh.

    function _update_ps1() {
    PS1=”$(~/powerline-shell.py $? 2> /dev/null)”
    }

    if [ “$TERM” != “linux” ]; then
    PROMPT_COMMAND=”_update_ps1; $PROMPT_COMMAND”
    fi

    • Thats a bit tricky too. You will have to alias cd to call the powerline script again. Something like:
      alias cd 'cd \!*; set prompt = "`~/powerline-shell.py --shell csh --cwd-mode plain`"'

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s