Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tanaka Akira
committed
Aug 23, 1999
1 parent
0066a6a
commit c21b91b
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#autoload | ||
|
||
compset -P '*:' | ||
_files -S: -r ': \t\t\-' -/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#autoload | ||
|
||
# This should be called from `_arguments' or otherwise the calling | ||
# function has to set up an array named `line' that contains the | ||
# name of the executable as its seconf element or it has to supply | ||
# that name as an argument. | ||
# One option is recognized: `-p' means that we are completing a pair | ||
# of names separated by a slash. | ||
|
||
local cmd pair expl | ||
|
||
if [[ "$1" = -p ]]; then | ||
pair=yes | ||
shift | ||
fi | ||
|
||
if (( $# )); then | ||
cmd="$1" | ||
elif [[ $#line -gt 1 ]]; then | ||
cmd="$line[2]" | ||
else | ||
return 1 | ||
fi | ||
|
||
if [[ -n "$cmd" ]]; then | ||
if [[ "$cmd" = /* ]]; then | ||
tmp="$cmd" | ||
else | ||
tmp="$PWD/$cmd" | ||
fi | ||
|
||
if [[ "$tmp" != "$_es_command" ]]; then | ||
_es_command="$tmp" | ||
_es_funcs=( "${(@)${(@M)${(@f)$(nm $cmd)}:#[^ ]# [tT] ([^_]|_[^_])*}##* }" ) | ||
fi | ||
|
||
if [[ -n "$pair" ]]; then | ||
if compset -P '*/'; then | ||
_description expl 'call arc to function' | ||
else | ||
_description expl 'call arc from function' | ||
fi | ||
else | ||
_description expl function | ||
fi | ||
compadd -M 'r:|_=* r:|=*' - "$_es_funcs[@]" | ||
else | ||
return 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#compdef gprof | ||
|
||
_arguments -s -{a,b,c,D,h,i,l,L,s,T,v,w,x,y,z} \ | ||
-{A,C,e,E,f,F,J,n,N,O,p,P,q,Q,Z}:'function name: _exec_funcs' \ | ||
'-I:directory:_dir_list' \ | ||
'-d-:debug level:' '-k:function names: _exec_funcs -p' \ | ||
'-m:minimum execution count:' \ | ||
':executable:_files -g *(*)' \ | ||
':profile file:_files -g gmon.*' \ | ||
-- -s '(#--[no-] --)' \ | ||
'*=name*:function name: _exec_funcs' \ | ||
'*=dirs*:directory:_dir_list' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#autoload | ||
|
||
local expl | ||
|
||
_description expl user | ||
compgen "$@" "$expl[@]" -u |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
For now this is just a list of things one should or shouldn't do. | ||
|
||
1) Use the functions `_files' and `_path_files' instead of `compgen' | ||
with the `-f', `-/', or `-g' options. | ||
2) *Never* use `compgen' with the `-s' option. This can always be done | ||
by a call to `compadd' which is faster. | ||
3) Using `compgen' with the `-k' option should only be done if a) the | ||
array is already existent or b) it is very large (several hundred | ||
or thousend elements). In other cases using `compadd' is faster. | ||
4) Supply match specifications to `compadd' and `compgen' if there are | ||
sensible ones. | ||
5) Use `_description' when adding matches with `compadd' or | ||
`compgen'. Use `_message' in places where no matches can be | ||
generated. If you want to add different types of matches, add them | ||
with multiple calls to `compadd' or `compgen', supplying different | ||
descriptions. | ||
6) Use helper functions that do option completion for you (like | ||
`_arguments' and `_long_options') -- it will make your life much | ||
easier. | ||
7) Use helper functions like `_users' and `_groups' instead of direct | ||
calls to `compgen -u' or some ad hoc mechanisms to generate such | ||
information. This ensures that user can change the way these things | ||
will be completed everywhere by just using their own implementations | ||
for these functions. | ||
8) Make sure that the return value of your functions is correct: zero | ||
if matches where added and non-zero if no matches were found. | ||
In some cases you'll need to test the value of `$compstate[nmatches]' | ||
for this. This should always be done by first saving the old value | ||
(`local nm="$compstate[nmatches]"') and later comparing this with | ||
the current value after all matches have been added (e.g. by | ||
writing `[[ nmm -ne compstate[nmatches] ]]' at the end of your | ||
function). This guarantees that your functions will be re-usable | ||
because calling functions may rely on the correct return value. | ||
9) In places where different behaviors may be useful, add a | ||
configuration key to allow users to select the behavior they | ||
prefer. Names for configuration keys should look like `prefix_name', | ||
where `prefix' is the (probably abbreviated) name of your function | ||
and `name' describes what can be configured. | ||
When testing the values of configuration keys, the empty string | ||
should result in the same behavior as if the key were unset. This | ||
can be achieved by the test `[[ -n "$compconfig[prefix_name]" ]]'. | ||
10) When writing helper functions that generate matches, the arguments | ||
of these should be given unchanged to `compadd' or `compgen' (if | ||
they are not used by the helper function itself). |