zsh-users
 help / color / mirror / code / Atom feed
* Bart's urlglobber question
@ 2002-10-03 15:28 Paul Lew
  2002-10-03 16:09 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Lew @ 2002-10-03 15:28 UTC (permalink / raw)
  To: zsh-users

I am trying to use the urlglobber but there is a problem:

    > w3m http://yahoo.com/?id=test&name=paul&addr=home
    zsh: parse error near `&'

    > echo $ZSH_VERSION
    4.0.5

Seems noglob does not handle the '&' because pure simple:

    > noglob foo&bar

will not work either.  So zsh will treat the above statement as:

     'noglob foo' &  and 'bar'

then how can I ever achieve the original goal of not supplying quotes
when using w3m?

BTW, the definitions for w3m is:

    > alias   w3m='globurl w3m'
    > alias   globurl='noglob urlglobber'

The urlglobber came from:
# Bart Schaefer" <schaefer@brasslantern.com>
# Fri, 30 Aug 2002 05:31:59 +0000
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}"
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Bart's urlglobber question
  2002-10-03 15:28 Bart's urlglobber question Paul Lew
@ 2002-10-03 16:09 ` Bart Schaefer
  2002-10-03 17:25   ` Bart's urlglobber question [url-magic-space] Paul Lew
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2002-10-03 16:09 UTC (permalink / raw)
  To: Paul Lew, zsh-users

On Oct 3,  8:28am, Paul Lew wrote:
}
} Seems noglob does not handle the '&'

Of course not.  It's not a glob character, it's a statement separator.

} then how can I ever achieve the original goal of not supplying quotes
} when using w3m?

Did you see my url-magic-space posting?

    http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=5319

Here's a slight variation on it:

---- 8< ---- snip ---- 8< ----
function url-quote-magic {
    local words back=0
    words=("${(@Q)${(q)=LBUFFER}}")
    [[ "$KEYS" != [[:space:]] ]] && back=1
    case "$words[-1]" in
    (*[\'\"]*) back=0;;
    (ftp://(|localhost)/(~|*([][?#*]|\(|\)))*)
	local left="${(qqM)${words[-1]}##ftp://(localhost|)}"
	local right="${${words[-1]}##ftp://(localhost|)}"
	right="${right/#\/~/~}"
	words[-1]="$left"'"${(f)^$(print -lr -- '"$right"')}"'
	((back)) && back=3;;
    (http(|s)|ftp):*) words[-1]="${(qq)words[-1]}" ;;
    esac
    LBUFFER="${(j: :)words}"
    ((CURSOR-=back))
    zle .self-insert
}
zle -N url-quote-magic
for key in ' ' '?' '&'; do bindkey "$key" url-quote-magic; done
---- 8< ---- snip ---- 8< ----

The above could use some improvement in for multi-line buffers; check the
value of BUFFERLINES and save and elide everything not on the current line
before manipulating $words, then restore it to the beginning of LBUFFER at
the end.  I don't have time to fiddle with that just now.

-- 
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   


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Bart's urlglobber question [url-magic-space]
  2002-10-03 16:09 ` Bart Schaefer
@ 2002-10-03 17:25   ` Paul Lew
  2002-10-03 17:55     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Lew @ 2002-10-03 17:25 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

>>>>> "Bart" == Bart Schaefer <schaefer@brasslantern.com> writes:

    Bart> On Oct 3,  8:28am, Paul Lew wrote:
    Bart> }
    Bart> } Seems noglob does not handle the '&'

    Bart> Of course not.  It's not a glob character, it's a statement
    Bart> separator.

    Bart> } then how can I ever achieve the original goal of not
    Bart> } supplying quotes when using w3m?

    Bart> Did you see my url-magic-space posting?

    Bart> http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=5319

I missed that.  Thanks for the tip, The quote insertion is neat!

The url-magic-space has some interesting behavior dont know if you
noticed:

* hit a space at beginning of the prompt result in 2 spaces.  However,
  another space will remove the leading two spaces.  As a result, if I
  type: 'space cd /usr<CR>' when I have histignorespace on, it will
  insert the command into history because the leading space is
  magically disappeared.

* can not type multiple spaces at end of a line, even inside a quote,
  i.e., I can not do the following:

  > echo "testing    here" > file


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Bart's urlglobber question [url-magic-space]
  2002-10-03 17:25   ` Bart's urlglobber question [url-magic-space] Paul Lew
@ 2002-10-03 17:55     ` Bart Schaefer
  2002-10-05 19:43       ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2002-10-03 17:55 UTC (permalink / raw)
  To: Paul Lew; +Cc: zsh-users

On Oct 3, 10:25am, Paul Lew wrote:
} Subject: Re: Bart's urlglobber question [url-magic-space]
}
} The url-magic-space has some interesting behavior dont know if you
} noticed:
} 
} * hit a space at beginning of the prompt result in 2 spaces.  However,
}   another space will remove the leading two spaces.
} 
} * can not type multiple spaces at end of a line, even inside a quote

Yeah, I didn't say it was perfect.  Leading space in LBUFFER should be
preserved and restored the same way preceding lines of multi-line input
should be, and for quoted words it should skip rebuilding LBUFFER from
the joined words.

Another improvement that occurred to me is to have it be aware of and
work with the urlglobber function, so that instead of rewriting the
local-ftp URLs it just quotes them and lets urlglobber deal with it.
Feel free to fiddle and post the result; I may get a chance to look at
it nine or ten hours from now ...

-- 
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   


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Bart's urlglobber question [url-magic-space]
  2002-10-03 17:55     ` Bart Schaefer
@ 2002-10-05 19:43       ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2002-10-05 19:43 UTC (permalink / raw)
  To: Paul Lew; +Cc: zsh-users

On Oct 3,  5:55pm, Bart Schaefer wrote:
}
} Another improvement that occurred to me is to have it be aware of and
} work with the urlglobber function, so that instead of rewriting the
} local-ftp URLs it just quotes them and lets urlglobber deal with it.

Here's something for zsh-workers to think about:  There's no good way
to "stack" functions like this one so that, e.g., you could use it at
the same time as insert-and-predict.

---- 8< ---- snip ---- 8< ----
# Functions to make it easier to type URLs as command line arguments.  As
# you type, the input character is analyzed and, if it may need quoting,
# the current word is checked for a URI schema.  If one is found and the
# current word is not already in quotes, a backslash is inserted before
# the input character.

# As an exception, glob characters in FTP URLs with local file paths are
# not quoted; instead it is assumed that the current command is aliased
# to use the urlglobber helper function.

# Setup:
#	autoload -U url-quote-magic
#	zle -N self-insert url-quote-magic

# TODO:
#	Add zstyles for which URI schema use local globbing.
#	Add zstyles for which characters to quote in each scheme.
#	Automatically recognize commands aliased to urlglobber.
#	Turn this on at colon, and off again at space or accept.
#	Use compsys for nested quoting analysis (e.g., eval).

typeset -gH __url_globs='*?[]^(|)~#{}=' __url_seps=';&<>!'

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'

function url-quote-magic {
    local qkey="${(q)KEYS}"
    if [[ "$KEYS" != "$qkey" ]]
    then
	local lbuf="$LBUFFER$qkey"
	if [[ "${(Q)LBUFFER}$KEYS" == "${(Q)lbuf}" ]]
	then
	    local words
	    words=("${(@Q)${(q)=LBUFFER}}")
	    case "$words[-1]" in
	    (*[\'\"]*) ;;
	    (ftp:/(|/localhost)/*)
		[[ "$__url_seps" == *"$KEYS"* ]] &&
		    LBUFFER="$LBUFFER\\" ;;
	    ((http(|s)|ftp):*)
		[[ "$__url_seps$__url_globs" == *"$KEYS"* ]] &&
		    LBUFFER="$LBUFFER\\" ;;
	    esac
	fi
    fi
    zle .self-insert
}
zle -N self-insert url-quote-magic

# Handle zsh autoloading conventions

[[ -o kshautoload ]] || url-quote-magic "$@"
---- 8< ---- snip ---- 8< ----

-- 
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   


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-10-05 19:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-03 15:28 Bart's urlglobber question Paul Lew
2002-10-03 16:09 ` Bart Schaefer
2002-10-03 17:25   ` Bart's urlglobber question [url-magic-space] Paul Lew
2002-10-03 17:55     ` Bart Schaefer
2002-10-05 19:43       ` Bart Schaefer

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).