about summary refs log tree commit diff
path: root/Completion/User/_urls
blob: 859402246b61a520e644f480d1bdf44c1ab4d922 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#autoload

# Usage: _urls [-f]
# Options:
#  -f : complete files.
#
# Configuration key used:
#
#  urls_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/

local ipre scheme dirs files

if [[ "$1" = -f ]]; then
  shift
  _files "$@" && return
fi

if [[ -z "$compconfig[urls_path]" ]]; then
  compconfig[urls_path]=${ZDOTDIR:-$HOME}/.zsh/urls
fi

ipre="$IPREFIX"

if [[ -prefix [-+.a-z0-9]#: ]]; then
  scheme="${PREFIX%%:*}"
  compset -P "[-+.a-z0-9]#:"
else
  compadd "$@" -S '' http:// ftp:// bookmark:
  return
fi

case "$scheme" in
  http) compset -P // || { compadd "$@" -S '' //; return };;
  ftp) compset -P // || { compadd "$@" -S '' //; return };;
esac

if [[ "$scheme" = bookmark &&
      -f "$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX" &&
      -s "$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX" ]]; then
  compadd "$@" -QU -- "$ipre$(<"$compconfig[urls_path]/$scheme/$PREFIX$SUFFIX")"
else
  dirs=($compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(/:t))
  files=($compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(.:t))
  compset -P '*/'
  compadd "$@" -Q -S '/' - $dirs
  if [[ "$scheme" = bookmark ]]; then
    compadd "$@" -QS '' - $files
  else
    compadd "$@" -Q - $files
  fi
fi