[issue1351] etc/zsh/zshrc: make sll() do actually s.th. usefull

Thilo Six bts at bts.grml.org
Mon May 18 23:31:27 CEST 2015


Thilo Six <TS at Xk2c.de> added the comment:

Thilo Six schrieb/wrote:
> -- <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.
> 
> Here is a slightly improved version. Improved regarding return status.

Fixed a bug with multiple arguments. Updated!



kind regards,

     Thilo

----------
files: sll, sll, test.sh
messages: 4955, 4956, 4957, 4958, 4959, 4960, 4961
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 --------------
# 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 jumpd
    local curdir="${PWD}"
    declare -i lncnt RTN
    RTN=0

    for file in "${@}" ; do
        lncnt=0
        ls -l "${file}" || RTN=1
        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}"  || RTN=1
            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}"  || RTN=1
            fi
            ls -l "${PWD}/${file}"     || RTN=1
            lncnt=$(( lncnt +1 ))
            if (( ${lncnt} == 8 ))
            then
                print "limit for recursive symlinks reeached!"
                if (( ${#}  == 1 ))
                then
                    print ""
                fi
                builtin cd "${curdir}"
                RTN=1
                break
            fi
        done
        shift 1
        if (( ${#} >= 1 ))
        then
            print ""
        fi
        builtin cd "${curdir}"
    done
    return ${RTN}
}



More information about the Bugs-changes mailing list