Discussion:
ksh, PS1 and PWD
(too old to reply)
Uwe Werler
2016-08-03 22:19:44 UTC
Permalink
Hello list,

maybe this can be done better (~/.kshrc):

_pwd(){

local _len="25"

local _sym="/<.."

[[ ${PWD} == ${HOME}* ]] && { PWD="~${PWD#${HOME}}"; _sym="~${_sym#/}"; }

[[ ${#PWD} -gt $_len ]] && { typeset -R"$_len" local _pwd=$PWD; PWD="${_sym}/${_pwd#*/}"; }

print $PWD
}

PS1='\h:$(_pwd)\\$ '

Any hints?

Thanks in advance.

--
Fred
2016-08-03 23:25:06 UTC
Permalink
Post by Uwe Werler
Hello list,
_pwd(){
local _len="25"
local _sym="/<.."
[[ ${PWD} == ${HOME}* ]] && { PWD="~${PWD#${HOME}}"; _sym="~${_sym#/}"; }
[[ ${#PWD} -gt $_len ]] && { typeset -R"$_len" local _pwd=$PWD; PWD="${_sym}/${_pwd#*/}"; }
print $PWD
}
PS1='\h:$(_pwd)\\$ '
Any hints?
Thanks in advance.
are you looking for \w?

as in:

PS1="\h:\u \w> "

hth

Fred
Fred
2016-08-03 23:28:13 UTC
Permalink
Post by Fred
Post by Uwe Werler
Hello list,
_pwd(){
local _len="25"
local _sym="/<.."
[[ ${PWD} == ${HOME}* ]] && { PWD="~${PWD#${HOME}}";
_sym="~${_sym#/}"; }
[[ ${#PWD} -gt $_len ]] && { typeset -R"$_len" local _pwd=$PWD;
PWD="${_sym}/${_pwd#*/}"; }
print $PWD
}
PS1='\h:$(_pwd)\\$ '
Any hints?
Thanks in advance.
are you looking for \w?
PS1="\h:\u \w> "
hth
Fred
\w won't help shorten the $PWD

Sorry for the noise...
l***@wrant.com
2016-08-04 00:10:33 UTC
Permalink
Post by Uwe Werler
Hello list,
[..]
Post by Uwe Werler
PS1='\h:$(_pwd)\\$ '
Any hints?
Thanks in advance.
Hi Uwe,

The best advice as always: simplicity. Check in ksh(1), parameter PS1:

man ksh - public domain Korn shell (parameters)
[http://man.openbsd.org/ksh#Parameters]

You know, you've gone too far with the file and directory names when \w
path does not fit on one line. Hiding this fact is harmful obscurity..

$ grep PS1 .profile
export PS1='\n\a=== \d [\A] \u@\h(\l) \w j\j e$? h\!\n\$ '

You're probably looking for directory abbreviation tools to help this:

dirabbrev - abbreviations for long directory paths
[https://staff.science.uva.nl/c.dominik/Tools/dirabbrev/]

At first glance, it's probably way too much for prompt display anyway..
I'd personally reduce this as much as possible with the ksh(1) default.

You can always call external tools for more information. You'll over
time decide how often you need it, and not feel limited on new setups.

Kind regards,
Anton
Craig Skinner
2016-08-04 08:04:03 UTC
Permalink
Hi Uwe,
Post by Uwe Werler
PS1='\h:$(_pwd)\\$ '
You may have already seen this in ksh(1):
PS1
...
\W The basename of the current working directory. $HOME is abbreviated as `~'.

e.g: PS1="<\u@\h:\W \j> \\$ "

<***@teak:~ 0>$ sleep 5 &
[1] 24386
<***@teak:~ 1>$ cd /var/unbound
<***@teak:unbound 1>$ print $PS1
<\u@\h:\W \j>\$

Cool,
--
Craig Skinner | http://linkd.in/yGqkv7
Paolo Aglialoro
2016-08-04 09:34:22 UTC
Permalink
If you like it coloured, and also would appreciate to know which terminal
you're in, here's my way:

TTY=$(tty)
TTY=${TTY##*/}
export
PS1="\[\e[32;1m\][\[\e[31;1m\]\u\[\e[32;1m\]@\h:\[\e[36;1m\]$TTY\[\e[32;1m\]:\[\e[34;1m\]\w\[\e[32;1m\]]
"

I usually put this in /etc/profile so that I have it system-wide.
Loading...