0

This question already has an answer here:

The reason I need to be able to do this, is to have 'updating' variables in my PS1. I'd like to have my prompt span across the entire width of the terminal, not wrapping around or going down to a new line. For this, I already found a way to get it working, but this method requires me to reload bash every time. Here's what I would like it to look like:

|me::awesome| --------------------------------------------------------- ~/.config/awesome
$

After that, when I cd into a new directory, it will look like this:

|me::themes| -------------------------------------------------------------------------
------ ~/.config/awesome/themes
$

But when I then run

exec bash

it will successfully change all values and look like this:

|me::themes| --------------------------------------------------- ~/.config/awesome/themes
$

So I'm looking for a way to incorporate changing variables into my PS1 variable, which I would want updated every time a new prompt is called. This is what my .bashrc looks like at the moment:

mytest=$PWD
mynext="$(basename $PWD)"
mylength=$((${#mytest}+${#mynext}))
length=$(($mylength+6))
PS1='|me::\W| $(printf "\\u2500%.0s" $(seq $length $(tput cols))) \w\n\$'

I've also tried putting the the variables into a separate shell script file, and running that within my PS1, as follows:

#/home/me/.PS1.sh
mytest=$PWD
mynext="$(basename $PWD)"
mylength=$((${#mytest}+${#mynext}))
length=$(($mylength+6))
echo "|me::\W| $(printf "\\u2500%.0s" $(seq $length $(tput cols))) \w\n\$"

#/home/me/.bashrc
PS1=$(/home/me/.PS1.sh)

marked as duplicate by Gilles bash Feb 11 '16 at 22:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

your variables get evaluated only the first time , you must put them inside the ps1 to be treated literally ffirst time and get evaluated after command execution .

PS1='|me::\W| $( mytest=$PWD;mynext="${PWD##*/}";  mylength=$((${#mytest}+${#mynext})) ; length=$(($mylength+6)) ; printf "\\u2500%.0s" $(seq $length $(tput cols))) \w\n\$'

you can change only 6 if you added stuff to ps1

Not the answer you're looking for? Browse other questions tagged or ask your own question.