An annotated guide to Jon's .bashrc

.bashrc

I have a very basic bash setup for the labs (however there is a lot of hidden stuff going on which I will explain later). In general I use this setup to add some aliases for commands I use a lot and to add some extra tools which are not part of the general build.

The following is my .bashrc, if you want you can just copy this into your ~/.bashrc and use it.

source /etc/profile.d/prompt.sh
alias ls='ls --color'
alias ll='ls -al'
alias rm='rm -i'
alias code='/public/devel/2021/VSCode-linux-x64/code --no-sandbox '
alias rg='/public/devel/2021/bin/rg'
alias mayapy='/opt/autodesk/maya/bin/mayapy'
alias mysqlsh='/public/devel/2021/mysqlsh/bin/mysqlsh'
export PATH="/home/jmacey/.pyenv/shims:${PATH}:/public/devel/2021/swig/bin/"
export PYTHONPATH=$PYTHONPATH:~/NGL/lib

What I will do next is explain what each line does and my motivation for adding it.

source /etc/profile.d/prompt.sh

This line executes the script /etc/profile.d/prompt.sh using the source this sets some command prompt variables.

export PS1="[\[\e[33m\]\u\[\e[m\]@\[\e[31m\]\h:\W$\[\e[m\]]"
export PS2="[\[\e[33m\]\u\[\e[m\]@\[\e[31m\]\h:\W$\[\e[m\]]"

These variables PS1-PS4 set different prompt levels depending upon how you are logged in. These commands set the prompt to be [Username@Hostname:CurrentDiR] so my root is [jmacey@w11901:~$] The escape codes set colours and other elements.

It is possible for you to override this into your own custom prompt, by using the export command.

For example this prompt created using the excellent https://bashrcgenerator.com/ will give you a git status for the current directory (if a repository)

export PS1="[\H]@\u\n\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\[$(tput sgr0)\]"

To make this work you just need to add it after the call to source /etc/profile.d/prompt.sh or remove it (you can use # in .bashrc as a comment)

alias ls='ls --color'

This line uses the alias command to default the ls to use ls --color by default. In general most linux distributions seem to do this but not the version we are using.

The colours are determined by an environment variable called LS_COLORS which can be show using echo $LS_COLORS

The basic colours are as follows

colourmeaning
BlueDirectory
GreenExecutable or recognized data file
CyanSymbolic link file
Yellow with black backgroundDevice
Magenta (Pink)Graphic image file
RedArchive file
Red with black backgroundBroken link

alias ll='ls -al'

This alias adds to the previous line and makes the command ll give a long listing (with added colour). Again this is quite common in other linux distros and I have muscle memory using it so add this on the lab machines.

alias rm='rm -i'

This could be one of the most important commands to alias when using the shell (and in particular when learning linux). By default the rm will assume you know what you are doing and remove everything you pass to is (with some caveats depending upon other flags).

The -i flag tells the shell to be interactive making it ask you to press Y for each file on a prompt.

alias code='/public/devel/2021/VSCode-linux-x64/code --no-sandbox '

This alias points to a different version of vscode than the old version installed by default. The reason for this is that I can update the /public/devel version than all of the lab machines. This is one of the major advantages of linux that having a shared server / install location makes it easier to update and modify things.

You will notice the --no-sandbox flag used here. This is because VSCode is an electron app and be default needs to be installed setuid root however this can’t be done for the shared folder / install process we use. Using the flag fixes this however should be used with caution as noted here

alias rg='/public/devel/2021/bin/rg'

This alias is for running the rip grep tool (rg) I use this a lot for searching in files and various other things. Have a look here for more examples.

alias mayapy='/opt/autodesk/maya/bin/mayapy'

This allows me to run the maya python interpreter (2.7 at present) in the terminal. This is very useful for a number of reason, see my MSc lectures for more examples.

alias mysqlsh='/public/devel/2021/mysqlsh/bin/mysqlsh'

This alias is used to allow me to run mysqlsh for accessing databases installed in w119, see the Pipeline and TD lectures and labs for this.

export PATH="/home/jmacey/.pyenv/shims:${PATH}:/public/devel/2021/swig/bin/"

This uses the export function to prepend to the $PATH environment variable the location of pyenv. I use pyenv to allow me to setup and install different python versions. It is not needed unless you need to play with different python versions. For more details see the pyenv install here

export PYTHONPATH=$PYTHONPATH:~/NGL/lib

This export add the location of NGL/lib to the python path so the pyngl library can be used. This takes some extra setup with NGL which is documented in the NGL readme files

Is that all?

Not really, when you login there are actually a number of scripts that run to setup the bulk of the environment for the user.

In particular the file /etc/profile.d/developer.sh is run for each user to setup the developer tools, environment variables for CMAKE and RENDERMAN. In the most part these are all used in programming / technical roles an are of no interest to most people so are hidden away.

The contents can be seen here.

export PATH=$PATH:/public/bin/2021:/opt/qt/5.15.2/gcc_64/bin:/opt/qt/Tools/QtCre
ator/bin

export CMAKE_TOOLCHAIN_FILE=/public/devel/2021/vcpkg/scripts/buildsystems/vcpkg.
cmake
export CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH:~/NGL:/opt/qt/5.15.2/gcc_64/lib/cmak
e/
export CMAKE_MODULE_PATH=/opt/qt/5.15.2/gcc_64/lib/cmake

# Setup modern compilers
# this set the default compiler tool-chain to be devtoolset-7
source scl_source enable devtoolset-9
source scl_source enable llvm-toolset-7

# update package config
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/public/devel/2021/vcpkg/installed/x64-l
inux/lib/pkgconfig

export RMANTREE=/opt/pixar/RenderManProServer-24.1
export PATH=$PATH:$RMANTREE/bin
export PYTHONPATH=$PYTHONPATH:$RMANTREE/bin
Next
Previous

Related