zsh-users
 help / color / mirror / code / Atom feed
From: Mikel Ward <mikel@mikelward.com>
To: zsh-users@sunsite.dk
Subject: zsh widget to resolve symlinks
Date: Sun, 10 Dec 2006 11:33:23 +1100	[thread overview]
Message-ID: <457B55D3.9030003@mikelward.com> (raw)
In-Reply-To: <457B5073.90206@mikelward.com>

Here's a working version of the widget to expand a shell word into its
canonical path.

It turns out copy-region-as-kill doesn't use killring but rather
CUTBUFFER.  This is a little confusing!

I'm also surprised that CUTBUFFER persists invocations of zle, yet it
isn't set in the top-level interactive shell.  If I don't reset
CUTBUFFER as the first thing I do, invoking the widget for a second time
on an empty command line inserts the result of the previous invocation,
for example:
> ls .zshrc<^X />
expands to
> ls /home/michael/etc/zshrc

but then
> <^X />
expands to
> /home/michael/etc/zshrc

The only problem I'm aware of with this version is where the file name
contains spaces.  I can't think of a way to easily do this, since we
have the copy-prev-shell-word widget, but no equivalent
kill-prev-shell-word that I would need to update the display.  (I could
get the word, but how would I overwrite it with its real path?)

expand-word-path ()
{
        CUTBUFFER=
        zle backward-word
        zle set-mark-command
        zle forward-word
        zle copy-region-as-kill
        local word=$CUTBUFFER

        local realpath=$(realpath $word 2>/dev/null)
        if test -n "$realpath"
        then
                zle backward-kill-word
                zle -U "$realpath"
        fi
}


  reply	other threads:[~2006-12-10  0:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-09 23:18 error using custom widget: widgets can only be called when ZLE is active Mikel Ward
2006-12-10  0:10 ` error using custom widget: widgets can only be called when ZLE is active [solved] Mikel Ward
2006-12-10  0:33   ` Mikel Ward [this message]
2006-12-10 17:56     ` zsh widget to resolve symlinks Peter Stephenson
2006-12-14 11:22       ` PATCH: argument splitting (was Re: zsh widget to resolve symlinks) Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=457B55D3.9030003@mikelward.com \
    --to=mikel@mikelward.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).