2000-04-01 22:43:43 +02:00
|
|
|
#compdef curl
|
1999-09-02 20:26:12 +02:00
|
|
|
|
|
|
|
# Usage: _urls [-f]
|
|
|
|
# Options:
|
2000-04-01 22:43:43 +02:00
|
|
|
# -f : complete files first.
|
|
|
|
#
|
|
|
|
# Configuration styles used:
|
|
|
|
#
|
|
|
|
# path
|
|
|
|
# The path to a directory containing a URL database, such as:
|
|
|
|
#
|
|
|
|
# % cd ~/.zsh/urls
|
|
|
|
# % find . -ls
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 02:46 .
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 02:48 ./http
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 02:52 ./http/www.zsh.org
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 03:01 ./http/www.zsh.org/mla
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 03:01 ./http/www.zsh.org/mla/workers
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 03:01 ./http/www.zsh.org/mla/workers/1999
|
|
|
|
# ... -rw-r--r-- ... 0 Sep 3 03:01 ./http/www.zsh.org/mla/workers/1999/index.html
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 02:48 ./http/sunsite.auc.dk
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 02:48 ./http/sunsite.auc.dk/zsh
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 02:47 ./bookmark
|
|
|
|
# ... drwxr-xr-x ... 512 Sep 3 02:48 ./bookmark/zsh
|
|
|
|
# ... -rw-r--r-- ... 27 Sep 3 02:47 ./bookmark/zsh/home
|
|
|
|
# ... -rw-r--r-- ... 20 Sep 3 02:48 ./bookmark/zsh/meta
|
|
|
|
# % cat bookmark/zsh/home
|
|
|
|
# http://sunsite.auc.dk/zsh/
|
|
|
|
# % cat bookmark/zsh/meta
|
|
|
|
# http://www.zsh.org/
|
1999-09-02 20:26:12 +02:00
|
|
|
#
|
2000-04-01 22:43:43 +02:00
|
|
|
# local
|
|
|
|
# Specify a local web server as an array with three elements:
|
|
|
|
# <hostname> <doc root> <user area>
|
|
|
|
# where hostname is the name of the web server, doc root is the path to
|
|
|
|
# the default web pages for the server and user area is the directory
|
|
|
|
# name used by a user placing web pages within their home area.
|
|
|
|
# E.g.:
|
|
|
|
# zstyle ':completion:*:urls' local www /usr/local/apache/htdocs public_html
|
1999-09-02 20:26:12 +02:00
|
|
|
|
2000-06-06 01:20:48 +02:00
|
|
|
local ipre scheme host user uhosts ret=1 expl match glob
|
2000-04-01 22:43:43 +02:00
|
|
|
local urls_path localhttp
|
|
|
|
zstyle -s ":completion:${curcontext}:urls" path urls_path ||
|
|
|
|
urls_path="${ZDOTDIR:-$HOME}/.zsh/urls"
|
|
|
|
zstyle -a ":completion:${curcontext}:urls" local localhttp
|
|
|
|
local localhttp_servername="$localhttp[1]"
|
|
|
|
local localhttp_documentroot="$localhttp[2]"
|
|
|
|
local localhttp_userdir="$localhttp[3]"
|
1999-09-02 20:26:12 +02:00
|
|
|
|
|
|
|
if [[ "$1" = -f ]]; then
|
|
|
|
shift
|
2000-04-27 11:24:37 +02:00
|
|
|
_wanted -C -f files expl file _files "$@" && return 0
|
1999-09-02 20:26:12 +02:00
|
|
|
fi
|
|
|
|
|
2000-06-06 21:43:29 +02:00
|
|
|
zparseopts -D -E g:=glob
|
|
|
|
: ${(A)=glob:=-g '*(^/)'}
|
2000-06-06 01:20:48 +02:00
|
|
|
|
1999-09-02 20:26:12 +02:00
|
|
|
ipre="$IPREFIX"
|
|
|
|
|
2000-04-11 09:57:56 +02:00
|
|
|
if ! compset -P '(#b)([-+.a-z0-9]#):'; then
|
|
|
|
_tags -C argument prefixes
|
|
|
|
while _tags; do
|
2000-05-23 18:11:57 +02:00
|
|
|
while _next_label prefixes expl 'URL prefix' -S '' "$@"; do
|
|
|
|
compset -S '[^:/]*' && compstate[to_end]=''
|
2000-04-11 09:57:56 +02:00
|
|
|
[[ -d $urls_path/bookmark ]] &&
|
2000-05-23 18:11:57 +02:00
|
|
|
compadd "$expl[@]" bookmark: && ret=0
|
|
|
|
compadd "$expl[@]" file: ftp:// gopher:// http:// && ret=0
|
2000-04-11 09:57:56 +02:00
|
|
|
done
|
|
|
|
(( ret )) || return 0
|
2000-04-01 22:43:43 +02:00
|
|
|
done
|
2000-04-11 09:57:56 +02:00
|
|
|
return 1
|
1999-09-02 20:26:12 +02:00
|
|
|
fi
|
2000-04-01 22:43:43 +02:00
|
|
|
scheme="$match[1]"
|
1999-09-02 20:26:12 +02:00
|
|
|
|
|
|
|
case "$scheme" in
|
2000-04-01 22:43:43 +02:00
|
|
|
http|ftp|gopher)
|
|
|
|
if ! compset -P //; then
|
2000-05-23 18:11:57 +02:00
|
|
|
_wanted -C "$scheme" prefixes expl 'end of prefix' compadd -S '' "$@" //
|
2000-04-01 22:43:43 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
file)
|
|
|
|
if ! compset -P //; then
|
2000-04-11 09:57:56 +02:00
|
|
|
_tags -C file files
|
|
|
|
while _tags; do
|
2000-05-19 20:44:21 +02:00
|
|
|
while _next_label files expl 'local file'; do
|
2000-04-11 09:57:56 +02:00
|
|
|
if [[ -prefix / ]]; then
|
2000-06-06 01:20:48 +02:00
|
|
|
_path_files "$expl[@]" -S '' "${glob[@]}" && ret=0
|
2000-04-11 09:57:56 +02:00
|
|
|
_path_files "$expl[@]" -S/ -r '/' -/ && ret=0
|
|
|
|
elif [[ -z "$PREFIX" ]]; then
|
2000-05-23 18:11:57 +02:00
|
|
|
compadd -S '/' -r '/' "$expl[@]" "$@" - "${PWD%/}" && ret=0
|
2000-04-11 09:57:56 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
(( ret )) || return 0
|
2000-04-01 22:43:43 +02:00
|
|
|
done
|
2000-04-11 09:57:56 +02:00
|
|
|
return 1
|
2000-04-01 22:43:43 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
bookmark)
|
|
|
|
if [[ -f "$urls_path/$scheme/${(Q)PREFIX}${(Q)SUFFIX}" &&
|
|
|
|
-s "$urls_path/$scheme/${(Q)PREFIX}${(Q)SUFFIX}" ]]; then
|
|
|
|
_wanted -C bookmark bookmarks expl bookmarks \
|
|
|
|
compadd "$@" -U - \
|
|
|
|
"$ipre$(<"$urls_path/$scheme/${(Q)PREFIX}${(Q)SUFFIX}")" && ret=0
|
|
|
|
else
|
2000-04-11 09:57:56 +02:00
|
|
|
_tags -C bookmark files
|
|
|
|
while _tags; do
|
2000-04-01 22:43:43 +02:00
|
|
|
while _next_label files expl 'bookmark'; do
|
2000-06-06 01:20:48 +02:00
|
|
|
_path_files -W "$urls_path/$scheme" "$expl[@]" -S '' "${glob[@]}" &&
|
2000-04-01 22:43:43 +02:00
|
|
|
ret=0
|
2000-05-23 18:11:57 +02:00
|
|
|
_path_files -W "$urls_path/$scheme" -S/ -r '/' "$expl[@]" -/ && ret=0
|
2000-04-01 22:43:43 +02:00
|
|
|
done
|
2000-04-11 09:57:56 +02:00
|
|
|
(( ret )) || return 0
|
|
|
|
done
|
2000-04-01 22:43:43 +02:00
|
|
|
fi
|
|
|
|
return ret
|
|
|
|
;;
|
1999-09-02 20:26:12 +02:00
|
|
|
esac
|
|
|
|
|
2000-04-01 22:43:43 +02:00
|
|
|
# Complete hosts
|
2000-04-11 09:57:56 +02:00
|
|
|
if ! compset -P '(#b)([^/]#)/'; then
|
2000-04-01 22:43:43 +02:00
|
|
|
uhosts=($urls_path/$scheme/$PREFIX*$SUFFIX(/:t))
|
|
|
|
|
2000-04-11 09:57:56 +02:00
|
|
|
_tags hosts
|
|
|
|
while _tags; do
|
2000-05-23 18:11:57 +02:00
|
|
|
while _next_label hosts expl host "$@"; do
|
|
|
|
compset -S '/*' || suf="/"
|
|
|
|
(( $#uhosts )) || _hosts -S "$suf" "$expl[@]" && ret=0
|
2000-04-11 09:57:56 +02:00
|
|
|
[[ "$scheme" = http ]] && uhosts=($uhosts $localhttp_servername)
|
2000-05-31 11:38:25 +02:00
|
|
|
compadd -S "$suf" "$expl[@]" -a uhosts && ret=0
|
2000-04-11 09:57:56 +02:00
|
|
|
done
|
|
|
|
(( ret )) || return 0
|
2000-04-01 22:43:43 +02:00
|
|
|
done
|
2000-04-11 09:57:56 +02:00
|
|
|
return 1
|
2000-04-01 22:43:43 +02:00
|
|
|
fi
|
|
|
|
host="$match[1]"
|
|
|
|
|
|
|
|
# Complete part after hostname
|
|
|
|
|
2000-04-11 09:57:56 +02:00
|
|
|
_tags -C local files || return 1
|
2000-04-01 22:43:43 +02:00
|
|
|
|
|
|
|
if [[ "$localhttp_servername" = "$host" ]]; then
|
|
|
|
if compset -P \~; then
|
|
|
|
if ! compset -P '(#b)([^/]#)/'; then
|
2000-05-23 18:11:57 +02:00
|
|
|
_users -S/ "$@"
|
2000-04-01 22:43:43 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
user="$match[1]"
|
2000-04-11 09:57:56 +02:00
|
|
|
while _tags; do
|
|
|
|
while _next_label files expl 'local file'; do
|
2000-06-06 01:20:48 +02:00
|
|
|
_path_files "$expl[@]" "$@" -W ~$user/$localhttp_userdir "${glob[@]}" && ret=0
|
2000-05-23 18:11:57 +02:00
|
|
|
_path_files -S/ -r '/' "$expl[@]" -W ~$user/$localhttp_userdir-/ && ret=0
|
2000-04-11 09:57:56 +02:00
|
|
|
done
|
|
|
|
(( ret )) || return 0
|
2000-04-01 22:43:43 +02:00
|
|
|
done
|
1999-09-02 20:26:12 +02:00
|
|
|
else
|
2000-04-11 09:57:56 +02:00
|
|
|
while _tags; do
|
|
|
|
while _next_label files expl 'local file'; do
|
2000-06-06 01:20:48 +02:00
|
|
|
_path_files "$expl[@]" "$@" -W $localhttp_documentroot "${glob[@]}" && ret=0
|
2000-05-23 18:11:57 +02:00
|
|
|
_path_files -S/ -r '/' "$expl[@]" -W $localhttp_documentroot -/ && ret=0
|
2000-04-11 09:57:56 +02:00
|
|
|
done
|
|
|
|
(( ret )) || return 0
|
2000-04-01 22:43:43 +02:00
|
|
|
done
|
1999-09-02 20:26:12 +02:00
|
|
|
fi
|
2000-04-01 22:43:43 +02:00
|
|
|
else
|
2000-04-11 09:57:56 +02:00
|
|
|
while _tags; do
|
|
|
|
while _next_label files expl 'local file'; do
|
2000-06-06 01:20:48 +02:00
|
|
|
_path_files "$expl[@]" "$@" -W $urls_path/$scheme/$host "${glob[@]}" && ret=0
|
2000-05-23 18:11:57 +02:00
|
|
|
_path_files -S/ -r '/' "$expl[@]" -W $urls_path/$scheme/$host -/ && ret=0
|
2000-04-11 09:57:56 +02:00
|
|
|
done
|
|
|
|
(( ret )) || return 0
|
2000-04-01 22:43:43 +02:00
|
|
|
done
|
1999-09-02 20:26:12 +02:00
|
|
|
fi
|
2000-04-01 22:43:43 +02:00
|
|
|
return $ret
|