zsh-workers
 help / color / mirror / code / Atom feed
From: Tanaka Akira <akr@jaist.ac.jp>
To: Zsh workers <zsh-workers@sunsite.auc.dk>
Subject: Re: PATCH: _urls again (Re: setopt localoptions noautoremoveslash)
Date: 15 Oct 1999 23:36:07 +0900	[thread overview]
Message-ID: <rsqr9iwr8rs.fsf@crane.jaist.ac.jp> (raw)
In-Reply-To: Oliver Kiddle's message of "Fri, 15 Oct 1999 12:24:32 +0100"

This is another refinement for _urls.

* _urls is used as completion function of `curl'
 (http://curl.haxx.nu/)
* Use [[ ... ]] instead of [ ... ].
* Use (#b) in an argument of compset -P to extract info.
* Eliminate unused variable.

Index: Completion/User/_urls
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_urls,v
retrieving revision 1.1.1.9
diff -u -F^( -r1.1.1.9 _urls
--- Completion/User/_urls	1999/10/15 13:09:11	1.1.1.9
+++ Completion/User/_urls	1999/10/15 14:28:55
@@ -1,4 +1,4 @@
-#autoload
+#compdef curl
 
 # Usage: _urls [-f]
 # Options:
@@ -37,7 +37,9 @@
 #    name used by a user placing web pages within their home area.
 #    e.g. compconf urls_localhttp=www:/usr/local/apache/htdocs:public_html
 
-local ipre scheme host user dirs files ret=1 expl
+setopt localoptions extendedglob
+
+local ipre scheme host user hosts ret=1 expl
 local urls_path="${compconfig[urls_path]:-${ZDOTDIR:-$HOME}/.zsh/urls}"
 local localhttp_servername="${${(@s.:.)compconfig[urls_localhttp]}[1]}"
 local localhttp_documentroot="${${(@s.:.)compconfig[urls_localhttp]}[2]}"
@@ -50,16 +52,14 @@
 
 ipre="$IPREFIX"
 
-if ! [[ -prefix [-+.a-z0-9]#: ]]; then
+if ! compset -P '(#b)([-+.a-z0-9]#):'; then
   _description expl 'URL prefix'
   [[ -d $urls_path/bookmark ]] &&
     compadd "$@" "$expl[@]" -S '' bookmark: && ret=0
   compadd "$@" "$expl[@]" -S '' file: ftp:// gopher:// http:// && ret=0
   return $ret
 fi
-
-scheme="${PREFIX%%:*}"
-compset -P "[-+.a-z0-9]#:"
+scheme="$match[1]"
 
 case "$scheme" in
   http|ftp|gopher)
@@ -70,10 +70,10 @@
   ;;
   file)
     if ! compset -P //; then
-      if [ -prefix / ]; then
+      if [[ -prefix / ]]; then
 	_path_files "$@" -S '' -g '*(^/)' && ret=0
 	_path_files "$@" -S/ -r '/' -/ && ret=0
-      elif [ ! "$PREFIX" ]; then
+      elif [[ -z "$PREFIX" ]]; then
 	compadd -S '/' -r '/' - "${PWD%/}"
 	ret=0
       fi
@@ -94,34 +94,31 @@
 esac
 
 # Complete hosts
-if ! [[ -prefix */* ]]; then
-  dirs=($urls_path/$scheme/$PREFIX*$SUFFIX(/:t))
-  (( $#dirs )) || _hosts -S/ && ret=0
-  [ "$scheme" = "http" ] && dirs=($dirs $localhttp_servername)
-  compadd "$@" -QS/ - $dirs && ret=0
+if ! compset -P '(#b)([^/]#)/'; then
+  hosts=($urls_path/$scheme/$PREFIX*$SUFFIX(/:t))
+  (( $#hosts )) || _hosts -S/ && ret=0
+  [[ "$scheme" = http ]] && hosts=($hosts $localhttp_servername)
+  compadd "$@" -QS/ - $hosts && ret=0
   return $ret
 fi
+host="$match[1]"
 
 # Complete part after hostname
-host=${PREFIX%%/*}
-compset -P "$host/"
-if [[ "$localhttp_servername" = $host ]]; then
-  if [[ -prefix \~ ]]; then
-    compset -P \~
-    if [[ -prefix */* ]]; then
-      user=${PREFIX%%/*}
-      compset -P $user/
-      _path_files -W ~$user/$localhttp_userdir -g '*(^/)' && ret=0
-      _path_files -W ~$user/$localhttp_userdir -S/ -r '/' -/ && ret=0
-    else
-      _users -S/ && ret=0
+if [[ "$localhttp_servername" = "$host" ]]; then
+  if compset -P \~; then
+    if ! compset -P '(#b)([^/]#)/'; then
+      _users -S/
+      return
     fi
+    user="$match[1]"
+    _path_files -W ~$user/$localhttp_userdir -g '*(^/)' && ret=0
+    _path_files -W ~$user/$localhttp_userdir -S/ -r '/' -/ && ret=0
   else
     _path_files -W $localhttp_documentroot -g '*(^/)' && ret=0
     _path_files -W $localhttp_documentroot -S/ -r '/' -/ && ret=0
   fi
 else
-  _path_files -W $urls_path/$scheme/$host/ -g '*(^/)' && ret=0
-  _path_files -W $urls_path/$scheme/$host/ -S/ -r '/' -/ && ret=0
+  _path_files -W $urls_path/$scheme/$host -g '*(^/)' && ret=0
+  _path_files -W $urls_path/$scheme/$host -S/ -r '/' -/ && ret=0
 fi
 return $ret
-- 
Tanaka Akira


  reply	other threads:[~1999-10-15 14:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-14 17:09 setopt localoptions noautoremoveslash Tanaka Akira
1999-10-14 17:15 ` Zefram
1999-10-14 18:08   ` Tanaka Akira
1999-10-15 11:24     ` PATCH: _urls again (Re: setopt localoptions noautoremoveslash) Oliver Kiddle
1999-10-15 14:36       ` Tanaka Akira [this message]
1999-10-15  3:15   ` setopt localoptions noautoremoveslash Wayne Davison
1999-10-15 12:10 PATCH: _urls again (Re: setopt localoptions noautoremoveslash) Sven Wischnowsky
1999-10-15 15:30 ` Oliver Kiddle
     [not found]   ` <991015155008.ZM24081@candle.brasslantern.com>
1999-10-15 16:05     ` Oliver Kiddle
1999-10-15 16:40       ` Bart Schaefer
1999-10-16 13:56   ` Tanaka Akira
1999-10-18  9:41 Sven Wischnowsky

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=rsqr9iwr8rs.fsf@crane.jaist.ac.jp \
    --to=akr@jaist.ac.jp \
    --cc=zsh-workers@sunsite.auc.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).