From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Paul Lew <paullew@cisco.com>
Cc: zsh-users@sunsite.dk
Subject: Re: Bart's urlglobber question [url-magic-space]
Date: Sat, 5 Oct 2002 19:43:57 +0000 [thread overview]
Message-ID: <1021005194357.ZM5844@candle.brasslantern.com> (raw)
In-Reply-To: <1021003175527.ZM21118@candle.brasslantern.com>
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
prev parent reply other threads:[~2002-10-05 19:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [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=1021005194357.ZM5844@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=paullew@cisco.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).