|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I have a custom prompt in Bash. However, I would like to further customise it so that it shows me the date and time. However, I would like this new addition to appear on the right side of the terminal window. The idea behind this is to "visually balance" some data on the right as most of the time the terminal is used from the left. I hope this make sense. Please let me know if you require further information. Regards, vnayak |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Not sure if such a thing is really possible with Bash.
Interestingly, the zsh shell has the ability to display things on the right hand side of a terminal. You can do the same things as with PS1, and you don't have to worry about typing over it, or it messing up your commands. The variable to set is RPS1. |
| The Following User Says Thank You to fpmurphy For This Useful Post: | ||
vnayak (12-27-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi fpmurphy, Many thanks for the suggestion and your prompt reply. I did find a few resources on the web which may benefit people using the terminal. These are below: 8 Useful and Interesting Bash Prompts and Add a Separator & Time Stamp Between Terminal Commands to Increase Readability I than mixed the codes I found on these sites together to make something below: Code:
Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="--- "
reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black
# Prompt variable:
#PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\$'"$command_style "
PS1='\n\[\e[32;1m\](\[\e[37;1m\]\u\[\e[32;1m\])-(\[\e[37;1m\]jobs:\j\[\e[32;1m\])-(\[\e[37;1m\]\w\[\e[32;1m\])$fill (\t)\n(\[\[\e[37;1m\]! \!\[\e[32;1m\])-> \[\e[0m\]`if [ $? = 0 ]; then echo \[\e[33m\]^_^\[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\]; f$
# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\033[00m"' DEBUG
function prompt_command {
# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-32
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=`basename "${PWD/$HOME/~}"`
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac
}
PROMPT_COMMAND=prompt_commandI am by no means an expert Bash scripter however, once I started looking at the code I was able to roughly figure out how this worked. Obviously this code be improved upon but this serves my purpose for now. Many thanks vnayak |
| Sponsored Links | ||
|
![]() |
| Tags |
| mac os x, terminal, terminal output |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bash answer prompt | noratx | Emergency UNIX and Linux Support !! Help Me!! | 3 | 01-21-2011 06:47 PM |
| Bash prompt wraparound | killer54291 | OS X (Apple) | 0 | 09-06-2010 10:27 PM |
| How can i change my bash prompt ? | admax | Shell Programming and Scripting | 13 | 12-01-2009 10:40 AM |
| justifying the fields | shary | Shell Programming and Scripting | 2 | 01-31-2008 10:18 AM |
| customize my prompt in bash | yankee428 | UNIX for Dummies Questions & Answers | 2 | 06-23-2005 02:02 PM |
|
|