zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Vincent Lefevre <vincent@vinc17.org>,
	Zsh users list <zsh-users@sunsite.dk>
Subject: Re: zsh-4.04 and w3m browser
Date: Fri, 30 Aug 2002 05:31:59 +0000	[thread overview]
Message-ID: <1020830053200.ZM9539@candle.brasslantern.com> (raw)
In-Reply-To: <1020828152500.ZM7603@candle.brasslantern.com>

On Aug 28,  3:25pm, Bart Schaefer wrote:
}
} Minimally tested, but seems to work:

Actually there was a bug, which is that even with ${var##pat} it's not
necessarily the case that the longest pattern will be matched when the
pattern contains alternatives with (|) -- because that form tries each
alternative in order, and stops when one matches.

So the right formulation is (only two of the `|' have moved):

---- 8< ---- snip ---- 8< ----
function urlglobber {
    local -a args globbed
    local arg command="$1"
    shift
    for arg
    do
	case "${arg}" in
	(ftp://(|localhost)/*)
	    globbed=( ${~${arg##ftp://(localhost|)}} )
	    args[$#args+1]=( "${(M)arg##ftp://(localhost|)}${(@)^globbed}" )
	    ;;
	((http(|s)|ftp):*) args[$#args+1]="$arg";;
	(*) args[$#args+1]=( ${~arg} );;
	esac
    done
    "$command" "${(@)args}"
}
alias globurl='noglob urlglobber'
---- 8< ---- snip ---- 8< ----

However, I had another thought about a possible approach to handling URLs
in shell input:

---- 8< ---- snip ---- 8< ----
function url-magic-space {
    local words
    words=("${(@Q)${(q)=LBUFFER}}") 
    case "$words[-1]" in
    (*[\'\"]*) ;;
    (ftp://(|localhost)/(~|*([][?#*]|\(|\)))*)
	local left="${(qqM)${words[-1]}##ftp://(localhost|)}"
	local right="${${words[-1]}##ftp://(localhost|)}"
	right="${right/#\/~/~}"
	words[-1]="$left"'"${(f)^$(print -lr -- '"$right"')}"' ;;
    (http(|s)|ftp):*) words[-1]="${(qq)words[-1]}" ;;
    esac
    LBUFFER="${(j: :)words}" 
    zle self-insert		# Or  zle magic-space  if you prefer ...
}
zle -N url-magic-space
bindkey ' ' url-magic-space
---- 8< ---- snip ---- 8< ----

When SPACE is pressed, the widget above rewrites e.g.

    zsh% echo ftp://localhost/~/*

into

    zsh% echo ftp://localhost"${(f)^$(print -lr -- ~/*)}" 

which should have the desired end result (unless you have file names with
embedded newlines), even if it's not so readable.

It also turns

    zsh% lynx http://somewhere.com/something.cgi?x=1&y=2&so=on

into

    zsh% lynx 'http://somewhere.com/something.cgi?x=1&y=2&so=on' 

(that is, it adds the quotes for you) and it is clever enough to try not
to mess with a word that already uses quotes (though that too might be
improved a little bit with a lot of effort).

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


      parent reply	other threads:[~2002-08-30  5:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-28 11:23 Arthur Alinovi
2002-08-28 11:27 ` Peter Stephenson
2002-08-28 11:28 ` Roman Neuhauser
2002-08-28 11:30 ` Sven Wischnowsky
2002-08-28 11:36 ` Thomas Köhler
2002-08-28 12:18   ` Vincent Lefevre
2002-08-28 12:50     ` Peter Stephenson
2002-08-28 13:08       ` Vincent Lefevre
2002-08-28 15:25         ` Bart Schaefer
2002-08-28 15:33           ` Vincent Lefevre
2002-08-28 15:52             ` Bart Schaefer
2002-08-28 16:48             ` Wayne Davison
2002-08-30  5:31           ` Bart Schaefer [this message]

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=1020830053200.ZM9539@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=vincent@vinc17.org \
    --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).