Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: _urls, _netscape, a seg fault and new completion thoughts



Attached is a completion for Netscape and a modified completion for
urls. The netscape completion handles the normal options, remote
commands and some Netscape specific urls. The main change to _urls is
support for a new configuration option which allows intelligent
completing for a local web server. I've also fixed the problem I
introduced with completing file urls from the root directory. A small
(untested with yodl) doc patch is also included.

I had a bit of difficulty in getting the remote command completion to
work properly with different types of quoting and there is probably
plenty of scope for that to be further improved. I'm not sure how many
of the problems with the quoting are my fault though: zsh will seg
fault if I do:
netscape -remote 'openURL(<tab>

Is there a good reason why I don't get a list of matches when
completing inside quotes? This is the general case not anything to do
with completing urls etc. e.g. cd 'm<tab> will complete to 'man/ but
if I added another directory beginning with m, nothing would happen - no
list.

While writing this completion, I came across a number of circumstances
where I wanted to pass certain compadd style options (e.g. -r, -s, -M)
to _urls or _files but couldn't because they were not handled in some
circumstances. As a way of making the new completions simpler, I think
we should try to make all the completion commands standardise much more
on their options so things such as -P -s -S -r can be used throughout
with a common meaning and can be safely passed from one completion
function to another.

I think it would make things easier if compgen in particular took more
of compadd's options. The problem is that most of the option letters
are already used because compgen takes all the standard compctl
options. Maybe we should strip compgen of many of the options
which nolonger are of much use because they are implemented by new
functions (e.g. -f -/ -g -u). I would even say we should consider
ditching compgen altogether: it would fit in much better with the rest
of the system where different functions complete different types of
things if for example jobs were completed with compjob instead of the
not very readable compgen -j, -z and -r. Alternatively, the option
letters could be freed by moving compgen syntax away from the compctl
style and use more full words to describe what it is completing -
compgen suspended-jobs would be much easier to read.

Oliver Kiddle


*** Completion/User/_urls.bak2	Fri Oct  8 10:40:46 1999
--- Completion/User/_urls	Wed Oct 13 12:31:56 1999
***************
*** 4,10 ****
  # Options:
  #  -f : complete files.
  #
! # Configuration key used:
  #
  #  urls_path
  #    The path to a directory containing a URL database, such as:
--- 4,10 ----
  # Options:
  #  -f : complete files.
  #
! # Configuration keys used:
  #
  #  urls_path
  #    The path to a directory containing a URL database, such as:
***************
*** 28,35 ****
  #      http://sunsite.auc.dk/zsh/
  #      % cat bookmark/zsh/meta
  #      http://www.zsh.org/
  
! local ipre scheme dirs files
  
  if [[ "$1" = -f ]]; then
    shift
--- 28,43 ----
  #      http://sunsite.auc.dk/zsh/
  #      % cat bookmark/zsh/meta
  #      http://www.zsh.org/
+ #
+ #  urls_localhttp
+ #    Specify a local web server in the form:
+ #      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. compconf urls_localhttp=www:/usr/local/apache/htdocs:public_html
  
! local ipre scheme host user dirs files ret=1
  
  if [[ "$1" = -f ]]; then
    shift
***************
*** 46,82 ****
    scheme="${PREFIX%%:*}"
    compset -P "[-+.a-z0-9]#:"
  else
!   compadd "$@" -S '' http:// ftp:// bookmark: file:
!   return
  fi
  
  case "$scheme" in
!   http|ftp) compset -P // || { compadd "$@" -S '' //; return };;
    file)
!     if [[ -prefix // ]]; then
!       compset -P //
!     elif [ -prefix / ]; then
!       _files "$@"
!       return
!     elif [ ! "$PREFIX" ]; then
!       compadd -S '/' ~+
!       return
      fi
    ;;
  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
--- 54,120 ----
    scheme="${PREFIX%%:*}"
    compset -P "[-+.a-z0-9]#:"
  else
!   [ -d $compconfig[urls_path]/bookmark ] &&
!       compadd "$@" -S '' bookmark: && ret=0
!   compadd "$@" -S '' file: ftp:// gopher:// http:// && ret=0
!   return $ret
  fi
  
  case "$scheme" in
!   http|ftp|gopher) compset -P // || { compadd "$@" -S '' //; return };;
    file)
!     if ! compset -P //; then
!       if [ -prefix / ]; then
! 	_files "$@"
! 	return
!       elif [ ! "$PREFIX" ]; then
! 	compadd -S '/' - "${PWD%/}"
! 	return
!       fi
      fi
    ;;
