-
|
In December 2018 Finnbar P. Murphy posted a PS1 discipline function that uses parameter-less macros that customizes the ksh93 shell prompt similar to the way you can in Bash. I have been using this function in my .kshrc for the last 3 years and have only found 2 problems with it. The /w and /W macros are supposed to replace $HOME with the ~ character but doesn't. I stumbled upon the following piece of code that replaces $HOME with ~. I have tried to modify the /w and /W macros to do the same but every attempt has failed. Any suggestions as to how to do this will be welcome. I have attached a copy of Finnbar's posting. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Some time ago I wrote these discipline functions for my # RELPWD expands to relative current working directory with ~ support
# and configurable number of pathname components kept
function RELPWD.get
{
typeset del ellip=$'\u2026' v=$PWD keep=${RELPWD.keep}
((${#ellip}==1)) || ellip='...'
[[ ($v == "$HOME" || $v == "$HOME"/*) && $HOME != / ]] && v=\~${v#"$HOME"}
if [[ -n $keep ]]
then del=${v%/$keep}/
[[ $v == /*/$keep ]] && v=$ellip/${v#"$del"}
[[ $v == \~/*/$keep ]] && v=\~/$ellip/${v#"$del"}
fi
.sh.value=$v
}
# convert <=1 to *, 2 to */*, 3 to */*/*, etc.
function RELPWD.keep.set
{
typeset -si i n
let "(n=${.sh.value}) ? 1 : 1" 2>/dev/null || n=2
((n>64)) && n=64 # sanity check
((n<1)) && .sh.value='' && return
.sh.value='*'
for ((i=2; i <= n; i++))
do .sh.value+='/*'
done
}
# change this anytime to set number of pathname components kept
# set to 0 to keep all (but still change your home directory to ~)
RELPWD.keep=2Now that you have w) var+="\$RELPWD";;
W) var+="\$(basename \"\$RELPWD\")";;To get the exact same behaviour as bash (i.e., don't replace any leading components by an ellipsis), set Hope this helps :) |
Beta Was this translation helpful? Give feedback.
Some time ago I wrote these discipline functions for my
.kshrc: