[issue1351] etc/zsh/zshrc: make sll() do actually s.th. usefull
Thilo Six
bts at bts.grml.org
Mon May 18 21:58:43 CEST 2015
Thilo Six <TS at Xk2c.de> added the comment:
-- <snip> --
> I look into this. And also in updating its comment and usage hint.
Attached is what i could come up with. It does not use zsh magic.
Could be zsh'ified though. ;) Personally i happy with the result.
Also attached is a shell script that creates a test env for sll().
I testet it as good as i could think of. Tell me what you think.
>
> Thanks!
>
> kind regards,
>
> Thilo
>
----------
files: 0001-etc_zsh_zshrc-fix-func-sll.patch, sll, test.sh
messages: 4955, 4956, 4957, 4958, 4959
nosy: Xk2c
status: chatting
title: etc/zsh/zshrc: make sll() do actually s.th. usefull
_____________________________________
GRML issue tracker <bts at bts.grml.org>
<http://bts.grml.org/grml/issue1351>
_____________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.sh
Type: application/x-sh
Size: 247 bytes
Desc: not available
URL: <http://ml.grml.org/pipermail/bugs-changes/attachments/20150518/122b01d5/attachment.sh>
-------------- next part --------------
# vim: ts=8:sw=4:sts=4:et:ft=zsh:
# kate: byte-order-marker false; dynamic-word-wrap false; indent-mode normal; indent-pasted-text true; indent-width 4; keep-extra-spaces false; newline-at-eof true; remove-trailing-spaces all; replace-tabs true; replace-tabs-save true; show-tabs true; smart-home true; syntax Zsh; tab-width 8; word-wrap false;
#-----------------------------------------------------------------------
#
#f1# List symlinks in detail (more detailed version of 'readlink -f' and 'whence -s')
#
# Usage:
#
# e.g.: a -> b -> c -> d ....
#
# sll a
#
# Note: limit for recursive symlinks on linux:
# http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/namei.c?id=refs/heads/master#l808
# This limits recursive symlink follows to 8, while limiting
# consecutive symlinks to 40.
#
# if given parameter with leading '=', lookup $PATH for parameter and resolve that
#
# sll =java
#
sll() {
if [[ -z ${1} ]]
then
printf 'Usage: %s <symlink(s)>\n' "${0}"
return 1
fi
local file
local curdir="${PWD}"
local jumpd
declare -i lncnt
lncnt=0
for file in "${@}" ; do
ls -l "${file}"
while [[ -h "$file" ]] ; do
# remove trailing / if any
file="${file%/}"
# split $file in dirname
jumpd="${file%/*}"
# ... and basename
file="${file##*/}"
if [[ -d ${jumpd} ]]
then
builtin cd "${jumpd}"
fi
file=$(readlink "$file")
# remove trailing / if any
file="${file%/}"
# split $file in dirname
jumpd="${file%/*}"
# ... and basename
file="${file##*/}"
if [[ -d ${jumpd} ]]
then
builtin cd "${jumpd}"
fi
ls -l "${PWD}/${file}"
lncnt=$(( lncnt +1 ))
if (( ${lncnt} == 8 ))
then
print "limit for recursive symlinks reeached!"
builtin cd "${curdir}"
return 1
fi
done
builtin cd "${curdir}"
done
return 0
}
More information about the Bugs-changes
mailing list