.bashrc guru needed

leeoliveshackelford at surewest.net leeoliveshackelford at surewest.net
Mon Sep 22 18:24:39 UTC 2014


Greetings, dear FreeBSD enthusiasts. Is there a bash guru who can help
me correct the following script for .bashrc. I copied this script from a
web page whose location I failed to record, and have forgotten. It is
supposed to write each word of the prompt in a different color, which it
does correctly. This color scheme is generated by the function
bash_prompt(). It is also supposed to write the current directory in an
abridged format in which the portion of the filepath that refers to the
home directory, if any, is replaced by a tilde (~), and then, long path
descriptions are truncated on the left at 25 characters, with two
periods then added. This result is created by the function
bash_prompt_command(). This function does not work. In place of the
value of the variable NEW_PWD, the operating system simply prints the
error message "unbound variable, then generates a prompt line listing
the variable's name, $NEW_PWD, in place of its value. This variable is
given values on three lines, 18, 22, and 24. Where does it loose its
binding? I have made several modifications to the function in an attempt
to get it to work, but to no avail. Following is a partial listing. 

CVSROOT="${CVSROOT:-/home/ncvs}"; export CVSROOT
TMPDIR="${TMPDIR:-/tmp}"; export TMPDIR 

set +H #disables bash!-completion 

export PATH=$PATH:$HOME/.local/bin 

#Inserted here are a group of alias commands.
# The following statements control the prompt. 

export CLICOLOR="YES" 

bash_prompt_command() { 

# How many characters of the $PWD should be kept 

local pwdmaxlen=25 

# Indicate that there has been dir truncation 

local trunc_symbol=".." 

local dir=${PWD##*/} 

pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen )) 


local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen )) 

if [ ${pwdoffset} -gt "0" ] 





fi } 



#Inserted here are a list of variables set to descriptions of various

local UC=$EMG # user's color 

[ $UID -eq "0" ] && UC=$EMR # root's color 

PS1="${UC}s ${EMW}${NEW_PWD} ${UC}\$ ${NONE}" 


PROMPT_COMMAND=bash_prompt_command; bash_prompt; unset bash_prompt 


# End of statements to control prompt 

I added the export statements on lines 1, 2, and 3. I added the
semi-colons on line 35, and the export PROMP_COMMAND on line 36. I
inserted the "else" statement on line 23. None of these modifications
helped. What is the programmer telling or trying to tell the interpreter
to do on line 16, "local dir=${PWD/##*/}" ? What is the programmer
telling, or trying to tell the interpreter to do on line 18,
"NEW_PWD=${PWD/#$HOME/~}" ? Please, to those coming from the world of c
programming language, bash syntax seems to be a mystery. Any and all
suggestions will be appreciated. Newby Lee 

More information about the freebsd-questions mailing list