diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-10-11 14:49:26 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-10-11 15:19:40 -0700 |
commit | 011c1d1c0766c65517ebd495465c99e86edb63ec (patch) | |
tree | 30d8f6a13235af90897c3223554871ef52225462 /examples | |
parent | 40cfaccf7b178b6239b5cd0013ef80b7ff8e503e (diff) | |
download | vyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.tar.gz vyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.zip |
Update to bash-4.1
Diffstat (limited to 'examples')
51 files changed, 11783 insertions, 1062 deletions
diff --git a/examples/INDEX.html b/examples/INDEX.html new file mode 100644 index 0000000..5e8cdc6 --- /dev/null +++ b/examples/INDEX.html @@ -0,0 +1,824 @@ +<table border=1> + <tr> + <th>Path</th> + <th>Description</th> + <th>X-Ref</th> + </tr> + <tr> + <td>./obashdb</td> + <td>Deprecated sample implementation of a bash debugger</td> + </tr> + <tr> + </tr> + <tr> + <td>./complete</td> + <td>Shell completion code</td> + </tr> + <tr> + </tr> + <tr> + <td>./functions</td> + <td>Example functions</td> + </tr> + <tr> + <td>./functions/array-stuff</td> + <td>Various array functions (ashift, array_sort, reverse).</td> + </tr> + <tr> + <td>./functions/array-to-string</td> + <td>Convert an array to a string.</td> + </tr> + <tr> + <td>./functions/autoload</td> + <td>An almost ksh-compatible 'autoload' (no lazy load).</td> + <td>ksh</td> + </tr> + <tr> + <td>./functions/autoload.v2</td> + <td>An almost ksh-compatible 'autoload' (no lazy load).</td> + <td>ksh</td> + </tr> + <tr> + <td>./functions/autoload.v3</td> + <td>A more ksh-compatible 'autoload' (with lazy load).</td> + <td>ksh</td> + </tr> + <tr> + <td>./functions/basename</td> + <td>A replacement for basename(1).</td> + <td>basename</td> + </tr> + <tr> + <td>./functions/basename2</td> + <td>Fast basename(1) and dirname(1) functions for BASH/SH.</td> + <td>basename, dirname</td> + </tr> + <tr> + <td>./functions/coproc.bash</td> + <td>Start, control, and end coprocesses.</td> + </tr> + <tr> + <td>./functions/coshell.bash</td> + <td>Control shell coprocesses (see coprocess.bash).</td> + </tr> + <tr> + <td>./functions/coshell.README</td> + <td>README for coshell and coproc.</td> + </tr> + <tr> + <td>./functions/csh-compat</td> + <td>A C-shell compatibility package.</td> + <td>csh</td> + </tr> + <tr> + <td>./functions/dirfuncs</td> + <td>Directory manipulation functions from the book 'The Korn Shell'.</td> + </tr> + <tr> + <td>./functions/dirname</td> + <td>A replacement for dirname(1).</td> + <td>dirname</td> + </tr> + <tr> + <td>./functions/emptydir</td> + <td>Find out if a directory is empty.</td> + </tr> + <tr> + <td>./functions/exitstat</td> + <td>Display the exit status of processes.</td> + </tr> + <tr> + <td>./functions/external</td> + <td>Like 'command' but FORCES use of external command.</td> + </tr> + <tr> + <td>./functions/fact</td> + <td>Recursive factorial function.</td> + </tr> + <tr> + <td>./functions/fstty</td> + <td>Front end to sync TERM changes to both stty(1) and readline 'bind'.</td> + <td>stty.bash</td> + </tr> + <tr> + <td>./functions/func</td> + <td>Print out definitions for functions named by arguments.</td> + </tr> + <tr> + <td>./functions/gethtml</td> + <td>Get a web page from a remote server (wget(1) in bash!).</td> + </tr> + <tr> + <td>./functions/getoptx.bash</td> + <td>getopt function that parses long-named options.</td> + </tr> + <tr> + <td>./functions/inetaddr</td> + <td>Internet address conversion (inet2hex & hex2inet).</td> + </tr> + <tr> + <td>./functions/inpath</td> + <td>Return zero if the argument is in the path and executable.</td> + <td>inpath</td> + </tr> + <tr> + <td>./functions/isnum.bash</td> + <td>Test user input on numeric or character value.</td> + </tr> + <tr> + <td>./functions/isnum2</td> + <td>Test user input on numeric values, with floating point.</td> + </tr> + <tr> + <td>./functions/isvalidip</td> + <td>Test user input for valid IP Addresses.</td> + </tr> + <tr> + <td>./functions/jdate.bash</td> + <td>Julian date conversion.</td> + </tr> + <tr> + <td>./functions/jj.bash</td> + <td>Look for running jobs.</td> + </tr> + <tr> + <td>./functions/keep</td> + <td>Try to keep some programs in the forground and running.</td> + </tr> + <tr> + <td>./functions/ksh-cd</td> + <td>ksh-like 'cd': cd [-LP] [dir [change]].</td> + <td>ksh</td> + </tr> + <tr> + <td>./functions/ksh-compat-test</td> + <td>ksh-like arithmetic test replacements.</td> + <td>ksh</td> + </tr> + <tr> + <td>./functions/kshenv</td> + <td>Functions and aliases to provide the beginnings of a ksh environment for bash.</td> + <td>ksh</td> + </tr> + <tr> + <td>./functions/login</td> + <td>Replace the 'login' and 'newgrp' builtins in old Bourne shells.</td> + </tr> + <tr> + <td>./functions/lowercase</td> + <td>Rename files to lower case.</td> + <td>rename lower</td> + </tr> + <tr> + <td>./functions/manpage</td> + <td>Find and print a manual page.</td> + <td>fman</td> + </tr> + <tr> + <td>./functions/mhfold</td> + <td>Print MH folders, useful only because folders(1) doesn't print mod date/times.</td> + </tr> + <tr> + <td>./functions/notify.bash</td> + <td>Notify when jobs change status.</td> + </tr> + <tr> + <td>./functions/pathfuncs</td> + <td>Path related functions (no_path, add_path, pre-path, del_path).</td> + <td>path</td> + </tr> + <tr> + <td>./functions/README</td> + <td>README</td> + </tr> + <tr> + <td>./functions/recurse</td> + <td>Recursive directory traverser.</td> + </tr> + <tr> + <td>./functions/repeat2</td> + <td>A clone of C shell builtin 'repeat'.</td> + <td>repeat, csh</td> + </tr> + <tr> + <td>./functions/repeat3</td> + <td>A clone of C shell builtin 'repeat'.</td> + <td>repeat, csh</td> + </tr> + <tr> + <td>./functions/seq</td> + <td>Generate a sequence from m to n, m defaults to 1.</td> + </tr> + <tr> + <td>./functions/seq2</td> + <td>Generate a sequence from m to n, m defaults to 1.</td> + </tr> + <tr> + <td>./functions/shcat</td> + <td>Readline-based pager.</td> + <td>cat, readline pager</td> + </tr> + <tr> + <td>./functions/shcat2</td> + <td>Readline-based pagers.</td> + <td>cat, readline pager</td> + </tr> + <tr> + <td>./functions/sort-pos-params</td> + <td>Sort the positional parameters.</td> + </tr> + <tr> + <td>./functions/substr</td> + <td>A function to emulate the ancient ksh builtin.</td> + <td>ksh</td> + </tr> + <tr> + <td>./functions/substr2</td> + <td>A function to emulate the ancient ksh builtin.</td> + <td>ksh</td> + </tr> + <tr> + <td>./functions/term</td> + <td>A shell function to set the terminal type interactively or not.</td> + </tr> + <tr> + <td>./functions/whatis</td> + <td>An implementation of the 10th Edition Unix sh builtin 'whatis(1)' command.</td> + </tr> + <tr> + <td>./functions/whence</td> + <td>An almost-ksh compatible 'whence(1)' command.</td> + </tr> + <tr> + <td>./functions/which</td> + <td>An emulation of 'which(1)' as it appears in FreeBSD.</td> + </tr> + <tr> + <td>./functions/xalias.bash</td> + <td>Convert csh alias commands to bash functions.</td> + <td>csh, aliasconv</td> + </tr> + <tr> + <td>./functions/xfind.bash</td> + <td>A 'find(1)' clone.</td> + </tr> + <tr> + </tr> + <tr> + <td>./loadables/</td> + <td>Example loadable replacements</td> + </tr> + <tr> + <td>./loadables/basename.c</td> + <td>Return non-directory portion of pathname.</td> + <td>basename</td> + </tr> + <tr> + <td>./loadables/cat.c</td> + <td>cat(1) replacement with no options - the way cat was intended.</td> + <td>cat, readline pager</td> + </tr> + <tr> + <td>./loadables/cut.c</td> + <td>cut(1) replacement.</td> + </tr> + <tr> + <td>./loadables/dirname.c</td> + <td>Return directory portion of pathname.</td> + <td>dirname</td> + </tr> + <tr> + <td>./loadables/finfo.c</td> + <td>Print file info.</td> + </tr> + <tr> + <td>./loadables/getconf.c</td> + <td>POSIX.2 getconf utility.</td> + </tr> + <tr> + <td>./loadables/getconf.h</td> + <td>Replacement definitions for ones the system doesn't provide.</td> + </tr> + <tr> + <td>./loadables/head.c</td> + <td>Copy first part of files.</td> + </tr> + <tr> + <td>./loadables/hello.c</td> + <td>Obligatory "Hello World" / sample loadable.</td> + </tr> + <tr> + <td>./loadables/id.c</td> + <td>POSIX.2 user identity.</td> + </tr> + <tr> + <td>./loadables/ln.c</td> + <td>Make links.</td> + </tr> + <tr> + <td>./loadables/logname.c</td> + <td>Print login name of current user.</td> + </tr> + <tr> + <td>./loadables/Makefile.in</td> + <td>Simple makefile for the sample loadable builtins.</td> + </tr> + <tr> + <td>./loadables/mkdir.c</td> + <td>Make directories.</td> + </tr> + <tr> + <td>./loadables/necho.c</td> + <td>echo without options or argument interpretation.</td> + </tr> + <tr> + <td>./loadables/pathchk.c</td> + <td>Check pathnames for validity and portability.</td> + </tr> + <tr> + <td>./loadables/print.c</td> + <td>Loadable ksh-93 style print builtin.</td> + </tr> + <tr> + <td>./loadables/printenv.c</td> + <td>Minimal builtin clone of BSD printenv(1).</td> + </tr> + <tr> + <td>./loadables/push.c</td> + <td>Anyone remember TOPS-20?</td> + </tr> + <tr> + <td>./loadables/README</td> + <td>README</td> + </tr> + <tr> + <td>./loadables/realpath.c</td> + <td>Canonicalize pathnames, resolving symlinks.</td> + </tr> + <tr> + <td>./loadables/rmdir.c</td> + <td>Remove directory.</td> + </tr> + <tr> + <td>./loadables/sleep.c</td> + <td>sleep for fractions of a second.</td> + </tr> + <tr> + <td>./loadables/strftime.c</td> + <td>Loadable builtin interface to strftime(3).</td> + </tr> + <tr> + <td>./loadables/sync.c</td> + <td>Sync the disks by forcing pending filesystem writes to complete.</td> + </tr> + <tr> + <td>./loadables/tee.c</td> + <td>Duplicate standard input.</td> + </tr> + <tr> + <td>./loadables/template.c</td> + <td>Example template for loadable builtin.</td> + </tr> + <tr> + <td>./loadables/truefalse.c</td> + <td>True and false builtins.</td> + </tr> + <tr> + <td>./loadables/tty.c</td> + <td>Return terminal name.</td> + </tr> + <tr> + <td>./loadables/uname.c</td> + <td>Print system information.</td> + </tr> + <tr> + <td>./loadables/unlink.c</td> + <td>Remove a directory entry.</td> + </tr> + <tr> + <td>./loadables/whoami.c</td> + <td>Print out username of current user.</td> + </tr> + <tr> + </tr> + <tr> + <td>./loadables/perl/</td> + <td>Illustrate how to build a Perl interpreter into bash.</td> + </tr> + <tr> + </tr> + <tr> + <td>./misc</td> + <td>Miscellaneous</td> + </tr> + <tr> + <td>./misc/aliasconv.bash</td> + <td>Convert csh aliases to bash aliases and functions.</td> + <td>csh, xalias</td> + </tr> + <tr> + <td>./misc/aliasconv.sh</td> + <td>Convert csh aliases to bash aliases and functions.</td> + <td>csh, xalias</td> + </tr> + <tr> + <td>./misc/cshtobash</td> + <td>Convert csh aliases, environment variables, and variables to bash equivalents.</td> + <td>csh, xalias</td> + </tr> + <tr> + <td>./misc/README</td> + <td>README</td> + </tr> + <tr> + <td>./misc/suncmd.termcap</td> + <td>SunView TERMCAP string.</td> + </tr> + <tr> + </tr> + <tr> + <td>./scripts.noah</td> + <td>Noah Friedman's collection of scripts (updated to bash v2 syntax by Chet Ramey)</td> + </tr> + <tr> + <td>./scripts.noah/aref.bash</td> + <td>Pseudo-arrays and substring indexing examples.</td> + </tr> + <tr> + <td>./scripts.noah/bash.sub.bash</td> + <td>Library functions used by require.bash.</td> + </tr> + <tr> + <td>./scripts.noah/bash_version.bash</td> + <td>A function to slice up $BASH_VERSION.</td> + </tr> + <tr> + <td>./scripts.noah/meta.bash</td> + <td>Enable and disable eight-bit readline input.</td> + </tr> + <tr> + <td>./scripts.noah/mktmp.bash</td> + <td>Make a temporary file with a unique name.</td> + </tr> + <tr> + <td>./scripts.noah/number.bash</td> + <td>A fun hack to translate numerals into English.</td> + </tr> + <tr> + <td>./scripts.noah/PERMISSION</td> + <td>Permissions to use the scripts in this directory.</td> + </tr> + <tr> + <td>./scripts.noah/prompt.bash</td> + <td>A way to set PS1 to some predefined strings.</td> + </tr> + <tr> + <td>./scripts.noah/README</td> + <td>README</td> + </tr> + <tr> + <td>./scripts.noah/remap_keys.bash</td> + <td>A front end to 'bind' to redo readline bindings.</td> + </tr> + <tr> + <td>./scripts.noah/require.bash</td> + <td>Lisp-like require/provide library functions for bash.</td> + </tr> + <tr> + <td>./scripts.noah/send_mail.bash</td> + <td>Replacement SMTP client written in bash.</td> + </tr> + <tr> + <td>./scripts.noah/shcat.bash</td> + <td>Bash replacement for 'cat(1)'.</td> + <td>cat</td> + </tr> + <tr> + <td>./scripts.noah/source.bash</td> + <td>Replacement for source that uses current directory.</td> + </tr> + <tr> + <td>./scripts.noah/string.bash</td> + <td>The string(3) functions at the shell level.</td> + </tr> + <tr> + <td>./scripts.noah/stty.bash</td> + <td>Front-end to stty(1) that changes readline bindings too.</td> + <td>fstty</td> + </tr> + <tr> + <td>./scripts.noah/y_or_n_p.bash</td> + <td>Prompt for a yes/no/quit answer.</td> + <td>ask</td> + </tr> + <tr> + </tr> + <tr> + <td>./scripts.v2</td> + <td>John DuBois' ksh script collection (converted to bash v2 syntax by Chet Ramey).</td> + </tr> + <tr> + <td>./scripts.v2/arc2tarz</td> + <td>Convert an "arc" archive to a compressed tar archive.</td> + </tr> + <tr> + <td>./scripts.v2/bashrand</td> + <td>Random number generator with upper and lower bounds and optional seed.</td> + <td>random</td> + </tr> + <tr> + <td>./scripts.v2/cal2day.bash</td> + <td>Convert a day number to a name.</td> + </tr> + <tr> + <td>./scripts.v2/cdhist.bash</td> + <td>cd replacement with a directory stack added.</td> + </tr> + <tr> + <td>./scripts.v2/corename</td> + <td>Tell what produced a core file.</td> + </tr> + <tr> + <td>./scripts.v2/fman</td> + <td>Fast man(1) replacement.</td> + <td>manpage</td> + </tr> + <tr> + <td>./scripts.v2/frcp</td> + <td>Copy files using ftp(1) but with rcp-type command line syntax.</td> + </tr> + <tr> + <td>./scripts.v2/lowercase</td> + <td>Change filenames to lower case.</td> + <td>rename lower</td> + </tr> + <tr> + <td>./scripts.v2/ncp</td> + <td>A nicer front end for cp(1) (has -i, etc.).</td> + </tr> + <tr> + <td>./scripts.v2/newext</td> + <td>Change the extension of a group of files.</td> + <td>rename</td> + </tr> + <tr> + <td>./scripts.v2/nmv</td> + <td>A nicer front end for mv(1) (has -i, etc.).</td> + <td>rename</td> + </tr> + <tr> + <td>./scripts.v2/pages</td> + <td>Print specified pages from files.</td> + </tr> + <tr> + <td>./scripts.v2/PERMISSION</td> + <td>Permissions to use the scripts in this directory.</td> + </tr> + <tr> + <td>./scripts.v2/pf</td> + <td>A pager front end that handles compressed files.</td> + </tr> + <tr> + <td>./scripts.v2/pmtop</td> + <td>Poor man's 'top(1)' for SunOS 4.x and BSD/OS.</td> + </tr> + <tr> + <td>./scripts.v2/README</td> + <td>README</td> + </tr> + <tr> + <td>./scripts.v2/ren</td> + <td>Rename files by changing parts of filenames that match a pattern.</td> + <td>rename</td> + </tr> + <tr> + <td>./scripts.v2/rename</td> + <td>Change the names of files that match a pattern.</td> + <td>rename</td> + </tr> + <tr> + <td>./scripts.v2/repeat</td> + <td>Execute a command multiple times.</td> + <td>repeat</td> + </tr> + <tr> + <td>./scripts.v2/shprof</td> + <td>Line profiler for bash scripts.</td> + </tr> + <tr> + <td>./scripts.v2/untar</td> + <td>Unarchive a (possibly compressed) tarfile into a directory.</td> + </tr> + <tr> + <td>./scripts.v2/uudec</td> + <td>Carefully uudecode(1) multiple files.</td> + </tr> + <tr> + <td>./scripts.v2/uuenc</td> + <td>uuencode(1) multiple files.</td> + </tr> + <tr> + <td>./scripts.v2/vtree</td> + <td>Print a visual display of a directory tree.</td> + <td>tree</td> + </tr> + <tr> + <td>./scripts.v2/where</td> + <td>Show where commands that match a pattern are.</td> + </tr> + <tr> + </tr> + <tr> + <td>./scripts</td> + <td>Example scripts</td> + </tr> + <tr> + <td>./scripts/adventure.sh</td> + <td>Text adventure game in bash!</td> + </tr> + <tr> + <td>./scripts/bcsh.sh</td> + <td>Bourne shell cshell-emulator.</td> + <td>csh</td> + </tr> + <tr> + <td>./scripts/cat.sh</td> + <td>Readline-based pager.</td> + <td>cat, readline pager</td> + </tr> + <tr> + <td>./scripts/center</td> + <td>Center - center a group of lines.</td> + </tr> + <tr> + <td>./scripts/dd-ex.sh</td> + <td>Line editor using only /bin/sh, /bin/dd and /bin/rm.</td> + </tr> + <tr> + <td>./scripts/fixfiles.bash</td> + <td>Recurse a tree and fix files containing various "bad" chars.</td> + </tr> + <tr> + <td>./scripts/hanoi.bash</td> + <td>The inevitable Towers of Hanoi in bash.</td> + </tr> + <tr> + <td>./scripts/inpath</td> + <td>Search $PATH for a file the same name as $1; return TRUE if found.</td> + <td>inpath</td> + </tr> + <tr> + <td>./scripts/krand.bash</td> + <td>Produces a random number within integer limits.</td> + <td>random</td> + </tr> + <tr> + <td>./scripts/line-input.bash</td> + <td>Line input routine for GNU Bourne-Again Shell plus terminal-control primitives.</td> + </tr> + <tr> + <td>./scripts/nohup.bash</td> + <td>bash version of 'nohup' command.</td> + </tr> + <tr> + <td>./scripts/precedence</td> + <td>Test relative precedences for '&&' and '||' operators.</td> + </tr> + <tr> + <td>./scripts/randomcard.bash</td> + <td>Print a random card from a card deck.</td> + <td>random</td> + </tr> + <tr> + <td>./scripts/README</td> + <td>README</td> + </tr> + <tr> + <td>./scripts/scrollbar</td> + <td>Display scrolling text.</td> + </tr> + <tr> + <td>./scripts/scrollbar2</td> + <td>Display scrolling text.</td> + </tr> + <tr> + <td>./scripts/self-repro</td> + <td>A self-reproducing script (careful!)</td> + </tr> + <tr> + <td>./scripts/showperm.bash</td> + <td>Convert ls(1) symbolic permissions into octal mode.</td> + </tr> + <tr> + <td>./scripts/shprompt</td> + <td>Display a prompt and get an answer satisfying certain criteria.</td> + <td>ask</td> + </tr> + <tr> + <td>./scripts/spin.bash</td> + <td>Display a 'spinning wheel' to show progress.</td> + </tr> + <tr> + <td>./scripts/timeout</td> + <td>Give rsh(1) a shorter timeout.</td> + </tr> + <tr> + <td>./scripts/timeout2</td> + <td>Execute a given command with a timeout.</td> + </tr> + <tr> + <td>./scripts/timeout3</td> + <td>Execute a given command with a timeout.</td> + </tr> + <tr> + <td>./scripts/vtree2</td> + <td>Display a tree printout of dir in 1k blocks.</td> + <td>tree</td> + </tr> + <tr> + <td>./scripts/vtree3</td> + <td>Display a graphical tree printout of dir.</td> + <td>tree</td> + </tr> + <tr> + <td>./scripts/vtree3a</td> + <td>Display a graphical tree printout of dir.</td> + <td>tree</td> + </tr> + <tr> + <td>./scripts/websrv.sh</td> + <td>A web server in bash!</td> + </tr> + <tr> + <td>./scripts/xterm_title</td> + <td>Print the contents of the xterm title bar.</td> + </tr> + <tr> + <td>./scripts/zprintf</td> + <td>Emulate printf (obsolete since it's now a bash builtin).</td> + </tr> + <tr> + </tr> + <tr> + <td>./startup-files</td> + <td>Example Start-up files.</td> + </tr> + <tr> + <td>./startup-files/Bash_aliases</td> + <td>Some useful aliases (Fox).</td> + </tr> + <tr> + <td>./startup-files/Bash_profile</td> + <td>Sample startup file for bash login shells (Fox).</td> + </tr> + <tr> + <td>./startup-files/bash-profile</td> + <td>Sample startup file for bash login shells (Ramey).</td> + </tr> + <tr> + <td>./startup-files/bashrc</td> + <td>Sample Bourne Again SHell init file (Ramey).</td> + </tr> + <tr> + <td>./startup-files/Bashrc.bfox</td> + <td>Sample Bourne Again SHell init file (Fox).</td> + </tr> + <tr> + <td>./startup-files/README</td> + <td>README</td> + </tr> + <tr> + </tr> + <tr> + <td>./startup-files/apple</td> + <td>Example Start-up files for Mac OS X.</td> + </tr> + <tr> + <td>./startup-files/apple/aliases</td> + <td>Sample aliases for Mac OS X.</td> + </tr> + <tr> + <td>./startup-files/apple/bash.defaults</td> + <td>Sample User preferences file.</td> + </tr> + <tr> + <td>./startup-files/apple/environment</td> + <td>Sample Bourne Again Shell environment file.</td> + </tr> + <tr> + <td>./startup-files/apple/login</td> + <td>Sample login wrapper.</td> + </tr> + <tr> + <td>./startup-files/apple/logout</td> + <td>Sample logout wrapper.</td> + </tr> + <tr> + <td>./startup-files/apple/rc</td> + <td>Sample Bourne Again Shell config file.</td> + </tr> + <tr> + <td>./startup-files/apple/README</td> + <td>README</td> + </tr> +</table> diff --git a/examples/INDEX.txt b/examples/INDEX.txt new file mode 100644 index 0000000..db2858f --- /dev/null +++ b/examples/INDEX.txt @@ -0,0 +1,198 @@ +Path Description X-Ref +./obashdb Deprecated sample implementation of a bash debugger + +./complete Shell completion code + +./functions Example functions +./functions/array-stuff Various array functions (ashift, array_sort, reverse). +./functions/array-to-string Convert an array to a string. +./functions/autoload An almost ksh-compatible 'autoload' (no lazy load). ksh +./functions/autoload.v2 An almost ksh-compatible 'autoload' (no lazy load). ksh +./functions/autoload.v3 A more ksh-compatible 'autoload' (with lazy load). ksh +./functions/basename A replacement for basename(1). basename +./functions/basename2 Fast basename(1) and dirname(1) functions for BASH/SH. basename, dirname +./functions/coproc.bash Start, control, and end coprocesses. +./functions/coshell.bash Control shell coprocesses (see coprocess.bash). +./functions/coshell.README README for coshell and coproc. +./functions/csh-compat A C-shell compatibility package. csh +./functions/dirfuncs Directory manipulation functions from the book 'The Korn Shell'. +./functions/dirname A replacement for dirname(1). dirname +./functions/emptydir Find out if a directory is empty. +./functions/exitstat Display the exit status of processes. +./functions/external Like 'command' but FORCES use of external command. +./functions/fact Recursive factorial function. +./functions/fstty Front end to sync TERM changes to both stty(1) and readline 'bind'. stty.bash +./functions/func Print out definitions for functions named by arguments. +./functions/gethtml Get a web page from a remote server (wget(1) in bash!). +./functions/getoptx.bash getopt function that parses long-named options. +./functions/inetaddr Internet address conversion (inet2hex & hex2inet). +./functions/inpath Return zero if the argument is in the path and executable. inpath +./functions/isnum.bash Test user input on numeric or character value. +./functions/isnum2 Test user input on numeric values, with floating point. +./functions/isvalidip Test user input for valid IP Addresses. +./functions/jdate.bash Julian date conversion. +./functions/jj.bash Look for running jobs. +./functions/keep Try to keep some programs in the forground and running. +./functions/ksh-cd ksh-like 'cd': cd [-LP] [dir [change]]. ksh +./functions/ksh-compat-test ksh-like arithmetic test replacements. ksh +./functions/kshenv Functions and aliases to provide the beginnings of a ksh environment for bash. ksh +./functions/login Replace the 'login' and 'newgrp' builtins in old Bourne shells. +./functions/lowercase Rename files to lower case. rename lower +./functions/manpage Find and print a manual page. fman +./functions/mhfold Print MH folders, useful only because folders(1) doesn't print mod date/times. +./functions/notify.bash Notify when jobs change status. +./functions/pathfuncs Path related functions (no_path, add_path, pre-path, del_path). path +./functions/README README +./functions/recurse Recursive directory traverser. +./functions/repeat2 A clone of C shell builtin 'repeat'. repeat, csh +./functions/repeat3 A clone of C shell builtin 'repeat'. repeat, csh +./functions/seq Generate a sequence from m to n, m defaults to 1. +./functions/seq2 Generate a sequence from m to n, m defaults to 1. +./functions/shcat Readline-based pager. cat, readline pager +./functions/shcat2 Readline-based pagers. cat, readline pager +./functions/sort-pos-params Sort the positional parameters. +./functions/substr A function to emulate the ancient ksh builtin. ksh +./functions/substr2 A function to emulate the ancient ksh builtin. ksh +./functions/term A shell function to set the terminal type interactively or not. +./functions/whatis An implementation of the 10th Edition Unix sh builtin 'whatis(1)' command. +./functions/whence An almost-ksh compatible 'whence(1)' command. +./functions/which An emulation of 'which(1)' as it appears in FreeBSD. +./functions/xalias.bash Convert csh alias commands to bash functions. csh, aliasconv +./functions/xfind.bash A 'find(1)' clone. + +./loadables/ Example loadable replacements +./loadables/basename.c Return non-directory portion of pathname. basename +./loadables/cat.c cat(1) replacement with no options - the way cat was intended. cat, readline pager +./loadables/cut.c cut(1) replacement. +./loadables/dirname.c Return directory portion of pathname. dirname +./loadables/finfo.c Print file info. +./loadables/getconf.c POSIX.2 getconf utility. +./loadables/getconf.h Replacement definitions for ones the system doesn't provide. +./loadables/head.c Copy first part of files. +./loadables/hello.c Obligatory "Hello World" / sample loadable. +./loadables/id.c POSIX.2 user identity. +./loadables/ln.c Make links. +./loadables/logname.c Print login name of current user. +./loadables/Makefile.in Simple makefile for the sample loadable builtins. +./loadables/mkdir.c Make directories. +./loadables/necho.c echo without options or argument interpretation. +./loadables/pathchk.c Check pathnames for validity and portability. +./loadables/print.c Loadable ksh-93 style print builtin. +./loadables/printenv.c Minimal builtin clone of BSD printenv(1). +./loadables/push.c Anyone remember TOPS-20? +./loadables/README README +./loadables/realpath.c Canonicalize pathnames, resolving symlinks. +./loadables/rmdir.c Remove directory. +./loadables/sleep.c sleep for fractions of a second. +./loadables/strftime.c Loadable builtin interface to strftime(3). +./loadables/sync.c Sync the disks by forcing pending filesystem writes to complete. +./loadables/tee.c Duplicate standard input. +./loadables/template.c Example template for loadable builtin. +./loadables/truefalse.c True and false builtins. +./loadables/tty.c Return terminal name. +./loadables/uname.c Print system information. +./loadables/unlink.c Remove a directory entry. +./loadables/whoami.c Print out username of current user. + +./loadables/perl/ Illustrate how to build a Perl interpreter into bash. + +./misc Miscellaneous +./misc/aliasconv.bash Convert csh aliases to bash aliases and functions. csh, xalias +./misc/aliasconv.sh Convert csh aliases to bash aliases and functions. csh, xalias +./misc/cshtobash Convert csh aliases, environment variables, and variables to bash equivalents. csh, xalias +./misc/README README +./misc/suncmd.termcap SunView TERMCAP string. + +./scripts.noah Noah Friedman's collection of scripts (updated to bash v2 syntax by Chet Ramey) +./scripts.noah/aref.bash Pseudo-arrays and substring indexing examples. +./scripts.noah/bash.sub.bash Library functions used by require.bash. +./scripts.noah/bash_version.bash A function to slice up $BASH_VERSION. +./scripts.noah/meta.bash Enable and disable eight-bit readline input. +./scripts.noah/mktmp.bash Make a temporary file with a unique name. +./scripts.noah/number.bash A fun hack to translate numerals into English. +./scripts.noah/PERMISSION Permissions to use the scripts in this directory. +./scripts.noah/prompt.bash A way to set PS1 to some predefined strings. +./scripts.noah/README README +./scripts.noah/remap_keys.bash A front end to 'bind' to redo readline bindings. +./scripts.noah/require.bash Lisp-like require/provide library functions for bash. +./scripts.noah/send_mail.bash Replacement SMTP client written in bash. +./scripts.noah/shcat.bash Bash replacement for 'cat(1)'. cat +./scripts.noah/source.bash Replacement for source that uses current directory. +./scripts.noah/string.bash The string(3) functions at the shell level. +./scripts.noah/stty.bash Front-end to stty(1) that changes readline bindings too. fstty +./scripts.noah/y_or_n_p.bash Prompt for a yes/no/quit answer. ask + +./scripts.v2 John DuBois' ksh script collection (converted to bash v2 syntax by Chet Ramey). +./scripts.v2/arc2tarz Convert an "arc" archive to a compressed tar archive. +./scripts.v2/bashrand Random number generator with upper and lower bounds and optional seed. random +./scripts.v2/cal2day.bash Convert a day number to a name. +./scripts.v2/cdhist.bash cd replacement with a directory stack added. +./scripts.v2/corename Tell what produced a core file. +./scripts.v2/fman Fast man(1) replacement. manpage +./scripts.v2/frcp Copy files using ftp(1) but with rcp-type command line syntax. +./scripts.v2/lowercase Change filenames to lower case. rename lower +./scripts.v2/ncp A nicer front end for cp(1) (has -i, etc.). +./scripts.v2/newext Change the extension of a group of files. rename +./scripts.v2/nmv A nicer front end for mv(1) (has -i, etc.). rename +./scripts.v2/pages Print specified pages from files. +./scripts.v2/PERMISSION Permissions to use the scripts in this directory. +./scripts.v2/pf A pager front end that handles compressed files. +./scripts.v2/pmtop Poor man's 'top(1)' for SunOS 4.x and BSD/OS. +./scripts.v2/README README +./scripts.v2/ren Rename files by changing parts of filenames that match a pattern. rename +./scripts.v2/rename Change the names of files that match a pattern. rename +./scripts.v2/repeat Execute a command multiple times. repeat +./scripts.v2/shprof Line profiler for bash scripts. +./scripts.v2/untar Unarchive a (possibly compressed) tarfile into a directory. +./scripts.v2/uudec Carefully uudecode(1) multiple files. +./scripts.v2/uuenc uuencode(1) multiple files. +./scripts.v2/vtree Print a visual display of a directory tree. tree +./scripts.v2/where Show where commands that match a pattern are. + +./scripts Example scripts +./scripts/adventure.sh Text adventure game in bash! +./scripts/bcsh.sh Bourne shell cshell-emulator. csh +./scripts/cat.sh Readline-based pager. cat, readline pager +./scripts/center Center - center a group of lines. +./scripts/dd-ex.sh Line editor using only /bin/sh, /bin/dd and /bin/rm. +./scripts/fixfiles.bash Recurse a tree and fix files containing various "bad" chars. +./scripts/hanoi.bash The inevitable Towers of Hanoi in bash. +./scripts/inpath Search $PATH for a file the same name as $1; return TRUE if found. inpath +./scripts/krand.bash Produces a random number within integer limits. random +./scripts/line-input.bash Line input routine for GNU Bourne-Again Shell plus terminal-control primitives. +./scripts/nohup.bash bash version of 'nohup' command. +./scripts/precedence Test relative precedences for '&&' and '||' operators. +./scripts/randomcard.bash Print a random card from a card deck. random +./scripts/README README +./scripts/scrollbar Display scrolling text. +./scripts/scrollbar2 Display scrolling text. +./scripts/self-repro A self-reproducing script (careful!) +./scripts/showperm.bash Convert ls(1) symbolic permissions into octal mode. +./scripts/shprompt Display a prompt and get an answer satisfying certain criteria. ask +./scripts/spin.bash Display a 'spinning wheel' to show progress. +./scripts/timeout Give rsh(1) a shorter timeout. +./scripts/timeout2 Execute a given command with a timeout. +./scripts/timeout3 Execute a given command with a timeout. +./scripts/vtree2 Display a tree printout of dir in 1k blocks. tree +./scripts/vtree3 Display a graphical tree printout of dir. tree +./scripts/vtree3a Display a graphical tree printout of dir. tree +./scripts/websrv.sh A web server in bash! +./scripts/xterm_title Print the contents of the xterm title bar. +./scripts/zprintf Emulate printf (obsolete since it's now a bash builtin). + +./startup-files Example Start-up files. +./startup-files/Bash_aliases Some useful aliases (Fox). +./startup-files/Bash_profile Sample startup file for bash login shells (Fox). +./startup-files/bash-profile Sample startup file for bash login shells (Ramey). +./startup-files/bashrc Sample Bourne Again SHell init file (Ramey). +./startup-files/Bashrc.bfox Sample Bourne Again SHell init file (Fox). +./startup-files/README README + +./startup-files/apple Example Start-up files for Mac OS X. +./startup-files/apple/aliases Sample aliases for Mac OS X. +./startup-files/apple/bash.defaults Sample User preferences file. +./startup-files/apple/environment Sample Bourne Again Shell environment file. +./startup-files/apple/login Sample login wrapper. +./startup-files/apple/logout Sample logout wrapper. +./startup-files/apple/rc Sample Bourne Again Shell config file. +./startup-files/apple/README README diff --git a/examples/bashdb/PERMISSION b/examples/bashdb/PERMISSION deleted file mode 100644 index 4e9460c..0000000 --- a/examples/bashdb/PERMISSION +++ /dev/null @@ -1,27 +0,0 @@ -From mikel@ora.com Tue Aug 1 12:13:20 1995 -Flags: 10 -Return-Path: mikel@ora.com -Received: from ruby.ora.com (ruby.ora.com [198.112.208.25]) by odin.INS.CWRU.Edu with ESMTP (8.6.12+cwru/CWRU-2.1-ins) - id MAA01565; Tue, 1 Aug 1995 12:13:18 -0400 (from mikel@ora.com for <chet@odin.INS.CWRU.Edu>) -Received: (from fax@localhost) by ruby.ora.com (8.6.12/8.6.11) with UUCP id MAA23251; Tue, 1 Aug 1995 12:07:51 -0400 -Received: by los.ora.com (4.1/Spike-2.1) - id AA00672; Tue, 1 Aug 95 08:57:32 EDT -Date: Tue, 1 Aug 95 08:57:32 EDT -From: mikel@ora.com (Michael Loukides) -Message-Id: <9508011257.AA00672@los.ora.com> -Subject: Re: Ksh debugger from Rosenblatt's book [for bash] -To: Chet Ramey <chet@odin.INS.CWRU.Edu> -Cc: cmarie@ora.com, cam@iinet.com.au, brosenblatt@tm.com -In-Reply-To: Chet Ramey <chet@odin.INS.CWRU.Edu>, Mon, 31 Jul 1995 16:22:48 -0400 - - I've modified a (modified) version of Bill Rosenblatt's ksh debugger - to work with bash-2.0. Does ORA have any problem with me distributing - it with bash-2.0? - -That's great! - -Go ahead and circulate it; in fact, we should probably grab it and -stick it in our ftp archive, and put a reference to it in the book. -(Too late to actually discuss the thing, at least for this edition). -------- - diff --git a/examples/bashdb/README b/examples/bashdb/README deleted file mode 100644 index 2f643d1..0000000 --- a/examples/bashdb/README +++ /dev/null @@ -1,3 +0,0 @@ -This is a sample implementation of a bash debugger. It is not the same -as the project available from http://bashdb.sourceforge.net, and has been -deprecated in favor of that implementation. diff --git a/examples/bashdb/bashdb b/examples/bashdb/bashdb deleted file mode 100755 index 560cb7c..0000000 --- a/examples/bashdb/bashdb +++ /dev/null @@ -1,581 +0,0 @@ -#! /bin/bash -# bashdb - Bash shell debugger -# -# Adapted from an idea in O'Reilly's `Learning the Korn Shell' -# Copyright (C) 1993-1994 O'Reilly and Associates, Inc. -# Copyright (C) 1998, 1999, 2001 Gary V. Vaughan <gvv@techie.com>> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -# NOTE: -# -# This program requires bash 2.x. -# If bash 2.x is installed as "bash2", you can invoke bashdb like this: -# -# DEBUG_SHELL=/bin/bash2 /bin/bash2 bashdb script.sh - -# TODO: -# -# break [regexp] -# cond [break] [condition] -# tbreak [regexp|+lines] -# restart -# Variable watchpoints -# Instrument `source' and `.' files in $_potbelliedpig -# be cleverer about lines we allow breakpoints to be set on -# break [function_name] - -echo 'Bash Debugger version 1.2.4' - -export _dbname=${0##*/} - -if test $# -lt 1; then - echo "$_dbname: Usage: $_dbname filename" >&2 - exit 1 -fi - -_guineapig=$1 - -if test ! -r $1; then - echo "$_dbname: Cannot read file '$_guineapig'." >&2 - exit 1 -fi - -shift - -__debug=${TMPDIR-/tmp}/bashdb.$$ -sed -e '/^# bashdb - Bash shell debugger/,/^# -- DO NOT DELETE THIS LINE -- /d' "$0" > $__debug -cat $_guineapig >> $__debug -exec ${DEBUG_SHELL-bash} $__debug $_guineapig "$@" - -exit 1 - -# -- DO NOT DELETE THIS LINE -- The program depends on it - -#bashdb preamble -# $1 name of the original guinea pig script - -__debug=$0 -_guineapig=$1 -__steptrap_calls=0 - -shift - -shopt -s extglob # turn on extglob so we can parse the debugger funcs - -function _steptrap -{ - local i=0 - - _curline=$1 - - if (( ++__steptrap_calls > 1 && $_curline == 1 )); then - return - fi - - if [ -n "$_disps" ]; then - while (( $i < ${#_disps[@]} )) - do - if [ -n "${_disps[$i]}" ]; then - _msg "${_disps[$i]}: \c" - eval _msg ${_disps[$i]} - fi - let i=$i+1 - done - fi - - if (( $_trace )); then - _showline $_curline - fi - - if (( $_steps >= 0 )); then - let _steps="$_steps - 1" - fi - - if _at_linenumbp ; then - _msg "Reached breakpoint at line $_curline" - _showline $_curline - _cmdloop - elif [ -n "$_brcond" ] && eval $_brcond; then - _msg "Break condition $_brcond true at line $_curline" - _showline $_curline - _cmdloop - elif (( $_steps == 0 )); then - # Assuming a real script will have the "#! /bin/sh" at line 1, - # assume that when $_curline == 1 we are inside backticks. - if (( ! $_trace )); then - _msg "Stopped at line $_curline" - _showline $_curline - fi - _cmdloop - fi -} - -function _setbp -{ - local i f line _x - - if [ -z "$1" ]; then - _listbp - return - fi - - eval "$_seteglob" - - if [[ $1 == *(\+)[1-9]*([0-9]) ]]; then - case $1 in - +*) - # normalize argument, then double it (+2 -> +2 + 2 = 4) - _x=${1##*([!1-9])} # cut off non-numeric prefix - _x=${x%%*([!0-9])} # cut off non-numeric suffix - f=$(( $1 + $_x )) - ;; - *) - f=$(( $1 )) - ;; - esac - - # find the next valid line - line="${_lines[$f]}" - while _invalidbreakp $f - do - (( f++ )) - line="${_lines[$f]}" - done - - if (( $f != $1 )) - then - _msg "Line $1 is not a valid breakpoint" - fi - - if [ -n "${_lines[$f]}" ]; then - _linebp[$1]=$1; - _msg "Breakpoint set at line $f" - else - _msg "Breakpoints can only be set on executable lines" - fi - else - _msg "Please specify a numeric line number" - fi - - eval "$_resteglob" -} - -function _listbp -{ - local i - - if [ -n "$_linebp" ]; then - _msg "Breakpoints:" - for i in ${_linebp[*]}; do - _showline $i - done - else - _msg "No breakpoints have been set" - fi -} - -function _clearbp -{ - local i - - if [ -z "$1" ]; then - read -e -p "Delete all breakpoints? " - case $REPLY in - [yY]*) - unset _linebp[*] - _msg "All breakpoints have been cleared" - ;; - esac - return 0 - fi - - eval "$_seteglob" - - if [[ $1 == [1-9]*([0-9]) ]]; then - unset _linebp[$1] - _msg "Breakpoint cleared at line $1" - else - _msg "Please specify a numeric line number" - fi - - eval "$_resteglob" -} - -function _setbc -{ - if (( $# > 0 )); then - _brcond=$@ - _msg "Break when true: $_brcond" - else - _brcond= - _msg "Break condition cleared" - fi -} - -function _setdisp -{ - if [ -z "$1" ]; then - _listdisp - else - _disps[${#_disps[@]}]="$1" - if (( ${#_disps[@]} < 10 )) - then - _msg " ${#_disps[@]}: $1" - else - _msg "${#_disps[@]}: $1" - fi - fi -} - -function _listdisp -{ - local i=0 j - - if [ -n "$_disps" ]; then - while (( $i < ${#_disps[@]} )) - do - let j=$i+1 - if (( ${#_disps[@]} < 10 )) - then - _msg " $j: ${_disps[$i]}" - else - _msg "$j: ${_disps[$i]}" - fi - let i=$j - done - else - _msg "No displays have been set" - fi -} - -function _cleardisp -{ - if (( $# < 1 )) ; then - read -e -p "Delete all display expressions? " - case $REPLY in - [Yy]*) - unset _disps[*] - _msg "All breakpoints have been cleared" - ;; - esac - return 0 - fi - - eval "$_seteglob" - - if [[ $1 == [1-9]*([0-9]) ]]; then - unset _disps[$1] - _msg "Display $i has been cleared" - else - _listdisp - _msg "Please specify a numeric display number" - fi - - eval "$_resteglob" -} - -# usage _ftrace -u funcname [funcname...] -function _ftrace -{ - local _opt=-t _tmsg="enabled" _func - if [[ $1 == -u ]]; then - _opt=+t - _tmsg="disabled" - shift - fi - for _func; do - declare -f $_opt $_func - _msg "Tracing $_tmsg for function $_func" - done -} - -function _cmdloop -{ - local cmd args - - while read -e -p "bashdb> " cmd args; do - test -n "$cmd" && history -s "$cmd $args" # save on history list - test -n "$cmd" || { set $_lastcmd; cmd=$1; shift; args=$*; } - if [ -n "$cmd" ] - then - case $cmd in - b|br|bre|brea|break) - _setbp $args - _lastcmd="break $args" - ;; - co|con) - _msg "ambiguous command: '$cmd', condition, continue?" - ;; - cond|condi|condit|conditi|conditio|condition) - _setbc $args - _lastcmd="condition $args" - ;; - c|cont|conti|contin|continu|continue) - _lastcmd="continue" - return - ;; - d) - _msg "ambiguous command: '$cmd', delete, display?" - ;; - de|del|dele|delet|delete) - _clearbp $args - _lastcmd="delete $args" - ;; - di|dis|disp|displ|displa|display) - _setdisp $args - _lastcmd="display $args" - ;; - f|ft|ftr|ftra|ftrace) - _ftrace $args - _lastcmd="ftrace $args" - ;; - \?|h|he|hel|help) - _menu - _lastcmd="help" - ;; - l|li|lis|list) - _displayscript $args - # _lastcmd is set in the _displayscript function - ;; - p|pr|pri|prin|print) - _examine $args - _lastcmd="print $args" - ;; - q|qu|qui|quit) - exit - ;; - s|st|ste|step|n|ne|nex|next) - let _steps=${args:-1} - _lastcmd="next $args" - return - ;; - t|tr|tra|trac|trace) - _xtrace - ;; - u|un|und|undi|undis|undisp|undispl|undispla|undisplay) - _cleardisp $args - _lastcmd="undisplay $args" - ;; - !*) - eval ${cmd#!} $args - _lastcmd="$cmd $args" - ;; - *) - _msg "Invalid command: '$cmd'" - ;; - esac - fi - done -} - -function _at_linenumbp -{ - [[ -n ${_linebp[$_curline]} ]] -} - -function _invalidbreakp -{ - local line=${_lines[$1]} - - # XXX - should use shell patterns - if test -z "$line" \ - || expr "$line" : '[ \t]*#.*' > /dev/null \ - || expr "$line" : '[ \t]*;;[ \t]*$' > /dev/null \ - || expr "$line" : '[ \t]*[^)]*)[ \t]*$' > /dev/null \ - || expr "$line" : '[ \t]*;;[ \t]*#.**$' > /dev/null \ - || expr "$line" : '[ \t]*[^)]*)[ \t]*;;[ \t]*$' > /dev/null \ - || expr "$line" : '[ \t]*[^)]*)[ \t]*;;*[ \t]*#.*$' > /dev/null - then - return 0 - fi - - return 1 -} - -function _examine -{ - if [ -n "$*" ]; then - _msg "$args: \c" - eval _msg $args - else - _msg "Nothing to print" - fi -} - -function _displayscript -{ - local i j start end bp cl - - if (( $# == 1 )); then # list 5 lines on either side of $1 - if [ $1 = "%" ]; then - let start=1 - let end=${#_lines[@]} - else - let start=$1-5 - let end=$1+5 - fi - elif (( $# > 1 )); then # list between start and end - if [ $1 = "^" ]; then - let start=1 - else - let start=$1 - fi - - if [ $2 = "\$" ]; then - let end=${#_lines[@]} - else - let end=$2 - fi - else # list 5 lines on either side of current line - let start=$_curline-5 - let end=$_curline+5 - fi - - # normalize start and end - if (( $start < 1 )); then - start=1 - fi - if (( $end > ${#_lines[@]} )); then - end=${#_lines[@]} - fi - - cl=$(( $end - $start )) - if (( $cl > ${LINES-24} )); then - pager=${PAGER-more} - else - pager=cat - fi - - i=$start - ( while (( $i <= $end )); do - _showline $i - let i=$i+1 - done ) 2>&1 | $pager - - # calculate the next block of lines - start=$(( $end + 1 )) - end=$(( $start + 11 )) - if (( $end > ${#_lines[@]} )) - then - end=${#_lines[@]} - fi - - _lastcmd="list $start $end" -} - -function _xtrace -{ - let _trace="! $_trace" - if (( $_trace )); then - _msg "Execution trace on" - else - _msg "Execution trace off" - fi -} - -function _msg -{ - echo -e "$@" >&2 -} - -function _showline -{ - local i=0 bp=' ' line=$1 cl=' ' - - if [[ -n ${_linebp[$line]} ]]; then - bp='*' - fi - - if (( $_curline == $line )); then - cl=">" - fi - - if (( $line < 100 )); then - _msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}" - elif (( $line < 10 )); then - _msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}" - elif (( $line > 0 )); then - _msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}" - fi -} - -function _cleanup -{ - rm -f $__debug $_potbelliedpig 2> /dev/null -} - -function _menu -{ - _msg 'bashdb commands: - break N set breakpoint at line N - break list breakpoints & break condition - condition foo set break condition to foo - condition clear break condition - delete N clear breakpoint at line N - delete clear all breakpoints - display EXP evaluate and display EXP for each debug step - display show a list of display expressions - undisplay N remove display expression N - list N M display all lines of script between N and M - list N display 5 lines of script either side of line N - list display 5 lines if script either side of current line - continue continue execution upto next breakpoint - next [N] execute [N] statements (default 1) - print expr prints the value of an expression - trace toggle execution trace on/off - ftrace [-u] func make the debugger step into function FUNC - (-u turns off tracing FUNC) - help print this menu - ! string passes string to a shell - quit quit' -} - -shopt -u extglob - -HISTFILE=~/.bashdb_history -set -o history -set +H - -# strings to save and restore the setting of `extglob' in debugger functions -# that need it -_seteglob='local __eopt=-u ; shopt -q extglob && __eopt=-s ; shopt -s extglob' -_resteglob='shopt $__eopt extglob' - -_linebp=() -let _trace=0 -let _i=1 - -# Be careful about quoted newlines -_potbelliedpig=${TMPDIR-/tmp}/${_guineapig/*\//}.$$ -sed 's,\\$,\\\\,' $_guineapig > $_potbelliedpig - -_msg "Reading source from file: $_guineapig" -while read; do - _lines[$_i]=$REPLY - let _i=$_i+1 -done < $_potbelliedpig - -trap _cleanup EXIT -# Assuming a real script will have the "#! /bin/sh" at line 1, -# don't stop at line 1 on the first run -let _steps=1 -LINENO=-1 -trap '_steptrap $LINENO' DEBUG diff --git a/examples/complete/bash_completion b/examples/complete/bash_completion new file mode 100644 index 0000000..b0cf4a8 --- /dev/null +++ b/examples/complete/bash_completion @@ -0,0 +1,9401 @@ +# bash_completion - programmable completion functions for bash 3.x +# (backwards compatible with bash 2.05b) +# +# $Id: bash_completion,v 1.872 2006/03/01 16:20:18 ianmacd Exp $ +# +# Copyright (C) Ian Macdonald <ian@caliban.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The latest version of this software can be obtained here: +# +# http://www.caliban.org/bash/index.shtml#completion +# +# RELEASE: 20060301 + +if [[ $- == *v* ]]; then + BASH_COMPLETION_ORIGINAL_V_VALUE="-v" +else + BASH_COMPLETION_ORIGINAL_V_VALUE="+v" +fi + +if [[ -n $BASH_COMPLETION_DEBUG ]]; then + set -v +else + set +v +fi + +# Alter the following to reflect the location of this file. +# +[ -n "$BASH_COMPLETION" ] || BASH_COMPLETION=/etc/bash_completion +[ -n "$BASH_COMPLETION_DIR" ] || BASH_COMPLETION_DIR=/etc/bash_completion.d +readonly BASH_COMPLETION BASH_COMPLETION_DIR + +# Set a couple of useful vars +# +UNAME=$( uname -s ) +# strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin) +UNAME=${UNAME/CYGWIN_*/Cygwin} +RELEASE=$( uname -r ) + +# features supported by bash 2.05 and higher +if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} > 04 ]] || + [ ${BASH_VERSINFO[0]} -gt 2 ]; then + declare -r bash205=$BASH_VERSION 2>/dev/null || : + default="-o default" + dirnames="-o dirnames" + filenames="-o filenames" +fi +# features supported by bash 2.05b and higher +if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} = "05b" ]] || + [ ${BASH_VERSINFO[0]} -gt 2 ]; then + declare -r bash205b=$BASH_VERSION 2>/dev/null || : + nospace="-o nospace" +fi +# features supported by bash 3.0 and higher +if [ ${BASH_VERSINFO[0]} -gt 2 ]; then + declare -r bash3=$BASH_VERSION 2>/dev/null || : + bashdefault="-o bashdefault" + plusdirs="-o plusdirs" +fi + +# Turn on extended globbing and programmable completion +shopt -s extglob progcomp + +# A lot of the following one-liners were taken directly from the +# completion examples provided with the bash 2.04 source distribution + +# Make directory commands see only directories +complete -d pushd + +# The following section lists completions that are redefined later +# Do NOT break these over multiple lines. +# +# START exclude -- do NOT remove this line +complete -f -X '!*.?(t)bz?(2)' bunzip2 bzcat bzcmp bzdiff bzegrep bzfgrep bzgrep +complete -f -X '!*.@(zip|ZIP|jar|JAR|exe|EXE|pk3|war|wsz|ear|zargo|xpi|sxw|ott)' unzip zipinfo +complete -f -X '*.Z' compress znew +complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' gunzip zcmp zdiff zcat zegrep zfgrep zgrep zless zmore +complete -f -X '!*.Z' uncompress +complete -f -X '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' ee display +complete -f -X '!*.@(gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|GIF|JPG|JP?(E)G|TIF?(F)|PNG|P[BGP]M|BMP|X[BP]M|RLE|RGB|PCX|FITS|PM)' xv qiv +complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv kghostview +complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi +complete -f -X '!*.@(dvi|DVI)?(.@(gz|bz2))' kdvi +complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype dvipdf advi dvipdfm dvipdfmx +complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf +complete -f -X '!*.@(?(e)ps|?(E)PS|pdf|PDF)' kpdf +complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ)|cb(r|z)|CB(R|Z)|djv?(u)|DJV?(U)||dvi|DVI|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' evince +complete -f -X '!*.@(?(e)ps|?(E)PS)' ps2pdf +complete -f -X '!*.texi*' makeinfo texi2html +complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi +complete -f -X '!*.@(mp3|MP3)' mpg123 mpg321 madplay +complete -f -X '!*.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp3|MP3|m4v|M4V|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV|asx|ASX|mng|MNG|srt)' xine aaxine fbxine kaffeine +complete -f -X '!*.@(avi|asf|wmv)' aviplay +complete -f -X '!*.@(rm?(j)|ra?(m)|smi?(l))' realplay +complete -f -X '!*.@(mpg|mpeg|avi|mov|qt)' xanim +complete -f -X '!*.@(ogg|OGG|m3u|flac|spx)' ogg123 +complete -f -X '!*.@(mp3|MP3|ogg|OGG|pls|m3u)' gqmpeg freeamp +complete -f -X '!*.fig' xfig +complete -f -X '!*.@(mid?(i)|MID?(I))' playmidi +complete -f -X '!*.@(mid?(i)|MID?(I)|rmi|RMI|rcp|RCP|[gr]36|[GR]36|g18|G18|mod|MOD|xm|XM|it|IT|x3m|X3M)' timidity +complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' vi vim gvim rvim view rview rgvim rgview gview +complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' emacs +complete -f -X '!*.@(exe|EXE|com|COM|scr|SCR|exe.so)' wine +complete -f -X '!*.@(zip|ZIP|z|Z|gz|GZ|tgz|TGZ)' bzme +complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx opera galeon curl dillo elinks amaya +complete -f -X '!*.@(sxw|stw|sxg|sgl|doc|dot|rtf|txt|htm|html|odt|ott|odm)' oowriter +complete -f -X '!*.@(sxi|sti|pps|ppt|pot|odp|otp)' ooimpress +complete -f -X '!*.@(sxc|stc|xls|xlw|xlt|csv|ods|ots)' oocalc +complete -f -X '!*.@(sxd|std|sda|sdd|odg|otg)' oodraw +complete -f -X '!*.@(sxm|smf|mml|odf)' oomath +complete -f -X '!*.odb' oobase +complete -f -X '!*.rpm' rpm2cpio +# FINISH exclude -- do not remove this line + +# start of section containing compspecs that can be handled within bash + +# user commands see only users +complete -u su usermod userdel passwd chage write chfn groups slay w sux + +# group commands see only groups +[ -n "$bash205" ] && complete -g groupmod groupdel newgrp 2>/dev/null + +# bg completes with stopped jobs +complete -A stopped -P '%' bg + +# other job commands +complete -j -P '%' fg jobs disown + +# readonly and unset complete with shell variables +complete -v readonly unset + +# set completes with set options +complete -A setopt set + +# shopt completes with shopt options +complete -A shopt shopt + +# helptopics +complete -A helptopic help + +# unalias completes with aliases +complete -a unalias + +# bind completes with readline bindings (make this more intelligent) +complete -A binding bind + +# type and which complete on commands +complete -c command type which + +# builtin completes on builtins +complete -b builtin + +# start of section containing completion functions called by other functions + +# This function checks whether we have a given program on the system. +# No need for bulky functions in memory if we don't. +# +have() +{ + unset -v have + PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null && + have="yes" +} + +# use GNU sed if we have it, since its extensions are still used in our code +# +[ $UNAME != Linux ] && have gsed && alias sed=gsed + +# This function checks whether a given readline variable +# is `on'. +# +_rl_enabled() +{ + [[ "$( bind -v )" = *$1+([[:space:]])on* ]] +} + +# This function shell-quotes the argument +quote() +{ + echo \'${1//\'/\'\\\'\'}\' #'# Help vim syntax highlighting +} + +# This function quotes the argument in a way so that readline dequoting +# results in the original argument +quote_readline() +{ + local t="${1//\\/\\\\}" + echo \'${t//\'/\'\\\'\'}\' #'# Help vim syntax highlighting +} + +# This function shell-dequotes the argument +dequote() +{ + eval echo "$1" +} + + +# Get the word to complete +# This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases +# where the user is completing in the middle of a word. +# (For example, if the line is "ls foobar", +# and the cursor is here --------> ^ +# it will complete just "foo", not "foobar", which is what the user wants.) +_get_cword() +{ + if [[ "${#COMP_WORDS[COMP_CWORD]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then + echo "${COMP_WORDS[COMP_CWORD]}" + else + local i + local cur="$COMP_LINE" + local index="$COMP_POINT" + for (( i = 0; i <= COMP_CWORD; ++i )); do + while [[ "${#cur}" -ge ${#COMP_WORDS[i]} ]] && [[ "${cur:0:${#COMP_WORDS[i]}}" != "${COMP_WORDS[i]}" ]]; do + cur="${cur:1}" + index="$(( index - 1 ))" + done + if [[ "$i" -lt "$COMP_CWORD" ]]; then + local old_size="${#cur}" + cur="${cur#${COMP_WORDS[i]}}" + local new_size="${#cur}" + index="$(( index - old_size + new_size ))" + fi + done + + if [[ "${COMP_WORDS[COMP_CWORD]:0:${#cur}}" != "$cur" ]]; then + # We messed up! At least return the whole word so things keep working + echo "${COMP_WORDS[COMP_CWORD]}" + else + echo "${cur:0:$index}" + fi + fi +} + + +# This function performs file and directory completion. It's better than +# simply using 'compgen -f', because it honours spaces in filenames. +# If passed -d, it completes only on directories. If passed anything else, +# it's assumed to be a file glob to complete on. +# +_filedir() +{ + local IFS=$'\t\n' xspec + + _expand || return 0 + + local toks=( ) tmp + while read -r tmp; do + [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp + done < <( compgen -d -- "$(quote_readline "$cur")" ) + + if [[ "$1" != -d ]]; then + xspec=${1:+"!*.$1"} + while read -r tmp; do + [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp + done < <( compgen -f -X "$xspec" -- "$(quote_readline "$cur")" ) + fi + + COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" ) +} + +# This function completes on signal names +# +_signals() +{ + local i + + # standard signal completion is rather braindead, so we need + # to hack around to get what we want here, which is to + # complete on a dash, followed by the signal name minus + # the SIG prefix + COMPREPLY=( $( compgen -A signal SIG${cur#-} )) + for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do + COMPREPLY[i]=-${COMPREPLY[i]#SIG} + done +} + +# This function completes on configured network interfaces +# +_configured_interfaces() +{ + if [ -f /etc/debian_version ]; then + # Debian system + COMPREPLY=( $( sed -ne 's|^iface \([^ ]\+\).*$|\1|p' \ + /etc/network/interfaces ) ) + elif [ -f /etc/SuSE-release ]; then + # SuSE system + COMPREPLY=( $( command ls \ + /etc/sysconfig/network/ifcfg-* | \ + sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) ) + elif [ -f /etc/pld-release ]; then + # PLD Linux + COMPREPLY=( $( command ls -B \ + /etc/sysconfig/interfaces | \ + sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) ) + else + # Assume Red Hat + COMPREPLY=( $( command ls \ + /etc/sysconfig/network-scripts/ifcfg-* | \ + sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) ) + fi +} + +# This function completes on all available network interfaces +# -a: restrict to active interfaces only +# -w: restrict to wireless interfaces only +# +_available_interfaces() +{ + local cmd + + if [ "${1:-}" = -w ]; then + cmd="iwconfig" + elif [ "${1:-}" = -a ]; then + cmd="ifconfig" + else + cmd="ifconfig -a" + fi + + COMPREPLY=( $( eval $cmd 2>/dev/null | \ + sed -ne 's|^\('$cur'[^[:space:][:punct:]]\{1,\}\).*$|\1|p') ) +} + +# This function expands tildes in pathnames +# +_expand() +{ + # FIXME: Why was this here? + # [ "$cur" != "${cur%\\}" ] && cur="$cur\\" + + # expand ~username type directory specifications + if [[ "$cur" == \~*/* ]]; then + eval cur=$cur + elif [[ "$cur" == \~* ]]; then + cur=${cur#\~} + COMPREPLY=( $( compgen -P '~' -u $cur ) ) + return ${#COMPREPLY[@]} + fi +} + +# This function completes on process IDs. +# AIX and Solaris ps prefers X/Open syntax. +[ $UNAME = SunOS -o $UNAME = AIX ] && +_pids() +{ + COMPREPLY=( $( compgen -W '$( command ps -efo pid | sed 1d )' -- $cur )) +} || +_pids() +{ + COMPREPLY=( $( compgen -W '$( command ps axo pid | sed 1d )' -- $cur ) ) +} + +# This function completes on process group IDs. +# AIX and SunOS prefer X/Open, all else should be BSD. +[ $UNAME = SunOS -o $UNAME = AIX ] && +_pgids() +{ + COMPREPLY=( $( compgen -W '$( command ps -efo pgid | sed 1d )' -- $cur )) +} || +_pgids() +{ + COMPREPLY=( $( compgen -W '$( command ps axo pgid | sed 1d )' -- $cur )) +} + +# This function completes on user IDs +# +_uids() +{ + if type getent &>/dev/null; then + COMPREPLY=( $( getent passwd | \ + awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) ) + elif type perl &>/dev/null; then + COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- $cur ) ) + else + # make do with /etc/passwd + COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\ + /etc/passwd ) ) + fi +} + +# This function completes on group IDs +# +_gids() +{ + if type getent &>/dev/null; then + COMPREPLY=( $( getent group | \ + awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) ) + elif type perl &>/dev/null; then + COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- $cur ) ) + else + # make do with /etc/group + COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\ + /etc/group ) ) + fi +} + +# This function completes on services +# +_services() +{ + local sysvdir famdir + [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d + famdir=/etc/xinetd.d + COMPREPLY=( $( builtin echo $sysvdir/!(*.rpmsave|*.rpmorig|*~|functions)) ) + + if [ -d $famdir ]; then + COMPREPLY=( "${COMPREPLY[@]}" $( builtin echo $famdir/!(*.rpmsave|*.rpmorig|*~)) ) + fi + + COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- $cur ) ) +} + +# This function complete on modules +# +_modules() +{ + local modpath + modpath=/lib/modules/$1 + COMPREPLY=( $( command ls -R $modpath | \ + sed -ne 's/^\('$cur'.*\)\.k\?o\(\|.gz\)$/\1/p') ) +} + +# this function complete on user:group format +# +_usergroup() +{ + local IFS=$'\n' + cur=${cur//\\\\ / } + if [[ $cur = *@(\\:|.)* ]] && [ -n "$bash205" ]; then + user=${cur%%*([^:.])} + COMPREPLY=( $(compgen -P ${user/\\\\} -g -- ${cur##*[.:]}) ) + elif [[ $cur = *:* ]] && [ -n "$bash205" ]; then + COMPREPLY=( $( compgen -g -- ${cur##*[.:]} ) ) + else + COMPREPLY=( $( compgen -S : -u -- $cur ) ) + fi +} + +# this function count the number of mandatory args +# +_count_args() +{ + args=1 + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" != -* ]]; then + args=$(($args+1)) + fi + done +} + +# start of section containing completion functions for bash built-ins + +# bash alias completion +# +_alias() +{ + local cur + + COMPREPLY=() + cur=${COMP_WORDS[$COMP_CWORD]} + + case "$COMP_LINE" in + *[^=]) + COMPREPLY=( $( compgen -A alias -S '=' -- $cur ) ) + ;; + *=) + COMPREPLY=( "$( alias ${cur%=} 2>/dev/null | \ + sed -e 's|^alias '$cur'\(.*\)$|\1|' )" ) + ;; + esac +} +complete -F _alias $nospace alias + +# bash export completion +# +_export() +{ + local cur + + COMPREPLY=() + cur=${COMP_WORDS[$COMP_CWORD]} + + case "$COMP_LINE" in + *=\$*) + COMPREPLY=( $( compgen -v -P '$' -- ${cur#*=\$} ) ) + ;; + *[^=]) + COMPREPLY=( $( compgen -v -S '=' -- $cur ) ) + ;; + *=) + COMPREPLY=( "$( eval echo -n \"$`echo ${cur%=}`\" | + ( echo -n \' + sed -e 's/'\''/'\''\\\'\'''\''/g' + echo -n \' ) )" ) + ;; + esac +} +complete -F _export $default $nospace export + +# bash shell function completion +# +_function() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ $1 == @(declare|typeset) ]]; then + if [ "$prev" = -f ]; then + COMPREPLY=( $( compgen -A function -- $cur ) ) + elif [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-a -f -F -i -r -x -p' -- \ + $cur ) ) + fi + elif [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -A function -- $cur ) ) + else + COMPREPLY=( "() $( type -- ${COMP_WORDS[1]} | sed -e 1,2d )" ) + fi +} +complete -F _function function declare typeset + +# bash complete completion +# +_complete() +{ + local cur prev options + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + -o) + options="default dirnames filenames" + [ -n "$bash205b" ] && options="$options nospace" + [ -n "$bash3" ] && options="$options bashdefault plusdirs" + COMPREPLY=( $( compgen -W "$options" -- $cur ) ) + return 0 + ;; + + -A) + COMPREPLY=( $( compgen -W 'alias arrayvar binding \ + builtin command directory disabled enabled \ + export file function group helptopic hostname \ + job keyword running service setopt shopt \ + signal stopped user variable' -- $cur ) ) + return 0 + ;; + + -C) + COMPREPLY=( $( compgen -A command -- $cur ) ) + return 0 + ;; + -F) + COMPREPLY=( $( compgen -A function -- $cur ) ) + return 0 + ;; + -@(p|r)) + COMPREPLY=( $( complete -p | sed -e 's|.* ||' | \ + grep "^$cur" ) ) + return 0 + ;; + + esac + + if [[ "$cur" == -* ]]; then + # relevant options completion + options="-a -b -c -d -e -f -g -j -k -s -v -u -A -G -W -P -S -X -F -C" + [ -n "$bash205" ] && options="$options -o" + COMPREPLY=( $( compgen -W "$options" -- $cur ) ) + else + COMPREPLY=( $( compgen -A command -- $cur ) ) + fi +} +complete -F _complete complete + +# start of section containing completion functions for external programs + +# a little help for FreeBSD ports users +[ $UNAME = FreeBSD ] && complete -W 'index search fetch fetch-list \ + extract patch configure build install reinstall \ + deinstall clean clean-depends kernel buildworld' make + +# This completes on a list of all available service scripts for the +# 'service' command and/or the SysV init.d directory, followed by +# that script's available commands +# +{ have service || [ -d /etc/init.d/ ]; } && +_service() +{ + local cur sysvdir + + COMPREPLY=() + prev=${COMP_WORDS[COMP_CWORD-1]} + cur=`_get_cword` + + # don't complete for things like killall, ssh and mysql if it's + # the standalone command, rather than the init script + [[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0 + + # don't complete past 2nd token + [ $COMP_CWORD -gt 2 ] && return 0 + + [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \ + || sysvdir=/etc/init.d + + if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then + _services + else + COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \ + s/^.*Usage.*{\(.*\)}.*$/\1/p" \ + $sysvdir/${prev##*/} 2>/dev/null`' -- $cur ) ) + fi + + return 0 +} && +complete -F _service service +[ -d /etc/init.d/ ] && complete -F _service $default \ + $(for i in /etc/init.d/*; do echo ${i##*/}; done) + +# chown(1) completion +# +_chown() +{ + local cur + cur=`_get_cword` + + # options completion + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \ + --dereference --no-dereference --from= --silent --quiet \ + --reference= --recursive --verbose --help --version' -- $cur ) ) + else + _count_args + + case $args in + 1) + _usergroup + ;; + *) + _filedir + ;; + esac + fi +} +complete -F _chown $filenames chown + +# chgrp(1) completion +# +_chgrp() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + cur=${cur//\\\\/} + prev=${COMP_WORDS[COMP_CWORD-1]} + + # options completion + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \ + --dereference --no-dereference --silent --quiet \ + --reference= --recursive --verbose --help --version' -- $cur ) ) + return 0 + fi + + # first parameter on line or first since an option? + if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]] || \ + [[ "$prev" == -* ]] && [ -n "$bash205" ]; then + local IFS=$'\n' + COMPREPLY=( $( compgen -g $cur 2>/dev/null ) ) + else + _filedir || return 0 + fi + + return 0 +} +complete -F _chgrp $filenames chgrp + +# umount(8) completion. This relies on the mount point being the third +# space-delimited field in the output of mount(8) +# +_umount() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + OLDIFS="$IFS" + IFS="\n" + COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- $cur ) ) + IFS="$OLDIFS" + + return 0 +} +complete -F _umount $dirnames umount + +# mount(8) completion. This will pull a list of possible mounts out of +# /etc/{,v}fstab, unless the word being completed contains a ':', which +# would indicate the specification of an NFS server. In that case, we +# query the server for a list of all available exports and complete on +# that instead. +# +_mount() +{ local cur i sm host + + COMPREPLY=() + cur=`_get_cword` + [[ "$cur" == \\ ]] && cur="/" + + for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done + + if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then + COMPREPLY=( $( $sm -e ${cur%%:*} | sed 1d | \ + grep ^${cur#*:} | awk '{print $1}' ) ) + elif [[ "$cur" == //* ]]; then + host=${cur#//} + host=${host%%/*} + if [ -n "$host" ]; then + COMPREPLY=( $( compgen -W "$( echo $( smbclient -d 0 -NL $host 2>/dev/null| + sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' | + sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|//'$host'/\1|p' ) )" -- "$cur" ) ) + fi + elif [ -r /etc/vfstab ]; then + # Solaris + COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \ + /etc/vfstab | grep "^$cur" ) ) + elif [ ! -e /etc/fstab ]; then + # probably Cygwin + COMPREPLY=( $( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \ + | grep "^$cur" ) ) + else + # probably Linux + COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \ + /etc/fstab | grep "^$cur" ) ) + fi + + return 0 +} +complete -F _mount $default $filenames mount + +# Linux rmmod(8) completion. This completes on a list of all currently +# installed kernel modules. +# +have rmmod && { +_rmmod() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + COMPREPLY=( $( /sbin/lsmod | \ + awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' 2>/dev/null )) + return 0 +} +complete -F _rmmod rmmod + +# Linux insmod(8), modprobe(8) and modinfo(8) completion. This completes on a +# list of all available modules for the version of the kernel currently +# running. +# +_insmod() +{ + local cur prev modpath + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # behave like lsmod for modprobe -r + if [ $1 = "modprobe" ] && + [ "${COMP_WORDS[1]}" = "-r" ]; then + COMPREPLY=( $( /sbin/lsmod | \ + awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' ) ) + return 0 + fi + + # do filename completion if we're giving a path to a module + if [[ "$cur" == */* ]]; then + _filedir '@(?(k)o?(.gz))' + return 0 + fi + + if [ $COMP_CWORD -gt 1 ] && + [[ "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then + # do module parameter completion + COMPREPLY=( $( /sbin/modinfo -p ${COMP_WORDS[1]} 2>/dev/null | \ + awk '{if ($1 ~ /^parm:/ && $2 ~ /^'$cur'/) { print $2 } \ + else if ($1 !~ /:/ && $1 ~ /^'$cur'/) { print $1 }}' ) ) + else + _modules $(uname -r) + fi + + return 0 +} +complete -F _insmod $filenames insmod modprobe modinfo +} + +# man(1) completion +# +[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \ + -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \ + -o $UNAME = OpenBSD ] && +_man() +{ + local cur prev sect manpath UNAME + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + _expand || return 0 + + # default completion if parameter contains / + if [[ "$cur" == */* ]]; then + _filedir + return 0 + fi + + UNAME=$( uname -s ) + # strip OS type and version under Cygwin + UNAME=${UNAME/CYGWIN_*/Cygwin} + if [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = FreeBSD \ + -o $UNAME = Cygwin ]; then + manpath=$( manpath 2>/dev/null || command man --path ) + else + manpath=$MANPATH + fi + + if [ -z "$manpath" ]; then + COMPREPLY=( $( compgen -c -- $cur ) ) + return 0 + fi + + # determine manual section to search + [[ "$prev" == [0-9ln] ]] && sect=$prev || sect='*' + + manpath=$manpath: + if [ -n "$cur" ]; then + manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }" + else + manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }" + fi + + # redirect stderr for when path doesn't exist + COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) ) + # weed out directory path names and paths to man pages + COMPREPLY=( ${COMPREPLY[@]##*/?(:)} ) + # strip suffix from man pages + COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} ) + COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) ) + + [[ "$prev" != [0-9ln] ]] && _filedir '[0-9ln]' + + return 0 +} +[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \ + -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \ + -o $UNAME = OpenBSD ] && \ +complete -F _man $filenames man apropos whatis + +# renice(8) completion +# +_renice() +{ + local command cur curopt i + + COMPREPLY=() + cur=`_get_cword` + command=$1 + + i=0 + # walk back through command line and find last option + while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do + curopt=${COMP_WORDS[COMP_CWORD-$i]} + case "$curopt" in + -u) + COMPREPLY=( $( compgen -u -- $cur ) ) + ;; + -g) + _pgids + ;; + -p|$command) + _pids + ;; + esac + i=$(( ++i )) + done +} +complete -F _renice renice + +# kill(1) completion +# +_kill() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then + # return list of available signals + _signals + else + # return list of available PIDs + _pids + fi +} +complete -F _kill kill + +# Linux and FreeBSD killall(1) completion. +# +[ $UNAME = Linux -o $UNAME = FreeBSD ] && +_killall() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then + _signals + else + COMPREPLY=( $( compgen -W '$( command ps axo command | \ + sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \ + sed -e "s/.*\///" )' -- $cur ) ) + fi + + return 0 +} +[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall pkill + +# Linux and FreeBSD pgrep(1) completion. +# +[ $UNAME = Linux -o $UNAME = FreeBSD ] && +_pgrep() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + COMPREPLY=( $( compgen -W '$( command ps axo command | \ + sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \ + sed -e "s/.*\///" )' -- $cur ) ) + + return 0 +} +[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _pgrep pgrep +# Linux pidof(8) completion. +[ $UNAME = Linux ] && complete -F _pgrep pidof + +# GNU find(1) completion. This makes heavy use of ksh style extended +# globs and contains Linux specific code for completing the parameter +# to the -fstype option. +# +_find() +{ + local cur prev i exprfound onlyonce + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(max|min)depth) + COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- $cur ) ) + return 0 + ;; + -?(a|c)newer|-fls|-fprint?(0|f)|-?(i)?(l)name|-?(i)wholename) + _filedir + return 0 + ;; + -fstype) + # this is highly non-portable + [ -e /proc/filesystems ] && + COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | \ + grep "^$cur" ) ) + return 0 + ;; + -gid) + _gids + return 0 + ;; + -group) + if [ -n "$bash205" ]; then + COMPREPLY=( $( compgen -g -- $cur 2>/dev/null) ) + fi + return 0 + ;; + -?(x)type) + COMPREPLY=( $( compgen -W 'b c d p f l s' -- $cur ) ) + return 0 + ;; + -uid) + _uids + return 0 + ;; + -user) + COMPREPLY=( $( compgen -u -- $cur ) ) + return 0 + ;; + -exec|-ok) + COMP_WORDS=(COMP_WORDS[0] $cur) + COMP_CWORD=1 + _command + return 0 + ;; + -[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \ + -links|-perm|-size|-used|-printf) + # do nothing, just wait for a parameter to be given + return 0 + ;; + esac + + _expand || return 0 + + # set exprfound to 1 if there is already an expression present + for i in ${COMP_WORDS[@]}; do + [[ "$i" = [-\(\),\!]* ]] && exprfound=1 && break + done + + # handle case where first parameter is not a dash option + if [ "$exprfound" != 1 ] && [[ "$cur" != [-\(\),\!]* ]]; then + _filedir -d + return 0 + fi + + # complete using basic options + COMPREPLY=( $( compgen -W '-daystart -depth -follow -help -maxdepth \ + -mindepth -mount -noleaf -version -xdev -amin -anewer \ + -atime -cmin -cnewer -ctime -empty -false -fstype \ + -gid -group -ilname -iname -inum -ipath -iregex \ + -wholename \ + -links -lname -mmin -mtime -name -newer -nouser \ + -nogroup -perm -regex -size -true -type -uid -used \ + -user -xtype -exec -fls -fprint -fprint0 -fprintf -ok \ + -print -print0 -printf -prune -ls' -- $cur ) ) + + # this removes any options from the list of completions that have + # already been specified somewhere on the command line, as long as + # these options can only be used once (in a word, "options", in + # opposition to "tests" and "actions", as in the find(1) manpage). + onlyonce=' -daystart -depth -follow -help -maxdepth -mindepth -mount \ + -noleaf -version -xdev ' + COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \ + (while read -d ' ' i; do + [ "$i" == "" ] || + [ "${onlyonce/ ${i%% *} / }" == "$onlyonce" ] && + continue + # flatten array with spaces on either side, + # otherwise we cannot grep on word boundaries of + # first and last word + COMPREPLY=" ${COMPREPLY[@]} " + # remove word from list of completions + COMPREPLY=( ${COMPREPLY/ ${i%% *} / } ) + done + echo "${COMPREPLY[@]}") + ) ) + + _filedir + + return 0 +} +complete -F _find $filenames find + +# Linux iwconfig(8) completion +# +[ $UNAME = Linux ] && have iwconfig && +_iwconfig() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + mode) + COMPREPLY=( $( compgen -W 'managed ad-hoc master \ + repeater secondary monitor' -- $cur ) ) + return 0 + ;; + essid) + COMPREPLY=( $( compgen -W 'on off any' -- $cur ) ) + if [ -n "${COMP_IWLIST_SCAN:-}" ]; then + COMPREPLY=( "${COMPREPLY[@]}" \ + $( iwlist ${COMP_WORDS[1]} scan | \ + awk -F '"' '/ESSID/ {print $2}' | \ + grep "^$cur" )) + fi + return 0 + ;; + nwid) + COMPREPLY=( $( compgen -W 'on off' -- $cur ) ) + return 0 + ;; + channel) + COMPREPLY=( $( iwlist ${COMP_WORDS[1]} channel | \ + awk '/^[[:space:]]*Channel/ {print $2}' | \ + grep "^$cur" ) ) + return 0 + ;; + + freq) + COMPREPLY=( $( iwlist ${COMP_WORDS[1]} channel | \ + awk '/^[[:space:]]*Channel/ {print $4"G"}' | \ + grep "^$cur" ) ) + return 0 + ;; + ap) + COMPREPLY=( $( compgen -W 'on off any' -- $cur ) ) + if [ -n "${COMP_IWLIST_SCAN:-}" ]; then + COMPREPLY=( "${COMPREPLY[@]}" \ + $( iwlist ${COMP_WORDS[1]} scan | \ + awk -F ': ' '/Address/ {print $2}' | \ + grep "^$cur" ) ) + fi + return 0 + ;; + rate) + COMPREPLY=( $( compgen -W 'auto fixed' -- $cur ) ) + COMPREPLY=( "${COMPREPLY[@]}" \ + $( iwlist ${COMP_WORDS[1]} rate | \ + awk '/^[[:space:]]*[0-9]/ {print $1"M"}' | \ + grep "^$cur" ) ) + return 0 + ;; + rts) + COMPREPLY=( $( compgen -W 'auto fixed off' -- $cur ) ) + return 0 + ;; + frag) + COMPREPLY=( $( compgen -W 'auto fixed off' -- $cur ) ) + return 0 + ;; + key) + COMPREPLY=( $( compgen -W 'off on open restricted' -- $cur ) ) + return 0 + ;; + enc) + COMPREPLY=( $( compgen -W 'off on open restricted' -- $cur ) ) + return 0 + ;; + power) + COMPREPLY=( $( compgen -W 'period timeout off on' -- $cur ) ) + return 0 + ;; + txpower) + COMPREPLY=( $( compgen -W 'off on auto' -- $cur ) ) + return 0 + ;; + retry) + COMPREPLY=( $( compgen -W 'limit lifetime' -- $cur ) ) + return 0 + ;; + esac + + if [ $COMP_CWORD -eq 1 ]; then + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--help --version' -- $cur ) ) + else + _available_interfaces -w + fi + else + COMPREPLY=( $( compgen -W 'essid nwid mode freq channel sens mode \ + ap nick rate rts frag enc key power txpower commit' -- $cur ) ) + fi + +} && +complete -F _iwconfig iwconfig + +# Linux iwlist(8) completion +# +[ $UNAME = Linux ] && have iwlist && +_iwlist() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [ $COMP_CWORD -eq 1 ]; then + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--help --version' -- $cur ) ) + else + _available_interfaces -w + fi + else + COMPREPLY=( $( compgen -W 'scan scanning freq frequency \ + channel rate bit bitrate key enc encryption power \ + txpower retry ap accesspoint peers event' -- $cur ) ) + fi +} && +complete -F _iwlist iwlist + +# Linux iwspy(8) completion +# +[ $UNAME = Linux ] && have iwspy && +_iwspy() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ]; then + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--help --version' -- $cur ) ) + else + _available_interfaces -w + fi + else + COMPREPLY=( $( compgen -W 'setthr getthr off' -- $cur ) ) + fi +} && +complete -F _iwspy iwspy + +# Linux iwpriv(8) completion +# +[ $UNAME = Linux ] && have iwpriv && +_iwpriv() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + roam) + COMPREPLY=( $( compgen -W 'on off' -- $cur ) ) + return 0 + ;; + port) + COMPREPLY=( $( compgen -W 'ad-hoc managed' -- $cur ) ) + return 0 + ;; + esac + + if [ $COMP_CWORD -eq 1 ]; then + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--help --version' -- $cur ) ) + else + _available_interfaces -w + fi + else + COMPREPLY=( $( compgen -W '--all roam port' -- $cur ) ) + fi +} && +complete -F _iwpriv iwpriv + +# RedHat & Debian GNU/Linux if{up,down} completion +# +[ $UNAME = Linux ] && { have ifup || have ifdown; } && +_ifupdown() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ]; then + _configured_interfaces + COMPREPLY=( $(compgen -W '${COMPREPLY[@]}' -- "$cur") ) + fi + + return 0 +} && +complete -F _ifupdown ifup ifdown +[ $UNAME = Linux ] && have ifstatus && complete -F _ifupdown ifstatus + +# Linux ipsec(8) completion (for FreeS/WAN) +# +[ $UNAME = Linux ] && have ipsec && +_ipsec() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look \ + manual pluto ranbits rsasigkey \ + setup showdefaults showhostkey spi \ + spigrp tncfg whack' -- $cur ) ) + return 0 + fi + + case ${COMP_WORDS[1]} in + auto) + COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete \ + --replace --down --route --unroute \ + --ready --status --rereadsecrets' \ + -- $cur ) ) + ;; + manual) + COMPREPLY=( $( compgen -W '--up --down --route --unroute \ + --union' -- $cur ) ) + ;; + ranbits) + COMPREPLY=( $( compgen -W '--quick --continuous --bytes' \ + -- $cur ) ) + ;; + setup) + COMPREPLY=( $( compgen -W '--start --stop --restart' -- $cur ) ) + ;; + + *) + ;; + esac + + return 0 +} && +complete -F _ipsec ipsec + +# Postfix completion. +# +have postfix && { +# postfix(1) +# +_postfix() +{ + local cur prev + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ $cur == '-' ]]; then + COMPREPLY=(-c -D -v) + return 0 + fi + if [[ $prev == '-c' ]]; then + _filedir -d + return 0 + fi + if [[ $prev == '-D' ]]; then + COMPREPLY=( $( compgen -W 'start' -- "`get_cword`" ) ) + return 0 + fi + COMPREPLY=( $( compgen -W 'start stop reload abort flush check' -- \ + "`get_cword`" ) ) +} +complete -F _postfix postfix + +# postalias(1) and postmap(1) +# +_postmap() +{ + local cur prev len idx + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ $cur == '-' ]]; then + COMPREPLY=(-N -f -i -n -o -p -r -v -w -c -d -q) + return 0 + fi + if [[ $prev == '-c' ]]; then + _filedir -d + return 0 + fi + if [[ $prev == -[dq] ]]; then + return 0 + fi + + if [[ "$cur" == *:* ]]; then + COMPREPLY=( $( compgen -f -- ${cur#*:} ) ) + else + len=${#cur} + idx=0 + for pval in $( /usr/sbin/postconf -m ); do + if [[ "$cur" == "${pval:0:$len}" ]]; then + COMPREPLY[$idx]="$pval:" + idx=$(($idx+1)) + fi + done + if [[ $idx -eq 0 ]]; then + COMPREPLY=( $( compgen -f -- "$cur" ) ) + fi + fi + return 0 +} +complete -F _postmap postmap postalias + +# postcat(1) +# +_postcat() +{ + local cur prev pval len idx qfile + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ $cur == '-' ]]; then + COMPREPLY=(-c -q -v) + return 0 + fi + if [[ $prev == '-c' ]]; then + _filedir -d + return 0 + fi + + qfile=0 + for idx in "${COMP_WORDS[@]}"; do + [[ "$idx" = -q ]] && qfile=1 && break + done + if [[ $qfile == 1 ]]; then + len=${#cur} + idx=0 + for pval in $( mailq | \ + sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do + if [[ "$cur" == "${pval:0:$len}" ]]; then + COMPREPLY[$idx]=$pval + idx=$(($idx+1)) + fi + done + return 0 + else + _filedir + return 0 + fi +} +complete -F _postcat postcat + +# postconf(1) +# +_postconf() +{ + local cur prev pval len idx eqext + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + if [[ $cur == '-' ]]; then + COMPREPLY=(-c -d -e -h -m -l -n -v) + return 0 + fi + if [[ $prev == '-c' ]]; then + _filedir -d + return 0 + fi + if [[ $prev == '-e' ]]; then + cur=${cur#[\"\']} + eqext='=' + fi + len=${#cur} + idx=0 + for pval in $( /usr/sbin/postconf | cut -d ' ' -f 1 ); do + if [[ "$cur" == "${pval:0:$len}" ]]; then + COMPREPLY[$idx]="$pval$eqext" + idx=$(($idx+1)) + fi + done + return 0 +} +complete -F _postconf postconf + +# postsuper(1) +# +_postsuper() +{ + local cur prev pval len idx + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ $cur == '-' ]]; then + COMPREPLY=(-c -d -h -H -p -r -s -v) + return 0 + fi + case $prev in + -[dr]) + len=${#cur} + idx=0 + for pval in $( echo ALL; mailq | \ + sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do + if [[ "$cur" == "${pval:0:$len}" ]]; then + COMPREPLY[$idx]=$pval + idx=$(($idx+1)) + fi + done + return 0 + ;; + -h) + len=${#cur} + idx=0 + for pval in $( echo ALL; mailq | \ + sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* ].*$//; /!$/d' ); do + if [[ "$cur" == "${pval:0:$len}" ]]; then + COMPREPLY[$idx]=$pval + idx=$(($idx+1)) + fi + done + return 0 + ;; + -H) + len=${#cur} + idx=0 + for pval in $( echo ALL; mailq | \ + sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//' ); do + if [[ "$cur" == "${pval:0:$len}" ]]; then + COMPREPLY[$idx]=$pval + idx=$(($idx+1)) + fi + done + return 0 + ;; + esac + COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- $cur ) ) + return 0 +} +complete -F _postsuper postsuper +} + +# cvs(1) completion +# +have cvs && { +set_prefix() +{ + [ -z ${prefix:-} ] || prefix=${cur%/*}/ + [ -r ${prefix:-}CVS/Entries ] || prefix="" +} + +get_entries() +{ + local IFS=$'\n' + [ -r ${prefix:-}CVS/Entries ] && \ + entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries) +} + +get_modules() +{ + if [ -n "$prefix" ]; then + COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) ) + else + COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) ) + fi +} + +_cvs() +{ + local cur count mode i cvsroot cvsroots pwd + local -a flags miss files entries changed newremoved + + COMPREPLY=() + cur=`_get_cword` + + count=0 + for i in "${COMP_WORDS[@]}"; do + [ $count -eq $COMP_CWORD ] && break + # Last parameter was the CVSROOT, now go back to mode selection + if [ "${COMP_WORDS[((count))]}" == "$cvsroot" -a "$mode" == "cvsroot" ]; then + mode="" + fi + if [ -z "$mode" ]; then + case $i in + -d) + mode=cvsroot + cvsroot=${COMP_WORDS[((count+1))]} + ;; + @(ad?(d)|new)) + mode=add + ;; + @(adm?(in)|rcs)) + mode=admin + ;; + ann?(notate)) + mode=annotate + ;; + @(checkout|co|get)) + mode=checkout + ;; + @(com?(mit)|ci)) + mode=commit + ;; + di?(f?(f))) + mode=diff + ;; + ex?(p?(ort))) + mode=export + ;; + ?(un)edit) + mode=$i + ;; + hi?(s?(tory))) + mode=history + ;; + im?(p?(ort))) + mode=import + ;; + re?(l?(ease))) + mode=release + ;; + ?(r)log) + mode=log + ;; + @(rdiff|patch)) + mode=rdiff + ;; + @(remove|rm|delete)) + mode=remove + ;; + @(rtag|rfreeze)) + mode=rtag + ;; + st?(at?(us))) + mode=status + ;; + @(tag|freeze)) + mode=tag + ;; + up?(d?(ate))) + mode=update + ;; + *) + ;; + esac + elif [[ "$i" = -* ]]; then + flags=( "${flags[@]}" $i ) + fi + count=$((++count)) + done + + case "$mode" in + add) + if [[ "$cur" != -* ]]; then + set_prefix + if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then + get_entries + [ -z "$cur" ] && \ + files=$( command ls -Ad !(CVS) ) || \ + files=$( command ls -d ${cur}* 2>/dev/null ) + for i in "${entries[@]}"; do + files=( ${files[@]/#$i//} ) + done + COMPREPLY=( $( compgen -W '${files[@]}' -- \ + $cur ) ) + fi + else + COMPREPLY=( $( compgen -W '-k -m' -- $cur ) ) + fi + ;; + admin) + if [[ "$cur" = -* ]]; then + COMPREPLY=( $( compgen -W '-i -a -A -e -b -c -k -l -u \ + -L -U -m -M -n -N -o -q -I \ + -s -t -t- -T -V -x -z' -- \ + $cur ) ) + fi + ;; + annotate) + if [[ "$cur" = -* ]]; then + COMPREPLY=( $( compgen -W '-D -F -f -l -R -r' -- $cur ) ) + else + get_entries + COMPREPLY=( $( compgen -W '${entries[@]}' -- $cur ) ) + fi + ;; + checkout) + if [[ "$cur" != -* ]]; then + [ -z "$cvsroot" ] && cvsroot=$CVSROOT + COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \ + awk '{print $1}' ) ) + COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) ) + else + COMPREPLY=( $( compgen -W '-A -N -P -R -c -f -l -n -p \ + -s -r -D -d -k -j' -- $cur ) ) + fi + ;; + commit) + set_prefix + + if [[ "$cur" != -* ]] && [ -r ${prefix:-}CVS/Entries ]; then + # if $COMP_CVS_REMOTE is not null, 'cvs commit' will + # complete on remotely checked-out files (requires + # passwordless access to the remote repository + if [ -n "${COMP_CVS_REMOTE:-}" ]; then + # this is the least computationally intensive + # way found so far, but other changes + # (something other than changed/removed/new) + # may be missing + changed=( $( cvs -q diff --brief 2>&1 | \ + sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) ) + newremoved=( $( cvs -q diff --brief 2>&1 | \ + sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) ) + COMPREPLY=( $( compgen -W '${changed[@]:-} \ + ${newremoved[@]:-}' -- $cur ) ) + else + _filedir + fi + else + COMPREPLY=( $( compgen -W '-n -R -l -f -F -m -r' -- \ + $cur ) ) + fi + ;; + cvsroot) + if [ -r ~/.cvspass ]; then + # Ugly escaping because of bash treating ':' specially + cvsroots=$( sed 's/^[^ ]* //; s/:/\\:/g' ~/.cvspass ) + COMPREPLY=( $( compgen -W '$cvsroots' -- $cur ) ) + fi + ;; + export) + if [[ "$cur" != -* ]]; then + [ -z "$cvsroot" ] && cvsroot=$CVSROOT + COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) ) + COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) ) + else + COMPREPLY=( $( compgen -W '-N -f -l -R -n \ + -r -D -d -k' -- $cur ) ) + fi + ;; + diff) + if [[ "$cur" == -* ]]; then + _longopt diff + else + get_entries + COMPREPLY=( $( compgen -W '${entries[@]:-}' -- $cur ) ) + fi + ;; + remove) + if [[ "$cur" != -* ]]; then + set_prefix + if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then + get_entries + # find out what files are missing + for i in "${entries[@]}"; do + [ ! -r "$i" ] && miss=( "${miss[@]}" $i ) + done + COMPREPLY=( $(compgen -W '${miss[@]:-}' -- $cur) ) + fi + else + COMPREPLY=( $( compgen -W '-f -l -R' -- $cur ) ) + fi + ;; + import) + if [[ "$cur" != -* ]]; then + # starts with same algorithm as checkout + [ -z "$cvsroot" ] && cvsroot=$CVSROOT + prefix=${cur%/*} + if [ -r ${cvsroot}/${prefix} ]; then + get_modules + COMPREPLY=( ${COMPREPLY[@]#$cvsroot} ) + COMPREPLY=( ${COMPREPLY[@]#\/} ) + fi + pwd=$( pwd ) + pwd=${pwd##*/} + COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- \ + $cur ) ) + else + COMPREPLY=( $( compgen -W '-d -k -I -b -m -W' -- $cur )) + fi + ;; + update) + if [[ "$cur" = -* ]]; then + COMPREPLY=( $( compgen -W '-A -P -C -d -f -l -R -p \ + -k -r -D -j -I -W' -- \ + $cur ) ) + fi + ;; + "") + COMPREPLY=( $( compgen -W 'add admin annotate checkout ci co \ + commit diff delete edit export \ + freeze get history import log new \ + patch rcs rdiff release remove \ + rfreeze rlog rm rtag stat status \ + tag unedit up update -H -Q -q -b \ + -d -e -f -l -n -t -r -v -w -x -z \ + --help --version' -- $cur ) ) + ;; + *) + ;; + esac + + return 0 +} +complete -F _cvs $default cvs +} + +have rpm && { +# helper functions for rpm completion +# +_rpm_installed_packages() +{ + local ver nodig nosig + + if [ -r /var/log/rpmpkgs -a \ + /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]; then + # using RHL 7.2 or later - this is quicker than querying the DB + COMPREPLY=( $( sed -ne \ + 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+.*\.rpm$|\1|p' \ + /var/log/rpmpkgs ) ) + else + nodig="" + nosig="" + ver=$(rpm --version) + ver=${ver##* } + + if [[ "$ver" > "4.0.4" ]]; then + nodig="--nodigest" + fi + if [[ "$ver" > "4.0.99" ]]; then + nosig="--nosignature" + fi + + COMPREPLY=( $( rpm -qa $nodig $nosig | sed -ne \ + 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+$|\1|p' ) ) + fi +} + +_rpm_groups() +{ + local IFS=$'\t' + # remove trailing backslash, or grep will complain + cur=${cur%"\\"} + COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat '%{group}\n' | \ + grep "^$cur" ) ) + # backslash escape spaces and translate newlines to tabs + COMPREPLY=( $( echo "${COMPREPLY[@]}" | sed 's/ /\\ /g' | tr '\n' '\t' ) ) +} + +# rpm(8) completion +# +_rpm() +{ + local cur prev ver nodig nosig + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + nodig="" + nosig="" + ver=$(rpm --version); ver=${ver##* } + + if [[ "$ver" > "4.0.4" ]]; then + nodig="--nodigest" + fi + if [[ "$ver" > "4.0.99" ]]; then + nosig="--nosignature" + fi + + if [ $COMP_CWORD -eq 1 ]; then + # first parameter on line + case "$cur" in + -b*) + COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs'\ + -- $cur ) ) + ;; + -t*) + COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts'\ + -- $cur ) ) + ;; + --*) + COMPREPLY=( $( compgen -W '--help --version --initdb \ + --checksig --recompile --rebuild --resign --addsign \ + --rebuilddb --showrc --setperms --setugids --tarbuild \ + --eval --install --upgrade --query --freshen --erase \ + --verify --querytags --rmsource --rmspec --clean \ + --import' -- $cur ) ) + ;; + *) + COMPREPLY=( $( compgen -W '-b -e -F -i -q -t -U -V' \ + -- $cur ) ) + ;; + esac + + return 0 + fi + + case "$prev" in + --@(@(db|exclude)path|prefix|relocate|root)) + _filedir -d + return 0 + ;; + --eval) + # get a list of macros + COMPREPLY=( $( sed -ne 's|^\(%'${cur#\%}'[^ '$'\t'']*\).*$|\1|p' \ + /usr/lib/rpm/macros ) ) + return 0 + ;; + --pipe) + COMPREPLY=( $( compgen -c -- $cur ) ) + return 0 + ;; + --rcfile) + _filedir + return 0 + ;; + --specfile) + # complete on .spec files + _filedir spec + return 0 + ;; + --whatprovides) + if [[ "$cur" == */* ]]; then + _filedir + else + # complete on capabilities + COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \ + '%{providename}\n' | grep "^$cur" ) ) + fi + return 0 + ;; + --whatrequires) + # complete on capabilities + COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \ + '%{requirename}\n' | grep "^$cur" ) ) + return 0 + ;; + esac + + case "${COMP_WORDS[1]}" in + -@([iFU]*|-install|-freshen|-upgrade)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--percent --force --test \ + --replacepkgs --replacefiles --root --excludedocs \ + --includedocs --noscripts --rcfile --ignorearch \ + --dbpath --prefix --ignoreos --nodeps --allfiles \ + --ftpproxy --ftpport --justdb --httpproxy --httpport \ + --noorder --relocate --badreloc --notriggers \ + --excludepath --ignoresize --oldpackage --define \ + --eval --pipe --queryformat --repackage --nosuggests \ + --nodigest --nosignature' -- $cur ) ) + else + _filedir 'rpm' + fi + ;; + -@(e|-erase)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--allmatches --noscripts \ + --notriggers --nodeps --test --repackage' -- $cur ) ) + else + _rpm_installed_packages + fi + ;; + -@(q*|-query)) + # check whether we're doing file completion + if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--scripts --root \ + --rcfile --requires --ftpport --ftpproxy \ + --httpproxy --httpport --provides --triggers \ + --dump --changelog --dbpath \ + --last --filesbypkg \ + --info --list --state \ + --docfiles --configfiles --queryformat \ + --conflicts --obsoletes \ + --nodigest --nosignature \ + --triggerscripts' -- $cur ) ) + else + _filedir + fi + elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then + _rpm_groups + elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then + # uninstalled package completion + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--scripts --root \ + --rcfile --whatprovides --whatrequires \ + --requires --triggeredby --ftpport --ftpproxy \ + --httpproxy --httpport --provides --triggers \ + --dump --changelog --dbpath --filesbypkg \ + --define --eval --pipe --showrc --info --list \ + --state --docfiles --configfiles --queryformat\ + --conflicts --obsoletes --nodigest \ + --nosignature' -- $cur ) ) + else + _filedir 'rpm' + fi + else + # installed package completion + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--scripts --root \ + --rcfile --whatprovides --whatrequires \ + --requires --triggeredby --ftpport --ftpproxy \ + --httpproxy --httpport --provides --triggers \ + --dump --changelog --dbpath --specfile \ + --querybynumber --last --filesbypkg --define \ + --eval --pipe --showrc --info --list --state \ + --docfiles --configfiles --queryformat \ + --conflicts --obsoletes --pkgid --hdrid \ + --fileid --tid --nodigest --nosignature \ + --triggerscripts' -- $cur ) ) + elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then + _rpm_installed_packages + fi + fi + ;; + -@(K*|-checksig)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--nopgp --nogpg --nomd5 \ + --nodigest --nosignature' -- $cur ) ) + else + _filedir 'rpm' + fi + ;; + -@([Vy]*|-verify)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--root --rcfile --dbpath \ + --nodeps --nogroup --nolinkto --nomode --nomtime \ + --nordev --nouser --nofiles --noscripts --nomd5 \ + --querytags --specfile --whatrequires --whatprovides \ + --nodigest --nosignature' -- $cur ) ) + # check whether we're doing file completion + elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then + _filedir + elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then + _rpm_groups + elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then + _filedir 'rpm' + else + _rpm_installed_packages + fi + ;; + -[bt]*) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--short-circuit --timecheck \ + --clean --rmsource --rmspec --test --sign --buildroot \ + --target -- buildarch --buildos --nobuild --nodeps \ + --nodirtokens' -- $cur ) ) + elif [[ ${COMP_WORDS[1]} == -b* ]]; then + _filedir 'spec' + else + _filedir '@(tgz|tar.@(gz|bz2))' + fi + ;; + --re@(build|compile)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--nodeps --rmsource \ + --rmspec --sign --nodirtokens --target' -- $cur ) ) + else + _filedir '?(no)src.rpm' + fi + ;; + --tarbuild) + _filedir '@(tgz|tar.@(gz|bz2))' + ;; + --@(re|add)sign) + _filedir 'rpm' + ;; + --set@(perms|gids)) + _rpm_installed_packages + ;; + --@(clean|rms@(ource|pec))) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--clean --rmsource \ + --rmspec' -- $cur ) ) + else + _filedir 'spec' + fi + ;; + --@(import|dbpath|root)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--import --dbpath --root' \ + -- $cur ) ) + else + _filedir + fi + ;; + esac + + return 0 +} +complete -F _rpm $filenames rpm rpmbuild +} + +# Debian apt-get(8) completion. +# +have apt-get && +_apt_get() +{ + local cur prev special i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == @(install|remove|purge|source|build-dep) ]]; then + special=${COMP_WORDS[i]} + fi + done + + if [ -n "$special" ]; then + case $special in + remove|purge) + if [ -f /etc/debian_version ]; then + # Debian system + COMPREPLY=( $( _comp_dpkg_installed_packages \ + $cur ) ) + else + # assume RPM based + _rpm_installed_packages + fi + return 0 + ;; + *) + COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) + return 0 + ;; + + esac + fi + + case "$prev" in + -@(c|-config-file)) + _filedir + return 0 + ;; + + -@(t|-target-release|-default-release)) + COMPREPLY=( $( apt-cache policy | \ + grep "release.o=Debian,a=$cur" | \ + sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null) ) + return 0 + ;; + + esac + + if [[ "$cur" == -* ]]; then + + COMPREPLY=( $( compgen -W '-d -f -h -v -m -q -s -y \ + -u -t -b -c -o --download-only --fix-broken \ + --help --version --ignore-missing \ + --fix-missing --no-download --quiet --simulate \ + --just-print --dry-run --recon --no-act --yes \ + --assume-yes --show-upgraded --only-source \ + --compile --build --ignore-hold \ + --target-release --no-upgrade --force-yes \ + --print-uris --purge --reinstall \ + --list-cleanup --default-release \ + --trivial-only --no-remove --diff-only \ + --tar-only --config-file --option --auto-remove' -- $cur ) ) + else + + COMPREPLY=( $( compgen -W 'update upgrade dselect-upgrade \ + dist-upgrade install remove purge source \ + build-dep check clean autoclean autoremove' \ + -- $cur ) ) + + fi + + + return 0 +} && +complete -F _apt_get $filenames apt-get + +# Debian apt-cache(8) completion. +# +have apt-cache && +_apt_cache() +{ + local cur prev special i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + + if [ "$cur" != show ]; then + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == @(add|depends|dotty|policy|rdepends|madison|show?(pkg|src|)) ]]; then + special=${COMP_WORDS[i]} + fi + done + fi + + + if [ -n "$special" ]; then + case $special in + add) + _filedir + return 0 + ;; + + *) + COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) + return 0 + ;; + + esac + fi + + + case "$prev" in + -@(c|p|s|-config-file|-@(pkg|src)-cache)) + _filedir + return 0 + ;; + search) + if [[ "$cur" != -* ]]; then + return 0 + fi + ;; + esac + + if [[ "$cur" == -* ]]; then + + COMPREPLY=( $( compgen -W '-h -v -p -s -q -i -f -a -g -c \ + -o --help --version --pkg-cache --src-cache \ + --quiet --important --full --all-versions \ + --no-all-versions --generate --no-generate \ + --names-only --all-names --recurse \ + --config-file --option' -- $cur ) ) + else + + COMPREPLY=( $( compgen -W 'add gencaches show showpkg showsrc \ + stats dump dumpavail unmet search search \ + depends rdepends pkgnames dotty xvcg \ + policy madison' -- $cur ) ) + + fi + + + return 0 +} && +complete -F _apt_cache $filenames apt-cache + + +# Debian aptitude(1) completion +# +have aptitude && { +have grep-status && { +_comp_dpkg_hold_packages() +{ + grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package +} +} || { +_comp_dpkg_hold_packages() +{ + grep -B 2 'hold' /var/lib/dpkg/status | grep "Package: $1" \ + | cut -d\ -f2 +} +} + +_aptitude() +{ + local cur dashoptions prev special i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + + dashoptions='-S -u -i -h --help --version -s --simulate -d \ + --download-only -P --prompt -y --assume-yes -F \ + --display-format -O --sort -w --width -f -r -g \ + --with-recommends --with-suggests -R -G \ + --without-recommends --without-suggests -t \ + --target-release -V --show-versions -D --show-deps\ + -Z -v --verbose --purge-unused' + + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == @(install|reinstall|hold|unhold|markauto|unmarkauto|dist-upgrade|full-upgrade|download|show|forbid-version|purge|remove|changelog|why|why-not|keep|keep-all) ]]; then + special=${COMP_WORDS[i]} + fi + #exclude some mutually exclusive options + [[ ${COMP_WORDS[i]} == '-u' ]] && dashoptions=${dashoptions/-i} + [[ ${COMP_WORDS[i]} == '-i' ]] && dashoptions=${dashoptions/-u} + done + + if [[ -n "$special" ]]; then + case $special in + @(install|hold|markauto|unmarkauto|dist-upgrade|full-upgrade|download|show|changelog|why|why-not)) + COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) + return 0 + ;; + @(purge|remove|reinstall|forbid-version)) + COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) ) + return 0 + ;; + unhold) + COMPREPLY=( $( _comp_dpkg_hold_packages $cur ) ) + return 0 + ;; + + esac + fi + + case $prev in + # don't complete anything if these options are found + @(autoclean|clean|forget-new|search|upgrade|safe-upgrade|update|keep-all)) + return 0 + ;; + + -S) + _filedir + return 0 + ;; + + -@(t|-target-release|-default-release)) + COMPREPLY=( $( apt-cache policy | \ + grep "release.o=Debian,a=$cur" | \ + sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null ) ) + return 0 + ;; + + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) ) + else + COMPREPLY=( $( compgen -W 'update upgrade safe-upgrade forget-new clean \ + autoclean install reinstall remove \ + hold unhold purge markauto unmarkauto why why-not \ + dist-upgrade full-upgrade download search show \ + forbid-version changelog keep-all' -- $cur ) ) + fi + + + return 0 +} +complete -F _aptitude $default aptitude +} + +# Debian apt-build(1) completion. +# +have apt-build && +_apt_build() +{ + local cur prev special i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == @(install|remove|source|info|clean) ]]; then + special=${COMP_WORDS[i]} + fi + done + + if [ -n "$special" ]; then + case $special in + @(install|source|info)) + COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) + return 0 + ;; + remove) + COMPREPLY=( $( _comp_dpkg_installed_packages \ + $cur ) ) + return 0 + ;; + *) + return 0 + ;; + esac + fi + + case "$prev" in + + --@(patch|build-dir|repository-dir)) + _filedir + return 0 + ;; + + -@(h|-help)) + return 0 + ;; + + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--help --show-upgraded -u --build-dir \ + --repository-dir --build-only \ + --build-command --reinstall --rebuild \ + --remove-builddep --no-wrapper --purge \ + --patch --patch-strip -p --yes -y \ + --version -v --no-source' -- $cur ) ) + + else + COMPREPLY=( $( compgen -W 'update upgrade install remove \ + source dist-upgrade world clean info \ + clean-build update-repository ' -- $cur ) ) + fi + + + return 0 +} && +complete -F _apt_build $filenames apt-build + +# chsh(1) completion +# +_chsh() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [ "$prev" = "-s" ]; then + if [ -f /etc/debian_version ]; then + COMPREPLY=( $( </etc/shells ) ) + else + COMPREPLY=( $( chsh -l | grep "^$cur" ) ) + fi + else + COMPREPLY=( $( compgen -u -- $cur ) ) + fi + + return 0 +} +complete -F _chsh chsh + +# chkconfig(8) completion +# +have chkconfig && +_chkconfig() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + @([1-6]|--@(list|add|del))) + _services + return 0 + ;; + --level) + COMPREPLY=( $( compgen -W '1 2 3 4 5 6' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--list --add --del --level' -- $cur ) ) + else + if [ $COMP_CWORD -eq 2 -o $COMP_CWORD -eq 4 ]; then + COMPREPLY=( $( compgen -W 'on off reset' -- $cur ) ) + else + _services + fi + fi +} && +complete -F _chkconfig chkconfig + +# This function provides simple user@host completion +# +_user_at_host() { + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ $cur == *@* ]]; then + _known_hosts + else + COMPREPLY=( $( compgen -u -- "$cur" ) ) + fi + + return 0 +} +shopt -u hostcomplete && complete -F _user_at_host $nospace talk ytalk finger + +# This function performs host completion based on ssh's known_hosts files, +# defaulting to standard host completion if they don't exist. +# +_known_hosts() +{ + local cur curd ocur user suffix aliases global_kh user_kh hosts i host + local -a kh khd config + + COMPREPLY=() + cur=`_get_cword` + ocur=$cur + + [ "$1" = -a ] || [ "$2" = -a ] && aliases='yes' + [ "$1" = -c ] || [ "$2" = -c ] && suffix=':' + [[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@} + kh=() + + # ssh config files + [ -r /etc/ssh/ssh_config ] && + config=( "${config[@]}" "/etc/ssh/ssh_config" ) + [ -r "${HOME}/.ssh/config" ] && + config=( "${config[@]}" "${HOME}/.ssh/config" ) + [ -r "${HOME}/.ssh2/config" ] && + config=( "${config[@]}" "${HOME}/.ssh2/config" ) + + if [ ${#config[@]} -gt 0 ]; then + # expand path (if present) to global known hosts file + global_kh=$( eval echo $( sed -ne 's/^[ \t]*[Gg][Ll][Oo][Bb][Aa][Ll][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' "${config[@]}" ) ) + # expand path (if present) to user known hosts file + user_kh=$( eval echo $( sed -ne 's/^[ \t]*[Uu][Ss][Ee][Rr][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' "${config[@]}" ) ) + fi + + # Global known_hosts files + [ -r "$global_kh" ] && + kh=( "${kh[@]}" "$global_kh" ) + [ -r /etc/ssh/ssh_known_hosts ] && + kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts ) + [ -r /etc/ssh/ssh_known_hosts2 ] && + kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts2 ) + [ -r /etc/known_hosts ] && + kh=( "${kh[@]}" /etc/known_hosts ) + [ -r /etc/known_hosts2 ] && + kh=( "${kh[@]}" /etc/known_hosts2 ) + [ -d /etc/ssh2/knownhosts ] && + khd=( "${khd[@]}" /etc/ssh2/knownhosts/*pub ) + + # User known_hosts files + [ -r "$user_kh" ] && + kh=( "${kh[@]}" "$user_kh" ) + [ -r ~/.ssh/known_hosts ] && + kh=( "${kh[@]}" ~/.ssh/known_hosts ) + [ -r ~/.ssh/known_hosts2 ] && + kh=( "${kh[@]}" ~/.ssh/known_hosts2 ) + [ -d ~/.ssh2/hostkeys ] && + khd=( "${khd[@]}" ~/.ssh2/hostkeys/*pub ) + + # If we have known_hosts files to use + if [ ${#kh[@]} -gt 0 -o ${#khd[@]} -gt 0 ]; then + # Escape slashes and dots in paths for awk + cur=${cur//\//\\\/} + cur=${cur//\./\\\.} + curd=$cur + + if [[ "$cur" == [0-9]*.* ]]; then + # Digits followed by a dot - just search for that + cur="^$cur.*" + elif [[ "$cur" == [0-9]* ]]; then + # Digits followed by no dot - search for digits followed + # by a dot + cur="^$cur.*\." + elif [ -z "$cur" ]; then + # A blank - search for a dot or an alpha character + cur="[a-z.]" + else + cur="^$cur" + fi + + if [ ${#kh[@]} -gt 0 ]; then + + # FS needs to look for a comma separated list + COMPREPLY=( $( awk 'BEGIN {FS=","} + /^[^|]/ {for (i=1; i<=2; ++i) { \ + gsub(" .*$", "", $i); \ + if ($i ~ /'$cur'/) {print $i} \ + }}' "${kh[@]}" 2>/dev/null ) ) + fi + if [ ${#khd[@]} -gt 0 ]; then + # Needs to look for files called + # .../.ssh2/key_22_<hostname>.pub + # dont fork any processes, because in a cluster environment, + # there can be hundreds of hostkeys + for i in "${khd[@]}" ; do + if [[ "$i" == *key_22_$curd*.pub ]] && [ -r "$i" ] ; then + host=${i/#*key_22_/} + host=${host/%.pub/} + COMPREPLY=( "${COMPREPLY[@]}" $host ) + fi + done + fi + + # append any available aliases from config files + if [ ${#config[@]} -gt 0 ] && [ -n "$aliases" ]; then + local host_aliases=$( sed -ne 's/^[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\?['"$'\t '"']\+\([^*?]*\)$/\2/p' "${config[@]}" ) + hosts=$( compgen -W "$host_aliases" -- $ocur ) + COMPREPLY=( "${COMPREPLY[@]}" $hosts ) + fi + + # Now add results of normal hostname completion + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -A hostname -- $ocur ) ) + + # apply suffix + for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do + COMPREPLY[i]=$user${COMPREPLY[i]}$suffix + done + else + # Just do normal hostname completion + COMPREPLY=( $( compgen -A hostname -S "$suffix" -- $cur ) ) + fi + + return 0 +} +complete -F _known_hosts traceroute traceroute6 tracepath tracepath6 \ + ping ping6 fping fping6 telnet host nslookup rsh rlogin ftp dig ssh-installkeys mtr + +# ssh(1) completion +# +have ssh && { +_ssh() +{ + local cur prev + local -a config + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -*c) + COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \ + arcfour cast128-cbc' -- $cur ) ) + ;; + -*i) + _filedir + ;; + -*l) + COMPREPLY=( $( compgen -u -- $cur ) ) + ;; + *) + _known_hosts -a + + [ $COMP_CWORD -eq 1 ] || \ + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) ) + esac + + return 0 +} +shopt -u hostcomplete && complete -F _ssh ssh slogin sftp xhost autossh + +# scp(1) completion +# +_scp() +{ + local cur userhost path + + COMPREPLY=() + cur=`_get_cword` + + _expand || return 0 + + if [[ "$cur" == *:* ]]; then + local IFS=$'\t\n' + # remove backslash escape from : + cur=${cur/\\:/:} + userhost=${cur%%?(\\):*} + path=${cur#*:} + # unescape spaces + path=${path//\\\\\\\\ / } + if [ -z "$path" ]; then + # default to home dir of specified user on remote host + path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null) + fi + # escape spaces; remove executables, aliases, pipes and sockets; + # add space at end of file names + COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \ + command ls -aF1d "$path*" 2>/dev/null | \ + sed -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\\\\\\\\\&/g" \ + -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) ) + return 0 + fi + + [[ "$cur" == */* ]] || _known_hosts -c -a + local IFS=$'\t\n' + COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \ + 2>/dev/null | sed \ + -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\&/g" \ + -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) ) + return 0 +} +complete -F _scp $nospace scp +} + +# rsync(1) completion +# +have rsync && +_rsync() +{ + local cur prev shell i userhost path + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + _expand || return 0 + + case "$prev" in + --@(config|password-file|include-from|exclude-from)) + _filedir + return 0 + ;; + -@(T|-temp-dir|-compare-dest)) + _filedir -d + return 0 + ;; + -@(e|-rsh)) + COMPREPLY=( $( compgen -W 'rsh ssh' -- $cur ) ) + return 0 + ;; + esac + + case "$cur" in + -*) + COMPREPLY=( $( compgen -W '-v -q -c -a -r -R -b -u -l -L -H \ + -p -o -g -D -t -S -n -W -x -B -e -C -I -T -P \ + -z -h -4 -6 --verbose --quiet --checksum \ + --archive --recursive --relative --backup \ + --backup-dir --suffix= --update --links \ + --copy-links --copy-unsafe-links --safe-links \ + --hard-links --perms --owner --group --devices\ + --times --sparse --dry-run --whole-file \ + --no-whole-file --one-file-system \ + --block-size= --rsh= --rsync-path= \ + --cvs-exclude --existing --ignore-existing \ + --delete --delete-excluded --delete-after \ + --ignore-errors --max-delete= --partial \ + --force --numeric-ids --timeout= \ + --ignore-times --size-only --modify-window= \ + --temp-dir= --compare-dest= --compress \ + --exclude= --exclude-from= --include= \ + --include-from= --version --daemon --no-detach\ + --address= --config= --port= --blocking-io \ + --no-blocking-io --stats --progress \ + --log-format= --password-file= --bwlimit= \ + --write-batch= --read-batch= --help' -- $cur )) + ;; + *:*) + # find which remote shell is used + shell=rsh + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then + shell=${COMP_WORDS[i+1]} + break + fi + done + if [[ "$shell" == ssh ]]; then + # remove backslash escape from : + cur=${cur/\\:/:} + userhost=${cur%%?(\\):*} + path=${cur#*:} + # unescape spaces + path=${path//\\\\\\\\ / } + if [ -z "$path" ]; then + # default to home dir of specified + # user on remote host + path=$(ssh -o 'Batchmode yes' \ + $userhost pwd 2>/dev/null) + fi + # escape spaces; remove executables, aliases, pipes + # and sockets; add space at end of file names + COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \ + command ls -aF1d "$path*" 2>/dev/null | \ + sed -e 's/ /\\\\\\\ /g' -e 's/[*@|=]$//g' \ + -e 's/[^\/]$/& /g' ) ) + fi + ;; + *) + _known_hosts -c -a + _filedir + ;; + esac + + return 0 +} && +complete -F _rsync $nospace $filenames rsync + +# Linux route(8) completion +# +[ $UNAME = Linux ] && +_route() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [ "$prev" = dev ]; then + COMPREPLY=( $( ifconfig -a | sed -ne 's|^\('$cur'[^ ]*\).*$|\1|p' )) + return 0 + fi + + COMPREPLY=( $( compgen -W 'add del -host -net netmask metric mss \ + window irtt reject mod dyn reinstate dev \ + default gw' -- $cur ) ) + + COMPREPLY=( $( echo " ${COMP_WORDS[@]}" | \ + (while read -d ' ' i; do + [ "$i" == "" ] && continue + # flatten array with spaces on either side, + # otherwise we cannot grep on word + # boundaries of first and last word + COMPREPLY=" ${COMPREPLY[@]} " + # remove word from list of completions + COMPREPLY=( ${COMPREPLY/ $i / } ) + done + echo "${COMPREPLY[@]}") + ) ) + return 0 +} +[ $UNAME = Linux ] && complete -F _route route + +# GNU make(1) completion +# +have make || have gmake || have gnumake || have pmake && +_make() +{ + local file makef makef_dir="." makef_inc cur prev i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # --name value style option + case $prev in + -@(f|o|W)) + _filedir + return 0 + ;; + -@(I|C)) + _filedir -d + return 0 + ;; + esac + + # --name=value style option + if [[ "$cur" == *=* ]]; then + prev=${cur/=*/} + cur=${cur/*=/} + case "$prev" in + --@(file|makefile)) + _filedir + return 0 + ;; + --@(directory|include-dir)) + _filedir -d + return 0 + ;; + esac + fi + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\ + -j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \ + --always-make --directory= --debug \ + --environment-overrides --file= --makefile= --help \ + --ignore-errors --include-dir= --jobs --load-average \ + --max-load --keep-going --just-print --dry-run \ + --recon --old-file= --assume-old= --print-data-base \ + --question --no-builtin-rules --no-builtin-variables \ + --silent --quiet --no-keep-goind --stop --touch \ + --version --print-directory --no-print-directory \ + --what-if= --new-file= --assume-new= \ + --warn-undefined-variables' -- $cur ) ) + else + # before we check for makefiles, see if a path was specified + # with -C + for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do + if [[ ${COMP_WORDS[i]} == -C ]]; then + # eval for tilde expansion + eval makef_dir=${COMP_WORDS[i+1]} + break + fi + done + + # make reads `GNUmakefile', then `makefile', then `Makefile' + if [ -f ${makef_dir}/GNUmakefile ]; then + makef=${makef_dir}/GNUmakefile + elif [ -f ${makef_dir}/makefile ]; then + makef=${makef_dir}/makefile + elif [ -f ${makef_dir}/Makefile ]; then + makef=${makef_dir}/Makefile + else + makef=${makef_dir}/*.mk # local convention + fi + + # before we scan for targets, see if a Makefile name was + # specified with -f + for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do + if [[ ${COMP_WORDS[i]} == -f ]]; then + # eval for tilde expansion + eval makef=${COMP_WORDS[i+1]} + break + fi + done + + [ ! -f $makef ] && return 0 + + # deal with included Makefiles + makef_inc=$( grep -E '^-?include' $makef | sed -e "s,^.* ,"$makef_dir"/," ) + + for file in $makef_inc; do + [ -f $file ] && makef="$makef $file" + done + + COMPREPLY=( $( awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \ + {split($1,A,/ /);for(i in A)print A[i]}' \ + $makef 2>/dev/null | command grep "^$cur" )) + fi +} && +complete -f -F _make $filenames make gmake gnumake pmake + +# GNU tar(1) completion +# +_tar() +{ + local cur ext regex tar untar + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) ) + return 0 + fi + + case "${COMP_WORDS[1]}" in + ?(-)[cr]*f) + _filedir + return 0 + ;; + +([^IZzjy])f) + ext='t@(ar?(.@(Z|gz|bz?(2)))|gz|bz?(2))' + regex='t\(ar\(\.\(Z\|gz\|bz2\?\)\)\?\|gz\|bz2\?\)' + ;; + *[Zz]*f) + ext='t?(ar.)@(gz|Z)' + regex='t\(ar\.\)\?\(gz\|Z\)' + ;; + *[Ijy]*f) + ext='t?(ar.)bz?(2)' + regex='t\(ar\.\)\?bz2\?' + ;; + *) + _filedir + return 0 + ;; + + esac + + if [[ "$COMP_LINE" == *$ext' ' ]]; then + # complete on files in tar file + # + # get name of tar file from command line + tar=$( echo "$COMP_LINE" | \ + sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' ) + # devise how to untar and list it + untar=t${COMP_WORDS[1]//[^Izjyf]/} + + COMPREPLY=( $( compgen -W "$( echo $( tar $untar $tar \ + 2>/dev/null ) )" -- "$cur" ) ) + return 0 + fi + + # file completion on relevant files + _filedir "$ext" + + return 0 +} +[ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar $dirnames tar || + complete -F _tar $filenames tar + +# jar(1) completion +# +have jar && +_jar() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD = 1 ]; then + COMPREPLY=( $( compgen -W 'c t x u' -- $cur ) ) + return 0 + fi + + case "${COMP_WORDS[1]}" in + *c*f) + _filedir + ;; + *f) + _filedir '?(e|j|w)ar' + ;; + *) + _filedir + ;; + esac +} && +complete -F _jar $filenames jar + +# Linux iptables(8) completion +# +have iptables && +_iptables() +{ + local cur prev table chain + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + chain='s/^Chain \([^ ]\+\).*$/\1/p' + + if [[ $COMP_LINE == *-t\ *filter* ]]; then + table="-t filter" + elif [[ $COMP_LINE == *-t\ *nat* ]]; then + table="-t nat" + elif [[ $COMP_LINE == *-t\ *mangle* ]]; then + table="-t mangle" + fi + + case "$prev" in + -*[AIDRPFXLZ]) + COMPREPLY=( $( compgen -W '`iptables $table -nL | \ + sed -ne "s/^Chain \([^ ]\+\).*$/\1/p"`' -- $cur ) ) + ;; + -*t) + COMPREPLY=( $( compgen -W 'nat filter mangle' -- $cur ) ) + ;; + -j) + if [ "$table" = "-t filter" -o "$table" = "" ]; then + COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \ + `iptables $table -nL | sed -ne "$chain" \ + -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \ + $cur ) ) + elif [ "$table" = "-t nat" ]; then + COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \ + MIRROR SNAT DNAT MASQUERADE `iptables $table -nL | \ + sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \ + -- $cur ) ) + elif [ "$table" = "-t mangle" ]; then + COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \ + MARK TOS `iptables $table -nL | sed -ne "$chain" \ + -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \ + $cur ) ) + fi + ;; + *) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-i -o -s -d -p -f -m --append \ + --delete --insert --replace --list --flush --zero --new \ + --delete-chain --policy --rename-chain --proto --source \ + --destination --in-interface --jump --match --numeric \ + --out-interface --table --verbose --line-numbers --exact \ + --fragment --modprobe= --set-counters --version' -- "$cur") ) + fi + ;; + esac + +} && +complete -F _iptables iptables + +# tcpdump(8) completion +# +have tcpdump && +_tcpdump() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(r|w|F)) + _filedir + return 0 + ;; + -i) + _available_interfaces -a + return 0 + ;; + esac + + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-a -d -e -f -l -n -N -O -p \ + -q -R -S -t -u -v -x -C -F -i -m -r -s -T -w \ + -E' -- $cur ) ) + fi + +} && +complete -F _tcpdump tcpdump + +# autorpm(8) completion +# +have autorpm && +_autorpm() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + COMPREPLY=( $( compgen -W '--notty --debug --help --version \ + auto add fullinfo info help install list \ + remove set' -- $cur ) ) + +} && +complete -F _autorpm autorpm + +# This meta-cd function observes the CDPATH variable, so that cd additionally +# completes on directories under those specified in CDPATH. +# +_cd() +{ + local IFS=$'\t\n' cur=`_get_cword` i j k + + # try to allow variable completion + if [[ "$cur" == ?(\\)\$* ]]; then + COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) ) + return 0 + fi + + # Use standard dir completion if no CDPATH or parameter starts with /, + # ./ or ../ + if [ -z "${CDPATH:-}" ] || [[ "$cur" == ?(.)?(.)/* ]]; then + _filedir -d + return 0 + fi + + local -r mark_dirs=$(_rl_enabled mark-directories && echo y) + local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y) + + # we have a CDPATH, so loop on its contents + for i in ${CDPATH//:/$'\t'}; do + # create an array of matched subdirs + k="${#COMPREPLY[@]}" + for j in $( compgen -d $i/$cur ); do + if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then + j="${j}/" + fi + COMPREPLY[k++]=${j#$i/} + done + done + + _filedir -d + + if [[ ${#COMPREPLY[@]} -eq 1 ]]; then + i=${COMPREPLY[0]} + if [ "$i" == "$cur" ] && [[ $i != "*/" ]]; then + COMPREPLY[0]="${i}/" + fi + fi + + return 0 +} +if shopt -q cdable_vars; then + complete -v -F _cd $nospace $filenames cd +else + complete -F _cd $nospace $filenames cd +fi + +_remove_comp_word() +{ + if [[ COMP_CWORD -eq 0 ]]; then + return + elif [[ ${#COMP_WORDS[@]} -ge 2 ]]; then + local old_cw0="${COMP_WORDS[0]}" + local new_cw0="${COMP_WORDS[1]}" + local old_length="${#COMP_LINE}" + COMP_LINE=${COMP_LINE#${old_cw0}} + local head=${COMP_LINE:0:${#new_cw0}} + local i=1 + while [[ $head != $new_cw0 ]]; do + COMP_LINE=${COMP_LINE:1} + head=${COMP_LINE:0:${#new_cw0}} + if (( ++i > 10 )); then + break + fi + done + local new_length="${#COMP_LINE}" + COMP_POINT=$(( COMP_POINT + new_length - old_length)) + + COMP_CWORD=$(( COMP_CWORD - 1 )) + for (( i=0; i < ${#COMP_WORDS[@]} - 1; ++i )); do + COMP_WORDS[i]="${COMP_WORDS[i+1]}" + done + unset COMP_WORDS[${#COMP_WORDS[@]}-1] + else + return + fi +} + +# A meta-command completion function for commands like sudo(8), which need to +# first complete on a command, then complete according to that command's own +# completion definition - currently not quite foolproof (e.g. mount and umount +# don't work properly), but still quite useful. +# +_command() +{ + local cur func cline cspec noglob cmd done i \ + _COMMAND_FUNC _COMMAND_FUNC_ARGS + + _remove_comp_word + COMPREPLY=() + cur=`_get_cword` + # If the the first arguments following our meta-command-invoker are + # switches, get rid of them. Most definitely not foolproof. + done= + while [ -z $done ] ; do + cmd=${COMP_WORDS[0]} + if [[ "$cmd" == -* ]] && [ $COMP_CWORD -ge 1 ]; then + _remove_comp_word + elif [[ "$cmd" == -* ]] && [[ $COMP_CWORD -eq 0 ]]; then + return + else + done=1 + fi + done + + if [ $COMP_CWORD -eq 0 ]; then + COMPREPLY=( $( compgen -c -- $cur ) ) + elif complete -p $cmd &>/dev/null; then + cspec=$( complete -p $cmd ) + if [ "${cspec#* -F }" != "$cspec" ]; then + # COMP_CWORD and COMP_WORDS() are not read-only, + # so we can set them before handing off to regular + # completion routine + + # get function name + func=${cspec#*-F } + func=${func%% *} + + if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then + $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}" + else + $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" + fi + + # remove any \: generated by a command that doesn't + # default to filenames or dirnames (e.g. sudo chown) + # FIXME: I'm pretty sure this does not work! + if [ "${cspec#*-o }" != "$cspec" ]; then + cspec=${cspec#*-o } + cspec=${cspec%% *} + if [[ "$cspec" != @(dir|file)names ]]; then + COMPREPLY=("${COMPREPLY[@]//\\\\:/:}") + fi + fi + elif [ -n "$cspec" ]; then + cspec=${cspec#complete}; + cspec=${cspec%%$cmd}; + COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) ); + fi + fi + + [ ${#COMPREPLY[@]} -eq 0 ] && _filedir +} +complete -F _command $filenames nohup exec nice eval strace time ltrace then \ + else do vsound command xargs + +_root_command() +{ + PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 $2 $3 +} +complete -F _root_command $filenames sudo fakeroot really + +# ant(1) completion +# +have ant && { +_ant() +{ + local cur prev buildfile i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -buildfile|-f) + _filedir 'xml' + return 0 + ;; + -logfile) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + # relevant options completion + COMPREPLY=( $( compgen -W '-help -projecthelp -version -quiet \ + -verbose -debug -emacs -logfile -logger \ + -listener -buildfile -f -D -find' -- $cur ) ) + else + # available targets completion + # find which buildfile to use + buildfile=build.xml + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == -buildfile ]]; then + buildfile=${COMP_WORDS[i+1]} + break + fi + done + [ ! -f $buildfile ] && return 0 + + # parse buildfile for targets + COMPREPLY=( $( awk -F'"' '/<target name="/ {print $2}' \ + $buildfile | grep "^$cur" ) + $( awk -F"'" "/<target name='/ "'{print $2}' \ + $buildfile | grep "^$cur" ) + $( awk -F'"' '/<target [^n]/ {if ($1 ~ /name=/) { print $2 } else if ($3 ~ /name=/) {print $4} else if ($5 ~ /name=/) {print $6}}' \ + $buildfile | grep "^$cur" ) ) + fi +} +have complete-ant-cmd.pl && \ + complete -C complete-ant-cmd.pl -F _ant $filenames ant || \ + complete -F _ant $filenames ant +} + +have nslookup && +_nslookup() +{ + local cur + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]#-} + + COMPREPLY=( $( compgen -P '-' -W 'all class= debug d2 domain= \ + srchlist= defname search port= querytype= \ + type= recurse retry root timeout vc \ + ignoretc' -- $cur ) ) +} && +complete -F _nslookup nslookup + +# mysqladmin(1) completion +# +have mysqladmin && +_mysqladmin() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -u) + COMPREPLY=( $( compgen -u -- $cur ) ) + return 0 + ;; + *) + ;; + esac + + COMPREPLY=( $( compgen -W '-# -f -? -C -h -p -P -i -r -E -s -S -t -u \ + -v -V -w' -- $cur ) ) + + COMPREPLY=( "${COMPREPLY[@]}" \ + $( compgen -W 'create drop extended-status flush-hosts \ + flush-logs flush-status flush-tables \ + flush-threads flush-privileges kill \ + password ping processlist reload refresh \ + shutdown status variables version' \ + -- $cur ) ) +} && +complete -F _mysqladmin mysqladmin + +# gzip(1) completion +# +have gzip && +_gzip() +{ + local cur prev xspec IFS=$'\t\n' + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c -d -f \ + -h -l -L -n -N -q -r -S -t -v -V \ + -1 -2 -3 -4 -5 -6 -7 -8 -9 \ + --stdout --decompress --force --help --list \ + --license --no-name --name --quiet --recursive \ + --suffix --test --verbose --version --fast \ + --best' -- $cur ) ) + return 0 + fi + + xspec="*.?(t)gz" + if [[ "$prev" == --* ]]; then + [[ "$prev" == --decompress || \ + "$prev" == --list || \ + "$prev" == --test ]] && xspec="!"$xspec + [[ "$prev" == --force ]] && xspec= + elif [[ "$prev" == -* ]]; then + [[ "$prev" == -*[dlt]* ]] && xspec="!"$xspec + [[ "$prev" == -*f* ]] && xspec= + elif [ "$prev" = '>' ]; then + xspec= + elif [ "$prev" = '<' ]; then + xspec= + fi + + _expand || return 0 + + COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \ + $( compgen -d -- $cur ) ) +} && +complete -F _gzip $filenames gzip + +# bzip2(1) completion +# +have bzip2 && +_bzip2() +{ + local cur prev xspec IFS=$'\t\n' + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c -d -f -h -k -L -q -s \ + -t -v -V -z -1 -2 -3 -4 -5 -6 -7 -8 -9 \ + --help --decompress --compress --keep --force \ + --test --stdout --quiet --verbose --license \ + --version --small --fast --best' -- $cur ) ) + return 0 + fi + + xspec="*.bz2" + if [[ "$prev" == --* ]]; then + [[ "$prev" == --decompress || \ + "$prev" == --list || \ + "$prev" == --test ]] && xspec="!"$xspec + [[ "$prev" == --compress ]] && xspec= + elif [[ "$prev" == -* ]]; then + [[ "$prev" == -*[dt]* ]] && xspec="!"$xspec + [[ "$prev" == -*z* ]] && xspec= + fi + + _expand || return 0 + + COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \ + $( compgen -d -- $cur ) ) +} && +complete -F _bzip2 $filenames bzip2 + +# openssl(1) completion +# +have openssl && { +_openssl_sections() +{ + local config + + config=/etc/ssl/openssl.cnf + [ ! -f $config ] && config=/usr/share/ssl/openssl.cnf + for (( i=2; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == -config ]]; then + config=${COMP_WORDS[i+1]} + break + fi + done + [ ! -f $config ] && return 0 + + COMPREPLY=( $( awk '/\[.*\]/ {print $2} ' $config | grep "^$cur" ) ) +} + +_openssl() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W 'asn1parse ca ciphers crl crl2pkcs7 \ + dgst dh dhparam dsa dsaparam enc errstr gendh gendsa \ + genrsa nseq passwd pkcs12 pkcs7 pkcs8 rand req rsa \ + rsautl s_client s_server s_time sess_id smime speed \ + spkac verify version x509 md2 md4 md5 mdc2 rmd160 sha \ + sha1 base64 bf bf-cbc bf-cfb bf-ecb bf-ofb cast \ + cast-cbc cast5-cbc cast5-cfb cast5-ecb cast5-ofb des \ + des-cbc des-cfb des-ecb des-ede des-ede-cbc \ + des-ede-cfb des-ede-ofb des-ede3 des-ede3-cbc \ + des-ede3-cfb des-ede3-ofb des-ofb des3 desx rc2 \ + rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb \ + rc4 rc4-40' -- $cur ) ) + else + prev=${COMP_WORDS[COMP_CWORD-1]} + case ${COMP_WORDS[1]} in + asn1parse) + case $prev in + -inform) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out|oid)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -in -out -noout -offset \ + -length -i -oid -strparse' -- $cur ) ) + fi + ;; + ca) + case $prev in + -@(config|revoke|cert|in|out|spkac|ss_cert)) + _filedir + return 0 + ;; + -outdir) + _filedir -d + return 0 + ;; + -@(name|crlexts|extensions)) + _openssl_sections + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-verbose -config -name \ + -gencrl -revoke -crldays -crlhours -crlexts \ + -startdate -enddate -days -md -policy -keyfile \ + -key -passin -cert -in -out -notext -outdir \ + -infiles -spkac -ss_cert -preserveDN -batch \ + -msie_hack -extensions' -- $cur ) ) + fi + ;; + ciphers) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-v -ssl2 -ssl3 -tls1' -- $cur ) ) + fi + ;; + crl) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out|CAfile)) + _filedir + return 0 + ;; + -CAPath) + _filedir -d + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -text -in -out -noout \ + -hash -issuer -lastupdate -nextupdate -CAfile -CApath' -- $cur ) ) + fi + ;; + crl2pkcs7) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -in -out -print_certs' -- $cur ) ) + fi + ;; + dgst) + case $prev in + -@(out|sign|verify|prvrify|signature)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-md5 -md4 -md2 -sha1 -sha -mdc2 -ripemd160 -dss1 \ + -c -d -hex -binary -out -sign -verify -prverify -signature' -- $cur ) ) + else + _filedir + fi + ;; + dsa) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -in -passin -out -passout -des -des3 -idea -text -noout \ + -modulus -pubin -pubout' -- $cur ) ) + fi + ;; + dsaparam) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out|rand)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -in -out -noout \ + -text -C -rand -genkey' -- $cur ) ) + fi + ;; + enc) + case $prev in + -@(in|out|kfile)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-ciphername -in -out -pass \ + -e -d -a -A -k -kfile -S -K -iv -p -P -bufsize -debug' -- $cur ) ) + fi + ;; + dhparam) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out|rand)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -in -out -dsaparam -noout \ + -text -C -2 -5 -rand' -- $cur ) ) + fi + ;; + gendsa) + case $prev in + -@(out|rand)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-out -des -des3 -idea -rand' -- $cur ) ) + else + _filedir + fi + ;; + genrsa) + case $prev in + -@(out|rand)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-out -passout -des -des3 -idea -f4 -3 -rand' -- $cur ) ) + fi + ;; + pkcs7) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -in -out -print_certs -text -noout' -- $cur ) ) + fi + ;; + rand) + case $prev in + -@(out|rand)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-out -rand -base64' -- $cur ) ) + fi + ;; + req) + case "$prev" in + -@(in|out|key)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + + -@(in|out|rand|key|keyout|config)) + _filedir + return 0 + ;; + -extensions) + _openssl_sections + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -in \ + -passin -out -passout -text -noout -verify \ + -modulus -new -rand -newkey -newkey -nodes \ + -key -keyform -keyout -md5 -sha1 -md2 -mdc2 \ + -config -x509 -days -asn1-kludge -newhdr \ + -extensions -reqexts section' -- $cur ) ) + fi + ;; + rsa) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER NET PEM' -- $cur ) ) + return 0 + ;; + -@(in|out)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -in -passin -out -passout \ + -sgckey -des -des3 -idea -text -noout -modulus -check -pubin \ + -pubout -engine' -- $cur ) ) + fi + ;; + rsautl) + case $prev in + -@(in|out|inkey)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-in -out -inkey -pubin -certin -sign -verify \ + -encrypt -decrypt -pkcs -ssl -raw -hexdump -asn1parse' -- $cur ) ) + fi + ;; + s_client) + case $prev in + -connect) + _known_hosts + return 0 + ;; + -@(cert|key|CAfile|rand)) + _filedir + return 0 + ;; + -CApath) + _filedir -d + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-connect -verify -cert -key -CApath -CAfile \ + -reconnect -pause -showcerts -debug -msg -nbio_test -state -nbio \ + -crlf -ign_eof -quiet -ssl2 -ssl3 -tls1 -no_ssl2 -no_ssl3 -no_tls1 \ + -bugs -cipher -starttls -engine -rand' -- $cur ) ) + fi + ;; + s_server) + case $prev in + -@(cert|key|dcert|dkey|dhparam|CAfile|rand)) + _filedir + return 0 + ;; + -CApath) + _filedir -d + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-accept -context -verify -Verify -cert -key \ + -dcert -dkey -dhparam -nbio -nbio_test -crlf -debug -msg -state -CApath \ + -CAfile -nocert -cipher -quiet -no_tmp_rsa -ssl2 -ssl3 -tls1 -no_ssl2 \ + -no_ssl3 -no_tls1 -no_dhe -bugs -hack -www -WWW -HTTP -engine -id_prefix \ + -rand' -- $cur ) ) + fi + ;; + s_time) + case $prev in + -connect) + _known_hosts + return 0 + ;; + -@(cert|key|CAfile)) + _filedir + return 0 + ;; + -CApath) + _filedir -d + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-connect -www -cert -key -CApath -CAfile -reuse \ + -new -verify -nbio -time -ssl2 -ssl3 -bugs -cipher' -- $cur ) ) + fi + ;; + + sess_id) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out)) + _filedir + return 0 + ;; + esac + + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform -in -out -text -noout \ + -context ID' -- $cur ) ) + fi + ;; + smime) + case $prev in + -@(in|out)form) + COMPREPLY=( $( compgen -W 'SMIME DER PEM' -- $cur ) ) + return 0 + ;; + -@(in|out|certfile|signer|recip|inkey|content|rand)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-encrypt -decrypt -sign -verify -pk7out -des -des3 \ + -rc2-40 -rc2-64 -rc2-128 -aes128 -aes192 -aes256 -in -certfile -signer \ + -recip -inform -passin -inkey -out -outform -content -to -from -subject \ + -text -rand' -- $cur ) ) + else + _filedir + fi + ;; + speed) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-engine' -- $cur ) ) + else + COMPREPLY=( $( compgen -W 'md2 mdc2 md5 hmac sha1 rmd160 idea-cbc \ + rc2-cbc rc5-cbc bf-cbc des-cbc des-ede3 rc4 rsa512 rsa1024 rsa2048 \ + rsa4096 dsa512 dsa1024 dsa2048 idea rc2 des rsa blowfish' -- $cur ) ) + fi + ;; + verify) + case $prev in + -@(CAfile|untrusted)) + _filedir + return 0 + ;; + -CApath) + _filedir -d + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-CApath -CAfile -purpose -untrusted -help -issuer_checks \ + -verbose -certificates' -- $cur ) ) + else + _filedir + fi + ;; + x509) + case "$prev" in + -@(in|out|CA|CAkey|CAserial|extfile)) + _filedir + return 0 + ;; + -@(in|out)form) + COMPREPLY=( $( compgen -W 'DER PEM NET' -- $cur ) ) + return 0 + ;; + -@(key|CA|CAkey)form) + COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) ) + return 0 + ;; + -extensions) + _openssl_sections + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-inform -outform \ + -keyform -CAform -CAkeyform -in -out \ + -serial -hash -subject -issuer -nameopt \ + -email -startdate -enddate -purpose \ + -dates -modulus -fingerprint -alias \ + -noout -trustout -clrtrust -clrreject \ + -addtrust -addreject -setalias -days \ + -set_serial -signkey -x509toreq -req \ + -CA -CAkey -CAcreateserial -CAserial \ + -text -C -md2 -md5 -sha1 -mdc2 -clrext \ + -extfile -extensions -engine' -- $cur ) ) + fi + ;; + @(md5|md4|md2|sha1|sha|mdc2|ripemd160)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c -d' -- $cur ) ) + else + _filedir + fi + ;; + esac + fi + + return 0 +} +complete -F _openssl $default openssl +} + +# screen(1) completion +# +have screen && +_screen() +{ + local cur prev preprev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + [ "$COMP_CWORD" -ge 2 ] && preprev=${COMP_WORDS[COMP_CWORD-2]} + + if [ "$preprev" = "-d" -o "$preprev" = "-D" -a "$prev" = "-r" -o \ + "$prev" = "-R" ]; then + # list all + COMPREPLY=( $( command screen -ls | \ + sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*$|\1|p' ) ) + else + case "$prev" in + -[rR]) + # list detached + COMPREPLY=( $( command screen -ls | \ + sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Detached.*$|\1|p' ) ) + ;; + -[dDx]) + # list attached + COMPREPLY=( $( command screen -ls | \ + sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Attached.*$|\1|p' ) ) + ;; + -s) + # shells + COMPREPLY=( $( grep ^${cur:-[^#]} /etc/shells ) ) + ;; + *) + ;; + esac + fi + + return 0 +} && +complete -F _screen $default screen + +# lftp(1) bookmark completion +# +have lftp && +_lftp() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ] && [ -f ~/.lftp/bookmarks ]; then + COMPREPLY=( $( compgen -W '$( sed -ne "s/^\(.*\)'$'\t''.*$/\1/p" \ + ~/.lftp/bookmarks )' -- $cur ) ) + fi + + return 0 +} && +complete -F _lftp $default lftp + +# ncftp(1) bookmark completion +# +have ncftp && +_ncftp() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ] && [ -f ~/.ncftp/bookmarks ]; then + COMPREPLY=( $( compgen -W '$( sed -ne "s/^\([^,]\{1,\}\),.*$/\1/p" \ + ~/.ncftp/bookmarks )' -- $cur ) ) + fi + + return 0 +} && +complete -F _ncftp $default ncftp + +# gdb(1) completion +# +have gdb && +_gdb() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -c -- $cur ) ) + elif [ $COMP_CWORD -eq 2 ]; then + prev=${prev##*/} + COMPREPLY=( $( compgen -fW "$( command ps axo comm,pid | \ + awk '{if ($1 ~ /^'"$prev"'/) print $2}' ) )" \ + -- "$cur" ) ) + fi +} && +complete -F _gdb $filenames gdb + +# Postgresql completion +# +have psql && { +_pg_databases() +{ + return + COMPREPLY=( $( psql -l 2>/dev/null | \ + sed -e '1,/^-/d' -e '/^(/,$d' | \ + awk '{print $1}' | grep "^$cur" ) ) +} + +_pg_users() +{ + #COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \ + # grep "^ $cur" ) ) + #[ ${#COMPREPLY[@]} -eq 0 ] && + COMPREPLY=( $( compgen -u -- $cur ) ) +} + +# createdb(1) completion +# +_createdb() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(h|-host=)) + _known_hosts + return 0 + ;; + -@(U|-username=)) + _pg_users + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-D -T -E -h -p -U -W -e -q \ + --location= --template= --encoding= --host= --port= \ + --username= --password --echo --quiet --help' -- $cur )) + else + _pg_databases + fi +} +complete -F _createdb $default createdb + +# dropdb(1) completion +# +_dropdb() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(h|-host=)) + _known_hosts + return 0 + ;; + -@(U|-username=)) + _pg_users + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-h -p -U -W -e -q \ + --host= --port= --username= --password \ + --interactive --echo --quiet --help' -- $cur ) ) + else + _pg_databases + fi +} +complete -F _dropdb $default dropdb + +# psql(1) completion +# +_psql() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -h|--host) + _known_hosts + return 0 + ;; + -U|--username) + _pg_users + return 0 + ;; + -d|--dbname) + _pg_databases + return 0 + ;; + -@(o|f)|--output|--file) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + # return list of available options + COMPREPLY=( $( compgen -W '-a --echo-all -A --no-align \ + -c --command -d --dbname -e --echo-queries \ + -E --echo-hidden -f --file -F --filed-separator \ + -h --host -H --html -l --list -n -o --output \ + -p --port -P --pset -q -R --record-separator \ + -s --single-step -S --single-line -t --tuples-only \ + -T --table-attr -U --username -v --variable \ + -V --version -W --password -x --expanded -X --nopsqlrc \ + -? --help ' -- $cur ) ) + else + # return list of available databases + _pg_databases + fi +} +complete -F _psql $default psql +} + +_longopt() +{ + local cur opt + + cur=`_get_cword` + + if [[ "$cur" == --*=* ]]; then + opt=${cur%%=*} + # cut backslash that gets inserted before '=' sign + opt=${opt%\\*} + cur=${cur#*=} + _filedir + COMPREPLY=( $( compgen -P "$opt=" -W '${COMPREPLY[@]}' -- $cur)) + return 0 + fi + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( $1 --help 2>&1 | sed -e '/--/!d' \ + -e 's/.*\(--[-A-Za-z0-9]\+=\?\).*/\1/' | \ + command grep "^$cur" | sort -u ) ) + elif [[ "$1" == @(mk|rm)dir ]]; then + _filedir -d + else + _filedir + fi +} +# makeinfo and texi2dvi are defined elsewhere. +for i in a2ps autoconf automake bc gprof ld nm objcopy objdump readelf strip \ + bison cpio diff patch enscript cp df dir du ln ls mkfifo mknod mv rm \ + touch vdir awk gperf grep grub indent less m4 sed shar date \ + tee who texindex cat csplit cut expand fmt fold head \ + md5sum nl od paste pr ptx sha1sum sort split tac tail tr unexpand \ + uniq wc ldd bash id irb mkdir rmdir; do + have $i && complete -F _longopt $filenames $i +done + +# These commands use filenames, so '-o filenames' is not needed. +for i in env netstat seq uname units wget; do + have $i && complete -F _longopt $default $i +done +unset i + +# gcc(1) completion +# +# The only unusual feature is that we don't parse "gcc --help -v" output +# directly, because that would include the options of all the other backend +# tools (linker, assembler, preprocessor, etc) without any indication that +# you cannot feed such options to the gcc driver directly. (For example, the +# linker takes a -z option, but you must type -Wl,-z for gcc.) Instead, we +# ask the driver ("g++") for the name of the compiler ("cc1"), and parse the +# --help output of the compiler. +# +have gcc && +_gcc() +{ + local cur cc backend + + COMPREPLY=() + cur=`_get_cword` + + _expand || return 0 + + case "$1" in + gcj) + backend=jc1 + ;; + gpc) + backend=gpc1 + ;; + *77) + backend=f771 + ;; + *) + backend=cc1 # (near-)universal backend + ;; + esac + + if [[ "$cur" == -* ]]; then + cc=$( $1 -print-prog-name=$backend ) + # sink stderr: + # for C/C++/ObjectiveC it's useless + # for FORTRAN/Java it's an error + COMPREPLY=( $( $cc --help 2>/dev/null | tr '\t' ' ' | \ + sed -e '/^ *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \ + command grep "^$cur" | sort -u ) ) + else + _filedir + fi +} && +complete $filenames -F _gcc gcc g++ c++ g77 gcj gpc +[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Cygwin ] && \ +[ -n "${have:-}" ] && complete $filenames -F _gcc cc + +# Linux cardctl(8) completion +# +have cardctl && +_cardctl() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W 'status config ident suspend \ + resume reset eject insert scheme' \ + -- $cur ) ) + fi +} && +complete -F _cardctl cardctl + +# This function is required by _dpkg() and _dpkg-reconfigure() +# +have dpkg && { +_comp_dpkg_installed_packages() +{ + grep -A 1 "Package: $1" /var/lib/dpkg/status | \ + grep -B 1 -E "ok installed|half-installed|unpacked| \ + half-configured|config-files" | \ + grep "Package: $1" | cut -d\ -f2 +} + +# Debian dpkg(8) completion +# +_dpkg() +{ + local cur prev i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + i=$COMP_CWORD + + _expand || return 0 + + # find the last option flag + if [[ $cur != -* ]]; then + while [[ $prev != -* && $i != 1 ]]; do + i=$((i-1)) + prev=${COMP_WORDS[i-1]} + done + fi + + case "$prev" in + -@(c|i|A|I|f|e|x|X|-@(install|unpack|record-avail|contents|info|fsys-tarfile|field|control|extract))) + _filedir '?(u)deb' + return 0 + ;; + -@(b|-build)) + _filedir -d + return 0 + ;; + -@(s|p|l|-@(status|print-avail|list))) + COMPREPLY=( $( apt-cache pkgnames $cur 2>/dev/null ) ) + return 0 + ;; + -@(S|-search)) + _filedir + return 0 + ;; + -@(r|L|P|-@(remove|purge|listfiles))) + COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) ) + return 0 + ;; + *) + + COMPREPLY=( $( compgen -W '-i --install --unpack -A --record-avail \ + --configure -r --remove -P --purge --get-selections \ + --set-selections --update-avail --merge-avail \ + --clear-avail --command-fd --forget-old-unavail -s \ + --status -p --print-avail -L --listfiles -l --list \ + -S --search -C --audit --print-architecture \ + --print-gnu-build-architecture \ + --print-installation-architecture \ + --compare-versions --help --version --force-help \ + --force-all --force-auto-select --force-downgrade \ + --force-configure-any --force-hold --force-bad-path \ + --force-not-root --force-overwrite \ + --force-overwrite-diverted --force-bad-verify \ + --force-depends-version --force-depends \ + --force-confnew --force-confold --force-confdef \ + --force-confmiss --force-conflicts --force-architecture\ + --force-overwrite-dir --force-remove-reinstreq \ + --force-remove-essential -Dh \ + --debug=help --licence --admindir= --root= --instdir= \ + -O --selected-only -E --skip-same-version \ + -G --refuse-downgrade -B --auto-deconfigure \ + --no-debsig --no-act -D --debug= --status-fd \ + -b --build -I --info -f --field -c --contents \ + -x --extract -X --vextract --fsys-tarfile -e --control \ + --ignore-depends= --abort-after' -- $cur ) ) + ;; + esac + + +} +complete -F _dpkg $filenames dpkg dpkg-deb +} + +# Debian GNU dpkg-reconfigure(8) completion +# +have dpkg-reconfigure && +_dpkg_reconfigure() +{ + local cur prev opt + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + + case "$prev" in + -@(f|-frontend)) + opt=( $( echo /usr/share/perl5/Debconf/FrontEnd/* ) ) + opt=( ${opt[@]##*/} ) + opt=( ${opt[@]%.pm} ) + COMPREPLY=( $( compgen -W '${opt[@]}' -- $cur ) ) + return 0 + ;; + -@(p|-priority)) + COMPREPLY=( $( compgen -W 'low medium high critical' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-f --frontend -p --priority -a --all \ + -u --unseen-only -h --help -s --showold \ + --force --terse' -- $cur ) ) + else + COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) ) + fi +} && +complete -F _dpkg_reconfigure $default dpkg-reconfigure + +# Debian dpkg-source completion +# +have dpkg-source && +_dpkg_source() +{ + local cur prev options work i action packopts unpackopts + + packopts="-c -l -F -V -T -D -U -W -E -sa -i -I -sk -sp -su -sr -ss -sn -sA -sK -sP -sU -sR" + unpackopts="-sp -sn -su" + options=`echo "-x -b $packopts $unpackopts" | xargs echo | sort -u | xargs echo` + + COMPREPLY=() + if [ "$1" != "dpkg-source" ]; then + exit 1 + fi + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + action="options" + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[$i]} == "-x" ]]; then + action=unpack + elif [[ ${COMP_WORDS[$i]} == "-b" ]]; then + action=pack + elif [[ ${COMP_WORDS[$i]} == "-h" ]]; then + action=help + fi + done + # if currently seeing a complete option, return just itself. + for i in $options; do + if [ "$cur" = "$i" ]; then + COMPREPLY=( "$cur" ) + return 0 + fi + done + case "$action" in + "unpack") + if [ "$cur" = "-" -o "$cur" = "-s" ]; then + COMPREPLY=( $unpackots ) + return 0 + fi + case "$prev" in + "-x") + COMPREPLY=( $( compgen -d -- "$cur" ) \ + $( compgen -f -X '!*.dsc' -- "$cur" ) ) + return 0 + ;; + *) + COMPREPLY=( $unpackopts $(compgen -d -f -- "$cur" ) ) + return 0 + ;; + esac + return 0 + ;; + "pack") + if [ "$cur" = "-" ]; then + COMPREPLY=( $packopts ) + return 0 + fi + if [ "$cur" = "-s" ]; then + COMPREPLY=( "-sa" "-sk" "-sp" "-su" "-sr" "-ss" "-sn" \ + "-sA" "-sK" "-sP" "-sU" "-sR" ) + return 0 + fi + case "$prev" in + "-b") + COMPREPLY=( $( compgen -d -- "$cur" ) ) + return 0 + ;; + "-c"|"-l"|"-T"|"-i"|"-I") + # -c: get controlfile + # -l: get per-version info from this file + # -T: read variables here, not debian/substvars + # -i: <regexp> filter out files to ignore diffs of. + # -I: filter out files when building tarballs. + # return directory names and file names + COMPREPLY=( $( compgen -d -f ) ) + return 0 + ;; + "-F") + # -F: force change log format + COMPREPLY=( $( ( cd /usr/lib/dpkg/parsechangelog; compgen -f "$cur" ) ) ) + return 0 + ;; + "-V"|"-D") + # -V: set a substitution variable + # we don't know anything about possible variables or values + # so we don't try to suggest any completion. + COMPREPLY=() + return 0 + ;; + "-D") + # -D: override or add a .dsc field and value + # if $cur doesn't contain a = yet, suggest variable names + if echo -- "$cur" | grep -q "="; then + # $cur contains a "=" + COMPREPLY=() + return 0 + else + COMPREPLY=( Format Source Version Binary Maintainer Uploader Architecture Standards-Version Build-Depends Files ) + return 0 + fi + ;; + "-U") + # -U: remove a field + # Suggest possible fieldnames + COMPREPLY=( Format Source Version Binary Maintainer Uploader Architecture Standards-Version Build-Depends Files ) + return 0 + ;; + *) + COMPREPLY=( $packopts ) + return 0 + ;; + esac + return 0 + ;; + *) + # if seeing a partial option, return possible completions. + if [ "$cur" = "-s" ]; then + COMPREPLY=( "-sa" "-sk" "-sp" "-su" "-sr" "-ss" "-sn" \ + "-sA" "-sK" "-sP" "-sU" "-sR" ) + return 0 + fi + # else return all possible options. + COMPREPLY=( $options ) + return 0 + ;; + esac +} && +complete -F _dpkg_source dpkg-source + +# Debian Linux dselect(8) completion. +# +have dselect && +_dselect() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --admindir) + _filedir -d + return 0 + ;; + + -@(D|debug)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--admindir --help --version --licence \ + --license --expert --debug' -- $cur ) ) + else + COMPREPLY=( $( compgen -W 'access update select install config \ + remove quit' -- $cur ) ) + fi + + + return 0 +} && +complete -F _dselect $filenames dselect + +# Java completion +# + +# available path elements completion +have java && { +_java_path() +{ + cur=${cur##*:} + _filedir '@(jar|zip)' +} + +# exact classpath determination +_java_find_classpath() +{ + local i + + # search first in current options + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == -@(cp|classpath) ]]; then + classpath=${COMP_WORDS[i+1]} + break + fi + done + + # default to environment + [ -z "$classpath" ] && classpath=$CLASSPATH + + # default to current directory + [ -z "$classpath" ] && classpath=. +} + +# exact sourcepath determination +_java_find_sourcepath() +{ + local i + + # search first in current options + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == -sourcepath ]]; then + sourcepath=${COMP_WORDS[i+1]} + break + fi + done + + # default to classpath + [ -z "$sourcepath" ] && _java_find_classpath + sourcepath=$classpath +} + +# available classes completion +_java_classes() +{ + local classpath i + + # find which classpath to use + _java_find_classpath + + # convert package syntax to path syntax + cur=${cur//.//} + # parse each classpath element for classes + for i in ${classpath//:/ }; do + if [ -r $i ] && [[ "$i" == *.@(jar|zip) ]]; then + if type zipinfo &> /dev/null; then + COMPREPLY=( "${COMPREPLY[@]}" $( zipinfo -1 \ + "$i" | grep "^$cur" | grep '\.class$' | \ + grep -v "\\$" ) ) + else + COMPREPLY=( "${COMPREPLY[@]}" $( jar tf "$i" \ + "$cur" | grep "\.class$" | grep -v "\\$" ) ) + fi + + elif [ -d $i ]; then + i=${i%/} + COMPREPLY=( "${COMPREPLY[@]}" $( find "$i" -type f \ + -path "$i/$cur*.class" 2>/dev/null | \ + grep -v "\\$" | sed -e "s|^$i/||" ) ) + fi + done + + # remove class extension + COMPREPLY=( ${COMPREPLY[@]%.class} ) + # convert path syntax to package syntax + COMPREPLY=( ${COMPREPLY[@]//\//.} ) +} + +# available packages completion +_java_packages() +{ + local sourcepath i + + # find wich sourcepath to use + _java_find_sourcepath + + # convert package syntax to path syntax + cur=${cur//.//} + # parse each sourcepath element for packages + for i in ${sourcepath//:/ }; do + if [ -d $i ]; then + COMPREPLY=( "${COMPREPLY[@]}" $( command ls -F -d \ + $i/$cur* 2>/dev/null | sed -e 's|^'$i'/||' ) ) + fi + done + # keep only packages + COMPREPLY=( $( echo "${COMPREPLY[@]}" | tr " " "\n" | grep "/$" ) ) + # remove packages extension + COMPREPLY=( ${COMPREPLY[@]%/} ) + # convert path syntax to package syntax + cur=${COMPREPLY[@]//\//.} +} + +# java completion +# +_java() +{ + local cur prev i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + for ((i=1; i < $COMP_CWORD; i++)); do + case ${COMP_WORDS[$i]} in + -cp|-classpath) + ((i++)) # skip the classpath string. + ;; + -*) + # this is an option, not a class/jarfile name. + ;; + *) + # once we've seen a class, just do filename completion + _filedir + return 0 + ;; + esac + done + + case $prev in + -@(cp|classpath)) + _java_path + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + # relevant options completion + COMPREPLY=( $( compgen -W '-client -hotspot -server -classic \ + -cp -classpath -D -verbose -verbose:class \ + -verbose:gc -version:jni -version \ + -showversion -? -help -X -jar \ + -ea -enableassertions -da -disableassertions \ + -esa -enablesystemassertions \ + -dsa -disablesystemassertions ' -- $cur ) ) + else + if [[ "$prev" == -jar ]]; then + # jar file completion + _filedir jar + else + # classes completion + _java_classes + fi + fi +} +complete -F _java $filenames java +} + +# javadoc completion +# +have javadoc && +_javadoc() +{ + COMPREPLY=() + local cur prev + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + -@(overview|helpfile|stylesheetfile)) + _filedir + return 0 + ;; + -d) + _filedir -d + return 0 + ;; + -@(classpath|bootclasspath|docletpath|sourcepath|extdirs)) + _java_path + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + # relevant options completion + COMPREPLY=( $( compgen -W '-overview -public -protected \ + -package -private -help -doclet -docletpath \ + -sourcepath -classpath -exclude -subpackages \ + -breakiterator -bootclasspath -source -extdirs \ + -verbose -locale -encoding -J -d -use -version \ + -author -docfilessubdirs -splitindex \ + -windowtitle -doctitle -header -footer -bottom \ + -link -linkoffline -excludedocfilessubdir \ + -group -nocomment -nodeprecated -noqualifier \ + -nosince -nodeprecatedlist -notree -noindex \ + -nohelp -nonavbar -quiet -serialwarn -tag \ + -taglet -tagletpath -charset -helpfile \ + -linksource -stylesheetfile -docencoding' -- \ + $cur ) ) + else + # source files completion + _filedir java + # packages completion + _java_packages + fi +} && +complete -F _javadoc $filenames javadoc + +# javac completion +# +have javac && +_javac() +{ + COMPREPLY=() + local cur prev + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + -d) + _filedir -d + return 0 + ;; + -@(classpath|bootclasspath|sourcepath|extdirs)) + _java_path + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + # relevant options completion + COMPREPLY=( $( compgen -W '-g -g:none -g:lines -g:vars\ + -g:source -O -nowarn -verbose -deprecation -classpath\ + -sourcepath -bootclasspath -extdirs -d -encoding -source\ + -target -help' -- $cur ) ) + else + # source files completion + _filedir java + fi +} && +complete -F _javac $filenames javac + +# PINE address-book completion +# +have pine && +_pineaddr() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + COMPREPLY=( $( compgen -W '$( awk "{print \$1}" ~/.addressbook 2>/dev/null)' \ + -- $cur ) ) +} && +complete -F _pineaddr $default pine + +# mutt completion +# +# Mutt doesn't have an "addressbook" like Pine, but it has aliases and +# a "query" function to retrieve addresses, so that's what we use here. +have mutt || have muttng && { +_muttaddr() +{ + _muttaliases + _muttquery + return 0 +} + +_muttconffiles() +{ + local file sofar + local -a newconffiles + + sofar=" $1 " + shift + while [[ "$1" ]]; do + newconffiles=( $(sed -rn 's|^source[[:space:]]+([^[:space:]]+).*$|\1|p' $(eval echo $1) ) ) + for file in "${newconffiles[@]}"; do + [[ ! "$file" ]] || [[ "${sofar/ ${file} / }" != "$sofar" ]] && + continue + sofar="$sofar $file" + sofar=" $(eval _muttconffiles \"$sofar\" $file) " + done + shift + done + echo $sofar +} + +_muttaliases() +{ + local cur muttrc + local -a conffiles aliases + cur=`_get_cword` + + [ -f ~/.${muttcmd}/${muttcmd}rc ] && muttrc="~/.${muttcmd}/${muttcmd}rc" + [ -f ~/.${muttcmd}rc ] && muttrc="~/.${muttcmd}rc" + [ -z "$muttrc" ] && return 0 + + conffiles=( $(eval _muttconffiles $muttrc $muttrc) ) + aliases=( $( sed -rn 's|^alias[[:space:]]+([^[:space:]]+).*$|\1|p' \ + $(eval echo "${conffiles[@]}") ) ) + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${aliases[*]}" -- $cur ) ) + + return 0 +} + +_muttquery() +{ + local cur querycmd + local -a queryresults + cur=`_get_cword` + + querycmd="$( $muttcmd -Q query_command | sed -r 's|^query_command=\"(.*)\"$|\1|; s|%s|'$cur'|' )" + if [ -z "$cur" -o -z "$querycmd" ]; then + queryresults=() + else + queryresults=( $( $querycmd | \ + sed -nr '2,$s|^([^[:space:]]+).*|\1|p' ) ) + fi + + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${queryresults[*]}" \ + -- $cur ) ) + + return 0 +} + +_muttfiledir() +{ + local cur folder spoolfile + cur=`_get_cword` + + # This is currently not working so well. Perhaps this function should + # just call _filedir() for the moment. + if [[ $cur == [=+]* ]]; then + folder="$( $muttcmd -Q folder | sed -r 's|^folder=\"(.*)\"$|\1|' )" + : folder:=~/Mail + + # Match any file in $folder beginning with $cur + # (minus the leading '=' sign). + COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) ) + COMPREPLY=( ${COMPREPLY[@]#$folder/} ) + return 0 + elif [ "$cur" == !* ]; then + spoolfile="$( $muttcmd -Q spoolfile | sed -r 's|^spoolfile=\"(.*)\"$|\1|' )" + [ ! -z "$spoolfile" ] && eval cur="${cur/^!/$spoolfile}"; + fi + _filedir + + return 0 +} + +_mutt() +{ + local cur prev + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + COMPREPLY=() + + [ ${COMP_WORDS[0]} == muttng ] && muttcmd="muttng" || muttcmd="mutt" + + case "$cur" in + -*) + COMPREPLY=( $( compgen -W '-A -a -b -c -e -f -F -H -i -m -n \ + -p -Q -R -s -v -x -y -z -Z -h' \ + -- $cur ) ) + return 0 + ;; + *) + case "$prev" in + -@(a|f|F|H|i)) + _muttfiledir + return 0 + ;; + -A) + _muttaliases + return 0 + ;; + -@(e|m|Q|s|h|p|R|v|y|z|Z)) + return 0 + ;; + *) + _muttaddr + return 0 + ;; + esac + ;; + esac + +} +complete -F _mutt $default $filenames mutt muttng +} + +_configure_func() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + # if $COMP_CONFIGURE_HINTS is not null, then completions of the form + # --option=SETTING will include 'SETTING' as a contextual hint + [[ "$cur" != -* ]] && return 0 + + if [ -n "$COMP_CONFIGURE_HINTS" ]; then + COMPREPLY=( $( $1 --help | awk '/^ --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,].*//g' | grep ^$cur ) ) + + else + COMPREPLY=( $( $1 --help | awk '/^ --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,=].*//g' | grep ^$cur ) ) + fi +} +complete -F _configure_func $default configure + +# Debian reportbug(1) completion +# +have reportbug && +_reportbug() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -f|--filename|-i|--include|--mta|-o|--output) + _filedir + return 0 + ;; + -B|--bts) + COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \ + $cur )) + return 0 + ;; + -e|--editor|--mua) + COMP_WORDS=(COMP_WORDS[0] $cur) + COMP_CWORD=1 + _command + return 0 + ;; + --mode) + COMPREPLY=( $( compgen -W "novice standard expert" -- $cur ) ) + return 0 + ;; + -S|--severity) + COMPREPLY=( $( compgen -W "grave serious important normal \ + minor wishlist" -- $cur ) ) + return 0 + ;; + -u|--ui|--interface) + COMPREPLY=( $( compgen -W "newt text gnome" -- $cur ) ) + return 0 + ;; + -t|--type) + COMPREPLY=( $( compgen -W "gnats debbugs" -- $cur ) ) + return 0 + ;; + -T|--tags) + COMPREPLY=( $( compgen -W "none patch security upstream sid \ + woody potato sarge fixed" -- $cur )) + return 0 + ;; + *) + ;; + esac + + COMPREPLY=($( compgen -W '-h --help -v --version -a --af -b \ + --no-query-bts --query-bts -B --bts -c --configure \ + --no-config-files --check-available -d --debug \ + --no-check-available -e --editor --email -f \ + --filename -g --gnupg -H --header -i --include -j \ + --justification -l --ldap --no-ldap -L --list-cc -m \ + --maintonly --mode --mua --mta --mutt -n --mh --nmh \ + -o --output -p --print -P --pgp --proxy --http_proxy\ + -q --quiet -Q --query-only --realname --report-quiet \ + --reply-to --replyto -s --subject -S --severity \ + --smtphost -t --type -T --tags --template -V -x \ + --no-cc --package-version -z --no-compress \ + --ui --interface -u \ + wnpp boot-floppies kernel-image' -- $cur ) \ + $( apt-cache pkgnames -- $cur 2> /dev/null ) ) + _filedir + return 0 +} && +complete -F _reportbug $filenames reportbug + +# Debian querybts(1) completion +# +have querybts && +_querybts() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -B|--bts) + COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \ + $cur )) + return 0 + ;; + -u|--ui|--interface) + COMPREPLY=($( compgen -W "newt text gnome" -- $cur )) + return 0 + ;; + *) + ;; + esac + + COMPREPLY=($( compgen -W '-h --help -v --version -A --archive \ + -B --bts -l --ldap --no-ldap --proxy= --http_proxy= \ + -s --source -w --web -u --ui --interface \ + wnpp boot-floppies' -- $cur ) \ + $( apt-cache pkgnames -- $cur 2> /dev/null ) ) +} && +complete -F _querybts $filenames querybts + +# update-alternatives completion +# +have update-alternatives && { +installed_alternatives() +{ + local admindir + # find the admin dir + for i in alternatives dpkg/alternatives rpm/alternatives; do + [ -d /var/lib/$i ] && admindir=/var/lib/$i && break + done + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == --admindir ]]; then + admindir=${COMP_WORDS[i+1]} + break + fi + done + COMPREPLY=( $( command ls $admindir | grep "^$cur" ) ) +} + +_update_alternatives() +{ + local cur prev mode args i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --@(altdir|admindir)) + _filedir -d + return 0 + ;; + --@(help|version)) + return 0 + ;; + esac + + # find wich mode to use and how many real args used so far + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all) ]]; then + mode=${COMP_WORDS[i]} + args=$(($COMP_CWORD - i)) + break + fi + done + + case $mode in + --install) + case $args in + 1) + _filedir + ;; + 2) + installed_alternatives + ;; + 3) + _filedir + ;; + esac + ;; + --remove) + case $args in + 1) + installed_alternatives + ;; + 2) + _filedir + ;; + esac + ;; + --auto) + installed_alternatives + ;; + --remove-all) + installed_alternatives + ;; + --display) + installed_alternatives + ;; + --config) + installed_alternatives + ;; + *) + COMPREPLY=( $( compgen -W '--verbose --quiet --help --version \ + --altdir --admindir' -- $cur ) \ + $( compgen -W '--install --remove --auto --display \ + --config' -- $cur ) ) + esac +} +complete -F _update_alternatives update-alternatives +} + +# Python completion +# +have python && +_python() +{ + local prev cur + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]##*/} + + case "$prev" in + -Q) + COMPREPLY=( $( compgen -W "old new warn warnall" -- $cur ) ) + return 0 + ;; + -W) + COMPREPLY=( $( compgen -W "ignore default all module once error" -- $cur ) ) + return 0 + ;; + -c) + _filedir '@(py|pyc|pyo)' + return 0 + ;; + !(python|-?)) + [[ ${COMP_WORDS[COMP_CWORD-2]} != -@(Q|W) ]] && _filedir + ;; + esac + + + # if '-c' is already given, complete all kind of files. + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == -c ]]; then + _filedir + fi + done + + + if [[ "$cur" != -* ]]; then + _filedir '@(py|pyc|pyo)' + else + COMPREPLY=( $( compgen -W "- -d -E -h -i -O -Q -S -t -u \ + -U -v -V -W -x -c" -- $cur ) ) + fi + + + + return 0 +} && +complete -F _python $filenames python + +# Perl completion +# +have perl && +{ +_perlmodules() +{ + COMPREPLY=( $( compgen -P "$prefix" -W "$( perl -e 'sub mods { my ($base,$dir)=@_; return if $base !~ /^\Q$ENV{cur}/; chdir($dir) or return; for (glob(q[*.pm])) {s/\.pm$//; print qq[$base$_\n]}; mods(/^(?:[.\d]+|$Config{archname}-$Config{osname}|auto)$/ ? undef : qq[${base}${_}\\\\:\\\\:],qq[$dir/$_]) for grep {-d} glob(q[*]); } mods(undef,$_) for @INC;' )" -- $cur ) ) +} + +_perl() +{ + local cur prev prefix temp + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + prefix="" + + # completing an option (may or may not be separated by a space) + if [[ "$cur" == -?* ]]; then + temp=$cur + prev=${temp:0:2} + cur=${temp:2} + prefix=$prev + fi + + # only handle module completion for now + case "$prev" in + -I|-x) + COMPREPLY=( $( compgen -d -P "$prev" -- "$cur" ) ) + return 0 + ;; + -m|-M) + _perlmodules + return 0 + ;; + esac + + # handle case where first parameter is not a dash option + if [[ "${COMP_WORDS[COMP_CWORD]}" != -* ]]; then + _filedir + return 0 + fi + + # complete using basic options + COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d -D -p \ + -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- $cur ) ) + return 0 +} +complete -F _perl $filenames perl + +_perldoc() +{ + local cur prev prefix temp + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + prefix="" + + # completing an option (may or may not be separated by a space) + if [[ "$cur" == -?* ]]; then + temp=$cur + prev=${temp:0:2} + cur=${temp:2} + prefix=$prev + fi + + # complete builtin perl functions + case $prev in + -f) + COMPREPLY=( $( compgen -W 'chomp chop chr crypt hex index lc \ + lcfirst length oct ord pack q qq reverse rindex sprintf \ + substr tr uc ucfirst y m pos quotemeta s split study qr abs \ + atan2 cos exp hex int log oct rand sin sqrt srand pop push \ + shift splice unshift grep join map qw reverse sort unpack \ + delete each exists keys values binmode close closedir \ + dbmclose dbmopen die eof fileno flock format getc print \ + printf read readdir rewinddir seek seekdir select syscall \ + sysread sysseek syswrite tell telldir truncate warn write \ + pack read syscall sysread syswrite unpack vec -X chdir chmod \ + chown chroot fcntl glob ioctl link lstat mkdir open opendir \ + readlink rename rmdir stat symlink umask unlink utime caller \ + continue do dump eval exit goto last next redo return \ + sub wantarray caller import local my our package use defined \ + formline reset scalar undef \ + alarm exec fork getpgrp getppid getpriority kill pipe qx \ + setpgrp setpriority sleep system times wait waitpid \ + import no package require use bless dbmclose dbmopen package \ + ref tie tied untie use accept bind connect getpeername \ + getsockname getsockopt listen recv send setsockopt shutdown \ + socket socketpair msgctl msgget msgrcv msgsnd semctl semget \ + semop shmctl shmget shmread shmwrite endgrent endhostent \ + endnetent endpwent getgrent getgrgid getgrnam getlogin \ + getpwent getpwnam getpwuid setgrent setpwent endprotoent \ + endservent gethostbyaddr gethostbyname gethostent \ + getnetbyaddr getnetbyname getnetent getprotobyname \ + getprotobynumber getprotoent getservbyname getservbyport \ + getservent sethostent setnetent setprotoent setservent \ + gmtime localtime time times' -- $cur ) ) + return 0 + ;; + esac + + case $cur in + -*) + COMPREPLY=( $( compgen -W '-h -v -t -u -m -l -F -X -f -q' -- $cur )) + return 0 + ;; + */*) + return 0 + ;; + *) + _perlmodules + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '$( PAGER=cat man perl 2>/dev/null | sed -ne "/perl.*Perl overview/,/perlwin32/s/^[^a-z0-9]*\([a-z0-9]*\).*$/\1/p")' -- $cur ) ) + + return 0 + ;; + esac +} +complete -F _perldoc $default perldoc +} + +# rcs(1) completion +# +have rcs && +_rcs() +{ + local cur prev file dir i + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + file=${cur##*/} + dir=${cur%/*} + + # deal with relative directory + [ "$file" = "$dir" ] && dir=. + + COMPREPLY=( $( compgen -f "$dir/RCS/$file" ) ) + + for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do + file=${COMPREPLY[$i]##*/} + dir=${COMPREPLY[$i]%RCS/*} + COMPREPLY[$i]=$dir$file + done + + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -G "$dir/$file*,v" ) ) + + for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do + COMPREPLY[$i]=${COMPREPLY[$i]%,v} + done + + # default to files if nothing returned and we're checking in. + # otherwise, default to directories + [ ${#COMPREPLY[@]} -eq 0 -a $1 = ci ] && _filedir || _filedir -d +} && +complete -F _rcs $filenames ci co rlog rcs rcsdiff + +# lilo(8) completion +# +have lilo && { +_lilo_labels() +{ + COMPREPLY=( $( awk -F'=' '/label/ {print $2}' \ + /etc/lilo.conf | sed -e 's/"//g' | grep "^$cur" ) ) +} + +_lilo() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + -@(C|i|m|s|S)) + _filedir + return 0 + ;; + -r) + _filedir -d + return 0 + ;; + -@(I|D|R)) + # label completion + _lilo_labels + return 0 + ;; + -@(A|b|M|u|U)) + # device completion + cur=${cur:=/dev/} + _filedir + return 0 + ;; + -T) + # topic completion + COMPREPLY=( $( compgen -W 'help ChRul EBDA geom geom= \ + table= video' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + # relevant options completion + COMPREPLY=( $( compgen -W '-A -b -c -C -d -f -g -i -I -l -L -m \ + -M -p -P -q -r -R -s -S -t -T -u -U -v -V -w -x -z' -- \ + $cur ) ) + fi +} +complete -F _lilo lilo +} + +# links completion +# +have links && +_links() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + case "$cur" in + --*) + COMPREPLY=( $( compgen -W '--help' -- $cur ) ) + ;; + -*) + COMPREPLY=( $( compgen -W '-async-dns -max-connections \ + -max-connections-to-host -retries \ + -receive-timeout -unrestartable-receive-timeout\ + -format-cache-size -memory-cache-size \ + -http-proxy -ftp-proxy -download-dir \ + -assume-codepage -anonymous -dump -no-connect \ + -source -version -help' -- $cur ) ) + ;; + *) + if [ -r ~/.links/links.his ]; then + COMPREPLY=( $( compgen -W '$( < ~/.links/links.his )' \ + -- $cur ) ) + fi + _filedir '@(htm|html)' + return 0 + ;; + esac + + return 0 +} && +complete -F _links $filenames links + +[ $UNAME = FreeBSD ] && { +# FreeBSD package management tool completion +# +_pkg_delete() +{ + local cur pkgdir prev + + pkgdir=${PKG_DBDIR:-/var/db/pkg}/ + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + [ "$prev" = "-o" -o "$prev" = "-p" -o "$prev" = "-W" ] && return 0 + + COMPREPLY=( $( compgen -d $pkgdir$cur ) ) + COMPREPLY=( ${COMPREPLY[@]#$pkgdir} ) + + return 0 +} +complete -F _pkg_delete $dirnames pkg_delete pkg_info +have pkg_deinstall && complete -F _pkg_delete $dirnames pkg_deinstall + +# FreeBSD kernel module commands +# +_kldload() +{ + local cur moddir + + moddir=/modules/ + [ -d $moddir ] || moddir=/boot/kernel/ + cur=`_get_cword` + + COMPREPLY=( $( compgen -f $moddir$cur ) ) + COMPREPLY=( ${COMPREPLY[@]#$moddir} ) + COMPREPLY=( ${COMPREPLY[@]%.ko} ) + + return 0 +} +complete -F _kldload $filenames kldload + +_kldunload() +{ + local cur + cur=`_get_cword` + COMPREPLY=( $(kldstat | sed -ne "s/^.*[ \t]\+\($cur[a-z_]\+\).ko$/\1/p") ) +} +complete -F _kldunload $filenames kldunload +} + +# FreeBSD portupgrade completion +# +have portupgrade && +_portupgrade() +{ + local cur pkgdir prev + + pkgdir=${PKG_DBDIR:-/var/db/pkg}/ + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0 + + COMPREPLY=( $( compgen -d $pkgdir$cur ) ) + COMPREPLY=( ${COMPREPLY[@]#$pkgdir} ) + COMPREPLY=( ${COMPREPLY[@]%-*} ) + + return 0 +} && +complete -F _portupgrade $dirnames portupgrade + +# FreeBSD portinstall completion +# +have portinstall && +_portinstall() +{ + local cur portsdir prev indexfile + local -a COMPREPLY2 + + portsdir=${PORTSDIR:-/usr/ports}/ + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + # First try INDEX-5 + indexfile=$portsdir/INDEX-5 + # Then INDEX if INDEX-5 does not exist or system is not FreeBSD 5.x + [ "${OSTYPE%.*}" = "freebsd5" -a -f $indexfile ] || + indexfile=$portsdir/INDEX + + [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0 + + COMPREPLY=( $( egrep "^$cur" < $indexfile | cut -d'|' -f1 ) ) + COMPREPLY2=( $( egrep "^[^\|]+\|$portsdir$cur" < $indexfile | \ + cut -d'|' -f2 ) ) + COMPREPLY2=( ${COMPREPLY2[@]#$portsdir} ) + COMPREPLY=( "${COMPREPLY[@]}" "${COMPREPLY2[@]}" ) + + return 0 +} && +complete -F _portinstall $dirnames portinstall + +# Slackware Linux removepkg completion +# +have removepkg && [ -f /etc/slackware-version ] && +_removepkg() +{ + local packages cur + + COMPREPLY=() + cur=`_get_cword` + + COMPREPLY=( $( (cd /var/log/packages; compgen -f -- "$cur") ) ) +} && +complete -F _removepkg $filenames removepkg && + complete $dirnames -f -X '!*.tgz' installpkg upgradepkg explodepkg + +# look(1) completion +# +have look && +_look() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD = 1 ]; then + COMPREPLY=( $( compgen -W '$(look $cur)' ) ) + fi +} && +complete -F _look $default look + +# ypcat(1) and ypmatch(1) completion +# +have ypmatch && +_ypmatch() +{ + local cur map + + COMPREPLY=() + cur=`_get_cword` + + [ $1 = ypcat ] && [ $COMP_CWORD -gt 1 ] && return 0 + [ $1 = ypmatch ] && [ $COMP_CWORD -gt 2 ] && return 0 + + if [ $1 = ypmatch ] && [ $COMP_CWORD -eq 1 ] && \ + [ ${#COMP_WORDS[@]} -eq 3 ]; then + map=${COMP_WORDS[2]} + COMPREPLY=( $( compgen -W '$( ypcat $map | \ + cut -d':' -f 1 )' -- $cur) ) + else + [ $1 = ypmatch ] && [ $COMP_CWORD -ne 2 ] && return 0 + COMPREPLY=( $( compgen -W \ + '$( echo $(ypcat -x | cut -d"\"" -f 2))' -- $cur)) + fi + + return 0 +} && +complete -F _ypmatch ypmatch ypcat + +# mplayer(1) completion +# +have mplayer && { +_mplayer_options_list() +{ + cur=${cur%\\} + COMPREPLY=( $( $1 $2 help 2> /dev/null | \ + sed -e '1,/^Available/d' | awk '{print $1}' | \ + sed -e 's/:$//' -e 's/^'${2#-}'$//' -e 's/<.*//' | \ + grep "^$cur" ) ) +} + +_mplayer() +{ + local cmd cur prev skinsdir IFS=$' \t\n' i j k=0 + + COMPREPLY=() + cmd=${COMP_WORDS[0]} + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(ac|afm|vc|vfm|ao|vo|vop|fstype)) + _mplayer_options_list mplayer $prev + return 0 + ;; + -@(oac|ovc|of)) + _mplayer_options_list mencoder $prev + return 0 + ;; + -audiofile) + _filedir '@(mp3|MP3|mpg|MPG|ogg|OGG|wav|WAV|mid|MID|flac|FLAC|mka|MKA)' + return 0 + ;; + -font) + _filedir '@(desc|ttf)' + return 0 + ;; + -sub) + _filedir '@(srt|SRT|sub|SUB|txt|TXT|utf|UTF|rar|RAR|mpsub|smi|js|ssa|SSA|aas|AAS)' + return 0 + ;; + -vobsub) + _filedir '@(idx|IDX|ifo|IFO|sub|SUB)' + IFS=$'\t\n' + COMPREPLY=( $( for i in "${COMPREPLY[@]}"; do + if [ -f $i -a -r $i ]; then + echo ${i%.*} + else + echo $i + fi + done ) ) + IFS=$' \t\n' + return 0 + ;; + -ifo) + _filedir '@(ifo|IFO)' + return 0 + ;; + -cuefile) + _filedir '@(bin|BIN|cue|CUE)' + return 0 + ;; + -skin) + # if you don't have installed mplayer in /usr/local you + # may want to set the MPLAYER_SKINS_DIR global variable + if [ -n "$MPLAYER_SKINS_DIR" ]; then + skinsdir=$MPLAYER_SKINS_DIR + else + skinsdir=/usr/local/share/mplayer/Skin + fi + + IFS=$'\t\n' + for i in ~/.mplayer/Skin $skinsdir; do + if [ -d $i -a -r $i ]; then + for j in $( compgen -d $i/$cur ); do + COMPREPLY[$k]=${j#$i/} + k=$((++k)) + done + fi + done + IFS=$' \t\n' + return 0 + ;; + -@(mixer|@(cdrom|dvd)-device|dvdauth|fb|zrdev)) + cur=${cur:=/dev/} + _filedir + return 0 + ;; + -@(edl?(out)|lircconf|menu-cfg|playlist|csslib|dumpfile)| \ + -@(subfile|vobsub|aofile|fbmodeconfig|include|o|dvdkey)| \ + -passlogfile) + _filedir + return 0 + ;; + -@(auto@(q|sync)|loop|menu-root|speed|sstep|aid|alang)| \ + -@(?(@(audio|sub)-)demuxer|bandwidth|cache|chapter)| \ + -@(dvd?(angle)|fps|frames|mc|passwd|user|sb|srate|ss|vcd)| \ + -@(vi?(d|vo)|ffactor|sid|slang|spu@(align|aa|gauss))| \ + -@(vobsubid|delay|bpp|brightness|contrast|dfbopts|display)| \ + -@(fbmode|geometry|guiwid|hue|icelayer|screen[wh]|wid)| \ + -@(monitor@(aspect|-@(dotclock|[hv]freq))|panscan|saturation)| \ + -@(xineramascreen|zr@(crop|norm|quality|[xy]doff|[vh]dec))| \ + -@(aspect|pp|x|y|xy|z|stereo|audio-@(density|delay|preload))| \ + -@(endpos|osdlevel|ffourcc|sws|channels|skiplimit|format)| \ + -@(ofps|aa@(driver|@(osd|sub)color)|vobsubout?(i@(ndex|d)))| \ + -sub@(-bg-@(alpha|color)|cp|delay|fps|pos|align|width)| \ + -sub@(font-@(blur|outline|autoscale|encoding|@(osd|text)-scale))) + return 0 + ;; + -lavdopts) + COMPREPLY=( $( compgen -W 'ec er= bug= idct= gray' \ + -- $cur ) ) + return 0 + ;; + -lavcopts) + COMPREPLY=( $( compgen -W 'vcodec= vqmin= vqscale= \ + vqmax= mbqmin= mbqmax= vqdiff= \ + vmax_b_frames= vme= vhq v4mv \ + keyint= vb_strategy= vpass= \ + aspect= vbitrate= vratetol= \ + vrc_maxrate= vrc_minrate= \ + vrc_buf_size= vb_qfactor= vi_qfactor= \ + vb_qoffset= vi_qoffset= vqblur= \ + vqcomp= vrc_eq= vrc_override= \ + vrc_init_cplx= vqsquish= vlelim= \ + vcelim= vstrict= vdpart vpsize= gray \ + vfdct= idct= lumi_mask= dark_mask= \ + tcplx_mask= scplx_mask= naq ildct \ + format= pred qpel precmp= cmp= \ + subcmp= predia= dia= trell last_pred= \ + preme= subq= psnr mpeg_quant aic umv' \ + -- $cur ) ) + return 0 + ;; + -ssf) + COMPREPLY=( $( compgen -W 'lgb= cgb= ls= cs= chs= \ + cvs=' -- $cur ) ) + return 0 + ;; + -jpeg) + COMPREPLY=( $( compgen -W 'noprogressive progressive \ + nobaseline baseline optimize= \ + smooth= quality= outdir=' -- $cur ) ) + return 0 + ;; + -xvidopts) + COMPREPLY=( $( compgen -W 'dr2 nodr2' -- $cur ) ) + return 0 + ;; + -xvidencopts) + COMPREPLY=( $( compgen -W 'pass= bitrate= \ + fixed_quant= me_quality= 4mv \ + rc_reaction_delay_factor= \ + rc_averaging_period= rc_buffer= \ + quant_range= min_key_interval= \ + max_key_interval= mpeg_quant \ + mod_quant lumi_mask hintedme \ + hintfile debug keyframe_boost= \ + kfthreshold= kfreduction=' -- $cur ) ) + return 0 + ;; + -divx4opts) + COMPREPLY=( $( compgen -W 'br= key= deinterlace q= \ + min_quant= max_quant= rc_period= \ + rc_reaction_period= crispness= \ + rc_reaction_ratio= pass= vbrpass= \ + help' -- $cur ) ) + return 0 + ;; + -info) + COMPREPLY=( $( compgen -W 'name= artist= genre= \ + subject= copyright= srcform= \ + comment= help' -- $cur ) ) + return 0 + ;; + -lameopts) + COMPREPLY=( $( compgen -W 'vbr= abr cbr br= q= aq= \ + ratio= vol= mode= padding= fast \ + preset= help' -- $cur ) ) + return 0 + ;; + -rawaudio) + COMPREPLY=( $( compgen -W 'on channels= rate= \ + samplesize= format=' -- $cur ) ) + return 0 + ;; + -rawvideo) + COMPREPLY=( $( compgen -W 'on fps= sqcif qcif cif \ + 4cif pal ntsc w= h= y420 yv12 yuy2 \ + y8 format= size=' -- $cur ) ) + return 0 + ;; + -aop) + COMPREPLY=( $( compgen -W 'list= delay= format= fout= \ + volume= mul= softclip' -- $cur ) ) + return 0 + ;; + -dxr2) + COMPREPLY=( $( compgen -W 'ar-mode= iec958-encoded \ + iec958-decoded mute ucode= 75ire bw \ + color interlaced macrovision= norm= \ + square-pixel ccir601-pixel cr-left= \ + cr-right= cr-top= cr-bot= ck-rmin= \ + ck-gmin= ck-bmin= ck-rmax= ck-gmax= \ + ck-bmax= ck-r= ck-g= ck-b= \ + ignore-cache= ol-osd= olh-cor= \ + olw-cor= olx-cor= oly-cor= overlay \ + overlay-ratio= update-cache' -- $cur )) + return 0 + ;; + -tv) + COMPREPLY=( $( compgen -W 'on noaudio driver= device= \ + input= freq= outfmt= width= height= \ + buffersize= norm= channel= chanlist= \ + audiorate= forceaudio alsa amode= \ + forcechan= adevice= audioid= volume= \ + bass= treble= balance= fps= \ + channels= immediatemode=' -- $cur ) ) + return 0 + ;; + -mf) + COMPREPLY=( $( compgen -W 'on w= h= fps= type=' \ + -- $cur ) ) + return 0 + ;; + -cdda) + COMPREPLY=( $( compgen -W 'speed= paranoia= \ + generic-dev= sector-size= overlap= \ + toc-bias toc-offset= skip noskip' \ + -- $cur ) ) + return 0 + ;; + -input) + COMPREPLY=( $( compgen -W 'conf= ar-delay ar-rate \ + keylist cmdlist js-dev file' -- $cur ) ) + return 0 + ;; + -af) + COMPREPLY=( $( compgen -W 'resample resample= \ + channels channels= format format= \ + volume volume= delay delay= pan \ + pan= sub sub= surround surround=' \ + -- $cur ) ) + return 0 + ;; + -af-adv) + COMPREPLY=( $( compgen -W 'force= list=' -- $cur ) ) + return 0 + ;; + esac + + case "$cur" in + -*) + COMPREPLY=( $( compgen -W '-aid -alang -audio-demuxer \ + -audiofile -cdrom-device -cache -cdda \ + -channels -chapter -csslib -demuxer \ + -dvd -dvd-device -dvdangle -dvdauth \ + -dvdkey -dvdnav -forceidx -fps -frames \ + -hr-mp3-seek -idx -mc -mf -ni -nobps \ + -passwd -rawaudio -rtsp-stream-over-tcp\ + -skipopening -sb -srate -ss -tv -user \ + -vcd -vid -vivo -ifo -ffactor -font \ + -noautosub -nooverlapsub -sid -slang \ + -sub -subcc -subcp -sub-demuxer \ + -subdelay -subfont-autoscale \ + -subfont-blur -subfont-encoding \ + -subfont-osd-scale -subfont-outline \ + -subfont-text-scale -subfps -subfile \ + -subpos -unicode -utf8 -vobsub \ + -vobsubid -ac -afm -aspect -flip \ + -lavdopts -noaspect -nosound -pp -ssf \ + -stereo -sws -vc -vfm -vop -xvidopts\ + -xy -zoom -bandwidth -cuefile \ + -noextbased -rawvideo -overlapsub \ + -sub-bg-alpha -sub-bg-color -subalign \ + -subwidth -sub-no-text-pp -spualign \ + -spuaa -spugauss -pphelp -verbose -v \ + -noni -noidx -nohr-mp3-seek -extbased \ + -bps -oldpp -nozoom -noflip -nounicode \ + -noutf8' -- $cur ) ) + # add mplayer specific options + [[ "$cmd" == @(?(g)mplayer) ]] && COMPREPLY=( "${COMPREPLY[@]}" \ + $(compgen -W '-autoq -autosync -benchmark \ + -framedrop -h -help -hardframedrop \ + -identify -input -lircconf -loop \ + -nojoystick -nolirc -nortc -playlist \ + -quiet -really-quiet -rnd -sdp -skin \ + -slave -softsleep -speed -sstep \ + -use-stdin -dumpaudio -dumpfile \ + -dumpstream -dumpvideo -dumpmicrodvdsub\ + -dumpmpsub -dumpsrtsub -dumpjacosub \ + -dumpsami -dumpsub -osdlevel -af \ + -af-adv -ao -aofile -aop -delay -mixer \ + -nowaveheader -bpp -brightness \ + -contrast -display -double -dr -dxr2 \ + -fb -fbmode -fbmodeconfig -forcexv -fs \ + -geometry -hue -icelayer -jpeg \ + -monitor-dotclock -monitor-hfreq \ + -monitor-vfreq -monitoraspect \ + -nograbpointer -noslices -panscan \ + -rootwin -saturation -screenw -screenh \ + -stop-xscreensaver -vm -vo -vsync -wid \ + -xineramascreen -z -zrbw -zrcrop \ + -zrdev -zrfd -zrhelp -zrnorm -zrquality \ + -zrvdec -zrhdec -zrxdoff -zrydoff -y \ + -edl -edlout -enqueue -fixed-vo \ + -menu -menu-root -menu-cfg -shuffle \ + -format -aahelp -dfbopts -fstype \ + -guiwid -nokeepaspect -x --help \ + -aaosdcolor -aasubcolor -aadriver \ + -aaextended -aaeight' -- $cur) ) + # add mencoder specific options + [[ "$cmd" = mencoder ]] && COMPREPLY=( "${COMPREPLY[@]}" \ + $(compgen -W '-audio-density -audio-delay \ + -audio-preload -divx4opts -endpos \ + -ffourcc -include -info -lameopts \ + -lavcopts -noskip -o -oac -ofps -ovc \ + -passlogfile -skiplimit -vobsubout \ + -vobsuboutindex -vobsuboutid \ + -xvidencopts -of --verbose' -- $cur) ) + ;; + *) + _filedir '@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|ASF|vob|VOB|bin|BIN|dat|DAT|vcd|VCD|ps|PS|pes|PES|fli|FLI|flv|FLV|viv|VIV|rm?(j)|RM?(J)|ra?(m)|RA?(M)|yuv|YUV|mov|MOV|qt|QT|mp[34]|MP[34]|m4v|M4V|og[gm]|OG[GM]|wav|WAV|dump|DUMP|mk[av]|MK[AV]|m4a|M4A|aac|AAC|m2v|M2V|dv|DV|rmvb|RMVB|mid|MID|ts|TS|3gp|mpc|MPC|flac|FLAC|flv|FLV|divx|DIVX)' + ;; + esac + + return 0 +} +complete $filenames -F _mplayer mplayer mencoder gmplayer kplayer +} + +# KDE dcop completion +# +have dcop && +_dcop() +{ + local cur compstr + + COMPREPLY=() + cur=`_get_cword` + if [ -z $cur ]; then + compstr=${COMP_WORDS[*]} + else + compstr=$( command echo ${COMP_WORDS[*]} | sed "s/ $cur$//" ) + fi + COMPREPLY=( $( compgen -W '$( command $compstr | sed s/\(.*\)// )' -- $cur ) ) +} && +complete -F _dcop dcop + +# wvdial(1) completion +# +have wvdial && +_wvdial() +{ + local cur prev config i IFS=$'\t\n' + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + --config) + _filedir + return 0 + ;; + esac + + case $cur in + -*) + COMPREPLY=( $( compgen -W '--config --chat \ + --remotename --help --version --no-syslog' \ + -- $cur ) ) + ;; + *) + # start with global and personal config files + config="/etc/wvdial.conf"$'\t'"$HOME/.wvdialrc" + # replace with command line config file if present + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == "--config" ]]; then + config=${COMP_WORDS[i+1]} + break + fi + done + # parse config files for sections and + # remove default section + COMPREPLY=( $( sed -ne \ + "s|^\[Dialer \($cur.*\)\]$|\1|p" \ + $config 2>/dev/null |grep -v '^Defaults$')) + # escape spaces + COMPREPLY=${COMPREPLY// /\\ } + ;; + esac + +} && +complete -F _wvdial wvdial + +# gpg(1) completion +# +have gpg && +_gpg() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(s|-sign|-clearsign|-decrypt-files|-load-extension)) + _filedir + return 0 + ;; + --@(export|@(?(l|nr|nrl)sign|edit)-key)) + # return list of public keys + COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*/\([^ ]*\).*\(<\([^>]*\)>\).*$@\1 \3@p')" -- "$cur" )) + return 0 + ;; + -@(r|-recipient)) + COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*<\([^>]*\)>.*$@\1@p')" -- "$cur" )) + if [ -e ~/.gnupg/gpg.conf ]; then + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$( sed -ne 's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' ~/.gnupg/gpg.conf )" -- "$cur") ) + fi + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-s -b -e -f -c -d -a -r -u -Z -o -v\ + -q -n -N $(gpg --dump-options)' -- $cur ) ) + fi + +} && +complete -F _gpg $default gpg + +# iconv(1) completion +# +have iconv && +_iconv() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(f|t|-@(from|to)-code)) + COMPREPLY=( $( compgen -W \ + '$( iconv --list | sed -e "s@//@@;" )' -- "$cur" ) ) + return 0 + ;; + esac + + + if [[ "$cur" = -* ]]; then + COMPREPLY=( $( compgen -W '--from-code -f --to-code -t --list + --output -o --verbose' -- "$cur" ) ) + return 0 + fi +} && +complete -F _iconv $default iconv + +# dict(1) completion +# +{ have dict || have rdict; } && { +_dictdata() +{ + dict $host $port $1 2>/dev/null | sed -ne \ + 's/^['$'\t '']['$'\t '']*\([^'$'\t '']*\).*$/\1/p' +} + +_dict() +{ + local cur prev host port db dictfile + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + dictfile=/usr/share/dict/words + + for (( i=1; i < COMP_CWORD; i++ )); do + case "${COMP_WORDS[i]}" in + -@(h|--host)) + host=${COMP_WORDS[i+1]} + [ -n "$host" ] && host="-h $host" + i=$((++i)) + ;; + -@(p|-port)) + port=${COMP_WORDS[i+1]} + [ -n "$port" ] && port="-p $port" + i=$((++i)) + ;; + -@(d|-database)) + db=${COMP_WORDS[i+1]} + [ -n "$db" ] && host="-d $db" + i=$((++i)) + ;; + *) + ;; + esac + done + + if [[ "$cur" = -* ]]; then + COMPREPLY=( $( compgen -W '-h --host -p --port -d --database \ + -m --match -s --strategy -c --config -C \ + --nocorrect -D --dbs -S --strats -H \ + --serverhelp -i --info -I --serverinfo \ + -a --noauth -u --user -k --key -V --version \ + -L --license --help -v --verbose -r --raw \ + -P --pager --debug --html --pipesize --client' \ + -- "$cur" ) ) + return 0 + fi + + case "$prev" in + -@(d|-database|i|info)) + COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) ) + return 0 + ;; + -@(s|-strategy)) + COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) ) + return 0 + ;; + *) + ;; + esac + + [ -r $dictfile ] && \ + COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) ) +} +complete -F _dict $default dict rdict +} + +# cdrecord(1) completion +# +have cdrecord && +_cdrecord() +{ + local cur prev i generic_options track_options track_mode + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # foo=bar style option + if [[ "$cur" == *=* ]]; then + prev=${cur/=*/} + cur=${cur/*=/} + case "$prev" in + @(text|cue)file) + _filedir + return 0 + ;; + blank) + COMPREPLY=( $( compgen -W 'help all fast \ + track unreserve trtail unclose session' \ + -- $cur ) ) + return 0 + ;; + driveropts) + COMPREPLY=( $( compgen -W 'burnfree noburnfree\ + varirec= audiomaster forcespeed noforcespeed\ + speedread nospeedread singlesession \ + nosinglesession hidecdr nohidecdr tattooinfo\ + tattoofile=' -- $cur ) ) + return 0 + ;; + esac + fi + + generic_options=(-version -v -V -d -silent -s -force -immed -dummy \ + -dao -raw -raw96r -raw96p -raw16 -multi -msinfo -toc \ + -atip -fix -nofix -waiti -load -lock -eject -format \ + -setdropts -checkdrive -prcap -inq -scanbus -reset \ + -abort -overburn -ignsize -useinfo -packet -noclose \ + -text debug= kdebug= kd= minbuf= speed= blank= fs= \ + dev= gracetime= timeout= driver= driveropts= \ + defpregap= pktsize= mcn= textfile= cuefile=) + track_options=(-audio -swab -data -mode2 -xa -xa1 -xa2 -xamix -cdi \ + -isosize -pad padsize= -nopad -shorttrack -noshorttrack\ + pregap= -preemp -nopreemp -copy -nocopy -scms tcsize= \ + isrc= index=) + # look if previous was either a file or a track option + track_mode=0 + if [ $COMP_CWORD -gt 1 ]; then + if [ -f "$prev" ]; then + track_mode=1 + else + for (( i=0; i < ${#track_options[@]}; i++ )); do + if [[ "${track_options[i]}" == "$prev" ]]; then + track_mode=1 + break + fi + done + fi + fi + + # files are always eligible completion + _filedir + # track options are always available + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '${track_options[@]}' -- $cur ) ) + # general options are no more available after file or track option + if [ $track_mode -eq 0 ]; then + COMPREPLY=( "${COMPREPLY[@]}" \ + $( compgen -W '${generic_options[@]}' -- $cur ) ) + fi + +} && +complete -F _cdrecord $filenames cdrecord + +# mkisofs(8) completion +# +have mkisofs && +_mkisofs() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(o|abstract|biblio|check-session|copyright|log-file|root-info|prep-boot|*-list)) + _filedir + return 0 + ;; + -*-charset) + COMPREPLY=( $( mkisofs -input-charset help 2>&1 | \ + tail +3 | grep "^$cur") ) + return 0 + ;; + -uid) + _uids + return 0 + ;; + -gid) + _gids + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-abstract -A -allow-lowercase \ + -allow-multidot -biblio -cache-inodes \ + -no-cache-inodes -b -eltorito-alt-boot -B -G \ + -hard-disk-boot -no-emul-boot -no-boot \ + -boot-load-seg -boot-load-size \ + -boot-info-table -C -c -check-oldname \ + -check-session -copyright -d -D -dir-mode \ + -dvd-video -f -file-mode -gid -gui \ + -graft-points -hide -hide-list -hidden \ + -hidden-list -hide-joliet -hide-joliet-list \ + -hide-joliet-trans-tbl -hide-rr-moved \ + -input-charset -output-charset -iso-level -J \ + -joliet-long -jcharset -l -L -log-file -m \ + -exclude-list -max-iso9660-filenames -M -N \ + -new-dir-mode -nobak -no-bak -force-rr -no-rr \ + -no-split-symlink-components \ + -no-split-symlink-fields -o -pad -no-pad \ + -path-list -P -p -print-size -quiet -R -r \ + -relaxed-filenames -sort -split-output \ + -stream-media-size -stream-file-name -sysid -T\ + -table-name -ucs-level -udf -uid \ + -use-fileversion -U -no-iso-translate -V \ + -volset -volset-size -volset-seqno -v -x -z \ + -hfs -apple -map -magic -hfs-creator \ + -hfs-type -probe -no-desktop -mac-name \ + -boot-hfs-file -part -auto -cluster-size \ + -hide-hfs -hide-hfs-list -hfs-volid \ + -icon-position -root-info -prep-boot \ + -input-hfs-charset -output-hfs-charset \ + -hfs-unlock -hfs-bless -hfs-parms --cap \ + --netatalk --double --ethershare --ushare \ + --exchange --sgi --xinet --macbin --single \ + --dave --sfm --osx-double --osx-hfs' -- $cur )) + else + _filedir + fi + +} && +complete -F _mkisofs $filenames mkisofs + +# mc(1) completion +# +have mc && +_mc() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # -name value style option + case "$prev" in + -@(e|v|l|P)) + _filedir + return 0 + ;; + esac + + # --name=value style option + if [[ "$cur" == *=* ]]; then + prev=${cur/=*/} + cur=${cur/*=/} + case "$prev" in + --@(edit|view|ftplog|printwd)) + _filedir + return 0 + ;; + esac + fi + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-a --stickchars -b --nocolor -c \ + --color -C --colors= -d --nomouse -e --edit= -f \ + --datadir -k --resetsoft -l --ftplog= -P --printwd= \ + -s --slow -t --termcap -u --nosubshell -U --subshell \ + -v --view= -V --version -x --xterm -h --help' -- $cur ) ) + else + _filedir -d + fi +} && +complete -F _mc $filenames mc + +# yum(8) completion +# +have yum && { +_yum() +{ + local cur prev special + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do + if [[ ${COMP_WORDS[i]} == @(install|update|upgrade|remove|erase|deplist) ]]; then + special=${COMP_WORDS[i]} + fi + done + + if [ -n "$special" ]; then + case $special in + install|deplist) + COMPREPLY=( $( compgen -W '$( yum -C list | cut -d" " -f1 )' -- $cur ) ) + return 0 + ;; + *) + _rpm_installed_packages + return 0 + ;; + esac + fi + + case $cur in + --*) + COMPREPLY=( $( compgen -W '--installroot --version --help --enablerepo --disablerepo --exclude --obsoletes --noplugins' -- $cur ) ) + return 0 + ;; + -*) + COMPREPLY=( $( compgen -W '-c -e -d -y -t -R -C -h' -- $cur ) ) + return 0 + ;; + esac + + case $prev in + list) + COMPREPLY=( $( compgen -W 'all available updates installed extras obsoletes recent' -- $cur ) ) + ;; + clean) + COMPREPLY=( $( compgen -W 'packages headers metadata cache dbcache all' -- $cur ) ) + ;; + localinstall) + _filedir rpm + ;; + -c) + _filedir + ;; + --installroot) + _filedir -d + ;; + *) + COMPREPLY=( $( compgen -W 'install update check-update upgrade remove list \ + search info provides clean groupinstall groupupdate \ + grouplist deplist erase groupinfo groupremove \ + localinstall localupdate makecache resolvedep \ + shell whatprovides' -- $cur ) ) + ;; + esac +} +complete -F _yum $filenames yum + +# yum-arch(8) completion +# +_yum_arch() +{ + local cur + COMPREPLY=() + cur=`_get_cword` + + case "$cur" in + -*) + COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- $cur ) ) + ;; + *) + _filedir -d + ;; + esac + + return 0 + +} +complete -F _yum_arch $filenames yum-arch +} + +# ImageMagick completion +# +have convert && { +_ImageMagick() +{ + local prev + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -channel) + COMPREPLY=( $( compgen -W 'Red Green Blue Opacity \ + Matte Cyan Magenta Yellow Black' -- $cur ) ) + return 0 + ;; + -colormap) + COMPREPLY=( $( compgen -W 'shared private' -- $cur ) ) + return 0 + ;; + -colorspace) + COMPREPLY=( $( compgen -W 'GRAY OHTA RGB Transparent \ + XYZ YCbCr YIQ YPbPr YUV CMYK' -- $cur ) ) + return 0 + ;; + -compose) + COMPREPLY=( $( compgen -W 'Over In Out Atop Xor Plus \ + Minus Add Subtract Difference Multiply Bumpmap\ + Copy CopyRed CopyGreen CopyBlue CopyOpacity' \ + -- $cur ) ) + return 0 + ;; + -compress) + COMPREPLY=( $( compgen -W 'None BZip Fax Group4 JPEG \ + Lossless LZW RLE Zip' -- $cur ) ) + return 0 + ;; + -dispose) + COMPREPLY=( $( compgen -W 'Undefined None Background \ + Previous' -- $cur ) ) + return 0 + ;; + -encoding) + COMPREPLY=( $( compgen -W 'AdobeCustom AdobeExpert \ + AdobeStandard AppleRoman BIG5 GB2312 Latin2 \ + None SJIScode Symbol Unicode Wansung' -- $cur)) + return 0 + ;; + -endian) + COMPREPLY=( $( compgen -W 'MSB LSB' -- $cur ) ) + return 0 + ;; + -filter) + COMPREPLY=( $( compgen -W 'Point Box Triangle Hermite \ + Hanning Hamming Blackman Gaussian Quadratic \ + Cubic Catrom Mitchell Lanczos Bessel Sinc' \ + -- $cur ) ) + return 0 + ;; + -format) + COMPREPLY=( $( convert -list format | \ + awk '/ [r-][w-][+-] / {print $1}' | \ + tr -d '*' | tr [:upper:] [:lower:] | \ + grep "^$cur" ) ) + return 0 + ;; + -gravity) + COMPREPLY=( $( compgen -W 'Northwest North NorthEast \ + West Center East SouthWest South SouthEast' \ + -- $cur ) ) + return 0 + ;; + -intent) + COMPREPLY=( $( compgen -W 'Absolute Perceptual \ + Relative Saturation' -- $cur ) ) + return 0 + ;; + -interlace) + COMPREPLY=( $( compgen -W 'None Line Plane Partition' \ + -- $cur ) ) + return 0 + ;; + -limit) + COMPREPLY=( $( compgen -W 'Disk File Map Memory' \ + -- $cur ) ) + return 0 + ;; + -list) + COMPREPLY=( $( compgen -W 'Delegate Format Magic \ + Module Resource Type' -- $cur ) ) + return 0 + ;; + -map) + COMPREPLY=( $( compgen -W 'best default gray red \ + green blue' -- $cur ) ) + _filedir + return 0 + ;; + -noise) + COMPREPLY=( $( compgen -W 'Uniform Gaussian \ + Multiplicative \ + Impulse Laplacian Poisson' -- $cur ) ) + return 0 + ;; + -preview) + COMPREPLY=( $( compgen -W 'Rotate Shear Roll Hue \ + Saturation Brightness Gamma Spiff \ + Dull Grayscale Quantize Despeckle \ + ReduceNoise AddNoise Sharpen Blur \ + Treshold EdgeDetect Spread Shade \ + Raise Segment Solarize Swirl Implode \ + Wave OilPaint CharcoalDrawing JPEG' \ + -- $cur ) ) + return 0 + ;; + -@(mask|profile|texture|tile|write)) + _filedir + return 0 + ;; + -type) + COMPREPLY=( $( compgen -W 'Bilevel Grayscale Palette \ + PaletteMatte TrueColor TrueColorMatte \ + ColorSeparation ColorSeparationlMatte \ + Optimize' -- $cur ) ) + return 0 + ;; + -units) + COMPREPLY=( $( compgen -W 'Undefined PixelsPerInch \ + PixelsPerCentimeter' -- $cur ) ) + return 0 + ;; + -virtual-pixel) + COMPREPLY=( $( compgen -W 'Constant Edge mirror tile' \ + -- $cur ) ) + return 0 + ;; + -visual) + COMPREPLY=( $( compgen -W 'StaticGray GrayScale \ + StaticColor PseudoColor TrueColor \ + DirectColor defaut visualid' -- $cur )) + return 0 + ;; + esac +} + +_convert() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + _ImageMagick + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-adjoin -affine -antialias -append \ + -authenticate -average -background -black-threshold \ + -blue-primary -blur -border -bordercolor -channel \ + -charcoal -chop -clip -coalesce -colorize -colors \ + -colorspace -comment -compress -contrast -convolve \ + -crop -cycle -debug -deconstruct -delay -density \ + -depth -despeckle -display -dispose -dither -draw \ + -edge -emboss -encoding -endian -enhance -equalize \ + -extract -fill -filter -flatten -flip -flop -font \ + -frame -fuzz -gamma -gaussian -geometry \ + -green-primary -gravity -help -implode -intent \ + -interlace -label -lat -level -limit -list -log -loop \ + -map -mask -matte -median -modulate -monochrome \ + -morph -mosaic -negate -noop -noise -normalize \ + -opaque -ordered-dither -page -paint -ping -pointsize \ + -preview -profile -quality -raise -random-threshold \ + -region -raise -red-primary -render -resize -resample \ + -roll -rotate -sample -sampling-factor -scale -scene \ + -seed -segment -shade -sharpen -shave -shear -size \ + -solarize -spread -stroke -strokewidth -swirl \ + -texture -threshold -thumbnail -tile -transform \ + -transparent -treedepth -trim -type -undercolor \ + -units -unsharp -verbose -version -view \ + -virtual-pixel -wave -white-point -white-threshold \ + -write' -- $cur ) ) + elif [[ "$cur" == +* ]]; then + COMPREPLY=( $( compgen -W '+adjoin +append +compress \ + +contrast +debug +dither +endian +gamma +label +map \ + +mask +matte +negate +noise +page +raise +render \ + +write' -- $cur ) ) + else + _filedir + fi +} +complete -F _convert $filenames convert + +_mogrify() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + _ImageMagick + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-affine -antialias -authenticate \ + -background -black-threshold -blue-primary -blur \ + -border -bordercolor -channel -charcoal -chop \ + -colorize -colors -colorspace -comment -compress \ + -contrast -convolve -crop -cycle -debug -delay \ + -density -depth -despeckle -display -dispose -dither \ + -draw -edge -emboss -encoding -endian -enhance \ + -equalize -extract -fill -filter -flip -flop -font \ + -format -frame -fuzz -gamma -gaussian -geometry \ + -green-primary -implode -interlace -help -label -lat \ + -level -limit -list -log -loop -map -mask -matte \ + -median -modulate -monochrome -negate -noop \ + -normalize -opaque -page -paint -fill -ordered-dither \ + -pointsize -profile -quality -raise -random-threshold \ + -red-primary -region -resample -resize -roll -rotate \ + -sample -sampling-factor -scale -scene -seed -segment \ + -shade -sharpen -shear -size -solarize -spread \ + -stroke -strokewidth -swirl -texture -threshold \ + -thumbnail -tile -transform -transparent -treedepth \ + -trim -type -undercolor -units -unsharp -verbose \ + -version -view -virtual-pixel -wave -white-point \ + -white-threshold' -- $cur ) ) + elif [[ "$cur" == +* ]]; then + COMPREPLY=( $( compgen -W '+compress +contrast +debug +dither \ + +endian +gamma +label +map +mask +matte +negate +page \ + +raise' -- $cur ) ) + else + _filedir + fi +} +complete -F _mogrify $filenames mogrify + +_display() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + _ImageMagick + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-authenticate -backdrop -border \ + -colormap -colors -colorspace -comment -compress \ + -contrast -crop -debug -delay -density -depth \ + -despeckle -display -dispose -dither -edge -endian \ + -enhance -extract -filter -flip -flop -frame -gamma \ + -geometry -help -immutable -interlace -label -limit \ + -log -map -matte -monochrome -negate -noop -page \ + -quality -raise -remote -roll -rotate -sample \ + -sampling-factor -scene -segment -sharpen -size \ + -texture -treedepth -trim -update -verbose -version \ + -virtual-pixel -window -window_group -write' -- $cur)) + elif [[ "$cur" == +* ]]; then + COMPREPLY=( $( compgen -W '+compress +contrast +debug +dither \ + +endian +gamma +label +map +matte +negate +page \ + +raise +write' -- $cur ) ) + else + _filedir + fi +} +complete -F _display $filenames display + +_animate() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + _ImageMagick + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-authenticate -backdrop -colormap \ + -colors -colorspace -crop -debug -delay -density \ + -depth -display -dither -extract -gamma -geometry \ + -help -interlace -limit -log -matte -map -monochrome \ + -noop -pause -remote -rotate -sampling-factor -scene \ + -size -treedepth -trim -verbose -version -visual \ + -virtual-pixel -window' -- $cur ) ) + elif [[ "$cur" == +* ]]; then + COMPREPLY=( $( compgen -W '+debug +dither +gamma +map +matte' -- $cur ) ) + else + _filedir + fi +} +complete -F _animate $filenames animate + +_identify() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + _ImageMagick + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-authenticate -debug -density \ + -depth -extract -format -help -interlace -limit -list \ + -log -size -sampling-factor -verbose -version \ + -virtual-pixel' -- $cur ) ) + elif [[ "$cur" == +* ]]; then + COMPREPLY=( $( compgen -W '+debug ' -- $cur ) ) + else + _filedir + fi +} +complete -F _identify $filenames identify + +_montage() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + _ImageMagick + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-adjoin -affine -authenticate \ + -blue-primary -blur -colors -colorspace -comment \ + -compose -compress -crop -debug -density -depth \ + -display -dispose -dither -draw -encoding -endian \ + -extract -fill -filter -flip -flop -frame -gamma \ + -geometry -gravity -green-primary -interlace -help \ + -label -limit -log -matte -mode -monochrome -noop \ + -page -pointsize -quality -red-primary -resize \ + -rotate -sampling-factor -scene -shadow -size \ + -stroke -texture -thumbnail -tile -transform \ + -transparent -treedepth -trim -type -verbose \ + -version -virtual-pixel -white-point' -- $cur ) ) + elif [[ "$cur" == +* ]]; then + COMPREPLY=( $( compgen -W '+adjoin +compress +debug +dither \ + +endian +gamma +label +matte +page' -- $cur ) ) + else + _filedir + fi +} +complete -F _montage $filenames montage + +_composite() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + _ImageMagick + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-affine -authenticate \ + -blue-primary -colors -colorspace -comment -compose \ + -compress -debug -density -depth -displace -display \ + -dispose -dissolve -dither -encoding -endian -extract \ + -filter -font -geometry -gravity -green-primary -help \ + -interlace -label -limit -log -matte -monochrome \ + -negate -page -profile -quality -red-primary -rotate \ + -resize -sampling-factor -scene -sharpen -size \ + -stegano -stereo -thumbnail -tile -transform \ + -treedepth -type -units -unsharp -verbose -version \ + -virtual-pixel -watermark -white-point -write' \ + -- $cur ) ) + elif [[ "$cur" == +* ]]; then + COMPREPLY=( $( compgen -W '+compress +debug +dither +endian +label \ + +matte +negate +page +write' -- $cur ) ) + else + _filedir + fi +} +complete -F _composite $filenames composite +} + +# dd(1) completion +# +have dd && +_dd() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + case "$cur" in + if=*|of=*) + cur=${cur#*=} + _filedir + return 0 + ;; + conv=*) + cur=${cur#*=} + COMPREPLY=( $( compgen -W 'ascii ebcdic ibm block unblock \ + lcase notrunc ucase swab noerror sync' \ + -- $cur ) ) + return 0 + ;; + esac + + _expand || return 0 + + COMPREPLY=( $( compgen -W '--help --version' -- $cur ) \ + $( compgen -W 'bs cbs conv count ibs if obs of seek skip'\ + -S '=' -- $cur ) ) +} && +complete -F _dd $nospace $filenames dd + +# CUPS cancel(1) completion +# +have cancel && +_cancel() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + COMPREPLY=( $( lpstat | cut -d' ' -f1 | grep "^$cur" ) ) +} && +complete -F _cancel $filenames cancel + +# aspell(1) completion +# +have aspell && { +_aspell_dictionary() +{ + local datadir + datadir=/usr/lib/aspell + COMPREPLY=( $( command ls $datadir/*.@(multi|alias) ) ) + COMPREPLY=( ${COMPREPLY[@]%.@(multi|alias)} ) + COMPREPLY=( $( compgen -W '${COMPREPLY[@]#$datadir/}' -- $cur ) ) +} + +_aspell() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # --name value style option + case "$prev" in + @(-c|-p|check)) + _filedir + return 0 + ;; + @(dump|create|merge)) + COMPREPLY=( $( compgen -W 'master personal repl' -- $cur ) ) + return 0 + ;; + -d) + _aspell_dictionary + return 0 + ;; + esac + + # --name=value style option + if [[ "$cur" == *=* ]]; then + prev=${cur/=*/} + cur=${cur/*=/} + case "$prev" in + --@(conf|personal|repl|per-conf)) + _filedir + return 0 + ;; + --@(conf-dir|data-dir|dict-dir|home-dir|local-data-dir|prefix)) + _filedir -d + return 0 + ;; + --master) + _aspell_dictionary + return 0 + ;; + --mode) + COMPREPLY=( $( compgen -W 'none url email sgml tex' -- $cur ) ) + return 0 + ;; + --sug-mode) + COMPREPLY=( $( compgen -W 'ultra fast normal bad-speller' -- $cur ) ) + return 0 + ;; + --keymapping) + COMPREPLY=( $( compgen -W 'aspell ispell' -- $cur ) ) + return 0 + ;; + esac + fi + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--conf= --conf-dir= --data-dir= --dict-dir= \ + --encoding= --add-filter= --rem-filter= --mode= -e \ + -H -t --add-extra-dicts= --rem-extra-dicts= \ + --home-dir= -W --ignore= --ignore-accents \ + --dont-ignore-accents --ignore-case --dont-ignore-case \ + --ignore-repl --dont-ignore-repl --jargon= --keyboard= \ + --lang= --language-tag= --local-data-dir= -d --master= \ + --module= --add-module-search-order= \ + --rem-module-search-order= --per-conf= -p --personal= \ + --prefix= --repl= -C -B --run-together --dont-run-together \ + --run-together-limit= --run-together-min= --save-repl \ + --dont-save-repl --set-prefix --dont-set-prefix --size= \ + --spelling= --strip-accents --dont-strip-accents \ + --sug-mode= --add-word-list-path= --rem-word-list-path= \ + -b -x --backup -b|-x --dont-backup --reverse --dont-reverse \ + --time --dont-time --keymapping= --add-email-quote= \ + --rem-email-quote= --email-margin= --add-tex-command= \ + --rem-tex-command= --tex-check-comments \ + --dont-tex-check-comments --add-tex-extension= \ + --rem-tex-extension= --add-sgml-check= --rem-sgml-check= \ + --add-sgml-extension= --rem-sgml-extension=' -- $cur ) ) + else + COMPREPLY=( $( compgen -W '-? help -c check -a pipe -l list \ + config config soundslike filter -v version dump \ + create merge' -- $cur ) ) + fi + +} +complete -F _aspell $filenames aspell +} + +# xmms(1) completion +# +have xmms && +_xmms() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-h --help -r --rew -p --play \ + -u --pause -s --stop -t --play-pause -f --fwd -e \ + --enqueue -m --show-main-window -i --sm-client-id \ + -v --version' -- $cur ) ) + else + _filedir '@(mp[23]|MP[23]|ogg|OGG|wav|WAV|pls|m3u|xm|mod|s[3t]m|it|mtm|ult|flac)' + + fi + +} && +complete -F _xmms $filenames xmms + +# info(1) completion +# +have info && +_info() +{ + local cur infopath UNAME + + COMPREPLY=() + cur=`_get_cword` + + _expand || return 0 + + # default completion if parameter contains / + if [[ "$cur" == */* ]]; then + _filedir + return 0 + fi + + infopath='/usr/share/info' + + if [ "${INFOPATH: -1:1}" == ':' ]; then + infopath=${INFOPATH}${infopath} + elif [ ${INFOPATH:+set} ]; then + infopath=$INFOPATH + fi + + infopath=$infopath: + if [ -n "$cur" ]; then + infopath="${infopath//://$cur* }" + else + infopath="${infopath//:// }" + fi + + # redirect stderr for when path doesn't exist + COMPREPLY=( $( eval command ls "$infopath" 2>/dev/null ) ) + # weed out directory path names and paths to info pages + COMPREPLY=( ${COMPREPLY[@]##*/?(:)} ) + # weed out info dir file + for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do + if [ "${COMPREPLY[$i]}" == 'dir' ]; then + unset COMPREPLY[$i]; + fi; + done + # strip suffix from info pages + COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} ) + COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) ) + + return 0 +} && +complete -F _info $filenames info + +# dhclient(1) completion +# +have dhclient && _dhclient() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(cf|lf|pf|sf)) + _filedir + return 0 + ;; + -s) + _known_hosts + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-p -d -q -1 -r -lf -pf \ + -cf -sf -s -g -n -nw -w' -- $cur ) ) + else + _available_interfaces + fi +} && +complete -F _dhclient dhclient + +# lvm(8) completion +# +have lvm && { +_volumegroups() +{ + COMPREPLY=( $(compgen -W "$( vgscan 2>/dev/null | \ + sed -n -e 's|.*Found.*"\(.*\)".*$|\1|p' )" -- $cur ) ) +} + +_physicalvolumes() +{ + COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \ + sed -n -e 's|^.*PV \(.*\) VG.*$|\1|p' )" -- $cur ) ) +} + +_logicalvolumes() +{ + COMPREPLY=( $(compgen -W "$( lvscan 2>/dev/null | \ + sed -n -e "s|^.*'\(.*\)'.*$|\1|p" )" -- $cur ) ) +} + +_units() +{ + COMPREPLY=( $( compgen -W 'h s b k m g t H K M G T' -- $cur ) ) +} + +_sizes() +{ + COMPREPLY=( $( compgen -W 'k K m M g G t T' -- $cur ) ) +} + +_args() +{ + args=0 + if [[ "${COMP_WORDS[0]}" == lvm ]]; then + offset=2 + else + offset=1 + fi + for (( i=$offset; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" != -* ]]; then + args=$(($args + 1)) + fi + done +} + +_lvmdiskscan() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -h -? --help -l \ + --lvmpartition -v --verbose --version' -- $cur ) ) + fi +} +complete -F _lvmdiskscan lvmdiskscan + +_pvscan() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -e \ + --exported -n --novolumegroup -h -? \ + --help --ignorelockingfailure -P \ + --partial -s --short -u --uuid -v \ + --verbose --version' -- $cur ) ) + fi +} +complete -F _pvscan pvscan + +_pvs() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(o|O|-options|-sort)) + COMPREPLY=( $( compgen -W 'pv_fmt pv_uuid \ + pv_size pv_free pv_used pv_name \ + pv_attr pv_pe_count \ + pv_pe_alloc_count' -- $cur ) ) + return 0 + ;; + --units) + _units + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--aligned -a --all -d --debug \ + -h -? --help --ignorelockingfailure --noheadings \ + --nosuffix -o --options -O --sort \ + --separator --unbuffered --units \ + -v --verbose --version' -- $cur ) ) + else + _physicalvolumes + fi +} +complete -F _pvs pvs + +_pvdisplay() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --units) + _units + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \ + -v --verbose -d --debug -h --help --version' -- $cur ) ) + else + _physicalvolumes + fi +} +complete -F _pvdisplay pvdisplay + +_pvchange() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|x|-autobackup|--allocatable)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-a --all -A --autobackup \ + -d --debug -h --help -t --test -u --uuid -x \ + --allocatable -v --verbose --addtag --deltag \ + --version' -- $cur ) ) + else + _physicalvolumes + fi +} +complete -F _pvchange pvchange + +_pvcreate() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --restorefile) + _filedir + return 0 + ;; + -@(M|-metadatatype)) + COMPREPLY=( $( compgen -W '1 2' -- $cur ) ) + return 0 + ;; + --metadatacopies) + COMPREPLY=( $( compgen -W '0 1 2' -- $cur ) ) + return 0 + ;; + --@(metadatasize|setphysicalvolumesize)) + _sizes + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--restorefile -d --debug -f \ + --force -h -? --help --labelsector -M --metadatatype \ + --metadatacopies --metadatasize \ + --setphysicalvolumesize -t --test -u --uuid uuid -v \ + --verbose -y --yes --version' -- $cur ) ) + else + _physicalvolumes + fi +} +complete -F _pvcreate pvcreate + +_pvmove() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(n|-name)) + _logicalvolumes + return 0 + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--abort -A --autobackup \ + -b --background -d --debug -f --force -h -? \ + --help -i --interval -t --test -v --verbose \ + --version -n --name' -- $cur ) ) + else + _physicalvolumes + fi +} +complete -F _pvmove pvmove + +_pvremove() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -f --force -h -? \ + --help -y --yes -t --test -v --verbose \ + --version' -- $cur ) ) + else + _physicalvolumes + fi +} +complete -F _pvremove pvremove + +_vgscan() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -h --help \ + --ignorelockingfailure --mknodes -P \ + --partial -v --verbose --version' -- $cur ) ) + fi +} +complete -F _vgscan vgscan + +_vgs() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(o|O|-options|-sort)) + COMPREPLY=( $( compgen -W 'vg_fmt vg_uuid vg_name \ + vg_attr vg_size vg_free vg_sysid \ + vg_extent_size vg_extent_count vg_free_count \ + max_lv max_pv pv_count lv_count snap_count \ + vg_seqno' -- $cur ) ) + return 0 + ;; + --units) + _units + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--aligned -d --debug \ + -h --help --ignorelockingfailure --noheadings \ + --nosuffix -o --options -O --sort -P --partial \ + --separator --unbuffered --units \ + -v --verbose --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgs vgs + +_vgdisplay() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --units) + _units + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \ + -P --partial -A --activevolumegroups -v --verbose \ + -d --debug -h --help --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgdisplay vgdisplay + +_vgchange() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(a|A|x|-available|-autobackup|-resizeable)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup --alloc -P \ + --partial -d --debug -h --help --ignorelockingfailure \ + -t --test -u --uuid -v --verbose --version -a \ + --available -x --resizeable -l --logicalvolume \ + --addtag --deltag' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgchange vgchange + +_vgcreate() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(M|-metadatatype)) + COMPREPLY=( $( compgen -W '1 2' -- $cur ) ) + return 0 + ;; + -@(s|-physicalextentsize)) + _sizes + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup --addtag \ + --alloc -d --debug -h --help -l --maxlogicalvolumes \ + -M --metadatatype -p --maxphysicalvolumes -s \ + --physicalextentsize -t --test -v --verbose \ + --version' -- $cur ) ) + else + _args + if [ $args -eq 0 ]; then + _volumegroups + else + _physicalvolumes + fi + fi +} +complete -F _vgcreate vgcreate + +_vgremove() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -h --help -t --test \ + -v --verbose --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgremove vgremove + +_vgrename() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \ + -? --help -t --test -v --verbose --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgrename vgrename + +_vgreduce() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-a --all -A --autobackup -d \ + --debug -h --help --removemissing -t --test -v \ + --verbose --version' -- $cur ) ) + + else + _args + if [ $args -eq 0 ]; then + _volumegroups + else + _physicalvolumes + fi + fi +} +complete -F _vgreduce vgreduce + +_vgextend() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(L|-size)) + _sizes + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \ + -? --help -t --test -v --verbose --version' -- $cur ) ) + else + _args + if [ $args -eq 0 ]; then + _volumegroups + else + _physicalvolumes + fi + fi +} +complete -F _vgextend vgextend + +_vgport() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-a --all -d --debug -h \ + -? --help -v --verbose --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgport vgimport vgexport + +_vgck() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -h \ + -? --help -v --verbose --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgck vgck + +_vgconvert() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(M|-metadatatype)) + COMPREPLY=( $( compgen -W '1 2' -- $cur ) ) + return 0 + ;; + --metadatacopies) + COMPREPLY=( $( compgen -W '0 1 2' -- $cur ) ) + return 0 + ;; + --metadatasize) + _sizes + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -h --help --labelsector \ + -M --metadatatype --metadatacopies --metadatasize \ + -t --test -v --verbose --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgconvert vgconvert + +_vgcfgbackup() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(f|-file)) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -f --file -h --help \ + --ignorelockingfailure -P --partial -v --verbose \ + --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgcfgbackup vgcfgbackup + +_vgcfgrestore() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(f|-file)) + _filedir + return 0 + ;; + -@(M|-metadatatype)) + COMPREPLY=( $( compgen -W '1 2' -- $cur ) ) + return 0 + ;; + -@(n|-name)) + _volumegroups + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -f --file -l --list \ + -h --help -M --Metadatatype -n --name -t --test \ + -v --verbose --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgcfgrestore vgcfgrestore + +_vgmerge() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup -d --debug \ + -h --help -l --list -t --test -v --verbose \ + --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgmerge vgmerge + +_vgsplit() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(M|-metadatatype)) + COMPREPLY=( $( compgen -W '1 2' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup -d --debug \ + -h --help -l --list -M --metadatatype -t --test \ + -v --verbose --version' -- $cur ) ) + else + _args + if [ $args -eq 0 -o $args -eq 1 ]; then + _volumegroups + else + _physicalvolumes + fi + fi +} +complete -F _vgsplit vgsplit + +_vgmknodes() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-d --debug -h --help -v --verbose \ + --version' -- $cur ) ) + else + _volumegroups + fi +} +complete -F _vgmknodes vgmknodes + +_lvscan() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-b --blockdevice -d --debug \ + -h -? --help --ignorelockingfailure -P \ + --partial -v --verbose --version' -- $cur ) ) + fi +} +complete -F _lvscan lvscan + +_lvs() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(o|O|-options|-sort)) + COMPREPLY=( $( compgen -W 'lv_uuid lv_name \ + lv_attr lv_minor lv_size seg_count \ + origin snap_percent segtype stripes \ + stripesize chunksize seg_start \ + seg_size' -- $cur ) ) + return 0 + ;; + --units) + _units + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--aligned -d --debug \ + -h --help --ignorelockingfailure --noheadings \ + --nosuffix -o --options -O --sort -P --partial \ + --segments --separator --unbuffered --units \ + -v --verbose --version' -- $cur ) ) + else + _logicalvolumes + fi +} +complete -F _lvs lvs + +_lvdisplay() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --units) + _units + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \ + -P --partial -m --maps -v --verbose -d --debug -h \ + --help --version' -- $cur ) ) + else + _logicalvolumes + fi +} +complete -F _lvdisplay lvdisplay + +_lvchange() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(a|A|C|M|-available|-autobackup|-continguous|-persistent)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(p|-permission)) + COMPREPLY=( $( compgen -W 'r rw' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup -a --available \ + --addtag --alloc -C --contiguous -d --debug --deltag \ + -f --force -h --help --ignorelockingfailure -M \ + --persistent --major major --minor minor -P --partial \ + -p --permission -r --readahead --refresh -t --test \ + -v --verbose --version' -- $cur ) ) + else + _logicalvolumes + fi +} +complete -F _lvchange lvchange + +_lvcreate() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|C|M|Z|-autobackup|-continguous|-persistent|-zero)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(L|-size)) + _sizes + return 0 + ;; + -@(p|-permission)) + COMPREPLY=( $( compgen -W 'r rw' -- $cur ) ) + return 0 + ;; + -@(n|-name)) + _logicalvolumes + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup --addtag --alloc \ + -C --contiguous -d --debug -h -? --help -i --stripes \ + -I --stripesize -l --extents -L --size -M --persistent \ + --major --minor -n --name -p --permission -r \ + --readahead -t --test --type -v --verbose -Z --zero \ + --version' -- $cur ) ) + else + _args + if [ $args -eq 0 ]; then + _volumegroups + else + _physicalvolumes + fi + fi +} +complete -F _lvcreate lvcreate + +_lvremove() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -f \ + --force -h -? --help -t --test -v --verbose \ + --version' -- $cur ) ) + else + _logicalvolumes + fi +} +complete -F _lvremove lvremove + +_lvrename() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \ + -? --help -t --test -v --verbose --version' -- $cur ) ) + else + _logicalvolumes + fi +} +complete -F _lvrename lvrename + +_lvreduce() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(L|-size)) + _sizes + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup -d \ + --debug -f --force -h --help -l --extents \ + -L --size -n --nofsck -r --resizefs -t --test \ + -v --verbose --version' -- $cur ) ) + else + _logicalvolumes + fi +} +complete -F _lvreduce lvreduce + +_lvresize() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(L|-size)) + _sizes + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup --alloc -d \ + --debug -h --help -i --stripes -I --stripesize \ + -l --extents -L --size -n --nofsck -r --resizefs \ + -t --test --type -v --verbose --version' -- $cur ) ) + else + _args + if [ $args -eq 0 ]; then + _logicalvolumes + else + _physicalvolumes + fi + fi +} +complete -F _lvresize lvresize + +_lvextend() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -@(A|-autobackup)) + COMPREPLY=( $( compgen -W 'y n' -- $cur ) ) + return 0 + ;; + -@(L|-size)) + _sizes + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-A --autobackup --alloc -d \ + --debug -h --help -i --stripes -I --stripesize \ + -l --extents -L --size -n --nofsck -r --resizefs \ + -t --test --type -v --verbose --version' -- $cur ) ) + else + _args + if [ $args -eq 0 ]; then + _logicalvolumes + else + _physicalvolumes + fi + fi +} +complete -F _lvextend lvextend + +_lvm() +{ + local prev + + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W 'dumpconfig help lvchange \ + lvcreate lvdisplay lvextend lvmchange \ + lvmdiskscan lvmsadc lvmsar lvreduce \ + lvremove lvrename lvresize lvs lvscan \ + pvchange pvcreate pvdata pvdisplay pvmove \ + pvremove pvresize pvs pvscan vgcfgbackup \ + vgcfgrestore vgchange vgck vgconvert \ + vgcreate vgdisplay vgexport vgextend \ + vgimport vgmerge vgmknodes vgreduce \ + vgremove vgrename vgs vgscan vgsplit \ + version' -- $cur ) ) + else + case ${COMP_WORDS[1]} in + pvchange) + _pvchange + ;; + pvcreate) + _pvcreate + ;; + pvdisplay) + _pvdisplay + ;; + pvmove) + _pvmove + ;; + pvremove) + _pvremove + ;; + pvresize) + _pvresize + ;; + pvs) + _pvs + ;; + pvscan) + _pvscan + ;; + vgcfgbackup) + _vgcfgbackup + ;; + vgcfgrestore) + _vgcfgrestore + ;; + vgchange) + _vgchange + ;; + vgck) + _vgck + ;; + vgconvert) + _vgconvert + ;; + vgcreate) + _vgcreate + ;; + vgdisplay) + _vgdisplay + ;; + vgexport) + _vgexport + ;; + vgextend) + _vgextend + ;; + vgimport) + _vgimport + ;; + vgmerge) + _vgmerge + ;; + vgmknodes) + _vgmknodes + ;; + vgreduce) + _vgreduce + ;; + vgremove) + _vgremove + ;; + vgrename) + _vgrename + ;; + vgs) + _vgs + ;; + vgscan) + _vgscan + ;; + vgsplit) + _vgsplit + ;; + lvchange) + _lvchange + ;; + lvcreate) + _lvcreate + ;; + lvdisplay) + _lvdisplay + ;; + lvextend) + _lvextend + ;; + lvreduce) + _lvreduce + ;; + lvremove) + _lvremove + ;; + lvrename) + _lvrename + ;; + lvresize) + _lvresize + ;; + lvs) + _lvs + ;; + lvscan) + _lvscan + ;; + esac + fi +} +complete -F _lvm lvm +} + +# mkinitrd(8) completion +# +have mkinitrd && +_mkinitrd() +{ + local cur args + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # --name value style option + case "$prev" in + --preload) + _modules + return 0 + ;; + esac + + # --name=value style option + if [[ "$cur" == *=* ]]; then + prev=${cur/=*/} + cur=${cur/*=/} + case "$prev" in + --@(with|builtin)) + _modules + return 0 + ;; + --@(fstab|dsdt)) + _filedir + return 0 + ;; + --tmpdir) + _filedir -d + return 0 + ;; + esac + fi + + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--version -v -f --preload \ + --with= --omit-scsi-modules --omit-raid-modules \ + --images-version --fstab= --nocompress --builtin= \ + --nopivot --noudev --allow-missing --tmpdir= \ + --initrdfs= --dsdt= --lvm-version= --froce-usb' \ + -- $cur ) ) + else + _count_args + + case $args in + 1) + _filedir + ;; + 2) + COMPREPLY=( $( command ls /lib/modules | grep "^$cur" ) ) + ;; + esac + fi + +} && +complete -F _mkinitrd mkinitrd + +# pkgconfig(1) completion +# +have pkg-config && +_pkg_config() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + # return list of available options + COMPREPLY=( $( compgen -W '-version --modversion \ + --atleast-pkgconfig-version= --libs --libs-only-l \ + --libs-only-other --libs-only-L --cflags \ + --cflags-only-I --cflags-only-other --variable= \ + --define-variable= --exists --uninstalled \ + --atleast-version= --exact-version= --max-version= \ + --list-all --debug --print-errors --silence-errors \ + --errors-to-stdout -? --help --usage' -- $cur)) + else + COMPREPLY=( $( pkg-config --list-all 2>/dev/null | \ + awk '{print $1}' | grep "^$cur" ) ) + fi +} && +complete -F _pkg_config pkg-config + + +# cpio(1) completion +# +have cpio && { +_cpio_format() +{ + COMPREPLY=( $( compgen -W 'bin odc newc crc tar ustar hpbin hpodc' -- $cur ) ) +} + +_cpio() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # --name value style option + case $prev in + -H) + _cpio_format + return 0 + ;; + -@(E|F|I)) + _filedir + return 0 + ;; + -R) + _usergroup + return 0 + ;; + esac + + # --name=value style option + if [[ "$cur" == *=* ]]; then + prev=${cur/=*/} + cur=${cur/*=/} + case $prev in + --format) + _cpio_format + return 0 + ;; + --@(file|pattern-file)) + _filedir + return 0 + ;; + --owner) + _usergroup + return 0 + ;; + --rsh-command) + COMPREPLY=( $( compgen -c -- $cur ) ) + return 0 + ;; + esac + fi + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W '-o --create -i --extract -p --pass-through' -- $cur) ) + else + case ${COMP_WORDS[1]} in + -@(o|-create)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-0 -a -c -v -A -B\ + -L -V -C -H -M -O -F --file= --format=\ + --message= --null --reset-access-time\ + --verbose --dot --append --block-size=\ + --dereference --io-size= --quiet\ + --force-local --rsh-command= --help\ + --version' -- $cur ) ) + fi + ;; + -@(i|-extract)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-b -c -d -f -m -n -r\ + -t -s -u -v -B -S -V -C -E -H -M -R -I\ + -F --file= --make-directories\ + --nonmatching\ + --preserve-modification-time\ + --numeric-uid-gid --rename -t --list\ + --swap-bytes --swap --dot\ + --unconditional --verbose --block-size=\ + --swap-halfwords --io-size=\ + --pattern-file= --format= --owner=\ + --no-preserve-owner --message=\ + --force-local --no-absolute-filenames\ + --sparse --only-verify-crc --quiet\ + --rsh-command= --help\ + --version' -- $cur ) ) + fi + ;; + -@(p|-pass-through)) + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-0 -a -d -l -m -u -v\ + -L -V -R --null --reset-access-time\ + --make-directories --link --quiet\ + --preserve-modification-time\ + --unconditional --verbose --dot\ + --dereference --owner=\ + --no-preserve-owner --sparse --help\ + --version' -- $cur ) ) + else + _filedir -d + fi + ;; + esac + fi +} +complete -F _cpio cpio +} + +# id(1) completion +# +have id && +_id() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-a -g --group -G --groups -n --name\ + -r --real -u --user --help --version' -- $cur ) ) + else + COMPREPLY=( $( compgen -u $cur ) ) + fi +} && +complete -F _id id + +# getent(1) completion +# +have getent && +_getent() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + passwd) + COMPREPLY=( $( compgen -u $cur ) ) + return 0 + ;; + group) + COMPREPLY=( $( compgen -g $cur ) ) + return 0 + ;; + services) + COMPREPLY=( $( compgen -s $cur ) ) + return 0 + ;; + hosts) + COMPREPLY=( $( compgen -A hostname $cur ) ) + return 0 + ;; + protocols) + COMPREPLY=( $( getent protocols | awk '{print $1}' | grep "^$cur" ) ) + return 0 + ;; + networks) + COMPREPLY=( $( getent networks | awk '{print $1}' | grep "^$cur" ) ) + return 0 + ;; + esac + + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W 'passwd group hosts services protocols networks' -- $cur ) ) + fi +} && +complete -F _getent getent + +# ntpdate(1) completion +# +have ntpdate && +_ntpdate() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + -k) + _filedir + return 0 + ;; + -U) + COMPREPLY=( $( compgen -u $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-4 -6 -b -B -d -Q -q -s -u -v -a\ + -e -k -p -o -r -t' -- $cur ) ) + else + _known_hosts + fi +} && +complete -F _ntpdate ntpdate + +# smartctl(8) completion +# +have smartctl && { +_smartctl_quietmode() +{ + COMPREPLY=( $( compgen -W 'errorsonly silent' -- $cur ) ) +} +_smartctl_device() +{ + COMPREPLY=( $( compgen -W 'ata scsi 3ware' -- $cur ) ) +} +_smartctl_tolerance() +{ + COMPREPLY=( $( compgen -W 'warn exit ignore' -- $cur ) ) +} +_smartctl_badsum() +{ + COMPREPLY=( $( compgen -W 'normal conservative permissive verypermissive' -- $cur ) ) +} +_smartctl_report() +{ + COMPREPLY=( $( compgen -W 'ioctl ataioctl scsiioctl' -- $cur ) ) +} +_smartctl_feature() +{ + COMPREPLY=( $( compgen -W 'on off' -- $cur ) ) +} +_smartctl_log() +{ + COMPREPLY=( $( compgen -W 'error selftest selective directory' -- $cur ) ) +} +_smartctl_vendorattribute() +{ + COMPREPLY=( $( compgen -W 'help 9,minutes 9,seconds 9,halfminutes \ + 9,temp 192,emergencyretractcyclect 193,loadunload \ + 194,10xCelsius 194,unknown 198,offlinescanuncsectorct \ + 200,writeerrorcount 201,detectedtacount 220,temp' -- $cur ) ) +} +_smartctl_firmwarebug() +{ + COMPREPLY=( $( compgen -W 'none samsung samsung2' -- $cur ) ) +} +_smartctl_presets() +{ + COMPREPLY=( $( compgen -W 'use ignore show showall' -- $cur ) ) +} +_smartctl_test() +{ + COMPREPLY=( $( compgen -W 'offline short long conveyance select afterselect,on afterselect,off pending' -- $cur ) ) +} + +_smartctl() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # --name value style option + case "$prev" in + -q) + _smartctl_quietmode + ;; + -d) + _smartctl_device + return 0 + ;; + -t) + _smartctl_tolerance + return 0 + ;; + -b) + _smartctl_badsum + return 0 + ;; + -r) + _smartctl_report + return 0 + ;; + -s) + _smartctl_feature + return 0 + ;; + -o) + _smartctl_feature + return 0 + ;; + -S) + _smartctl_feature + return 0 + ;; + -l) + _smartctl_log + return 0 + ;; + -v) + _smartctl_vendorattribute + return 0 + ;; + -F) + _smartctl_firmwarebug + return 0 + ;; + -P) + _smartctl_presets + return 0 + ;; + -t) + _smartctl_test + return 0 + ;; + esac + + # --name=value style option + if [[ "$cur" == *=* ]]; then + prev=${cur/=*/} + cur=${cur/*=/} + case "$prev" in + --quietmode) + _smartctl_quietmode + return 0 + ;; + --device) + _smartctl_device + return 0 + ;; + --tolerance) + _smartctl_tolerance + return 0 + ;; + --badsum) + _smartctl_badsum + return 0 + ;; + --report) + _smartctl_report + return 0 + ;; + --smart) + _smartctl_feature + return 0 + ;; + --offlineauto) + _smartctl_feature + return 0 + ;; + --saveauto) + _smartctl_feature + return 0 + ;; + --log) + _smartctl_log + return 0 + ;; + --vendorattribute) + _smartctl_vendorattribute + return 0 + ;; + --firmwarebug) + _smartctl_firmwarebug + return 0 + ;; + --presets) + _smartctl_presets + return 0 + ;; + --test) + _smartctl_test + return 0 + ;; + esac + fi + + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-h --help --usage -V --version \ + --copyright --license-i --info -a --all -q \ + --quietmode= -d --device= -T --tolerance= -b --badsum= \ + -r --report= -s --smart= -o --offlineauto= -S \ + --saveauto= -H --health -c --capabilities -A \ + --attributes -l --log= -v --vendorattribute= -F \ + --firmwarebug= -P --presets= -t --test= -C \ + --captive -X --abort' -- $cur ) ) + else + cur=${cur:=/dev/} + _filedir + fi +} +complete -F _smartctl smartctl +} + +# vncviewer(1) completion +# +have vncviewer && +_vncviewer() +{ + local cur prev + local -a config + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + -via) + _known_hosts -a + ;; + *) + # ssh into the the server, find and ping the broadcast address, then + # sort and show the results. + COMPREPLY=( $( ssh -o 'Batchmode yes' $prev \ + "ping -bnc 4 255.255.255.255" 2>/dev/null | \ + awk -F ' ' '{print $4}' | \ + sort -n | uniq | egrep '[0-9]+\.[0-9]+\.' 2>/dev/null ) ) + esac + + return 0 +} && +complete -F _vncviewer vncviewer + +# sysctl(8) completion +# +have sysctl && +_sysctl() +{ + local cur + + COMPREPLY=() + cur=`_get_cword` + + COMPREPLY=( $( compgen -W "$(sysctl -N -a 2>/dev/null)" -- $cur ) ) + + return 0 +} && +complete -F _sysctl sysctl + +# update-rc.d(8) completion +# +# Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com> +# +have update-rc.d && +_update_rc_d() +{ + local cur prev sysvdir services options valid_options + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \ + || sysvdir=/etc/init.d + + services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) ) + services=( ${services[@]#$sysvdir/} ) + options=( -f -n ) + + if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then + valid_options=( $( \ + echo "${COMP_WORDS[@]} ${options[@]}" \ + | tr " " "\n" \ + | sed -ne "/$( echo "${options[@]}" | sed "s/ /\\|/g" )/p" \ + | sort | uniq -u \ + ) ) + COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \ + -X '$( echo ${COMP_WORDS[@]} | tr " " "|" )' -- $cur ) ) + elif [[ "$prev" == ?($( echo ${services[@]} | tr " " "|" )) ]]; then + COMPREPLY=( $( compgen -W 'remove defaults start stop' -- $cur ) ) + elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then + COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 ) + elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then + COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 ) + elif [[ "$prev" == defaults && -z "$cur" ]]; then + COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k ) + elif [[ "$prev" == ?(start|stop) ]]; then + if [[ "$cur" == [0-9] || -z "$cur" ]]; then + COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 ) + elif [[ "$cur" == [0-9][0-9] ]]; then + COMPREPLY=( $cur ) + else + COMPREPLY=() + fi + elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then + if [[ -z "$cur" ]]; then + if [[ $prev == [0-9][0-9] ]]; then + COMPREPLY=( 0 1 2 3 4 5 6 S ) + else + COMPREPLY=( 0 1 2 3 4 5 6 S . ) + fi + elif [[ "$cur" == [0-6S.] ]]; then + COMPREPLY=( $cur ) + else + COMPREPLY=() + fi + elif [[ "$prev" == "." ]]; then + COMPREPLY=( $(compgen -W "start stop" -- $cur) ) + else + COMPREPLY=() + fi + + return 0 +} && +complete -F _update_rc_d update-rc.d + +# invoke-rc.d(8) completion +# +# Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com> +# +have invoke-rc.d && +_invoke_rc_d() +{ + local cur prev sysvdir services options valid_options + + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \ + || sysvdir=/etc/init.d + + services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) ) + services=( ${services[@]#$sysvdir/} ) + options=( --help --quiet --force --try-anyway --disclose-deny --query --no-fallback ) + + if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then + valid_options=( $( \ + echo ${COMP_WORDS[@]} ${options[@]} \ + | tr " " "\n" \ + | sed -ne "/$( echo ${options[@]} | sed "s/ /\\\\|/g" )/p" \ + | sort | uniq -u \ + ) ) + COMPREPLY=( $( compgen -W '${valid_options[@]} ${services[@]}' -- \ + $cur ) ) + elif [ -x $sysvdir/$prev ]; then + COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \ + s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \ + $sysvdir/$prev`' -- \ + $cur ) ) + else + COMPREPLY=() + fi + + return 0 +} && +complete -F _invoke_rc_d invoke-rc.d + +# minicom(1) completion +# +have minicom && +_minicom() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + -@(a|c)) + COMPREPLY=( $( compgen -W 'on off' -- $cur ) ) + return 0 + ;; + -@(S|C)) + _filedir + return 0 + ;; + -P) + COMPREPLY=( $( command ls /dev/tty* ) ) + COMPREPLY=( $( compgen -W '${COMPREPLY[@]} ${COMPREPLY[@]#/dev/}' -- $cur ) ) + return 0 + ;; + esac + + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-s -o -m -M -z -l -L -w -a -t \ + -c -S -d -p -C -T -8' -- $cur ) ) + else + COMPREPLY=( $( command ls /etc/minicom/minirc.* 2>/dev/null | sed -e 's|/etc/minicom/minirc.||' | grep "^$cur" ) ) + fi +} && +complete -F _minicom minicom + +# svn completion +# +have svn && +{ +_svn() +{ + local cur prev commands options command + + COMPREPLY=() + cur=`_get_cword` + + commands='add blame praise annotate ann cat checkout co cleanup commit \ + ci copy cp delete del remove rm diff di export help ? h import \ + info list ls lock log merge mkdir move mv rename ren \ + propdel pdel pd propedit pedit pe propget pget pg \ + proplist plist pl propset pset ps resolved revert \ + status stat st switch sw unlock update up' + + if [[ $COMP_CWORD -eq 1 ]] ; then + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--version' -- $cur ) ) + else + COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) + fi + else + + prev=${COMP_WORDS[COMP_CWORD-1]} + case $prev in + --config-dir) + _filedir -d + return 0; + ;; + -@(F|-file|-targets)) + _filedir + return 0; + ;; + --encoding) + COMPREPLY=( $( compgen -W \ + '$( iconv --list | sed -e "s@//@@;" )' \ + -- "$cur" ) ) + return 0; + ;; + --@(editor|diff|diff3)-cmd) + COMP_WORDS=(COMP_WORDS[0] $cur) + COMP_CWORD=1 + _command + return 0; + ;; + esac + + command=${COMP_WORDS[1]} + + if [[ "$cur" == -* ]]; then + # possible options for the command + case $command in + add) + options='--auto-props --no-auto-props \ + --force --targets --no-ignore \ + --non-recursive -N -q --quiet' + ;; + @(blame|annotate|ann|praise)) + options='-r --revisions --username \ + --password --no-auth-cache \ + --non-interactive -v \ + --verbose --incremental --xml' + ;; + cat) + options='-r --revision --username \ + --password --no-auth-cache \ + --non-interactive' + ;; + @(checkout|co)) + options='-r --revision -q --quiet -N \ + --non-recursive --username \ + --password --no-auth-cache \ + --non-interactive \ + --ignore-externals' + ;; + cleanup) + options='--diff3-cmd' + ;; + @(commit|ci)) + options='-m --message -F --file \ + --encoding --force-log -q \ + --quiet --non-recursive -N \ + --targets --editor-cmd \ + --username --password \ + --no-auth-cache \ + --non-interactive --no-unlock' + ;; + @(copy|cp)) + options='-m --message -F --file \ + --encoding --force-log -r \ + --revision -q --quiet \ + --editor-cmd -username \ + --password --no-auth-cache \ + --non-interactive' + ;; + @(delete|del|remove|rm)) + options='--force -m --message -F \ + --file --encoding --force-log \ + -q --quiet --targets \ + --editor-cmd -username \ + --password --no-auth-cache \ + --non-interactive' + ;; + @(diff|di)) + options='-r --revision -x --extensions \ + --diff-cmd --no-diff-deleted \ + -N --non-recursive --username \ + --password --no-auth-cache \ + --non-interactive --force \ + --old --new --notice-ancestry' + ;; + export) + options='-r --revision -q --quiet \ + --username --password \ + --no-auth-cache \ + --non-interactive -N \ + --non-recursive --force \ + --native-eol --ignore-externals' + ;; + import) + options='--auto-props --no-auto-props \ + -m --message -F --file \ + --encoding --force-log -q \ + --quiet --non-recursive \ + --no-ignore --editor-cmd \ + --username --password \ + --no-auth-cache \ + --non-interactive' + ;; + info) + options='--username --password \ + --no-auth-cache \ + --non-interactive -r \ + --revision --xml --targets \ + -R --recursive --incremental' + ;; + @(list|ls)) + options='-r --revision -v --verbose -R \ + --recursive --username \ + --password --no-auth-cache \ + --non-interactive \ + --incremental --xml' + ;; + lock) + options='-m --message -F --file \ + --encoding --force-log \ + --targets --force --username \ + --password --no-auth-cache \ + --non-interactive' + ;; + log) + options='-r --revision -v --verbose \ + --targets --username \ + --password --no-auth-cache \ + --non-interactive \ + --stop-on-copy --incremental \ + --xml -q --quiet --limit' + ;; + merge) + options='-r --revision -N \ + --non-recursive -q --quiet \ + --force --dry-run --diff3-cmd \ + --username --password \ + --no-auth-cache \ + --non-interactive \ + --ignore-ancestry' + ;; + mkdir) + options='-m --message -F --file \ + --encoding --force-log -q \ + --quiet --editor-cmd \ + --username --password \ + --no-auth-cache \ + --non-interactive' + ;; + @(move|mv|rename|ren)) + options='-m --message -F --file \ + --encoding --force-log -r \ + --revision -q --quiet \ + --force --editor-cmd \ + --username --password \ + --no-auth-cache \ + --non-interactive' + ;; + @(propdel|pdel|pd)) + options='-q --quiet -R --recursive -r \ + --revision --revprop \ + --username --password \ + --no-auth-cache \ + --non-interactive' + ;; + @(propedit|pedit|pe)) + options='-r --revision --revprop \ + --encoding --editor-cmd \ + --username --password \ + --no-auth-cache \ + --non-interactive --force' + ;; + @(propget|pget|pg)) + options='-R --recursive -r --revision \ + --revprop --strict --username \ + --password --no-auth-cache \ + --non-interactive' + ;; + @(proplist|plist|pl)) + options='-v --verbose -R --recursive \ + -r --revision --revprop -q \ + --quiet --username --password \ + --no-auth-cache \ + --non-interactive' + ;; + @(propset|pset|ps)) + options='-F --file -q --quiet \ + --targets -R --recursive \ + --revprop --encoding \ + --username --password \ + --no-auth-cache \ + --non-interactive -r \ + --revision --force' + ;; + resolved) + options='--targets -R --recursive -q \ + --quiet' + ;; + revert) + options='--targets -R --recursive -q \ + --quiet' + ;; + @(status|stat|st)) + options='-u --show-updates -v \ + --verbose -N --non-recursive \ + -q --quiet --username \ + --password --no-auth-cache \ + --non-interactive --no-ignore \ + --ignore-externals \ + --incremental --xml' + ;; + @(switch|sw)) + options='--relocate -r --revision -N \ + --non-recursive -q --quiet \ + --username --password \ + --no-auth-cache \ + --non-interactive --diff3-cmd' + ;; + unlock) + options='--targets --force --username \ + --password --no-auth-cache \ + --non-interactive' + ;; + @(update|up)) + options='-r --revision -N \ + --non-recursive -q --quiet \ + --username --password \ + --no-auth-cache \ + --non-interactive \ + --diff3-cmd --ignore-externals' + ;; + esac + options="$options --help -h --config-dir" + + COMPREPLY=( $( compgen -W "$options" -- $cur ) ) + else + if [[ "$command" == @(help|h|\?) ]]; then + COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) + else + _filedir + fi + fi + fi + + return 0 +} +complete -F _svn $default svn + +_svnadmin() +{ + local cur prev commands options mode + + COMPREPLY=() + cur=`_get_cword` + + commands='create deltify dump help ? hotcopy list-dblogs \ + list-unused-dblogs load lslocks lstxns recover rmlocks \ + rmtxns setlog verify' + + if [[ $COMP_CWORD -eq 1 ]] ; then + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--version' -- $cur ) ) + else + COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) + fi + else + prev=${COMP_WORDS[COMP_CWORD-1]} + case $prev in + --config-dir) + _filedir -d + return 0; + ;; + --fs-type) + COMPREPLY=( $( compgen -W 'fsfs bdb' -- $cur ) ) + return 0; + ;; + esac + + command=${COMP_WORDS[1]} + + if [[ "$cur" == -* ]]; then + # possible options for the command + case $command in + create) + options='--bdb-txn-nosync \ + --bdb-log-keep --config-dir \ + --fs-type' + ;; + deltify) + options='-r --revision -q --quiet' + ;; + dump) + options='-r --revision --incremental \ + -q --quiet --deltas' + ;; + hotcopy) + options='--clean-logs' + ;; + load) + options='--ignore-uuid --force-uuid \ + --parent-dir -q --quiet \ + --use-pre-commit-hook \ + --use-post-commit-hook' + ;; + rmtxns) + options='-q --quiet' + ;; + setlog) + options='-r --revision --bypass-hooks' + ;; + esac + + options="$options --help -h" + COMPREPLY=( $( compgen -W "$options" -- $cur ) ) + else + if [[ "$command" == @(help|h|\?) ]]; then + COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) + else + _filedir + fi + fi + fi + + return 0 +} +complete -F _svnadmin $default svnadmin + +_svnlook() +{ + local cur prev commands options mode + + COMPREPLY=() + cur=`_get_cword` + + commands='author cat changed date diff dirs-changed help ? h history \ + info lock log propget pget pg proplist plist pl tree uuid \ + youngest' + + if [[ $COMP_CWORD -eq 1 ]] ; then + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--version' -- $cur ) ) + else + COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) + fi + else + command=${COMP_WORDS[1]} + + if [[ "$cur" == -* ]]; then + # possible options for the command + case $command in + @(author|cat|date|dirs-changed|info|log)) + options='-r --revision -t \ + --transaction' + ;; + changed) + options='-r --revision -t \ + --transaction --copy-info' + ;; + diff) + options='-r --revision -t \ + --transaction \ + --no-diff-deleted \ + --no-diff-added \ + --diff-copy-from' + ;; + history) + options='-r --revision --show-ids' + ;; + prop@(get|list)) + options='-r --revision -t \ + --transaction --revprop' + ;; + tree) + options='-r --revision -t \ + --transaction --show-ids \ + --full-paths' + ;; + esac + + options="$options --help -h" + COMPREPLY=( $( compgen -W "$options" -- $cur ) ) + else + if [[ "$command" == @(help|h|\?) ]]; then + COMPREPLY=( $( compgen -W "$commands" -- $cur ) ) + else + _filedir + fi + fi + fi + + return 0 +} +complete -F _svnlook $default svnlook +} + +_filedir_xspec() +{ + local IFS cur xspec + + IFS=$'\t\n' + COMPREPLY=() + cur=`_get_cword` + + _expand || return 0 + + # get first exclusion compspec that matches this command + xspec=$( sed -ne $'/^complete .*[ \t]'${1##*/}$'\([ \t]\|$\)/{p;q;}' \ + $BASH_COMPLETION ) + # prune to leave nothing but the -X spec + xspec=${xspec#*-X } + xspec=${xspec%% *} + + local toks=( ) tmp + + while read -r tmp; do + [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp + done < <( compgen -d -- "$(quote_readline "$cur")" ) + + while read -r tmp; do + [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp + done < <( eval compgen -f -X $xspec -- "\$(quote_readline "\$cur")" ) + + COMPREPLY=( "${toks[@]}" ) +} +list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' \ + $BASH_COMPLETION | \ + # read exclusion compspecs + ( + while read line + do + # ignore compspecs that are commented out + if [ "${line#\#}" != "$line" ]; then continue; fi + line=${line%# START exclude*} + line=${line%# FINISH exclude*} + line=${line##*\'} + list=( "${list[@]}" $line ) + done + echo "${list[@]}" + ) + ) ) +# remove previous compspecs +if [ ${#list[@]} -gt 0 ]; then + eval complete -r ${list[@]} + # install new compspecs + eval complete -F _filedir_xspec $filenames "${list[@]}" +fi +unset list + +# source completion directory definitions +if [ -d $BASH_COMPLETION_DIR -a -r $BASH_COMPLETION_DIR -a \ + -x $BASH_COMPLETION_DIR ]; then + for i in $BASH_COMPLETION_DIR/*; do + [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|.rpm*) ]] && + [ \( -f $i -o -h $i \) -a -r $i ] && . $i + done +fi +unset i + +# source user completion file +[ $BASH_COMPLETION != ~/.bash_completion -a -r ~/.bash_completion ] \ + && . ~/.bash_completion +unset -f have +unset UNAME RELEASE default dirnames filenames have nospace bashdefault \ + plusdirs + +set $BASH_COMPLETION_ORIGINAL_V_VALUE +unset BASH_COMPLETION_ORIGINAL_V_VALUE + +### Local Variables: +### mode: shell-script +### End: diff --git a/examples/functions/autoload.v3 b/examples/functions/autoload.v3 index a82ffe9..b1e5dfe 100644 --- a/examples/functions/autoload.v3 +++ b/examples/functions/autoload.v3 @@ -1,4 +1,4 @@ -#From: Mark Kennedy <mtk@ny.ubs.com> +#From: Mark Kennedy <mark.t.kennedy@gmail.com> (<mtk@ny.ubs.com>) #Message-ID: <35E2B899.63A02DF5@ny.ubs.com> #Date: Tue, 25 Aug 1998 09:14:01 -0400 #To: chet@nike.ins.cwru.edu diff --git a/examples/loadables/Makefile.in b/examples/loadables/Makefile.in index f6208f5..343beb0 100644 --- a/examples/loadables/Makefile.in +++ b/examples/loadables/Makefile.in @@ -1,21 +1,21 @@ # # Simple makefile for the sample loadable builtins # -# Copyright (C) 1996 Free Software Foundation, Inc. +# Copyright (C) 1996-2009 Free Software Foundation, Inc. -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# # Include some boilerplate Gnu makefile definitions. prefix = @prefix@ @@ -26,6 +26,8 @@ libdir = @libdir@ infodir = @infodir@ includedir = @includedir@ +datarootdir = @datarootdir@ + topdir = @top_srcdir@ BUILD_DIR = @BUILD_DIR@ srcdir = @srcdir@ @@ -68,7 +70,7 @@ CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS) SHOBJ_CC = @SHOBJ_CC@ SHOBJ_CFLAGS = @SHOBJ_CFLAGS@ SHOBJ_LD = @SHOBJ_LD@ -SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ +SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ @LDFLAGS@ SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@ SHOBJ_LIBS = @SHOBJ_LIBS@ SHOBJ_STATUS = @SHOBJ_STATUS@ @@ -83,7 +85,7 @@ INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins \ ALLPROG = print truefalse sleep pushd finfo logname basename dirname \ tty pathchk tee head mkdir rmdir printenv id whoami \ - uname sync push ln unlink cut realpath getconf strftime + uname sync push ln unlink cut realpath getconf strftime mypid OTHERPROG = necho hello cat all: $(SHOBJ_STATUS) @@ -186,6 +188,9 @@ realpath: realpath.o strftime: strftime.o $(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ strftime.o $(SHOBJ_LIBS) +mypid: mypid.o + $(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ mypid.o $(SHOBJ_LIBS) + # pushd is a special case. We use the same source that the builtin version # uses, with special compilation options. # @@ -236,3 +241,4 @@ push.o: push.c mkdir.o: mkdir.c realpath.o: realpath.c strftime.o: strftime.c +mypid.o: mypid.c diff --git a/examples/loadables/README b/examples/loadables/README index 8a2ac81..d29b43a 100644 --- a/examples/loadables/README +++ b/examples/loadables/README @@ -32,9 +32,6 @@ the canonical example. There is no real `builtin writers' programming guide'. The file template.c provides a template to use for creating new loadable builtins. -On Debian GNU/Linux systems, the bash headers are in /usr/include/bash. -The appropriate options are already set in the example Makefile. - basename.c Return non-directory portion of pathname. cat.c cat(1) replacement with no options - the way cat was intended. cut.c cut(1) replacement. diff --git a/examples/loadables/basename.c b/examples/loadables/basename.c index 7f254c7..b5705cb 100644 --- a/examples/loadables/basename.c +++ b/examples/loadables/basename.c @@ -11,6 +11,7 @@ #include <stdio.h> #include "builtins.h" #include "shell.h" +#include "common.h" basename_builtin (list) WORD_LIST *list; @@ -90,6 +91,8 @@ basename_builtin (list) } char *basename_doc[] = { + "Return non-directory portion of pathname.", + "", "The STRING is converted to a filename corresponding to the last", "pathname component in STRING. If the suffix string SUFFIX is", "supplied, it is removed.", diff --git a/examples/loadables/cat.c b/examples/loadables/cat.c index 9dd1d1a..1ce2e2d 100644 --- a/examples/loadables/cat.c +++ b/examples/loadables/cat.c @@ -4,6 +4,24 @@ * no options - the way cat was intended */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <fcntl.h> #include <errno.h> @@ -84,6 +102,8 @@ WORD_LIST *list; } char *cat_doc[] = { + "Display files.", + "", "Read each FILE and display it on the standard output. If any", "FILE is `-' or if no FILE argument is given, the standard input", "is read.", diff --git a/examples/loadables/cut.c b/examples/loadables/cut.c index d874034..47d7d3e 100644 --- a/examples/loadables/cut.c +++ b/examples/loadables/cut.c @@ -63,6 +63,7 @@ static const char sccsid[] = "@(#)cut.c 8.3 (Berkeley) 5/4/95"; #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -359,6 +360,8 @@ _cut_strsep(stringp, delim) } static char *cut_doc[] = { + "Select portions of lines.", + "", "Select portions of each line (as specified by LIST) from each FILE", "(by default, the standard input), and write them to the standard output.", "Items specified by LIST are either column positions or fields delimited", diff --git a/examples/loadables/dirname.c b/examples/loadables/dirname.c index 6159560..0f30286 100644 --- a/examples/loadables/dirname.c +++ b/examples/loadables/dirname.c @@ -2,6 +2,24 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "config.h" #if defined (HAVE_UNISTD_H) @@ -11,6 +29,7 @@ #include <stdio.h> #include "builtins.h" #include "shell.h" +#include "common.h" dirname_builtin (list) WORD_LIST *list; @@ -78,6 +97,8 @@ dirname_builtin (list) } char *dirname_doc[] = { + "Display directory portion of pathname.", + "", "The STRING is converted to the name of the directory containing", "the filename corresponding to the last pathname component in STRING.", (char *)NULL diff --git a/examples/loadables/finfo.c b/examples/loadables/finfo.c index c1682ed..af7ffb6 100644 --- a/examples/loadables/finfo.c +++ b/examples/loadables/finfo.c @@ -1,5 +1,8 @@ /* * finfo - print file info + * + * Chet Ramey + * chet@po.cwru.edu */ #ifdef HAVE_CONFIG_H @@ -12,6 +15,7 @@ #include <pwd.h> #include <grp.h> #include <errno.h> +#include "posixtime.h" #include "bashansi.h" #include "shell.h" @@ -353,7 +357,7 @@ int flags; else printf("%d\n", st->st_gid); } else if (flags & OPT_SIZE) - printf("%ld\n", st->st_size); + printf("%ld\n", (long) st->st_size); return (0); } @@ -375,6 +379,8 @@ finfo_builtin(list) } static char *finfo_doc[] = { + "Display information about file attributes.", + "", "Display information about each FILE. Only single operators should", "be supplied. If no options are supplied, a summary of the info", "available about each FILE is printed. If FILE is of the form", diff --git a/examples/loadables/getconf.c b/examples/loadables/getconf.c index 0bf2079..d3dec41 100644 --- a/examples/loadables/getconf.c +++ b/examples/loadables/getconf.c @@ -1343,6 +1343,8 @@ getconf_one(list) } static char *getconf_doc[] = { + "Display values of system limits and options.", + "", "getconf writes the current value of a configurable system limit or", "option variable to the standard output.", (char *)NULL diff --git a/examples/loadables/head.c b/examples/loadables/head.c index 9052689..22cf6ab 100644 --- a/examples/loadables/head.c +++ b/examples/loadables/head.c @@ -2,6 +2,24 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "config.h" #include "bashtypes.h" @@ -21,6 +39,7 @@ #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -127,6 +146,8 @@ head_builtin (list) } char *head_doc[] = { + "Display lines from beginning of file.", + "", "Copy the first N lines from the input files to the standard output.", "N is supplied as an argument to the `-n' option. If N is not given,", "the first ten lines are copied.", diff --git a/examples/loadables/hello.c b/examples/loadables/hello.c index 1d68c6f..bff6e76 100644 --- a/examples/loadables/hello.c +++ b/examples/loadables/hello.c @@ -41,8 +41,11 @@ hello_builtin (list) } /* An array of strings forming the `long' documentation for a builtin xxx, - which is printed by `help xxx'. It must end with a NULL. */ + which is printed by `help xxx'. It must end with a NULL. By convention, + the first line is a short description. */ char *hello_doc[] = { + "Sample builtin.", + "", "this is the long doc for the sample hello builtin", (char *)NULL }; diff --git a/examples/loadables/id.c b/examples/loadables/id.c index 945190d..8773349 100644 --- a/examples/loadables/id.c +++ b/examples/loadables/id.c @@ -9,6 +9,24 @@ * uid=xxx(chet) gid=xx groups=aa(aname), bb(bname), cc(cname) */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #include <stdio.h> #include "bashtypes.h" @@ -294,7 +312,9 @@ id_prall (uname) } char *id_doc[] = { - "return information about user identity", + "Display information about user." + "", + "Return information about user identity", (char *)NULL }; diff --git a/examples/loadables/ln.c b/examples/loadables/ln.c index e3234e3..ec73636 100644 --- a/examples/loadables/ln.c +++ b/examples/loadables/ln.c @@ -2,6 +2,24 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "config.h" #include "bashtypes.h" @@ -18,6 +36,7 @@ #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -186,6 +205,8 @@ dolink (src, dst, flags) } char *ln_doc[] = { + "Link files.", + "", "Create a new directory entry with the same modes as the original", "file. The -f option means to unlink any existing file, permitting", "the link to occur. The -s option means to create a symbolic link.", diff --git a/examples/loadables/logname.c b/examples/loadables/logname.c index 00cfd19..95b7e21 100644 --- a/examples/loadables/logname.c +++ b/examples/loadables/logname.c @@ -1,5 +1,23 @@ /* logname - print login name of current user */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #if defined (HAVE_UNISTD_H) @@ -11,6 +29,7 @@ #include "builtins.h" #include "shell.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -35,7 +54,9 @@ logname_builtin (list) } char *logname_doc[] = { - "write the current user's login name to the standard output", + "Display user login name.", + "", + "Write the current user's login name to the standard output", "and exit. logname ignores the LOGNAME and USER variables.", "logname ignores any non-option arguments.", (char *)NULL diff --git a/examples/loadables/mkdir.c b/examples/loadables/mkdir.c index cd6e5f9..f41f171 100644 --- a/examples/loadables/mkdir.c +++ b/examples/loadables/mkdir.c @@ -2,6 +2,24 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #include "bashtypes.h" @@ -16,6 +34,7 @@ #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -191,6 +210,8 @@ make_path (path, nmode, parent_mode) } char *mkdir_doc[] = { + "Create directories.", + "", "Make directories. Create the directories named as arguments, in", "the order specified, using mode rwxrwxrwx as modified by the current", "umask (see `help umask'). The -m option causes the file permission", diff --git a/examples/loadables/mypid.c b/examples/loadables/mypid.c new file mode 100644 index 0000000..135cdb3 --- /dev/null +++ b/examples/loadables/mypid.c @@ -0,0 +1,74 @@ +/* This module should be dynamically loaded with enable -f + * which would create a new builtin named mypid. You'll need + * the source code for GNU bash to recompile this module. + * + * Then, from within bash, enable -f ./mypid enable_mypid, where ./mypid + * is the binary obtained from running make. Hereafter, `${MYPID}' + * is a shell builtin variable. + */ + +#include <stdio.h> +#include <errno.h> +#include <string.h> + +#include "builtins.h" +#include "shell.h" + +#define INIT_DYNAMIC_VAR(var, val, gfunc, afunc) \ + do \ + { SHELL_VAR *v = bind_variable (var, (val), 0); \ + v->dynamic_value = gfunc; \ + v->assign_func = afunc; \ + } \ + while (0) + +static SHELL_VAR * +assign_mypid ( + SHELL_VAR *self, + char *value, + arrayind_t unused, + char *key ) +{ + return (self); +} + +static SHELL_VAR * +get_mypid (SHELL_VAR *var) +{ + int rv; + char *p; + + rv = getpid(); + p = itos (rv); + + FREE (value_cell (var)); + + VSETATTR (var, att_integer); + var_setvalue (var, p); + return (var); +} + +int +enable_mypid_builtin(WORD_LIST *list) +{ + INIT_DYNAMIC_VAR ("MYPID", (char *)NULL, get_mypid, assign_mypid); + + return 0; +} + +char const *enable_mypid_doc[] = { + "Enable $MYPID.", + "", + "Enables use of the ${MYPID} dynamic variable. ", + "It will yield the current pid of a subshell.", + (char *)0 +}; + +struct builtin enable_mypid_struct = { + "enable_mypid", + enable_mypid_builtin, + BUILTIN_ENABLED, + (char**)(void*)enable_mypid_doc, + "enable_mypid N", + 0 +}; diff --git a/examples/loadables/necho.c b/examples/loadables/necho.c index 521ee2c..b567389 100644 --- a/examples/loadables/necho.c +++ b/examples/loadables/necho.c @@ -3,6 +3,24 @@ /* Sample builtin to be dynamically loaded with enable -f and replace an existing builtin. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <stdio.h> #include "builtins.h" #include "shell.h" @@ -17,6 +35,8 @@ WORD_LIST *list; } char *necho_doc[] = { + "Display arguments.", + "", "Print the arguments to the standard ouput separated", "by space characters and terminated with a newline.", (char *)NULL diff --git a/examples/loadables/pathchk.c b/examples/loadables/pathchk.c index 2e36f8f..c5fd24a 100644 --- a/examples/loadables/pathchk.c +++ b/examples/loadables/pathchk.c @@ -22,6 +22,24 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #include <sys/types.h> @@ -45,6 +63,7 @@ #include "stdc.h" #include "bashgetopt.h" #include "maxpath.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -112,6 +131,8 @@ pathchk_builtin (list) } char *pathchk_doc[] = { + "Check pathnames for validity.", + "", "Check each pathname argument for validity (i.e., it may be used to", "create or access a file without casuing syntax errors) and portability", "(i.e., no filename truncation will result). If the `-p' option is", diff --git a/examples/loadables/perl/Makefile.in b/examples/loadables/perl/Makefile.in index 3af9b85..d8860bd 100644 --- a/examples/loadables/perl/Makefile.in +++ b/examples/loadables/perl/Makefile.in @@ -2,31 +2,33 @@ # Makefile for builtin perl interpreter # # -# Copyright (C) 1998 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. +# Copyright (C) 1998 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# # Include some boilerplate Gnu makefile definitions. prefix = @prefix@ - exec_prefix = @exec_prefix@ + bindir = @bindir@ libdir = @libdir@ infodir = @infodir@ includedir = @includedir@ +datarootdir = @datarootdir@ + topdir = @top_srcdir@ BUILD_DIR = @BUILD_DIR@ srcdir = @srcdir@ diff --git a/examples/loadables/print.c b/examples/loadables/print.c index ad658a7..e17597b 100644 --- a/examples/loadables/print.c +++ b/examples/loadables/print.c @@ -2,6 +2,24 @@ * print -- loadable ksh-93 style print builtin */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #ifdef HAVE_CONFIG_H # include <config.h> #endif @@ -17,6 +35,8 @@ #include "builtins.h" #include "stdc.h" #include "bashgetopt.h" +#include "builtext.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -30,6 +50,8 @@ static FILE *ofp; extern char *this_command_name; static char *print_doc[] = { + "Display arguments.", + "", "Output the arguments. The -f option means to use the argument as a", "format string as would be supplied to printf(1). The rest of the", "options are as in ksh.", diff --git a/examples/loadables/printenv.c b/examples/loadables/printenv.c index 16f398f..8d3a05d 100644 --- a/examples/loadables/printenv.c +++ b/examples/loadables/printenv.c @@ -5,12 +5,31 @@ * */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #include <stdio.h> #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" extern char **export_env; @@ -53,11 +72,14 @@ printenv_builtin (list) else print_var_value (var, 0); + printf("\n"); return (EXECUTION_SUCCESS); } char *printenv_doc[] = { - "print values of environment variables", + "Display environment.", + "", + "Print names and values of environment variables", (char *)NULL }; diff --git a/examples/loadables/push.c b/examples/loadables/push.c index 497ecd0..b076073 100644 --- a/examples/loadables/push.c +++ b/examples/loadables/push.c @@ -3,6 +3,24 @@ * */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #include <stdio.h> #include <errno.h> @@ -11,6 +29,7 @@ #include "shell.h" #include "jobs.h" #include "bashgetopt.h" +#include "common.h" #ifndef errno extern int errno; @@ -78,6 +97,8 @@ push_builtin (list) } char *push_doc[] = { + "Create child shell.", + "", "Create a child that is an exact duplicate of the running shell", "and wait for it to exit. The $SHLVL, $!, $$, and $PPID variables", "are adjusted in the child. The return value is the exit status", diff --git a/examples/loadables/realpath.c b/examples/loadables/realpath.c index 16478b7..ffcbef8 100644 --- a/examples/loadables/realpath.c +++ b/examples/loadables/realpath.c @@ -18,6 +18,24 @@ * chet@po.cwru.edu */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "config.h" #include <sys/types.h> @@ -34,6 +52,7 @@ #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" #ifndef errno extern int errno; @@ -67,14 +86,14 @@ WORD_LIST *list; vflag = 1; break; default: - usage(); + builtin_usage(); } } list = loptend; if (list == 0) - usage(); + builtin_usage(); for (es = EXECUTION_SUCCESS; list; list = list->next) { p = list->word->word; @@ -101,6 +120,8 @@ WORD_LIST *list; } char *realpath_doc[] = { + "Display pathname in canonical form.", + "", "Display the canonicalized version of each PATHNAME argument, resolving", "symbolic links. The -c option checks whether or not each resolved name", "exists. The -s option produces no output; the exit status determines the", diff --git a/examples/loadables/rmdir.c b/examples/loadables/rmdir.c index 8d0f06a..0cfe6c7 100644 --- a/examples/loadables/rmdir.c +++ b/examples/loadables/rmdir.c @@ -2,12 +2,31 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "config.h" #include <stdio.h> #include <errno.h> #include "builtins.h" #include "shell.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -33,6 +52,8 @@ rmdir_builtin (list) } char *rmdir_doc[] = { + "Remove directory.", + "", "rmdir removes the directory entry specified by each argument,", "provided the directory is empty.", (char *)NULL diff --git a/examples/loadables/sleep.c b/examples/loadables/sleep.c index 10a62cf..a9bd36f 100644 --- a/examples/loadables/sleep.c +++ b/examples/loadables/sleep.c @@ -3,6 +3,25 @@ * * usage: sleep seconds[.fraction] */ + +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "config.h" #include "bashtypes.h" @@ -27,6 +46,7 @@ #include "shell.h" #include "builtins.h" +#include "common.h" #define RETURN(x) \ do { \ @@ -35,77 +55,6 @@ return (x); \ } while (0) -#if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) -static int -fsleep(sec, usec) -long sec, usec; -{ - struct timeval tv; - - tv.tv_sec = sec; - tv.tv_usec = usec; - - return select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv); -} -#else /* !HAVE_TIMEVAL || !HAVE_SELECT */ -static int -fsleep(sec, usec) -long sec, usec; -{ - if (usec >= 500000) /* round */ - sec++; - return (sleep(sec)); -} -#endif /* !HAVE_TIMEVAL || !HAVE_SELECT */ - -/* - * An incredibly simplistic floating point converter. - */ -static int multiplier[7] = { 1, 100000, 10000, 1000, 100, 10, 1 }; - -static int -convert(s, sp, usp) -char *s; -long *sp, *usp; -{ - int n; - long sec, usec; - char *p; - - sec = usec = 0; - -#define DECIMAL '.' - - for (p = s; p && *p; p++) { - if (*p == DECIMAL) /* decimal point */ - break; - if (DIGIT(*p) == 0) - RETURN(0); - sec = (sec * 10) + (*p - '0'); - } - - if (*p == 0) - RETURN(1); - - if (*p == DECIMAL) - p++; - - /* Look for up to six digits past a decimal point. */ - for (n = 0; n < 6 && p[n]; n++) { - if (DIGIT(p[n]) == 0) - RETURN(0); - usec = (usec * 10) + (p[n] - '0'); - } - - /* Now convert to millionths */ - usec *= multiplier[n]; - - if (n == 6 && p[6] >= '5' && p[6] <= '9') - usec++; /* round up 1 */ - - RETURN(1); -} - int sleep_builtin (list) WORD_LIST *list; @@ -122,7 +71,7 @@ WORD_LIST *list; return (EX_USAGE); } - if (convert(list->word->word, &sec, &usec)) { + if (uconvert(list->word->word, &sec, &usec)) { fsleep(sec, usec); return(EXECUTION_SUCCESS); } @@ -132,6 +81,8 @@ WORD_LIST *list; } static char *sleep_doc[] = { + "Suspend execution for specified period.", + "" "sleep suspends execution for a minimum of SECONDS[.FRACTION] seconds.", (char *)NULL }; diff --git a/examples/loadables/strftime.c b/examples/loadables/strftime.c index 92f489e..2de09e3 100644 --- a/examples/loadables/strftime.c +++ b/examples/loadables/strftime.c @@ -2,6 +2,24 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #if defined (HAVE_UNISTD_H) @@ -85,6 +103,8 @@ strftime_builtin (list) /* An array of strings forming the `long' documentation for a builtin xxx, which is printed by `help xxx'. It must end with a NULL. */ char *strftime_doc[] = { + "Display formatted time.", + "", "Converts date and time format to a string and displays it on the", "standard output. If the optional second argument is supplied, it", "is used as the number of seconds since the epoch to use in the", diff --git a/examples/loadables/sync.c b/examples/loadables/sync.c index 44d4e09..d91852e 100644 --- a/examples/loadables/sync.c +++ b/examples/loadables/sync.c @@ -1,5 +1,23 @@ /* sync - sync the disks by forcing pending filesystem writes to complete */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #ifdef HAVE_UNISTD_H @@ -18,7 +36,9 @@ sync_builtin (list) } char *sync_doc[] = { - "force completion of pending disk writes", + "Sync disks.", + "" + "Force completion of pending disk writes", (char *)NULL }; diff --git a/examples/loadables/tee.c b/examples/loadables/tee.c index 934abda..8b5715f 100644 --- a/examples/loadables/tee.c +++ b/examples/loadables/tee.c @@ -2,6 +2,24 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "config.h" #include "bashtypes.h" @@ -22,6 +40,7 @@ #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" #if !defined (errno) extern int errno; @@ -140,6 +159,8 @@ tee_builtin (list) } char *tee_doc[] = { + "Duplicate standard output.", + "", "Copy standard input to standard output, making a copy in each", "filename argument. If the `-a' option is gived, the specified", "files are appended to, otherwise they are overwritten. If the", diff --git a/examples/loadables/template.c b/examples/loadables/template.c index 7bb3f9f..3a5814f 100644 --- a/examples/loadables/template.c +++ b/examples/loadables/template.c @@ -43,6 +43,9 @@ template_builtin (list) } char *template_doc[] = { + "Short description.", + "" + "Longer description of builtin and usage.", (char *)NULL }; diff --git a/examples/loadables/truefalse.c b/examples/loadables/truefalse.c index e77c74c..113e88f 100644 --- a/examples/loadables/truefalse.c +++ b/examples/loadables/truefalse.c @@ -1,8 +1,29 @@ /* true and false builtins */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + #include "bashtypes.h" #include "shell.h" #include "builtins.h" +#include "common.h" true_builtin (list) WORD_LIST *list; @@ -17,11 +38,15 @@ false_builtin (list) } static char *true_doc[] = { + "Exit successfully.", + "", "Return a successful result.", (char *)NULL }; static char *false_doc[] = { + "Exit unsuccessfully.", + "", "Return an unsuccessful result.", (char *)NULL }; diff --git a/examples/loadables/tty.c b/examples/loadables/tty.c index 2183123..1d88506 100644 --- a/examples/loadables/tty.c +++ b/examples/loadables/tty.c @@ -2,12 +2,31 @@ /* See Makefile for compilation details. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include "config.h" #include <stdio.h> #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" extern char *ttyname (); @@ -40,6 +59,8 @@ tty_builtin (list) } char *tty_doc[] = { + "Display terminal name.", + "", "tty writes the name of the terminal that is opened for standard", "input to standard output. If the `-s' option is supplied, nothing", "is written; the exit status determines whether or not the standard", diff --git a/examples/loadables/uname.c b/examples/loadables/uname.c index 9f450cd..a1bddd5 100644 --- a/examples/loadables/uname.c +++ b/examples/loadables/uname.c @@ -5,6 +5,24 @@ * */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #include <stdio.h> @@ -27,6 +45,7 @@ struct utsname { #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" #define FLAG_SYSNAME 0x01 /* -s */ #define FLAG_NODENAME 0x02 /* -n */ @@ -125,7 +144,9 @@ uprint (flag, info) } char *uname_doc[] = { - "display information about the system", + "Display system information.", + "", + "Display information about the system hardware and OS.", (char *)NULL }; diff --git a/examples/loadables/unlink.c b/examples/loadables/unlink.c index 8c81ad0..07e3f3d 100644 --- a/examples/loadables/unlink.c +++ b/examples/loadables/unlink.c @@ -3,6 +3,24 @@ /* Should only be used to remove directories by a superuser prepared to let fsck clean up the file system. */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #ifdef HAVE_UNISTD_H @@ -14,6 +32,7 @@ #include "builtins.h" #include "shell.h" +#include "common.h" #ifndef errno extern int errno; @@ -39,6 +58,8 @@ unlink_builtin (list) char *unlink_doc[] = { "Remove a directory entry.", + "", + "Forcibly remove a directory entry, even if it's a directory.", (char *)NULL }; diff --git a/examples/loadables/whoami.c b/examples/loadables/whoami.c index 41fd5c4..6f8471a 100644 --- a/examples/loadables/whoami.c +++ b/examples/loadables/whoami.c @@ -2,12 +2,31 @@ * whoami - print out username of current user */ +/* + Copyright (C) 1999-2009 Free Software Foundation, Inc. + + This file is part of GNU Bash. + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ + #include <config.h> #include <stdio.h> #include "builtins.h" #include "shell.h" #include "bashgetopt.h" +#include "common.h" whoami_builtin (list) WORD_LIST *list; @@ -38,7 +57,9 @@ whoami_builtin (list) } char *whoami_doc[] = { - "display name of current user", + "Print user name", + "", + "Display name of current user.", (char *)NULL }; diff --git a/examples/misc/aliasconv.bash b/examples/misc/aliasconv.bash index 2245f06..22a0447 100755 --- a/examples/misc/aliasconv.bash +++ b/examples/misc/aliasconv.bash @@ -7,11 +7,13 @@ # Chet Ramey # chet@po.cwru.edu # -trap 'rm -f /tmp/cb$$.?' 0 1 2 3 6 15 +trap 'rm -f $TMPFILE' 0 1 2 3 6 15 + +TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1 T=$'\t' -cat << \EOF >/tmp/cb$$.1 +cat << \EOF >$TMPFILE mkalias () { case $2 in @@ -31,9 +33,9 @@ EOF # since they whole thing is going to be surrounded by single quotes when # passed to mkalias -sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>/tmp/cb$$.1 +sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE -$BASH /tmp/cb$$.1 | sed -e 's/\$cwd/\$PWD/g' \ +$BASH $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \ -e 's/\$term/\$TERM/g' \ -e 's/\$home/\$HOME/g' \ -e 's/\$user/\$USER/g' \ diff --git a/examples/misc/aliasconv.sh b/examples/misc/aliasconv.sh index 75db077..fe975d6 100755 --- a/examples/misc/aliasconv.sh +++ b/examples/misc/aliasconv.sh @@ -7,11 +7,11 @@ # Chet Ramey # chet@po.cwru.edu # -trap 'rm -f /tmp/cb$$.?' 0 1 2 3 6 15 - +trap 'rm -f $TMPFILE' 0 1 2 3 6 15 +TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1 T=' ' -cat << \EOF >/tmp/cb$$.1 +cat << \EOF >$TMPFILE mkalias () { case $2 in @@ -31,9 +31,9 @@ EOF # since they whole thing is going to be surrounded by single quotes when # passed to mkalias -sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>/tmp/cb$$.1 +sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE -sh /tmp/cb$$.1 | sed -e 's/\$cwd/\$PWD/g' \ +sh $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \ -e 's/\$term/\$TERM/g' \ -e 's/\$home/\$HOME/g' \ -e 's/\$user/\$USER/g' \ diff --git a/examples/misc/cshtobash b/examples/misc/cshtobash index 8e2b05c..ce49bfc 100755 --- a/examples/misc/cshtobash +++ b/examples/misc/cshtobash @@ -15,25 +15,34 @@ # Chet Ramey # chet@po.cwru.edu # -trap 'rm -f /tmp/cb$$.? cshout cshin' 0 1 2 3 6 15 +trap 'rm -f $TMPFILE1 $TMPFILEa $TMPFILEe $TMPFILEv $TMPFILEco $TMPFILEci' 0 1 2 3 6 15 + +{ TMPFILE1=$(mktemp -t cb.1.XXXXXX) && + TMPFILEa=$(mktemp -t cb.a.XXXXXX) && + TMPFILEe=$(mktemp -t cb.e.XXXXXX) && + TMPFILEv=$(mktemp -t cb.v.XXXXXX) && + TMPFILEco=$(mktemp -t cshout.XXXXXX) && + TMPFILEci=$(mktemp -t cshin.XXXXXX) +} || exit 1 + T=$'\t' SOURCE="${1:+source $1}" -cat << EOF >cshin +cat << EOF >$TMPFILEci $SOURCE -alias >! /tmp/cb$$.a -setenv >! /tmp/cb$$.e -set >! /tmp/cb$$.v +alias >! $TMPFILEa +setenv >! $TMPFILEe +set >! $TMPFILEv EOF # give csh a minimal environment, similar to what login would provide -/usr/bin/env - USER=$USER HOME=$HOME PATH=/usr/bin:/bin:/usr/ucb:. TERM=$TERM SHELL=$SHELL /bin/csh -i < ./cshin > cshout 2>&1 +/usr/bin/env - USER=$USER HOME=$HOME PATH=/usr/bin:/bin:/usr/ucb:. TERM=$TERM SHELL=$SHELL /bin/csh -i < $TMPFILEci > $TMPFILEco 2>&1 # First convert aliases -cat << \EOF >/tmp/cb$$.1 +cat << \EOF >$TMPFILE1 mkalias () { case $2 in @@ -49,12 +58,12 @@ mkalias () } EOF -sed "s/^\([a-zA-Z0-9_]*\)$T\(.*\)$/mkalias \1 '\2'/" < /tmp/cb$$.a >>/tmp/cb$$.1 +sed "s/^\([a-zA-Z0-9_]*\)$T\(.*\)$/mkalias \1 '\2'/" < $TMPFILEa >>$TMPFILE1 echo '# csh aliases' echo -$BASH /tmp/cb$$.1 | sed -e 's/\$cwd/\$PWD/g' \ +$BASH $TMPFILE1 | sed -e 's/\$cwd/\$PWD/g' \ -e 's/\$term/\$TERM/g' \ -e 's/\$home/\$HOME/g' \ -e 's/\$user/\$USER/g' \ @@ -70,7 +79,7 @@ sed -e '/^SHLVL/d' \ -e '/^PWD/d' \ -e "s/'/'"\\\\"''"/g \ -e "s/^\([A-Za-z0-9_]*=\)/export \1'/" \ - -e "s/$/'/" < /tmp/cb$$.e + -e "s/$/'/" < $TMPFILEe # Finally, convert local variables echo @@ -82,7 +91,7 @@ sed -e 's/'"$T"'/=/' \ -e '/^[A-Za-z0-9_]*=[^(]/{ s/=/='"'/"' s/$/'"'/"' - }' < /tmp/cb$$.v | + }' < $TMPFILEv | sed -e '/^argv=/d' -e '/^cwd=/d' -e '/^filec=/d' -e '/^status=/d' \ -e '/^verbose=/d' \ -e '/^term=/d' \ @@ -110,7 +119,7 @@ echo echo '# special csh variables converted to bash equivalents' echo -sed -e 's/'"$T"'/=/' < /tmp/cb$$.v | +sed -e 's/'"$T"'/=/' < $TMPFILEv | grep "^cdpath=" | sed 's/(// s/ /:/g @@ -118,7 +127,7 @@ sed 's/(// s/cdpath=/CDPATH=/' -sed -e 's/'"$T"'/=/' < /tmp/cb$$.v | +sed -e 's/'"$T"'/=/' < $TMPFILEv | grep "^mail=" | sed 's/(// s/ /:/g diff --git a/examples/obashdb/README b/examples/obashdb/README index 3373f5f..2f643d1 100644 --- a/examples/obashdb/README +++ b/examples/obashdb/README @@ -1,12 +1,3 @@ -This is a modified version of the Korn Shell debugger from Bill -Rosenblatt's `Learning the Korn Shell', published by O'Reilly -and Associates (ISBN 1-56592-054-6). - -The original `kshdb' is available for anonymous FTP with the URL - -http://examples.oreilly.com/korn/ksh.tar.Z - -A revised edition is available at: - -http://examples.oreilly.com/korn2/korn2_examples.tar.gz - +This is a sample implementation of a bash debugger. It is not the same +as the project available from http://bashdb.sourceforge.net, and has been +deprecated in favor of that implementation. diff --git a/examples/obashdb/bashdb b/examples/obashdb/bashdb index 97d287d..560cb7c 100644..100755 --- a/examples/obashdb/bashdb +++ b/examples/obashdb/bashdb @@ -1,33 +1,581 @@ -# kshdb - Korn Shell Debugger main file -# adapted from 'Learning the Korn Shell' by Bill Rosenblatt (O'Reilly) -# by Cigy Cyriac (cigy@felix.tulblr.unisys.com) -# Main driver: constructs full script (with preamble) and runs it +#! /bin/bash +# bashdb - Bash shell debugger +# +# Adapted from an idea in O'Reilly's `Learning the Korn Shell' +# Copyright (C) 1993-1994 O'Reilly and Associates, Inc. +# Copyright (C) 1998, 1999, 2001 Gary V. Vaughan <gvv@techie.com>> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. -echo 'Bourne-Again Shell Debugger version 0.1' +# NOTE: +# +# This program requires bash 2.x. +# If bash 2.x is installed as "bash2", you can invoke bashdb like this: +# +# DEBUG_SHELL=/bin/bash2 /bin/bash2 bashdb script.sh -_pname=${0##*/} +# TODO: +# +# break [regexp] +# cond [break] [condition] +# tbreak [regexp|+lines] +# restart +# Variable watchpoints +# Instrument `source' and `.' files in $_potbelliedpig +# be cleverer about lines we allow breakpoints to be set on +# break [function_name] -[ $# -eq 0 ] && { - echo "${_pname}: usage: ${_pname} <script_file>" - exit 1 -} +echo 'Bash Debugger version 1.2.4' + +export _dbname=${0##*/} + +if test $# -lt 1; then + echo "$_dbname: Usage: $_dbname filename" >&2 + exit 1 +fi _guineapig=$1 -[ -r $_guineapig ] || { - echo "${_pname}: cannot read $_guineapig." >&2 - exit 1 -} +if test ! -r $1; then + echo "$_dbname: Cannot read file '$_guineapig'." >&2 + exit 1 +fi + shift -_tmpdir=/tmp -_libdir=. -_dbgfile=$_tmpdir/bashdb$$ #temp file for script being debugged +__debug=${TMPDIR-/tmp}/bashdb.$$ +sed -e '/^# bashdb - Bash shell debugger/,/^# -- DO NOT DELETE THIS LINE -- /d' "$0" > $__debug +cat $_guineapig >> $__debug +exec ${DEBUG_SHELL-bash} $__debug $_guineapig "$@" -cat $_libdir/bashdb.pre $_guineapig > $_dbgfile -if [ -f "$BASH" ]; then - exec $BASH $_dbgfile $_guineapig $_tmpdir $_libdir "$@" -else - exec bash $_dbgfile $_guineapig $_tmpdir $_libdir "$@" -fi -# end of bashdb +exit 1 + +# -- DO NOT DELETE THIS LINE -- The program depends on it + +#bashdb preamble +# $1 name of the original guinea pig script + +__debug=$0 +_guineapig=$1 +__steptrap_calls=0 + +shift + +shopt -s extglob # turn on extglob so we can parse the debugger funcs + +function _steptrap +{ + local i=0 + + _curline=$1 + + if (( ++__steptrap_calls > 1 && $_curline == 1 )); then + return + fi + + if [ -n "$_disps" ]; then + while (( $i < ${#_disps[@]} )) + do + if [ -n "${_disps[$i]}" ]; then + _msg "${_disps[$i]}: \c" + eval _msg ${_disps[$i]} + fi + let i=$i+1 + done + fi + + if (( $_trace )); then + _showline $_curline + fi + + if (( $_steps >= 0 )); then + let _steps="$_steps - 1" + fi + + if _at_linenumbp ; then + _msg "Reached breakpoint at line $_curline" + _showline $_curline + _cmdloop + elif [ -n "$_brcond" ] && eval $_brcond; then + _msg "Break condition $_brcond true at line $_curline" + _showline $_curline + _cmdloop + elif (( $_steps == 0 )); then + # Assuming a real script will have the "#! /bin/sh" at line 1, + # assume that when $_curline == 1 we are inside backticks. + if (( ! $_trace )); then + _msg "Stopped at line $_curline" + _showline $_curline + fi + _cmdloop + fi +} + +function _setbp +{ + local i f line _x + + if [ -z "$1" ]; then + _listbp + return + fi + + eval "$_seteglob" + + if [[ $1 == *(\+)[1-9]*([0-9]) ]]; then + case $1 in + +*) + # normalize argument, then double it (+2 -> +2 + 2 = 4) + _x=${1##*([!1-9])} # cut off non-numeric prefix + _x=${x%%*([!0-9])} # cut off non-numeric suffix + f=$(( $1 + $_x )) + ;; + *) + f=$(( $1 )) + ;; + esac + + # find the next valid line + line="${_lines[$f]}" + while _invalidbreakp $f + do + (( f++ )) + line="${_lines[$f]}" + done + + if (( $f != $1 )) + then + _msg "Line $1 is not a valid breakpoint" + fi + + if [ -n "${_lines[$f]}" ]; then + _linebp[$1]=$1; + _msg "Breakpoint set at line $f" + else + _msg "Breakpoints can only be set on executable lines" + fi + else + _msg "Please specify a numeric line number" + fi + + eval "$_resteglob" +} + +function _listbp +{ + local i + + if [ -n "$_linebp" ]; then + _msg "Breakpoints:" + for i in ${_linebp[*]}; do + _showline $i + done + else + _msg "No breakpoints have been set" + fi +} + +function _clearbp +{ + local i + + if [ -z "$1" ]; then + read -e -p "Delete all breakpoints? " + case $REPLY in + [yY]*) + unset _linebp[*] + _msg "All breakpoints have been cleared" + ;; + esac + return 0 + fi + + eval "$_seteglob" + + if [[ $1 == [1-9]*([0-9]) ]]; then + unset _linebp[$1] + _msg "Breakpoint cleared at line $1" + else + _msg "Please specify a numeric line number" + fi + + eval "$_resteglob" +} + +function _setbc +{ + if (( $# > 0 )); then + _brcond=$@ + _msg "Break when true: $_brcond" + else + _brcond= + _msg "Break condition cleared" + fi +} + +function _setdisp +{ + if [ -z "$1" ]; then + _listdisp + else + _disps[${#_disps[@]}]="$1" + if (( ${#_disps[@]} < 10 )) + then + _msg " ${#_disps[@]}: $1" + else + _msg "${#_disps[@]}: $1" + fi + fi +} + +function _listdisp +{ + local i=0 j + + if [ -n "$_disps" ]; then + while (( $i < ${#_disps[@]} )) + do + let j=$i+1 + if (( ${#_disps[@]} < 10 )) + then + _msg " $j: ${_disps[$i]}" + else + _msg "$j: ${_disps[$i]}" + fi + let i=$j + done + else + _msg "No displays have been set" + fi +} + +function _cleardisp +{ + if (( $# < 1 )) ; then + read -e -p "Delete all display expressions? " + case $REPLY in + [Yy]*) + unset _disps[*] + _msg "All breakpoints have been cleared" + ;; + esac + return 0 + fi + + eval "$_seteglob" + + if [[ $1 == [1-9]*([0-9]) ]]; then + unset _disps[$1] + _msg "Display $i has been cleared" + else + _listdisp + _msg "Please specify a numeric display number" + fi + + eval "$_resteglob" +} + +# usage _ftrace -u funcname [funcname...] +function _ftrace +{ + local _opt=-t _tmsg="enabled" _func + if [[ $1 == -u ]]; then + _opt=+t + _tmsg="disabled" + shift + fi + for _func; do + declare -f $_opt $_func + _msg "Tracing $_tmsg for function $_func" + done +} + +function _cmdloop +{ + local cmd args + + while read -e -p "bashdb> " cmd args; do + test -n "$cmd" && history -s "$cmd $args" # save on history list + test -n "$cmd" || { set $_lastcmd; cmd=$1; shift; args=$*; } + if [ -n "$cmd" ] + then + case $cmd in + b|br|bre|brea|break) + _setbp $args + _lastcmd="break $args" + ;; + co|con) + _msg "ambiguous command: '$cmd', condition, continue?" + ;; + cond|condi|condit|conditi|conditio|condition) + _setbc $args + _lastcmd="condition $args" + ;; + c|cont|conti|contin|continu|continue) + _lastcmd="continue" + return + ;; + d) + _msg "ambiguous command: '$cmd', delete, display?" + ;; + de|del|dele|delet|delete) + _clearbp $args + _lastcmd="delete $args" + ;; + di|dis|disp|displ|displa|display) + _setdisp $args + _lastcmd="display $args" + ;; + f|ft|ftr|ftra|ftrace) + _ftrace $args + _lastcmd="ftrace $args" + ;; + \?|h|he|hel|help) + _menu + _lastcmd="help" + ;; + l|li|lis|list) + _displayscript $args + # _lastcmd is set in the _displayscript function + ;; + p|pr|pri|prin|print) + _examine $args + _lastcmd="print $args" + ;; + q|qu|qui|quit) + exit + ;; + s|st|ste|step|n|ne|nex|next) + let _steps=${args:-1} + _lastcmd="next $args" + return + ;; + t|tr|tra|trac|trace) + _xtrace + ;; + u|un|und|undi|undis|undisp|undispl|undispla|undisplay) + _cleardisp $args + _lastcmd="undisplay $args" + ;; + !*) + eval ${cmd#!} $args + _lastcmd="$cmd $args" + ;; + *) + _msg "Invalid command: '$cmd'" + ;; + esac + fi + done +} + +function _at_linenumbp +{ + [[ -n ${_linebp[$_curline]} ]] +} + +function _invalidbreakp +{ + local line=${_lines[$1]} + + # XXX - should use shell patterns + if test -z "$line" \ + || expr "$line" : '[ \t]*#.*' > /dev/null \ + || expr "$line" : '[ \t]*;;[ \t]*$' > /dev/null \ + || expr "$line" : '[ \t]*[^)]*)[ \t]*$' > /dev/null \ + || expr "$line" : '[ \t]*;;[ \t]*#.**$' > /dev/null \ + || expr "$line" : '[ \t]*[^)]*)[ \t]*;;[ \t]*$' > /dev/null \ + || expr "$line" : '[ \t]*[^)]*)[ \t]*;;*[ \t]*#.*$' > /dev/null + then + return 0 + fi + + return 1 +} + +function _examine +{ + if [ -n "$*" ]; then + _msg "$args: \c" + eval _msg $args + else + _msg "Nothing to print" + fi +} + +function _displayscript +{ + local i j start end bp cl + + if (( $# == 1 )); then # list 5 lines on either side of $1 + if [ $1 = "%" ]; then + let start=1 + let end=${#_lines[@]} + else + let start=$1-5 + let end=$1+5 + fi + elif (( $# > 1 )); then # list between start and end + if [ $1 = "^" ]; then + let start=1 + else + let start=$1 + fi + + if [ $2 = "\$" ]; then + let end=${#_lines[@]} + else + let end=$2 + fi + else # list 5 lines on either side of current line + let start=$_curline-5 + let end=$_curline+5 + fi + + # normalize start and end + if (( $start < 1 )); then + start=1 + fi + if (( $end > ${#_lines[@]} )); then + end=${#_lines[@]} + fi + + cl=$(( $end - $start )) + if (( $cl > ${LINES-24} )); then + pager=${PAGER-more} + else + pager=cat + fi + + i=$start + ( while (( $i <= $end )); do + _showline $i + let i=$i+1 + done ) 2>&1 | $pager + + # calculate the next block of lines + start=$(( $end + 1 )) + end=$(( $start + 11 )) + if (( $end > ${#_lines[@]} )) + then + end=${#_lines[@]} + fi + + _lastcmd="list $start $end" +} + +function _xtrace +{ + let _trace="! $_trace" + if (( $_trace )); then + _msg "Execution trace on" + else + _msg "Execution trace off" + fi +} + +function _msg +{ + echo -e "$@" >&2 +} + +function _showline +{ + local i=0 bp=' ' line=$1 cl=' ' + + if [[ -n ${_linebp[$line]} ]]; then + bp='*' + fi + + if (( $_curline == $line )); then + cl=">" + fi + + if (( $line < 100 )); then + _msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}" + elif (( $line < 10 )); then + _msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}" + elif (( $line > 0 )); then + _msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}" + fi +} + +function _cleanup +{ + rm -f $__debug $_potbelliedpig 2> /dev/null +} + +function _menu +{ + _msg 'bashdb commands: + break N set breakpoint at line N + break list breakpoints & break condition + condition foo set break condition to foo + condition clear break condition + delete N clear breakpoint at line N + delete clear all breakpoints + display EXP evaluate and display EXP for each debug step + display show a list of display expressions + undisplay N remove display expression N + list N M display all lines of script between N and M + list N display 5 lines of script either side of line N + list display 5 lines if script either side of current line + continue continue execution upto next breakpoint + next [N] execute [N] statements (default 1) + print expr prints the value of an expression + trace toggle execution trace on/off + ftrace [-u] func make the debugger step into function FUNC + (-u turns off tracing FUNC) + help print this menu + ! string passes string to a shell + quit quit' +} + +shopt -u extglob + +HISTFILE=~/.bashdb_history +set -o history +set +H + +# strings to save and restore the setting of `extglob' in debugger functions +# that need it +_seteglob='local __eopt=-u ; shopt -q extglob && __eopt=-s ; shopt -s extglob' +_resteglob='shopt $__eopt extglob' + +_linebp=() +let _trace=0 +let _i=1 + +# Be careful about quoted newlines +_potbelliedpig=${TMPDIR-/tmp}/${_guineapig/*\//}.$$ +sed 's,\\$,\\\\,' $_guineapig > $_potbelliedpig + +_msg "Reading source from file: $_guineapig" +while read; do + _lines[$_i]=$REPLY + let _i=$_i+1 +done < $_potbelliedpig + +trap _cleanup EXIT +# Assuming a real script will have the "#! /bin/sh" at line 1, +# don't stop at line 1 on the first run +let _steps=1 +LINENO=-1 +trap '_steptrap $LINENO' DEBUG diff --git a/examples/bashdb/bashdb.el b/examples/obashdb/bashdb.el index 40584dd..40584dd 100644 --- a/examples/bashdb/bashdb.el +++ b/examples/obashdb/bashdb.el diff --git a/examples/obashdb/bashdb.fns b/examples/obashdb/bashdb.fns deleted file mode 100644 index ac0612c..0000000 --- a/examples/obashdb/bashdb.fns +++ /dev/null @@ -1,237 +0,0 @@ -# bashdb.fns - Bourne-Again Shell Debugger functions - -_BUFSIZ=100 - -# Here after each statement in script being debugged. -# Handle single-step and breakpoints. -_steptrap() { - let _curline=$1-1 # no. of line that just ran - let "$_curline < 1" && let _curline=1 - - let "$_curline > $_firstline+$_BUFSIZ" && _readin $_curline - - let " $_trace" && - _msg "$PS4, line $_curline: ${_lines[$(($_curline-$_firstline+1))]}" - - - # if in step mode, decrement counter - let " $_steps >= 0" && let _steps="$_steps - 1" - - # first check if line num or string brkpt. reached - if _at_linenumbp || _at_stringbp; then - _msg "Reached breakpoint at line $_curline" - _cmdloop # enter debugger - - # if not, check whether break condition exists and is true - elif [ -n "$_brcond" ] && eval $_brcond; then - _msg "Break condition $_brcond true at line $_curline" - _cmdloop # enter debugger - - # next, check if step mode and no. of steps is up - elif let "$_steps == 0"; then - _msg "Stopped at line $_curline" - _cmdloop # enter debugger - fi -} - - -# Debugger command loop. -# Here at start of debugger session, when brkpt. reached, or after single-step. -_cmdloop() { - local cmd args - -# added support for default command (last one entered) - - while read -e -p "bashdb> [$lastcmd $lastargs] " cmd args; do - if [ -z "$cmd" ]; then - cmd=$lastcmd - args=$lastargs - fi - - lastcmd="$cmd" - lastargs=$args - -# made commands to be debugger commands by default, no need for '*' prefix - - case $cmd in - bp ) _setbp $args ;; #set brkpt at line num or string - - bc ) _setbc $args ;; # set break condition - - cb ) _clearbp ;; # clear all brkpts. - - g ) return ;; # start/resume execution - - s ) let _steps=${args:-1} - return ;; # single-step N times(default 1) - - x ) _xtrace ;; # toggle execution trace - - pr ) _print $args ;; # print lines in file - - \? | h | help ) _menu ;; # print command menu - - hi ) history ;; # show command history - - q ) _cleanup; exit ;; # quit - - \! ) eval $args ;; # run shell command - - * ) _msg "Invalid command: $cmd" ; _menu ;; - esac - done -} - - -# see if next line no. is a brkpt. -_at_linenumbp() { - if [ -z "${_linebp}" ]; then - return 1 - fi - echo "${_curline}" | grep -E "(${_linebp%\|})" >/dev/null 2>&1 - return $? -} - - -# search string brkpts to see if next line in script matches. -_at_stringbp() { - local l; - - if [ -z "$_stringbp" ]; then - return 1; - fi - l=${_lines[$_curline-$_firstline+1]} - echo "${l}" | grep -E "\\*(${_stringbp%\|})\\*" >/dev/null 2>&1 - return $? -} - - -# print message to stderr -_msg() { - echo -e "$@" >&2 -} - - -# set brkpt(s) at given line numbers and/or strings -# by appending lines to brkpt file -_setbp() { - declare -i n - case "$1" in - "") _listbp ;; - [0-9]*) #number, set brkpt at that line - n=$1 - _linebp="${_linebp}$n|" - _msg "Breakpoint at line " $1 - ;; - *) #string, set brkpt at next line w/string - _stringbp="${_stringbp}$@|" - _msg "Breakpoint at next line containing $@." - ;; - esac -} - - -# list brkpts and break condition. -_listbp() { - _msg "Breakpoints at lines:" - _msg "${_linebp//\|/ }" - _msg "Breakpoints at strings:" - _msg "${_stringbp//\|/ }" - _msg "Break on condition:" - _msg "$_brcond" -} - - -# set or clear break condition -_setbc() { - if [ -n "$@" ] ; then - _brcond=$args - _msg "Break when true: $_brcond" - else - _brcond= - _msg "Break condition cleared" - fi -} - - -# clear all brkpts -_clearbp() { - _linebp= - _stringbp= - _msg "All breakpoints cleared" -} - - -# toggle execution trace feature -_xtrace() { - let _trace="! $_trace" - - _msg "Execution trace \c" - let " $_trace" && _msg "on." || _msg "off." -} - - -# print command menu -_menu() { - -# made commands to be debugger commands by default, no need for '*' prefix - - _msg 'bashdb commands: - bp N set breakpoint at line N - bp string set breakpoint at next line containing "string" - bp list breakpoints and break condition - bc string set break condition to "string" - bc clear break condition - cb clear all breakpoints - g start/resume execution - s [N] execute N statements (default 1) - x toggle execution trace on/off (default on) - pr [start|.] [cnt] print "cnt" lines from line no. "start" - ?, h, help print this menu - hi show command history - q quit - - ! cmd [args] execute command "cmd" with "args" - - default: last command (in "[ ]" at the prompt) - - Readline command line editing (emacs/vi mode) is available' -} - - -# erase temp files before exiting -_cleanup() { - rm $_dbgfile 2>/dev/null -} - - -# read $_BUFSIZ lines from $_guineapig into _lines array, starting from line $1 -# save number of first line read in _firstline -_readin() { - declare -i _i=1 - let _firstline=$1 - - SEDCMD="$_firstline,$(($_firstline+$_BUFSIZ))p" - - sed -n "$SEDCMD" $_guineapig > /tmp/_script.$$ - while read -r _lines[$_i]; do - _i=_i+1 - done < /tmp/_script.$$ - rm -f /tmp/_script.$$ 2>/dev/null -} - -_print() { - typeset _start _cnt - - if [ -z "$1" ] || [ "$1" = . ]; then - _start=$_curline - else - _start=$1 - fi - - _cnt=${2:-9} - - SEDCMD="$_start,$(($_start+$_cnt))p" - - pr -tn $_guineapig | sed -n "$SEDCMD" -} diff --git a/examples/obashdb/bashdb.pre b/examples/obashdb/bashdb.pre deleted file mode 100644 index c9cdb72..0000000 --- a/examples/obashdb/bashdb.pre +++ /dev/null @@ -1,37 +0,0 @@ -# bashdb.pre - Bourne-Again Shell Debugger preamble file -# prepended to script being ddebugged -#arguments: -# $1 = name of original guineapig script -# $2 = dir where temp files are stored -# $3 = dir where bashdb.pre and bashdb.fns are stored - -# separate history file for bashdb -HISTFILE=~/.bashdb_history -set -o history -set +H - -# prompt for trace line -PS4="${1}" - -_dbgfile=$0 -_guineapig=$1 -_tmpdir=$2 -_libdir=$3 -shift 3 #move user's args into place - -. $_libdir/bashdb.fns #read in the debugger functions - -_linebp= -_stringbp= -let _trace=1 #init execution trace flag to on - -#read guineapig file into _lines array -_readin 1 - -trap _cleanup EXIT #erase files before exiting - -let _steps=1 #no. of statements to run after setting trap -#set LINENO, gets incremented to 1 -LINENO=0 -trap '_steptrap $LINENO' DEBUG -: diff --git a/examples/scripts/cat.sh b/examples/scripts/cat.sh index 78106b2..3e65b3f 100644 --- a/examples/scripts/cat.sh +++ b/examples/scripts/cat.sh @@ -1,7 +1,7 @@ shcat() { while read -r ; do - echo "$REPLY" + printf "%s\n" "$REPLY" done } diff --git a/examples/scripts/timeout2 b/examples/scripts/timeout2 new file mode 100755 index 0000000..2c6fb77 --- /dev/null +++ b/examples/scripts/timeout2 @@ -0,0 +1,29 @@ +#!/bin/sh + +# Author: P@draigBrady.com +# V1.0 : Nov 3 2006 +# +# Execute a command with a timeout. +# If the timeout occurs the exit status is 128 +# +# Note there is an asynchronous equivalent of this +# script packaged with bash (under /usr/share/doc/ in my distro), +# which I only noticed after writing this. + +if [ "$#" -lt "2" ]; then + echo "Usage: `basename $0` timeout_in_seconds command" >&2 + echo "Example: `basename $0` 2 sleep 3 || echo timeout" >&2 + exit 1 +fi + +cleanup() +{ + kill %1 2>/dev/null #kill sleep $timeout if running + kill %2 2>/dev/null && exit 128 #kill monitored job if running +} + +set -m #enable job control +trap "cleanup" 17 #cleanup after timeout or command +timeout=$1 && shift #first param is timeout in seconds +sleep $timeout& #start the timeout +"$@" #start the job diff --git a/examples/scripts/timeout3 b/examples/scripts/timeout3 new file mode 100644 index 0000000..5c19d2e --- /dev/null +++ b/examples/scripts/timeout3 @@ -0,0 +1,91 @@ +#!/bin/bash +# +# The Bash shell script executes a command with a time-out. +# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal +# is blocked, then the subsequent SIGKILL (9) terminates it. +# +# Based on the Bash documentation example. + +# Hello Chet, +# please find attached a "little easier" :-) to comprehend +# time-out example. If you find it suitable, feel free to include +# anywhere: the very same logic as in the original examples/scripts, a +# little more transparent implementation to my taste. +# +# Dmitry V Golovashkin <Dmitry.Golovashkin@sas.com> + +scriptName="${0##*/}" + +declare -i DEFAULT_TIMEOUT=9 +declare -i DEFAULT_INTERVAL=1 +declare -i DEFAULT_DELAY=1 + +# Timeout. +declare -i timeout=DEFAULT_TIMEOUT +# Interval between checks if the process is still alive. +declare -i interval=DEFAULT_INTERVAL +# Delay between posting the SIGTERM signal and destroying the process by SIGKILL. +declare -i delay=DEFAULT_DELAY + +function printUsage() { + cat <<EOF + +Synopsis + $scriptName [-t timeout] [-i interval] [-d delay] command + Execute a command with a time-out. + Upon time-out expiration SIGTERM (15) is sent to the process. If SIGTERM + signal is blocked, then the subsequent SIGKILL (9) terminates it. + + -t timeout + Number of seconds to wait for command completion. + Default value: $DEFAULT_TIMEOUT seconds. + + -i interval + Interval between checks if the process is still alive. + Positive integer, default value: $DEFAULT_INTERVAL seconds. + + -d delay + Delay between posting the SIGTERM signal and destroying the + process by SIGKILL. Default value: $DEFAULT_DELAY seconds. + +As of today, Bash does not support floating point arithmetic (sleep does), +therefore all delay/time values must be integers. +EOF +} + +# Options. +while getopts ":t:i:d:" option; do + case "$option" in + t) timeout=$OPTARG ;; + i) interval=$OPTARG ;; + d) delay=$OPTARG ;; + *) printUsage; exit 1 ;; + esac +done +shift $((OPTIND - 1)) + +# $# should be at least 1 (the command to execute), however it may be strictly +# greater than 1 if the command itself has options. +if (($# == 0 || interval <= 0)); then + printUsage + exit 1 +fi + +# kill -0 pid Exit code indicates if a signal may be sent to $pid process. +( + ((t = timeout)) + + while ((t > 0)); do + sleep $interval + kill -0 $$ || exit 0 + ((t -= interval)) + done + + # Be nice, post SIGTERM first. + # The 'exit 0' below will be executed if any preceeding command fails. + kill -s SIGTERM $$ && kill -0 $$ || exit 0 + sleep $delay + kill -s SIGKILL $$ +) 2> /dev/null & + +exec "$@" |