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

Re: Widget of the day: expand absolute path



> Sometimes I want to expand the name of a file on the command line to its
> absolute path with all symbolic links removed, e.g. because I know the
> symbolic link is volatile.  I can do that with glob qualifiers, but if
> I'm likely to want to refer to the file in the ZLE history, or I want to
> edit the path to refer to a related file in the resulting target path,
> it's quite convenient to expand it immediately. This widget does that.

Thank you! This is very useful.

But there is a small problem when executing it on a word that does not
actually match any file. It will print an error message and clear out
the word completely.

I suggest the following change:

@@ -10,7 +10,8 @@ autoload -Uz modify-current-argument
 if (( ! ${+functions[glob-expand-absolute-path]} )); then
   glob-expand-absolute-path() {
     local -a files
-    files=(${~1}(:A))
+    files=(${~1}(N:A))
+    (( $#files )) || return
     REPLY=${(D)files[1]}
   }
 fi



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