Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adiroiban
Created June 21, 2017 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adiroiban/5d81d3fd7a821a17aaa651013b2f0de2 to your computer and use it in GitHub Desktop.
Save adiroiban/5d81d3fd7a821a17aaa651013b2f0de2 to your computer and use it in GitHub Desktop.
Bash Prompt
# based on the prompt from
# http://www.gilesorr.com/bashprompt/prompts/twtty.html
function prompt_command {
TERMWIDTH=${COLUMNS}
# Calculate the width of the prompt:
hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
# "whoami" and "pwd" include a trailing newline
#usernam=$(whoami)
newPWD="${PWD}"
# Add all the accessories below ...
let promptsize=$(echo -n "${USER}@${hostnam} -${PWD}HH" \
| wc -c | tr -d " ")
let fillsize=${TERMWIDTH}-${promptsize}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="${fill}-"
let fillsize=${fillsize}-1
done
if [ "$fillsize" -lt "0" ]
then
# if pwd is to large left-truncate it
let cut=2-${fillsize}
newPWD="$(echo -n $PWD | sed -e "s/\(^.\{$cut\}\)\(.*\)/\2/")"
fill=""
prefill="..."
else
# else add a space to hint for a full path
fill="${fill} "
prefill=""
fi
# On some shells we don't have PS2, so we fix PS1 here.
user_id=`id -g`
if [ "$user_id" = "0" ]; then
cursor='#'
else
cursor='$'
fi
ps_time=`date '+%H:%M'`
}
PROMPT_COMMAND=prompt_command
function twtty {
local GRAY="\[\033[1;30m\]"
local LIGHT_GRAY="\[\033[0;37m\]"
local WHITE="\[\033[1;37m\]"
local NO_COLOUR="\[\033[0m\]"
local LIGHT_BLUE="\[\033[1;34m\]"
local YELLOW="\[\033[1;32m\]"
PS1="\n$TITLEBAR\
$WHITE\${prefill}$YELLOW\${newPWD} \
\${fill}$YELLOW\${ps_time}$LIGHT_BLUE@$YELLOW\$hostnam\
\n\
$WHITE\${cursor}$NO_COLOUR "
PS2="$YELLOW>$NO_COLOUR "
}
twtty
unset twtty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment