Difference between revisions of ".bashrc"

From CSEE Documentation
m (Remove cleanup tag)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Cleanup}}
 
 
 
A .bashrc or .bash_profile file contains settings that are applied to non-interactive or interactive shells respectively.  All the things described in this document are applicable to both, so it's reasonable to create only one and symlink the other one to it (or include it by saying something like <tt>. ~/.bashrc</tt> in your <tt>.bash_profile</tt>).
 
A .bashrc or .bash_profile file contains settings that are applied to non-interactive or interactive shells respectively.  All the things described in this document are applicable to both, so it's reasonable to create only one and symlink the other one to it (or include it by saying something like <tt>. ~/.bashrc</tt> in your <tt>.bash_profile</tt>).
  
Line 6: Line 4:
 
===Setting the PATH===
 
===Setting the PATH===
 
It's often nice to have more binaries directly accessible in your PATH environment variable.  To do this, I use the following settings:
 
It's often nice to have more binaries directly accessible in your PATH environment variable.  To do this, I use the following settings:
os=`uname -s`
+
 
if [ "$os" = "SunOS" ]; then
+
 
  export PATH=/usr/ccs/bin:/usr/site/bin:/usr/sbin:/usr/bin:/bin:/opt/csw/bin:/opt/csw/sbin:/usr/sfw/bin:/opt/sfw/bin:/usr/local/bin
+
 
else
+
  export PATH=/usr/site/bin:/usr/sbin:/usr/bin:/usr/local/bin:/bin
  if [ "$os" = "Linux" ]; then
+
    
    export PATH=/usr/site/bin:/usr/sbin:/usr/bin:/usr/local/bin:/bin
+
   
   fi
 
  fi
 
 
  if [ "$LOGNAME" = "root" ]; then
 
  if [ "$LOGNAME" = "root" ]; then
 
   export PATH=$PATH:/sbin
 
   export PATH=$PATH:/sbin
Line 21: Line 17:
 
Having a colored prompt can be helpful to notice quickly where the prompt is in a long listing of output, and having a reminder who you are logged in as and where you are never hurts.  To accomplish this, I use the following prompt:
 
Having a colored prompt can be helpful to notice quickly where the prompt is in a long listing of output, and having a reminder who you are logged in as and where you are never hurts.  To accomplish this, I use the following prompt:
 
  export PS1="\[\033[34m\]\u\[\033[0m\]@\[\033[32m\]\h\[\033[0m\]:\[\033[31m\]\w\[\033[0m\]\\$ "
 
  export PS1="\[\033[34m\]\u\[\033[0m\]@\[\033[32m\]\h\[\033[0m\]:\[\033[31m\]\w\[\033[0m\]\\$ "
This gives your username in blue (i.e., if you sudo -s it'll be <tt>root</tt> instead of your username) followed by a black @ followed by the hostname of the machine you're on followed by a colon followed by the path to the current directory, followed by the sigil $ or # for user or root respectively.  This format has the advantage of being usable by <tt>scp</tt>; if you have to copy a file from that directory onto another machine, you can copy/paste the whole string into your <tt>scp</tt> command.
+
 
 +
This translates to a comman dprompt that looks like the following.  
 +
 
 +
[[File:Command prompt.png|alt=ii69854@aerial:~$]]
 +
 
 +
This format has the advantage of being usable by <tt>scp</tt>; if you have to copy a file from that directory onto another machine, you can copy/paste the whole string into your <tt>scp</tt> command.
  
 
===Changing the terminal name===
 
===Changing the terminal name===
Line 35: Line 36:
 
     ;;
 
     ;;
 
  esac
 
  esac
 +
 +
This will give a title that looks like
 +
 +
  username@hostname:~/Documents
  
 
===Changing your default pager===
 
===Changing your default pager===
<tt>more</tt> is for losers. Use <tt>less</tt> instead.
+
If you are on a sufficiently old system, the outdated pager <tt>more</tt> is used. You may want to set the pager to <tt>less</tt> instead.
 
  export PAGER=less
 
  export PAGER=less

Latest revision as of 14:37, 27 February 2024

A .bashrc or .bash_profile file contains settings that are applied to non-interactive or interactive shells respectively. All the things described in this document are applicable to both, so it's reasonable to create only one and symlink the other one to it (or include it by saying something like . ~/.bashrc in your .bash_profile).

Simple things

Setting the PATH

It's often nice to have more binaries directly accessible in your PATH environment variable. To do this, I use the following settings:


 export PATH=/usr/site/bin:/usr/sbin:/usr/bin:/usr/local/bin:/bin
  

if [ "$LOGNAME" = "root" ]; then
  export PATH=$PATH:/sbin
fi

Changing the prompt

Having a colored prompt can be helpful to notice quickly where the prompt is in a long listing of output, and having a reminder who you are logged in as and where you are never hurts. To accomplish this, I use the following prompt:

export PS1="\[\033[34m\]\u\[\033[0m\]@\[\033[32m\]\h\[\033[0m\]:\[\033[31m\]\w\[\033[0m\]\\$ "

This translates to a comman dprompt that looks like the following.

ii69854@aerial:~$

This format has the advantage of being usable by scp; if you have to copy a file from that directory onto another machine, you can copy/paste the whole string into your scp command.

Changing the terminal name

Setting the name of the terminal is reflected in the title bar in gnome-terminal, or with a similar mechanism for other terminals (or GNU screen). I use the following settings:

case $TERM in
  xterm*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
    ;;
  screen*)
    PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
    ;;
  *)
    ;;
esac

This will give a title that looks like

 username@hostname:~/Documents

Changing your default pager

If you are on a sufficiently old system, the outdated pager more is used. You may want to set the pager to less instead.

export PAGER=less