12 Jan 2013, 06:21

Shells within shells

As a *nix admin I spend most of my time on the command line which means I want to optimise that experience as much as I can. When editing files with vim I find I often need to drop into a shell to do some tasks before resuming the edit, but rather than quit vim I just spawn a subshell. The trouble is I often forget that I’m in a subshell and go to open the same file again. A neat trick I found to stop that happening is as follows - change the shell prompt to clearly indicate that I’m in a subshell:

if [ $VIM ]; then  
    export PS1='\[\e[1;31m\]**VIM**[\u@\h \W]\$\[\e[0m\] '  
fi
  • exit from your terminal session, then log back in again
    Now when I edit a file with Vim and drop to a shell, I get a prompt that looks something like:
    VIM[me@localhost tmp]$