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

Re: _canonical_path not working on *BSD




Quoting Peter Stephenson <pws@xxxxxxx>:

On Wed, 26 Mar 2008 17:38:24 +0100
Pea <zsh@xxxxxxxxxxxx> wrote:
This almost works:

umount [TAB] gives me:
[pea@coredump:~]% umount
             /            /dev/sd0a    /dev/svnd0a  /home/pea


umout /[TAB] gives me:
[pea@coredump:~]% umount /
/            /dev/sd0a    /dev/svnd0a  /home/pea


But umount /d[TAB] or umount /de[TAB] or umount /h[TAB] give me
nothing...
It worked with readlinks

Thanks for trying...  looks like my assumption about the status test
was wrong.

Index: Completion/Unix/Type/_canonical_paths
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_canonical_paths,v
retrieving revision 1.1
diff -u -r1.1 _canonical_paths
--- Completion/Unix/Type/_canonical_paths	28 May 2006 18:36:06 -0000	1.1
+++ Completion/Unix/Type/_canonical_paths	26 Mar 2008 16:43:46 -0000
@@ -27,18 +27,38 @@

 shift 2

-if (( ! $+commands[readlink] )); then
+if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then
   _wanted "$tag" expl "$desc" compadd $__gopts $@ && ret=0
   return ret
 fi

+typeset REPLY
 typeset -a matches files

+_canonical_paths_get_canonical_path() {
+  typeset newfile
+  typeset -A seen
+
+  REPLY=$1
+  # Guard against loops.
+  while [[ -z ${seen[$REPLY]} ]]; do
+    seen[$REPLY]=1
+    newfile=$(zstat +link $REPLY 2>/dev/null)
+    if [[ -n $newfile ]]; then
+      REPLY=$newfile
+    else
+      break
+    fi
+  done
+}
+
+
 if (( $__opts[(I)-N] )); then
   files=($@)
 else
   for __index in $@; do
-    files+=$(readlink -qf $__index)
+    _canonical_paths_get_canonical_path $__index
+    files+=($REPLY)
   done
 fi

@@ -48,13 +68,16 @@
   expref=${~origpref}
   [[ $origpref == (|*/). ]] && rltrim=.
   curpref=${${expref%$rltrim}:-./}
-  canpref=$(readlink -qf $curpref)
-  if [[ $? -eq 0 ]]; then
-    [[ $curpref == */ && $canpref == *[^/] ]] && canpref+=/
-    canpref+=$rltrim
-    [[ $expref == *[^/] && $canpref == */ ]] && origpref+=/
-    matches+=(${${(M)files:#$canpref*}/$canpref/$origpref})
+  if zstat $curpref >&/dev/null; then
+    _canonical_paths_get_canonical_path $curpref
+    canpref=$REPLY
+  else
+    canpref=$curpref
   fi
+  [[ $curpref == */ && $canpref == *[^/] ]] && canpref+=/
+  canpref+=$rltrim
+  [[ $expref == *[^/] && $canpref == */ ]] && origpref+=/
+  matches+=(${${(M)files:#$canpref*}/$canpref/$origpref})
   for subdir in $expref?*(@); do
     _canonical_paths_add_paths ${subdir/$expref/$origpref} add
   done


--
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


Wonderful, this one works great on FreeBSD, hope it will be ok for others.

Thanks.
Baptiste.

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



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