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

Re: Converting relative paths to full




On 11/08/2021 00.36, Bart Schaefer wrote:
That's far more complicated than necessary.

function _edit_command_to_register_full_path {
   emulate -L zsh
   for element in ${(z)1}; do
     # Don't care about parameters
     [[ $element == -* ]] && continue
     FULLPATH="${element:P}"
     # Don't replace when already the full path
     [[ $element == $FULLPATH ]] && continue
     # Don't replace when path doesn't exist
     [[ -f $FULLPATH || -d $FULLPATH ]] || continue
     # [[:space:]] to protect previous replacements
     # (this is still not foolproof for path prefixes)
     set -- "${1/[[:space:]]$element/ $FULLPATH}"
   done
   print -Sr -- ${1%%$'\n'}
   return 1
}

Thank you, that looks indeed much better.

I am still potato on shell builtins topic, will read and try to shorten my 400-line rc file :)





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