Max Mikhanosha | 29 Jul 04:44

PATCH: option for completion file-sort to follow symlinks

I have all my dotfiles under version control in a separate directory,
and ~/.zshrc ~/.zalias etc are symlinks to the version controlled
directory.

So even when I have: "zstyle ':completion:*:*:*:*' file-sort date"
doing vi ~/.z<Tab> sorts the files based on symlink modtime and not
the file that its pointing to.

The one line patch included into the end of this email adds one
additional option `follow' to the file-sort, which makes it follow
symlinks.

# follow symlinks when sorting
zstyle ':completion:*:*:*:*' file-sort date follow

Regards,
  Max

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.25
diff -u -r1.25 _path_files
--- Completion/Unix/Type/_path_files	7 Mar 2006 12:52:27 -0000	1.25
+++ Completion/Unix/Type/_path_files	29 Jul 2008 02:43:12 -0000
@@ -113,6 +113,7 @@
   *)                  sort=on;;
   esac
   [[ "$tmp1" = *rev* ]] && sort[1]=O
+  [[ "$tmp1" = *follow* ]] && sort="-$sort"
(Continue reading)

Peter Stephenson | 29 Jul 10:39
Favicon

Re: PATCH: option for completion file-sort to follow symlinks

Max Mikhanosha wrote:
> The one line patch included into the end of this email adds one
> additional option `follow' to the file-sort, which makes it follow
> symlinks.

Thanks, I've committed this with some documentation.

Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.212
diff -u -u -r1.212 compsys.yo
--- compsys.yo	14 Jul 2008 17:39:26 -0000	1.212
+++ compsys.yo	29 Jul 2008 08:38:41 -0000
@@ -1494,7 +1494,10 @@
 `tt(inode)' (or `tt(change)') to sort by the last inode change
 time.  If the style is set to any other value, or is unset, files will be
 sorted alphabetically by name.  If the value contains the string
-`tt(reverse)', sorting is done in the opposite order.
+`tt(reverse)', sorting is done in the opposite order.  If the value
+contains the string `tt(follow)', timestamps are associated with the
+targets of symbolic links; the default is to use the timestamps
+of the links themselves.
 )
 kindex(filter, completion style)
 item(tt(filter))(

--

-- 
Peter Stephenson <pws <at> csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
(Continue reading)

Max Mikhanosha | 30 Jul 15:34

Re: PATCH: option for completion file-sort to follow symlinks

My initial patch broke completing cd into a symbolic link pointing to
the directory (if sorting with follow was turned on).  That is because
for cd completion final flags are (-/) and with sorting set to "date
follow" flags were becoming "(-om-/)" thus 2nd dash was turning
following links off.

Correction below: make sort-files follow option restore the
follow-links qualifier to initial state:

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.33
diff -u -r1.33 _path_files
--- Completion/Unix/Type/_path_files	29 Jul 2008 08:39:42 -0000	1.33
+++ Completion/Unix/Type/_path_files	30 Jul 2008 13:32:08 -0000
@@ -123,7 +123,7 @@
   *)                  sort=on;;
   esac
   [[ "$tmp1" = *rev* ]] && sort[1]=O
-  [[ "$tmp1" = *follow* ]] && sort="-$sort"
+  [[ "$tmp1" = *follow* ]] && sort="-${sort}-"

   if [[ "$sort" = on ]]; then
     sort=

At Tue, 29 Jul 2008 09:39:44 +0100,
Peter Stephenson wrote:
> 
> Max Mikhanosha wrote:
(Continue reading)


Gmane