- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- limiting length of PS1 that uses pwd
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2007 09:01 AM
тАО09-18-2007 09:01 AM
limiting length of PS1 that uses pwd
My question is how to limit the length of the prompt to say 30 characters?
If I am working in a term window and traverse a long directory path, the prompt gets so long that I cannot see much of what I type.
So when the path is long (say over 30 characters), I would like to have the prompt truncate the beginning of the path and leave the last 10-15 characters.
For example, when using this for the prompt in .profile:
export PS1=`hostname`:'$PWD # '
I see the following:
# cd /htc/technology
rx203:/htc/technology #
But when the path is long, I need to limit the display:
# cd softwaresystems/regional/field_locations
rx203:/htc/technology/softwaresystems/regional/field_locations #
(I would prefer to see something like the following, with the hostname, some filler like " ... ", and only the end of the path)
rx203: ... d_locations #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2007 12:58 PM
тАО09-18-2007 12:58 PM
Re: limiting length of PS1 that uses pwd
you want:
dy # cat ~/pwdp.sh
#!/bin/sh
x=` pwd `
xs=` echo "$x" | sed -e 's/^.*\(.\{16\}$\)/\1/' `
if [ "$x" != "$xs" ]; then
xs="...$xs"
fi
echo "$xs"
dy # export PS1='` ~/pwdp.sh ` '
...sr/local/src/zip cd /usr
/usr
where the user input was:
cd /usr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2007 02:07 PM
тАО09-18-2007 02:07 PM
Re: limiting length of PS1 that uses pwd
You can use escape sequences for hpterm and dtterm to set the title.
function settitle { # Set the ivoterm titlebar:
if [ "$TERM" = "hp2392a" -o $TERM = "hpterm" ]; then
ti="$host $PWD"
echo "^[&f0k${#ti}D${ti}\c"
elif [ "$TERM" = "dtterm" -o "$TERM" = "xterm" ]; then
ti="$host $PWD"
echo "^[]2;${ti}^G\c"
fi
}
^[ is really an escape and ^G is a control G.
Of course to drive all of this, I have pushd/popd functions, including cd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2007 03:19 PM
тАО09-18-2007 03:19 PM
Re: limiting length of PS1 that uses pwd
HN=$(hostname)
export PS1='$HN...${PWD##${PWD%/*/*}/} # '
If you want to use some highlighting, you can pick from this list:
# set char enhancments only if interactive (ie, TERM is set)
# If TERM is not set or the TERM value is not found in terminfo
# files, then enhancements are null.
export HB=$(tput dim 2>/dev/null) # dim text
export HV=$(tput smso 2>/dev/null) # 1/2 bright inverse
export IV=$(tput bold 2>/dev/null) # inverse
export UL=$(tput smul 2>/dev/null) # underline
export BL=$(tput blink 2>/dev/null) # blink
export EL=$(tput el 2>/dev/null) # clear to end of line
export ED=$(tput ed 2>/dev/null) # clear to end of display
export EE=$(tput sgr0 2>/dev/null) # end all enhancements
Then add them to your PS1 prompt:
HN="$IV$(hostname)$EE"
export PS1='$HN...$HB${PWD##${PWD%/*/*}/}$EE # '
Modern terminal emulators can display a number of video enhancements and these can often be configured with different colors within the emulator. After running all the export lines above, run this echo to show all the enhancements supported by your terminal:
echo "normal $HV smso $HB dim $IV bold $UL smul $BL blink $EE normal"
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2007 05:25 PM
тАО09-18-2007 05:25 PM
Re: limiting length of PS1 that uses pwd
one can use a shell script to do some more
complicated things than can easily be placed
directly into a PS1 assignment.
Personally, I use PS1="` hostname ` # ", and
if I forget which directory I'm in, I find
that "pwd" tells me what I need to know
pretty easily. (But I'm a stone-axe kind of
guy.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2007 11:50 PM
тАО09-18-2007 11:50 PM
Re: limiting length of PS1 that uses pwd
Try this in your profile:
===============================
export HOST=`/usr/bin/hostname`
export PS1='
$LOGNAME@$HOST: [$PWD] \
# '
===============================
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 01:45 AM
тАО09-19-2007 01:45 AM
Re: limiting length of PS1 that uses pwd
I recommend scp/rcp-compatible output:
HOST=${HOST:-$(uname -n)}
PS1="$LOGNAME@$HOST:\${PWD#$HOME/}[!]
"
gives relative pathnames for files under $HOME.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-19-2007 08:50 AM
тАО09-19-2007 08:50 AM
Re: limiting length of PS1 that uses pwd
export PS1=$(hostname):'$PWD'$(echo "\n# ")
then you would have:
rx203:/htc/technology/softwaresystems/regional/field_locations
# _
This allows much longer paths to be visible, while avoiding visual confusion.
-Eric