From b4a5b9db8b528f9c9b6a9cbb00db381c95659380 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 15 Apr 1999 18:16:27 +0000 Subject: zsh-3.1.5-pws-9 --- Config/version.mk | 4 +- Doc/Makefile.in | 4 +- Doc/Zsh/.distfiles | 8 +- Doc/Zsh/compctl.yo | 4 +- Doc/Zsh/compwid.yo | 428 ++++++++ Doc/Zsh/guide.yo | 8 + Doc/Zsh/intro.yo | 1 + Doc/Zsh/metafaq.yo | 2 +- Doc/Zsh/mod_compctl.yo | 9 +- Doc/Zsh/mod_zftp.yo | 4 + Doc/Zsh/mod_zle.yo | 27 +- Doc/Zsh/modules.yo | 5 +- Doc/Zsh/options.yo | 6 +- Doc/Zsh/seealso.yo | 1 + Doc/zsh.yo | 2 + Doc/zshcompwid.yo | 3 + Etc/MACHINES | 5 +- Functions/Completion/_aliases | 3 + Functions/Completion/_arrays | 3 + Functions/Completion/_autoload | 3 + Functions/Completion/_bg_jobs | 3 + Functions/Completion/_bindkey | 7 + Functions/Completion/_builtin | 7 + Functions/Completion/_cd | 3 + Functions/Completion/_command | 7 + Functions/Completion/_command_names | 3 + Functions/Completion/_compress | 3 + Functions/Completion/_condition | 10 + Functions/Completion/_configure | 12 + Functions/Completion/_dd | 13 + Functions/Completion/_default | 13 + Functions/Completion/_dirs | 3 + Functions/Completion/_disable | 6 + Functions/Completion/_dvi | 3 + Functions/Completion/_echotc | 3 + Functions/Completion/_enable | 6 + Functions/Completion/_fc | 7 + Functions/Completion/_files | 10 + Functions/Completion/_find | 21 + Functions/Completion/_functions | 3 + Functions/Completion/_gunzip | 3 + Functions/Completion/_gzip | 3 + Functions/Completion/_hash | 13 + Functions/Completion/_hosts | 3 + Functions/Completion/_jobs | 3 + Functions/Completion/_kill | 8 + Functions/Completion/_kill_helper | 3 + Functions/Completion/_limits | 3 + Functions/Completion/_main_complete | 48 + Functions/Completion/_make | 3 + Functions/Completion/_man | 11 + Functions/Completion/_mh | 70 ++ Functions/Completion/_most_recent_file | 3 + Functions/Completion/_normal | 56 + Functions/Completion/_path_files | 272 +++++ Functions/Completion/_pdf | 3 + Functions/Completion/_precommand | 5 + Functions/Completion/_ps | 3 + Functions/Completion/_rcs | 9 + Functions/Completion/_rlogin | 9 + Functions/Completion/_sched | 3 + Functions/Completion/_set | 7 + Functions/Completion/_setopt | 7 + Functions/Completion/_source | 7 + Functions/Completion/_strip | 2 + Functions/Completion/_stty | 16 + Functions/Completion/_subscript | 4 + Functions/Completion/_tar | 11 + Functions/Completion/_tex | 3 + Functions/Completion/_trap | 7 + Functions/Completion/_uncompress | 3 + Functions/Completion/_unhash | 6 + Functions/Completion/_unsetopt | 7 + Functions/Completion/_vars | 3 + Functions/Completion/_vars_eq | 3 + Functions/Completion/_wait | 4 + Functions/Completion/_which | 3 + Functions/Completion/_x_options | 5 + Functions/Completion/_xfig | 3 + Functions/Completion/_zftp | 50 + Functions/Completion/_zle | 7 + Functions/Completion/_zmodload | 9 + Functions/Completion/dump | 89 ++ Functions/Completion/init | 246 ++--- Misc/zftp-functions | 329 +++++- Src/Modules/zftp.c | 25 +- Src/Zle/comp.h | 16 +- Src/Zle/compctl.c | 8 +- Src/Zle/zle_tricky.c | 1847 ++++++++++++++++++++++++++++---- Src/cond.c | 60 +- Src/exec.c | 42 +- Src/glob.c | 2 +- Src/params.c | 10 +- Src/subst.c | 32 +- Src/utils.c | 2 +- Src/zsh.h | 5 + config.guess | 3 + configure.in | 2 +- patchlist.txt | 58 + 99 files changed, 3672 insertions(+), 478 deletions(-) create mode 100644 Doc/Zsh/compwid.yo create mode 100644 Doc/zshcompwid.yo create mode 100644 Functions/Completion/_aliases create mode 100644 Functions/Completion/_arrays create mode 100644 Functions/Completion/_autoload create mode 100644 Functions/Completion/_bg_jobs create mode 100644 Functions/Completion/_bindkey create mode 100644 Functions/Completion/_builtin create mode 100644 Functions/Completion/_cd create mode 100644 Functions/Completion/_command create mode 100644 Functions/Completion/_command_names create mode 100644 Functions/Completion/_compress create mode 100644 Functions/Completion/_condition create mode 100644 Functions/Completion/_configure create mode 100644 Functions/Completion/_dd create mode 100644 Functions/Completion/_default create mode 100644 Functions/Completion/_dirs create mode 100644 Functions/Completion/_disable create mode 100644 Functions/Completion/_dvi create mode 100644 Functions/Completion/_echotc create mode 100644 Functions/Completion/_enable create mode 100644 Functions/Completion/_fc create mode 100644 Functions/Completion/_files create mode 100644 Functions/Completion/_find create mode 100644 Functions/Completion/_functions create mode 100644 Functions/Completion/_gunzip create mode 100644 Functions/Completion/_gzip create mode 100644 Functions/Completion/_hash create mode 100644 Functions/Completion/_hosts create mode 100644 Functions/Completion/_jobs create mode 100644 Functions/Completion/_kill create mode 100644 Functions/Completion/_kill_helper create mode 100644 Functions/Completion/_limits create mode 100644 Functions/Completion/_main_complete create mode 100644 Functions/Completion/_make create mode 100644 Functions/Completion/_man create mode 100644 Functions/Completion/_mh create mode 100644 Functions/Completion/_most_recent_file create mode 100644 Functions/Completion/_normal create mode 100644 Functions/Completion/_path_files create mode 100644 Functions/Completion/_pdf create mode 100644 Functions/Completion/_precommand create mode 100644 Functions/Completion/_ps create mode 100644 Functions/Completion/_rcs create mode 100644 Functions/Completion/_rlogin create mode 100644 Functions/Completion/_sched create mode 100644 Functions/Completion/_set create mode 100644 Functions/Completion/_setopt create mode 100644 Functions/Completion/_source create mode 100644 Functions/Completion/_strip create mode 100644 Functions/Completion/_stty create mode 100644 Functions/Completion/_subscript create mode 100644 Functions/Completion/_tar create mode 100644 Functions/Completion/_tex create mode 100644 Functions/Completion/_trap create mode 100644 Functions/Completion/_uncompress create mode 100644 Functions/Completion/_unhash create mode 100644 Functions/Completion/_unsetopt create mode 100644 Functions/Completion/_vars create mode 100644 Functions/Completion/_vars_eq create mode 100644 Functions/Completion/_wait create mode 100644 Functions/Completion/_which create mode 100644 Functions/Completion/_x_options create mode 100644 Functions/Completion/_xfig create mode 100644 Functions/Completion/_zftp create mode 100644 Functions/Completion/_zle create mode 100644 Functions/Completion/_zmodload create mode 100644 Functions/Completion/dump diff --git a/Config/version.mk b/Config/version.mk index 675dede6e..3e36faf5c 100644 --- a/Config/version.mk +++ b/Config/version.mk @@ -27,5 +27,5 @@ # This must also serve as a shell script, so do not add spaces around the # `=' signs. -VERSION=3.1.5-pws-8 -VERSION_DATE='February 13, 1999' +VERSION=3.1.5-pws-9 +VERSION_DATE='February 18, 1999' diff --git a/Doc/Makefile.in b/Doc/Makefile.in index e22f3c71d..7bc5d7ada 100644 --- a/Doc/Makefile.in +++ b/Doc/Makefile.in @@ -38,7 +38,7 @@ TEXI2HTML = texi2html -expandinfo -split_chapter .SUFFIXES: .yo .1 # man pages to install -MAN = zsh.1 zshbuiltins.1 zshcompctl.1 \ +MAN = zsh.1 zshbuiltins.1 zshcompctl.1 zshcompwid.1 \ zshexpn.1 zshmisc.1 zshmodules.1 \ zshoptions.1 zshparam.1 zshzle.1 zshall.1 @@ -48,7 +48,7 @@ YODLSRC = zmacros.yo zman.yo ztexi.yo Zsh/arith.yo Zsh/builtins.yo \ Zsh/compat.yo Zsh/compctl.yo Zsh/cond.yo Zsh/exec.yo Zsh/expn.yo \ Zsh/filelist.yo Zsh/files.yo Zsh/func.yo Zsh/grammar.yo Zsh/guide.yo \ Zsh/index.yo Zsh/intro.yo Zsh/invoke.yo Zsh/jobs.yo Zsh/metafaq.yo \ -Zsh/modules.yo Zsh/mod_cap.yo \ +Zsh/modules.yo Zsh/mod_cap.yo Zsh/compwid.yo \ Zsh/mod_clone.yo Zsh/mod_comp1.yo Zsh/mod_compctl.yo Zsh/mod_deltochar.yo \ Zsh/mod_example.yo Zsh/mod_files.yo Zsh/mod_stat.yo \ Zsh/mod_zle.yo Zsh/options.yo \ diff --git a/Doc/Zsh/.distfiles b/Doc/Zsh/.distfiles index 42517f507..c4a6d8080 100644 --- a/Doc/Zsh/.distfiles +++ b/Doc/Zsh/.distfiles @@ -1,9 +1,9 @@ DISTFILES_SRC=' .distfiles - arith.yo builtins.yo compat.yo compctl.yo cond.yo exec.yo expn.yo - filelist.yo files.yo func.yo grammar.yo guide.yo index.yo intro.yo + arith.yo builtins.yo compat.yo compctl.yo compwid.yo cond.yo exec.yo + expn.yo filelist.yo files.yo func.yo grammar.yo guide.yo index.yo intro.yo invoke.yo jobs.yo metafaq.yo mod_cap.yo mod_clone.yo mod_comp1.yo mod_compctl.yo mod_deltochar.yo mod_example.yo mod_files.yo mod_sched.yo - mod_stat.yo mod_zle.yo modules.yo options.yo params.yo prompt.yo - redirect.yo restricted.yo seealso.yo zle.yo + mod_stat.yo mod_zftp.yo mod_zle.yo modules.yo options.yo params.yo + prompt.yo redirect.yo restricted.yo seealso.yo zle.yo ' diff --git a/Doc/Zsh/compctl.yo b/Doc/Zsh/compctl.yo index 6a7f19023..124f9e604 100644 --- a/Doc/Zsh/compctl.yo +++ b/Doc/Zsh/compctl.yo @@ -1,4 +1,4 @@ -texinode(Programmable Completion)(Zsh Modules)(Zsh Line Editor)(Top) +texinode(Programmable Completion)(Completion Widgets)(Zsh Line Editor)(Top) chapter(Programmable Completion) cindex(completion, programmable) cindex(completion, controlling) @@ -89,7 +89,7 @@ to the user database is too slow and/or it contains too many users (so that completion after `tt(~)' is too slow to be usable), you can use indent( -tt(compctl -T -x 'C[0,*/*]' -f - 's[~]' -k friends -S/ -tn) +tt(compctl -T -x 's[~] C[0,[^/]#]' -k friends -S/ -tn) ) to complete the strings in the array tt(friends) after a `tt(~)'. diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo new file mode 100644 index 000000000..2cb12e2c2 --- /dev/null +++ b/Doc/Zsh/compwid.yo @@ -0,0 +1,428 @@ +texinode(Completion Widgets)(Zsh Modules)(Programmable Completion)(Top) +chapter(Completion Widgets) +cindex(completion, widgets) +cindex(completion, programmable) +cindex(completion, controlling) +sect(Description) +Completion widgets are defined using the tt(-C) option to the tt(zle) +builtin command provided by the tt(zle) module (see +ifzman(zmanref(zshzle))\ +ifnzman(noderef(The zle Module))\ +). For example, the invocation: + +indent(nofill( +tt(zle -C complete expand-or-complete completer))) + +defines a widget named tt(complete). If this widget is bound to a key +using the tt(bindkey) builtin command defined in the tt(zle) module +(see +ifzman(zmanref(zshzle))\ +ifnzman(noderef(Zsh Line Editor))\ +) typing that key will make the completion code call the shell +function tt(completer). This function is responsible for generating +the possible matches using the builtins described below. Once the +function returns, the completion code takes over control again and +treats the matches the way the builtin widget tt(expand-or-complete) +would do it. For this second argument, the name of any of the builtin +widgets that handle completions can be given, i.e. it may be any of +tt(complete-word), tt(expand-or-complete), +tt(expand-or-complete-prefix), tt(menu-complete), +tt(menu-expand-or-complete), tt(reverse-menu-complete), +tt(list-choices), or tt(delete-char-or-list). + +startmenu() +menu(Special Parameters) +menu(Builtin Commands) +menu(Condition Codes) +menu(Examples) +endmenu() + +texinode(Special Parameters)(Builtin Commands)()(Completion Widgets) +sect(Special Parameters) + +Inside completion widgets some parameters have special meaning. They +will be used inside the widget function and other shell functions +called from it. Outside of these function they are not special to the +shell in any way. + +The parameters are used to give information about the internal state +from the completion code to the completion widget and can be set to +give information to the completion code from the completion +widget. Some of the builtin commands and the condition codes use or +change the current values of these parameters. While the completion +widget is active, these parameters are reseton each function exit to +the values they had when the function was entered. + +startitem() +item(tt(argv))( +The positional parameters are set to the arguments on the command line +when the widget function is invoked from the completion code. +) +item(tt(CURRENT))( +This is the number of the current word, i.e. the word the cursor is +currently on in the tt(argv) array. +) +item(tt(CONTEXT))( +This will be set by the completion code to the overall context +completion is attempted in. Possible values are: + +startitem() +item(tt(command))( +when completing in a command position, e.g. in the first word on the +command line +) +item(tt(argument))( +when completing an argument for a command +) +item(tt(redirect))( +when completing after a redirection operator; in this case the +positional parameters contain not only the arguments but also the +command name itself as the first element +) +item(tt(condition))( +when completing inside a `tt([[)...tt(]])' conditional expressing; in +this case the positional parameters are set to the words inside the +conditional expressions +) +item(tt(math))( +when completing in a mathematical environment such as a +`tt(LPAR()LPAR())...tt(RPAR()RPAR())' construct +) +item(tt(value))( +when completing the value of a parameter assignment; in case of an +array value the positional parameters are set to the words in +parentheses +) +item(tt(subscript))( +when completing inside a parameter expansion subscript +) +enditem() +) +item(tt(COMMAND))( +In most cases this is set to name of the command for which completion +is tried. When completing after a redirection operator it contains the +string forming that operator. Also, when completing in the value of a +parameter assignment or in a parameter subscript it is set to the name +of the parameter. +) +item(tt(PREFIX))( +This should be set to that part of the current word that should be +taken as the string every possible match has to begin with. Initially +this will be set to the part of the current word from the beginning of +the word up to the position of the cursor. When +) +item(tt(IPREFIX))( +When a part of the current word should not be considered part of the +matches, this part should be taken from the tt(PREFIX) parameter and +appended to this parameter. This will initially be set to the empty +string when called from the completion code. +) +item(tt(SUFFIX))( +This should be set to that part of the current word that should be +taken as the string every possible match has to end with. The +completion code sets this to the part of the current word from the +cursor position to the end. +) +item(tt(NMATCHES))( +This is always set to the number of matches generated and accepted by +the completion code so far. +) +item(tt(MATCHER))( +When completion is used with a global match specification (i.e. a +tt(compctl) with only a tt(-M) option), this parameter is set to the +number of the specification string which is currently used. +) +enditem() + +texinode(Builtin Commands)(Condition Codes)(Special Parameters)(Completion Widgets) +sect(Builtin Commands) +startitem() +findex(complist) +item(tt(complist) var(flags ...))( + +Generate matches according to the given var(flags) which can be any of +the option flags supported by the tt(compctl) builtin command (see +ifzman(zmanref(zshcompctl))\ +ifnzman(noderef(Programmable Completion))\ +) except for the tt(-t) and tt(-l) flags. Also, when using the tt(-K) +flag, the function given as argument to it can not access the command +line with the tt(read) builtin command. + +The matches will be generated in the same way as if the completion code +generated them directly from a tt(compctl)-definition with the same +flags. The completion code will consider only those matches as +possible completions that match the prefix and suffix from the special +parameters desribed above. These strings will be compared with the +generated matches using the normal matching rules and any matching +specifications given with the tt(-M) flag to tt(complist) and the +global matching specifications given to the tt(compctl) builtin +command. +) +xitem(tt(compadd) [ tt(-qQfnUam) ] [ tt(-F) var(array) ]) +xitem([ tt(-P) var(prefix) ] [ tt(-S) var(suffix) ]) +xitem([ tt(-p) var(hidden-prefix) ] [ tt(-s) var(hidden-suffix) ]) +xitem([ tt(-i) var(ignored-prefix) ] [ tt(-W) var(file-prefix) ]) +xitem([ tt(-J) var(name) ] [ tt(-V) var(name) ]) +xitem([ tt(-r) var(remove-chars) ] [ tt(-R) var(remove-func) ]) +item([ tt(-M) var(match-spec) ] [ tt(--) ] [ var(words) ... ])( + +This builtin command can be used to add matches and directly control +all the information the completion code stores with each possible +match. + +The supported flags are: + +startitem() +item(tt(-P) var(prefix))( +The same as for tt(compctl) and tt(complist), it gives a string that +should be inserted before the given words when they are completed. The +string given is not considered to be part of the match. +) +item(tt(-S) var(suffix))( +Like tt(-P) but gives a string that has to be inserted after the match. +) +item(tt(-p) var(hidden-prefix))( +This gives a string that should be +... +) +item(tt(-s) var(hidden-suffix))( +... +) +item(tt(-i) var(ignored-prefix))( +... +) +item(tt(-J) var(name))( +As for tt(compctl) and tt(complist) this gives the name of the group +of matches the words should be stored in. +) +item(tt(-V) var(name))( +Like tt(-J) but naming a unsorted group. +) +item(tt(-q))( +This flag has the same meaning as for tt(compctl) and tt(complist), +too. It makes the suffix given with tt(-S) be automatically removed if +the next character typed is a blank or does not insert anything or if +the suffix consists of only one character and the next character typed +is the same character. +) +item(tt(-r) var(remove-chars))( +This makes the suffix given with tt(-S) be automatically removed if +the next character typed inserts one of the characters given in the +var(remove-chars). This string is parsed as a characters class with +the usual backslash-sequences understood, e.g. using `tt(-r "a-z\t")' +removes the suffix if the next character typed inserts one of the +lower case letters or a TAB, and `tt(-r "^0-9")' removes the suffix if +the next character typed inserts anything but a digit. One extra +backslash sequence is understood in this string: `tt(\-)' stands for +all characters that insert nothing. Thus `tt(-S "=" -q)' is the same +as `tt(-S "=" -r "= \t\n\-")'. +) +item(tt(-R) var(remove-func))( +For the cases where one wants to remove suffix and the tt(-r) option +does not give enough control, this option can be used. It stores the +name of the shell function var(remove-func) in the matches. If one of +the matches is finally accepted and the tt(-S)-suffix inserted, this +function will be called after the next character typed. It gets the +length of the suffix as its argument and can use the special +parameters available in zle widgets (see +ifzman(zmanref(zshzle))\ +ifnzman(noderef(Zsh Line Editor))\ +) to analyse and modify the command line. +) +item(tt(-f))( +If this flag is given, the matches build are marked as being the names +of files. They need not be actual filenames, though. But if they are +and the option tt(LIST_TYPES) is set, the characters describing the +types of the files in the completion lists will be shown. This also +makes a slash automatically be added when the name of a directory is +completed. +) +item(tt(-W) var(file-prefix))( +This option has the same meaning as for the tt(compctl) and +tt(complist) builtin commands. Here, however, only one string may be +given, not an array. This string is used as a pathname that will be +prepended to the given words and the prefix given with the tt(-p) +option to perform the file-tests when showing completion +listings. Hence it is only useful if combined with the tt(-f) flag, +since the tests will only be performed if that flag is given. +) +item(tt(-a))( +When used by tt(compctl) or tt(complist) the completion code normally +builds two sets of matches: the normal one where words with one of the +suffixes in the array parameter tt(fignore) are not considered +possible matches, and the alternate set where the words excluded +from the first set are stored. Normally only the matches in the first +set are used. But if this set is empty, the words from the alternate +set are used. + +The tt(compadd) builtin does not use tt(fignore) parameter and +normally stores all words in the first set. With the tt(-a)-flag +given, however, they are all stored in the alternate set unless this +flag is overridden by the tt(-F) option. +) +item(tt(-F) var(array))( +This can be used to give an array containing suffixes like the +tt(fignore) parameter. Words with one of these suffixes are stored in +the alternate set of matches and words without one of these suffixes +are stored in the normal set. + +The var(array) may be the name of an array parameter or a list of +literal suffixes enclosed in parentheses as in `tt(-F "(.o .h)")'. If +the name of an array is given, the elements of the array are taken as +the suffixes. +) +item(tt(-Q))( +As for tt(compctl) and tt(complist) this flag instructs the completion +code not to quote any metacharacters in the words when inserting them +in the command line. +) +item(tt(-m))( +Normally the matches added by tt(compadd) will not be compared with +what is already on the line. If this flag is given, this comparison is +performed as usual and the match specifications given with the tt(-M) +option to tt(compadd) and the global match specifications defined with +tt(compctl) will be used. This means that probably not all the word +given will be stored as matches since some of them may not match the +string on the line. +) +item(tt(-M) var(match-spec))( +This option allows one to give local match specifications with the +same meaning and format as for the tt(compctl) and tt(complist) +builtin commands. Note that they will only be used if the tt(-m) is +given, too. +) +item(tt(-n))( +Words added with tt(compadd) with this flag will be used as possible +matches as usual but they not appear in the completion listing. +) +item(tt(-U))( +If this flag is given to one of the calls to tt(compadd) and the +option tt(AUTO_MENU) is set, the completion code will immediatly +switch to menucompletion. +) +item(tt(-), tt(--))( +This flag ends the list of flags and options. All arguments after it +will be taken as the words to use as matches even if they begin with +hyphens. +) +enditem() +) +item(tt(compcall) [ tt(-TD) ])( + +This allows one to use completion definitions given with the +tt(compctl) builtin from within completion widgets. It makes +completion code complete the current word according to the +tt(compctl)s defined. Normally only tt(compctl)s given for specific +commands are used. To make the code use the completion flags given to +the tt(-T) option of tt(compctl), one can give the tt(-T) flag to +tt(compctl). Likewise, the tt(-D) flag to tt(compcall) makes the +default completion flags given to tt(compctl) with the tt(-D) option +be used. +) +enditem() + +texinode(Condition Codes)(Examples)(Builtin Commands)(Completion Widgets) +sect(Condition Codes) + +Inside completion widgets not only the builtin commands described +above can be used, but also some additional condition codes. These +work on the special parameters and can be used to easily build +completion functions that generate different matches depending on the +strings on the line. + +The following condition codes are made available inside completion +widgets: + +startitem() +item(tt(-prefix) var(string))( +true if the content of tt(PREFIX) starts with var(string) +) +item(tt(-iprefix) var(string))( +like tt(-prefix), but the var(string) is removed from tt(PREFIX) and +added to tt(IPREFIX) +) +item(tt(-position) var(beg) [ var(end) ])( +true if tt(CURRENT) is equal to var(beg) or, if var(end) is given, +equal to or greater than var(beg) and equal to or less than var(end); +both of var(beg) and var(end) may be arithmetic expressions, if they +are less than zero the number of words in tt(argv) are added to them +before comparing them to tt(CURRENT); thus, tt(-1) is the last word, +tt(-2) is the word before that and so on +) +item(tt(-word) var(index) var(string))( +true if the word number var(index) in tt(argv) is equal to +var(string); again, var(index) may be negative, counting backwards +) +item(tt(-mword) var(index) var(pattern))( +like tt(-word) but using pattern matching +) +item(tt(-current) var(offset) var(string))( +like tt(-word) but var(offset) is relative to the value of +tt(CURRENT) +) +item(tt(-mcurrent) var(offset) var(pattern))( +like tt(-current) but using pattern matching +) +item(tt(-string) [ var(number) ] var(string))( +true if the current word contains var(string); anything up to the last +occurrence of this string will be ingnored by removing it from +tt(PREFIX) and adding it to tt(IPREFIX); if var(number) is given, +anything up to the var(number)'th occurrence of the var(string) will +be ignored; again, var(nmuber) may be any arithmetic expression and +negative values count backward +) +item(tt(-class) [ var(number) ] var(class))( +like tt(-string) but the var(class) is used as a character class so +that anything up to and including the last or the var(number)'th +occurrence of any character from the string var(class) is ignored +) +item(tt(-words) var(min) [ var(max) ])( +true if the number of words is equal to var(min); if var(max) is +given, it is true if the number of words is equal to or greater than +var(min) and equal to or less than var(max) +) +item(tt(-after) var(string))( +true if the cursor is after a word that is equal to var(string) +) +item(tt(-mafter) var(pattern))( +like tt(-after) but using pattern matching +) +item(tt(-between) var(string1) var(string2))( +true if the cursor is after a word that is equal to var(string1), if +there is also a word that is equal to va(string2), this is true only +if the cursor is before it +) +item(tt(-mbetween) var(pattern1) var(pattern2))( +like tt(-between) but using pattern matching +) +item(tt(-nmatches) var(number))( +true if the the value of tt(NMATCHES) is equal to var(number) +) +item(tt(-matcher) var(number))( +true if the value of tt(MATCHER) is equal to var(number) +) +enditem() + +texinode(Examples)()(Condition Codes)(Completion Widgets) +sect(Examples) + +The first step is to define the widget: + +indent(nofill( +tt(zle -C complete complete-word complete-history))) + +Then the widget can be bound to a key using the tt(bindkey) builtin +command: + +indent(nofill( +tt(bindkey '^X\t' complete))) + +After that the shell function tt(complete-history) will be invoked +after typing control-X and TAB. The function should then generte the +matches, e.g.: + +indent(nofill( +tt(complete-history LPAR()RPAR() { complist -H 0 '' }))) + +In this the function will complete words from the history matching the +current word. diff --git a/Doc/Zsh/guide.yo b/Doc/Zsh/guide.yo index 0fb954e26..e0005e339 100644 --- a/Doc/Zsh/guide.yo +++ b/Doc/Zsh/guide.yo @@ -29,6 +29,7 @@ menu(Options) menu(Shell Builtin Commands) menu(Zsh Line Editor) menu(Programmable Completion) +menu(Completion Widgets) menu(Zsh Modules) --- Indices --- @@ -103,6 +104,13 @@ menu(Alternative Completion) menu(Extended Completion) menu(Example) +Completion Widgets + +menu(Special Parameters) +menu(Builtin Commands) +menu(Condition Codes) +menu(Examples) + Zsh Modules menu(The cap Module) diff --git a/Doc/Zsh/intro.yo b/Doc/Zsh/intro.yo index ebb678f70..f619f82fe 100644 --- a/Doc/Zsh/intro.yo +++ b/Doc/Zsh/intro.yo @@ -21,6 +21,7 @@ list(em(zshoptions) Zsh options) list(em(zshbuiltins) Zsh built-in functions) list(em(zshzle) Zsh command line editing) list(em(zshcompctl) Zsh completion control) +list(em(zshcompwid) Zsh completion widgets) list(em(zshmodules) Zsh loadable modules) ifzshone(\ list(em(zshall) Meta-man page containing all of the above) diff --git a/Doc/Zsh/metafaq.yo b/Doc/Zsh/metafaq.yo index cad82ee65..1d1636942 100644 --- a/Doc/Zsh/metafaq.yo +++ b/Doc/Zsh/metafaq.yo @@ -11,7 +11,7 @@ sect(Author) cindex(author) Zsh was originally written by Paul Falstad tt(). Zsh is now maintained by the members of the zsh-workers mailing -list tt(). The development is currently +list tt(). The development is currently coordinated by Andrew Main (Zefram) tt(). The coordinator can be contacted at tt(), but matters relating to the code should generally go to the mailing list. diff --git a/Doc/Zsh/mod_compctl.yo b/Doc/Zsh/mod_compctl.yo index b7adf8fa6..cfd615b2d 100644 --- a/Doc/Zsh/mod_compctl.yo +++ b/Doc/Zsh/mod_compctl.yo @@ -1,7 +1,12 @@ texinode(The compctl Module)(The deltochar Module)(The comp1 Module)(Zsh Modules) sect(The compctl Module) -The tt(compctl) module makes available one builtin command, tt(compctl), -which is the standard way to control completions for ZLE. See +The tt(compctl) module makes available several builtin commands. tt(compctl), +is the standard way to control completions for ZLE. See ifzman(zmanref(zshcompctl))\ ifnzman(noderef(Programmable Completion))\ . +The other builtin commands can be used in user-defined completion widgets, +see +ifzman(zmanref(zshcompwid))\ +ifnzman(noderef(Completion Widgets))\ +. diff --git a/Doc/Zsh/mod_zftp.yo b/Doc/Zsh/mod_zftp.yo index c08130bf5..395bf26de 100644 --- a/Doc/Zsh/mod_zftp.yo +++ b/Doc/Zsh/mod_zftp.yo @@ -439,4 +439,8 @@ until the next call to tt(zftp). Other status changes in subshells will not be reflected by changes to the variables (but should be otherwise harmless). +On some operatings systems, the control connection is not valid after a +fork(), so that operations in subshells or on the left hand side of a +pipeline are not possible. + enditem() diff --git a/Doc/Zsh/mod_zle.yo b/Doc/Zsh/mod_zle.yo index 86d145636..ad88c94c7 100644 --- a/Doc/Zsh/mod_zle.yo +++ b/Doc/Zsh/mod_zle.yo @@ -165,7 +165,7 @@ xitem(tt(zle) tt(-l) [ tt(-L) ]) xitem(tt(zle) tt(-D) var(widget) ...) xitem(tt(zle) tt(-A) var(old-widget) var(new-widget)) xitem(tt(zle) tt(-N) var(widget) [ var(function) ]) -xitem(tt(zle) tt(-C) [ tt(-mMgG) ] var(widget) [ var(compctl-options) ]) +xitem(tt(zle) tt(-C) var(widget) var(completion-widget) var(function)) item(tt(zle) var(widget))( The tt(zle) builtin performs a number of different actions concerning ZLE. Which operation it performs depends on its options: @@ -193,22 +193,15 @@ widget is invoked from within the editor, the specified shell var(function) is called. If no function name is specified, it defaults to the same name as the widget. ) -item(tt(-C) [ tt(-mMgG) ] var(widget) [ var(compctl-options) ])( -Create a user-defined widget which will perform completion according -to var(compctl-options). These are passed directly to the -tt(compctl) command, see -ifzman(zmanref(zshcompctl))\ -ifnzman(noderef(Programmable Completion))\ -; no command names or special options (tt(-LDCT)) may be used. If the -var(compctl-options) are missing the widget will have normal -completion behaviour as modified by the tt(zle) options. - -There are four additional tt(zle) options, which must precede the -widget name: tt(-m) and tt(-M) force the widget to use or not to use -menu completion, respectively, while tt(-g) and tt(-G) likewise force -the widget to use or not to use glob completion. The defaults are to -use the current settings of tt(MENU_COMPLETE) and tt(GLOB_COMPLETE) -as with normal completion. +item(tt(-C) var(widget) var(completion-widget) var(function))( +Create a user-defined completion widget names var(widget). The +completion widget will behave like the built-in completion-widget +whose name is given as var(completion-widget). To generate the +completions, the shell function var(function) will be called. +For further information, see +ifzman(zmanref(zshcompwid))\ +ifnzman(noderef(Completion Widgets))\ +. ) item(var(widget))( Invoke the specified widget. This can only be done when ZLE is diff --git a/Doc/Zsh/modules.yo b/Doc/Zsh/modules.yo index 300553845..97c420eed 100644 --- a/Doc/Zsh/modules.yo +++ b/Doc/Zsh/modules.yo @@ -1,4 +1,4 @@ -texinode(Zsh Modules)()(Programmable Completion)(Top) +texinode(Zsh Modules)()(Completion Widgets)(Top) chapter(Zsh Modules) cindex(modules) sect(Description) @@ -19,7 +19,8 @@ item(tt(comp1))( Base of the completion system. Used by the tt(compctl) and tt(zle) modules. ) item(tt(compctl))( -The tt(compctl) builtin for controlling completion. +The tt(compctl) builtin for controlling completion and the builtins for +completion widgets. ) item(tt(deltochar))( A ZLE function duplicating EMACS' tt(zap-to-char). diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index b9455f578..b59fa624a 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -544,12 +544,14 @@ List jobs in the long format by default. ) pindex(MAGIC_EQUAL_SUBST) item(tt(MAGIC_EQUAL_SUBST))( -All unquoted arguments of the form `var(identifier)tt(=)var(expression)' +All unquoted arguments of the form `var(anything)tt(=)var(expression)' appearing after the command name have filename expansion (that is, where var(expression) has a leading `tt(~)' or `tt(=)') performed on var(expression) as if it were a parameter assignment. The argument is not otherwise treated specially; it is passed to the command as a single -argument, and not used as an actual parameter assignment. +argument, and not used as an actual parameter assignment. For example, in +tt(echo foo=~/bar:~/rod), both occurrences of tt(~) would be replaced. +Note that this happens anyway with tt(typeset) and similar statements. ) pindex(MAIL_WARNING) cindex(mail, warning of reading) diff --git a/Doc/Zsh/seealso.yo b/Doc/Zsh/seealso.yo index 8289e6628..5231e8828 100644 --- a/Doc/Zsh/seealso.yo +++ b/Doc/Zsh/seealso.yo @@ -10,6 +10,7 @@ ifzshone(\ , zmanref(zshbuiltins), zmanref(zshcompctl), +zmanref(zshcompwid), zmanref(zshexpn), zmanref(zshmisc), zmanref(zshmodules), diff --git a/Doc/zsh.yo b/Doc/zsh.yo index a97f023e7..e6cef6a32 100644 --- a/Doc/zsh.yo +++ b/Doc/zsh.yo @@ -64,6 +64,7 @@ ifnzman(includefile(Zsh/options.yo)) ifnzman(includefile(Zsh/builtins.yo)) ifnzman(includefile(Zsh/zle.yo)) ifnzman(includefile(Zsh/compctl.yo)) +ifnzman(includefile(Zsh/compwid.yo)) ifnzman(includefile(Zsh/modules.yo)) ifzshall(\ def(source)(1)(NOTRANS(.so )man1/ARG1NOTRANS(.)1)\ @@ -75,6 +76,7 @@ source(zshoptions) source(zshbuiltins) source(zshzle) source(zshcompctl) +source(zshcompwid) source(zshmodules) manpage(ZSHALL)(1)(date())(zsh version()) )\ diff --git a/Doc/zshcompwid.yo b/Doc/zshcompwid.yo new file mode 100644 index 000000000..d876e422d --- /dev/null +++ b/Doc/zshcompwid.yo @@ -0,0 +1,3 @@ +manpage(ZSHCOMPWID)(1)(date())(zsh version()) +manpagename(zshcompwid)(zsh completion widgets) +includefile(Zsh/compwid.yo) diff --git a/Etc/MACHINES b/Etc/MACHINES index b9d3290c0..27e21f330 100644 --- a/Etc/MACHINES +++ b/Etc/MACHINES @@ -76,9 +76,12 @@ Reliant: SINIX linking; configure now detects this and will disable dynamic linking even if you requested it. -SGI: IRIX 5.1.1.1, 5.2, 5.3, 6.2, 6.3 +SGI: IRIX 5.1.1.1, 5.2, 5.3, 6.2, 6.3, 6.5 Should build `out-of-the-box'. + On 6.5.2, zsh malloc routines are reported not to work; also + full optimization (cc -O3 -OPT:Olimit=0) causes problems. + Sun: SunOS 4.1.* Under 4.1.3 if yellow pages is used, username completion may cause segmentation violation. This is a bug in the shared library not diff --git a/Functions/Completion/_aliases b/Functions/Completion/_aliases new file mode 100644 index 000000000..1038a726e --- /dev/null +++ b/Functions/Completion/_aliases @@ -0,0 +1,3 @@ +#defcomp unalias + +complist -a diff --git a/Functions/Completion/_arrays b/Functions/Completion/_arrays new file mode 100644 index 000000000..cbeac7118 --- /dev/null +++ b/Functions/Completion/_arrays @@ -0,0 +1,3 @@ +#defcomp shift + +complist -A diff --git a/Functions/Completion/_autoload b/Functions/Completion/_autoload new file mode 100644 index 000000000..4f506baeb --- /dev/null +++ b/Functions/Completion/_autoload @@ -0,0 +1,3 @@ +#defcomp autoload + +complist -s '${^fpath}/*(N:t)' diff --git a/Functions/Completion/_bg_jobs b/Functions/Completion/_bg_jobs new file mode 100644 index 000000000..511bb8308 --- /dev/null +++ b/Functions/Completion/_bg_jobs @@ -0,0 +1,3 @@ +#defcomp bg + +complist -z -P '%' diff --git a/Functions/Completion/_bindkey b/Functions/Completion/_bindkey new file mode 100644 index 000000000..8eddeb2a8 --- /dev/null +++ b/Functions/Completion/_bindkey @@ -0,0 +1,7 @@ +#defcomp bindkey + +if [[ -mword 1 -*[DAN]* || -mcurrent -1 -*M ]]; then + complist -s '$(bindkey -l)' +else + complist -b +fi diff --git a/Functions/Completion/_builtin b/Functions/Completion/_builtin new file mode 100644 index 000000000..d2b11226b --- /dev/null +++ b/Functions/Completion/_builtin @@ -0,0 +1,7 @@ +#defcomp builtin + +if [[ -position 2 -1 ]]; then + compsub +else + complist -eB +fi diff --git a/Functions/Completion/_cd b/Functions/Completion/_cd new file mode 100644 index 000000000..f3ce67ec7 --- /dev/null +++ b/Functions/Completion/_cd @@ -0,0 +1,3 @@ +#defcomp cd + +_files -W cdpath -g '*(-/)' diff --git a/Functions/Completion/_command b/Functions/Completion/_command new file mode 100644 index 000000000..b2812de25 --- /dev/null +++ b/Functions/Completion/_command @@ -0,0 +1,7 @@ +#defcomp command + +if [[ -position 2 -1 ]]; then + _normal "$@" +else + complist -em +fi diff --git a/Functions/Completion/_command_names b/Functions/Completion/_command_names new file mode 100644 index 000000000..d3b8a109a --- /dev/null +++ b/Functions/Completion/_command_names @@ -0,0 +1,3 @@ +#defcomp -command- + +complist -c diff --git a/Functions/Completion/_compress b/Functions/Completion/_compress new file mode 100644 index 000000000..860aeb5b0 --- /dev/null +++ b/Functions/Completion/_compress @@ -0,0 +1,3 @@ +#defcomp compress + +_files -g '*~*.Z' diff --git a/Functions/Completion/_condition b/Functions/Completion/_condition new file mode 100644 index 000000000..3e45e1b8f --- /dev/null +++ b/Functions/Completion/_condition @@ -0,0 +1,10 @@ +#defcomp -condition- + +if [[ -current -1 -o ]]; then + complist -o -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' +elif [[ -current -1 -nt || -current -1 -ot || -current -1 -ef ]]; then + _files +else + _files + complist -v +fi diff --git a/Functions/Completion/_configure b/Functions/Completion/_configure new file mode 100644 index 000000000..de8d5fba5 --- /dev/null +++ b/Functions/Completion/_configure @@ -0,0 +1,12 @@ +#defcomp configure + +if [[ $PREFIX = *=* ]]; then + # Complete filenames after e.g. --prefix= + IPREFIX=${PREFIX%%=*}= + PREFIX=${PREFIX#*=} + complist -f +else + # Generate a list of options from configure --help + complist -s '$($COMMAND --help | + sed -n -e '\''s/^ *\(--[-a-z0-9]*\)[ =,].*$/\1/p'\'')' +fi diff --git a/Functions/Completion/_dd b/Functions/Completion/_dd new file mode 100644 index 000000000..2458541ea --- /dev/null +++ b/Functions/Completion/_dd @@ -0,0 +1,13 @@ +#defcomp dd + +if [[ -iprefix conv= ]]; then + # If there's a comma present, ignore up to the last one. The + # test alone will have that effect. + [[ -string , ]] + complist -S, -q \ + -k '(ascii ebcdic ibm block unblock lcase ucase swab noerror sync)' +elif [[ -iprefix 'if=' || -iprefix 'of=' ]]; then + _files +else + complist -S '=' -k '(if of ibs obs bs cbs skip files seek count conv)' +fi diff --git a/Functions/Completion/_default b/Functions/Completion/_default new file mode 100644 index 000000000..8bcf14f6a --- /dev/null +++ b/Functions/Completion/_default @@ -0,0 +1,13 @@ +#defcomp -default- + +# We first try the `compctl's. This is without first (-T) and default (-D) +# completion. If you want them add `-T' and/or `-D' to this command. +# If there is a `compctl' for the command we are working on, we return +# immediatly. If you want to use new style completion anyway, remove the +# `|| return'. Also, you may want to use new style completion if the +# `compctl' didn't produce any matches. In that case remove the `|| return' +# and at the line `[[ -nmatches 0 ]] || return' after `compcall'. + +compcall || return + +_files diff --git a/Functions/Completion/_dirs b/Functions/Completion/_dirs new file mode 100644 index 000000000..c79080d58 --- /dev/null +++ b/Functions/Completion/_dirs @@ -0,0 +1,3 @@ +#defcomp rmdir df du dircmp + +_files -/ '*(-/)' diff --git a/Functions/Completion/_disable b/Functions/Completion/_disable new file mode 100644 index 000000000..063b65a7d --- /dev/null +++ b/Functions/Completion/_disable @@ -0,0 +1,6 @@ +#defcomp disable + +[[ -mcurrent -1 -*a* ]] && complist -ea +[[ -mcurrent -1 -*f* ]] && complist -eF +[[ -mcurrent -1 -*r* ]] && complist -ew +[[ ! -mcurrent -1 -* ]] && complist -eB diff --git a/Functions/Completion/_dvi b/Functions/Completion/_dvi new file mode 100644 index 000000000..bb2fc293e --- /dev/null +++ b/Functions/Completion/_dvi @@ -0,0 +1,3 @@ +#defcomp xdvi dvips dvibook dviconcat dvicopy dvidvi dviselect dvitodvi dvitype + +_files -g '*.(dvi|DVI)' diff --git a/Functions/Completion/_echotc b/Functions/Completion/_echotc new file mode 100644 index 000000000..85ebb97ce --- /dev/null +++ b/Functions/Completion/_echotc @@ -0,0 +1,3 @@ +#defcomp echotc + +complist -k '(al dc dl do le up al bl cd ce cl cr dc dl do ho is le ma nd nl se so up)' diff --git a/Functions/Completion/_enable b/Functions/Completion/_enable new file mode 100644 index 000000000..22ff53ee7 --- /dev/null +++ b/Functions/Completion/_enable @@ -0,0 +1,6 @@ +#defcomp enable + +[[ -mcurrent -1 -*a* ]] && complist -da +[[ -mcurrent -1 -*f* ]] && complist -dF +[[ -mcurrent -1 -*r* ]] && complist -dw +[[ ! -mcurrent -1 -* ]] && complist -dB diff --git a/Functions/Completion/_fc b/Functions/Completion/_fc new file mode 100644 index 000000000..f0d2c03fd --- /dev/null +++ b/Functions/Completion/_fc @@ -0,0 +1,7 @@ +#defcomp fc + +if [[ -mcurrent -1 -*e ]]; then + complist -c +elif [[ -mcurrent -1 -[ARWI]## ]]; then + _files +fi diff --git a/Functions/Completion/_files b/Functions/Completion/_files new file mode 100644 index 000000000..ab3006e39 --- /dev/null +++ b/Functions/Completion/_files @@ -0,0 +1,10 @@ +#autoload + +# Utility function for completing files of a given type or any file. +# In many cases you will want to call this one instead of _path_files(). + +local nm=$NMATCHES + +_path_files "$@" + +[[ $# -ne 0 && -nmatches nm ]] && _path_files diff --git a/Functions/Completion/_find b/Functions/Completion/_find new file mode 100644 index 000000000..ca4f79908 --- /dev/null +++ b/Functions/Completion/_find @@ -0,0 +1,21 @@ +#defcomp find + +if [[ -mbetween -(ok|exec) \\\; ]]; then + _normal "$@" +elif [[ -iprefix - ]]; then + complist -s 'daystart {max,min,}depth follow noleaf version xdev \ + {a,c,}newer {a,c,m}{min,time} empty false {fs,x,}type gid inum links \ + {i,}{l,}name {no,}{user,group} path perm regex size true uid used \ + exec {f,}print{f,0,} ok prune ls' +elif [[ -position 1 ]]; then + complist -g '. ..' + _files -g '(-/)' +elif [[ -mcurrent -1 -((a|c|)newer|fprint(|0|f)) ]]; then + _files +elif [[ -current -1 -fstype ]]; then + complist -k '(ufs 4.2 4.3 nfs tmp mfs S51K S52K)' +elif [[ -current -1 -group ]]; then + complist -k groups +elif [[ -current -1 -user ]]; then + complist -u +fi diff --git a/Functions/Completion/_functions b/Functions/Completion/_functions new file mode 100644 index 000000000..8a352ea08 --- /dev/null +++ b/Functions/Completion/_functions @@ -0,0 +1,3 @@ +#defcomp unfunction + +complist -F diff --git a/Functions/Completion/_gunzip b/Functions/Completion/_gunzip new file mode 100644 index 000000000..35a27e774 --- /dev/null +++ b/Functions/Completion/_gunzip @@ -0,0 +1,3 @@ +#defcomp gunzip zcat + +_files -g '*.[gG][z]' diff --git a/Functions/Completion/_gzip b/Functions/Completion/_gzip new file mode 100644 index 000000000..3cda1e4ed --- /dev/null +++ b/Functions/Completion/_gzip @@ -0,0 +1,3 @@ +#defcomp gzip + +_files -g '*~*.[gG][zZ]' diff --git a/Functions/Completion/_hash b/Functions/Completion/_hash new file mode 100644 index 000000000..a6109563d --- /dev/null +++ b/Functions/Completion/_hash @@ -0,0 +1,13 @@ +#defcomp hash + +if [[ -mword 1 -*d* ]]; then + if [[ -string 1 '=' ]]; then + _path_files -g '*(-/)' + else + complist -n -q -S '=' + fi +elif [[ -string 1 '=' ]]; then + _files -g '*(*)' '*(-/)' +else + complist -m -q -S '=' +fi diff --git a/Functions/Completion/_hosts b/Functions/Completion/_hosts new file mode 100644 index 000000000..3acc327ac --- /dev/null +++ b/Functions/Completion/_hosts @@ -0,0 +1,3 @@ +#defcomp ftp ncftp ping rwho rup xping traceroute nslookup + +complist -k hosts diff --git a/Functions/Completion/_jobs b/Functions/Completion/_jobs new file mode 100644 index 000000000..018883c61 --- /dev/null +++ b/Functions/Completion/_jobs @@ -0,0 +1,3 @@ +#defcomp fg jobs + +complist -j -P '%' diff --git a/Functions/Completion/_kill b/Functions/Completion/_kill new file mode 100644 index 000000000..bf0e1d3f8 --- /dev/null +++ b/Functions/Completion/_kill @@ -0,0 +1,8 @@ +#defcomp kill + +if [[ -iprefix '-' ]]; then + complist -k "($signals[1,-3])" +else + complist -P '%' -j + complist -y _kill_helper -s '`ps 2>/dev/null | tail +2 | cut -c1-5`' +fi diff --git a/Functions/Completion/_kill_helper b/Functions/Completion/_kill_helper new file mode 100644 index 000000000..d3e9aaf4a --- /dev/null +++ b/Functions/Completion/_kill_helper @@ -0,0 +1,3 @@ +#autoload + +reply=( "$(ps 2>/dev/null)" ) diff --git a/Functions/Completion/_limits b/Functions/Completion/_limits new file mode 100644 index 000000000..35ccbe07e --- /dev/null +++ b/Functions/Completion/_limits @@ -0,0 +1,3 @@ +#defcomp limit unlimit + +complist -k "(${(j: :)${(f)$(limit)}%% *})" diff --git a/Functions/Completion/_main_complete b/Functions/Completion/_main_complete new file mode 100644 index 000000000..003a01785 --- /dev/null +++ b/Functions/Completion/_main_complete @@ -0,0 +1,48 @@ +#autoload + +# The main loop of the completion code. This is what is called when +# completion is attempted from the command line. +# The completion code gives us the special variables and the arguments +# from the command line are given as positional parameters. + +local comp name + +setopt localoptions nullglob rcexpandparam globdots +unsetopt markdirs globsubst shwordsplit nounset + +# An entry for `-first-' is the replacement for `compctl -T' +# Completion functions may set `COMPSKIP' to any value to make the +# main loops stop calling other completion functions. + +comp="$comps[-first-]" +if [[ ! -z "$comp" ]]; then + "$comp" "$@" + if (( $+COMPSKIP )); then + unset COMPSKIP + return + fi +fi + +# For arguments we use the `_normal function. + +if [[ $CONTEXT == argument || $CONTEXT == command ]]; then + _normal "$@" +else + # Let's see if we have a special completion definition for the other + # possible contexts. + + comp='' + + case $CONTEXT in + redirect) comp="$comps[-redirect-]";; + math) comp="$comps[-math-]";; + subscript) comp="$comps[-subscript-]";; + value) comp="$comps[-value-]";; + condition) comp="$comps[-condition-]";; + esac + + # If not, we use default completion, if any. + + [[ -z "$comp" ]] && comp="$comps[-default-]" + [[ -z "$comp" ]] || "$comp" "$@" +fi diff --git a/Functions/Completion/_make b/Functions/Completion/_make new file mode 100644 index 000000000..d576b0308 --- /dev/null +++ b/Functions/Completion/_make @@ -0,0 +1,3 @@ +#defcomp make gmake pmake + +complist -s "\$(awk '/^[a-zA-Z0-9][^/ ]+:/ {print \$1}' FS=: [mM]akefile)" diff --git a/Functions/Completion/_man b/Functions/Completion/_man new file mode 100644 index 000000000..8204fba0b --- /dev/null +++ b/Functions/Completion/_man @@ -0,0 +1,11 @@ +#defcomp man +setopt localoptions rcexpandparam + +local rep +if [[ $2 = (<->*|ln) ]]; then + rep=( $manpath/(man|cat)$2/$PREFIX*$SUFFIX.<->*(N:t:r) ) +else + rep=( $manpath/(man|cat)*/$PREFIX*$SUFFIX.<->*(N:t:r) ) +fi + +(( $#rep )) && compadd -m $rep diff --git a/Functions/Completion/_mh b/Functions/Completion/_mh new file mode 100644 index 000000000..67ce49fd2 --- /dev/null +++ b/Functions/Completion/_mh @@ -0,0 +1,70 @@ +#defcomp folder comp inc mark refile repl scan show next prev rmm pick whom mhn mhpath mhpatch + +# Completion for all possible MH commands. +# Alter the following two to your own mh directory and the directory +# where standard mh library files live. (It works anyway, but this +# will save a little time.) +local mymhdir=~/Mail +local mhlib=/usr/lib/mh + +# To be on the safe side, check this exists and if not, get it anyway. +[[ -d $mymhdir ]] || mymhdir=$(mhpath +) + +if [[ -iprefix - ]]; then + # get list of options, which MH commands can generate themselves + # awk is just too icky to use for this, sorry. send me one if + # you come up with it. + compadd -m $($COMMAND -help | perl -ne 'if (/^\s*-\(?(\S+)/) { + $n = $1; + $n =~ s/\)//g; + print $n =~ s/^\[([a-z]+)\]// ? "$n\n$1$n\n" : "$n\n"; + }') + return +elif [[ -iprefix '+' || -iprefix '@' || -current -1 -draftfolder ]]; then + # Complete folder names. + local mhpath + if [[ $IPREFIX != '@' ]]; then + [[ $IPREFIX = '+' ]] || IPREFIX=+ + mhpath=$mymhdir + else + mhpath=$(mhpath) + fi + + # painless, or what? + complist -W mhpath -/ +elif [[ -mcurrent -1 -(editor|(whatnow|rmm|show|more)proc) ]]; then + complist -c +elif [[ -current -1 -file ]]; then + complist -f +elif [[ -mcurrent -1 -(form|audit|filter) ]]; then + # Need some MH template file, which may be in our own MH directory + # or with the standard library. + local mhfpath + # This is the only place we need mhlib, so leave the test till here. + [[ -d $mhlib ]] || { mhlib=$(mhparam mhlproc); mhlib=$mhlib:h; } + mhfpath=($mymhdir $mhlib) + + complist -W mhfpath -g '*(.)' +elif [[ -mcurrent -1 -(no|)cc ]]; then + compadd -m all to cc me +elif [[ -mcurrent -1 -[rw]cache ]]; then + compadd -m public private never ask +else + # Generate sequences. + local foldnam folddir f + for f in $argv; do + [[ $f = [@+]* ]] && foldnam=$f + done + if [[ $foldnam = '+'* ]]; then + folddir=$mymhdir/${foldnam#+} + elif [[ $foldnam = '@'* ]]; then + folddir=$(mhpath)/${foldnam#@} + else + folddir=$(mhpath) + # leaving foldnam empty works here + fi + + complist -s '$(mark $foldnam | awk -F: '\''{ print $1 }'\'')' + compadd -m reply next cur prev first last all unseen + complist -W folddir -g '<->' +fi diff --git a/Functions/Completion/_most_recent_file b/Functions/Completion/_most_recent_file new file mode 100644 index 000000000..69900e6ff --- /dev/null +++ b/Functions/Completion/_most_recent_file @@ -0,0 +1,3 @@ +#defkeycomp expand-or-complete \C-xm + +complist -g '*(om[1])' diff --git a/Functions/Completion/_normal b/Functions/Completion/_normal new file mode 100644 index 000000000..22cc1decf --- /dev/null +++ b/Functions/Completion/_normal @@ -0,0 +1,56 @@ +#autoload + +local comp cmd1 cmd2 pat val name + +# Completing in command position? If not we set up `cmd1' and `cmd2' as +# two strings we have search in the completion definition arrays (e.g. +# a path and the last path name component). + +if [[ $CONTEXT == command ]]; then + comp="$comps[-command-]" + [[ -z "$comp" ]] || "$comp" "$@" + return +elif [[ "$COMMAND[1]" == '=' ]]; then + eval cmd1\=$COMMAND + cmd2="$COMMAND[2,-1]" +elif [[ "$COMMAND" == */* ]]; then + cmd1="$COMMAND" + cmd2="${COMMAND:t}" +else + cmd1="$COMMAND" + eval cmd2=$(whence -p $COMMAND) +fi + +# See if there are any matching pattern completions. + +if (( $#patcomps )); then + for i in "$patcomps[@]"; do + pat="${i% *}" + val="${i#* }" + if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then + "$val" "$@" + if (( $+COMPSKIP )); then + unset COMPSKIP + return + fi + fi + done +fi + +# Now look up the two names in the normal completion array. + +name="$cmd1" +comp="$comps[$cmd1]" + +if [[ -z "$comp" ]]; then + name="$cmd2" + comp="$comps[$cmd2]" +fi + +# And generate the matches, probably using default completion. + +if [[ -z "$comp" ]]; then + name=-default- + comp="$comps[-default-]" +fi +[[ -z "$comp" ]] || "$comp" "$@" diff --git a/Functions/Completion/_path_files b/Functions/Completion/_path_files new file mode 100644 index 000000000..7db364b7d --- /dev/null +++ b/Functions/Completion/_path_files @@ -0,0 +1,272 @@ +#autoload + +# Utility function for in-path completion. +# First argument should be an complist-option (e.g. -f, -/, -g). The other +# arguments should be glob patterns, one per argument. +# +# E.g.: _path_files -g '*.tex' '*.texi' +# +# This is intended as a replacement for `complist -f', `complist -/', and +# `complist -g ...' (but don't use it with other options). +# +# You may also give the `-W ' option as with `compctl' and `complist', +# but only as the first argument. +# +# This function also accepts an optional `-F ' option as its first +# argument or just after the `-W '. This can be used to define file +# name extension (a la `fignore'). Files with such an extension will not +# be considered possible completions. +# +# This function behaves as if you have a matcher definition like: +# compctl -M 'r:|[-.,_/]=* r:|=* m:{a-z}={A-Z} m:-=_ m:.=,' \ +# 'm:{a-z}={A-Z} l:|=* r:|=*' +# so you may want to modify this. + +local nm prepaths str linepath realpath donepath patstr prepath testpath rest +local tmp1 collect tmp2 suffixes i ignore + +setopt localoptions nullglob rcexpandparam globdots extendedglob +unsetopt markdirs globsubst shwordsplit nounset + +# Get the optional `-W' option and its argument. +if [[ "$1" = -W ]]; then + tmp1="$2" + if [[ "$tmp1[1]" = '(' ]]; then + prepaths=( $tmp1[2,-2]/ ) + else + prepaths=( ${(P)${tmp1}} ) + [[ $#prepaths -eq 0 ]] && prepaths=( $tmp1/ ) + fi + [[ $#prepaths -eq 0 ]] && prepaths=( '' ) + shift 2 +else + prepaths=( '' ) +fi + +# Get the optional `-F' option and its argument. +if [[ "$1" = -F ]]; then + ignore=(-F "$2") + shift 2 +else + ignore='' +fi + +# str holds the whole string from the command line with a `*' between +# the prefix and the suffix. + +str="${PREFIX:q}*${SUFFIX:q}" + +# We will first try normal completion called with `complist', but only if we +# weren't given a `-F' option. + +if [[ -z "$ignore" ]]; then + # First build an array containing the `-W' option, if there is any and we + # want to use it. We don't want to use it if the string from the command line + # is a absolute path or relative to the current directory. + + if [[ -z "$tmp1[1]" || "$str[1]" = [~/] || "$str" = (.|..)/* ]]; then + tmp1=() + else + tmp1=(-W "( $prepaths )") + fi + + # Now call complist. + + nm=$NMATCHES + if [[ $# -eq 0 ]]; then + complist "$tmp1[@]" -f + elif [[ "$1" = -g ]]; then + complist "$tmp1[@]" -g "$argv[2,-1]" + shift + else + complist "$tmp1[@]" $1 + shift + fi + + # If this generated any matches, we don't wnat to do in-path completion. + + [[ -nmatches nm ]] || return + + # No `-F' option, so we want to use `fignore'. + + ignore=(-F fignore) +fi + +# If we weren't given any file patterns as arguments, we trick ourselves +# into believing that we were given the pattern `*'. This is just to simplify +# the following code. + +[[ -z "$1" ]] && 1='*' + +# Now let's have a closer look at the string to complete. + +if [[ "$str[1]" = \~ ]]; then + # It begins with `~', so remember anything before the first slash to be able + # to report it to the completion code. Also get an expanded version of it + # (in `realpath'), so that we can generate the matches. Then remove that + # prefix from the string to complete, set `donepath' to build the correct + # paths and make sure that the loop below is run only once with an empty + # prefix path by setting `prepaths'. + + linepath="${str%%/*}/" + eval realpath\=path + str="${str#*/}" + donepath='' + prepaths=( '' ) +else + # If the string does not start with a `~' we don't remove a prefix from the + # string. + + liniepath='' + realpath='' + + if [[ "$str[1]" = / ]]; then + # If it is a absolut path name, we remove the first slash and put it in + # `donepath' meaning that we treat it as the path that was already handled. + # Also, we don't use the paths from `-W'. + + str="$str[2,-1]" + donepath='/' + prepaths=( '' ) + else + # The common case, we just use the string as it is, unless it begins with + # `./' or `../' in which case we don't use the paths from `-W'. + + [[ "$str" = (.|..)/* ]] && prepaths=( '' ) + donepath='' + fi +fi + +# First we skip over all pathname components in `str' which really exist in +# the file-system, so that `/usr/lib/l' doesn't offer you `lib' and +# `lib5'. Pathname components skipped this way are taken from `str' and added +# to `donepath'. + +while [[ "$str" = */* ]] do + [[ -e "$realpath$donepath${str%%/*}" ]] || break + donepath="$donepath${str%%/*}/" + str="${str#*/}" +done + +# Now build the glob pattern. As noted above, this function behaves as if +# a global matcher with two matching specifications are given. + +if [[ -matcher 1 ]]; then + patstr="$str:gs/,/*,/:gs/_/*_/:gs./.*/.:gs/-/*[-_]/:gs/./*[.,]/:gs-*[.,]*[.,]*/-../-:gs.**.*." +else + patstr="${str%/*}/*${str##*/}*" + patstr="$patstr:gs./.*/.:gs.**.*." +fi + +# Finally, generate the matches. First we loop over all the paths from `-W'. +# Note that in this loop `str' is used as a modifyable version of `patstr' +# and `testpath' is a modifyable version of `donepath'. + +for prepath in "$prepaths[@]"; do + str="$patstr" + testpath="$donepath" + + # The second loop tests the components of the path in `str' to get the + # possible matches. + + while [[ "$str" = */* ]] do + # `rest' is the pathname after the first slash that is left. In `tmp1' + # we get the globbing matches for the pathname component currently + # handled. + + rest="${str#*/}" + tmp1="${prepath}${realpath}${testpath}(#l)${str%%/*}(-/)" + tmp1=( $~tmp1 ) + + if [[ $#tmp1 -eq 0 ]]; then + # If this didn't produce any matches, we don't need to test this path + # any further, so continue with the next `-W' path, if any. + + continue 2 + elif [[ $#tmp1 -gt 1 ]]; then + # If it produced more than one match, we want to remove those which + # don't have possible following pathname components matching the + # rest of the string we are completing. (The case with only one + # match is handled below.) + # In `collect' we will collect those of the produced pathnames that + # have a matching possible path-suffix. In `suffixes' we build an + # array containing strings build from the rest of the string to + # complete and the glob patterns we were given as arguments. + + collect=() + suffixes=( $rest$@ ) + suffixes=( "${(@)suffixes:gs.**.*.}" ) + + # In the loop the prefixes from the `tmp1' array produced above and + # the suffixes we just built are used to produce possible matches + # via globbing. + + for i in $tmp1; do + tmp2=( $~i/(#l)$~suffixes ) + [[ $#tmp2 -ne 0 ]] && collect=( $collect $i ) + done + + # If this test showed that none of the matches from the glob in `tmp1' + # has a possible sub-path matching what's on the line, we give up and + # continue with the next `-W' path. + + if [[ $#collect -eq 0 ]]; then + continue 2 + elif [[ $#collect -ne 1 ]]; then + # If we have more than one possible match, this means that the + # pathname component currently handled is ambiguous, so we give + # it to the completion code. + # First we build the full path prefix in `tmp1'. + + tmp1="$prepath$realpath$testpath" + + # Now produce all matching pathnames in `collect'. + + collect=( $~collect/(#l)$~suffixes ) + + # And then remove the common path prefix from all these matches. + + collect=( ${collect#$tmp1} ) + + # Finally, we add all these matches with the common (unexpanded) + # pathprefix (the `-p' option), the path-prefix (the `-W' option) + # to allow the completion code to test file type, and the path- + # suffix (the `-s' option). We also tell the completion code that + # these are file names and that `fignore' should be used as usual + # (the `-f' and `-F' options). + + for i in $collect; do + compadd -p "$linepath$testpath" -W "$tmp1" -s "/${i#*/}" -f "$ignore[@]" - "${i%%/*}" + done + + # We have just finished handling all the matches from above, so we + # can continue with the next `-W' path. + + continue 2 + fi + # We reach this point if only one of the path prefixes in `tmp1' + # has a existing path-suffix matching the string from the line. + # In this case we accept this match and continue with the next + # path-name component. + + tmp1=( "$collect[1]" ) + fi + # This is also reached if the first globbing produced only one match + # in this case we just continue with the next pathname component, too. + + tmp1="$tmp1[1]" + testpath="$testpath${tmp1##*/}/" + str="$rest" + done + + # We are here if all pathname components except the last one (which is still + # not tested) are unambiguous. So we add matches with the full path prefix, + # no path suffix, the `-W' we are currently handling, all the matches we + # can produce in this directory, if any. + + tmp1="$prepath$realpath$testpath" + suffixes=( $str$@ ) + suffixes=( "${(@)suffixes:gs.**.*.}" ) + tmp2=( $~tmp1(#l)$~suffixes ) + compadd -p "$linepath$testpath" -W "$prepath$realpath$testpath" -f "$ignore[@]" - ${tmp2#$tmp1} +done diff --git a/Functions/Completion/_pdf b/Functions/Completion/_pdf new file mode 100644 index 000000000..7d7756c3e --- /dev/null +++ b/Functions/Completion/_pdf @@ -0,0 +1,3 @@ +function acroread + +_files -g '*.(pdf|PDF)' diff --git a/Functions/Completion/_precommand b/Functions/Completion/_precommand new file mode 100644 index 000000000..2cf661147 --- /dev/null +++ b/Functions/Completion/_precommand @@ -0,0 +1,5 @@ +#defcomp - nohup nice eval time rusage noglob nocorrect exec + +[[ -position 1 -1 ]] + +_normal "$@" diff --git a/Functions/Completion/_ps b/Functions/Completion/_ps new file mode 100644 index 000000000..6bc0643b2 --- /dev/null +++ b/Functions/Completion/_ps @@ -0,0 +1,3 @@ +#defcomp gs ghostview gview psnup psselect pswrap pstops pstruct lpr + +_files -g '*([pP][sS]|eps)' diff --git a/Functions/Completion/_rcs b/Functions/Completion/_rcs new file mode 100644 index 000000000..537db6278 --- /dev/null +++ b/Functions/Completion/_rcs @@ -0,0 +1,9 @@ +#defcomp co ci rcs + +[[ $COMMAND = ci || $COMMAND = rcs ]] && _files + +if [[ $NMATCHES -eq 0 && -d RCS && $COMMAND != ci ]]; then + local rep + rep=(RCS/$PREFIX*$SUFFIX,v(:t:s/\,v//)) + (( $#rep )) && compadd -m $rep +fi diff --git a/Functions/Completion/_rlogin b/Functions/Completion/_rlogin new file mode 100644 index 000000000..e36554f23 --- /dev/null +++ b/Functions/Completion/_rlogin @@ -0,0 +1,9 @@ +#defcomp rlogin rsh ssh + +if [[ -position 1 ]]; then + complist -k hosts +elif [[ -position 2 ]]; then + complist -k '(-l)' +else + complist -u +fi diff --git a/Functions/Completion/_sched b/Functions/Completion/_sched new file mode 100644 index 000000000..ee785879b --- /dev/null +++ b/Functions/Completion/_sched @@ -0,0 +1,3 @@ +#defcomp sched + +[[ -position 2 -1 ]] && compsub diff --git a/Functions/Completion/_set b/Functions/Completion/_set new file mode 100644 index 000000000..e3069f134 --- /dev/null +++ b/Functions/Completion/_set @@ -0,0 +1,7 @@ +#defcomp set + +if [[ -mcurrent -1 [-+]o ]]; then + complist -o +elif [[ -current -1 -A ]]; then + complist -A +fi diff --git a/Functions/Completion/_setopt b/Functions/Completion/_setopt new file mode 100644 index 000000000..4abb3ccee --- /dev/null +++ b/Functions/Completion/_setopt @@ -0,0 +1,7 @@ +#defcomp setopt + +local nm=$NMATCHES + +complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \ + -s '$({ unsetopt kshoptionprint; unsetopt } 2>/dev/null)' +[[ -nmatches nm ]] && complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o diff --git a/Functions/Completion/_source b/Functions/Completion/_source new file mode 100644 index 000000000..94e3fbeb1 --- /dev/null +++ b/Functions/Completion/_source @@ -0,0 +1,7 @@ +#defcomp source + +if [[ -position 2 -1 ]]; then + compsub +else + _files +fi diff --git a/Functions/Completion/_strip b/Functions/Completion/_strip new file mode 100644 index 000000000..6962ac455 --- /dev/null +++ b/Functions/Completion/_strip @@ -0,0 +1,2 @@ +#defcomp strip +_files -g '*(*)' diff --git a/Functions/Completion/_stty b/Functions/Completion/_stty new file mode 100644 index 000000000..6b54b5007 --- /dev/null +++ b/Functions/Completion/_stty @@ -0,0 +1,16 @@ +#defcomp stty + +if [[ -mcurrent -1 \ + (*erase|discard|status|dsusp|intr|kill|lnext|quit|reprint|start|s*p) ]] +then + compadd -m -Q '^-' '^h' '^?' '^c' '^u' +else + [[ -string '-' || -string '+' ]] + compadd -m rows columns intr quit erase kill eof eol \ + eol2 start stop susp dsusp reprint discard werase lnext \ + parenb parodd cs8 cstopb hupcl cread clocal parext \ + ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl iuclc \ + ixon ixany ixoff imaxbel isig icanon xcase echo echoe echok \ + echonl noflsh tostop echoctl echoprt echoke flusho pending iexten \ + opost olcuc onlcr ocrnl onocr onlret ofill ofdel +fi diff --git a/Functions/Completion/_subscript b/Functions/Completion/_subscript new file mode 100644 index 000000000..2b827a117 --- /dev/null +++ b/Functions/Completion/_subscript @@ -0,0 +1,4 @@ +#defcomp -subscript- + +_compalso -math- "$@" +[[ ${(Pt)${COMMAND}} = assoc* ]] && complist -k "( ${(kP)${COMMAND}} )" diff --git a/Functions/Completion/_tar b/Functions/Completion/_tar new file mode 100644 index 000000000..91767e44d --- /dev/null +++ b/Functions/Completion/_tar @@ -0,0 +1,11 @@ +#defcomp tar + +local nm=$NMATCHES tf="$2" + +if [[ ( -mword 1 *t*f* || -mword 1 *x*f* ) && -position 3 100000 ]]; then + complist -k "( $(tar tf $tf) )" +elif [[ -mword 1 *c*f* && -position 3 100000 ]]; then + _files +elif [[ -mcurrent -1 *f* && -position 2 ]]; then + _files -g '*.(tar|TAR)' +fi diff --git a/Functions/Completion/_tex b/Functions/Completion/_tex new file mode 100644 index 000000000..1f645e2a2 --- /dev/null +++ b/Functions/Completion/_tex @@ -0,0 +1,3 @@ +#defcomp tex latex slitex + +_files -g '*.(tex|TEX|texinfo|texi)' diff --git a/Functions/Completion/_trap b/Functions/Completion/_trap new file mode 100644 index 000000000..59e81c589 --- /dev/null +++ b/Functions/Completion/_trap @@ -0,0 +1,7 @@ +#defcomp trap + +if [[ -position 1 ]]; then + complist -c +else + complist -k signals +fi diff --git a/Functions/Completion/_uncompress b/Functions/Completion/_uncompress new file mode 100644 index 000000000..e25805d50 --- /dev/null +++ b/Functions/Completion/_uncompress @@ -0,0 +1,3 @@ +#defcomp uncompress zmore + +_files -g '*.Z' diff --git a/Functions/Completion/_unhash b/Functions/Completion/_unhash new file mode 100644 index 000000000..fe40c25a2 --- /dev/null +++ b/Functions/Completion/_unhash @@ -0,0 +1,6 @@ +#defcomp unhash + +[[ -mword 1 -*d* ]] && complist -n +[[ -mword 1 -*a* ]] && complist -a +[[ -mword 1 -*f* ]] && complist -F +[[ ! -mword 1 -* ]] && complist -m diff --git a/Functions/Completion/_unsetopt b/Functions/Completion/_unsetopt new file mode 100644 index 000000000..90d642b51 --- /dev/null +++ b/Functions/Completion/_unsetopt @@ -0,0 +1,7 @@ +#defcomp unsetopt + +local nm=$NMATCHES + +complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' \ + -s '$({ unsetopt kshoptionprint; setopt } 2>/dev/null)' +[[ -nmatches nm ]] && complist -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' -o diff --git a/Functions/Completion/_vars b/Functions/Completion/_vars new file mode 100644 index 000000000..7153b6f38 --- /dev/null +++ b/Functions/Completion/_vars @@ -0,0 +1,3 @@ +#defcomp -math- getopts read unset vared + +complist -v diff --git a/Functions/Completion/_vars_eq b/Functions/Completion/_vars_eq new file mode 100644 index 000000000..fcbb0148c --- /dev/null +++ b/Functions/Completion/_vars_eq @@ -0,0 +1,3 @@ +#defcomp declare export integer local readonly typeset + +complist -v -q -S '=' diff --git a/Functions/Completion/_wait b/Functions/Completion/_wait new file mode 100644 index 000000000..34bc53ee3 --- /dev/null +++ b/Functions/Completion/_wait @@ -0,0 +1,4 @@ +#defcomp wait + +complist -P '%' -j +complist -y _kill_helper -s '`ps 2>/dev/null | tail +2 | cut -c1-5`' diff --git a/Functions/Completion/_which b/Functions/Completion/_which new file mode 100644 index 000000000..324256e3d --- /dev/null +++ b/Functions/Completion/_which @@ -0,0 +1,3 @@ +#defcomp which whence where type + +complist -caF diff --git a/Functions/Completion/_x_options b/Functions/Completion/_x_options new file mode 100644 index 000000000..cc469286d --- /dev/null +++ b/Functions/Completion/_x_options @@ -0,0 +1,5 @@ +#defpatcomp */X11/* + +# A simple pattern completion, just as an example. + +complist -J options -k '(-display -name -xrm)' diff --git a/Functions/Completion/_xfig b/Functions/Completion/_xfig new file mode 100644 index 000000000..fcd2bba9f --- /dev/null +++ b/Functions/Completion/_xfig @@ -0,0 +1,3 @@ +#defcomp xfig + +_files -g '*.fig' diff --git a/Functions/Completion/_zftp b/Functions/Completion/_zftp new file mode 100644 index 000000000..4ff707cc6 --- /dev/null +++ b/Functions/Completion/_zftp @@ -0,0 +1,50 @@ +#defpatcomp zf* + +# Don't try any more completion after this. +COMPSKIP=1 + +# Completion for zftp builtin and zf* functions. The functions +# zfcd_match and zfget_match (used for old-style completion) +# need to be installed for remote file and directory completion to work. + +local subcom + +if [[ $COMMAND = zftp ]]; then + if [[ $CURRENT -eq 1 ]]; then + compadd -m open params user login type ascii binary mode put \ + putat get getat append appendat ls dir local remote mkdir rmdir + return + fi + subcom=$1 +else + subcom=$COMMAND +fi + +case $subcom in + *(cd|ls|dir)) + # complete remote directories; we could be smarter about hiding prefixes + zfcd_match $PREFIX $SUFFIX + (( $#reply )) && compadd -m -S/ -q $reply + ;; + + *(get(|at)|gcp|delete|remote)) + # complete remote files + zfget_match $PREFIX $SUFFIX + (( $#reply )) && compadd -F fignore -m $reply + ;; + + *(put(|at)|pcp)) + # complete local files + _files + ;; + + *(open|anon|params)) + # complete hosts: should do cleverer stuff with user names + complist -k hosts + ;; + + *) + # dunno... try ordinary completion after all. + unset COMPSKIP + ;; +esac diff --git a/Functions/Completion/_zle b/Functions/Completion/_zle new file mode 100644 index 000000000..bb1102e74 --- /dev/null +++ b/Functions/Completion/_zle @@ -0,0 +1,7 @@ +#defcomp zle + +if [[ -word 1 -N && -position 3 ]]; then + complist -F +else + complist -b +fi diff --git a/Functions/Completion/_zmodload b/Functions/Completion/_zmodload new file mode 100644 index 000000000..112acb57c --- /dev/null +++ b/Functions/Completion/_zmodload @@ -0,0 +1,9 @@ +#defcomp zmodload + +if [[ -mword 1 -*(a*u|u*a)* || -mword 1 -*a* && -position 3 -1 ]]; then + complist -B +elif [[ -mword 1 -*u* ]]; then + complist -s '$(zmodload)' +else + complist -s '${^module_path}/*(N:t:r)' +fi diff --git a/Functions/Completion/dump b/Functions/Completion/dump new file mode 100644 index 000000000..ad5547bea --- /dev/null +++ b/Functions/Completion/dump @@ -0,0 +1,89 @@ +# This is a file to be sourced to dump the definitions for new-style +# completion defined by 'init' in the same directory. For best results, +# it should be run immediately after init, before any of the completions +# have been autoloaded. The output should be directed into the "init.dump" +# in the same directory as init. If you rename init, just stick .dump onto +# the end of whatever you have called it and put it in the same directory. +# +# You will need to update the dump every time you add a new completion. +# To do this, simply remove the .dump file, start a new shell, and +# create the .dump file as before. +# +# It relies on KSH_ARRAYS not being set. + +# Print the number of files used for completion. This is used in init +# to see if auto-dump should re-dump the dump-file. + +_d_file=${COMPDUMP-${0:h}/init.dump} + +_d_files=( ${^~fpath}/_*~*~ ) + +print "#files: $#_d_files" > $_d_file + +unset _d_files + +# First dump the arrays comps and patcomps. The quoting hieroglyphyics +# ensure that a single quote inside a variable is itself correctly quoted. + +print "comps=(" >> $_d_file +for _d_f in ${(k)comps}; do + print -r - "'${_d_f//\'/'\\''}'" "'${comps[$_d_f]//\'/'\\''}'" +done >> $_d_file +print ")" >> $_d_file + +if (( $#patcomps )); then + print "\npatcomps=(" >> $_d_file + for _d_f in "$patcomps[@]"; do + print -r - "'${_d_f//\'/'\\''}'" + done >> $_d_file + print ")" >> $_d_file +fi + +print >> $_d_file + +# Now dump the key bindings. We dump all bindings for zle widgets +# whose names start with a underscore. +# We need both the zle -C's and the bindkey's to recreate. + +_d_bks=() +zle -lL | + while read -rA _d_line; do + if [[ ${_d_line[5]} = _* ]]; then + print -r - ${_d_line} + _d_bks=($_d_bks ${_d_line[3]}) + fi + done >> $_d_file +bindkey | + while read -rA _d_line; do + if [[ ${_d_line[2]} = (${(j.|.)~_d_bks}) ]]; then + print -r "bindkey '${_d_line[1][2,-2]}' ${_d_line[2]}" + fi + done >> $_d_file + +print >> $_d_file + + +# Autoloads: whence -w produces "_d_foo: function", so look for +# all functions beginning with `_'. + +_d_als=($(whence -wm '_*' | +while read -rA _d_line; do + [[ ${_d_line[2]} = function ]] && print -r - ${_d_line[1]%:} +done)) + +# print them out: about six to a line looks neat + +while (( $#_d_als )); do + print -n autoload + for (( _i = 0; _i < 6; _i++ )); do + if (( $#_d_als )); then + print -n " $_d_als[1]" + shift _d_als + fi + done + print +done >> $_d_file + +print >> $_d_file + +unset _d_line _d_zle _d_bks _d_als _d_f _f_file diff --git a/Functions/Completion/init b/Functions/Completion/init index a40c5f61b..35e7f6a3c 100644 --- a/Functions/Completion/init +++ b/Functions/Completion/init @@ -3,34 +3,22 @@ # directory that will automatically be made autoloaded (see the end of this # file). # The names of the files that will be considered for autoloading have to -# start with two underscores (like `__setopt). +# start with a underscores (like `_setopt). # The first line of these files will be read and has to say what should be # done with its contents: # -# `#function ' +# `#defcomp ' # if the first line looks like this, the file is # autoloaded as a function and that function will # be called to generate the matches when completing # for one of the commands whose is given # -# `#array ' -# with a first line like this, the filename is taken as -# the name of an array; when trying to generate matches -# for the command , the file will be sourced and -# should define this array, the builtin `complist' will -# then be called with the elements of this array as its -# arguments; this is intended for simple definitions -# for which you don't need a shell function -# -# `#pattern-function ' +# `#defpatcomp ' # this defines a function that should be called to generate # matches for commands whose name matches ; note # that only one pattern may be given # -# `#pattern-array ' -# like `#pattern-function' but defining an array -# -# `#key-function