BTS

Issue1351

Title etc/zsh/zshrc: make sll() do actually s.th. usefull
Priority feature Status resolved
Superseder Nosy List Xk2c
Assigned To Topics

Created on 2015-05-17.15:01:19 by Xk2c, last changed 2016-05-08.14:08:11 by Xk2c.

Files
File name Uploaded Type Edit Remove
0001-patch-b_sll_updated.patch Xk2c, 2015-05-24.20:01:33 text/x-diff
test.sh TS, 2015-05-18.19:58:43 application/x-sh
Messages
msg5015 (view) Author: Xk2c Date: 2015-06-06.12:35:04
Hello Frank,

Frank Terbeck schrieb/wrote:
> 
> Frank Terbeck <ft@grml.org> added the comment:
> 
> Looks good! I've just pushed this to the repository.
> 
> Thanks again!

Thank you! ;)

nice day.


kind regards,

     Thilo
msg5011 (view) Author: ft Date: 2015-06-06.09:20:30
Looks good! I've just pushed this to the repository.

Thanks again!
msg4971 (view) Author: Xk2c Date: 2015-05-24.20:01:33
Frank Terbeck schrieb/wrote:

-- <snip> --
> The #f1# line needs to be located directly above the "sll() {" line,

check.

> I'd like this to be
> 
>     if ...; then

check.

-- <snip> --
> Also for consistency, "local -i RTN ..." and "local -a SEENINODES" here.

check.

-- <snip> --
> Also for consistency
> 
>     for i in ...; do

check.

Updated patch attached. It also fixes a bug in symlink loop detection.
I ran a complete test suite to make sure no regression is introduced.


> Other than that, this looks good to me.
> 
> Thanks for your work!

Thank you for your review!



kind regards,

     Thilo
msg4970 (view) Author: ft Date: 2015-05-24.09:29:31
Hi,

Mika highlighted this to me for review. So here goes:

-#f1# List symlinks in detail (more detailed version of 'readlink -f' and
'whence -s')
+#f1# List symlinks in detail (more detailed version of 'readlink -f', 'whence
-s' and 'namei -l')
+#
+# Usage:
+#
[...]

The #f1# line needs to be located directly above the "sll() {" line, because
the reference-chart generation script takes a look at the line below to
determine the name of the function that is documented.

 sll() {
-    [[ -z "$1" ]] && printf 'Usage: %s <file(s)>\n' "$0" && return 1
-    local file
-    for file in "$@" ; do
+    if [[ -z ${1} ]]
+    then

I'd like this to be

    if ...; then

for consistency with most of the existing code.

[...]
+    local curdir="${PWD}"
+    declare -i RTN LINODE i
+    declare -a SEENINODES

Also for consistency, "local -i RTN ..." and "local -a SEENINODES" here.

[...]
+                LINODE=$(zstat -L +inode "${file}")
+                for i in ${SEENINODES}
+                do

Also for consistency

    for i in ...; do


Other than that, this looks good to me.

Thanks for your work!


Regards, Frank
msg4969 (view) Author: TS Date: 2015-05-23.11:45:14
Thilo Six schrieb/wrote:
-- <snip> --
> This whole thing is quite more complex then i ever could imagine, before.
> But then what i really like is, i have learned quite a bit through all that.

Hello

now i have a version that suits me. The decision if it also suit grml is left to
you.

A few notes:
The usage of cd seem hackish probably at first. Yet i have come to conclude cd
is a rather powerfull builtin. Especially after reading the aforementioned
article. I now think using cd is no more insane then storing a value in a
variable. It simply just changes the env. Also this way we drop the hard work of
resolving absolute vs. relative symlinks to the shell which is rather informed
about how to do that.
Yes i am aware of modifiers :a and :A. Still these break in certain use cases.

anyway. Final version attached.


kind regards,

     Thilo
msg4962 (view) Author: Xk2c Date: 2015-05-19.23:22:13
Hello

-- <snip a whole lot of crap> --

the more i look into this the more i get puzzeld.


First of i have read this:
http://unix.stackexchange.com/a/79621

Which seems to me like a comprehensive summary of the whole complexity surouding
handling of symlinks.

Linux Kernel source says:
This limits recursive symlink follows to 8, while limiting consecutive symlinks
to 40.

% namei -l
says "exceeded limit of symlinks" after an arbitrary limit of 20.

% ls
starts to mark symlinks as broken after 42 linked symlinks (which i guess is
what meant as consecutive symlinks).

I guess with my arbitrary limit of 8 i am arbitrary in the middle of everyone
else.  ;)

