Andrew’s Cool Bash Prompt

Andrew wrote a tip today to have your bash prompt show the last ‘n’ folders of your current directory. His original suggestions is on his website, [Readable Path for Terminal][1].

His code gave me several errors, which I am pretty sure at least one was because of the bash to HTML conversion. So I wanted to get it working so I played around with it and got it to do what Andrew said it should do. Then I modified it to use the same idea as absolute vs relative paths. If it is a truncated path it will not have a preceding / (or ~). It extends on my previous suggestion, [Better Terminal Prompt][2], so show the username in green (as opposed to red for root).

My profile is available as a [text file][file] and shown below:

# Function that returns the last n path components of the specified
# path after replacing $HOME with ~.  Call like:
#     breadcrumbs path n
function breadcrumbs
{
    echo $1 | sed "s|^$HOME|~|" | awk -v n=$2 '{
        # Split the path into components
        count = split($0, components, "/");

        # If there are less than n components, print the whole path
        if (count = n) {
            for (i = count - n + 1; i

Better Terminal Prompt

Set terminal prompt color and style, green user, red root (set elsewhere), machine, and working directory. Place in your .profile or .bash_profile:

if [ "$TERM" = "xterm-color" ]; then
        C1="[33[0;32m]"
        C2="[33[1;0m]"
        export PS1="${C1}u${C2}@h: W $ "
fi

Generate gnuplot Scripts For Data Sets

plot.sh is a script I wrote as a hack to “dynamically” generate gnuplot scripts for each of the regions I need to plot. There is probably a better way to do this but I am not a gnuplot guru.

My program stored the results of each batch of particles in a numbered folder as well as aggregating the results in the main directory. The script allows you to select whether you are plotting the z-distribution or the v-distribution.

The syntax is:

./plot.sh z .

Plots the z-distribution from the zstate file in the main directory.

./plot.sh +8 .

Plots the v-distribution of the eighth bin in z, the file vstate+8 in the main directory.

./plot.sh +8 0

Plots the v-distribution of the eighth bin in z, the file vstate+8 in the 0 directory, the directory storing the results for the first batch of particles.