Exercise 1.2: Making an rc file
Having a .bashrc
or .zshrc
file allows you to configure your shell how you like.
a) If you are using Linux or macOS, open a terminal and type
echo $SHELL
This will tell you if you are using a Bash shell or Zsh, which will tell you which kind of rc file to set up in the next part of the exercise. If you are using Windows, you will create a .bashrc
file.
b) Create a .bashrc
or .zshrc
file in your home directory. If you already have one, open it up for editing using Jupyter’s text editor.
c) It is often useful to alias
functions to other functions. For example, I am always worried I will accidentally delete things by accident. I therefore have the following line in my .zshrc
file.
alias rm="rm -i"
You should create aliases for commands like ls
based on the flags you like to always use. Do the same for rm
and mv
(I use the -i
flag with these). To figure out what flags are available, you can look at the man
pages. Asking Google will usually give you the information you need on flags.
If you like, you can use my .bashrc
file, available in ~/git/bootcamp/misc/jb_bashrc
, or my .zshrc
file, available in ~/git/bootcamp/misc/jb_zshrc
.
d) Depending on your operating system, if you are using Bash, your ~/.bashrc
file may or may not be properly loaded upon opening a new bash shell. You may, e.g. for new macOS versions, need to explicitly source your .bashrc
file in your ~/.bash_profile
file. Therefore, you should add the following to the bottom of your ~/.bash_profile
file.
if [ -f $HOME/.bashrc ]; then
. $HOME/.bashrc
fi
Solution
Again, this was mostly you messing around with the command line. The contents of my .bashrc file is shown below.
# Give me a nice prompt that tells me my pwd
export PS1="\[\e[1;32m\]\u\[\e[0m\]@\e[1;36m\]\h\[\e[0m\] [\w]\n% "
# Keep me out of trouble!
alias rm="rm -i"
alias mv="mv -i"
alias cp="cp -i"
# customize list output
alias ls="ls -FGh"
export LSCOLORS="gxfxcxdxCxegedabagacad"
And my .zshrc file is:
# This is a nice prompt; gives green check mark if last command executed
# without a problem and gives a red questionmark with an exit code
# if it didn't, along with pwd.
PROMPT='%(?.%F{green}√.%F{red}?%?)%f [%B%F{240}%10~%f%b]
%# '
# Aliases for save moving, removing, and copying of files
alias rm="rm -i"
alias mv="mv -i"
alias cp="cp -i"
# Nicely formatted listing
alias ls="ls -FGh"
# Nice set of colors
export LSCOLORS="gxfxcxdxCxegedabagacad"