This whole thing is quite more complex then i ever could imagine, before.
But then what i really like is, i have learned quite a bit through all that.

i stop for tonight.

I look more into this later this week.



kind regards,

     Thilo
msg4961 (view) Author: TS Date: 2015-05-18.21:31:27
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
msg4960 (view) Author: Xk2c Date: 2015-05-18.20:20:38
-- <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.

> 
>>
>> Thanks!
>>
>> kind regards,
>>
>>      Thilo
>>
> 
> _____________________________________
> GRML issue tracker <bts@bts.grml.org>
> <http://bts.grml.org/grml/issue1351>
> _____________________________________
>
msg4959 (view) Author: TS Date: 2015-05-18.19:58:43
-- <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
>
msg4958 (view) Author: Xk2c Date: 2015-05-18.17:35:33
Michael Prokop schrieb/wrote:

-- <snip> --
>> Attached patch fixes this.
> 
> I think the present logic is fine:
> 
> | % sll =java
> | lrwxrwxrwx 1 root root 22 Nov 28  2013 /usr/bin/java -> /etc/alternatives/java
> | lrwxrwxrwx 1 root root 46 Nov 28  2013 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

ahh ok. I have not been aware of this = thing.
I tried like this:
% l
total 0
-rw------- 1 user user 0  19:23 18.05.2015  file
lrwxrwxrwx 1 user user 4  19:24 18.05.2015  lnk1 -> file
% sll lnk1
lrwxrwxrwx 1 user user 4 Mai 18 19:24 lnk1 -> file

Which gave me nothing more usefull over ls -l. But as i understand its purpose
is to do a $path lookup first, which in turn is neat.

> So /usr/bin/java is my java binary in $PATH, pointing to
> /etc/alternatives/java which itself points to
> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java.
> 
> With your patch we would get:
> 
> | % sll =java
> | lrwxrwxrwx 1 root root 46 Nov 28  2013 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
> | -rwxr-xr-x 1 root root 6368 Apr 26 15:48 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
> 
> ... which dereferences the files before listing them, so the
> output is incomplete because of the missing /usr/bin/java ->
> /etc/alternatives/java connection.
> 
> What we might want do though is actually adding a full listing of
> the resulting target file, so being
> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java in the above example
> - maybe that's the point you're trying to address? So what might be
> interesting to get is:
> 
> | % sll =java
> | lrwxrwxrwx 1 root root 22 Nov 28  2013 /usr/bin/java -> /etc/alternatives/java
> | lrwxrwxrwx 1 root root 46 Nov 28  2013 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
> | -rwxr-xr-x 1 root root 6368 Apr 26 15:48 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
> 
> I'd definitely appreciate and welcome a patch which implements that.

I look into this. And also in updating its comment and usage hint.

Thanks!

kind regards,

     Thilo
msg4957 (view) Author: mika Date: 2015-05-18.11:15:42
* Thilo Six wrote in grml's BTS on 20150517 / 17:01:

> looking at sll() in etc/zsh/zshrc i think two lines should be swapped to
> actually do s.th. useful in that function.
> Excuse me if i miss s.th. obvious.

> Attached patch fixes this.

I think the present logic is fine:

| % sll =java
| lrwxrwxrwx 1 root root 22 Nov 28  2013 /usr/bin/java -> /etc/alternatives/java
| lrwxrwxrwx 1 root root 46 Nov 28  2013 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

So /usr/bin/java is my java binary in $PATH, pointing to
/etc/alternatives/java which itself points to
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java.

