Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Tidying MANPATH



Hi!

> MANPATH=/path1:/path2::/path3
> 
> That means that system manpaths are searched after /path1
> and /path2 but before /path3. The problem is that while
> 
> manpath=($^manpath(N))

After few hours of experimenting I was able to come up with these lines, they're surely ugly but seem to work well:

# Testing only
mkdir -p "/tmp/test dir"
export MANPATH="//usr//:/tmp/test dir:///notdir//::/bin://usr///://etc//:/var/"
echo "MANPATH before: $MANPATH"
# Remove non-existing directories
path=($^path(N^M))
[[ -n "$MANPATH" ]] && export MANPATH=${MANPATH//::/:/:}
[[ -n "$MANPATH" ]] && manpath=($^manpath(N^M))
# Remove duplicate and trailing slashes
setopt EXTENDED_GLOB
path=(${${path//\/##/\/}%/})
[[ -n "$MANPATH" ]] && export MANPATH=${${${MANPATH//\/##/\/}//\/:/:}%/}
unsetopt EXTENDED_GLOB
[[ -n "$MANPATH" ]] && export MANPATH=${MANPATH//:\/:/::}
# Remove duplicate directories
typeset -U path manpath
echo "MANPATH after : $MANPATH"

And output for those echoes is:

MANPATH before: //usr//:/tmp/test dir:///notdir//::/bin://usr///://etc//:/var/
MANPATH after : /usr:/tmp/test dir::/bin:/etc:/var

Due to extreme ugliness I might remove the duplicate/trailing slash cleaning but most importantly the non-existing and duplicate dirs are now removed ok while still preserving :: in MANPATH.

Cheers!




      



Messages sorted by: Reverse Date, Date, Thread, Author