1#compdef mozilla mozilla-firefox mozilla-xremote-client firefox iceweasel=firefox
2
3local curcontext="$curcontext" state line expl ret=1 suf
4typeset -A opt_args
5
6local popts="-installer -CreateProfile -P -ProfileWizard -ProfileManager -SelectProfile"
7local -a mozopts
8
9if [[ $service = *remote* ]]; then
10  state=remote
11else
12  if [[ $service = *firefox* ]]; then
13    mozopts=(
14    '-browser[open browser window]' \
15    '-console[start with debugging console]' \
16    '-h[output help message]' \
17    '-help[output help message]' \
18    '-inspector[start with DOM Inspector]:URL to inspect:->location' \
19    '-install-global-extension[install an extension]:extension to install:_files' \
20    '-new-window[load URL in new window]:URL to load:->location' \
21    '-new-tab[load URL in new tab]:URL to load:->location' \
22    '-no-remote[run with multiple profiles]' \
23    '-profile[specify profile file]:profile file:_files' \
24    '-v[show version]' \
25    '-version[show version]' \
26    '-safe-mode[disable extensions and themes for this session]'
27    )
28  else
29    mozopts=(
30      "($popts)-installer[start with 4.x migration window]"
31      "($popts)-ProfileWizard[start with profile wizard]"
32      "($popts)-SelectProfile[start with profile selection dialog]"
33      '-splash[enable splash screen]'
34      '-chat[start with IRC client]'
35      '-news[start with news]'
36      '-venkman[start with JavaScript debugger]'
37      '-terminal[start with command line terminal]'
38      '-mail[start with mail]'
39      '-compose[start with messenger compose]:URL:_urls'
40    )
41  fi
42  _x_arguments -C  $mozopts \
43    '-height[height of startup window]:height' \
44    '(-)'{-h,-help}'[show usage message]' \
45      "($popts)-CreateProfile:profile" \
46    '-width[width of startup window]:width' \
47    '(-)'{-v,-version}'[show the version number and build date]' \
48    "($popts)-P[start with profile]:profile:->profile" \
49    "($popts)-ProfileManager[start with profile manager]" \
50    '-UILocale:locale' \
51    '-contentLocale:locale' \
52    '-remote[execute a command in an existing Mozilla]:remote command:->remote' \
53    '-jsconsole[start with JavaScript Console]' \
54    '-edit[start with editor]:URL:_urls' \
55    '-chrome[load the specified chrome]:URL:_urls' \
56    '*:location:->urls' && ret=0
57fi
58
59[[ "$state" = "urls" ]] &&
60  _files "$@" && return 0
61
62# Handle mozilla remote commands
63if [[ "$state" = "remote" ]]; then
64  local -a remote_commands
65  remote_commands=(openURL openFile saveAs mailto addBookmark ping)
66
67  compset -P '*\('
68  if compset -S '(|\\)\)*'; then
69    set - -S "" "$@"
70  else
71    set - -S"${${QIPREFIX:+)}:-\)}$compstate[quote] " "$@"
72  fi
73  case $IPREFIX in
74    openURL*)
75      if compset -P "*,"; then
76        _wanted option expl 'option' compadd "$@" new-tab new-window && ret=0
77      else
78        compset -S ',*'
79        state=urls
80      fi
81    ;;
82    addBookmark*) state=urls;;
83    openFile*) _files "$@" -W ~;;
84    saveAs*)
85      if compset -P "*,"; then
86        _wanted types expl 'data type' \
87            compadd "$@" -M 'm:{a-zA-Z}={A-Za-z}' HTML Text PostScript && ret=0
88      else
89        compset -S ",*" || suf=","
90        _files -qS "$suf" -W ~ && ret=0
91      fi
92    ;;
93    mailto*)
94      _email_addresses -s, -c && ret=0
95    ;;
96    *)
97      compset -S '(|\\)\(*' || suf="${${QIPREFIX:+(}:-\(}"
98      _wanted commands expl 'remote commands' \
99          compadd -qS "$suf" -M 'm:{a-zA-Z}={A-Za-z}' -a \
100                  remote_commands && ret=0
101    ;;
102  esac
103fi
104
105if [[ "$state" = "urls" ]]; then
106  # Complete mozilla urls
107  if compset -P about: ; then
108    _wanted values expl 'about what' \
109        compadd "$@" authors blank cache document fonts global hype image-cache \
110            license logo memory-cache mozilla plugins && ret=0
111  elif compset -P news: ; then
112    _newsgroups "$@" && ret=0
113  elif compset -P mailto: ; then
114    _email_addresses -c && ret=0
115  else
116    _tags prefixes
117    while _tags; do
118      while _next_label prefixes expl 'URL prefix' "$@"; do
119        _urls "$expl[@]" && ret=0
120	compset -S '[^:]*'
121        compadd -S '' "$expl[@]" about: news: mailto: mocha: javascript: && ret=0
122      done
123      (( ret )) || return 0
124    done
125  fi
126fi
127
128if [[ $state == "profile" ]]; then
129  if [[ $service == *firefox* ]]; then
130    local -a profiles text profiledir
131    case "$OSTYPE" in
132    darwin*) profiledir=~/"Library/Application Support/Firefox" ;;
133    *)       profiledir=~/.mozilla/firefox/ ;;
134    esac
135    profiles=(${(f)"$(< ${profiledir}/profiles.ini)"})
136    profiles=(${(M)${profiles}:#(\[Profile|(Path|Name)=)*})
137    text=${(F)profiles}
138    profiles=(${(f)text//(#b)\[Profile([0-9]##)\]
139Name=([^
140]##|)
141Path=([^
142]##|)/$match[2]})
143    profiles=(${profiles%:})
144    compadd $profiles
145  else
146    compadd ~/.mozilla/*/*.slt(\:h\:t)
147  fi
148fi
149
150return ret
151