Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Right justifying prompt data in bash Post 302749123 by vnayak on Thursday 27th of December 2012 02:10:57 PM
Old 12-27-2012
Apple Right justify for bash

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_command

I 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
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

customize my prompt in bash

in csh I was using: set prompt=""$HOSTNAME".tk.\!> " to customize the look of my prompt. I have seen the light after reading the perils of csh scripting and wish to switch to bash. How do I customize my bash prompt??? I've tried many variation of the above w/no success, and searching this... (2 Replies)
Discussion started by: yankee428
2 Replies

2. Shell Programming and Scripting

justifying the fields

hi experts, i just need a help that my script is generating the output which i will mentioned below but the fileds are not justified the alignment is disturbed. 0 8718 8718 0 8777 1 7450 7450 0 7483 2 5063 5063 0 5091 3 3840 3840 0 3855 4 ... (2 Replies)
Discussion started by: shary
2 Replies

3. Shell Programming and Scripting

Works from bash prompt, but not from script!

I'm trying to use unison from bash on windows with cygwin. I don't know if this is a cygwin question, bash question or unison question. Since I always get reprimanded by the cygwin mailing list for assuming it is a cygwin problem, I'll assume it is a bash question. The following commands work... (7 Replies)
Discussion started by: siegfried
7 Replies

4. Shell Programming and Scripting

How can i change my bash prompt ?

It looks like, user@hostname:/auto/home3/user$ Desired, user@hostname$ I added following line in .bashrc, but still its same. export PS1=" $ " Please help me :confused: (13 Replies)
Discussion started by: admax
13 Replies

5. UNIX for Advanced & Expert Users

Bash conditional prompt?

Hi, Does anyone know any way of making bash prompt extended with conditional content? Example: export PS1="] && echo '#' || echo '\$'" # This won't work - prompt is not executed # export PS1="\$" # This is an existing but also working equivalent I would like to use more complex... (8 Replies)
Discussion started by: adderek
8 Replies

6. OS X (Apple)

Bash prompt wraparound

I'm using a custom prompt with PS1 in my .profile. It is PS1="\\u@\e\:\W\ \\$\ \" and it works well, as you can see, http://content.screencast.com/users/killer54291/folders/Jing/media/2b3db52a-ebf7-43e2-95cc-f45dadbc2b98/00000023.png but, when i type more than the width of the window, it... (0 Replies)
Discussion started by: killer54291
0 Replies

7. Shell Programming and Scripting

BASH: Getting titlebar and prompt to 'sync up'

This is an instance of "if it's not one thing, it's another." I recently fell victim to my own stupidity in trashing, by accident, my long-running and very highly-customized .bash_profile and .bashrc files for Cygwin & Cygwin/X. I had backups from a previous "go" with this, and decided to use... (0 Replies)
Discussion started by: SilversleevesX
0 Replies

8. Emergency UNIX and Linux Support

Bash answer prompt

I am working with a script to simplyfy some operations where I work, but one of the programs needs me to enter a password. It will as me "Please enter the administrator password:" Is there a way to make a bash script to automatically answer the question with the needed password? I am looking... (3 Replies)
Discussion started by: noratx
3 Replies

9. Shell Programming and Scripting

Running an executable from bash prompt

Hi, I'm trying to run a program from the bash prompt and I don't understand why it is returning with an error. Dig is my C program, and it takes in parameters J4, detect, 3 and 0182F98E var1="cygdrive/c/2i/test fixture/software/mccdaqtest/debug/Dig J4 detect 3 0182F98E" when I do ... (6 Replies)
Discussion started by: oahmad
6 Replies

10. UNIX for Dummies Questions & Answers

Bash prompt is over lapping

Hello Guys, I have facing problem with linux shell prompt .Am expecting my Bash prompt to be like below but its showing like ~]$ ot@Servername and while typing the commands the prompt looks like below: ~]$ echo $PS1 $ ~]$ ot@ServernameChecked the .bash_profile and also changed... (9 Replies)
Discussion started by: kapil514
9 Replies
sag(1)								   User Commands							    sag(1)

NAME
sag - system activity graph SYNOPSIS
sag [-e time] [-f file] [-i sec] [-s time] [-T term] [-x spec] [-y spec] DESCRIPTION
The sag utility graphically displays the system activity data stored in a binary data file by a previous sar(1) run. Any of the sar data items may be plotted singly or in combination, as cross plots or versus time. Simple arithmetic combinations of data may be specified. sag invokes sar and finds the desired data by string-matching the data column header (run sar to see what is available). The sag utility requires a graphic terminal to draw the graph, and uses tplot(1) to produce its output. When running Solaris 2.x and OpenWindows, perform the following steps: 1. Run an xterm as a Tektronics terminal: prompt# xterm -t 2. In the xterm window, run sag specifying a tek terminal: prompt# sag -T tek options OPTIONS
The following options are supported and passed through to sar (see sar(1)): -e time Select data up to time. Default is 18:00. -f file Use file as the data source for sar. Default is the current daily data file /usr/adm/sa/sadd. -i sec Select data at intervals as close as possible to sec seconds. -s time Select data later than time in the form hh[:mm]. Default is 08:00. -T term Produce output suitable for terminal term. See tplot(1) for known terminals. Default for term is $TERM. -x spec x axis specification with spec in the form: name[op name]...[lo hi] name is either a string that will match a column header in the sar report, with an optional device name in square brackets, for example, r+w/s[dsk-1], or an integer value. op is + - * or / surrounded by blank spaces. Up to five names may be specified. Parentheses are not recognized. Contrary to custom, + and - have precedence over * and /. Evaluation is left to right. Thus, A/A+B*100 is evaluated as (A/(A+B))*100, and A+B/C+D is (A+B)/(C+D). lo and hi are optional numeric scale limits. If unspeci- fied, they are deduced from the data. Enclose spec in double-quotes ("") if it includes white space. A single spec is permitted for the x axis. If unspecified, time is used. -y spec y axis specification with spec in the same form as for -x. Up to 5 spec arguments separated by a semi-colon (;) may be given for -y. The -y default is: -y"%usr0100;%usr+%sys0100;%usr+%sys+%wio0100" EXAMPLES
Example 1 Examples of the sag command. To see today's CPU utilization: example$ sag To see activity over 15 minutes of all disk drives: example$ TS=`date +%H:%M` example$ sar -o /tmp/tempfile 60 15 example$ TE=`date +%H:%M` example$ sag -f /tmp/tempfile -s $TS -e $TE -y "r+w/s[dsk]" FILES
/usr/adm/sa/sadd daily data file for day dd ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWaccu | +-----------------------------+-----------------------------+ SEE ALSO
sar(1), tplot(1), attributes(5) System Administration Guide: Advanced Administration SunOS 5.11 4 Mar 1998 sag(1)
All times are GMT -4. The time now is 03:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy