From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22556 invoked from network); 5 Oct 2002 19:45:12 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 5 Oct 2002 19:45:12 -0000 Received: (qmail 21443 invoked by alias); 5 Oct 2002 19:44:37 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5424 Received: (qmail 21431 invoked from network); 5 Oct 2002 19:44:35 -0000 From: "Bart Schaefer" Message-Id: <1021005194357.ZM5844@candle.brasslantern.com> Date: Sat, 5 Oct 2002 19:43:57 +0000 In-Reply-To: <1021003175527.ZM21118@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "Re: Bart's urlglobber question [url-magic-space]" (Oct 3, 5:55pm) References: <15772.25139.506561.955462@paullew-ultra.cisco.com> <1021003160943.ZM20996@candle.brasslantern.com> <15772.32150.190303.622794@paullew-ultra.cisco.com> <1021003175527.ZM21118@candle.brasslantern.com> X-Mailer: Z-Mail (5.0.0 30July97) To: Paul Lew Subject: Re: Bart's urlglobber question [url-magic-space] Cc: zsh-users@sunsite.dk MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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