├── .CFUserTextEncoding ├── .vimrc.before ├── .vimrc ├── .cvsrc ├── .irbrc ├── .vimrc.after ├── .public.files ├── .inputrc ├── .gitignore ├── .gitk ├── .screenrc ├── .profile ├── .dircolors ├── .bash_completion_svn ├── .bash-functions.sh ├── .bashrc └── .bash_completion /.CFUserTextEncoding: -------------------------------------------------------------------------------- 1 | 0:0 -------------------------------------------------------------------------------- /.vimrc.before: -------------------------------------------------------------------------------- 1 | let mapleader = "," 2 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | /Users/aharnly/.vim/janus/vim/vimrc -------------------------------------------------------------------------------- /.cvsrc: -------------------------------------------------------------------------------- 1 | # recommended CVS config file from pkgsrc guide 2 | # http://www.netbsd.org/docs/pkgsrc/getting.html 3 | # 4 | checkout -P 5 | update -dP 6 | release -d 7 | diff -upN 8 | cvs -q -z3 9 | rdiff -u 10 | -------------------------------------------------------------------------------- /.irbrc: -------------------------------------------------------------------------------- 1 | require 'irb/completion' 2 | require 'irb/ext/save-history' 3 | ARGV.concat [ "--readline", "--prompt-mode", "simple" ] 4 | IRB.conf[:SAVE_HISTORY] = 100 5 | IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_save_history" 6 | 7 | -------------------------------------------------------------------------------- /.vimrc.after: -------------------------------------------------------------------------------- 1 | " Install solarized with: 2 | " cd ~/.janus 3 | " git clone git://github.com/altercation/vim-colors-solarized.git 4 | set background=dark 5 | colorscheme solarized 6 | "set tw=0 7 | nmap w :set wrap! 8 | nmap x :!chmod +x % 9 | -------------------------------------------------------------------------------- /.public.files: -------------------------------------------------------------------------------- 1 | .CFUserTextEncoding 2 | .bash-functions.sh 3 | .bash_completion 4 | .bash_completion_svn 5 | .bashrc 6 | .cvsrc 7 | .dir_colors 8 | .git-public.files 9 | .gitignore 10 | .gitk 11 | .inputrc 12 | .irbrc 13 | .profile 14 | .public.files 15 | .pydistutils.cfg 16 | .screenrc 17 | .vimrc 18 | -------------------------------------------------------------------------------- /.inputrc: -------------------------------------------------------------------------------- 1 | # mode 2 | #set editing-mode vi 3 | 4 | # completion 5 | set show-all-if-ambiguous on 6 | set show-all-if-unmodified on 7 | set completion-ignore-case on 8 | set completion-map-case on 9 | set completion-prefix-display-length 2 10 | Control-j: menu-complete 11 | #Control-i: menu-complete-backward 12 | 13 | # history 14 | "\e[A": history-search-backward 15 | "\e[B": history-search-forward 16 | 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore non-dotfiles in the root directory 2 | /[^.]* 3 | 4 | # ignore these files in any directory 5 | .DS_Store 6 | *.swp 7 | 8 | # ignore these dotfiles in the root directory 9 | /.*_history 10 | /.Trash 11 | /.Xauthority 12 | /.aap 13 | /.cups 14 | /.fontconfig 15 | /.gdbinit 16 | /.private.git 17 | /.public.git 18 | /.inkscape 19 | /.inkscape-etc 20 | /.lesshst 21 | /.neverball 22 | /.parallels_settings 23 | /.rnd 24 | /.viminfo 25 | 26 | # ignore these files in subdirs 27 | /.ssh/config 28 | 29 | /.ssh/id_dsa 30 | /.ssh/id_dsa.pub 31 | /.mtr 32 | /.bash_profile 33 | /.macports 34 | /.m2/repository 35 | /.vim 36 | -------------------------------------------------------------------------------- /.gitk: -------------------------------------------------------------------------------- 1 | set mainfont {Helvetica 9} 2 | set textfont {Courier 9} 3 | set uifont {Helvetica 9 bold} 4 | set tabstop 8 5 | set findmergefiles 0 6 | set maxgraphpct 50 7 | set maxwidth 16 8 | set cmitmode tree 9 | set wrapcomment none 10 | set autoselect 1 11 | set showneartags 1 12 | set hideremotes 0 13 | set showlocalchanges 1 14 | set datetimeformat {%Y-%m-%d %H:%M:%S} 15 | set limitdiffs 1 16 | set uicolor grey85 17 | set want_ttk 1 18 | set bgcolor white 19 | set fgcolor black 20 | set colors {green red blue magenta darkgrey brown orange} 21 | set diffcolors {red "#00a000" blue} 22 | set markbgcolor #e0e0ff 23 | set diffcontext 1 24 | set selectbgcolor gray85 25 | set extdifftool meld 26 | set perfile_attrs 0 27 | set geometry(main) 985x778+5+27 28 | set geometry(state) normal 29 | set geometry(topwidth) 985 30 | set geometry(topheight) 150 31 | set geometry(pwsash0) "348 1" 32 | set geometry(pwsash1) "523 1" 33 | set geometry(botwidth) 536 34 | set geometry(botheight) 623 35 | set permviews {} 36 | -------------------------------------------------------------------------------- /.screenrc: -------------------------------------------------------------------------------- 1 | ######### standard screens 2 | screen 1 3 | screen 2 4 | screen 3 5 | screen 4 6 | screen 5 7 | screen 6 8 | screen 0 9 | 10 | ######### basics 11 | autodetach on 12 | startup_message off 13 | 14 | ######### UI 15 | # start with visual bell as default 16 | # vbell on 17 | # vbell_msg "bell on %t (%n)" 18 | 19 | # caption + hardstatus 20 | # these settings create a two-line statusbar, 21 | # where the top line shows the host and current directory, 22 | # and the bottom line shows a list of windows on the left, then the host and a clock 23 | # 24 | # coral1: ~/src 25 | # 0 aaron 1 scripts 2 scripts 3 bin 4 data 5 work @coral1 Tue, Jul 27 2:04:26pm 26 | # 27 | # 28 | backtick 1 86400 86400 echo "$USER" 29 | backtick 2 86400 86400 echo "$PLATFORM" 30 | caption always "%{= bb}%{+b W}%h %=" 31 | hardstatus on 32 | hardstatus alwayslastline 33 | hardstatus string "%{.kW}%-w%{+b bW}%n %t%{-}%+w %=%{..G} %1`@%H [%2`] %{..Y} %D, %M %d %C:%s%a " 34 | 35 | ######### keybindings 36 | # set the escape character 37 | escape ^Tt 38 | 39 | # set other handy shortcuts 40 | bind \\ quit 41 | bind ^\ quit 42 | bind n next 43 | bind ^n next 44 | bind h prev 45 | bind ^h prev 46 | 47 | bindkey "^[[5D" prev 48 | bindkey "^[[5C" next 49 | 50 | ######### other behaviors 51 | altscreen on # use altscreen capability 52 | defscrollback 5000 # default: 100 53 | defencoding utf8 # default encoding is UTF-8 54 | # termcapinfo xterm "ks=E[?1lE:kuE[A:kd=E[B:kl=E[D:kr=E[C:kh=E[5~:kH=E[F" 55 | # Prepend/append register [/] to the paste if ^a^] is pressed. 56 | # This lets me have autoindent mode in vi. 57 | register [ "\033:se noai\015a" 58 | register ] "\033:se ai\015a" 59 | bind ^] paste [.] 60 | 61 | 62 | -------------------------------------------------------------------------------- /.profile: -------------------------------------------------------------------------------- 1 | # 2 | # Aaron's bash settings for login shells 3 | # 4 | 5 | # ==================== Initialization ==================== 6 | # First, set up like we do for non-login interactive shells 7 | source "$HOME/.bashrc" 8 | 9 | # 10 | # ==================== Login shell setup ==================== 11 | # 12 | 13 | function setup_login_shell() 14 | { 15 | show_connection_message 16 | show_screen_message 17 | } 18 | 19 | function show_connection_message() 20 | { 21 | # Where are we logged in from? 22 | if [ "$LOCALNESS" = "local" ]; then 23 | LOCATION_MESSAGE="locally on $LAUNCHING_APP" 24 | else 25 | LOCATION_MESSAGE="via ssh from $SSH_REMOTE_HOST" 26 | fi 27 | 28 | # print info about the shell environment 29 | if [ -z "$SHOWED_CONNECTION_INFO" ]; then 30 | display_boxed --centered "Connected to $HOST $LOCATION_MESSAGE." "Platform is $PLATFORM." 31 | export SHOWED_CONNECTION_INFO="yes" 32 | fi 33 | } 34 | 35 | function show_screen_message() 36 | { 37 | # if we're not already in screen, offer the opportunity 38 | # to reattach to detached screens: 39 | local screen_path=$(which screen) 40 | if [ ! -z "$screen_path" ]; then 41 | if [ -z "$RUNNING_SCREEN" ]; then 42 | local detached_screens=$(screen -list | awk '/Detached/ {print $1}' ) 43 | if [ ! -z "$detached_screens" ]; then 44 | local line_1="Detached screens available: " 45 | local line_2=" " 46 | local end_line_1=" " 47 | local end_line_2=" Type 'screen -r ' to reattach." 48 | display_boxed --centered "$line_1" "$line_2" $detached_screens "$end_line_1" "$end_line_2" 49 | fi 50 | fi 51 | fi 52 | 53 | } 54 | 55 | ########################### The actual execution ###################### 56 | setup_login_shell 57 | 58 | # ----------------- Additional files -------------------- 59 | # Host-specific login messages 60 | source_if "$HOME/.profile.${HOST}" 61 | -------------------------------------------------------------------------------- /.dircolors: -------------------------------------------------------------------------------- 1 | # Configuration file for dircolors, a utility to help you set the 2 | # LS_COLORS environment variable used by GNU ls with the --color option. 3 | # Copyright (C) 1996, 1999-2008 4 | # Free Software Foundation, Inc. 5 | # Copying and distribution of this file, with or without modification, 6 | # are permitted provided the copyright notice and this notice are preserved. 7 | # The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the 8 | # slackware version of dircolors) are recognized but ignored. 9 | # Below, there should be one TERM entry for each termtype that is colorizable 10 | TERM Eterm 11 | TERM ansi 12 | TERM color-xterm 13 | TERM con132x25 14 | TERM con132x30 15 | TERM con132x43 16 | TERM con132x60 17 | TERM con80x25 18 | TERM con80x28 19 | TERM con80x30 20 | TERM con80x43 21 | TERM con80x50 22 | TERM con80x60 23 | TERM cons25 24 | TERM console 25 | TERM cygwin 26 | TERM dtterm 27 | TERM eterm-color 28 | TERM gnome 29 | TERM gnome-256color 30 | TERM jfbterm 31 | TERM konsole 32 | TERM kterm 33 | TERM linux 34 | TERM linux-c 35 | TERM mach-color 36 | TERM mlterm 37 | TERM putty 38 | TERM rxvt 39 | TERM rxvt-cygwin 40 | TERM rxvt-cygwin-native 41 | TERM rxvt-unicode 42 | TERM screen 43 | TERM screen-256color 44 | TERM screen-bce 45 | TERM screen-w 46 | TERM screen.linux 47 | TERM vt100 48 | TERM xterm 49 | TERM xterm-16color 50 | TERM xterm-256color 51 | TERM xterm-88color 52 | TERM xterm-color 53 | TERM xterm-debian 54 | # Below are the color init strings for the basic file types. A color init 55 | # string consists of one or more of the following numeric codes: 56 | # Attribute codes: 57 | # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed 58 | # Text color codes: 59 | # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white 60 | # Background color codes: 61 | # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white 62 | #NORMAL 00 # no color code at all 63 | #FILE 00 # regular file: use no color at all 64 | #RESET 0 # reset to "normal" color 65 | DIR 01;34 # directory 66 | LINK 01;36 # symbolic link. (If you set this to 'target' instead of a 67 | # numerical value, the color is as for the file pointed to.) 68 | FIFO 40;33 # pipe 69 | SOCK 01;35 # socket 70 | DOOR 01;35 # door 71 | BLK 40;33;01 # block device driver 72 | CHR 40;33;01 # character device driver 73 | #ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file 74 | SETUID 37;41 # file that is setuid (u+s) 75 | SETGID 30;43 # file that is setgid (g+s) 76 | STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w) 77 | OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky 78 | STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable 79 | # This is for files with execute permission: 80 | EXEC 01;32 81 | # List any file extensions like '.gz' or '.tar' that you would like ls 82 | # to colorize below. Put the extension, a space, and the color init string. 83 | # (and any comments you want to add after a '#') 84 | # If you use DOS-style suffixes, you may want to uncomment the following: 85 | #.cmd 01;32 # executables (bright green) 86 | #.exe 01;32 87 | #.com 01;32 88 | #.btm 01;32 89 | #.bat 01;32 90 | # Or if you want to colorize scripts even if they do not have the 91 | # executable bit actually set. 92 | #.sh 01;32 93 | #.csh 01;32 94 | # archives or compressed (bright red) 95 | .tar 01;31 96 | .tgz 01;31 97 | .arj 01;31 98 | .taz 01;31 99 | .lzh 01;31 100 | .lzma 01;31 101 | .zip 01;31 102 | .z 01;31 103 | .Z 01;31 104 | .dz 01;31 105 | .gz 01;31 106 | .bz2 01;31 107 | .bz 01;31 108 | .tbz2 01;31 109 | .tz 01;31 110 | .deb 01;31 111 | .rpm 01;31 112 | .jar 01;31 113 | .rar 01;31 114 | .ace 01;31 115 | .zoo 01;31 116 | .cpio 01;31 117 | .7z 01;31 118 | .rz 01;31 119 | # image formats 120 | .jpg 01;35 121 | .jpeg 01;35 122 | .gif 01;35 123 | .bmp 01;35 124 | .pbm 01;35 125 | .pgm 01;35 126 | .ppm 01;35 127 | .tga 01;35 128 | .xbm 01;35 129 | .xpm 01;35 130 | .tif 01;35 131 | .tiff 01;35 132 | .png 01;35 133 | .svg 01;35 134 | .svgz 01;35 135 | .mng 01;35 136 | .pcx 01;35 137 | .mov 01;35 138 | .mpg 01;35 139 | .mpeg 01;35 140 | .m2v 01;35 141 | .mkv 01;35 142 | .ogm 01;35 143 | .mp4 01;35 144 | .m4v 01;35 145 | .mp4v 01;35 146 | .vob 01;35 147 | .qt 01;35 148 | .nuv 01;35 149 | .wmv 01;35 150 | .asf 01;35 151 | .rm 01;35 152 | .rmvb 01;35 153 | .flc 01;35 154 | .avi 01;35 155 | .fli 01;35 156 | .flv 01;35 157 | .gl 01;35 158 | .dl 01;35 159 | .xcf 01;35 160 | .xwd 01;35 161 | .yuv 01;35 162 | # audio formats 163 | .aac 00;36 164 | .au 00;36 165 | .flac 00;36 166 | .mid 00;36 167 | .midi 00;36 168 | .mka 00;36 169 | .mp3 00;36 170 | .mpc 00;36 171 | .ogg 00;36 172 | .ra 00;36 173 | .wav 00;36 174 | -------------------------------------------------------------------------------- /.bash_completion_svn: -------------------------------------------------------------------------------- 1 | # Programmable completion for the Subversion svn command under bash. Source 2 | # this file (or on some systems add it to ~/.bash_completion and start a new 3 | # shell) and bash's completion mechanism will know all about svn's options! 4 | # Provides completion for the svnadmin command as well. Who wants to read 5 | # man pages/help text... 6 | 7 | # Known to work with bash 2.05a with programmable completion and extended 8 | # pattern matching enabled (use 'shopt -s extglob progcomp' to enable 9 | # these if they are not already enabled). 10 | 11 | _svn() 12 | { 13 | local cur cmds cmdOpts pOpts mOpts rOpts qOpts nOpts optsParam opt 14 | local helpCmds optBase i 15 | 16 | COMPREPLY=() 17 | cur=${COMP_WORDS[COMP_CWORD]} 18 | 19 | # Possible expansions, without unambiguous abbreviations such as "up". 20 | cmds='add blame annotate praise cat checkout co cleanup commit ci \ 21 | copy cp delete remove rm diff export help ? import info \ 22 | list ls log merge mkdir move mv rename \ 23 | propdel pdel propedit pedit propget pget \ 24 | proplist plist propset pset resolved revert \ 25 | status switch update version --version' 26 | 27 | if [[ $COMP_CWORD -eq 1 ]] ; then 28 | COMPREPLY=( $( compgen -W "$cmds" -- $cur ) ) 29 | return 0 30 | fi 31 | 32 | # options that require a parameter 33 | # note: continued lines must end '|' continuing lines must start '|' 34 | optsParam="-r|--revision|--username|--password|--targets| 35 | |-x|--extensions|-m|--message|-F|--file|--encoding| 36 | |--diff-cmd|--diff3-cmd|--editor-cmd|--old|--new| 37 | |--config-dir|--native-eol|--limit" 38 | 39 | # if not typing an option, or if the previous option required a 40 | # parameter, then fallback on ordinary filename expansion 41 | helpCmds='help|--help|h|\?' 42 | urlCmds='co|checkout|ls|list|cp|copy|mv|move' 43 | if [[ ${COMP_WORDS[1]} != @($helpCmds) ]] && \ 44 | [[ "$cur" != -* ]] || \ 45 | [[ ${COMP_WORDS[COMP_CWORD-1]} == @($optsParam) ]] ; then 46 | if [[ ${COMP_WORDS[1]} == @($urlCmds) ]] ; then 47 | _svn_url 48 | fi 49 | return 0 50 | fi 51 | 52 | pOpts="--username --password --no-auth-cache --non-interactive" 53 | mOpts="-m --message -F --file --encoding --force-log" 54 | rOpts="-r --revision" 55 | qOpts="-q --quiet" 56 | nOpts="-N --non-recursive" 57 | 58 | # possible options for the command 59 | cmdOpts= 60 | case ${COMP_WORDS[1]} in 61 | --version) 62 | cmdOpts="$qOpts" 63 | ;; 64 | add) 65 | cmdOpts="--auto-props --no-auto-props --force --targets \ 66 | $nOpts $qOpts" 67 | ;; 68 | blame|annotate|ann|praise) 69 | cmdOpts="$rOpts $pOpts -v --verbose" 70 | ;; 71 | cat) 72 | cmdOpts="$rOpts $pOpts" 73 | ;; 74 | checkout|co) 75 | cmdOpts="$rOpts $qOpts $nOpts $pOpts" 76 | ;; 77 | cleanup) 78 | cmdOpts="--diff3-cmd" 79 | ;; 80 | commit|ci) 81 | cmdOpts="$mOpts $qOpts $nOpts --targets --editor-cmd $pOpts" 82 | ;; 83 | copy|cp) 84 | cmdOpts="$mOpts $rOpts $qOpts --editor-cmd $pOpts" 85 | ;; 86 | delete|del|remove|rm) 87 | cmdOpts="--force $mOpts $qOpts --targets --editor-cmd $pOpts" 88 | ;; 89 | diff|di) 90 | cmdOpts="$rOpts -x --extensions --diff-cmd --no-diff-deleted \ 91 | $nOpts $pOpts --force --old --new --notice-ancestry" 92 | ;; 93 | export) 94 | cmdOpts="$rOpts $qOpts $pOpts --force --native-eol" 95 | ;; 96 | help|h|\?) 97 | cmdOpts="$cmds $qOpts" 98 | ;; 99 | import) 100 | cmdOpts="--auto-props --no-auto-props $mOpts $qOpts $nOpts \ 101 | --editor-cmd $pOpts" 102 | ;; 103 | info) 104 | cmdOpts="--targets -R --recursive" 105 | ;; 106 | list|ls) 107 | cmdOpts="$rOpts -v --verbose -R --recursive $pOpts" 108 | ;; 109 | log) 110 | cmdOpts="$rOpts -v --verbose --targets $pOpts --stop-on-copy \ 111 | --incremental --xml $qOpts --limit" 112 | ;; 113 | merge) 114 | cmdOpts="$rOpts $nOpts $qOpts --force --dry-run --diff3-cmd \ 115 | $pOpts --ignore-ancestry" 116 | ;; 117 | mkdir) 118 | cmdOpts="$mOpts $qOpts --editor-cmd $pOpts" 119 | ;; 120 | move|mv|rename|ren) 121 | cmdOpts="$mOpts $rOpts $qOpts --force --editor-cmd $pOpts" 122 | ;; 123 | propdel|pdel|pd) 124 | cmdOpts="$qOpts -R --recursive $rOpts --revprop $pOpts" 125 | ;; 126 | propedit|pedit|pe) 127 | cmdOpts="$rOpts --revprop --encoding --editor-cmd $pOpts \ 128 | --force" 129 | ;; 130 | propget|pget|pg) 131 | cmdOpts="-R --recursive $rOpts --revprop --strict $pOpts" 132 | ;; 133 | proplist|plist|pl) 134 | cmdOpts="-v --verbose -R --recursive $rOpts --revprop $qOpts \ 135 | $pOpts" 136 | ;; 137 | propset|pset|ps) 138 | cmdOpts="-F --file $qOpts --targets -R --recursive --revprop \ 139 | --encoding $pOpts $rOpts --force" 140 | ;; 141 | resolved) 142 | cmdOpts="--targets -R --recursive $qOpts" 143 | ;; 144 | revert) 145 | cmdOpts="--targets -R --recursive $qOpts" 146 | ;; 147 | status|stat|st) 148 | cmdOpts="-u --show-updates -v --verbose $nOpts $qOpts $pOpts \ 149 | --no-ignore" 150 | ;; 151 | switch|sw) 152 | cmdOpts="--relocate $rOpts $nOpts $qOpts $pOpts --diff3-cmd" 153 | ;; 154 | update|up) 155 | cmdOpts="$rOpts $nOpts $qOpts $pOpts --diff3-cmd" 156 | ;; 157 | version) 158 | cmdOpts="$qOpts" 159 | ;; 160 | *) 161 | ;; 162 | esac 163 | 164 | cmdOpts="$cmdOpts --help -h --config-dir" 165 | 166 | # take out options already given 167 | for (( i=2; i<=$COMP_CWORD-1; ++i )) ; do 168 | opt=${COMP_WORDS[$i]} 169 | 170 | case $opt in 171 | --*) optBase=${opt/=*/} ;; 172 | -*) optBase=${opt:0:2} ;; 173 | esac 174 | 175 | cmdOpts=" $cmdOpts " 176 | cmdOpts=${cmdOpts/ ${optBase} / } 177 | 178 | # take out alternatives and mutually exclusives 179 | case $optBase in 180 | -v) cmdOpts=${cmdOpts/ --verbose / } ;; 181 | --verbose) cmdOpts=${cmdOpts/ -v / } ;; 182 | -N) cmdOpts=${cmdOpts/ --non-recursive / } ;; 183 | --non-recursive) cmdOpts=${cmdOpts/ -N / } ;; 184 | -R) cmdOpts=${cmdOpts/ --recursive / } ;; 185 | --recursive) cmdOpts=${cmdOpts/ -R / } ;; 186 | -x) cmdOpts=${cmdOpts/ --extensions / } ;; 187 | --extensions) cmdOpts=${cmdOpts/ -x / } ;; 188 | -q) cmdOpts=${cmdOpts/ --quiet / } ;; 189 | --quiet) cmdOpts=${cmdOpts/ -q / } ;; 190 | -h) cmdOpts=${cmdOpts/ --help / } ;; 191 | --help) cmdOpts=${cmdOpts/ -h / } ;; 192 | -r) cmdOpts=${cmdOpts/ --revision / } ;; 193 | --revision) cmdOpts=${cmdOpts/ -r / } ;; 194 | --auto-props) cmdOpts=${cmdOpts/ --no-auto-props / } ;; 195 | --no-auto-props) cmdOpts=${cmdOpts/ --auto-props / } ;; 196 | 197 | -m|--message|-F|--file) 198 | cmdOpts=${cmdOpts/ --message / } 199 | cmdOpts=${cmdOpts/ -m / } 200 | cmdOpts=${cmdOpts/ --file / } 201 | cmdOpts=${cmdOpts/ -F / } 202 | ;; 203 | esac 204 | 205 | # skip next option if this one requires a parameter 206 | if [[ $opt == @($optsParam) ]] ; then 207 | ((++i)) 208 | fi 209 | done 210 | 211 | COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) ) 212 | 213 | return 0 214 | } 215 | complete -F _svn -o default -o nospace svn 216 | 217 | _svn_url () 218 | { 219 | local cur protocols path repopath tmp 220 | 221 | COMPREPLY=() 222 | cur=${COMP_WORDS[COMP_CWORD]} 223 | 224 | if [[ ${cur} == *:* ]] ; then 225 | path=${cur#file://} 226 | tmp=${path%svnrepo*} 227 | 228 | if [ "$path" != "" ] && [ "$path" != "$tmp" ]; then 229 | path=${tmp}svnrepo 230 | fi 231 | 232 | if [ -r "${path}/db" ]; then 233 | repopath=${cur#*svnrepo} 234 | 235 | if [[ ${repopath} == */* ]] ; then 236 | validpath=${repopath%\/*} 237 | else 238 | validpath="" 239 | fi 240 | 241 | files=$( svn ls file://$path$validpath ) 242 | COMPREPLY=( $( compgen -P "//$path$validpath/" -W "$files" ${repopath##*/} ) ) 243 | else 244 | COMPREPLY=( $( compgen -P "//" -S "/" -d $path ) ) 245 | fi 246 | else 247 | protocols="svn file http ssh+svn" 248 | COMPREPLY=( $( compgen -S "://" -W "$protocols" $cur ) ) 249 | fi 250 | 251 | return 0 252 | } 253 | 254 | _svnadmin () 255 | { 256 | local cur cmds cmdOpts optsParam opt helpCmds optBase i 257 | 258 | COMPREPLY=() 259 | cur=${COMP_WORDS[COMP_CWORD]} 260 | 261 | cmds='create deltify dump help h ? hotcopy load list-dblogs \ 262 | list-unused-dblogs lstxns recover rmtxns setlog verify' 263 | 264 | if [[ $COMP_CWORD -eq 1 ]] ; then 265 | COMPREPLY=( $( compgen -W "$cmds" -- $cur ) ) 266 | return 0 267 | fi 268 | 269 | # options that require a parameter 270 | # note: continued lines must end '|' continuing lines must start '|' 271 | optsParam="-r|--revision|--parent-dir|--fs-type" 272 | 273 | # if not typing an option, or if the previous option required a 274 | # parameter, then fallback on ordinary filename expansion 275 | helpCmds='help|--help|h|\?' 276 | if [[ ${COMP_WORDS[1]} != @($helpCmds) ]] && \ 277 | [[ "$cur" != -* ]] || \ 278 | [[ ${COMP_WORDS[COMP_CWORD-1]} == @($optsParam) ]] ; then 279 | return 0 280 | fi 281 | 282 | cmdOpts= 283 | case ${COMP_WORDS[1]} in 284 | create) 285 | cmdOpts="--bdb-txn-nosync --bdb-log-keep --config-dir --fs-type" 286 | ;; 287 | deltify) 288 | cmdOpts="-r --revision -q --quiet" 289 | ;; 290 | dump) 291 | cmdOpts="-r --revision --incremental -q --quiet --deltas" 292 | ;; 293 | help|h|\?) 294 | cmdOpts="$cmds $qOpts" 295 | ;; 296 | hotcopy) 297 | cmdOpts="--clean-logs" 298 | ;; 299 | load) 300 | cmdOpts="--ignore-uuid --force-uuid --parent-dir -q --quiet" 301 | ;; 302 | list-dblogs) 303 | ;; 304 | list-unused-dblogs) 305 | ;; 306 | setlog) 307 | cmdOpts="-r --revision" 308 | ;; 309 | *) 310 | ;; 311 | esac 312 | 313 | cmdOpts="$cmdOpts --help -h" 314 | 315 | # take out options already given 316 | for (( i=2; i<=$COMP_CWORD-1; ++i )) ; do 317 | opt=${COMP_WORDS[$i]} 318 | 319 | case $opt in 320 | --*) optBase=${opt/=*/} ;; 321 | -*) optBase=${opt:0:2} ;; 322 | esac 323 | 324 | cmdOpts=" $cmdOpts " 325 | cmdOpts=${cmdOpts/ ${optBase} / } 326 | 327 | # take out alternatives 328 | case $optBase in 329 | -q) cmdOpts=${cmdOpts/ --quiet / } ;; 330 | --quiet) cmdOpts=${cmdOpts/ -q / } ;; 331 | -h) cmdOpts=${cmdOpts/ --help / } ;; 332 | --help) cmdOpts=${cmdOpts/ -h / } ;; 333 | -r) cmdOpts=${cmdOpts/ --revision / } ;; 334 | --revision) cmdOpts=${cmdOpts/ -r / } ;; 335 | esac 336 | 337 | # skip next option if this one requires a parameter 338 | if [[ $opt == @($optsParam) ]] ; then 339 | ((++i)) 340 | fi 341 | done 342 | 343 | COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) ) 344 | 345 | return 0 346 | } 347 | complete -F _svnadmin -o default svnadmin 348 | -------------------------------------------------------------------------------- /.bash-functions.sh: -------------------------------------------------------------------------------- 1 | # 2 | # A collection of useful bash functions 3 | # 4 | 5 | # 6 | # 7 | # =========================== useful functions ============================== 8 | # 9 | # 10 | 11 | # 12 | # --------------------- Scripting -------------------------- 13 | # 14 | # Usage: source_if 15 | # If a file is present at , it will be sourced into the current script. 16 | source_if() 17 | { 18 | local path="$1" 19 | if [ -f "$path" ]; then 20 | source "$path" 21 | fi 22 | } 23 | 24 | # Usage: doalias [args] 25 | # executes an alias 26 | doalias() 27 | { 28 | local cmd="$1" 29 | shift 30 | local expanded=$(alias "$cmd" | perl -ne 'if ( m/.*?=.(.*)./ ) { print $1 }') 31 | echo "Expanded alias: $expanded $@" 32 | eval $expanded $@ 33 | } 34 | 35 | # 36 | # --------------------- env-var manipulations -------------------------- 37 | # 38 | 39 | 40 | # Usage: path_append [variable] 41 | # Appends to the variable [variable], 42 | # (if [variable] is not supplied, defaults to PATH) 43 | path_append() 44 | { 45 | local target="$1" 46 | if [ -z "$2" ]; then 47 | local pathvar=PATH 48 | else 49 | local pathvar=$2 50 | fi 51 | 52 | if [ -e "$target" ]; then 53 | if [[ ! $(eval echo \${$pathvar}) == *$target* ]]; then 54 | eval export ${pathvar}=\"\${$pathvar}:$target\" 55 | fi 56 | fi 57 | } 58 | 59 | # Usage: path_prepend [variable] 60 | # Prepends to the variable [variable], 61 | # (if [variable] is not supplied, defaults to PATH) 62 | path_prepend() 63 | { 64 | local target="$1" 65 | if [ -z $2 ]; then 66 | local pathvar=PATH 67 | else 68 | local pathvar=$2 69 | fi 70 | 71 | if [ -e "$target" ]; then 72 | if [[ ! $(eval echo \${$pathvar}) == *$target* ]]; then 73 | eval export ${pathvar}=$target:\${$pathvar} 74 | fi 75 | fi 76 | } 77 | 78 | 79 | # Usage: path_set 80 | # Sets the env variable to , 81 | # if and only if exists. 82 | # 83 | path_set() 84 | { 85 | thepath="$1" 86 | varname="$2" 87 | 88 | # echo "Evaluating: $thepath for $varname" 89 | 90 | if [ -e "$thepath" ]; then 91 | # echo "Path found. Setting $varname to $thepath" 92 | eval export ${varname}=${thepath} 93 | fi 94 | # eval echo "$varname is \${$varname}" 95 | } 96 | 97 | path_set_if_empty() 98 | { 99 | thepath="$1" 100 | varname="$2" 101 | varvalue=$(eval echo "\$$varname") 102 | 103 | if [ -z "$varvalue" ]; then 104 | path_set "$thepath" "$varname" 105 | fi 106 | } 107 | 108 | path_print() 109 | { 110 | varname="$1" 111 | echo "${varname}=" 112 | eval echo -e \$\{$varname//:/\\\\n\} 113 | } 114 | 115 | 116 | # 117 | # Sets an env var, by choosing from a key-value list. 118 | # The key-value list is established simply by defining a series of env vars with a common prefix; 119 | # e.g. 120 | # WGEN_DB_key1="value1" 121 | # WGEN_DB_key2="value2" 122 | # ... 123 | # 124 | # 125 | # Usage: choose [-q] 126 | # 127 | # e.g. choose DB_OF_MY_DREAMS WGEN_DB_ key2 128 | # will perform: 129 | # export DB_OF_MY_DREAMS="value2" 130 | # 131 | choose() 132 | { 133 | local var_to_set="$1" 134 | local key_prefix="$2" 135 | local key="$3" 136 | local quiet_arg="$4" 137 | if [ ! -z "$quiet_arg" ]; then 138 | if [ "$quiet_arg" = "-q" -o "$quiet_arg" = "--quiet" ]; then 139 | local quiet="YES" 140 | else 141 | local quiet="NO" 142 | fi 143 | else 144 | local quiet="NO" 145 | fi 146 | if [ -z "$key" ]; then # list the possibilities for this variable 147 | echo "Currently," 148 | echo " ${var_to_set}=$(eval echo \$${var_to_set})" 149 | echo " " 150 | echo "Available values:" 151 | env | perl -ne 'if (m/^'$key_prefix'(\w+)=(.+)/) { printf "%20s: %s\n", $1, $2 }' 152 | else 153 | # get the value for the key given 154 | local value=$(eval echo \$${key_prefix}${key}) 155 | if [ -z "$value" ]; then 156 | # We don't seem to have a value for that key 157 | # So we'll just use the key itself as the value 158 | local value="$key" 159 | fi 160 | # set the target variable 161 | eval export ${var_to_set}=\"$value\" 162 | if [ "$quiet" != "YES" ]; then 163 | echo "export ${var_to_set}=\"$(eval echo \$${var_to_set})\"" 164 | fi 165 | fi 166 | } 167 | 168 | # 169 | # --------------------- filepath manipulations -------------------------- 170 | # 171 | 172 | function basename() 173 | { 174 | local name="${1##*/}" 175 | echo "${name%$2}" 176 | } 177 | 178 | # 179 | # Usage: left_half 180 | # 181 | # returns the left half of , up to & not including , 182 | # e.g. left_half . filename.txt returns filename 183 | function left_half() 184 | { 185 | local separator="$1" 186 | local name=${2##*/} 187 | local name0="${name%${separator}*}" 188 | echo "${name0:-$name}" 189 | } 190 | 191 | # 192 | # Usage: right_half_with_sep 193 | # 194 | # returns the right half of , from forward, 195 | # including 196 | # e.g. right_half_with_sep . filename.txt returns .txt 197 | # 198 | function right_half_with_sep() 199 | { 200 | local separator="$1" 201 | local name=${2##*/} 202 | local name0="${name%${separator}*}" 203 | local ext=${name0:+${name#$name0}} 204 | echo "${ext:-${separator}}" 205 | } 206 | 207 | # 208 | # Usage: right_half 209 | # 210 | # returns the right half of , from forward 211 | # (not including ) 212 | # e.g. right_half . filename.txt returns txt 213 | function right_half() 214 | { 215 | local separator="$1" 216 | local name=${2##*/} 217 | local name0="${name%${separator}*}" 218 | local ext=${name0:+${name#$name0}} 219 | local ext=${ext#${separator}} 220 | echo "${ext}" 221 | } 222 | 223 | function namename() # get the name without the file extension 224 | { 225 | echo $(left_half . "$1") 226 | } 227 | 228 | function ext() # get the file extension, including '.' 229 | { 230 | echo $(right_half_with_sep . "$1") 231 | } 232 | 233 | function extonly() # get the file extension, without '.' 234 | { 235 | echo $(right_half . "$1") 236 | } 237 | 238 | function dirname() 239 | { 240 | local dir="${1%${1##*/}}" 241 | [ "${dir:=./}" != "/" ] && dir="${dir%?}" 242 | echo "$dir" 243 | } 244 | 245 | 246 | # 247 | # --------------------- directory navigation -------------------------- 248 | # 249 | 250 | # 251 | # lf makes a nicely indented listing of directory structure, up 252 | # to the given depth 253 | # 254 | function lf() 255 | { 256 | local depth=2 257 | if [ ! -z $1 ]; then 258 | depth=$1 259 | fi 260 | find . -maxdepth $depth -type d | perl -ne ' $count = @matches = m/\//g; print " " x $count; print' 261 | } 262 | 263 | # 264 | # Usage: mycd 265 | # 266 | # Replacement for builtin 'cd', which keeps a separate bash-history 267 | # for every directory. 268 | function mycd() 269 | { 270 | history -w # write current history file 271 | builtin cd "$@" # do actual cd 272 | local HISTDIR="$HOME/.bash_history.d$PWD" # use nested folders for history 273 | if [ ! -d "$HISTDIR" ]; then # create folder if needed 274 | mkdir -p "$HISTDIR" 275 | fi 276 | export HISTFILE="$HISTDIR/${USER}_bash_history.txt" # set new history file 277 | history -c # clear memory 278 | history -r #read from current histfile 279 | 280 | # if we're entering a project directory, check for a virtualenv 281 | this_dir=$(basename "$PWD") 282 | parent_dir=$(dirname "$PWD") 283 | if [ ! -z "$PROJECT_HOME" -a "$parent_dir" == "$PROJECT_HOME" ]; then 284 | if [ -z "$WORKINGON" ]; then 285 | if [ -d "$WORKON_HOME/${this_dir}" ]; then 286 | echo "Activating virtualenv $this_dir..." 287 | export WORKINGON="$this_dir" 288 | workon "${this_dir}" 289 | fi 290 | fi 291 | else 292 | unset WORKINGON 293 | fi 294 | } 295 | 296 | # 297 | # back: toggle between current and previous directory. 298 | # This is equivalent to: cd - 299 | # It might be nice to implement this as an actual stack. 300 | # 301 | function back() 302 | { 303 | if [ ! -z "$OLDPWD" ]; then 304 | mycd "$OLDPWD" 305 | fi 306 | } 307 | 308 | # 309 | # pff: change terminal directory to current Path Finder folder (pff!) 310 | # 311 | function pff() 312 | { 313 | # if under Path Finder, cd to the current PF directory 314 | 315 | if [ "$OS" = "Darwin" ]; then 316 | if [ "$LAUNCHING_APP" = "Path Finder" ]; then 317 | # get new path 318 | pf_path=$(osascript "$HOME/software/$PLATFORM/share/scripts/get_path_finder_path.scpt") 319 | if [ ! -z "$pf_path" ]; then 320 | if [ "$pf_path" != "$PWD" ]; then 321 | cd "$pf_path" 322 | fi 323 | fi 324 | fi 325 | fi 326 | } 327 | 328 | # 329 | # pf: open specified directory in Path Finder 330 | # 331 | function pf() 332 | { 333 | open -a 'Path Finder' $@ 334 | } 335 | 336 | 337 | 338 | # 339 | # pft: change Path Finder window to current Path Finder Terminal 340 | # 341 | function pft() 342 | { 343 | if [ "$OS" = "Darwin" ]; then 344 | if [ "$LAUNCHING_APP" = "Path Finder" ]; then 345 | # get new path as a "folder 'blah' of disk 'foo'" type string 346 | folder_path=`perl -e '$_ = $ENV{PWD}; 347 | chomp; @parts = reverse( split(/\//) ); 348 | print "folder \""; $folder_str = join("\" of folder \"", @parts); 349 | $folder_str =~ s/folder \"$/disk \"\/\"/; 350 | print $folder_str'` 351 | osascript </dev/null; echo $?) 526 | if [ $status_result -eq 0 -o $status_result -eq 1 ]; then 527 | echo "true" 528 | else 529 | echo "false" 530 | fi 531 | } 532 | 533 | function is_git_dirty() 534 | { 535 | local git_status=$(git diff-index --name-only HEAD 2>/dev/null) 536 | if [ -z "$git_status" ]; then 537 | echo "false" 538 | else 539 | echo "true" 540 | fi 541 | } 542 | 543 | function is_git_ahead_of_remote() 544 | { 545 | local is_ahead_result=$(git status 2>/dev/null | grep "Your branch is ahead" &>/dev/null; echo $?) 546 | if [ $is_ahead_result -eq 0 ]; then 547 | echo "true" 548 | else 549 | echo "false" 550 | fi 551 | } 552 | 553 | function git_branch_name() 554 | { 555 | local branch_name=$(git status 2>/dev/null | perl -ne 'if (m/On branch (.+)/) { print $1}') 556 | echo $branch_name 557 | } 558 | 559 | function git_dirty_display() 560 | { 561 | local no_control_sequences="$1" 562 | local is_dirty=$(is_git_dirty) 563 | local is_ahead=$(is_git_ahead_of_remote) 564 | 565 | if [ -z "$no_control_sequences" ]; then 566 | local left_color="${TERM_WHITE}" 567 | local right_color="${TERM_WHITE}" 568 | local dirty_color="${TERM_RED}" 569 | local ahead_color="${TERM_GREEN}" 570 | fi 571 | 572 | if [ "$is_dirty" = "true" ]; then 573 | local dirty="* " 574 | if [[ "$OS" == "Darwin" ]]; then 575 | local dirty="✏️ " 576 | fi 577 | else 578 | local dirty=" " 579 | fi 580 | 581 | if [ "$is_ahead" = "true" ]; then 582 | local ahead="@ " 583 | if [[ "$OS" == "Darwin" ]]; then 584 | local ahead="💭 " 585 | fi 586 | else 587 | local ahead=" " 588 | fi 589 | 590 | local left="[" 591 | local right="]" 592 | echo "${left_color}${left}${dirty_color}${dirty}${ahead_color}${ahead}${right_color}${right}" 593 | } 594 | 595 | function git_info() 596 | { 597 | local no_control_sequences="$1" 598 | 599 | if [ $(is_git_dir) = "true" ]; then 600 | local dirty=$(git_dirty_display $no_control_sequences) 601 | local branch=$(git_branch_name) 602 | 603 | if [ ! -z "$no_control_sequences" ]; then 604 | echo "${dirty} ${branch}" 605 | else 606 | echo "${dirty} ${TERM_GREEN}${branch}" 607 | fi 608 | else 609 | echo "" 610 | fi 611 | } 612 | 613 | # 614 | # ----------------------------- Web --------------------------------- 615 | # 616 | function wiki() 617 | { 618 | dig +short txt "$*".wp.dg.cx 619 | } 620 | 621 | -------------------------------------------------------------------------------- /.bashrc: -------------------------------------------------------------------------------- 1 | # 2 | # Aaron's bash settings for interactive shells 3 | # 4 | 5 | # ==================== Initialization ==================== 6 | # First, read some useful bash functions 7 | source "$HOME/.bash-functions.sh" 8 | 9 | function setup_interactive_shell() 10 | { 11 | setup_env_vars 12 | setup_aliases 13 | setup_terminal 14 | } 15 | 16 | # 17 | # ==================== Environment variables ==================== 18 | # 19 | 20 | # 21 | # Master function for env vars 22 | # 23 | function setup_env_vars() 24 | { 25 | setup_whereami 26 | setup_path 27 | setup_general_prefs 28 | setup_app_prefs 29 | setup_projects 30 | setup_aboutme 31 | } 32 | 33 | # Returns the best guess of the terminal program. 34 | # requires $TERM to be in its original state. 35 | function get_launching_app() 36 | { 37 | if [ ! -z "$TERM_PROGRAM" ]; then 38 | echo $TERM_PROGRAM 39 | elif [ ! -z "$PATH_FINDER" ]; then 40 | echo "Path Finder" 41 | elif [ ! -z "$TERM" -a "$TERM" = "terminator" ]; then 42 | echo "Terminator" 43 | elif [ ! -z "$COLORTERM" -a "$COLORTERM" = "gnome-terminal" ]; then 44 | echo "Gnome Terminal" 45 | elif [ "$OS" = "Darwin" ]; then 46 | frontmost_script="$HOME/software/$PLATFORM/applescripts/get_frontmost_application.scpt" 47 | if [ -f "$frontmost_script" ]; then 48 | echo $(osascript "$frontmost_script") 49 | else 50 | echo "an unknown Mac terminal" 51 | fi 52 | else 53 | echo "an unknown terminal" 54 | fi 55 | } 56 | 57 | # 58 | # Environment variables that tell us about the machine we're on 59 | # 60 | function setup_whereami() 61 | { 62 | # Platform and host 63 | export PLATFORM=$(uname -s)-$(uname -m | sed 's/ /_/g') 64 | export OS=$(uname -s) 65 | export HOST_LONG=$(hostname) 66 | export HOST_SHORT=$(hostname | awk -F\. '{print $1}') 67 | export HOST="$HOST_SHORT" 68 | 69 | # Terminal application 70 | # What terminal are we under? 71 | export LAUNCHING_TERM="$TERM" 72 | export LAUNCHING_APP=$(get_launching_app) 73 | 74 | # Are we logged in locally, or over ssh? 75 | SSH_COMBO="$SSH_CONNECTION$SSH_CLIENT" 76 | if [ -z "$SSH_COMBO" ]; then 77 | export LOCALNESS="local" 78 | else 79 | SSH_REMOTE_IP="${SSH_COMBO%% *}" 80 | SSH_REMOTE_HOST=$(host $SSH_REMOTE_IP 2>/dev/null | awk -v SSH_REMOTE_IP=$SSH_REMOTE_IP '/name pointer/ {print $5} /NXDOMAIN/ {print SSH_REMOTE_IP }') 81 | if [ -z "$SSH_REMOTE_HOST" ]; then 82 | export SSH_REMOTE_HOST="$SSH_REMOTE_IP" 83 | fi 84 | export LOCALNESS="remote" 85 | fi 86 | 87 | # In Mac OS X, what network location is set? 88 | if [ -f "/usr/sbin/scselect" ]; then 89 | export LOCATION=$(/usr/sbin/scselect 2>&1 | perl -ne 'if (m/^\s+\*\s+(\S+)\s+\((.+)\)$/) { print "$2\n"; }') 90 | fi 91 | } 92 | 93 | # 94 | # Setting up the generic PATH 95 | # 96 | # Note that we prepend each time -- so the last path listed will 97 | # be used first. 98 | # 99 | # Thus we start with the general system paths, and then go to 100 | # increasingly specialized paths where we might place custom versions 101 | # of applications. 102 | function setup_path() 103 | { 104 | # Reset path -------------- 105 | # except not on Windows 106 | if [ "$OS" != "CYGWIN_NT-5.1" ]; then 107 | unset PATH 108 | fi 109 | 110 | # Generic useful paths ----------------- 111 | path_prepend /bin 112 | path_prepend /sbin 113 | path_prepend /usr/bin 114 | path_prepend /usr/sbin 115 | path_prepend /usr/X11R6/bin 116 | path_prepend /usr/X11/bin 117 | path_prepend /usr/local/bin 118 | path_prepend /usr/local/bin/perl/bin 119 | path_prepend /usr/ucb 120 | path_prepend /usr/local/gnu/bin 121 | path_prepend /opt/default/bin 122 | 123 | # darwinports 124 | path_prepend /opt/local/bin 125 | path_prepend /opt/local/sbin 126 | 127 | # Fink 128 | source_if "/sw/bin/init.sh" 129 | 130 | # Personal versions of applications 131 | path_prepend "$HOME/external-software/crossplatform/bin" 132 | path_prepend "$HOME/external-software/$PLATFORM/bin" 133 | 134 | # Custom scripts and utilities 135 | path_prepend "$HOME/software/crossplatform/bin" 136 | path_prepend "$HOME/software/$PLATFORM/bin" 137 | 138 | # Private scripts and utilities 139 | path_prepend "$HOME/private-software/crossplatform/bin" 140 | path_prepend "$HOME/private-software/$PLATFORM/bin" 141 | } 142 | 143 | # 144 | # Environment variables for system-wide preferences 145 | # 146 | function setup_general_prefs() 147 | { 148 | # 149 | # ------------ Application selection ------------ 150 | # 151 | 152 | if [ "$OS" = "Darwin" ]; then 153 | export EDITOR="vim" 154 | else 155 | export EDITOR="vim" 156 | fi 157 | export PAGER="less" 158 | 159 | # 160 | # ------------ Other universal stuff ------------ 161 | # 162 | export LANG="en_US.UTF-8" 163 | export LC_CTYPE="en_US.UTF-8" 164 | 165 | # X11 166 | # if [ -z $DISPLAY ]; then 167 | # export DISPLAY=:0.0 168 | # fi 169 | 170 | # Temporary file path; uses $HOME/tmp if it exists 171 | path_set "/tmp" TMP 172 | path_set "$HOME/tmp" TMP 173 | } 174 | 175 | # 176 | # Environment variables for specific applications 177 | # 178 | # Maintained in alphabetical order by application name 179 | function setup_app_prefs() 180 | { 181 | # Ant 182 | path_set "$HOME/external-software/crossplatform/stow/apache-ant-1.7.1" ANT_HOME 183 | path_prepend "$ANT_HOME/bin" 184 | 185 | # Eclim 186 | path_set "$HOME/external-software/$PLATFORM/stow/eclipse" ECLIM_ECLIPSE_HOME 187 | 188 | # Emscripten 189 | path_append "$HOME/external-software/$PLATFORM/stow/emscripten" 190 | 191 | # GCC 192 | path_prepend "$HOME/external-software/$PLATFORM/lib" LD_LIBRARY_PATH 193 | 194 | # Gnu coreutils 195 | if [ ! -z $(which dircolors) ]; then 196 | local dircolors_ver=$(dircolors --version | grep dircolors) 197 | if [ $(echo $dircolors_ver | grep '6.' | wc -l) = "1" ]; then 198 | if [ -f "$HOME/.dircolors" ]; then 199 | eval `dircolors "$HOME/.dircolors"` 200 | fi 201 | fi 202 | fi 203 | 204 | # Google depot_tools 205 | path_append "$HOME/external-src/depot_tools" 206 | 207 | # Homebrew 208 | path_append "/usr/local/sbin" 209 | 210 | # IDEA 211 | path_set "/usr/lib/jvm/java-6-openjdk" IDEA_JDK 212 | 213 | # Java 214 | unset CLASSPATH 215 | path_set "$HOME/external-software/$PLATFORM/stow/jdk" JAVA_HOME 216 | path_set "/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home" JAVA_HOME 217 | path_set "/usr/local/java" JAVA_HOME 218 | path_prepend "/usr/local/java/bin" 219 | path_prepend "/usr/local/java/java1.5/bin" 220 | export JAVA_OPTS="-Xmx1024m" 221 | 222 | # Jython 223 | path_append "$HOME/external-software/crossplatform/stow/jython-2.5.1/bin" 224 | 225 | # Less 226 | export LESSCHARSET="utf-8" 227 | 228 | # Lynx 229 | path_set "$HOME/software/crossplatform/etc/lynx.cfg" LYNX_CFG 230 | 231 | # MacVim 232 | path_append "$HOME/external-software/$PLATFORM/stow/macvim/bin" 233 | path_set "/Applications/3rdPartyApplications/Develop" VIM_APP_DIR 234 | 235 | # MySQL 236 | path_append "/usr/local/mysql/bin" 237 | 238 | # Node 239 | path_append "/usr/local/share/npm/bin" 240 | 241 | # Perl 242 | unset PERL5LIB 243 | path_append "$HOME/software/crossplatform/lib/site_perl" PERL5LIB 244 | path_append "$HOME/external-software/crossplatform/lib/site_perl" PERL5LIB 245 | export PERL_UNICODE="SDA" 246 | 247 | # Postgres 248 | path_append "/Library/PostgreSQL/8.4/bin" 249 | 250 | # Python 251 | path_append /usr/local/share/python3 252 | path_prepend /usr/local/share/python 253 | # path_append "/Library/Frameworks/Python.framework/Versions/2.6/bin" 254 | path_append "$HOME/external-software/crossplatform/common/etc/python" 255 | export PYTHONSTARTUP="$HOME/software/crossplatform/etc/python/startup.py" 256 | 257 | # R 258 | path_set "/Library/Frameworks/R.framework/Versions/Current/Resources" R_HOME 259 | 260 | # Ruby 261 | # unset RUBYLIB 262 | #export RUBYOPT=rubygems 263 | #path_append "$HOME/software/crossplatform/lib/ruby" RUBYLIB 264 | #path_prepend "$HOME/external-software/$PLATFORM/stow/ruby-1.8.6-p110/bin" 265 | 266 | # Scala 267 | path_set "$HOME/external-software/crossplatform/stow/scala-2.7.5.final" SCALA_HOME 268 | export ANT_OPTS="$ANT_OPTS -Dscala.home=$SCALA_HOME" 269 | # some particular items for classpath 270 | local mvn_repo="$HOME/.m2/repository" 271 | # path_append "$mvn_repo/org/scalacheck/scalacheck/1.2/scalacheck-1.2.jar" CLASSPATH 272 | # path_append "$mvn_repo/org/specs/specs/1.2.5/specs-1.2.5.jar" CLASSPATH 273 | # path_append "$mvn_repo/junit/junit/4.4/junit-4.4.jar" CLASSPATH 274 | # Subversion 275 | path_append "/usr/local/subversion/bin" 276 | 277 | # Tetex 278 | path_append "/usr/local/texlive/2007/bin/i386-darwin/" 279 | 280 | # XCode 281 | path_append "/Developer/Tools" 282 | path_append "/Volumes/MacBookPro/3rdPartyStuff/Developer-10.5/Tools" 283 | } 284 | 285 | # 286 | # Environment variables that tell the system who I am 287 | # 288 | function setup_aboutme() 289 | { 290 | export EMAIL="aaron@harnly.net" 291 | } 292 | 293 | # 294 | # Environment variables for projects 295 | # 296 | function setup_projects() 297 | { 298 | ######################### Projects ----------------------- 299 | # initialize the paths of any projects we find 300 | PROJECTS_DIR="$HOME/projects" 301 | if [ -d "$PROJECTS_DIR" ]; then 302 | for proj in $(ls "$PROJECTS_DIR") 303 | do 304 | proj_name=$(basename "$proj") 305 | proj_name__cap=$(echo "$proj_name" | perl -pe 's/\s+//g; s/([a-z])/\u\1/g; s/[^A-Z_]/_/g') 306 | eval export ${proj_name__cap}_DIR="$PROJECTS_DIR/$proj" 307 | if [ -d "$PROJECTS_DIR/$proj/data" ]; then 308 | eval export ${proj__name_cap}_DATA="$PROJECTS_DIR/$proj/data" 309 | fi 310 | PROJECT_INIT="$proj/tools/util/project_init.sh" 311 | source_if "$PROJECT_INIT" 312 | done 313 | fi 314 | } 315 | 316 | # 317 | # ==================== Aliases ==================== 318 | # 319 | function setup_aliases() 320 | { 321 | # Alphabetical by the underlying command 322 | 323 | # ----- cd ----- 324 | alias cd="mycd" ; export HISTFILE="$HOME/.dir_bash_history$PWD/${USER}_bash_history.txt" 325 | if [ ! -z "$WD" ]; then 326 | alias cdg="cd $WD" 327 | fi 328 | alias ..="cd .." 329 | 330 | # ----- git ---- 331 | alias pubgit="git --git-dir=$HOME/.public.git --work-tree=$HOME" 332 | alias prvgit="git --git-dir=$HOME/.private.git --work-tree=$HOME" 333 | function git_setup() 334 | { 335 | git-init 336 | git-config branch.master.remote origin 337 | git-config branch.master.merge refs/heads/master 338 | 339 | relative_path=${PWD#$HOME/} 340 | git-config remote.origin.fetch +refs/heads/*:refs/remotes/origin/* 341 | git-config remote.origin.url aaron@harnly.net@harnly.net:${relative_path} 342 | } 343 | 344 | # ----- less ------ 345 | alias more="less" 346 | 347 | # ----- ls ----- 348 | alias ll="ls -lGh" 349 | alias l="ls -lGh" 350 | alias ls="ls" 351 | 352 | # ---- open ---- 353 | if [ "$OS" = "Linux" ]; then 354 | alias open="gnome-open" 355 | fi 356 | 357 | # ---- rsync --- 358 | alias scpr="rsync --partial --progress --rsh=ssh --archive" 359 | 360 | # ----- Scala ----- 361 | alias rscala="rlwrap scala -Xnojline" 362 | alias rconsole="rlwrap mvn -Djava.awt.headless=true scala:console" 363 | export SCALA_OPTS="-Xnojline" 364 | alias scala-latest="$HOME/external-software/crossplatform/stow/scala-latest/bin/scala" 365 | alias scalac-latest="$HOME/external-software/crossplatform/stow/scala-latest/bin/scalac" 366 | alias rscala-latest="rlwrap $HOME/external-software/crossplatform/stow/scala-latest/bin/scala -Xnojline" 367 | 368 | function scala_setup() 369 | { 370 | dirname=$(basename "$PWD") 371 | projname=${projname/scala-/} 372 | mkdir -p "src/main/scala/net/harnly/$projname" 373 | mkdir -p "src/test/scala/net/harnly/$projname" 374 | cp "$HOME/software/crossplatform/etc/templates/scala-project/pom.xml" pom.xml 375 | } 376 | 377 | 378 | # ----- ssh ----- 379 | if [ "$OS" = "Darwin" ]; then 380 | alias ssh="ssh -Y" 381 | else 382 | alias ssh="ssh -X" 383 | fi 384 | alias renew_authorized_keys="cat \"$HOME/.ssh/keys.pub/\"* > \"$HOME/.ssh/authorized_keys2\"" 385 | 386 | # ---- top ---- 387 | alias topu="top -ocpu -R -F -s 2 -n30" 388 | 389 | # ---- tree ---- 390 | alias lst="tree -AlCNh --dirsfirst" 391 | 392 | # ---- xstow --- 393 | alias xstow="xstow -v 3 -ire 'entries|README.txt|format|.svn-base|.svn-work|empty-file'" 394 | 395 | } 396 | 397 | # 398 | # ==================== Terminal settings ==================== 399 | # 400 | 401 | function setup_terminal() 402 | { 403 | setup_term_colors 404 | setup_term_settings 405 | setup_term_prompt 406 | } 407 | 408 | # 409 | # Environment variables for terminal colors 410 | # 411 | function setup_term_colors() 412 | { 413 | OLD_TERM="$TERM" 414 | if [ -z "$TERM" -o "$TERM" = "dumb" ]; then 415 | export TERM=xterm-color 416 | fi 417 | export TERM_BLACK=$(tput setaf 0) 418 | export TERM_RED=$(tput setaf 1) 419 | export TERM_GREEN=$(tput setaf 2) 420 | export TERM_YELLOW=$(tput setaf 3) 421 | export TERM_BLUE=$(tput setaf 4) 422 | export TERM_PURPLE=$(tput setaf 5) 423 | export TERM_CYAN=$(tput setaf 6) 424 | export TERM_WHITE=$(tput setaf 7) 425 | 426 | export TERM_BG_BLACK=$(tput setab 0) 427 | export TERM_BG_RED=$(tput setab 1) 428 | export TERM_BG_GREEN=$(tput setab 2) 429 | export TERM_BG_YELLOW=$(tput setab 3) 430 | export TERM_BG_BLUE=$(tput setab 4) 431 | export TERM_BG_PURPLE=$(tput setab 5) 432 | export TERM_BG_CYAN=$(tput setab 6) 433 | export TERM_BG_WHITE=$(tput setab 7) 434 | 435 | export TERM_BOLD=$(tput smso) 436 | export TERM_BOLD_END=$(tput rmso) 437 | export TERM_UNDERLINE=$(tput smul) 438 | export TERM_UNDERLINE_END=$(tput rmul) 439 | export TERM_RESET=$(tput sgr0) 440 | 441 | export TERM="$OLD_TERM" 442 | export LSCOLORS="gxBxhxDxfxhxhxhxhxcxcx" 443 | } 444 | 445 | # 446 | # Environment variables and scripts controlling some bash settings 447 | # 448 | function setup_term_settings() 449 | { 450 | # ----------------- Shell options ------------------ 451 | shopt -s histappend 452 | 453 | # ----------------- Termcap ----------------- 454 | if [ "$TERM" != "screen" ]; then 455 | if [ "$LAUNCHING_APP" = "terminator" ]; then 456 | export TERM="ansi" 457 | export TERMINFO="$HOME/.terminfo" 458 | else 459 | export TERM="xterm-color" 460 | fi 461 | fi 462 | # export TERMINFO="$HOME/.terminfo" 463 | # export TERMCAP="$HOME/software/crossplatform/etc/termcap" 464 | 465 | # ----------------- Command completion ----------------- 466 | source_if "$HOME/.bash_completion" 467 | source_if "$HOME/.bash_completion_svn" 468 | source_if "$HOME/external-software/crossplatform/etc/bash_completion_svk" 469 | # ignore .svn directories for path completion 470 | export FIGNORE=.svn 471 | # ignore CVS directories for path completion 472 | export FIGNORE=$FIGNORE:CVS 473 | # after the command completion, reset manpath 474 | unset MANPATH 475 | } 476 | 477 | # 478 | # Updates the prompt. 479 | # 480 | function update_prompt() 481 | { 482 | EXIT_STATUS="$?" 483 | update_location_vars 484 | update_ps1 485 | } 486 | 487 | # 488 | # Updates env vars that should change with location 489 | # 490 | function update_location_vars() 491 | { 492 | PUBGIT_DIR="$HOME/.public.git" 493 | # in the home dir, show the status of pubgit 494 | if [ "$PWD" = "$HOME" ]; then 495 | export GIT_DIR="$PUBGIT_DIR" 496 | export GIT_WORK_TREE="$HOME" 497 | else 498 | if [ ! -z "$GIT_DIR" -a "$GIT_DIR" = "$PUBGIT_DIR" ]; then 499 | unset GIT_DIR 500 | unset GIT_WORK_TREE 501 | fi 502 | fi 503 | } 504 | 505 | # 506 | # Updates the PS1 prompt 507 | # 508 | function update_ps1() 509 | { 510 | # Line 1, left side 511 | if [ "$EXIT_STATUS" -eq 0 ]; then 512 | local exit_status_clean="" 513 | local exit_status="" 514 | else 515 | local exit_status_clean="[FAILED: $EXIT_STATUS]" 516 | local exit_status="${TERM_RED}${exit_status_clean}" 517 | fi 518 | 519 | local now=$(date +'%I:%M:%S %p') 520 | local ps_time_clean="[${now}]" 521 | local ps_time_color=${TERM_YELLOW} 522 | local ps_time="${ps_time_color}${ps_time_clean}" 523 | 524 | local userpath="${USER}@${HOST_LONG}:${PWD}" 525 | local ps_userpath_clean="${userpath}" 526 | local ps_userpath="${TERM_WHITE}${ps_userpath_clean}" 527 | 528 | local prefix="" 529 | local ps_prefix_clean="${prefix}" 530 | local ps_prefix="${TERM_BG_COLOR}${TERM_WHITE}${ps_prefix_clean}" 531 | 532 | local line_1_left_clean="${exit_status_clean}${ps_prefix_clean}${ps_time_clean}$ ${ps_userpath_clean}" 533 | local line_1_left="${exit_status}${ps_prefix}${ps_time} ${ps_userpath}" 534 | 535 | # Line 1, right side 536 | local git_info_clean=$(git_info clean) 537 | local git_info=$(git_info) 538 | 539 | local line_1_right_clean="${git_info_clean}" 540 | local line_1_right="${git_info}" 541 | 542 | # Line 1, padding 543 | local total_width=$(tput cols) 544 | local line_1_left_clean_width=$(length_of_longest_arg "$line_1_left_clean") 545 | local line_1_right_clean_width=$(length_of_longest_arg "$line_1_right_clean") 546 | 547 | local line_1_content_width=$(( $line_1_left_clean_width + $line_1_right_clean_width )) 548 | local line_1_padding_width=$(( $total_width - $line_1_content_width )) 549 | local line_1_padding=$(str_repeat " " $line_1_padding_width) 550 | 551 | # Line 1, combined 552 | local line_1="${line_1_left}${line_1_padding}${line_1_right}${TERM_RESET}" 553 | 554 | # Line 2 555 | local venv_display=$(virtualenv_display) 556 | local venv_display_clean=$(virtualenv_display clean) 557 | 558 | local line_2="${prefix}${venv_display}${USER_PROMPT}" 559 | 560 | # Prompt 561 | PS1="${line_1}\n${line_2}" 562 | } 563 | 564 | # 565 | # Environment variables controlling the prompt 566 | # 567 | function setup_term_prompt() 568 | { 569 | # ----------------- Prompt ----------------- 570 | # Show 'root' in red 571 | if [ $UID = 0 ]; then 572 | TERM_BG_COLOR=${TERM_BG_RED} 573 | else 574 | TERM_BG_COLOR=${TERM_BG_BLUE} 575 | fi 576 | 577 | # Set the basic user prompt 578 | if [[ "$OS" == "Darwin" ]]; then 579 | if [ $UID = 0 ]; then 580 | USER_PROMPT="‼️ " 581 | else 582 | USER_PROMPT="👀 " 583 | fi 584 | else 585 | if [ $UID = 0 ]; then 586 | USER_PROMPT="$ " 587 | else 588 | USER_PROMPT="# " 589 | fi 590 | fi 591 | 592 | # A basic prompt 593 | export PS1="${USER_PROMPT} " 594 | export PS2="${USER_PROMPT}| " 595 | 596 | # before each prompt, run a routine to set the prompt 597 | export PROMPT_COMMAND='update_prompt' 598 | } 599 | 600 | ########################### The actual execution ###################### 601 | 602 | setup_interactive_shell 603 | source_if "$HOME/.bashrc.$HOST" 604 | -------------------------------------------------------------------------------- /.bash_completion: -------------------------------------------------------------------------------- 1 | # bash_completion - some programmable completion functions for bash 2.05b 2 | # 3 | # $Id: bash_completion,v 1.644 2003/10/22 09:16:51 ianmacd Exp $ 4 | # 5 | # Copyright (C) Ian Macdonald 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 2, or (at your option) 10 | # any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program; if not, write to the Free Software Foundation, 19 | # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | # 21 | # The latest version of this software can be obtained here: 22 | # 23 | # http://www.caliban.org/bash/index.shtml#completion 24 | # 25 | # RELEASE: 20031022 26 | 27 | [ -n "${DEBUG:-}" ] && set -v || set +v 28 | 29 | # Alter the following to reflect the location of this file 30 | # 31 | if [ -n "${FUNCNAME:-}" ]; then 32 | # we're being sourced from within a function, so we can't use 33 | # 'declare', as this will create local variables within a function 34 | BASH_COMPLETION=${BASH_COMPLETION:-$HOME/.bash_completion} 2>/dev/null 35 | BASH_COMPLETION_DIR=${BASH_COMPLETION_DIR:=$HOME/.bash_completion.d} \ 36 | 2>/dev/null 37 | else 38 | declare -r BASH_COMPLETION=${BASH_COMPLETION:-$HOME/.bash_completion} \ 39 | 2>/dev/null 40 | declare -r \ 41 | BASH_COMPLETION_DIR=${BASH_COMPLETION_DIR:=$HOME/.bash_completion.d} \ 42 | 2>/dev/null 43 | fi 44 | 45 | # Set a couple of useful vars 46 | # 47 | UNAME=$( uname -s ) 48 | RELEASE=$( uname -r ) 49 | 50 | # features supported by bash 2.05 and higher 51 | if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} > 04 ]] || 52 | [ ${BASH_VERSINFO[0]} -gt 2 ]; then 53 | declare -r bash205=$BASH_VERSION 2>/dev/null 54 | default="-o default" 55 | dirnames="-o dirnames" 56 | filenames="-o filenames" 57 | fi 58 | # features supported by bash 2.05b and higher 59 | if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} = "05b" ]] || 60 | [ ${BASH_VERSINFO[0]} -gt 2 ]; then 61 | declare -r bash205b=$BASH_VERSION 2>/dev/null 62 | nospace="-o nospace" 63 | fi 64 | # features supported by bash 3.0 and higher 65 | if [ ${BASH_VERSINFO[0]} -gt 2 ]; then 66 | declare -r bash3=$BASH_VERSION 2>/dev/null 67 | bashdefault="-o bashdefault" 68 | plusdirs="-o plusdirs" 69 | fi 70 | 71 | # Turn on extended globbing and programmable completion 72 | shopt -s extglob progcomp 73 | 74 | # A lot of the following one-liners were taken directly from the 75 | # completion examples provided with the bash 2.04 source distribution 76 | 77 | # Make directory commands see only directories 78 | complete -d pushd 79 | 80 | # The following section lists completions that are redefined later 81 | # Do NOT break these over multiple lines. 82 | # 83 | # START exclude -- do NOT remove this line 84 | complete -f -X '!*.?(t)bz2' bunzip2 bzcat bzcmp bzdiff bzegrep bzfgrep bzgrep 85 | complete -f -X '!*.@(zip|ZIP|jar|JAR|exe|EXE|pk3|war|wsz|ear|zargo|xpi)' unzip zipinfo 86 | complete -f -X '*.Z' compress znew 87 | complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' gunzip zcmp zdiff zcat zegrep zfgrep zgrep zless zmore 88 | complete -f -X '!*.Z' uncompress 89 | complete -f -X '!*.@(gif|jp?(e)g|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' ee display 90 | 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 91 | complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv 92 | complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi 93 | complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype 94 | complete -f -X '!*.@(pdf|PDF)' acroread xpdf 95 | complete -f -X '!*.texi*' makeinfo texi2html 96 | complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi 97 | complete -f -X '!*.@(mp3|MP3|m3u)' mpg123 mpg321 98 | complete -f -X '!*.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|bin|dat|vcd|ps|pes|fli|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp3|MP3|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV)' xine 99 | complete -f -X '!*.@(avi|asf|wmv)' aviplay 100 | complete -f -X '!*.@(rm|ram|smi?(l))' realplay 101 | complete -f -X '!*.@(mpg|mpeg|avi|mov|qt)' xanim 102 | complete -f -X '!*.@(ogg|OGG|m3u)' ogg123 103 | complete -f -X '!*.@(mp3|MP3|ogg|OGG|pls|m3u)' gqmpeg freeamp 104 | complete -f -X '!*.@(mp[23]|MP[23]|ogg|OGG|wav|WAV|pls|m3u|xm|mod|s[3t]m|it|mtm|ult|flac)' xmms 105 | complete -f -X '!*.fig' xfig 106 | complete -f -X '!*.@(mid?(i))' timidity playmidi 107 | complete -f -X '*.@(o|so|so.!(conf)|a|tar?(.@(gz|bz2))|tgz|tbz2|rpm|zip|ZIP|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 emacs 108 | complete -f -X '!*.@(exe|EXE|com|COM|scr|SCR)' wine 109 | complete -f -X '!*.@(zip|ZIP|z|Z|gz|GZ|tgz|TGZ)' bzme 110 | complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx opera w3m galeon curl dillo elinks links 111 | # FINISH exclude -- do not remove this line 112 | 113 | # start of section containing compspecs that can be handled within bash 114 | 115 | # user commands see only users 116 | complete -u su usermod userdel passwd chage write chfn groups slay 117 | 118 | # group commands see only groups 119 | [ -n "$bash205" ] && complete -g groupmod groupdel newgrp 2>/dev/null 120 | 121 | # bg completes with stopped jobs 122 | complete -A stopped -P '%' bg 123 | 124 | # other job commands 125 | complete -j -P '%' fg jobs disown 126 | 127 | # readonly and unset complete with shell variables 128 | complete -v readonly unset 129 | 130 | # set completes with set options 131 | complete -A setopt set 132 | 133 | # shopt completes with shopt options 134 | complete -A shopt shopt 135 | 136 | # helptopics 137 | complete -A helptopic help 138 | 139 | # unalias completes with aliases 140 | complete -a unalias 141 | 142 | # bind completes with readline bindings (make this more intelligent) 143 | complete -A binding bind 144 | 145 | # type and which complete on commands 146 | complete -c command type which 147 | 148 | # start of section containing completion functions called by other functions 149 | 150 | # This function checks whether we have a given programs on the system. 151 | # No need for bulky functions in memory if we don't. 152 | # 153 | have() 154 | { 155 | unset -v have 156 | PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null && 157 | have="yes" 158 | } 159 | 160 | # use GNU sed if we have it, since its extensions are still used in our code 161 | # 162 | [ $UNAME != Linux ] && have gsed && alias sed=gsed 163 | 164 | # This function performs file and directory completion. It's better than 165 | # simply using 'compgen -f', because it honours spaces in filenames. 166 | # If passed -d, it completes only on directories. If passed anything else, 167 | # it's assumed to be a file glob to complete on. 168 | # 169 | _filedir() 170 | { 171 | local IFS=$'\t\n' xspec 172 | 173 | _expand || return 0 174 | 175 | if [ "${1:-}" = -d ]; then 176 | COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -d -- $cur ) ) 177 | return 0 178 | fi 179 | 180 | xspec=${1:+"!*.$1"} # set only if glob passed in as $1 181 | COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) 182 | $( compgen -d -- "$cur" ) ) 183 | } 184 | 185 | # This function completes on signal names 186 | # 187 | _signals() 188 | { 189 | local i 190 | 191 | # standard signal completion is rather braindead, so we need 192 | # to hack around to get what we want here, which is to 193 | # complete on a dash, followed by the signal name minus 194 | # the SIG prefix 195 | COMPREPLY=( $( compgen -A signal SIG${cur#-} )) 196 | for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do 197 | COMPREPLY[i]=-${COMPREPLY[i]#SIG} 198 | done 199 | } 200 | 201 | # This function completes on network interfaces 202 | # 203 | _interfaces() 204 | { 205 | if [ -f /etc/debian_version ]; then 206 | # Debian system 207 | COMPREPLY=( $( sed -ne 's|^iface \([^ ]\+\).*$|\1|p' \ 208 | /etc/network/interfaces ) ) 209 | else 210 | # Assume Red Hat 211 | COMPREPLY=( $( command ls \ 212 | /etc/sysconfig/network-scripts/ifcfg-* | \ 213 | sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) ) 214 | fi 215 | } 216 | 217 | # This function expands tildes in pathnames 218 | # 219 | _expand() 220 | { 221 | [ "$cur" != "${cur%\\}" ] && cur="$cur\\" 222 | 223 | # expand ~username type directory specifications 224 | if [[ "$cur" == \~*/* ]]; then 225 | eval cur=$cur 226 | 227 | elif [[ "$cur" == \~* ]]; then 228 | cur=${cur#\~} 229 | COMPREPLY=( $( compgen -P '~' -u $cur ) ) 230 | return ${#COMPREPLY[@]} 231 | fi 232 | } 233 | 234 | # This function completes on process IDs 235 | # 236 | _pids() 237 | { 238 | COMPREPLY=( $( compgen -W '$( command ps axo pid | sed 1d )' -- $cur ) ) 239 | } 240 | 241 | # This function completes on process group IDs 242 | # 243 | _pgids() 244 | { 245 | COMPREPLY=( $( compgen -W '$( command ps axo pgid | sed 1d )' -- $cur )) 246 | } 247 | 248 | # This function completes on user IDs 249 | # 250 | _uids() 251 | { 252 | if type perl &>/dev/null; then 253 | COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- $cur ) ) 254 | else 255 | # make do with /etc/passwd 256 | COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\ 257 | /etc/passwd ) ) 258 | fi 259 | } 260 | 261 | # This function completes on group IDs 262 | # 263 | _gids() 264 | { 265 | if type perl &>/dev/null; then 266 | COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- $cur ) ) 267 | else 268 | # make do with /etc/group 269 | COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\ 270 | /etc/group ) ) 271 | fi 272 | } 273 | 274 | # Linux ifconfig(8) and iwconfig(8) helper function 275 | # 276 | [ $UNAME = Linux -o $UNAME = FreeBSD ] && { have ifconfig || have iwconfig; } && 277 | _ifwconfig() 278 | { 279 | COMPREPLY=() 280 | cur=${COMP_WORDS[COMP_CWORD]} 281 | 282 | case "${COMP_WORDS[1]}" in 283 | -|*[0-9]*) 284 | #COMPREPLY=( $( compgen -W '${keywords[@]}' ) ) 285 | COMPREPLY=( ${keywords[@]} ) 286 | COMPREPLY=( $( echo " ${COMP_WORDS[@]}" | \ 287 | (while read -d ' ' i; do 288 | [ "$i" == "" ] && continue 289 | # flatten array with spaces on either side, 290 | # otherwise we cannot grep on word 291 | # boundaries of first and last word 292 | COMPREPLY=" ${COMPREPLY[@]} " 293 | # remove word from list of completions 294 | COMPREPLY=( ${COMPREPLY/ $i / } ) 295 | done 296 | echo ${COMPREPLY[@]}) 297 | ) ) 298 | return 0 299 | ;; 300 | esac 301 | 302 | COMPREPLY=( $( eval "$@" 2>/dev/null | \ 303 | sed -ne \ 304 | 's|^\('$cur'[^[:space:][:punct:]]\{1,\}\).*$|\1|p') ) 305 | } 306 | 307 | # start of section containing completion functions for bash built-ins 308 | 309 | # bash alias completion 310 | # 311 | _alias() 312 | { 313 | local cur 314 | 315 | COMPREPLY=() 316 | cur=${COMP_WORDS[$COMP_CWORD]} 317 | 318 | case "$COMP_LINE" in 319 | *[^=]) 320 | COMPREPLY=( $( compgen -A alias -S '=' -- $cur ) ) 321 | ;; 322 | *=) 323 | COMPREPLY=( "$( alias ${cur%=} 2>/dev/null | \ 324 | sed -e 's|^alias '$cur'\(.*\)$|\1|' )" ) 325 | ;; 326 | esac 327 | } 328 | complete -F _alias alias 329 | 330 | # bash export completion 331 | # 332 | _export() 333 | { 334 | local cur 335 | 336 | COMPREPLY=() 337 | cur=${COMP_WORDS[$COMP_CWORD]} 338 | 339 | case "$COMP_LINE" in 340 | *=\$*) 341 | COMPREPLY=( $( compgen -v -P '$' -- ${cur#*=\$} ) ) 342 | ;; 343 | *[^=]) 344 | COMPREPLY=( $( compgen -v -S '=' -- $cur ) ) 345 | ;; 346 | *=) 347 | COMPREPLY=( $( eval echo $`echo ${cur%=}` ) ) 348 | ;; 349 | esac 350 | } 351 | complete -F _export $default $nospace export 352 | 353 | # bash shell function completion 354 | # 355 | _function() 356 | { 357 | local cur prev 358 | 359 | COMPREPLY=() 360 | cur=${COMP_WORDS[COMP_CWORD]} 361 | prev=${COMP_WORDS[COMP_CWORD-1]} 362 | 363 | if [[ $1 == @(declare|typeset) ]]; then 364 | if [ "$prev" = -f ]; then 365 | COMPREPLY=( $( compgen -A function -- $cur ) ) 366 | elif [[ "$cur" == -* ]]; then 367 | COMPREPLY=( $( compgen -W '-a -f -F -i -r -x -p' -- \ 368 | $cur ) ) 369 | fi 370 | elif [ $COMP_CWORD -eq 1 ]; then 371 | COMPREPLY=( $( compgen -A function -- $cur ) ) 372 | else 373 | COMPREPLY=( "() $( type -- ${COMP_WORDS[1]} | sed -e 1,2d )" ) 374 | fi 375 | } 376 | complete -F _function function declare typeset 377 | 378 | # bash complete completion 379 | # 380 | _complete() 381 | { 382 | local cur prev options 383 | 384 | COMPREPLY=() 385 | cur=${COMP_WORDS[COMP_CWORD]} 386 | prev=${COMP_WORDS[COMP_CWORD-1]} 387 | 388 | case $prev in 389 | -o) 390 | options="default dirnames filenames" 391 | [ -n "$bash205b" ] && options="$options nospace" 392 | [ -n "$bash3" ] && options="$options bashdefault plusdirs" 393 | COMPREPLY=( $( compgen -W "$options" -- $cur ) ) 394 | return 0 395 | ;; 396 | 397 | -A) 398 | COMPREPLY=( $( compgen -W 'alias arrayvar binding \ 399 | builtin command directory disabled enabled \ 400 | export file function group helptopic hostname \ 401 | job keyword running service setopt shopt \ 402 | signal stopped user variable' -- $cur ) ) 403 | return 0 404 | ;; 405 | 406 | -C) 407 | COMPREPLY=( $( compgen -A command -- $cur ) ) 408 | return 0 409 | ;; 410 | -F) 411 | COMPREPLY=( $( compgen -A function -- $cur ) ) 412 | return 0 413 | ;; 414 | -@(p|r)) 415 | COMPREPLY=( $( complete -p | sed -e 's|.* ||' | \ 416 | grep "^$cur" ) ) 417 | return 0 418 | ;; 419 | 420 | esac 421 | 422 | if [[ "$cur" == -* ]]; then 423 | # relevant options completion 424 | options="-a -b -c -d -e -f -g -j -k -s -v -u -A -G -W -P -S -X -F -C" 425 | [ -n "$bash205" ] && options="$options -o" 426 | COMPREPLY=( $( compgen -W "$options" -- $cur ) ) 427 | else 428 | COMPREPLY=( $( compgen -A command -- $cur ) ) 429 | fi 430 | } 431 | complete -F _complete complete 432 | 433 | # start of section containing completion functions for external programs 434 | 435 | # a little help for FreeBSD ports users 436 | [ $UNAME = FreeBSD ] && complete -W 'index search fetch fetch-list \ 437 | extract patch configure build install reinstall \ 438 | deinstall clean clean-depends kernel buildworld' make 439 | 440 | # This completes on a list of all available service scripts for the 441 | # 'service' command and/or the SysV init.d directory, followed by 442 | # that script's available commands 443 | # 444 | { have service || [ -d /etc/init.d/ ]; } && 445 | _service() 446 | { 447 | local cur sysvdir 448 | 449 | COMPREPLY=() 450 | prev=${COMP_WORDS[COMP_CWORD-1]} 451 | cur=${COMP_WORDS[COMP_CWORD]} 452 | 453 | # don't complete for things like killall, ssh and mysql if it's 454 | # the standalone command, rather than the init script 455 | [[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0 456 | 457 | # don't complete past 2nd token 458 | [ $COMP_CWORD -gt 2 ] && return 0 459 | 460 | [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \ 461 | || sysvdir=/etc/init.d 462 | 463 | if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then 464 | COMPREPLY=( $( compgen -W '`echo $sysvdir/!(*.rpmsave|*.rpmorig)`' ) ) 465 | COMPREPLY=( $( compgen -W '${COMPREPLY[@]#$sysvdir/}' -- \ 466 | $cur ) ) 467 | else 468 | COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \ 469 | s/^.*Usage.*{\(.*\)}.*$/\1/p" \ 470 | $sysvdir/${prev##*/}`' -- \ 471 | $cur ) ) 472 | fi 473 | 474 | return 0 475 | } 476 | [ -n "${have:-}" ] && complete -F _service service 477 | [ -d /etc/init.d/ ] && complete -F _service $default \ 478 | $(for i in /etc/init.d/*; do echo ${i##*/}; done) 479 | 480 | # chown(1) completion 481 | # 482 | _chown() 483 | { 484 | local user 485 | local cur=${COMP_WORDS[COMP_CWORD]} 486 | local prev=${COMP_WORDS[COMP_CWORD-1]} 487 | 488 | # options completion 489 | if [[ "$cur" == -* ]]; then 490 | COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \ 491 | --dereference --no-dereference --from= --silent --quiet \ 492 | --reference= --recursive --verbose --help --version' -- $cur ) ) 493 | return 0 494 | fi 495 | 496 | if (( COMP_CWORD == 1 )) || [[ "$prev" == -* ]]; then 497 | if [[ $cur = *@(\\:|.)* ]] && [ -n "$bash205" ]; then 498 | user=${cur%%*([^:.])} 499 | COMPREPLY=( $(compgen -P ${user/\\\\} -g -- ${cur##*[.:]}) ) 500 | elif [[ $cur = *:* ]] && [ -n "$bash205" ]; then 501 | COMPREPLY=( $( compgen -g -- ${cur##*[.:]} ) ) 502 | else 503 | COMPREPLY=( $( compgen -S : -u -- $cur ) ) 504 | fi 505 | else 506 | _filedir 507 | fi 508 | } 509 | complete -F _chown $filenames chown 510 | 511 | # chgrp(1) completion 512 | # 513 | _chgrp() 514 | { 515 | local cur prev 516 | 517 | COMPREPLY=() 518 | cur=${COMP_WORDS[COMP_CWORD]} 519 | prev=${COMP_WORDS[COMP_CWORD-1]} 520 | 521 | # options completion 522 | if [[ "$cur" == -* ]]; then 523 | COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \ 524 | --dereference --no-dereference --silent --quiet \ 525 | --reference= --recursive --verbose --help --version' -- $cur ) ) 526 | return 0 527 | fi 528 | 529 | # first parameter on line or first since an option? 530 | if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]] || \ 531 | [[ "$prev" == -* ]] && [ -n "$bash205" ]; then 532 | COMPREPLY=( $( compgen -g $cur 2>/dev/null ) ) 533 | else 534 | _expand || return 0 535 | fi 536 | 537 | return 0 538 | } 539 | complete -F _chgrp $default chgrp 540 | 541 | # umount(8) completion. This relies on the mount point being the third 542 | # space-delimited field in the output of mount(8) 543 | # 544 | _umount() 545 | { 546 | local cur 547 | 548 | COMPREPLY=() 549 | cur=${COMP_WORDS[COMP_CWORD]} 550 | 551 | COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- $cur ) ) 552 | 553 | return 0 554 | } 555 | complete -F _umount $dirnames umount 556 | 557 | # mount(8) completion. This will pull a list of possible mounts out of 558 | # /etc/{,v}fstab, unless the word being completed contains a ':', which 559 | # would indicate the specification of an NFS server. In that case, we 560 | # query the server for a list of all available exports and complete on 561 | # that instead. 562 | # 563 | _mount() 564 | { local cur i sm host 565 | 566 | COMPREPLY=() 567 | cur=${COMP_WORDS[COMP_CWORD]} 568 | [[ "$cur" == \\ ]] && cur="/" 569 | 570 | for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done 571 | 572 | if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then 573 | COMPREPLY=( $( $sm -e ${cur%%:*} | sed 1d | \ 574 | grep ^${cur#*:} | awk '{print $1}' ) ) 575 | elif [[ "$cur" == //* ]]; then 576 | host=${cur#//} 577 | host=${host%%/*} 578 | if [ -n "$host" ]; then 579 | COMPREPLY=( $( compgen -W "$( echo $( smbclient -d 0 -NL $host | 580 | sed -ne '/^['$'\t '']*Sharename/,/^$/p' | 581 | sed -ne '3,$s|^[^A-Za-z]*\([^'$'\t '']*\).*$|//'$host'/\1|p' ) )" -- "$cur" ) ) 582 | fi 583 | elif [ -r /etc/vfstab ]; then 584 | # Solaris 585 | COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \ 586 | /etc/vfstab | grep "^$cur" ) ) 587 | else 588 | # probably Linux 589 | COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \ 590 | /etc/fstab | grep "^$cur" ) ) 591 | fi 592 | 593 | return 0 594 | } 595 | complete -F _mount $default $filenames mount 596 | 597 | # Linux rmmod(8) completion. This completes on a list of all currently 598 | # installed kernel modules. 599 | # 600 | have rmmod && { 601 | _rmmod() 602 | { 603 | local cur 604 | 605 | COMPREPLY=() 606 | cur=${COMP_WORDS[COMP_CWORD]} 607 | 608 | COMPREPLY=( $( /sbin/lsmod | \ 609 | awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' 2>/dev/null )) 610 | return 0 611 | } 612 | complete -F _rmmod rmmod 613 | 614 | # Linux insmod(8), modprobe(8) and modinfo(8) completion. This completes on a 615 | # list of all available modules for the version of the kernel currently 616 | # running. 617 | # 618 | _insmod() 619 | { 620 | local cur prev modpath 621 | 622 | COMPREPLY=() 623 | cur=${COMP_WORDS[COMP_CWORD]} 624 | prev=${COMP_WORDS[COMP_CWORD-1]} 625 | modpath=/lib/modules/`uname -r` 626 | 627 | # behave like lsmod for modprobe -r 628 | if [ $1 = "modprobe" ] && 629 | [ "${COMP_WORDS[1]}" = "-r" ]; then 630 | COMPREPLY=( $( /sbin/lsmod | \ 631 | awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' ) ) 632 | return 0 633 | fi 634 | 635 | # do filename completion if we're giving a path to a module 636 | if [[ "$cur" == ?(.|..)/* ]]; then 637 | _filedir 638 | return 0 639 | fi 640 | 641 | if [ $COMP_CWORD -gt 1 ] && 642 | [[ "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then 643 | # do module parameter completion 644 | COMPREPLY=( $( /sbin/modinfo -p ${COMP_WORDS[1]} 2>/dev/null | \ 645 | awk '{if ($1 ~ /^parm:/ && $2 ~ /^'$cur'/) { print $2 } \ 646 | else if ($1 !~ /:/ && $1 ~ /^'$cur'/) { print $1 }}' ) ) 647 | elif [ -r $modpath -a -x $modpath ]; then 648 | # do module name completion 649 | COMPREPLY=( $( command ls -R $modpath | \ 650 | sed -ne 's/^\('$cur'.*\)\.k\?o\(\|.gz\)$/\1/p') ) 651 | else 652 | _filedir 653 | fi 654 | 655 | return 0 656 | } 657 | complete -F _insmod $filenames insmod modprobe modinfo 658 | } 659 | 660 | # man(1) completion 661 | # 662 | [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \ 663 | -o $UNAME = FreeBSD -o $UNAME = SunOS ] && 664 | _man() 665 | { 666 | local cur prev sect manpath UNAME 667 | 668 | COMPREPLY=() 669 | cur=${COMP_WORDS[COMP_CWORD]} 670 | prev=${COMP_WORDS[COMP_CWORD-1]} 671 | 672 | _expand || return 0 673 | 674 | # default completion if parameter contains / 675 | if [[ "$cur" == */* ]]; then 676 | _filedir 677 | return 0 678 | fi 679 | 680 | UNAME=$( uname -s ) 681 | if [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = FreeBSD ]; then 682 | manpath=$( manpath 2>/dev/null || command man --path ) 683 | else 684 | manpath=$MANPATH 685 | fi 686 | 687 | if [ -z "$manpath" ]; then 688 | COMPREPLY=( $( compgen -c -- $cur ) ) 689 | return 0 690 | fi 691 | 692 | # determine manual section to search 693 | [[ "$prev" == [0-9ln] ]] && sect=$prev || sect='*' 694 | 695 | manpath=$manpath: 696 | if [ -n "$cur" ]; then 697 | manpath="${manpath//://*man$sect/$cur* }" 698 | else 699 | manpath="${manpath//://*man$sect/ }" 700 | fi 701 | 702 | # redirect stderr for when path doesn't exist 703 | COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) ) 704 | # weed out directory path names and paths to man pages 705 | COMPREPLY=( ${COMPREPLY[@]##*/?(:)} ) 706 | # strip suffix from man pages 707 | COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} ) 708 | COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) ) 709 | 710 | [[ "$prev" != [0-9ln] ]] && _filedir '[0-9ln]' 711 | 712 | return 0 713 | } 714 | [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \ 715 | -o $UNAME = FreeBSD -o $UNAME = SunOS ] && complete -F _man $filenames man 716 | 717 | # renice(8) completion 718 | # 719 | _renice() 720 | { 721 | local command cur curopt i 722 | 723 | COMPREPLY=() 724 | cur=${COMP_WORDS[COMP_CWORD]} 725 | command=$1 726 | 727 | i=0 728 | # walk back through command line and find last option 729 | while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do 730 | curopt=${COMP_WORDS[COMP_CWORD-$i]} 731 | case "$curopt" in 732 | -u) 733 | COMPREPLY=( $( compgen -u -- $cur ) ) 734 | ;; 735 | -g) 736 | _pgids 737 | ;; 738 | -p|$command) 739 | _pids 740 | ;; 741 | esac 742 | i=$(( ++i )) 743 | done 744 | } 745 | complete -F _renice renice 746 | 747 | # kill(1) completion 748 | # 749 | _kill() 750 | { 751 | local cur 752 | 753 | COMPREPLY=() 754 | cur=${COMP_WORDS[COMP_CWORD]} 755 | 756 | if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then 757 | # return list of available signals 758 | _signals 759 | else 760 | # return list of available PIDs 761 | _pids 762 | fi 763 | } 764 | complete -F _kill kill 765 | 766 | # Linux and FreeBSD killall(1) completion. 767 | # 768 | [ $UNAME = Linux -o $UNAME = FreeBSD ] && 769 | _killall() 770 | { 771 | local cur 772 | 773 | COMPREPLY=() 774 | cur=${COMP_WORDS[COMP_CWORD]} 775 | 776 | if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then 777 | _signals 778 | else 779 | COMPREPLY=( $( compgen -W '$( command ps axo command | \ 780 | sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \ 781 | sed -e "s/.*\///" )' -- $cur ) ) 782 | fi 783 | 784 | return 0 785 | } 786 | [ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall pkill 787 | 788 | # GNU find(1) completion. This makes heavy use of ksh style extended 789 | # globs and contains Linux specific code for completing the parameter 790 | # to the -fstype option. 791 | # 792 | _find() 793 | { 794 | local cur prev i switchfound 795 | 796 | COMPREPLY=() 797 | cur=${COMP_WORDS[COMP_CWORD]} 798 | prev=${COMP_WORDS[COMP_CWORD-1]} 799 | 800 | case "$prev" in 801 | -@(max|min)depth) 802 | COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- $cur ) ) 803 | return 0 804 | ;; 805 | -?(a|c)newer|-fls|-fprint?(0|f)|-?(i)?(l)name) 806 | _filedir 807 | return 0 808 | ;; 809 | -fstype) 810 | # this is highly non-portable 811 | COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | \ 812 | grep "^$cur" ) ) 813 | return 0 814 | ;; 815 | -gid) 816 | _gids 817 | return 0 818 | ;; 819 | -group) 820 | if [ -n "$bash205" ]; then 821 | COMPREPLY=( $( compgen -g -- $cur 2>/dev/null) ) 822 | fi 823 | return 0 824 | ;; 825 | -?(x)type) 826 | COMPREPLY=( $( compgen -W 'b c d p f l s' -- $cur ) ) 827 | return 0 828 | ;; 829 | -uid) 830 | _uids 831 | return 0 832 | ;; 833 | -user) 834 | COMPREPLY=( $( compgen -u -- $cur ) ) 835 | return 0 836 | ;; 837 | -[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \ 838 | -links|-perm|-size|-used|-exec|-ok|-printf) 839 | # do nothing, just wait for a parameter to be given 840 | return 0 841 | ;; 842 | esac 843 | 844 | _expand || return 0 845 | 846 | # set switchfound to 1 if there is already a switch argument 847 | for i in ${COMP_WORDS[@]}; do 848 | [[ "$i" = -* ]] && switchfound=1 && break 849 | done 850 | 851 | # handle case where first parameter is not a dash option 852 | if [ "$switchfound" != 1 ] && [[ "$cur" != -* ]]; then 853 | _filedir -d 854 | return 0 855 | fi 856 | 857 | # complete using basic options 858 | COMPREPLY=( $( compgen -W '-daystart -depth -follow -help -maxdepth \ 859 | -mindepth -mount -noleaf -version -xdev -amin -anewer \ 860 | -atime -cmin -cnewer -ctime -empty -false -fstype \ 861 | -gid -group -ilname -iname -inum -ipath -iregex \ 862 | -links -lname -mmin -mtime -name -newer -nouser \ 863 | -nogroup -perm -regex -size -true -type -uid -used \ 864 | -user -xtype -exec -fls -fprint -fprint0 -fprintf -ok \ 865 | -print -print0 -printf -prune -ls' -- $cur ) ) 866 | 867 | # this removes any options from the list of completions that have 868 | # already been specified somewhere on the command line. 869 | COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \ 870 | (while read -d ' ' i; do 871 | [ "$i" == "" ] && continue 872 | # flatten array with spaces on either side, 873 | # otherwise we cannot grep on word boundaries of 874 | # first and last word 875 | COMPREPLY=" ${COMPREPLY[@]} " 876 | # remove word from list of completions 877 | COMPREPLY=( ${COMPREPLY/ ${i%% *} / } ) 878 | done 879 | echo ${COMPREPLY[@]}) 880 | ) ) 881 | 882 | _filedir 883 | 884 | return 0 885 | } 886 | complete -F _find $filenames find 887 | 888 | # Linux ifconfig(8) completion 889 | # 890 | [ $UNAME = Linux -o $UNAME = FreeBSD ] && have ifconfig && 891 | _ifconfig() 892 | { 893 | local cur 894 | local -a keywords=( -a up down arp promisc allmulti metric mtu dstaddr \ 895 | netmask add del tunnel irq io_addr mem_start media \ 896 | broadcast pointopoint hw multicast address txqueuelen ) 897 | 898 | _ifwconfig ifconfig -a 899 | 900 | COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) ) 901 | } 902 | [ $UNAME = Linux -o $UNAME = FreeBSD ] && have ifconfig && 903 | complete -F _ifconfig ifconfig 904 | 905 | # Linux iwconfig(8) completion 906 | # 907 | [ $UNAME = Linux ] && have iwconfig && 908 | _iwconfig() 909 | { 910 | local -a keywords=( essid nwid domain freq channel sens mode ap nick \ 911 | rate bit rts frag key enc power ) 912 | 913 | _ifwconfig iwconfig 914 | 915 | COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) ) 916 | } 917 | [ $UNAME = Linux ] && complete -F _iwconfig iwconfig 918 | 919 | # RedHat & Debian GNU/Linux if{up,down} completion 920 | # 921 | [ $UNAME = Linux ] && ( have ifup || have ifdown ) && 922 | _ifupdown() 923 | { 924 | local cur 925 | 926 | COMPREPLY=() 927 | cur=${COMP_WORDS[COMP_CWORD]} 928 | 929 | if [ $COMP_CWORD -eq 1 ]; then 930 | _interfaces 931 | fi 932 | 933 | return 0 934 | } 935 | [ $UNAME = Linux ] && have ifup && complete -F _ifupdown ifup ifdown 936 | 937 | # Linux ipsec(8) completion (for FreeS/WAN) 938 | # 939 | [ $UNAME = Linux ] && have ipsec && 940 | _ipsec() 941 | { 942 | local cur 943 | 944 | COMPREPLY=() 945 | cur=${COMP_WORDS[COMP_CWORD]} 946 | 947 | 948 | if [ $COMP_CWORD -eq 1 ]; then 949 | COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look \ 950 | manual pluto ranbits rsasigkey \ 951 | setup showdefaults showhostkey spi \ 952 | spigrp tncfg whack' -- $cur ) ) 953 | return 0 954 | fi 955 | 956 | case ${COMP_WORDS[1]} in 957 | auto) 958 | COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete \ 959 | --replace --down --route --unroute \ 960 | --ready --status --rereadsecrets' \ 961 | -- $cur ) ) 962 | ;; 963 | manual) 964 | COMPREPLY=( $( compgen -W '--up --down --route --unroute \ 965 | --union' -- $cur ) ) 966 | ;; 967 | ranbits) 968 | COMPREPLY=( $( compgen -W '--quick --continuous --bytes' \ 969 | -- $cur ) ) 970 | ;; 971 | setup) 972 | COMPREPLY=( $( compgen -W '--start --stop --restart' -- $cur ) ) 973 | ;; 974 | 975 | *) 976 | ;; 977 | esac 978 | 979 | return 0 980 | } 981 | [ $UNAME = Linux ] && [ -n "${have:-}" ] && complete -F _ipsec ipsec 982 | 983 | # Postfix completion. 984 | # 985 | have postfix && { 986 | # postfix(1) 987 | # 988 | _postfix() 989 | { 990 | COMPREPLY=( $( compgen -W 'start stop reload abort flush check' -- \ 991 | "${COMP_WORDS[COMP_CWORD]}" ) ) 992 | } 993 | complete -F _postfix postfix 994 | 995 | # postalias(1) and postmap(1) 996 | # 997 | _postmap() 998 | { 999 | local cur prev len idx 1000 | 1001 | cur=${COMP_WORDS[COMP_CWORD]} 1002 | prev=${COMP_WORDS[COMP_CWORD-1]} 1003 | 1004 | if [[ $cur == '-' ]]; then 1005 | COMPREPLY=(-N -f -i -n -o -p -r -v -w -c -d -q) 1006 | return 0 1007 | fi 1008 | if [[ $prev == '-c' ]]; then 1009 | _filedir -d 1010 | return 0 1011 | fi 1012 | if [[ $prev == -[dq] ]]; then 1013 | return 0 1014 | fi 1015 | 1016 | if [[ "$cur" == *:* ]]; then 1017 | COMPREPLY=( $( compgen -f -- ${cur#*:} ) ) 1018 | else 1019 | len=${#cur} 1020 | idx=0 1021 | for pval in $( /usr/sbin/postconf -m ); do 1022 | if [[ "$cur" == "${pval:0:$len}" ]]; then 1023 | COMPREPLY[$idx]="$pval:" 1024 | idx=$(($idx+1)) 1025 | fi 1026 | done 1027 | if [[ $idx -eq 0 ]]; then 1028 | COMPREPLY=( $( compgen -f -- "$cur" ) ) 1029 | fi 1030 | fi 1031 | return 0 1032 | } 1033 | complete -F _postmap postmap postalias 1034 | 1035 | # postcat(1) 1036 | # 1037 | _postcat() 1038 | { 1039 | local cur prev pval len idx qfile 1040 | 1041 | cur=${COMP_WORDS[COMP_CWORD]} 1042 | prev=${COMP_WORDS[COMP_CWORD-1]} 1043 | 1044 | if [[ $cur == '-' ]]; then 1045 | COMPREPLY=(-c -q -v) 1046 | return 0 1047 | fi 1048 | if [[ $prev == '-c' ]]; then 1049 | _filedir -d 1050 | return 0 1051 | fi 1052 | 1053 | qfile=0 1054 | for idx in ${COMP_WORDS[@]}; do 1055 | [[ "$idx" = -q ]] && qfile=1 && break 1056 | done 1057 | if [[ $qfile == 1 ]]; then 1058 | len=${#cur} 1059 | idx=0 1060 | for pval in $( mailq | \ 1061 | sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do 1062 | if [[ "$cur" == "${pval:0:$len}" ]]; then 1063 | COMPREPLY[$idx]=$pval 1064 | idx=$(($idx+1)) 1065 | fi 1066 | done 1067 | return 0 1068 | else 1069 | _filedir 1070 | return 0 1071 | fi 1072 | } 1073 | complete -F _postcat postcat 1074 | 1075 | # postconf(1) 1076 | # 1077 | _postconf() 1078 | { 1079 | local cur prev pval len idx eqext 1080 | 1081 | cur=${COMP_WORDS[COMP_CWORD]} 1082 | prev=${COMP_WORDS[COMP_CWORD-1]} 1083 | if [[ $cur == '-' ]]; then 1084 | COMPREPLY=(-c -d -e -h -m -l -n -v) 1085 | return 0 1086 | fi 1087 | if [[ $prev == '-c' ]]; then 1088 | _filedir -d 1089 | return 0 1090 | fi 1091 | if [[ $prev == '-e' ]]; then 1092 | cur=${cur#[\"\']} 1093 | eqext='=' 1094 | fi 1095 | len=${#cur} 1096 | idx=0 1097 | for pval in $( /usr/sbin/postconf | cut -d ' ' -f 1 ); do 1098 | if [[ "$cur" == "${pval:0:$len}" ]]; then 1099 | COMPREPLY[$idx]="$pval$eqext" 1100 | idx=$(($idx+1)) 1101 | fi 1102 | done 1103 | return 0 1104 | } 1105 | complete -F _postconf postconf 1106 | 1107 | # postsuper(1) 1108 | # 1109 | _postsuper() 1110 | { 1111 | local cur prev pval len idx 1112 | 1113 | cur=${COMP_WORDS[COMP_CWORD]} 1114 | prev=${COMP_WORDS[COMP_CWORD-1]} 1115 | 1116 | if [[ $cur == '-' ]]; then 1117 | COMPREPLY=(-c -d -h -H -p -r -s -v) 1118 | return 0 1119 | fi 1120 | case $prev in 1121 | -[dr]) 1122 | len=${#cur} 1123 | idx=0 1124 | for pval in $( echo ALL; mailq | \ 1125 | sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do 1126 | if [[ "$cur" == "${pval:0:$len}" ]]; then 1127 | COMPREPLY[$idx]=$pval 1128 | idx=$(($idx+1)) 1129 | fi 1130 | done 1131 | return 0 1132 | ;; 1133 | -h) 1134 | len=${#cur} 1135 | idx=0 1136 | for pval in $( echo ALL; mailq | \ 1137 | sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* ].*$//; /!$/d' ); do 1138 | if [[ "$cur" == "${pval:0:$len}" ]]; then 1139 | COMPREPLY[$idx]=$pval 1140 | idx=$(($idx+1)) 1141 | fi 1142 | done 1143 | return 0 1144 | ;; 1145 | -H) 1146 | len=${#cur} 1147 | idx=0 1148 | for pval in $( echo ALL; mailq | \ 1149 | sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//' ); do 1150 | if [[ "$cur" == "${pval:0:$len}" ]]; then 1151 | COMPREPLY[$idx]=$pval 1152 | idx=$(($idx+1)) 1153 | fi 1154 | done 1155 | return 0 1156 | ;; 1157 | esac 1158 | COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- $cur ) ) 1159 | return 0 1160 | } 1161 | complete -F _postsuper postsuper 1162 | } 1163 | 1164 | # cvs(1) completion 1165 | # 1166 | have cvs && { 1167 | set_prefix() 1168 | { 1169 | [ -z ${prefix:-} ] || prefix=${cur%/*}/ 1170 | [ -r ${prefix:-}CVS/Entries ] || prefix="" 1171 | } 1172 | 1173 | get_entries() 1174 | { 1175 | [ -r ${prefix:-}CVS/Entries ] && \ 1176 | entries=( $( compgen -W \ 1177 | "$( echo $( cut -d/ -f2 -s ${prefix:-}CVS/Entries ) )" -- $cur ) ) 1178 | } 1179 | 1180 | get_modules() 1181 | { 1182 | if [ -n "$prefix" ]; then 1183 | COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) ) 1184 | else 1185 | COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) ) 1186 | fi 1187 | } 1188 | 1189 | _cvs() 1190 | { 1191 | local cur count mode i cvsroot cvsroots pwd 1192 | local -a flags miss files entries changed newremoved 1193 | 1194 | COMPREPLY=() 1195 | cur=${COMP_WORDS[COMP_CWORD]} 1196 | 1197 | count=0 1198 | for i in ${COMP_WORDS[@]}; do 1199 | [ $count -eq $COMP_CWORD ] && break 1200 | # Last parameter was the CVSROOT, now go back to mode selection 1201 | if [ "${COMP_WORDS[((count))]}" == "$cvsroot" -a "$mode" == "cvsroot" ]; then 1202 | mode="" 1203 | fi 1204 | if [ -z "$mode" ]; then 1205 | case $i in 1206 | -d) 1207 | mode=cvsroot 1208 | cvsroot=${COMP_WORDS[((count+1))]} 1209 | ;; 1210 | @(add|new)) 1211 | mode=add 1212 | ;; 1213 | @(admin|rcs)) 1214 | mode=admin 1215 | ;; 1216 | @(checkout|co|get)) 1217 | mode=checkout 1218 | ;; 1219 | @(commit|ci)) 1220 | mode=commit 1221 | ;; 1222 | @(ex?(p?(ort)))) 1223 | mode=export 1224 | ;; 1225 | @(annotate|diff|history|import|release|status|update|?(un)edit)) 1226 | mode=$i 1227 | ;; 1228 | ?(r)log) 1229 | mode=log 1230 | ;; 1231 | @(rdiff|patch)) 1232 | mode=rdiff 1233 | ;; 1234 | @(remove|rm|delete)) 1235 | mode=remove 1236 | ;; 1237 | @(rtag|rfreeze)) 1238 | mode=rtag 1239 | ;; 1240 | @(tag|freeze)) 1241 | mode=tag 1242 | ;; 1243 | *) 1244 | ;; 1245 | esac 1246 | elif [[ "$i" = -* ]]; then 1247 | flags=( ${flags[@]:-} $i ) 1248 | fi 1249 | count=$((++count)) 1250 | done 1251 | 1252 | case "$mode" in 1253 | add) 1254 | if [[ "$cur" != -* ]]; then 1255 | set_prefix 1256 | if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then 1257 | get_entries 1258 | [ -z "$cur" ] && \ 1259 | files=$( command ls -Ad !(CVS) ) || \ 1260 | files=$( command ls -d ${cur}* 2>/dev/null ) 1261 | for i in ${entries[@]:-}; do 1262 | files=( ${files[@]/#$i//} ) 1263 | done 1264 | COMPREPLY=( $( compgen -W '${files[@]}' -- \ 1265 | $cur ) ) 1266 | fi 1267 | else 1268 | COMPREPLY=( $( compgen -W '-k -m' -- $cur ) ) 1269 | fi 1270 | ;; 1271 | admin) 1272 | if [[ "$cur" = -* ]]; then 1273 | COMPREPLY=( $( compgen -W '-i -a -A -e -b -c -k -l -u \ 1274 | -L -U -m -M -n -N -o -q -I \ 1275 | -s -t -t- -T -V -x -z' -- \ 1276 | $cur ) ) 1277 | fi 1278 | ;; 1279 | checkout) 1280 | if [[ "$cur" != -* ]]; then 1281 | [ -z "$cvsroot" ] && cvsroot=$CVSROOT 1282 | COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) ) 1283 | COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) ) 1284 | else 1285 | COMPREPLY=( $( compgen -W '-A -N -P -R -c -f -l -n -p \ 1286 | -s -r -D -d -k -j' -- $cur ) ) 1287 | fi 1288 | ;; 1289 | commit) 1290 | set_prefix 1291 | 1292 | if [[ "$cur" != -* ]] && [ -r ${prefix:-}CVS/Entries ]; then 1293 | # if $COMP_CVS_REMOTE is not null, 'cvs commit' will 1294 | # complete on remotely checked-out files (requires 1295 | # passwordless access to the remote repository 1296 | if [ -n "${COMP_CVS_REMOTE:-}" ]; then 1297 | # this is the least computationally intensive 1298 | # way found so far, but other changes 1299 | # (something other than changed/removed/new) 1300 | # may be missing 1301 | changed=( $( cvs diff --brief 2>&1 | \ 1302 | sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) ) 1303 | newremoved=( $( cvs diff --brief 2>&1 | \ 1304 | sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) ) 1305 | COMPREPLY=( $( compgen -W '${changed[@]:-} \ 1306 | ${newremoved[@]:-}' -- $cur ) ) 1307 | else 1308 | COMPREPLY=( $( compgen -f -- $cur ) ) 1309 | fi 1310 | else 1311 | COMPREPLY=( $( compgen -W '-n -R -l -f -F -m -r' -- \ 1312 | $cur ) ) 1313 | fi 1314 | ;; 1315 | cvsroot) 1316 | if [ -r ~/.cvspass ]; then 1317 | # Ugly escaping because of bash treating ':' specially 1318 | cvsroots=$( sed 's/^[^ ]* //; s/:/\\:/g' ~/.cvspass ) 1319 | COMPREPLY=( $( compgen -W '$cvsroots' -- $cur ) ) 1320 | fi 1321 | ;; 1322 | export) 1323 | if [[ "$cur" != -* ]]; then 1324 | [ -z "$cvsroot" ] && cvsroot=$CVSROOT 1325 | COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) ) 1326 | COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) ) 1327 | else 1328 | COMPREPLY=( $( compgen -W '-N -f -l -R -n \ 1329 | -r -D -d -k' -- $cur ) ) 1330 | fi 1331 | ;; 1332 | diff) 1333 | if [[ "$cur" == -* ]]; then 1334 | _longopt diff 1335 | else 1336 | get_entries 1337 | COMPREPLY=( ${entries[@]:-} ) 1338 | fi 1339 | ;; 1340 | remove) 1341 | if [[ "$cur" != -* ]]; then 1342 | set_prefix 1343 | if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then 1344 | get_entries 1345 | # find out what files are missing 1346 | for i in ${entries[@]}; do 1347 | [ ! -r "$i" ] && miss=( ${miss[@]:-} $i ) 1348 | done 1349 | COMPREPLY=( $(compgen -W '${miss[@]:-}' -- $cur) ) 1350 | fi 1351 | else 1352 | COMPREPLY=( $( compgen -W '-f -l -R' -- $cur ) ) 1353 | fi 1354 | ;; 1355 | import) 1356 | if [[ "$cur" != -* ]]; then 1357 | # starts with same algorithm as checkout 1358 | [ -z "$cvsroot" ] && cvsroot=$CVSROOT 1359 | prefix=${cur%/*} 1360 | if [ -r ${cvsroot}/${prefix} ]; then 1361 | get_modules 1362 | COMPREPLY=( ${COMPREPLY[@]#$cvsroot} ) 1363 | COMPREPLY=( ${COMPREPLY[@]#\/} ) 1364 | fi 1365 | pwd=$( pwd ) 1366 | pwd=${pwd##*/} 1367 | COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- \ 1368 | $cur ) ) 1369 | else 1370 | COMPREPLY=( $( compgen -W '-d -k -I -b -m -W' -- $cur )) 1371 | fi 1372 | ;; 1373 | "") 1374 | COMPREPLY=( $( compgen -W 'add admin annotate checkout ci co \ 1375 | commit diff delete edit export \ 1376 | freeze get history import log new \ 1377 | patch rcs rdiff release remove \ 1378 | rfreeze rlog rm rtag status tag \ 1379 | unedit update -H -Q -q -b -d -e -f \ 1380 | -l -n -t -r -v -w -x -z --help \ 1381 | --version' -- $cur ) ) 1382 | ;; 1383 | *) 1384 | ;; 1385 | esac 1386 | 1387 | return 0 1388 | } 1389 | complete -F _cvs $default cvs 1390 | } 1391 | 1392 | have rpm && { 1393 | # helper functions for rpm completion 1394 | # 1395 | _rpm_installed_packages() 1396 | { 1397 | local i 1398 | 1399 | if [ -r /var/log/rpmpkgs -a \ 1400 | /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]; then 1401 | # using RHL 7.2 or later - this is quicker than querying the DB 1402 | COMPREPLY=( $( sed -ne \ 1403 | 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+.*\.rpm$|\1|p' \ 1404 | /var/log/rpmpkgs ) ) 1405 | else 1406 | COMPREPLY=( $( rpm -qa $options | sed -ne \ 1407 | 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+$|\1|p' ) ) 1408 | fi 1409 | } 1410 | 1411 | _rpm_groups() 1412 | { 1413 | local IFS=$'\t' 1414 | # remove trailing backslash, or grep will complain 1415 | cur=${cur%"\\"} 1416 | COMPREPLY=( $( rpm -qa $options --queryformat '%{group}\n' | \ 1417 | grep "^$cur" ) ) 1418 | # backslash escape spaces and translate newlines to tabs 1419 | COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) ) 1420 | } 1421 | 1422 | # rpm(8) completion 1423 | # 1424 | _rpm() 1425 | { 1426 | local cur prev ver options 1427 | 1428 | COMPREPLY=() 1429 | cur=${COMP_WORDS[COMP_CWORD]} 1430 | prev=${COMP_WORDS[COMP_CWORD-1]} 1431 | options="" 1432 | ver=$(rpm --version); ver=${ver##* } 1433 | 1434 | if [[ "$ver" > "4.0.4" ]]; then 1435 | options="--nodigest" 1436 | fi 1437 | if [[ "$ver" > "4.0.99" ]]; then 1438 | options="$options --nosignature" 1439 | fi 1440 | 1441 | if [ $COMP_CWORD -eq 1 ]; then 1442 | # first parameter on line 1443 | case "$cur" in 1444 | -b*) 1445 | COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs'\ 1446 | -- $cur ) ) 1447 | ;; 1448 | -t*) 1449 | COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts'\ 1450 | -- $cur ) ) 1451 | ;; 1452 | --*) 1453 | COMPREPLY=( $( compgen -W '--help --version --initdb \ 1454 | --checksig --recompile --rebuild --resign --addsign \ 1455 | --rebuilddb --showrc --setperms --setugids --tarbuild \ 1456 | --eval --install --upgrade --query --freshen --erase \ 1457 | --verify --querytags --rmsource --rmspec --clean \ 1458 | --import' -- $cur ) ) 1459 | ;; 1460 | *) 1461 | COMPREPLY=( $( compgen -W '-b -e -F -i -q -t -U -V' \ 1462 | -- $cur ) ) 1463 | ;; 1464 | esac 1465 | 1466 | return 0 1467 | fi 1468 | 1469 | case "$prev" in 1470 | --@(@(db|exclude)path|prefix|relocate|root)) 1471 | _filedir -d 1472 | return 0 1473 | ;; 1474 | --eval) 1475 | # get a list of macros 1476 | COMPREPLY=( $( sed -ne 's|^\(%'${cur#\%}'[^ '$'\t'']*\).*$|\1|p' \ 1477 | /usr/lib/rpm/macros ) ) 1478 | return 0 1479 | ;; 1480 | --pipe) 1481 | COMPREPLY=( $( compgen -c -- $cur ) ) 1482 | return 0 1483 | ;; 1484 | --rcfile) 1485 | _filedir 1486 | return 0 1487 | ;; 1488 | --specfile) 1489 | # complete on .spec files 1490 | _filedir spec 1491 | return 0 1492 | ;; 1493 | --whatprovides) 1494 | if [[ "$cur" == */* ]]; then 1495 | _filedir 1496 | else 1497 | # complete on capabilities 1498 | COMPREPLY=( $( rpm -qa $options --queryformat \ 1499 | '%{providename}\n' | grep "^$cur" ) ) 1500 | fi 1501 | return 0 1502 | ;; 1503 | --whatrequires) 1504 | # complete on capabilities 1505 | COMPREPLY=( $( rpm -qa $options --queryformat \ 1506 | '%{requirename}\n' | grep "^$cur" ) ) 1507 | return 0 1508 | ;; 1509 | esac 1510 | 1511 | case "${COMP_WORDS[1]}" in 1512 | -@([iFU]*|-install|-freshen|-upgrade)) 1513 | if [[ "$cur" == -* ]]; then 1514 | COMPREPLY=( $( compgen -W '--percent --force --test \ 1515 | --replacepkgs --replacefiles --root --excludedocs \ 1516 | --includedocs --noscripts --rcfile --ignorearch \ 1517 | --dbpath --prefix --ignoreos --nodeps --allfiles \ 1518 | --ftpproxy --ftpport --justdb --httpproxy --httpport \ 1519 | --noorder --relocate --badreloc --notriggers \ 1520 | --excludepath --ignoresize --oldpackage --define \ 1521 | --eval --pipe --queryformat --repackage --nosuggests \ 1522 | --nodigest --nosignature' -- $cur ) ) 1523 | else 1524 | _filedir 'rpm' 1525 | fi 1526 | ;; 1527 | -@(e|-erase)) 1528 | if [[ "$cur" == -* ]]; then 1529 | COMPREPLY=( $( compgen -W '--allmatches --noscripts \ 1530 | --notriggers --nodeps --test --repackage' -- $cur ) ) 1531 | else 1532 | _rpm_installed_packages 1533 | fi 1534 | ;; 1535 | -@(q*|-query)) 1536 | # check whether we're doing file completion 1537 | if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then 1538 | _filedir 1539 | elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then 1540 | _rpm_groups 1541 | elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then 1542 | # uninstalled package completion 1543 | if [[ "$cur" == -* ]]; then 1544 | COMPREPLY=( $( compgen -W '--scripts --root \ 1545 | --rcfile --whatprovides --whatrequires \ 1546 | --requires --triggeredby --ftpport --ftpproxy \ 1547 | --httpproxy --httpport --provides --triggers \ 1548 | --dump --changelog --dbpath --filesbypkg \ 1549 | --define --eval --pipe --showrc --info --list \ 1550 | --state --docfiles --configfiles --queryformat\ 1551 | --conflicts --obsoletes --nodigest \ 1552 | --nosignature' -- $cur ) ) 1553 | else 1554 | _filedir 'rpm' 1555 | fi 1556 | else 1557 | # installed package completion 1558 | if [[ "$cur" == -* ]]; then 1559 | COMPREPLY=( $( compgen -W '--scripts --root \ 1560 | --rcfile --whatprovides --whatrequires \ 1561 | --requires --triggeredby --ftpport --ftpproxy \ 1562 | --httpproxy --httpport --provides --triggers \ 1563 | --dump --changelog --dbpath --specfile \ 1564 | --querybynumber --last --filesbypkg --define \ 1565 | --eval --pipe --showrc --info --list --state \ 1566 | --docfiles --configfiles --queryformat \ 1567 | --conflicts --obsoletes --pkgid --hdrid \ 1568 | --fileid --tid --nodigest --nosignature \ 1569 | --triggerscripts' -- $cur ) ) 1570 | elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then 1571 | _rpm_installed_packages 1572 | fi 1573 | fi 1574 | ;; 1575 | -@(K*|-checksig)) 1576 | if [[ "$cur" == -* ]]; then 1577 | COMPREPLY=( $( compgen -W '--nopgp --nogpg --nomd5 \ 1578 | --nodigest --nosignature' -- $cur ) ) 1579 | else 1580 | _filedir 'rpm' 1581 | fi 1582 | ;; 1583 | -@([Vy]*|-verify)) 1584 | if [[ "$cur" == -* ]]; then 1585 | COMPREPLY=( $( compgen -W '--root --rcfile --dbpath \ 1586 | --nodeps --nogroup --nolinkto --nomode --nomtime \ 1587 | --nordev --nouser --nofiles --noscripts --nomd5 \ 1588 | --querytags --specfile --whatrequires --whatprovides \ 1589 | --nodigest --nosignature' -- $cur ) ) 1590 | # check whether we're doing file completion 1591 | elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then 1592 | _filedir 1593 | elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then 1594 | _rpm_groups 1595 | elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then 1596 | _filedir 'rpm' 1597 | else 1598 | _rpm_installed_packages 1599 | fi 1600 | ;; 1601 | -[bt]*) 1602 | if [[ "$cur" == -* ]]; then 1603 | COMPREPLY=( $( compgen -W '--short-circuit --timecheck \ 1604 | --clean --rmsource --rmspec --test --sign --buildroot \ 1605 | --target -- buildarch --buildos --nobuild --nodeps \ 1606 | --nodirtokens' -- $cur ) ) 1607 | elif [[ ${COMP_WORDS[1]} == -b* ]]; then 1608 | _filedir 'spec' 1609 | else 1610 | _filedir '@(tgz|tar.@(gz|bz2))' 1611 | fi 1612 | ;; 1613 | --re@(build|compile)) 1614 | if [[ "$cur" == -* ]]; then 1615 | COMPREPLY=( $( compgen -W '--nodeps --rmsource \ 1616 | --rmspec --sign --nodirtokens --target' -- $cur ) ) 1617 | else 1618 | _filedir '?(no)src.rpm' 1619 | fi 1620 | ;; 1621 | --tarbuild) 1622 | _filedir '@(tgz|tar.@(gz|bz2))' 1623 | ;; 1624 | --@(re|add)sign) 1625 | _filedir 'rpm' 1626 | ;; 1627 | --set@(perms|gids)) 1628 | _rpm_installed_packages 1629 | ;; 1630 | --@(clean|rms@(ource|pec))) 1631 | if [[ "$cur" == -* ]]; then 1632 | COMPREPLY=( $( compgen -W '--clean --rmsource \ 1633 | --rmspec' -- $cur ) ) 1634 | else 1635 | _filedir 'spec' 1636 | fi 1637 | ;; 1638 | --@(import|dbpath|root)) 1639 | if [[ "$cur" == -* ]]; then 1640 | COMPREPLY=( $( compgen -W '--import --dbpath --root' \ 1641 | -- $cur ) ) 1642 | else 1643 | _filedir 1644 | fi 1645 | ;; 1646 | esac 1647 | 1648 | return 0 1649 | } 1650 | complete -F _rpm $filenames rpm rpmbuild 1651 | } 1652 | 1653 | # Debian apt-get(8) completion. 1654 | # 1655 | have apt-get && 1656 | _apt_get() 1657 | { 1658 | local cur prev special i 1659 | 1660 | COMPREPLY=() 1661 | cur=${COMP_WORDS[COMP_CWORD]} 1662 | prev=${COMP_WORDS[COMP_CWORD-1]} 1663 | 1664 | for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do 1665 | if [[ ${COMP_WORDS[i]} == @(install|remove|source|build-dep) ]]; then 1666 | special=${COMP_WORDS[i]} 1667 | fi 1668 | done 1669 | 1670 | if [ -n "$special" ]; then 1671 | case $special in 1672 | remove) 1673 | if [ -f /etc/debian_version ]; then 1674 | # Debian system 1675 | COMPREPLY=( $( _comp-dpkg-installed-packages \ 1676 | $cur ) ) 1677 | else 1678 | # assume RPM based 1679 | _rpm_installed_packages 1680 | fi 1681 | return 0 1682 | ;; 1683 | *) 1684 | COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) 1685 | return 0 1686 | ;; 1687 | 1688 | esac 1689 | fi 1690 | 1691 | case "$prev" in 1692 | -@(c|-config-file)) 1693 | _filedir 1694 | return 0 1695 | ;; 1696 | 1697 | -@(t|-target-release|-default-release)) 1698 | COMPREPLY=( $( apt-cache policy | \ 1699 | grep "release.o=Debian,a=$cur" | \ 1700 | sed -e "s/.*a=\(\w*\).*/\1/" | uniq ) ) 1701 | return 0 1702 | ;; 1703 | 1704 | esac 1705 | 1706 | if [[ "$cur" == -* ]]; then 1707 | 1708 | COMPREPLY=( $( compgen -W '-d -f -h -v -m -q -s -y \ 1709 | -u -t -b -c -o --download-only --fix-broken \ 1710 | --help --version --ignore-missing \ 1711 | --fix-missing --no-download --quiet --simulate \ 1712 | --just-print --dry-run --recon --no-act --yes \ 1713 | --assume-yes --show-upgraded --only-source \ 1714 | --compile --build --ignore-hold \ 1715 | --target-release --no-upgrade --force-yes \ 1716 | --print-uris --purge --reinstall \ 1717 | --list-cleanup --default-release \ 1718 | --trivial-only --no-remove --diff-only \ 1719 | --tar-only --config-file --option' -- $cur ) ) 1720 | else 1721 | 1722 | COMPREPLY=( $( compgen -W 'update upgrade dselect-upgrade \ 1723 | dist-upgrade install remove source build-dep \ 1724 | check clean autoclean' -- $cur ) ) 1725 | 1726 | fi 1727 | 1728 | 1729 | return 0 1730 | } 1731 | [ -n "${have:-}" ] && complete -F _apt_get $filenames apt-get 1732 | 1733 | # Debian apt-cache(8) completion. 1734 | # 1735 | have apt-cache && 1736 | _apt_cache() 1737 | { 1738 | local cur prev special i 1739 | 1740 | COMPREPLY=() 1741 | cur=${COMP_WORDS[COMP_CWORD]} 1742 | prev=${COMP_WORDS[COMP_CWORD-1]} 1743 | 1744 | 1745 | if [ "$cur" != show ]; then 1746 | for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do 1747 | if [[ ${COMP_WORDS[i]} == @(add|depends|dotty|policy|show?(pkg|src)) ]]; then 1748 | special=${COMP_WORDS[i]} 1749 | fi 1750 | done 1751 | fi 1752 | 1753 | 1754 | if [ -n "$special" ]; then 1755 | case $special in 1756 | add) 1757 | _filedir 1758 | return 0 1759 | ;; 1760 | 1761 | *) 1762 | COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) 1763 | return 0 1764 | ;; 1765 | 1766 | esac 1767 | fi 1768 | 1769 | 1770 | case "$prev" in 1771 | -@(c|p|s|-config-file|-@(pkg|src)-cache)) 1772 | _filedir 1773 | return 0 1774 | ;; 1775 | search) 1776 | if [[ "$cur" != -* ]]; then 1777 | return 0 1778 | fi 1779 | ;; 1780 | esac 1781 | 1782 | if [[ "$cur" == -* ]]; then 1783 | 1784 | COMPREPLY=( $( compgen -W '-h -v -p -s -q -i -f -a -g -c \ 1785 | -o --help --version --pkg-cache --src-cache \ 1786 | --quiet --important --full --all-versions \ 1787 | --generate --no-generate --names-only \ 1788 | --all-names --config-file --option \ 1789 | --recurse' -- $cur ) ) 1790 | else 1791 | 1792 | COMPREPLY=( $( compgen -W 'add gencaches showpkg show stats \ 1793 | dumpavail unmet check search dump dotty policy \ 1794 | depends pkgnames showsrc' -- $cur ) ) 1795 | 1796 | fi 1797 | 1798 | 1799 | return 0 1800 | } 1801 | [ -n "${have:-}" ] && complete -F _apt_cache $filenames apt-cache 1802 | 1803 | 1804 | # Debian aptitude(1) completion 1805 | # 1806 | have aptitude && { 1807 | _comp-dpkg-hold-packages() 1808 | { 1809 | grep -B 2 'hold' /var/lib/dpkg/status | grep "Package: $1" \ 1810 | | cut -d\ -f2 1811 | } 1812 | 1813 | _aptitude() 1814 | { 1815 | local cur dashoptions prev special i 1816 | 1817 | COMPREPLY=() 1818 | cur=${COMP_WORDS[COMP_CWORD]} 1819 | prev=${COMP_WORDS[COMP_CWORD-1]} 1820 | 1821 | 1822 | dashoptions='-S -u -i -h --help --version -s --simulate -d \ 1823 | --download-only -P --prompt -y --assume-yes -F \ 1824 | --display-format -w --width -f --with-recommends \ 1825 | --with-suggests --without-recommends --without-suggests' 1826 | 1827 | for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do 1828 | if [[ ${COMP_WORDS[i]} == @(install|hold|unhold|markauto|unmarkauto|dist-upgrade|download|purge|remove) ]]; then 1829 | special=${COMP_WORDS[i]} 1830 | fi 1831 | #exclude some mutually exclusive options 1832 | [[ ${COMP_WORDS[i]} == '-u' ]] && dashoptions=${dashoptions/-i} 1833 | [[ ${COMP_WORDS[i]} == '-i' ]] && dashoptions=${dashoptions/-u} 1834 | done 1835 | 1836 | if [[ -n "$special" ]]; then 1837 | case $special in 1838 | @(install|hold|markauto|unmarkauto|dist-upgrade|download)) 1839 | COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) 1840 | return 0 1841 | ;; 1842 | @(purge|remove)) 1843 | COMPREPLY=( $( _comp-dpkg-installed-packages $cur ) ) 1844 | return 0 1845 | ;; 1846 | unhold) 1847 | COMPREPLY=( $( _comp-dpkg-hold-packages $cur ) ) 1848 | return 0 1849 | ;; 1850 | 1851 | esac 1852 | fi 1853 | 1854 | case $prev in 1855 | # don't complete anything if these options are found 1856 | @(autoclean|clean|forget-new|search|upgrade|update)) 1857 | return 0 1858 | ;; 1859 | -S) 1860 | _filedir 1861 | return 0 1862 | ;; 1863 | esac 1864 | 1865 | if [[ "$cur" == -* ]]; then 1866 | COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) ) 1867 | else 1868 | COMPREPLY=( $( compgen -W 'update upgrade forget-new clean \ 1869 | autoclean install remove hold unhold \ 1870 | purge markauto unmarkauto dist-upgrade \ 1871 | download search' -- $cur ) ) 1872 | fi 1873 | 1874 | 1875 | return 0 1876 | } 1877 | [ -n "${have:-}" ] && complete -F _aptitude $default aptitude 1878 | } 1879 | 1880 | # Debian apt-build(1) completion. 1881 | # 1882 | have apt-build && 1883 | _apt_build() 1884 | { 1885 | local cur prev special i 1886 | 1887 | COMPREPLY=() 1888 | cur=${COMP_WORDS[COMP_CWORD]} 1889 | prev=${COMP_WORDS[COMP_CWORD-1]} 1890 | 1891 | for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do 1892 | if [[ ${COMP_WORDS[i]} == @(install|remove|source|info|clean) ]]; then 1893 | special=${COMP_WORDS[i]} 1894 | fi 1895 | done 1896 | 1897 | if [ -n "$special" ]; then 1898 | case $special in 1899 | @(install|source|info)) 1900 | COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) 1901 | return 0 1902 | ;; 1903 | remove) 1904 | COMPREPLY=( $( _comp-dpkg-installed-packages \ 1905 | $cur ) ) 1906 | return 0 1907 | ;; 1908 | *) 1909 | return 0 1910 | ;; 1911 | esac 1912 | fi 1913 | 1914 | case "$prev" in 1915 | 1916 | --@(patch|build-dir|repository-dir)) 1917 | _filedir 1918 | return 0 1919 | ;; 1920 | 1921 | -@(h|-help)) 1922 | return 0 1923 | ;; 1924 | 1925 | esac 1926 | 1927 | if [[ "$cur" == -* ]]; then 1928 | COMPREPLY=( $( compgen -W '--help --show-upgraded -u --build-dir \ 1929 | --repository-dir --build-only \ 1930 | --build-command --reinstall --rebuild \ 1931 | --remove-builddep --no-wrapper --purge \ 1932 | --patch --patch-strip -p --yes -y \ 1933 | --version -v --no-source' -- $cur ) ) 1934 | 1935 | else 1936 | COMPREPLY=( $( compgen -W 'update upgrade install remove \ 1937 | source dist-upgrade world clean info \ 1938 | clean-build update-repository ' -- $cur ) ) 1939 | fi 1940 | 1941 | 1942 | return 0 1943 | } 1944 | [ -n "${have:-}" ] && complete -F _apt_build $filenames apt-build 1945 | 1946 | # chsh(1) completion 1947 | # 1948 | _chsh() 1949 | { 1950 | local cur prev 1951 | 1952 | COMPREPLY=() 1953 | cur=${COMP_WORDS[COMP_CWORD]} 1954 | prev=${COMP_WORDS[COMP_CWORD-1]} 1955 | 1956 | if [ "$prev" = "-s" ]; then 1957 | COMPREPLY=( $( chsh -l | grep "^$cur" ) ) 1958 | else 1959 | COMPREPLY=( $( compgen -u -- $cur ) ) 1960 | fi 1961 | 1962 | return 0 1963 | } 1964 | complete -F _chsh chsh 1965 | 1966 | # chkconfig(8) completion 1967 | # 1968 | have chkconfig && 1969 | _chkconfig() 1970 | { 1971 | local cur prev 1972 | 1973 | COMPREPLY=() 1974 | cur=${COMP_WORDS[COMP_CWORD]} 1975 | prev=${COMP_WORDS[COMP_CWORD-1]} 1976 | 1977 | if [ $COMP_CWORD -eq 1 ]; then 1978 | COMPREPLY=( $( compgen -W '--list --add --del --level' -- \ 1979 | $cur ) ) 1980 | return 0 1981 | fi 1982 | 1983 | if [ $COMP_CWORD -eq 4 ]; then 1984 | COMPREPLY=( $( compgen -W 'on off reset' -- $cur ) ) 1985 | return 0 1986 | fi 1987 | 1988 | case "$prev" in 1989 | @([1-6]|--@(list|add|del))) 1990 | COMPREPLY=( $( compgen -W "`(cd /etc/rc.d/init.d; echo *)`" \ 1991 | -- $cur) ) 1992 | return 0 1993 | ;; 1994 | --level) 1995 | COMPREPLY=( $( compgen -W '1 2 3 4 5 6' -- $cur ) ) 1996 | return 0 1997 | ;; 1998 | esac 1999 | 2000 | return 0 2001 | } 2002 | [ -n "${have:-}" ] && complete -F _chkconfig chkconfig 2003 | 2004 | # This function provides simple user@host completion 2005 | # 2006 | _user_at_host() { 2007 | local cur 2008 | 2009 | COMPREPLY=() 2010 | cur=${COMP_WORDS[COMP_CWORD]} 2011 | 2012 | if [[ $cur == *@* ]]; then 2013 | _known_hosts 2014 | else 2015 | COMPREPLY=( $( compgen -S '@' -u -- "$cur" ) ) 2016 | fi 2017 | 2018 | return 0 2019 | } 2020 | shopt -u hostcomplete && complete -F _user_at_host $nospace talk ytalk finger 2021 | 2022 | # This function performs host completion based on ssh's known_hosts files, 2023 | # defaulting to standard host completion if they don't exist. 2024 | # 2025 | _known_hosts() 2026 | { 2027 | local cur ocur user suffix aliases global_kh user_kh hosts 2028 | local -a kh config 2029 | 2030 | COMPREPLY=() 2031 | cur=${COMP_WORDS[COMP_CWORD]} 2032 | ocur=$cur 2033 | 2034 | [ "$1" = -a ] || [ "$2" = -a ] && aliases='yes' 2035 | [ "$1" = -c ] || [ "$2" = -c ] && suffix=':' 2036 | [[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@} 2037 | kh=() 2038 | 2039 | # ssh config files 2040 | [ -r /etc/ssh/ssh_config ] && config[0]=/etc/ssh/ssh_config 2041 | [ -r ~/.ssh/config ] && config[1]=~/.ssh/config 2042 | 2043 | if [ ${#config[@]} -gt 0 ]; then 2044 | # expand path (if present) to global known hosts file 2045 | global_kh=$( eval echo $( sed -ne 's/^[Gg][Ll][Oo][Bb][Aa][Ll][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['$'\t '']*\(.*\)$/\1/p' ${config[@]} ) ) 2046 | # expand path (if present) to user known hosts file 2047 | user_kh=$( eval echo $( sed -ne 's/^[Uu][Ss][Ee][Rr][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['$'\t '']*\(.*\)$/\1/p' ${config[@]} ) ) 2048 | fi 2049 | 2050 | # choose which global known hosts file to use 2051 | if [ -r "$global_kh" ]; then 2052 | kh=( "$global_kh" ) 2053 | else 2054 | [ -r /etc/ssh/ssh_known_hosts ] && kh[0]=/etc/ssh/ssh_known_hosts 2055 | [ -r /etc/ssh/ssh_known_hosts2 ] && kh[1]=/etc/ssh/ssh_known_hosts2 2056 | [ -r /etc/known_hosts ] && kh[2]=/etc/known_hosts 2057 | [ -r /etc/known_hosts2 ] && kh[3]=/etc/known_hosts2 2058 | fi 2059 | 2060 | # choose which user known hosts file to use 2061 | if [ -r "$user_kh" ]; then 2062 | kh=( ${kh[@]} "$user_kh" ) 2063 | else 2064 | [ -r ~/.ssh/known_hosts ] && kh=( ${kh[@]} ~/.ssh/known_hosts ) 2065 | [ -r ~/.ssh/known_hosts2 ] && kh=( ${kh[@]} ~/.ssh/known_hosts2 ) 2066 | fi 2067 | 2068 | # If we have known_hosts files to use 2069 | if [ ${#kh[@]} -gt 0 ]; then 2070 | # Escape slashes and dots in paths for awk 2071 | cur=${cur//\//\\\/} 2072 | cur=${cur//\./\\\.} 2073 | 2074 | if [[ "$cur" == [0-9]*.* ]]; then 2075 | # Digits followed by a dot - just search for that 2076 | cur="^$cur.*" 2077 | elif [[ "$cur" == [0-9]* ]]; then 2078 | # Digits followed by no dot - search for digits followed 2079 | # by a dot 2080 | cur="^$cur.*\." 2081 | elif [ -z "$cur" ]; then 2082 | # A blank - search for a dot or an alpha character 2083 | cur="[a-z.]" 2084 | else 2085 | cur="^$cur" 2086 | fi 2087 | 2088 | # FS needs to look for a comma separated list 2089 | COMPREPLY=( $( awk 'BEGIN {FS=","} 2090 | {for (i=1; i<=2; ++i) { \ 2091 | gsub(" .*$", "", $i); \ 2092 | if ($i ~ /'$cur'/) {print $i} \ 2093 | }}' ${kh[@]} 2>/dev/null ) ) 2094 | 2095 | # append any available aliases from config files 2096 | if [ ${#config[@]} -gt 0 ] && [ -n "$aliases" ]; then 2097 | hosts=$( compgen -W "$( echo $( sed -ne "s/^[Hh][Oo][Ss][Tt]["$'\t '"]*\([^*?]*\)$/\1/p" ${config[@]} ) )" -- $ocur ) 2098 | COMPREPLY=( ${COMPREPLY[@]} $hosts ) 2099 | fi 2100 | 2101 | # apply suffix 2102 | for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do 2103 | COMPREPLY[i]=$user${COMPREPLY[i]}$suffix 2104 | done 2105 | else 2106 | # Just do normal hostname completion 2107 | COMPREPLY=( $( compgen -A hostname -S "$suffix" -- $cur ) ) 2108 | fi 2109 | 2110 | return 0 2111 | } 2112 | complete -F _known_hosts traceroute traceroute6 tracepath tracepath6 \ 2113 | ping fping telnet host nslookup rsh rlogin ftp dig 2114 | 2115 | # ssh(1) completion 2116 | # 2117 | have ssh && { 2118 | _ssh() 2119 | { 2120 | local cur prev 2121 | local -a config 2122 | 2123 | COMPREPLY=() 2124 | cur=${COMP_WORDS[COMP_CWORD]} 2125 | prev=${COMP_WORDS[COMP_CWORD-1]} 2126 | 2127 | case "$prev" in 2128 | -*c) 2129 | COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \ 2130 | arcfour cast128-cbc' -- $cur ) ) 2131 | ;; 2132 | -*i) 2133 | _filedir 2134 | ;; 2135 | -*l) 2136 | COMPREPLY=( $( compgen -u -- $cur ) ) 2137 | ;; 2138 | *) 2139 | _known_hosts -a 2140 | 2141 | [ $COMP_CWORD -eq 1 ] || \ 2142 | COMPREPLY=( ${COMPREPLY[@]} $( compgen -c -- $cur ) ) 2143 | esac 2144 | 2145 | return 0 2146 | } 2147 | shopt -u hostcomplete && complete -F _ssh ssh slogin sftp xhost 2148 | 2149 | # scp(1) completion 2150 | # 2151 | _scp() 2152 | { 2153 | local cur userhost path 2154 | 2155 | local IFS=$'\t\n' 2156 | COMPREPLY=() 2157 | cur=${COMP_WORDS[COMP_CWORD]} 2158 | 2159 | _expand || return 0 2160 | 2161 | if [[ "$cur" == *:* ]]; then 2162 | # remove backslash escape from : 2163 | cur=${cur/\\:/:} 2164 | userhost=${cur%%?(\\):*} 2165 | path=${cur#*:} 2166 | # unescape spaces 2167 | path=${path//\\\\\\\\ / } 2168 | if [ -z "$path" ]; then 2169 | # default to home dir of specified user on remote host 2170 | path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null) 2171 | fi 2172 | # escape spaces; remove executables, aliases, pipes and sockets; 2173 | # add space at end of file names 2174 | COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \ 2175 | command ls -aF1d "$path*" 2>/dev/null | \ 2176 | sed -e 's/ /\\\\\\\ /g' -e 's/[*@|=]$//g' \ 2177 | -e 's/[^\/]$/& /g' ) ) 2178 | return 0 2179 | fi 2180 | 2181 | [[ "$cur" == */* ]] || _known_hosts -c -a 2182 | COMPREPLY=( ${COMPREPLY[@]} $( command ls -aF1d $cur* \ 2183 | 2>/dev/null | sed -e 's/ /\\ /g' -e 's/[*@|=]$//g'\ 2184 | -e 's/[^\/]$/& /g' ) ) 2185 | 2186 | 2187 | 2188 | return 0 2189 | } 2190 | complete -F _scp $nospace scp 2191 | } 2192 | 2193 | # rsync(1) completion 2194 | # 2195 | have rsync && 2196 | _rsync() 2197 | { 2198 | local cur prev shell i userhost path 2199 | 2200 | COMPREPLY=() 2201 | cur=${COMP_WORDS[COMP_CWORD]} 2202 | prev=${COMP_WORDS[COMP_CWORD-1]} 2203 | 2204 | _expand || return 0 2205 | 2206 | case "$prev" in 2207 | --@(config|password-file|include-from|exclude-from)) 2208 | _filedir 2209 | return 0 2210 | ;; 2211 | -@(T|-temp-dir|-compare-dest)) 2212 | _filedir -d 2213 | return 0 2214 | ;; 2215 | -@(e|-rsh)) 2216 | COMPREPLY=( $( compgen -W 'rsh ssh' -- $cur ) ) 2217 | return 0 2218 | ;; 2219 | esac 2220 | 2221 | case "$cur" in 2222 | -*) 2223 | COMPREPLY=( $( compgen -W '-v -q -c -a -r -R -b -u -l -L -H \ 2224 | -p -o -g -D -t -S -n -W -x -B -e -C -I -T -P \ 2225 | -z -h -4 -6 --verbose --quiet --checksum \ 2226 | --archive --recursive --relative --backup \ 2227 | --backup-dir --suffix= --update --links \ 2228 | --copy-links --copy-unsafe-links --safe-links \ 2229 | --hard-links --perms --owner --group --devices\ 2230 | --times --sparse --dry-run --whole-file \ 2231 | --no-whole-file --one-file-system \ 2232 | --block-size= --rsh= --rsync-path= \ 2233 | --cvs-exclude --existing --ignore-existing \ 2234 | --delete --delete-excluded --delete-after \ 2235 | --ignore-errors --max-delete= --partial \ 2236 | --force --numeric-ids --timeout= \ 2237 | --ignore-times --size-only --modify-window= \ 2238 | --temp-dir= --compare-dest= --compress \ 2239 | --exclude= --exclude-from= --include= \ 2240 | --include-from= --version --daemon --no-detach\ 2241 | --address= --config= --port= --blocking-io \ 2242 | --no-blocking-io --stats --progress \ 2243 | --log-format= --password-file= --bwlimit= \ 2244 | --write-batch= --read-batch= --help' -- $cur )) 2245 | ;; 2246 | *:*) 2247 | # find which remote shell is used 2248 | shell=rsh 2249 | for (( i=1; i < COMP_CWORD; i++ )); do 2250 | if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then 2251 | shell=${COMP_WORDS[i+1]} 2252 | break 2253 | fi 2254 | done 2255 | if [[ "$shell" == ssh ]]; then 2256 | # remove backslash escape from : 2257 | cur=${cur/\\:/:} 2258 | userhost=${cur%%?(\\):*} 2259 | path=${cur#*:} 2260 | # unescape spaces 2261 | path=${path//\\\\\\\\ / } 2262 | if [ -z "$path" ]; then 2263 | # default to home dir of specified 2264 | # user on remote host 2265 | path=$(ssh -o 'Batchmode yes' \ 2266 | $userhost pwd 2>/dev/null) 2267 | fi 2268 | # escape spaces; remove executables, aliases, pipes 2269 | # and sockets; add space at end of file names 2270 | COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \ 2271 | command ls -aF1d "$path*" 2>/dev/null | \ 2272 | sed -e 's/ /\\\\\\\ /g' -e 's/[*@|=]$//g' \ 2273 | -e 's/[^\/]$/& /g' ) ) 2274 | fi 2275 | ;; 2276 | *) 2277 | _known_hosts -c -a 2278 | _filedir 2279 | ;; 2280 | esac 2281 | 2282 | return 0 2283 | } 2284 | [ -n "${have:-}" ] && complete -F _rsync $nospace rsync 2285 | 2286 | # Linux route(8) completion 2287 | # 2288 | [ $UNAME = Linux ] && 2289 | _route() 2290 | { 2291 | local cur prev 2292 | 2293 | COMPREPLY=() 2294 | cur=${COMP_WORDS[COMP_CWORD]} 2295 | prev=${COMP_WORDS[COMP_CWORD-1]} 2296 | 2297 | if [ "$prev" = dev ]; then 2298 | COMPREPLY=( $( ifconfig -a | sed -ne 's|^\('$cur'[^ ]*\).*$|\1|p' )) 2299 | return 0 2300 | fi 2301 | 2302 | COMPREPLY=( $( compgen -W 'add del -host -net netmask metric mss \ 2303 | window irtt reject mod dyn reinstate dev \ 2304 | default gw' -- $cur ) ) 2305 | 2306 | COMPREPLY=( $( echo " ${COMP_WORDS[@]}" | \ 2307 | (while read -d ' ' i; do 2308 | [ "$i" == "" ] && continue 2309 | # flatten array with spaces on either side, 2310 | # otherwise we cannot grep on word 2311 | # boundaries of first and last word 2312 | COMPREPLY=" ${COMPREPLY[@]} " 2313 | # remove word from list of completions 2314 | COMPREPLY=( ${COMPREPLY/ $i / } ) 2315 | done 2316 | echo ${COMPREPLY[@]}) 2317 | ) ) 2318 | return 0 2319 | } 2320 | [ $UNAME = Linux ] && complete -F _route route 2321 | 2322 | # GNU make(1) completion (adapted from the example supplied with the bash 2.04 2323 | # source code) 2324 | # 2325 | have make && 2326 | _make() 2327 | { 2328 | local makef cur prev i 2329 | 2330 | COMPREPLY=() 2331 | cur=${COMP_WORDS[COMP_CWORD]} 2332 | prev=${COMP_WORDS[COMP_CWORD-1]} 2333 | 2334 | # --name value style option 2335 | case $prev in 2336 | -@(f|o|W)) 2337 | _filedir 2338 | return 0 2339 | ;; 2340 | -@(I|C)) 2341 | _filedir -d 2342 | return 0 2343 | ;; 2344 | esac 2345 | 2346 | # --name=value style option 2347 | if [[ "$cur" == *=* ]]; then 2348 | prev=${cur/=*/} 2349 | cur=${cur/*=/} 2350 | case "$prev" in 2351 | --@(file|makefile)) 2352 | _filedir 2353 | return 0 2354 | ;; 2355 | --@(directory|include-dir)) 2356 | _filedir -d 2357 | return 0 2358 | ;; 2359 | esac 2360 | fi 2361 | 2362 | if [[ "$cur" == -* ]]; then 2363 | COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\ 2364 | -j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \ 2365 | --always-make --directory= --debug \ 2366 | --environment-overrides --file= --makefile= --help \ 2367 | --ignore-errors --include-dir= --jobs --load-average \ 2368 | --max-load --keep-going --just-print --dry-run \ 2369 | --recon --old-file= --assume-old= --print-data-base \ 2370 | --question --no-builtin-rules --no-builtin-variables \ 2371 | --silent --quiet --no-keep-goind --stop --touch \ 2372 | --version --print-directory --no-print-directory \ 2373 | --what-if= --new-file= --assume-new= \ 2374 | --warn-undefined-variables' -- $cur ) ) 2375 | else 2376 | # make reads `GNUmakefile', then `makefile', then `Makefile' 2377 | if [ -f GNUmakefile ]; then 2378 | makef=GNUmakefile 2379 | elif [ -f makefile ]; then 2380 | makef=makefile 2381 | elif [ -f Makefile ]; then 2382 | makef=Makefile 2383 | else 2384 | makef=*.mk # local convention 2385 | fi 2386 | 2387 | # before we scan for targets, see if a makefile name was specified 2388 | # with -f 2389 | for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do 2390 | if [[ ${COMP_WORDS[i]} == -f ]]; then 2391 | # eval for tilde expansion 2392 | eval makef=${COMP_WORDS[i+1]} 2393 | break 2394 | fi 2395 | done 2396 | 2397 | [ ! -f $makef ] && return 0 2398 | 2399 | COMPREPLY=( $( awk -F':' '/^[^\t ]*:/ {print $1}' $makef \ 2400 | 2>/dev/null | grep -v "^[.%#]" | grep "^$cur" )) 2401 | 2402 | fi 2403 | } 2404 | [ -n "${have:-}" ] && complete -F _make $default make gmake pmake 2405 | 2406 | # GNU tar(1) completion 2407 | # 2408 | _tar() 2409 | { 2410 | local cur ext regex tar untar 2411 | 2412 | COMPREPLY=() 2413 | cur=${COMP_WORDS[COMP_CWORD]} 2414 | 2415 | if [ $COMP_CWORD -eq 1 ]; then 2416 | COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) ) 2417 | return 0 2418 | fi 2419 | 2420 | case "${COMP_WORDS[1]}" in 2421 | ?(-)c*f) 2422 | _filedir 2423 | return 0 2424 | ;; 2425 | +([^Izjy])f) 2426 | ext='tar' 2427 | regex=$ext 2428 | ;; 2429 | *z*f) 2430 | ext='t?(ar.)@(gz|Z)' 2431 | regex='t\(ar\.\)\(gz\|Z\)' 2432 | ;; 2433 | *[Ijy]*f) 2434 | ext='t?(ar.)bz?(2)' 2435 | regex='t\(ar\.\)bz2\?' 2436 | ;; 2437 | *) 2438 | _filedir 2439 | return 0 2440 | ;; 2441 | 2442 | esac 2443 | 2444 | if [[ "$COMP_LINE" == *$ext' ' ]]; then 2445 | # complete on files in tar file 2446 | # 2447 | # get name of tar file from command line 2448 | tar=$( echo "$COMP_LINE" | \ 2449 | sed -e 's|^.* \([^ ]*'$regex'\) .*$|\1|' ) 2450 | # devise how to untar and list it 2451 | untar=t${COMP_WORDS[1]//[^Izjyf]/} 2452 | 2453 | COMPREPLY=( $( compgen -W "$( echo $( tar $untar $tar \ 2454 | 2>/dev/null ) )" -- "$cur" ) ) 2455 | return 0 2456 | fi 2457 | 2458 | # file completion on relevant files 2459 | _filedir $ext 2460 | 2461 | return 0 2462 | } 2463 | [ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar $dirnames tar || 2464 | complete -F _tar $filenames tar 2465 | 2466 | # jar(1) completion 2467 | # 2468 | have jar && 2469 | _jar() 2470 | { 2471 | local cur 2472 | 2473 | COMPREPLY=() 2474 | cur=${COMP_WORDS[COMP_CWORD]} 2475 | 2476 | if [ $COMP_CWORD = 1 ]; then 2477 | COMPREPLY=( $( compgen -W 'c t x u' -- $cur ) ) 2478 | return 0 2479 | fi 2480 | 2481 | case "${COMP_WORDS[1]}" in 2482 | *c*f) 2483 | _filedir 2484 | ;; 2485 | *f) 2486 | _filedir '?(e|j|w)ar' 2487 | ;; 2488 | *) 2489 | _filedir 2490 | ;; 2491 | esac 2492 | } 2493 | [ -n "${have:-}" ] && complete -F _jar $filenames jar 2494 | 2495 | # Linux iptables(8) completion 2496 | # 2497 | have iptables && 2498 | _iptables() 2499 | { 2500 | local cur prev table chain 2501 | 2502 | COMPREPLY=() 2503 | cur=${COMP_WORDS[COMP_CWORD]} 2504 | prev=${COMP_WORDS[COMP_CWORD-1]} 2505 | chain='s/^Chain \([^ ]\+\).*$/\1/p' 2506 | 2507 | if [[ $COMP_LINE == *-t\ *filter* ]]; then 2508 | table="-t filter" 2509 | elif [[ $COMP_LINE == *-t\ *nat* ]]; then 2510 | table="-t nat" 2511 | elif [[ $COMP_LINE == *-t\ *mangle* ]]; then 2512 | table="-t mangle" 2513 | fi 2514 | 2515 | case "$prev" in 2516 | -*[AIDRPFXLZ]) 2517 | COMPREPLY=( $( compgen -W '`iptables $table -nL | \ 2518 | sed -ne "s/^Chain \([^ ]\+\).*$/\1/p"`' -- $cur ) ) 2519 | ;; 2520 | -*t) 2521 | COMPREPLY=( $( compgen -W 'nat filter mangle' -- $cur ) ) 2522 | ;; 2523 | -j) 2524 | if [ "$table" = "-t filter" -o "$table" = "" ]; then 2525 | COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \ 2526 | `iptables $table -nL | sed -ne "$chain" \ 2527 | -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \ 2528 | $cur ) ) 2529 | elif [ "$table" = "-t nat" ]; then 2530 | COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \ 2531 | MIRROR SNAT DNAT MASQUERADE `iptables $table -nL | \ 2532 | sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \ 2533 | -- $cur ) ) 2534 | elif [ "$table" = "-t mangle" ]; then 2535 | COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \ 2536 | MARK TOS `iptables $table -nL | sed -ne "$chain" \ 2537 | -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \ 2538 | $cur ) ) 2539 | fi 2540 | ;; 2541 | *) 2542 | if [[ "$cur" == -* ]]; then 2543 | COMPREPLY=( $( compgen -W '-i -o -s -d -p -f -m --append \ 2544 | --delete --insert --replace --list --flush --zero --new \ 2545 | --delete-chain --policy --rename-chain --proto --source \ 2546 | --destination --in-interface --jump --match --numeric \ 2547 | --out-interface --table --verbose --line-numbers --exact \ 2548 | --fragment --modprobe= --set-counters --version' -- "$cur") ) 2549 | fi 2550 | ;; 2551 | esac 2552 | 2553 | } 2554 | [ -n "${have:-}" ] && complete -F _iptables iptables 2555 | 2556 | # tcpdump(8) completion 2557 | # 2558 | have tcpdump && 2559 | _tcpdump() 2560 | { 2561 | local cur 2562 | 2563 | COMPREPLY=() 2564 | cur=${COMP_WORDS[COMP_CWORD]} 2565 | prev=${COMP_WORDS[COMP_CWORD-1]} 2566 | 2567 | case "$prev" in 2568 | -@(r|w|F)) 2569 | _filedir 2570 | return 0 2571 | ;; 2572 | -i) 2573 | _interfaces 2574 | return 0 2575 | ;; 2576 | esac 2577 | 2578 | 2579 | if [[ "$cur" == -* ]]; then 2580 | COMPREPLY=( $( compgen -W '-a -d -e -f -l -n -N -O -p \ 2581 | -q -R -S -t -u -v -x -C -F -i -m -r -s -T -w \ 2582 | -E' -- $cur ) ) 2583 | fi 2584 | 2585 | } 2586 | [ -n "${have:-}" ] && complete -F _tcpdump tcpdump 2587 | 2588 | # autorpm(8) completion 2589 | # 2590 | have autorpm && 2591 | _autorpm() 2592 | { 2593 | local cur 2594 | 2595 | COMPREPLY=() 2596 | cur=${COMP_WORDS[COMP_CWORD]} 2597 | 2598 | COMPREPLY=( $( compgen -W '--notty --debug --help --version \ 2599 | auto add fullinfo info help install list \ 2600 | remove set' -- $cur ) ) 2601 | 2602 | } 2603 | [ -n "${have:-}" ] && complete -F _autorpm autorpm 2604 | 2605 | # This meta-cd function observes the CDPATH variable, so that cd additionally 2606 | # completes on directories under those specified in CDPATH. 2607 | # 2608 | _cd() 2609 | { 2610 | local IFS=$'\t\n' cur=${COMP_WORDS[COMP_CWORD]} i j k 2611 | 2612 | # try to allow variable completion 2613 | if [[ "$cur" == ?(\\)\$* ]]; then 2614 | COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) ) 2615 | return 0 2616 | fi 2617 | 2618 | # Use standard dir completion if no CDPATH or parameter starts with /, 2619 | # ./ or ../ 2620 | if [ -z "${CDPATH:-}" ] || [[ "$cur" == ?(.)?(.)/* ]]; then 2621 | _filedir -d 2622 | return 0 2623 | fi 2624 | 2625 | IFS=$'\t\n' 2626 | # we have a CDPATH, so loop on its contents 2627 | for i in ${CDPATH//:/$'\t'}; do 2628 | # create an array of matched subdirs 2629 | k=${#COMPREPLY[@]} 2630 | for j in $( compgen -d $i/$cur ); do 2631 | COMPREPLY[$k]=${j#$i/} 2632 | k=$((++k)) 2633 | done 2634 | done 2635 | 2636 | _filedir -d 2637 | 2638 | return 0 2639 | } 2640 | if shopt -q cdable_vars; then 2641 | complete -v -F _cd $nospace $filenames cd 2642 | else 2643 | complete -F _cd $nospace $filenames cd 2644 | fi 2645 | 2646 | # A meta-command completion function for commands like sudo(8), which need to 2647 | # first complete on a command, then complete according to that command's own 2648 | # completion definition - currently not quite foolproof (e.g. mount and umount 2649 | # don't work properly), but still quite useful 2650 | # 2651 | _command() 2652 | { 2653 | local cur func cline cspec noglob IFS=$' \t\n' cmd \ 2654 | _COMMAND_FUNC _COMMAND_FUNC_ARGS 2655 | 2656 | COMPREPLY=() 2657 | cur=${COMP_WORDS[COMP_CWORD]} 2658 | cmd=${COMP_WORDS[1]} 2659 | 2660 | if [ $COMP_CWORD -eq 1 ]; then 2661 | IFS=$'\n\t' 2662 | COMPREPLY=( $( compgen -c -- $cur ) ) 2663 | IFS=$' \t\n' 2664 | elif complete -p $cmd &>/dev/null; then 2665 | cspec=$( complete -p $cmd ) 2666 | if [ "${cspec#* -F }" != "$cspec" ]; then 2667 | # complete -F 2668 | # 2669 | # COMP_CWORD and COMP_WORDS() are not read-only, 2670 | # so we can set them before handing off to regular 2671 | # completion routine 2672 | 2673 | # set current token number to 1 less than now 2674 | COMP_CWORD=$(( $COMP_CWORD - 1 )) 2675 | # get function name 2676 | func=${cspec#*-F } 2677 | func=${func%% *} 2678 | # get current command line minus initial command 2679 | cline="${COMP_LINE#$1 }" 2680 | # save noglob state 2681 | shopt -o noglob >/dev/null; noglob=$? 2682 | # turn on noglob, as things like 'sudo ls *' 2683 | # don't work otherwise 2684 | shopt -so noglob 2685 | # split current command line tokens into array 2686 | COMP_WORDS=( $cline ) 2687 | # reset noglob if necessary 2688 | [ $noglob -eq 1 ] && shopt -uo noglob 2689 | # this is needed in case user finished entering command and pressed tab (e.g. sudo ls ) 2690 | COMP_CWORD=$(( $COMP_CWORD > 0 ? $COMP_CWORD : 1 )) 2691 | cur=${COMP_WORDS[COMP_CWORD]} 2692 | _COMMAND_FUNC=$func 2693 | _COMMAND_FUNC_ARGS=( $cmd $2 $3 ) 2694 | COMP_LINE=$cline 2695 | COMP_POINT=$(( ${COMP_POINT} - ${#1} - 1 )) 2696 | $func $cmd $2 $3 2697 | # remove any \: generated by a command that doesn't 2698 | # default to filenames or dirnames (e.g. sudo chown) 2699 | if [ "${cspec#*-o }" != "$cspec" ]; then 2700 | cspec=${cspec#*-o } 2701 | cspec=${cspec%% *} 2702 | if [[ "$cspec" != @(dir|file)names ]]; then 2703 | IFS=$'\n\t' 2704 | COMPREPLY=( ${COMPREPLY[@]//\\\\:/:} ) 2705 | IFS=$' \t\n' 2706 | fi 2707 | fi 2708 | elif [ -n "$cspec" ]; then 2709 | cspec=${cspec#complete}; 2710 | cspec=${cspec%%$cmd}; 2711 | IFS=$'\n\t' 2712 | COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) ); 2713 | IFS=$' \t\n' 2714 | fi 2715 | fi 2716 | 2717 | [ ${#COMPREPLY[@]} -eq 0 ] && _filedir 2718 | } 2719 | complete -F _command $filenames nohup exec nice eval strace time ltrace then \ 2720 | else do vsound 2721 | 2722 | _root_command() 2723 | { 2724 | PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 $2 $3 2725 | } 2726 | complete -F _root_command $filenames sudo fakeroot really 2727 | 2728 | # ant(1) completion 2729 | # 2730 | have ant && 2731 | _ant() 2732 | { 2733 | local cur prev buildfile i 2734 | 2735 | COMPREPLY=() 2736 | cur=${COMP_WORDS[COMP_CWORD]} 2737 | prev=${COMP_WORDS[COMP_CWORD-1]} 2738 | 2739 | case "$prev" in 2740 | -buildfile|-f) 2741 | _filedir 'xml' 2742 | return 0 2743 | ;; 2744 | -logfile) 2745 | _filedir 2746 | return 0 2747 | ;; 2748 | esac 2749 | 2750 | if [[ "$cur" == -* ]]; then 2751 | # relevant options completion 2752 | COMPREPLY=( $( compgen -W '-help -projecthelp -version -quiet \ 2753 | -verbose -debug -emacs -logfile -logger \ 2754 | -listener -buildfile -f -D -find' -- $cur ) ) 2755 | else 2756 | # available targets completion 2757 | # find which buildfile to use 2758 | buildfile=build.xml 2759 | for (( i=1; i < COMP_CWORD; i++ )); do 2760 | if [[ "${COMP_WORDS[i]}" == -buildfile ]]; then 2761 | buildfile=${COMP_WORDS[i+1]} 2762 | break 2763 | fi 2764 | done 2765 | [ ! -f $buildfile ] && return 0 2766 | 2767 | # parse buildfile for targets 2768 | COMPREPLY=( $( awk -F'"' '//dev/null | \ 3039 | sed -e '1,/^-/d' -e '/^(/,$d' | \ 3040 | awk '{print $1}' | grep "^$cur" ) ) 3041 | } 3042 | 3043 | _pg_users() 3044 | { 3045 | COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \ 3046 | grep "^ $cur" ) ) 3047 | [ ${#COMPREPLY[@]} -eq 0 ] && COMPREPLY=( $( compgen -u -- $cur ) ) 3048 | } 3049 | 3050 | # psql(1) completion 3051 | # 3052 | _psql() 3053 | { 3054 | local cur prev 3055 | 3056 | COMPREPLY=() 3057 | cur=${COMP_WORDS[COMP_CWORD]} 3058 | prev=${COMP_WORDS[COMP_CWORD-1]} 3059 | 3060 | case "$prev" in 3061 | -h|--host) 3062 | _known_hosts 3063 | return 0 3064 | ;; 3065 | -U|--username) 3066 | _pg_users 3067 | return 0 3068 | ;; 3069 | -d|--dbname) 3070 | _pg_databases 3071 | return 0 3072 | ;; 3073 | -@(o|f)|--output|--file) 3074 | _filedir 3075 | return 0 3076 | ;; 3077 | esac 3078 | 3079 | if [[ "$cur" == -* ]]; then 3080 | # return list of available options 3081 | COMPREPLY=( $( compgen -W '-a --echo-all -A --no-align \ 3082 | -c --command -d --dbname -e --echo-queries \ 3083 | -E --echo-hidden -f --file -F --filed-separator \ 3084 | -h --host -H --html -l --list -n -o --output \ 3085 | -p --port -P --pset -q -R --record-separator \ 3086 | -s --single-step -S --single-line -t --tuples-only \ 3087 | -T --table-attr -U --username -v --variable \ 3088 | -V --version -W --password -x --expanded -X --nopsqlrc \ 3089 | -? --help ' -- $cur ) ) 3090 | else 3091 | # return list of available databases 3092 | _pg_databases 3093 | fi 3094 | } 3095 | complete -F _psql $default psql 3096 | 3097 | # createdb(1) completion 3098 | # 3099 | _createdb() 3100 | { 3101 | local cur prev 3102 | 3103 | COMPREPLY=() 3104 | cur=${COMP_WORDS[COMP_CWORD]} 3105 | prev=${COMP_WORDS[COMP_CWORD-1]} 3106 | 3107 | case "$prev" in 3108 | -@(h|-host=)) 3109 | _known_hosts 3110 | return 0 3111 | ;; 3112 | -@(U|-username=)) 3113 | _pg_users 3114 | return 0 3115 | ;; 3116 | esac 3117 | 3118 | if [[ "$cur" == -* ]]; then 3119 | COMPREPLY=( $( compgen -W '-D -T -E -h -p -U -W -e -q \ 3120 | --location= --template= --encoding= --host= --port= \ 3121 | --username= --password --echo --quiet --help' -- $cur )) 3122 | else 3123 | _pg_databases 3124 | fi 3125 | } 3126 | complete -F _createdb $default createdb 3127 | 3128 | # dropdb(1) completion 3129 | # 3130 | _dropdb() 3131 | { 3132 | local cur prev 3133 | 3134 | COMPREPLY=() 3135 | cur=${COMP_WORDS[COMP_CWORD]} 3136 | prev=${COMP_WORDS[COMP_CWORD-1]} 3137 | 3138 | case "$prev" in 3139 | -@(h|-host=)) 3140 | _known_hosts 3141 | return 0 3142 | ;; 3143 | -@(U|-username=)) 3144 | _pg_users 3145 | return 0 3146 | ;; 3147 | esac 3148 | 3149 | if [[ "$cur" == -* ]]; then 3150 | COMPREPLY=( $( compgen -W '-h -p -U -W -e -q \ 3151 | --host= --port= --username= --password \ 3152 | --interactive --echo --quiet --help' -- $cur ) ) 3153 | else 3154 | _pg_databases 3155 | fi 3156 | } 3157 | complete -F _dropdb $default dropdb 3158 | } 3159 | 3160 | _longopt() 3161 | { 3162 | local cur opt 3163 | 3164 | cur=${COMP_WORDS[COMP_CWORD]} 3165 | 3166 | if [[ "$cur" == --*=* ]]; then 3167 | opt=${cur%%=*} 3168 | # cut backslash that gets inserted before '=' sign 3169 | opt=${opt%\\*} 3170 | cur=${cur#*=} 3171 | _filedir 3172 | COMPREPLY=( $( compgen -P "$opt=" -W '${COMPREPLY[@]}' -- $cur)) 3173 | return 0 3174 | fi 3175 | 3176 | if [[ "$cur" == -* ]]; then 3177 | COMPREPLY=( $( $1 --help 2>&1 | sed -e '/--/!d' \ 3178 | -e 's/.*\(--[-A-Za-z0-9]\+=\?\).*/\1/' | \ 3179 | grep "^$cur" | sort -u ) ) 3180 | elif [[ "$1" == @(mk|rm)dir ]]; then 3181 | _filedir -d 3182 | else 3183 | _filedir 3184 | fi 3185 | } 3186 | # makeinfo and texi2dvi are defined elsewhere 3187 | for i in a2ps autoconf automake bc gprof ld nm objcopy objdump readelf strip \ 3188 | bison cpio diff patch enscript cp df dir du ln ls mkfifo mknod mv rm \ 3189 | touch vdir xargs awk gperf grep grub indent less m4 sed shar date \ 3190 | env seq tee uname who texindex cat csplit cut expand fmt fold head \ 3191 | md5sum nl od paste pr ptx sha1sum sort split tac tail tr unexpand \ 3192 | uniq wc units wget ldd bash id info irb mkdir rmdir netstat; do 3193 | have $i && complete -F _longopt $filenames $i 3194 | done 3195 | unset i 3196 | 3197 | # gcc(1) completion 3198 | # 3199 | # The only unusual feature is that we don't parse "gcc --help -v" output 3200 | # directly, because that would include the options of all the other backend 3201 | # tools (linker, assembler, preprocessor, etc) without any indication that 3202 | # you cannot feed such options to the gcc driver directly. (For example, the 3203 | # linker takes a -z option, but you must type -Wl,-z for gcc.) Instead, we 3204 | # ask the driver ("g++") for the name of the compiler ("cc1"), and parse the 3205 | # --help output of the compiler. 3206 | # 3207 | have gcc && 3208 | _gcc() 3209 | { 3210 | local cur cc backend 3211 | 3212 | COMPREPLY=() 3213 | cur=${COMP_WORDS[COMP_CWORD]} 3214 | 3215 | _expand || return 0 3216 | 3217 | case "$1" in 3218 | gcj) 3219 | backend=jc1 3220 | ;; 3221 | gpc) 3222 | backend=gpc1 3223 | ;; 3224 | *77) 3225 | backend=f771 3226 | ;; 3227 | *) 3228 | backend=cc1 # (near-)universal backend 3229 | ;; 3230 | esac 3231 | 3232 | if [[ "$cur" == -* ]]; then 3233 | cc=$( $1 -print-prog-name=$backend ) 3234 | # sink stderr: 3235 | # for C/C++/ObjectiveC it's useless 3236 | # for FORTRAN/Java it's an error 3237 | COMPREPLY=( $( $cc --help 2>/dev/null | tr '\t' ' ' | \ 3238 | sed -e '/^ *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \ 3239 | grep "^$cur" | sort -u ) ) 3240 | else 3241 | _filedir 3242 | fi 3243 | } 3244 | [ -n "${have:-}" ] && complete $filenames -F _gcc gcc g++ c++ g77 gcj gpc 3245 | [ $UNAME = GNU -o $UNAME = Linux ] && complete $filenames -F _gcc cc 3246 | 3247 | # Linux cardctl(8) completion 3248 | # 3249 | have cardctl && 3250 | _cardctl() 3251 | { 3252 | local cur 3253 | 3254 | COMPREPLY=() 3255 | cur=${COMP_WORDS[COMP_CWORD]} 3256 | 3257 | if [ $COMP_CWORD -eq 1 ]; then 3258 | COMPREPLY=( $( compgen -W 'status config ident suspend \ 3259 | resume reset eject insert scheme' \ 3260 | -- $cur ) ) 3261 | fi 3262 | } 3263 | [ -n "${have:-}" ] && complete -F _cardctl cardctl 3264 | 3265 | # This function is required by _dpkg() and _dpkg-reconfigure() 3266 | # 3267 | have dpkg && { 3268 | _comp-dpkg-installed-packages() 3269 | { 3270 | grep -B 2 'ok installed' /var/lib/dpkg/status | grep "Package: $1" | \ 3271 | cut -d\ -f2 3272 | 3273 | } 3274 | 3275 | # Debian dpkg(8) completion 3276 | # 3277 | _dpkg() 3278 | { 3279 | local cur prev 3280 | 3281 | COMPREPLY=() 3282 | cur=${COMP_WORDS[COMP_CWORD]} 3283 | prev=${COMP_WORDS[COMP_CWORD-1]} 3284 | 3285 | _expand || return 0 3286 | 3287 | # find the last option flag 3288 | if [[ $cur != -* ]]; then 3289 | while [[ $prev != -* && $COMP_CWORD != 1 ]]; do 3290 | COMP_CWORD=$((COMP_CWORD-1)) 3291 | prev=${COMP_WORDS[COMP_CWORD-1]} 3292 | done 3293 | fi 3294 | 3295 | case "$prev" in 3296 | -@(c|i|A|I|f|e|x|X|-@(install|unpack|record-avail|contents|info| \ 3297 | fsys-tarfile|field|control|extract))) 3298 | _filedir '?(u)deb' 3299 | return 0 3300 | ;; 3301 | -@(b|-build)) 3302 | _filedir -d 3303 | return 0 3304 | ;; 3305 | -@(s|p|l|-@(status|print-avail|list))) 3306 | COMPREPLY=( $( apt-cache pkgnames $cur 2>/dev/null ) ) 3307 | return 0 3308 | ;; 3309 | -@(S|-search)) 3310 | _filedir 3311 | return 0 3312 | ;; 3313 | -@(r|L|-@(remove|purge|listfiles))) 3314 | COMPREPLY=( $( _comp-dpkg-installed-packages $cur ) ) 3315 | return 0 3316 | ;; 3317 | *) 3318 | 3319 | COMPREPLY=( $( compgen -W '-i --install --unpack -A --record-avail \ 3320 | --configure -r --remove --purge --get-selections \ 3321 | --set-selections --update-avail --merge-avail \ 3322 | --clear-avail --command-fd --forget-old-unavail -s \ 3323 | --status -p --print-avail -L --listfiles -l --list \ 3324 | -S --search -C --audit --print-architecture \ 3325 | --print-gnu-build-architecture \ 3326 | --print-installation-architecture \ 3327 | --compare-versions --help --version --force-help \ 3328 | --force-all --force-auto-select --force-downgrade \ 3329 | --force-configure-any --force-hold --force-bad-path \ 3330 | --force-not-root --force-overwrite \ 3331 | --force-overwrite-diverted --force-bad-verify \ 3332 | --force-depends-version --force-depends \ 3333 | --force-confnew --force-confold --force-confdef \ 3334 | --force-confmiss --force-conflicts --force-architecture\ 3335 | --force-overwrite-dir --force-remove-reinstreq \ 3336 | --force-remove-essential -Dh \ 3337 | --debug=help --licence --admindir= --root= --instdir= \ 3338 | -O --selected-only -E --skip-same-version \ 3339 | -G --refuse-downgrade -B --auto-deconfigure \ 3340 | --no-debsig --no-act -D --debug= --status-fd \ 3341 | -b --build -I --info -f --field -c --contents \ 3342 | -x --extract -X --vextract --fsys-tarfile -e --control \ 3343 | --ignore-depends= --abort-after' -- $cur ) ) 3344 | ;; 3345 | esac 3346 | 3347 | 3348 | } 3349 | complete -F _dpkg $filenames dpkg dpkg-deb 3350 | } 3351 | 3352 | # Debian GNU dpkg-reconfigure(8) completion 3353 | # 3354 | have dpkg-reconfigure && 3355 | _dpkg_reconfigure() 3356 | { 3357 | local cur prev opt 3358 | 3359 | COMPREPLY=() 3360 | cur=${COMP_WORDS[COMP_CWORD]} 3361 | prev=${COMP_WORDS[COMP_CWORD-1]} 3362 | 3363 | 3364 | case "$prev" in 3365 | -@(f|-frontend)) 3366 | opt=( $( echo /usr/share/perl5/Debconf/FrontEnd/* ) ) 3367 | opt=( ${opt[@]##*/} ) 3368 | opt=( ${opt[@]%.pm} ) 3369 | COMPREPLY=( $( compgen -W '${opt[@]}' -- $cur ) ) 3370 | return 0 3371 | ;; 3372 | -@(p|-priority)) 3373 | COMPREPLY=( $( compgen -W 'low medium high critical' -- $cur ) ) 3374 | return 0 3375 | ;; 3376 | esac 3377 | 3378 | if [[ "$cur" == -* ]]; then 3379 | COMPREPLY=( $( compgen -W '-f --frontend -p --priority -a --all \ 3380 | -u --unseen-only -h --help -s --showold \ 3381 | --force --terse' -- $cur ) ) 3382 | else 3383 | COMPREPLY=( $( _comp-dpkg-installed-packages $cur ) ) 3384 | fi 3385 | } 3386 | [ -n "${have:-}" ] && complete -F _dpkg_reconfigure $default dpkg-reconfigure 3387 | 3388 | # Debian Linux dselect(8) completion. 3389 | # 3390 | have dselect && 3391 | _dselect() 3392 | { 3393 | local cur prev 3394 | 3395 | COMPREPLY=() 3396 | cur=${COMP_WORDS[COMP_CWORD]} 3397 | prev=${COMP_WORDS[COMP_CWORD-1]} 3398 | 3399 | case "$prev" in 3400 | --admindir) 3401 | _filedir -d 3402 | return 0 3403 | ;; 3404 | 3405 | -@(D|debug)) 3406 | _filedir 3407 | return 0 3408 | ;; 3409 | esac 3410 | 3411 | if [[ "$cur" == -* ]]; then 3412 | COMPREPLY=( $( compgen -W '--admindir --help --version --licence \ 3413 | --license --expert --debug' -- $cur ) ) 3414 | else 3415 | COMPREPLY=( $( compgen -W 'access update select install config \ 3416 | remove quit' -- $cur ) ) 3417 | fi 3418 | 3419 | 3420 | return 0 3421 | } 3422 | [ -n "${have:-}" ] && complete -F _dselect $filenames dselect 3423 | 3424 | # Java completion 3425 | # 3426 | 3427 | # available path elements completion 3428 | have java && { 3429 | _java_path() 3430 | { 3431 | cur=${cur##*:} 3432 | _filedir '@(jar|zip)' 3433 | } 3434 | 3435 | # exact classpath determination 3436 | _java_find_classpath() 3437 | { 3438 | local i 3439 | 3440 | # search first in current options 3441 | for (( i=1; i < COMP_CWORD; i++ )); do 3442 | if [[ "${COMP_WORDS[i]}" == -@(cp|classpath) ]]; then 3443 | classpath=${COMP_WORDS[i+1]} 3444 | break 3445 | fi 3446 | done 3447 | 3448 | # default to environment 3449 | [ -z "$classpath" ] && classpath=$CLASSPATH 3450 | 3451 | # default to current directory 3452 | [ -z "$classpath" ] && classpath=. 3453 | } 3454 | 3455 | # exact sourcepath determination 3456 | _java_find_sourcepath() 3457 | { 3458 | local i 3459 | 3460 | # search first in current options 3461 | for (( i=1; i < COMP_CWORD; i++ )); do 3462 | if [[ "${COMP_WORDS[i]}" == -sourcepath ]]; then 3463 | sourcepath=${COMP_WORDS[i+1]} 3464 | break 3465 | fi 3466 | done 3467 | 3468 | # default to classpath 3469 | [ -z "$sourcepath" ] && _java_find_classpath 3470 | sourcepath=$classpath 3471 | } 3472 | 3473 | # available classes completion 3474 | _java_classes() 3475 | { 3476 | local classpath i 3477 | 3478 | # find which classpath to use 3479 | _java_find_classpath 3480 | 3481 | # convert package syntax to path syntax 3482 | cur=${cur//.//} 3483 | # parse each classpath element for classes 3484 | for i in ${classpath//:/ }; do 3485 | if [ -r $i ] && [[ "$i" == *.@(jar|zip) ]]; then 3486 | if type zipinfo &> /dev/null; then 3487 | COMPREPLY=( ${COMPREPLY[@]} $( zipinfo -1 \ 3488 | "$i" | grep "^$cur" | grep '\.class$' | \ 3489 | grep -v "\\$" ) ) 3490 | else 3491 | COMPREPLY=( ${COMPREPLY[@]} $( jar tf "$i" \ 3492 | "$cur" | grep "\.class$" | grep -v "\\$" ) ) 3493 | fi 3494 | 3495 | elif [ -d $i ]; then 3496 | i=${i%/} 3497 | COMPREPLY=( ${COMPREPLY[@]} $( find "$i" -type f \ 3498 | -path "$i/$cur*.class" 2>/dev/null | \ 3499 | grep -v "\\$" | sed -e "s|^$i/||" ) ) 3500 | fi 3501 | done 3502 | 3503 | # remove class extension 3504 | COMPREPLY=( ${COMPREPLY[@]%.class} ) 3505 | # convert path syntax to package syntax 3506 | COMPREPLY=( ${COMPREPLY[@]//\//.} ) 3507 | } 3508 | 3509 | # available packages completion 3510 | _java_packages() 3511 | { 3512 | local sourcepath i 3513 | 3514 | # find wich sourcepath to use 3515 | _java_find_sourcepath 3516 | 3517 | # convert package syntax to path syntax 3518 | cur=${cur//.//} 3519 | # parse each sourcepath element for packages 3520 | for i in ${sourcepath//:/ }; do 3521 | if [ -d $i ]; then 3522 | COMPREPLY=( ${COMPREPLY[@]} $( command ls -F -d \ 3523 | $i/$cur* 2>/dev/null | sed -e 's|^'$i'/||' ) ) 3524 | fi 3525 | done 3526 | # keep only packages 3527 | COMPREPLY=( $( echo ${COMPREPLY[@]} | tr " " "\n" | grep "/$" ) ) 3528 | # remove packages extension 3529 | COMPREPLY=( ${COMPREPLY[@]%/} ) 3530 | # convert path syntax to package syntax 3531 | cur=${COMPREPLY[@]//\//.} 3532 | } 3533 | 3534 | # java completion 3535 | # 3536 | _java() 3537 | { 3538 | local cur prev i 3539 | 3540 | COMPREPLY=() 3541 | cur=${COMP_WORDS[COMP_CWORD]} 3542 | prev=${COMP_WORDS[COMP_CWORD-1]} 3543 | 3544 | for ((i=1; i < $COMP_CWORD; i++)); do 3545 | case ${COMP_WORDS[$i]} in 3546 | -cp|-classpath) 3547 | ((i++)) # skip the classpath string. 3548 | ;; 3549 | -*) 3550 | # this is an option, not a class/jarfile name. 3551 | ;; 3552 | *) 3553 | # once we've seen a class, just do filename completion 3554 | _filedir 3555 | return 0 3556 | ;; 3557 | esac 3558 | done 3559 | 3560 | case $prev in 3561 | -@(cp|classpath)) 3562 | _java_path 3563 | return 0 3564 | ;; 3565 | esac 3566 | 3567 | if [[ "$cur" == -* ]]; then 3568 | # relevant options completion 3569 | COMPREPLY=( $( compgen -W '-client -hotspot -server -classic \ 3570 | -cp -classpath -D -verbose -verbose:class \ 3571 | -verbose:gc -version:jni -version \ 3572 | -showversion -? -help -X -jar \ 3573 | -ea -enableassertions -da -disableassertions \ 3574 | -esa -enablesystemassertions \ 3575 | -dsa -disablesystemassertions ' -- $cur ) ) 3576 | else 3577 | if [[ "$prev" == -jar ]]; then 3578 | # jar file completion 3579 | _filedir jar 3580 | else 3581 | # classes completion 3582 | _java_classes 3583 | fi 3584 | fi 3585 | } 3586 | complete -F _java $filenames java 3587 | } 3588 | 3589 | # javadoc completion 3590 | # 3591 | have javadoc && 3592 | _javadoc() 3593 | { 3594 | COMPREPLY=() 3595 | local cur prev 3596 | 3597 | cur=${COMP_WORDS[COMP_CWORD]} 3598 | prev=${COMP_WORDS[COMP_CWORD-1]} 3599 | 3600 | case $prev in 3601 | -@(overview|helpfile|stylesheetfile)) 3602 | _filedir 3603 | return 0 3604 | ;; 3605 | -d) 3606 | _filedir -d 3607 | return 0 3608 | ;; 3609 | -@(classpath|bootclasspath|docletpath|sourcepath|extdirs)) 3610 | _java_path 3611 | return 0 3612 | ;; 3613 | esac 3614 | 3615 | if [[ "$cur" == -* ]]; then 3616 | # relevant options completion 3617 | COMPREPLY=( $( compgen -W '-overview -public -protected \ 3618 | -package -private -help -doclet -docletpath \ 3619 | -sourcepath -classpath -exclude -subpackages \ 3620 | -breakiterator -bootclasspath -source -extdirs \ 3621 | -verbose -locale -encoding -J -d -use -version \ 3622 | -author -docfilessubdirs -splitindex \ 3623 | -windowtitle -doctitle -header -footer -bottom \ 3624 | -link -linkoffline -excludedocfilessubdir \ 3625 | -group -nocomment -nodeprecated -noqualifier \ 3626 | -nosince -nodeprecatedlist -notree -noindex \ 3627 | -nohelp -nonavbar -quiet -serialwarn -tag \ 3628 | -taglet -tagletpath -charset -helpfile \ 3629 | -linksource -stylesheetfile -docencoding' -- \ 3630 | $cur ) ) 3631 | else 3632 | # source files completion 3633 | _filedir java 3634 | # packages completion 3635 | _java_packages 3636 | fi 3637 | } 3638 | [ -n "${have:-}" ] && complete -F _javadoc $filenames javadoc 3639 | 3640 | # javac completion 3641 | # 3642 | have javac && 3643 | _javac() 3644 | { 3645 | COMPREPLY=() 3646 | local cur prev 3647 | 3648 | cur=${COMP_WORDS[COMP_CWORD]} 3649 | prev=${COMP_WORDS[COMP_CWORD-1]} 3650 | 3651 | case $prev in 3652 | -d) 3653 | _filedir -d 3654 | return 0 3655 | ;; 3656 | -@(classpath|bootclasspath|sourcepath|extdirs)) 3657 | _java_path 3658 | return 0 3659 | ;; 3660 | esac 3661 | 3662 | if [[ "$cur" == -* ]]; then 3663 | # relevant options completion 3664 | COMPREPLY=( $( compgen -W '-g -g:none -g:lines -g:vars\ 3665 | -g:source -O -nowarn -verbose -deprecation -classpath\ 3666 | -sourcepath -bootclasspath -extdirs -d -encoding -source\ 3667 | -target -help' -- $cur ) ) 3668 | else 3669 | # source files completion 3670 | _filedir java 3671 | fi 3672 | } 3673 | [ -n "${have:-}" ] && complete -F _javac $filenames javac 3674 | 3675 | # PINE address-book completion 3676 | # 3677 | have pine && 3678 | _pineaddr() 3679 | { 3680 | local cur 3681 | 3682 | COMPREPLY=() 3683 | cur=${COMP_WORDS[COMP_CWORD]} 3684 | 3685 | COMPREPLY=( $( compgen -W '$( awk "{print \$1}" ~/.addressbook 2>/dev/null)' \ 3686 | -- $cur ) ) 3687 | } 3688 | [ -n "${have:-}" ] && complete -F _pineaddr $default pine 3689 | 3690 | _configure_func() 3691 | { 3692 | local cur 3693 | 3694 | COMPREPLY=() 3695 | cur=${COMP_WORDS[COMP_CWORD]} 3696 | 3697 | # if $COMP_CONFIGURE_HINTS is not null, then completions of the form 3698 | # --option=SETTING will include 'SETTING' as a contextual hint 3699 | [[ "$cur" != -* ]] && return 0 3700 | 3701 | if [ -n "$COMP_CONFIGURE_HINTS" ]; then 3702 | COMPREPLY=( $( $1 --help | awk '/^ --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[,[].*//g' | grep ^$cur ) ) 3703 | 3704 | else 3705 | COMPREPLY=( $( $1 --help | awk '/^ --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[,=[].*//g' | grep ^$cur ) ) 3706 | fi 3707 | } 3708 | complete -F _configure_func $default configure 3709 | 3710 | # Debian reportbug(1) completion 3711 | # 3712 | have reportbug && 3713 | _reportbug() 3714 | { 3715 | local cur prev 3716 | 3717 | COMPREPLY=() 3718 | cur=${COMP_WORDS[COMP_CWORD]} 3719 | prev=${COMP_WORDS[COMP_CWORD-1]} 3720 | 3721 | case "$prev" in 3722 | -f|--filename|-i|--include|--mta|-o|--output) 3723 | _filedir 3724 | return 0 3725 | ;; 3726 | -B|--bts) 3727 | COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \ 3728 | $cur )) 3729 | return 0 3730 | ;; 3731 | -e|--editor|--mua) 3732 | COMP_WORDS=(COMP_WORDS[0] $cur) 3733 | COMP_CWORD=1 3734 | _command 3735 | return 0 3736 | ;; 3737 | --mode) 3738 | COMPREPLY=( $( compgen -W "novice standard expert" -- $cur ) ) 3739 | return 0 3740 | ;; 3741 | -S|--severity) 3742 | COMPREPLY=( $( compgen -W "grave serious important normal \ 3743 | minor wishlist" -- $cur ) ) 3744 | return 0 3745 | ;; 3746 | -u|--ui|--interface) 3747 | COMPREPLY=( $( compgen -W "newt text gnome" -- $cur ) ) 3748 | return 0 3749 | ;; 3750 | -t|--type) 3751 | COMPREPLY=( $( compgen -W "gnats debbugs" -- $cur ) ) 3752 | return 0 3753 | ;; 3754 | -T|--tags) 3755 | COMPREPLY=( $( compgen -W "none patch security upstream sid \ 3756 | woody potato sarge fixed" -- $cur )) 3757 | return 0 3758 | ;; 3759 | *) 3760 | ;; 3761 | esac 3762 | 3763 | COMPREPLY=($( compgen -W '-h --help -v --version -a --af -b \ 3764 | --no-query-bts --query-bts -B --bts -c --configure \ 3765 | --no-config-files --check-available -d --debug \ 3766 | --no-check-available -e --editor --email -f \ 3767 | --filename -g --gnupg -H --header -i --include -j \ 3768 | --justification -l --ldap --no-ldap -L --list-cc -m \ 3769 | --maintonly --mode --mua --mta --mutt -n --mh --nmh \ 3770 | -o --output -p --print -P --pgp --proxy --http_proxy\ 3771 | -q --quiet -Q --query-only --realname --report-quiet \ 3772 | --reply-to --replyto -s --subject -S --severity \ 3773 | --smtphost -t --type -T --tags --template -V -x \ 3774 | --no-cc --package-version -z --no-compress \ 3775 | --ui --interface -u \ 3776 | wnpp boot-floppies kernel-image' -- $cur ) \ 3777 | $( apt-cache pkgnames -- $cur ) ) 3778 | _filedir 3779 | return 0 3780 | } 3781 | [ -n "${have:-}" ] && complete -F _reportbug $filenames reportbug 3782 | 3783 | # Debian querybts(1) completion 3784 | # 3785 | have querybts && 3786 | _querybts() 3787 | { 3788 | local cur prev 3789 | 3790 | COMPREPLY=() 3791 | cur=${COMP_WORDS[COMP_CWORD]} 3792 | prev=${COMP_WORDS[COMP_CWORD-1]} 3793 | 3794 | case "$prev" in 3795 | -B|--bts) 3796 | COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \ 3797 | $cur )) 3798 | return 0 3799 | ;; 3800 | -u|--ui|--interface) 3801 | COMPREPLY=($( compgen -W "newt text gnome" -- $cur )) 3802 | return 0 3803 | ;; 3804 | *) 3805 | ;; 3806 | esac 3807 | 3808 | COMPREPLY=($( compgen -W '-h --help -v --version -A --archive \ 3809 | -B --bts -l --ldap --no-ldap --proxy= --http_proxy= \ 3810 | -s --source -w --web -u --ui --interface \ 3811 | wnpp boot-floppies' -- $cur ) \ 3812 | $( apt-cache pkgnames -- $cur ) ) 3813 | } 3814 | [ -n "${have:-}" ] && complete -F _querybts $filenames querybts 3815 | 3816 | # update-alternatives completion 3817 | # 3818 | have update-alternatives && 3819 | _update_alternatives() 3820 | { 3821 | installed_alternatives() 3822 | { 3823 | local admindir 3824 | # find wich admin dir to use 3825 | if [ -f /etc/debian_version ]; then 3826 | admindir=/var/lib/dpkg/alternatives 3827 | else 3828 | admindir=/var/lib/rpm/alternatives 3829 | fi 3830 | for (( i=1; i < COMP_CWORD; i++ )); do 3831 | if [[ "${COMP_WORDS[i]}" == --admindir ]]; then 3832 | admindir=${COMP_WORDS[i+1]} 3833 | break 3834 | fi 3835 | done 3836 | COMPREPLY=( $( command ls $admindir | grep "^$cur" ) ) 3837 | } 3838 | 3839 | local cur prev mode args 3840 | 3841 | COMPREPLY=() 3842 | cur=${COMP_WORDS[COMP_CWORD]} 3843 | prev=${COMP_WORDS[COMP_CWORD-1]} 3844 | 3845 | case "$prev" in 3846 | --@(altdir|admindir)) 3847 | _filedir -d 3848 | return 0 3849 | ;; 3850 | --@(help|version)) 3851 | return 0 3852 | ;; 3853 | esac 3854 | 3855 | # find wich mode to use and how many real args used so far 3856 | for (( i=1; i < COMP_CWORD; i++ )); do 3857 | if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config) ]]; then 3858 | mode=${COMP_WORDS[i]} 3859 | args=$(($COMP_CWORD - i)) 3860 | break 3861 | fi 3862 | done 3863 | 3864 | case $mode in 3865 | --install) 3866 | case $args in 3867 | 1) 3868 | _filedir 3869 | ;; 3870 | 2) 3871 | installed_alternatives 3872 | ;; 3873 | 3) 3874 | _filedir 3875 | ;; 3876 | esac 3877 | ;; 3878 | --remove) 3879 | case $args in 3880 | 1) 3881 | installed_alternatives 3882 | ;; 3883 | 2) 3884 | _filedir 3885 | ;; 3886 | esac 3887 | ;; 3888 | --auto) 3889 | installed_alternatives 3890 | ;; 3891 | --display) 3892 | installed_alternatives 3893 | ;; 3894 | --config) 3895 | installed_alternatives 3896 | ;; 3897 | *) 3898 | COMPREPLY=( $( compgen -W '--verbose --quiet --help --version \ 3899 | --altdir --admindir' -- $cur ) \ 3900 | $( compgen -W '--install --remove --auto --display \ 3901 | --config' -- $cur ) ) 3902 | esac 3903 | } 3904 | [ -n "${have:-}" ] && complete -F _update_alternatives update-alternatives 3905 | 3906 | # Python completion 3907 | # 3908 | have python && 3909 | _python() 3910 | { 3911 | local prev cur 3912 | 3913 | COMPREPLY=() 3914 | cur=${COMP_WORDS[COMP_CWORD]} 3915 | prev=${COMP_WORDS[COMP_CWORD-1]} 3916 | 3917 | case "$prev" in 3918 | -Q) 3919 | COMPREPLY=( $( compgen -W "old new warn warnall" -- $cur ) ) 3920 | return 0 3921 | ;; 3922 | -W) 3923 | COMPREPLY=( $( compgen -W "ignore default all module once error" -- $cur ) ) 3924 | return 0 3925 | ;; 3926 | -c) 3927 | _filedir '@(py|pyc|pyo)' 3928 | return 0 3929 | ;; 3930 | !(python|-?)) 3931 | [[ ${COMP_WORDS[COMP_CWORD-2]} != -@(Q|W) ]] && _filedir 3932 | ;; 3933 | esac 3934 | 3935 | 3936 | # if '-c' is already given, complete all kind of files. 3937 | for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do 3938 | if [[ ${COMP_WORDS[i]} == -c ]]; then 3939 | _filedir 3940 | fi 3941 | done 3942 | 3943 | 3944 | if [[ "$cur" != -* ]]; then 3945 | _filedir '@(py|pyc|pyo)' 3946 | else 3947 | COMPREPLY=( $( compgen -W "- -d -E -h -i -O -Q -S -t -u \ 3948 | -U -v -V -W -x -c" -- $cur ) ) 3949 | fi 3950 | 3951 | 3952 | 3953 | return 0 3954 | } 3955 | [ -n "${have:-}" ] && complete -F _python $filenames python 3956 | 3957 | # Perl completion 3958 | # 3959 | have perl && 3960 | { 3961 | _perlmodules() 3962 | { 3963 | 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 ) ) 3964 | } 3965 | 3966 | _perl() 3967 | { 3968 | local cur prev prefix temp 3969 | 3970 | COMPREPLY=() 3971 | cur=${COMP_WORDS[COMP_CWORD]} 3972 | prev=${COMP_WORDS[COMP_CWORD-1]} 3973 | prefix="" 3974 | 3975 | # completing an option (may or may not be separated by a space) 3976 | if [[ "$cur" == -?* ]]; then 3977 | temp=$cur 3978 | prev=${temp:0:2} 3979 | cur=${temp:2} 3980 | prefix=$prev 3981 | fi 3982 | 3983 | # only handle module completion for now 3984 | case "$prev" in 3985 | -m|-M) 3986 | _perlmodules 3987 | return 0 3988 | ;; 3989 | esac 3990 | 3991 | # handle case where first parameter is not a dash option 3992 | if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]]; then 3993 | _filedir 3994 | return 0 3995 | fi 3996 | 3997 | # complete using basic options 3998 | COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d -D -p \ 3999 | -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- $cur ) ) 4000 | return 0 4001 | } 4002 | complete -F _perl $default perl 4003 | 4004 | _perldoc() 4005 | { 4006 | local cur prev prefix temp 4007 | 4008 | COMPREPLY=() 4009 | cur=${COMP_WORDS[COMP_CWORD]} 4010 | prev=${COMP_WORDS[COMP_CWORD-1]} 4011 | prefix="" 4012 | 4013 | # completing an option (may or may not be separated by a space) 4014 | if [[ "$cur" == -?* ]]; then 4015 | temp=$cur 4016 | prev=${temp:0:2} 4017 | cur=${temp:2} 4018 | prefix=$prev 4019 | fi 4020 | 4021 | # complete builtin perl functions 4022 | case $prev in 4023 | -f) 4024 | COMPREPLY=( $( compgen -W 'chomp chop chr crypt hex index lc \ 4025 | lcfirst length oct ord pack q qq reverse rindex sprintf \ 4026 | substr tr uc ucfirst y m pos quotemeta s split study qr abs \ 4027 | atan2 cos exp hex int log oct rand sin sqrt srand pop push \ 4028 | shift splice unshift grep join map qw reverse sort unpack \ 4029 | delete each exists keys values binmode close closedir \ 4030 | dbmclose dbmopen die eof fileno flock format getc print \ 4031 | printf read readdir rewinddir seek seekdir select syscall \ 4032 | sysread sysseek syswrite tell telldir truncate warn write \ 4033 | pack read syscall sysread syswrite unpack vec -X chdir chmod \ 4034 | chown chroot fcntl glob ioctl link lstat mkdir open opendir \ 4035 | readlink rename rmdir stat symlink umask unlink utime caller \ 4036 | continue do dump eval exit goto last next redo return \ 4037 | sub wantarray caller import local my our package use defined \ 4038 | formline reset scalar undef \ 4039 | alarm exec fork getpgrp getppid getpriority kill pipe qx \ 4040 | setpgrp setpriority sleep system times wait waitpid \ 4041 | import no package require use bless dbmclose dbmopen package \ 4042 | ref tie tied untie use accept bind connect getpeername \ 4043 | getsockname getsockopt listen recv send setsockopt shutdown \ 4044 | socket socketpair msgctl msgget msgrcv msgsnd semctl semget \ 4045 | semop shmctl shmget shmread shmwrite endgrent endhostent \ 4046 | endnetent endpwent getgrent getgrgid getgrnam getlogin \ 4047 | getpwent getpwnam getpwuid setgrent setpwent endprotoent \ 4048 | endservent gethostbyaddr gethostbyname gethostent \ 4049 | getnetbyaddr getnetbyname getnetent getprotobyname \ 4050 | getprotobynumber getprotoent getservbyname getservbyport \ 4051 | getservent sethostent setnetent setprotoent setservent \ 4052 | gmtime localtime time times' -- $cur ) ) 4053 | return 0 4054 | ;; 4055 | esac 4056 | 4057 | case $cur in 4058 | -*) 4059 | COMPREPLY=( $( compgen -W '-h -v -t -u -m -l -F -X -f -q' -- $cur )) 4060 | return 0 4061 | ;; 4062 | *) 4063 | _perlmodules 4064 | 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 ) ) 4065 | 4066 | return 0 4067 | ;; 4068 | esac 4069 | } 4070 | complete -F _perldoc $default perldoc 4071 | } 4072 | 4073 | # rcs(1) completion 4074 | # 4075 | have rcs && 4076 | _rcs() 4077 | { 4078 | local cur prev file dir 4079 | 4080 | COMPREPLY=() 4081 | cur=${COMP_WORDS[COMP_CWORD]} 4082 | prev=${COMP_WORDS[COMP_CWORD-1]} 4083 | 4084 | file=${cur##*/} 4085 | dir=${cur%/*} 4086 | 4087 | # deal with relative directory 4088 | [ "$file" = "$dir" ] && dir=. 4089 | 4090 | COMPREPLY=( $( compgen -f "$dir/RCS/$file" ) ) 4091 | 4092 | for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do 4093 | file=${COMPREPLY[$i]##*/} 4094 | file=${file%,v} 4095 | dir=${COMPREPLY[$i]%RCS/*} 4096 | COMPREPLY[$i]=$dir$file 4097 | done 4098 | 4099 | # default to files if nothing returned and we're checking in. 4100 | # otherwise, default to directories 4101 | [ ${#COMPREPLY[@]} -eq 0 -a $1 = ci ] && _filedir || _filedir -d 4102 | } 4103 | [ -n "${have:-}" ] && complete -F _rcs $filenames ci co rlog rcs rcsdiff 4104 | 4105 | # lilo(8) completion 4106 | # 4107 | have lilo && 4108 | _lilo() 4109 | { 4110 | local cur prev 4111 | 4112 | COMPREPLY=() 4113 | cur=${COMP_WORDS[COMP_CWORD]} 4114 | prev=${COMP_WORDS[COMP_CWORD-1]} 4115 | 4116 | case $prev in 4117 | -@(C|i|m|s|S)) 4118 | _filedir 4119 | return 0 4120 | ;; 4121 | -r) 4122 | _filedir -d 4123 | return 0 4124 | ;; 4125 | -@(I|D|R)) 4126 | # label completion 4127 | COMPREPLY=( $( awk -F'=' '/label/ {print $2}' \ 4128 | /etc/lilo.conf | grep "^$cur" ) ) 4129 | return 0 4130 | ;; 4131 | -@(A|b|M|u|U)) 4132 | # device completion 4133 | cur=${cur:=/dev/} 4134 | _filedir 4135 | return 0 4136 | ;; 4137 | -T) 4138 | # topic completion 4139 | COMPREPLY=( $( compgen -W 'help ChRul EBDA geom geom= \ 4140 | table= video' -- $cur ) ) 4141 | return 0 4142 | ;; 4143 | esac 4144 | 4145 | if [[ "$cur" == -* ]]; then 4146 | # relevant options completion 4147 | COMPREPLY=( $( compgen -W '-A -b -c -C -d -f -g -i -I -l -L -m \ 4148 | -M -p -P -q -r -R -s -S -t -T -u -U -v -V -w -x -z' -- \ 4149 | $cur ) ) 4150 | fi 4151 | } 4152 | [ -n "${have:-}" ] && complete -F _lilo lilo 4153 | 4154 | # links completion 4155 | # 4156 | have links && 4157 | _links() 4158 | { 4159 | local cur 4160 | 4161 | COMPREPLY=() 4162 | cur=${COMP_WORDS[COMP_CWORD]} 4163 | 4164 | case "$cur" in 4165 | --*) 4166 | COMPREPLY=( $( compgen -W '--help' -- $cur ) ) 4167 | ;; 4168 | -*) 4169 | COMPREPLY=( $( compgen -W '-async-dns -max-connections \ 4170 | -max-connections-to-host -retries \ 4171 | -receive-timeout -unrestartable-receive-timeout\ 4172 | -format-cache-size -memory-cache-size \ 4173 | -http-proxy -ftp-proxy -download-dir \ 4174 | -assume-codepage -anonymous -dump -no-connect \ 4175 | -source -version -help' -- $cur ) ) 4176 | ;; 4177 | *) 4178 | if [ -r ~/.links/links.his ]; then 4179 | COMPREPLY=( $( compgen -W '$( < ~/.links/links.his )' \ 4180 | -- $cur ) ) 4181 | fi 4182 | _filedir '@(htm|html)' 4183 | return 0 4184 | ;; 4185 | esac 4186 | 4187 | return 0 4188 | } 4189 | [ -n "${have:-}" ] && complete -F _links $filenames links 4190 | 4191 | [ $UNAME = FreeBSD ] && { 4192 | # FreeBSD package management tool completion 4193 | # 4194 | _pkg_delete() 4195 | { 4196 | local cur pkgdir prev 4197 | 4198 | pkgdir=${PKG_DBDIR:-/var/db/pkg}/ 4199 | cur=${COMP_WORDS[COMP_CWORD]} 4200 | prev=${COMP_WORDS[COMP_CWORD-1]} 4201 | 4202 | test "$prev" = "-o" -o "$prev" = "-p" -o "$prev" = "-W" && return 0 4203 | 4204 | COMPREPLY=( $( compgen -d $pkgdir$cur ) ) 4205 | COMPREPLY=( ${COMPREPLY[@]#$pkgdir} ) 4206 | 4207 | return 0 4208 | } 4209 | complete -F _pkg_delete $dirnames pkg_delete pkg_info 4210 | have pkg_deinstall && complete -F _pkg_delete $dirnames pkg_deinstall 4211 | 4212 | # FreeBSD kernel module commands 4213 | # 4214 | _kldload() 4215 | { 4216 | local cur moddir 4217 | 4218 | moddir=/modules/ 4219 | [ -d $moddir ] || moddir=/boot/kernel/ 4220 | cur=${COMP_WORDS[COMP_CWORD]} 4221 | 4222 | COMPREPLY=( $( compgen -f $moddir$cur ) ) 4223 | COMPREPLY=( ${COMPREPLY[@]#$moddir} ) 4224 | COMPREPLY=( ${COMPREPLY[@]%.ko} ) 4225 | 4226 | return 0 4227 | } 4228 | complete -F _kldload $filenames kldload 4229 | 4230 | _kldunload() 4231 | { 4232 | local cur 4233 | cur=${COMP_WORDS[COMP_CWORD]} 4234 | COMPREPLY=( $(kldstat | sed -ne "s/^.*[ \t]\+\($cur[a-z_]\+\).ko$/\1/p") ) 4235 | } 4236 | complete -F _kldunload $filenames kldunload 4237 | } 4238 | 4239 | # FreeBSD portupgrade completion 4240 | # 4241 | have portupgrade && 4242 | _portupgrade() 4243 | { 4244 | local cur pkgdir prev 4245 | 4246 | pkgdir=${PKG_DBDIR:-/var/db/pkg}/ 4247 | cur=${COMP_WORDS[COMP_CWORD]} 4248 | prev=${COMP_WORDS[COMP_CWORD-1]} 4249 | 4250 | test "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" && return 0 4251 | 4252 | COMPREPLY=( $( compgen -d $pkgdir$cur ) ) 4253 | COMPREPLY=( ${COMPREPLY[@]#$pkgdir} ) 4254 | COMPREPLY=( ${COMPREPLY[@]%-*} ) 4255 | 4256 | return 0 4257 | } 4258 | [ -n "${have:-}" ] && complete -F _portupgrade $dirnames portupgrade 4259 | 4260 | # FreeBSD portinstall completion 4261 | # 4262 | have portinstall && 4263 | _portinstall() 4264 | { 4265 | local cur portsdir prev indexfile 4266 | local -a COMPREPLY2 4267 | 4268 | portsdir=${PORTSDIR:-/usr/ports}/ 4269 | cur=${COMP_WORDS[COMP_CWORD]} 4270 | prev=${COMP_WORDS[COMP_CWORD-1]} 4271 | # First try INDEX-5 4272 | indexfile=$portsdir/INDEX-5 4273 | # Then INDEX 4274 | test -f $indexfile || indexfile=$portsdir/INDEX 4275 | 4276 | [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0 4277 | 4278 | COMPREPLY=( $( egrep "^$cur" < $indexfile | cut -d'|' -f1 ) ) 4279 | COMPREPLY2=( $( egrep "^[^\|]+\|$portsdir$cur" < $indexfile | \ 4280 | cut -d'|' -f2 ) ) 4281 | COMPREPLY2=( ${COMPREPLY2[@]#$portsdir} ) 4282 | COMPREPLY=( ${COMPREPLY[@]} ${COMPREPLY2[@]} ) 4283 | 4284 | return 0 4285 | } 4286 | [ -n "${have:-}" ] && complete -F _portinstall $dirnames portinstall 4287 | 4288 | # Slackware Linux removepkg completion 4289 | # 4290 | have removepkg && [ -f /etc/slackware-version ] && 4291 | _removepkg() 4292 | { 4293 | local packages cur 4294 | 4295 | COMPREPLY=() 4296 | cur=${COMP_WORDS[COMP_CWORD]} 4297 | 4298 | COMPREPLY=( $( (cd /var/log/packages; compgen -f -- "$cur") ) ) 4299 | } 4300 | [ -n "${have:-}" ] && complete -F _removepkg $filenames removepkg && 4301 | complete $dirnames -f -X '!*.tgz' installpkg upgradepkg explodepkg 4302 | 4303 | # look(1) completion 4304 | # 4305 | have look && 4306 | _look() 4307 | { 4308 | local cur 4309 | 4310 | COMPREPLY=() 4311 | cur=${COMP_WORDS[COMP_CWORD]} 4312 | 4313 | if [ $COMP_CWORD = 1 ]; then 4314 | COMPREPLY=( $( compgen -W '$(look $cur)' ) ) 4315 | fi 4316 | } 4317 | [ -n "${have:-}" ] && complete -F _look $default look 4318 | 4319 | # ypcat(1) and ypmatch(1) completion 4320 | # 4321 | have ypmatch && 4322 | _ypmatch() 4323 | { 4324 | local cur map 4325 | 4326 | COMPREPLY=() 4327 | cur=${COMP_WORDS[COMP_CWORD]} 4328 | 4329 | [ $1 = ypcat ] && [ $COMP_CWORD -gt 1 ] && return 0 4330 | [ $1 = ypmatch ] && [ $COMP_CWORD -gt 2 ] && return 0 4331 | 4332 | if [ $1 = ypmatch ] && [ $COMP_CWORD -eq 1 ] && \ 4333 | [ ${#COMP_WORDS[@]} -eq 3 ]; then 4334 | map=${COMP_WORDS[2]} 4335 | COMPREPLY=( $( compgen -W '$( ypcat $map | \ 4336 | cut -d':' -f 1 )' -- $cur) ) 4337 | else 4338 | [ $1 = ypmatch ] && [ $COMP_CWORD -ne 2 ] && return 0 4339 | COMPREPLY=( $( compgen -W \ 4340 | '$( echo $(ypcat -x | cut -d"\"" -f 2))' -- $cur)) 4341 | fi 4342 | 4343 | return 0 4344 | } 4345 | [ -n "${have:-}" ] && complete -F _ypmatch ypmatch ypcat 4346 | 4347 | # mplayer(1) completion 4348 | # 4349 | have mplayer && { 4350 | _mplayer_options_list() 4351 | { 4352 | cur=${cur%\\} 4353 | COMPREPLY=( $( $1 $2 help 2> /dev/null | \ 4354 | sed -e '1,/^Available/d' | awk '{print $1}' | \ 4355 | sed -e 's/:$//' -e 's/^'${2#-}'$//' -e 's/<.*//' | \ 4356 | grep "^$cur" ) ) 4357 | } 4358 | 4359 | _mplayer() 4360 | { 4361 | local cmd cur prev skinsdir IFS=$' \t\n' i j k=0 4362 | 4363 | COMPREPLY=() 4364 | cmd=${COMP_WORDS[0]} 4365 | cur=${COMP_WORDS[COMP_CWORD]} 4366 | prev=${COMP_WORDS[COMP_CWORD-1]} 4367 | 4368 | case "$prev" in 4369 | -@(ac|afm|vc|vfm|ao|vo|vop|fstype)) 4370 | _mplayer_options_list mplayer $prev 4371 | return 0 4372 | ;; 4373 | -@(oac|ovc|of)) 4374 | _mplayer_options_list mencoder $prev 4375 | return 0 4376 | ;; 4377 | -audiofile) 4378 | _filedir '@(mp3|MP3|mpg|MPG|ogg|OGG|wav|WAV)' 4379 | return 0 4380 | ;; 4381 | -font) 4382 | _filedir '@(desc|ttf)' 4383 | return 0 4384 | ;; 4385 | -sub) 4386 | _filedir '@(srt|SRT|sub|SUB|txt|TXT|utf|UTF|rar|RAR)' 4387 | return 0 4388 | ;; 4389 | -vobsub) 4390 | _filedir '@(idx|IDX|ifo|IFO|sub|SUB)' 4391 | IFS=$'\t\n' 4392 | COMPREPLY=( $( for i in ${COMPREPLY[@]}; do 4393 | if [ -f $i -a -r $i ]; then 4394 | echo ${i%.*} 4395 | else 4396 | echo $i 4397 | fi 4398 | done ) ) 4399 | IFS=$' \t\n' 4400 | return 0 4401 | ;; 4402 | -ifo) 4403 | _filedir '@(ifo|IFO)' 4404 | return 0 4405 | ;; 4406 | -cuefile) 4407 | _filedir '@(bin|BIN|cue|CUE)' 4408 | return 0 4409 | ;; 4410 | -skin) 4411 | # if you don't have installed mplayer in /usr/local you 4412 | # may want to set the MPLAYER_SKINS_DIR global variable 4413 | if [ -n "$MPLAYER_SKINS_DIR" ]; then 4414 | skinsdir=$MPLAYER_SKINS_DIR 4415 | else 4416 | skinsdir=/usr/local/share/mplayer/Skin 4417 | fi 4418 | 4419 | IFS=$'\t\n' 4420 | for i in ~/.mplayer/Skin $skinsdir; do 4421 | if [ -d $i -a -r $i ]; then 4422 | for j in $( compgen -d $i/$cur ); do 4423 | COMPREPLY[$k]=${j#$i/} 4424 | k=$((++k)) 4425 | done 4426 | fi 4427 | done 4428 | IFS=$' \t\n' 4429 | return 0 4430 | ;; 4431 | -@(mixer|@(cdrom|dvd)-device|dvdauth|fb|zrdev)) 4432 | cur=${cur:=/dev/} 4433 | _filedir 4434 | return 0 4435 | ;; 4436 | -@(edl?(out)|lircconf|menu-cfg|playlist|csslib|dumpfile)| \ 4437 | -@(subfile|vobsub|aofile|fbmodeconfig|include|o|dvdkey)| \ 4438 | -passlogfile) 4439 | _filedir 4440 | return 0 4441 | ;; 4442 | -@(auto@(q|sync)|loop|menu-root|speed|sstep|aid|alang)| \ 4443 | -@(?(@(audio|sub)-)demuxer|bandwidth|cache|chapter)| \ 4444 | -@(dvd?(angle)|fps|frames|mc|passwd|user|sb|srate|ss|vcd)| \ 4445 | -@(vi?(d|vo)|ffactor|sid|slang|spu@(align|aa|gauss))| \ 4446 | -@(vobsubid|delay|bpp|brightness|contrast|dfbopts|display)| \ 4447 | -@(fbmode|geometry|guiwid|hue|icelayer|screen[wh]|wid)| \ 4448 | -@(monitor@(aspect|_@(dotclock|[hv]freq))|panscan|saturation)| \ 4449 | -@(xineramascreen|zr@(crop|norm|quality|[xy]doff|[vh]dec))| \ 4450 | -@(aspect|pp|x|y|xy|z|stereo|audio-@(density|delay|preload))| \ 4451 | -@(endpos|osdlevel|ffourcc|sws|channels|skiplimit|format)| \ 4452 | -@(ofps|aa@(driver|@(osd|sub)color)|vobsubout?(i@(ndex|d)))| \ 4453 | -sub@(-bg-@(alpha|color)|cp|delay|fps|pos|align|width)| \ 4454 | -sub@(font-@(blur|outline|autoscale|encoding|@(osd|text)-scale))) 4455 | return 0 4456 | ;; 4457 | -lavdopts) 4458 | COMPREPLY=( $( compgen -W 'ec er= bug= idct= gray' \ 4459 | -- $cur ) ) 4460 | return 0 4461 | ;; 4462 | -lavcopts) 4463 | COMPREPLY=( $( compgen -W 'vcodec= vqmin= vqscale= \ 4464 | vqmax= mbqmin= mbqmax= vqdiff= \ 4465 | vmax_b_frames= vme= vhq v4mv \ 4466 | keyint= vb_strategy= vpass= \ 4467 | aspect= vbitrate= vratetol= \ 4468 | vrc_maxrate= vrc_minrate= \ 4469 | vrc_buf_size= vb_qfactor= vi_qfactor= \ 4470 | vb_qoffset= vi_qoffset= vqblur= \ 4471 | vqcomp= vrc_eq= vrc_override= \ 4472 | vrc_init_cplx= vqsquish= vlelim= \ 4473 | vcelim= vstrict= vdpart vpsize= gray \ 4474 | vfdct= idct= lumi_mask= dark_mask= \ 4475 | tcplx_mask= scplx_mask= naq ildct \ 4476 | format= pred qpel precmp= cmp= \ 4477 | subcmp= predia= dia= trell last_pred= \ 4478 | preme= subq= psnr mpeg_quant aic umv' \ 4479 | -- $cur ) ) 4480 | return 0 4481 | ;; 4482 | -ssf) 4483 | COMPREPLY=( $( compgen -W 'lgb= cgb= ls= cs= chs= \ 4484 | cvs=' -- $cur ) ) 4485 | return 0 4486 | ;; 4487 | -jpeg) 4488 | COMPREPLY=( $( compgen -W 'noprogressive progressive \ 4489 | nobaseline baseline optimize= \ 4490 | smooth= quality= outdir=' -- $cur ) ) 4491 | return 0 4492 | ;; 4493 | -xvidopts) 4494 | COMPREPLY=( $( compgen -W 'dr2 nodr2' -- $cur ) ) 4495 | return 0 4496 | ;; 4497 | -xvidencopts) 4498 | COMPREPLY=( $( compgen -W 'pass= bitrate= \ 4499 | fixed_quant= me_quality= 4mv \ 4500 | rc_reaction_delay_factor= \ 4501 | rc_averaging_period= rc_buffer= \ 4502 | quant_range= min_key_interval= \ 4503 | max_key_interval= mpeg_quant \ 4504 | mod_quant lumi_mask hintedme \ 4505 | hintfile debug keyframe_boost= \ 4506 | kfthreshold= kfreduction=' -- $cur ) ) 4507 | return 0 4508 | ;; 4509 | -divx4opts) 4510 | COMPREPLY=( $( compgen -W 'br= key= deinterlace q= \ 4511 | min_quant= max_quant= rc_period= \ 4512 | rc_reaction_period= crispness= \ 4513 | rc_reaction_ratio= pass= vbrpass= \ 4514 | help' -- $cur ) ) 4515 | return 0 4516 | ;; 4517 | -info) 4518 | COMPREPLY=( $( compgen -W 'name= artist= genre= \ 4519 | subject= copyright= srcform= \ 4520 | comment= help' -- $cur ) ) 4521 | return 0 4522 | ;; 4523 | -lameopts) 4524 | COMPREPLY=( $( compgen -W 'vbr= abr cbr br= q= aq= \ 4525 | ratio= vol= mode= padding= fast \ 4526 | preset= help' -- $cur ) ) 4527 | return 0 4528 | ;; 4529 | -rawaudio) 4530 | COMPREPLY=( $( compgen -W 'on channels= rate= \ 4531 | samplesize= format=' -- $cur ) ) 4532 | return 0 4533 | ;; 4534 | -rawvideo) 4535 | COMPREPLY=( $( compgen -W 'on fps= sqcif qcif cif \ 4536 | 4cif pal ntsc w= h= y420 yv12 yuy2 \ 4537 | y8 format= size=' -- $cur ) ) 4538 | return 0 4539 | ;; 4540 | -aop) 4541 | COMPREPLY=( $( compgen -W 'list= delay= format= fout= \ 4542 | volume= mul= softclip' -- $cur ) ) 4543 | return 0 4544 | ;; 4545 | -dxr2) 4546 | COMPREPLY=( $( compgen -W 'ar-mode= iec958-encoded \ 4547 | iec958-decoded mute ucode= 75ire bw \ 4548 | color interlaced macrovision= norm= \ 4549 | square-pixel ccir601-pixel cr-left= \ 4550 | cr-right= cr-top= cr-bot= ck-rmin= \ 4551 | ck-gmin= ck-bmin= ck-rmax= ck-gmax= \ 4552 | ck-bmax= ck-r= ck-g= ck-b= \ 4553 | ignore-cache= ol-osd= olh-cor= \ 4554 | olw-cor= olx-cor= oly-cor= overlay \ 4555 | overlay-ratio= update-cache' -- $cur ) ) 4556 | return 0 4557 | ;; 4558 | -tv) 4559 | COMPREPLY=( $( compgen -W 'on noaudio driver= device= \ 4560 | input= freq= outfmt= width= height= \ 4561 | buffersize= norm= channel= chanlist= \ 4562 | audiorate= forceaudio alsa amode= \ 4563 | forcechan= adevice= audioid= volume= \ 4564 | bass= treble= balance= fps= \ 4565 | channels= immediatemode=' -- $cur ) ) 4566 | return 0 4567 | ;; 4568 | -mf) 4569 | COMPREPLY=( $( compgen -W 'on w= h= fps= type=' -- $cur ) ) 4570 | return 0 4571 | ;; 4572 | -cdda) 4573 | COMPREPLY=( $( compgen -W 'speed= paranoia= \ 4574 | generic-dev= sector-size= overlap= \ 4575 | toc-bias toc-offset= skip noskip' \ 4576 | -- $cur ) ) 4577 | return 0 4578 | ;; 4579 | -input) 4580 | COMPREPLY=( $( compgen -W 'conf= ar-delay ar-rate \ 4581 | keylist cmdlist js-dev file' -- $cur ) ) 4582 | return 0 4583 | ;; 4584 | -af) 4585 | COMPREPLY=( $( compgen -W 'resample resample= \ 4586 | channels channels= format format= \ 4587 | volume volume= delay delay= pan \ 4588 | pan= sub sub= surround surround=' \ 4589 | -- $cur ) ) 4590 | return 0 4591 | ;; 4592 | -af-adv) 4593 | COMPREPLY=( $( compgen -W 'force= list=' -- $cur ) ) 4594 | return 0 4595 | ;; 4596 | esac 4597 | 4598 | case "$cur" in 4599 | -*) 4600 | COMPREPLY=( $( compgen -W '-aid -alang -audio-demuxer \ 4601 | -audiofile -cdrom-device -cache -cdda \ 4602 | -channels -chapter -csslib -demuxer \ 4603 | -dvd -dvd-device -dvdangle -dvdauth \ 4604 | -dvdkey -dvdnav -forceidx -fps -frames \ 4605 | -hr-mp3-seek -idx -mc -mf -ni -nobps \ 4606 | -passwd -rawaudio -rtsp-stream-over-tcp\ 4607 | -skipopening -sb -srate -ss -tv -user \ 4608 | -vcd -vid -vivo -ifo -ffactor -font \ 4609 | -noautosub -nooverlapsub -sid -slang \ 4610 | -sub -subcc -subcp -sub-demuxer \ 4611 | -subdelay -subfont-autoscale \ 4612 | -subfont-blur -subfont-encoding \ 4613 | -subfont-osd-scale -subfont-outline \ 4614 | -subfont-text-scale -subfps -subfile \ 4615 | -subpos -unicode -utf8 -vobsub \ 4616 | -vobsubid -ac -afm -aspect -flip \ 4617 | -lavdopts -noaspect -nosound -pp -ssf \ 4618 | -stereo -sws -vc -vfm -vop -xvidopts\ 4619 | -xy -zoom -bandwidth -cuefile \ 4620 | -noextbased -rawvideo -overlapsub \ 4621 | -sub-bg-alpha -sub-bg-color -subalign \ 4622 | -subwidth -sub-no-text-pp -spualign \ 4623 | -spuaa -spugauss -pphelp -verbose -v \ 4624 | -noni -noidx -nohr-mp3-seek -extbased \ 4625 | -bps -oldpp -nozoom -noflip -nounicode \ 4626 | -noutf8' -- $cur ) ) 4627 | # add mplayer specific options 4628 | [[ "$cmd" == @(?(g)mplayer) ]] && COMPREPLY=( ${COMPREPLY[@]} \ 4629 | $(compgen -W '-autoq -autosync -benchmark \ 4630 | -framedrop -h -help -hardframedrop \ 4631 | -identify -input -lircconf -loop \ 4632 | -nojoystick -nolirc -nortc -playlist \ 4633 | -quiet -really-quiet -rnd -sdp -skin \ 4634 | -slave -softsleep -speed -sstep \ 4635 | -use-stdin -dumpaudio -dumpfile \ 4636 | -dumpstream -dumpvideo -dumpmicrodvdsub\ 4637 | -dumpmpsub -dumpsrtsub -dumpjacosub \ 4638 | -dumpsami -dumpsub -osdlevel -af \ 4639 | -af-adv -ao -aofile -aop -delay -mixer \ 4640 | -nowaveheader -bpp -brightness \ 4641 | -contrast -display -double -dr -dxr2 \ 4642 | -fb -fbmode -fbmodeconfig -forcexv -fs \ 4643 | -geometry -hue -icelayer -jpeg \ 4644 | -monitor_dotclock -monitor_hfreq \ 4645 | -monitor_vfreq -monitoraspect \ 4646 | -nograbpointer -noslices -panscan \ 4647 | -rootwin -saturation -screenw -screenh \ 4648 | -stop_xscreensaver -vm -vo -vsync -wid \ 4649 | -xineramascreen -z -zrbw -zrcrop \ 4650 | -zrdev -zrfd -zrhelp -zrnorm -zrquality \ 4651 | -zrvdec -zrhdec -zrxdoff -zrydoff -y \ 4652 | -edl -edlout -enqueue -fixed-vo \ 4653 | -menu -menu-root -menu-cfg -shuffle \ 4654 | -format -aahelp -dfbopts -fstype \ 4655 | -guiwid -nokeepaspect -x --help \ 4656 | -aaosdcolor -aasubcolor -aadriver \ 4657 | -aaextended -aaeight' -- $cur) ) 4658 | # add mencoder specific options 4659 | [[ "$cmd" = mencoder ]] && COMPREPLY=( ${COMPREPLY[@]} \ 4660 | $(compgen -W '-audio-density -audio-delay \ 4661 | -audio-preload -divx4opts -endpos \ 4662 | -ffourcc -include -info -lameopts \ 4663 | -lavcopts -noskip -o -oac -ofps -ovc \ 4664 | -passlogfile -skiplimit -vobsubout \ 4665 | -vobsuboutindex -vobsuboutid \ 4666 | -xvidencopts -of --verbose' -- $cur) ) 4667 | ;; 4668 | *) 4669 | _filedir '@(mpg|mpeg|MPG|MPEG|wma|avi|AVI|asf|vob|bin|dat|vcd|ps|pes|fli|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp3|MP3|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV|dump|DUMP)' 4670 | ;; 4671 | esac 4672 | 4673 | return 0 4674 | } 4675 | } 4676 | [ -n "${have:-}" ] && complete $filenames -F _mplayer mplayer mencoder gmplayer 4677 | 4678 | # KDE dcop completion 4679 | # 4680 | have dcop && 4681 | _dcop() 4682 | { 4683 | local cur compstr 4684 | 4685 | COMPREPLY=() 4686 | cur=${COMP_WORDS[COMP_CWORD]} 4687 | if [ -z $cur ]; then 4688 | compstr=${COMP_WORDS[*]} 4689 | else 4690 | compstr=$( command echo ${COMP_WORDS[*]} | sed "s/ $cur$//" ) 4691 | fi 4692 | COMPREPLY=( $( compgen -W '$( command $compstr | sed s/\(.*\)// )' -- $cur ) ) 4693 | } 4694 | [ "${have:-}" ] && complete -F _dcop dcop 4695 | 4696 | # wvdial(1) completion 4697 | # 4698 | have wvdial && 4699 | _wvdial() 4700 | { 4701 | local cur prev configfile i 4702 | 4703 | COMPREPLY=() 4704 | cur=${COMP_WORDS[COMP_CWORD]} 4705 | prev=${COMP_WORDS[COMP_CWORD-1]} 4706 | 4707 | case $prev in 4708 | --config) 4709 | _filedir 4710 | return 0 4711 | ;; 4712 | esac 4713 | 4714 | case $cur in 4715 | -*) 4716 | COMPREPLY=( $( compgen -W '--config --chat \ 4717 | --remotename --help --version --no-syslog' -- $cur ) ) 4718 | ;; 4719 | *) 4720 | # find which config file to use 4721 | configfile=/etc/wvdial.conf 4722 | for (( i=1; i < COMP_CWORD; i++ )); do 4723 | if [[ "${COMP_WORDS[i]}" == $1 ]]; then 4724 | configfile=${COMP_WORDS[i+1]} 4725 | break 4726 | fi 4727 | done 4728 | [ ! -f $configfile ] && return 0 4729 | # parse config file for sections 4730 | COMPREPLY=( $( awk '/\[Dialer .+\]/ {print $0}' $configfile |\ 4731 | sed -e '1d' -e 's/^\[Dialer //' -e 's/\]$//' | grep "^$cur" ) ) 4732 | ;; 4733 | esac 4734 | 4735 | } 4736 | [ -n "${have:-}" ] && complete -F _wvdial wvdial 4737 | 4738 | # gpg(1) completion 4739 | # 4740 | have gpg && 4741 | _gpg() 4742 | { 4743 | local cur prev 4744 | 4745 | COMPREPLY=() 4746 | cur=${COMP_WORDS[COMP_CWORD]} 4747 | prev=${COMP_WORDS[COMP_CWORD-1]} 4748 | 4749 | case "$prev" in 4750 | -@(s|-sign|-clearsign|-decrypt-files|-load-extension)) 4751 | _filedir 4752 | return 0 4753 | ;; 4754 | --@(export|@(?(l|nr|nrl)sign|edit)-key)) 4755 | # return list of public keys 4756 | COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*/\([^ ]*\).*\(<\([^>]*\)>\).*$@\1 \3@p')" -- "$cur" )) 4757 | return 0 4758 | ;; 4759 | -@(r|-recipient)) 4760 | COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*<\([^>]*\)>.*$@\1@p')" -- "$cur" )) 4761 | if [ -e ~/.gnupg/gpg.conf ]; then 4762 | COMPREPLY=( ${COMPREPLY[@]} $( compgen -W "$( sed -ne 's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' ~/.gnupg/gpg.conf )" -- "$cur") ) 4763 | fi 4764 | return 0 4765 | ;; 4766 | esac 4767 | 4768 | if [[ "$cur" == -* ]]; then 4769 | COMPREPLY=( $( compgen -W '-s -b -e -f -c -d -a -r -u -Z -o -v \ 4770 | -q -n -N --sign --clearsign --detach-sign \ 4771 | --encrypt --encrypt-files --symmetric --store \ 4772 | --decrypt --decrypt-files --verify --list-keys \ 4773 | --list-sigs --check-sigs --fingerprint \ 4774 | --list-secret-keys --gen-key --delete-keys \ 4775 | --delete-secret-keys --sign-key --lsign-key \ 4776 | --nrsign-key --nrlsign-key --edit-key \ 4777 | --gen-revoke --export --send-key --recv-keys \ 4778 | --search-keys --refresh-keys --import \ 4779 | --list-packets --export-ownertrust \ 4780 | --import-ownertrust --update-trustdb \ 4781 | --check-trustdb --fix-trustdb --dearmor \ 4782 | --enarmor --print-md --armor --recipient \ 4783 | --default-recipient --default-recipient-self \ 4784 | --local-user --textmode --output --verbose \ 4785 | --quiet --no-tty --force-v3-sigs \ 4786 | --no-force-v3-sigs --force-v4-certs \ 4787 | --no-force-v4-certs --force-mdc --disable-mdc \ 4788 | --dry-run --use-agent --batch --yes --no \ 4789 | --keyring --secret-keyring --show-keyring \ 4790 | --default-key --keyserver --charset --options \ 4791 | --status-fd --trusted-key --load-extension \ 4792 | --rfc1991 --openpgp --pgp2 --s2k-mode \ 4793 | --s2k-digest-algo --s2k-cipher-algo \ 4794 | --cipher-algo --digest-algo --compress-algo \ 4795 | --throw-keyid --show-photos --no-show-photos \ 4796 | --photo-viewer --notation-data' -- $cur ) ) 4797 | fi 4798 | 4799 | } 4800 | [ "${have:-}" ] && complete -F _gpg $default gpg 4801 | 4802 | # iconv(1) completion 4803 | # 4804 | have iconv && 4805 | _iconv() 4806 | { 4807 | local cur prev 4808 | 4809 | COMPREPLY=() 4810 | cur=${COMP_WORDS[COMP_CWORD]} 4811 | prev=${COMP_WORDS[COMP_CWORD-1]} 4812 | 4813 | if [[ "$cur" = -* ]]; then 4814 | COMPREPLY=( $( compgen -W '--from-code -f --to-code -t --list 4815 | --output -o --verbose' -- "$cur" ) ) 4816 | return 0 4817 | fi 4818 | 4819 | 4820 | if [[ "$prev" == -@(f|t|-@(from|to)-code) ]]; then 4821 | COMPREPLY=( $( compgen -W \ 4822 | '$( iconv --list | sed "1,/^$/d; s@//@@;" )' -- "$cur" ) ) 4823 | fi 4824 | 4825 | return 0 4826 | } 4827 | [ -n "${have:-}" ] && complete -F _iconv $default iconv 4828 | 4829 | # dict(1) completion 4830 | # 4831 | { have dict || have rdict; } && { 4832 | _dictdata() 4833 | { 4834 | dict $host $port $1 2>/dev/null | sed -ne \ 4835 | 's/^['$'\t '']['$'\t '']*\([^'$'\t '']*\).*$/\1/p' 4836 | } 4837 | 4838 | _dict() 4839 | { 4840 | local cur prev host port db dictfile 4841 | 4842 | COMPREPLY=() 4843 | cur=${COMP_WORDS[COMP_CWORD]} 4844 | prev=${COMP_WORDS[COMP_CWORD-1]} 4845 | dictfile=/usr/share/dict/words 4846 | 4847 | for (( i=1; i < COMP_CWORD; i++ )); do 4848 | case "${COMP_WORDS[i]}" in 4849 | -@(h|--host)) 4850 | host=${COMP_WORDS[i+1]} 4851 | [ -n "$host" ] && host="-h $host" 4852 | i=$((++i)) 4853 | ;; 4854 | -@(p|-port)) 4855 | port=${COMP_WORDS[i+1]} 4856 | [ -n "$port" ] && port="-p $port" 4857 | i=$((++i)) 4858 | ;; 4859 | -@(d|-database)) 4860 | db=${COMP_WORDS[i+1]} 4861 | [ -n "$db" ] && host="-d $db" 4862 | i=$((++i)) 4863 | ;; 4864 | *) 4865 | ;; 4866 | esac 4867 | done 4868 | 4869 | if [[ "$cur" = -* ]]; then 4870 | COMPREPLY=( $( compgen -W '-h --host -p --port -d --database \ 4871 | -m --match -s --strategy -c --config -C \ 4872 | --nocorrect -D --dbs -S --strats -H \ 4873 | --serverhelp -i --info -I --serverinfo \ 4874 | -a --noauth -u --user -k --key -V --version \ 4875 | -L --license --help -v --verbose -r --raw \ 4876 | -P --pager --debug --html --pipesize --client' \ 4877 | -- "$cur" ) ) 4878 | return 0 4879 | fi 4880 | 4881 | case "$prev" in 4882 | -@(d|-database|i|info)) 4883 | COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) ) 4884 | return 0 4885 | ;; 4886 | -@(s|-strategy)) 4887 | COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) ) 4888 | return 0 4889 | ;; 4890 | *) 4891 | ;; 4892 | esac 4893 | 4894 | [ -r $dictfile ] && \ 4895 | COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) ) 4896 | } 4897 | complete -F _dict $default dict rdict 4898 | } 4899 | 4900 | # cdrecord(1) completion 4901 | # 4902 | have cdrecord && 4903 | _cdrecord() 4904 | { 4905 | local cur prev i generic_options track_options track_mode 4906 | 4907 | COMPREPLY=() 4908 | cur=${COMP_WORDS[COMP_CWORD]} 4909 | prev=${COMP_WORDS[COMP_CWORD-1]} 4910 | 4911 | # foo=bar style option 4912 | if [[ "$cur" == *=* ]]; then 4913 | prev=${cur/=*/} 4914 | cur=${cur/*=/} 4915 | case "$prev" in 4916 | @(text|cue)file) 4917 | _filedir 4918 | return 0 4919 | ;; 4920 | blank) 4921 | COMPREPLY=( $( compgen -W 'help all fast \ 4922 | track unreserve trtail unclose session' \ 4923 | -- $cur ) ) 4924 | return 0 4925 | ;; 4926 | driveropts) 4927 | COMPREPLY=( $( compgen -W 'burnfree noburnfree\ 4928 | varirec= audiomaster forcespeed noforcespeed\ 4929 | speedread nospeedread singlesession \ 4930 | nosinglesession hidecdr nohidecdr tattooinfo\ 4931 | tattoofile=' -- $cur ) ) 4932 | return 0 4933 | ;; 4934 | esac 4935 | fi 4936 | 4937 | generic_options=(-version -v -V -d -silent -s -force -immed -dummy \ 4938 | -dao -raw -raw96r -raw96p -raw16 -multi -msinfo -toc \ 4939 | -atip -fix -nofix -waiti -load -lock -eject -format \ 4940 | -setdropts -checkdrive -prcap -inq -scanbus -reset \ 4941 | -abort -overburn -ignsize -useinfo -packet -noclose \ 4942 | -text debug= kdebug= kd= minbuf= speed= blank= fs= \ 4943 | dev= gracetime= timeout= driver= driveropts= \ 4944 | defpregap= pktsize= mcn= textfile= cuefile=) 4945 | track_options=(-audio -swab -data -mode2 -xa -xa1 -xa2 -xamix -cdi \ 4946 | -isosize -pad padsize= -nopad -shorttrack -noshorttrack\ 4947 | pregap= -preemp -nopreemp -copy -nocopy -scms tcsize= \ 4948 | isrc= index=) 4949 | # look if previous was either a file or a track option 4950 | track_mode=0 4951 | if [ $COMP_CWORD -gt 1 ]; then 4952 | if [ -f "$prev" ]; then 4953 | track_mode=1 4954 | else 4955 | for (( i=0; i < ${#track_options[@]}; i++ )); do 4956 | if [[ "${track_options[i]}" == "$prev" ]]; then 4957 | track_mode=1 4958 | break 4959 | fi 4960 | done 4961 | fi 4962 | fi 4963 | 4964 | # files are always eligible completion 4965 | _filedir 4966 | # track options are always available 4967 | COMPREPLY=( ${COMPREPLY[@]} $( compgen -W '${track_options[@]}' -- $cur ) ) 4968 | # general options are no more available after file or track option 4969 | if [ $track_mode -eq 0 ]; then 4970 | COMPREPLY=( ${COMPREPLY[@]} \ 4971 | $( compgen -W '${generic_options[@]}' -- $cur ) ) 4972 | fi 4973 | 4974 | } 4975 | [ -n "${have:-}" ] && complete -F _cdrecord cdrecord 4976 | 4977 | # mkisofs(8) completion 4978 | # 4979 | have mkisofs && 4980 | _mkisofs() 4981 | { 4982 | local cur prev 4983 | 4984 | COMPREPLY=() 4985 | cur=${COMP_WORDS[COMP_CWORD]} 4986 | prev=${COMP_WORDS[COMP_CWORD-1]} 4987 | 4988 | case "$prev" in 4989 | -@(o|abstract|biblio|check-session|copyright|log-file|root-info|prep-boot|*-list)) 4990 | _filedir 4991 | return 0 4992 | ;; 4993 | -*-charset) 4994 | COMPREPLY=( $( mkisofs -input-charset help 2>&1 | \ 4995 | tail +3 | grep "^$cur") ) 4996 | return 0 4997 | ;; 4998 | -uid) 4999 | _uids 5000 | return 0 5001 | ;; 5002 | -gid) 5003 | _gids 5004 | return 0 5005 | ;; 5006 | esac 5007 | 5008 | if [[ "$cur" == -* ]]; then 5009 | COMPREPLY=( $( compgen -W '-abstract -A -allow-lowercase \ 5010 | -allow-multidot -biblio -cache-inodes \ 5011 | -no-cache-inodes -b -eltorito-alt-boot -B -G \ 5012 | -hard-disk-boot -no-emul-boot -no-boot \ 5013 | -boot-load-seg -boot-load-size \ 5014 | -boot-info-table -C -c -check-oldname \ 5015 | -check-session -copyright -d -D -dir-mode \ 5016 | -dvd-video-f -file-mode -gid -gui \ 5017 | -graft-points -hide -hide-list -hidden \ 5018 | -hidden-list -hide-joliet -hide-joliet-list \ 5019 | -hide-joliet-trans-tbl -hide-rr-moved \ 5020 | -input-charset -output-charset -iso-level -J \ 5021 | -joliet-long -jcharset -l -L -log-file -m \ 5022 | -exclude-list -max-iso9660-filenames -M -N \ 5023 | -new-dir-mode -nobak -no-bak -force-rr -no-rr \ 5024 | -no-split-symlink-components \ 5025 | -no-split-symlink-fields -o -pad -no-pad \ 5026 | -path-list -P -p -print-size -quiet -R -r \ 5027 | -relaxed-filenames -sort -split-output \ 5028 | -stream-media-size -stream-file-name -sysid -T\ 5029 | -table-name -ucs-level -udf -uid \ 5030 | -use-fileversion -U -no-iso-translate -V \ 5031 | -volset -volset-size -volset-seqno -v -x -z \ 5032 | -hfs -apple -map -magic -hfs-creator \ 5033 | -hfs-type -probe -no-desktop -mac-name \ 5034 | -boot-hfs-file -part -auto -cluster-size \ 5035 | -hide-hfs -hide-hfs-list -hfs-volid \ 5036 | -icon-position -root-info -prep-boot \ 5037 | -input-hfs-charset -output-hfs-charset \ 5038 | -hfs-unlock -hfs-bless -hfs-parms --cap \ 5039 | --netatalk --double --ethershare --ushare \ 5040 | --exchange --sgi --xinet --macbin --single \ 5041 | --dave --sfm --osx-double --osx-hfs' -- $cur )) 5042 | else 5043 | _filedir 5044 | fi 5045 | 5046 | } 5047 | [ -n "${have:-}" ] && complete -F _mkisofs mkisofs 5048 | 5049 | # mc(1) completion 5050 | # 5051 | have mc && 5052 | _mc() 5053 | { 5054 | local cur prev 5055 | 5056 | COMPREPLY=() 5057 | cur=${COMP_WORDS[COMP_CWORD]} 5058 | prev=${COMP_WORDS[COMP_CWORD-1]} 5059 | 5060 | if [ "$prev" = "-e" -o "$prev" = "-v" ]; then 5061 | _filedir 5062 | else 5063 | _filedir -d 5064 | fi 5065 | } 5066 | [ "${have:-}" ] && complete -F _mc $filenames mc 5067 | 5068 | # yum(8) completion 5069 | # 5070 | have yum && 5071 | _yum() 5072 | { 5073 | local cur 5074 | COMPREPLY=() 5075 | cur=${COMP_WORDS[COMP_CWORD]} 5076 | prev=${COMP_WORDS[COMP_CWORD-1]} 5077 | 5078 | case "$prev" in 5079 | -c) 5080 | _filedir 5081 | return 0 5082 | ;; 5083 | --installroot) 5084 | _filedir -d 5085 | return 0 5086 | ;; 5087 | esac 5088 | 5089 | case "$cur" in 5090 | --*) 5091 | COMPREPLY=( $( compgen -W '--installroot --version --help' -- \ 5092 | $cur ) ) 5093 | ;; 5094 | -*) 5095 | COMPREPLY=( $( compgen -W '-c -e -d -y -t -R -C -h' -- $cur ) ) 5096 | ;; 5097 | *) 5098 | COMPREPLY=( $( compgen -W 'update upgrade install info remove \ 5099 | list clean provides check-update \ 5100 | groupinstall groupupdate grouplist' -- \ 5101 | $cur ) ) 5102 | ;; 5103 | esac 5104 | 5105 | return 0 5106 | 5107 | } 5108 | [ -n "${have:-}" ] && complete -F _yum $filenames yum 5109 | 5110 | # yum-arch(8) completion 5111 | # 5112 | _yum_arch() 5113 | { 5114 | local cur 5115 | COMPREPLY=() 5116 | cur=${COMP_WORDS[COMP_CWORD]} 5117 | 5118 | case "$cur" in 5119 | -*) 5120 | COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- $cur ) ) 5121 | ;; 5122 | *) 5123 | _filedir -d 5124 | ;; 5125 | esac 5126 | 5127 | return 0 5128 | 5129 | } 5130 | complete -F _yum_arch $filenames yum-arch 5131 | 5132 | _filedir_xspec() 5133 | { 5134 | local IFS cur xspec 5135 | 5136 | IFS=$'\t\n' 5137 | COMPREPLY=() 5138 | cur=${COMP_WORDS[COMP_CWORD]} 5139 | 5140 | _expand || return 0 5141 | 5142 | # get first exclusion compspec that matches this command 5143 | xspec=$( sed -ne '/ '${1##*/}'/{p;q;}' $BASH_COMPLETION ) 5144 | # prune to leave nothing but the -X spec 5145 | xspec=${xspec#*-X } 5146 | xspec=${xspec%% *} 5147 | 5148 | COMPREPLY=( $( eval compgen -f -X "$xspec" -- \ 5149 | \"${cur#[\`\"\']}\" 2>/dev/null ) \ 5150 | $( compgen -d -- $cur ) ) 5151 | } 5152 | list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' \ 5153 | $BASH_COMPLETION | \ 5154 | # read exclusion compspecs 5155 | ( 5156 | while read line 5157 | do 5158 | # ignore compspecs that are commented out 5159 | if [ "${line#\#}" != "$line" ]; then continue; fi 5160 | line=${line%# START exclude*} 5161 | line=${line%# FINISH exclude*} 5162 | line=${line##*\'} 5163 | list=( ${list[@]:-} $line ) 5164 | done 5165 | echo ${list[@]} 5166 | ) 5167 | ) ) 5168 | # remove previous compspecs 5169 | if [ ${#list[@]} -gt 0 ]; then 5170 | eval complete -r ${list[@]} 5171 | # install new compspecs 5172 | eval complete -F _filedir_xspec $filenames ${list[@]} 5173 | fi 5174 | unset list 5175 | 5176 | # source completion directory definitions 5177 | if [ -d $BASH_COMPLETION_DIR -a -r $BASH_COMPLETION_DIR -a \ 5178 | -x $BASH_COMPLETION_DIR ]; then 5179 | for i in $BASH_COMPLETION_DIR/*; do 5180 | [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*) ]] && 5181 | [ -f $i -a -r $i ] && . $i 5182 | done 5183 | fi 5184 | unset i 5185 | 5186 | # source user completion file 5187 | [ $BASH_COMPLETION != ~/.bash_completion -a -r ~/.bash_completion ] \ 5188 | && . ~/.bash_completion 5189 | unset -f have 5190 | unset UNAME RELEASE have default dirnames filenames nospace bashdefault plusdirs 5191 | 5192 | ### Local Variables: 5193 | ### mode: shell-script 5194 | ### End: 5195 | --------------------------------------------------------------------------------