With your patch we would get:

| % sll =java
| lrwxrwxrwx 1 root root 46 Nov 28  2013 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
| -rwxr-xr-x 1 root root 6368 Apr 26 15:48 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

... which dereferences the files before listing them, so the
output is incomplete because of the missing /usr/bin/java ->
/etc/alternatives/java connection.

What we might want do though is actually adding a full listing of
the resulting target file, so being
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java in the above example
- maybe that's the point you're trying to address? So what might be
interesting to get is:

| % sll =java
| lrwxrwxrwx 1 root root 22 Nov 28  2013 /usr/bin/java -> /etc/alternatives/java
| lrwxrwxrwx 1 root root 46 Nov 28  2013 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
| -rwxr-xr-x 1 root root 6368 Apr 26 15:48 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

I'd definitely appreciate and welcome a patch which implements that.

regards,
-mika-
msg4956 (view) Author: Xk2c Date: 2015-05-17.15:19:07
> Hello
> 
> looking at sll() in etc/zsh/zshrc i think two lines should be swapped to
> actually do s.th. useful in that function.
> Excuse me if i miss s.th. obvious.

And since we are at this, make it whitespace save.
Patch updated accordingly.

> Attached patch fixes this.
> 
> 
> kind regards,
> 
>      Thilo
> 
> ----------
> files: 0001-etc_zsh_zshrc-fix-func-sll.patch
> messages: 4955
> nosy: Xk2c
> status: unread
> title: etc/zsh/zshrc: make sll() do actually s.th. usefull
> 
> _____________________________________
> GRML issue tracker <bts@bts.grml.org>
> <http://bts.grml.org/grml/issue1351>
> _____________________________________
>
msg4955 (view) Author: Xk2c Date: 2015-05-17.15:01:19
Hello

looking at sll() in etc/zsh/zshrc i think two lines should be swapped to
actually do s.th. useful in that function.
Excuse me if i miss s.th. obvious.

Attached patch fixes this.


kind regards,

     Thilo
History
Date User Action Args
2016-05-08 14:08:11Xk2csetstatus: fixed-in-git -> resolved
2015-06-06 12:35:04Xk2csetmessages: + msg5015
2015-06-06 09:20:30ftsetstatus: chatting -> fixed-in-git
messages: + msg5011
2015-05-24 20:07:06Xk2csetfiles: - 0001-modified-sll-to-among-others-detect-symlink-loops-an.patch
2015-05-24 20:01:33Xk2csetfiles: + 0001-patch-b_sll_updated.patch
messages: + msg4971
2015-05-24 09:29:31ftsetmessages: + msg4970
2015-05-23 11:46:02Xk2csetfiles: - sll
2015-05-23 11:45:14TSsetfiles: + 0001-modified-sll-to-among-others-detect-symlink-loops-an.patch
messages: + msg4969
2015-05-20 16:56:16mikasetpriority: feature
2015-05-19 23:22:14Xk2csetmessages: + msg4962
2015-05-18 21:32:52Xk2csetfiles: - sll
2015-05-18 21:31:27TSsetfiles: + sll
messages: + msg4961
2015-05-18 20:21:26Xk2csetfiles: - 0001-etc_zsh_zshrc-fix-func-sll.patch
2015-05-18 20:21:20Xk2csetfiles: - sll
2015-05-18 20:20:38Xk2csetfiles: + sll
messages: + msg4960
2015-05-18 19:58:43TSsetfiles: + test.sh, sll
messages: + msg4959
2015-05-18 17:35:33Xk2csetmessages: + msg4958
2015-05-18 11:15:42mikasetmessages: + msg4957
2015-05-17 15:20:19Xk2csetfiles: - 0001-etc_zsh_zshrc-fix-func-sll.patch
2015-05-17 15:19:07Xk2csetfiles: + 0001-etc_zsh_zshrc-fix-func-sll.patch
status: unread -> chatting
messages: + msg4956
2015-05-17 15:01:19Xk2ccreate