+   bookmark)
+     if [[ -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
+       compadd "$@" -Q -S '/' - \
+           $compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(/:t) && ret=0
+       compadd "$@" -QS '' - \
+           $compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(.:t) || return $ret
+     fi
+     return 
+   ;;
  esac
  
! if [[ -prefix */* ]]; then
! 
!   # Complete part after hostname
!   host=${PREFIX%%/*}
!   compset -P "$host/"
!   if [[ "$compconfig[urls_localhttp]" = ${host}:* ]]; then
!     if [[ -prefix \~ ]]; then
!       compset -P \~
!       if [[ -prefix */* ]]; then
!         user=${PREFIX%%/*}
! 	compset -P $user/
! 	_path_files -W ~$user/${${(s.:.)compconfig[urls_localhttp]}[3]}/
!       else
!         _users -S/
!       fi
!     else
!       _path_files -W ${${(s.:.)compconfig[urls_localhttp]}[2]}
!     fi
    else
!     _path_files -W $compconfig[urls_path]/$scheme/$host/
    fi
+ else
+ 
+   # Complete hosts
+   dirs=($compconfig[urls_path]/$scheme/$PREFIX*$SUFFIX(/:t))
+   (( $#dirs )) || _hosts -S/ && ret=0
+   [ "$scheme" = "http" ] && 
+       dirs=($dirs ${${(s.:.)compconfig[urls_localhttp]}[1]})
+   compadd "$@" -Q -S '/' - $dirs || return $ret
  fi
*** Completion/User/_webbrowser.bak	Fri Oct  8 14:58:01 1999
--- Completion/User/_webbrowser	Fri Oct  8 14:59:07 1999
***************
*** 1,3 ****
! #compdef amaya arena chimera express grail gzilla hotjava mmm mozilla netscape w3m www xmosaic Mosaic
  
  _urls -f
--- 1,3 ----
! #compdef amaya arena chimera express grail gzilla hotjava mmm mozilla w3m www xmosaic Mosaic
  
  _urls -f
*** /dev/null	Wed Oct 13 04:01:01 1999
--- Completion/User/_netscape	Wed Oct 13 12:28:49 1999
***************
*** 0 ****
--- 1,75 ----
+ #compdef netscape
+ 
+ local state
+ 
+ _x_arguments \
+   '-xrm:resource:_x_resource' \
+   '-help[show usage message]' \
+   '-version[show the version number and build date]' \
+   '-visual[use a specific server visual]:id-or-number:' \
+   '-install[install a private colormap]' \
+   '-no-install[use the default colormap]' \
+   '-ncols[max no. of colors to allocate for images]:n:' \
+   '-mono[force 1-bit-deep image display]' \
+   '-iconic[start up iconified]' \
+   '-remote[execute a command in an existing Netscape]:remote command:->remote' \
+   '-id[id of X window to send remote commands to]:window-id:' \
+   '-raise[raise window following remote command]' \
+   "-noraise[don't raise window following remote command]" \
+   '-nethelp[show nethelp]' \
+   -{dont-force-window-stacking,no-about-splash} \
+   -{,no-}{,irix-}session-management \
+   -{done-save,ignore}-geometry-prefs \
+   -{component-bar,composer,edit,messenger,mail,discussions,news} \
+   '*:location:->urls'
+ 
+ [ "$state" = "urls" ] && _files "$@" && return
+ 
+ # Handle netscape remote commands
+ if [ "$state" = "remote" ]; then  
+   local -a remote_commands
+   remote_commands=(openURL openFile saveAs mailto addBookmark)
+ 
+   [[ $compstate[quoting] = (double|single) ]] && compset -q
+   compset -P '*\('
+   case $IPREFIX in
+     openURL*|addBookmark* ) state=urls;;
+     openFile* ) _files -W ~;;
+     saveAs* ) 
+       if compset -P "*,"; then
+         compadd -s")" -M 'm:{a-zA-Z}={A-Za-z}' HTML Text PostScript
+       else
+         _path_files -W ~
+       fi
+     ;;
+     mailto* )
+       compset -P "*,"
+       if compset -P '*@'; then
+         _description expl 'remote host name'
+         _hosts "$expl[@]" -q -S,
+       else
+         _description expl 'login name'
+         _users "$expl[@]" -q -S@
+       fi
+     ;;
+     * )
+       if [ "$QIPREFIX" ]; then
+         compadd -q -S '(' -M 'm:{a-zA-Z}={A-Za-z}' $remote_commands
+       else
+ 	compadd -s'(' -S '' -M 'm:{a-zA-Z}={A-Za-z}' $remote_commands
+       fi
+     ;;
+   esac
+ fi
+ 
+ if [ "$state" = "urls" ]; then
+   # Complete netscape urls
+   if [[ -prefix about: ]]; then
+     compset -P about:
+     compadd authors blank cache document fonts global hype image-cache \
+         license logo memory-cache mozilla plugins
+   else
+     compadd -S '' about: mocha: javascript:
+     _urls "$@"
+   fi
+ fi
*** Doc/Zsh/compsys.yo.bak	Wed Oct 13 12:11:01 1999
--- Doc/Zsh/compsys.yo	Wed Oct 13 12:23:36 1999
***************
*** 1582,1587 ****
--- 1582,1596 ----
  output of tt(ps) called with the value of this key as its argument
  when showing completion lists.
  )
+ item(tt(urls_localhttp))(
+ This key is used by completion functions which generate URLs as
+ possible matches to add suitable matches when a URL points to a
+ local web server. Its value should be of the form
+ `tt(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
+ )
  item(tt(urls_path))(
  This key is used by completion functions that generate URLs as
  possible matches. It should be set to the path of a directory



Messages sorted by: Reverse Date, Date, Thread, Author