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

Re: Absolute pathnames similar to expand-cmd-path



On 25 January 2011 16:56, David Evans <david.evans@xxxxxxxxxxxx> wrote:
> expand-cmd-path is a great widget. Is there a similar thing for turning the current word
> into an absolute path? Sometimes I'm typing a ../../.. chain and would like to see how far
> I've gone. This should be easy with a widget function and :a but I don't want to write it
> if even less work is needed.

I have this lying around. It shouldn't be too hard to modify it to do
what you want.

autoload -U split-shell-arguments

function _split_shell_arguments_under()
{
  local -a reply
  split-shell-arguments
  #have to duplicate some of modify-current-argument to get the word
  #_under_ the cursor, not after.
  setopt localoptions noksharrays multibyte
  if (( REPLY > 1 )); then
    if (( REPLY & 1 )); then
      (( REPLY-- ))
    fi
  fi
  REPLY=${reply[$REPLY]}
}

function _showcurrargrealpath() {
  setopt localoptions nonomatch
  local REPLY REALPATH
  _split_shell_arguments_under
  #zle -M "$(realpath ${(Q)${~REPLY}} 2> /dev/null | head -n1 || echo
1>&2 "No such path")"
  REALPATH=( ${(Q)${~REPLY}}(:A) )
  zle -M "${REALPATH:-Path not found: $REPLY}"
}


-- 
Mikael Magnusson



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