Skip to content
Discussion options

You must be logged in to vote

Some time ago I wrote these discipline functions for my .kshrc:

# 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
{
  …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@rwmills
Comment options

@McDutchie
Comment options

Answer selected by rwmills
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants