bash-completion/bash_completion

1807 lines
56 KiB
Bash
Raw Normal View History

#
# bash_completion - programmable completion functions for bash 3.x
2009-10-04 10:46:01 -07:00
# (backwards compatible with bash 2.05b)
#
2008-06-21 13:37:16 -07:00
# Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
# © 2009, Bash Completion Maintainers
# <bash-completion-devel@lists.alioth.debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The latest version of this software can be obtained here:
#
2008-06-21 13:37:16 -07:00
# http://bash-completion.alioth.debian.org/
#
2009-10-22 01:17:10 -07:00
# RELEASE: 2.x
2002-01-05 12:04:01 -08:00
if [[ $- == *v* ]]; then
2009-10-04 10:42:50 -07:00
BASH_COMPLETION_ORIGINAL_V_VALUE="-v"
else
2009-10-04 10:42:50 -07:00
BASH_COMPLETION_ORIGINAL_V_VALUE="+v"
fi
if [[ -n $BASH_COMPLETION_DEBUG ]]; then
2009-10-04 10:42:50 -07:00
set -v
else
2009-10-04 10:42:50 -07:00
set +v
fi
# Alter the following to reflect the location of this file.
#
[ -n "$BASH_COMPLETION" ] || BASH_COMPLETION=/etc/bash_completion
[ -n "$BASH_COMPLETION_DIR" ] || BASH_COMPLETION_DIR=/etc/bash_completion.d
[ -n "$BASH_COMPLETION_COMPAT_DIR" ] || BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d
readonly BASH_COMPLETION BASH_COMPLETION_DIR BASH_COMPLETION_COMPAT_DIR
# Set a couple of useful vars
#
UNAME=$( uname -s )
# strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
UNAME=${UNAME/CYGWIN_*/Cygwin}
2003-10-06 23:02:00 -07:00
case ${UNAME} in
2009-10-04 10:42:50 -07:00
Linux|GNU|GNU/*) USERLAND=GNU ;;
*) USERLAND=${UNAME} ;;
esac
# Turn on extended globbing and programmable completion
shopt -s extglob progcomp
# A lot of the following one-liners were taken directly from the
# completion examples provided with the bash 2.04 source distribution
# Make directory commands see only directories
complete -d pushd
# The following section lists completions that are redefined later
# Do NOT break these over multiple lines.
#
# START exclude -- do NOT remove this line
2009-08-18 01:45:47 -07:00
# bzcmp, bzdiff, bz*grep, bzless, bzmore intentionally not here, see Debian: #455510
complete -f -X '!*.?(t)bz?(2)' bunzip2 bzcat
complete -f -X '!*.@(zip|ZIP|jar|JAR|exe|EXE|pk3|war|wsz|ear|zargo|xpi|sxw|ott|od[fgpst]|epub)' unzip zipinfo
complete -f -X '*.Z' compress znew
# zcmp, zdiff, z*grep, zless, zmore intentionally not here, see Debian: #455510
2009-08-18 01:45:47 -07:00
complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' gunzip zcat
complete -f -X '!*.Z' uncompress
# lzcmp, lzdiff intentionally not here, see Debian: #455510
complete -f -X '!*.lzma' lzcat lzegrep lzfgrep lzgrep lzless lzmore unlzma
complete -f -X '!*.@(xz|lzma)' unxz xzcat
complete -f -X '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' ee
complete -f -X '!*.@(gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|GIF|JPG|JP?(E)G|TIF?(F)|PNG|P[BGP]M|BMP|X[BP]M|RLE|RGB|PCX|FITS|PM)' xv qiv
complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv kghostview
complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi
2008-05-01 13:22:11 -07:00
complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' kdvi
2008-05-01 13:59:32 -07:00
complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype dvipdf advi dvipdfm dvipdfmx
2008-05-01 13:22:11 -07:00
complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf
complete -f -X '!*.@(?(e)ps|?(E)PS|pdf|PDF)' kpdf
complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF|dvi|DVI)?(.gz|.GZ|.bz2|.BZ2)|cb[rz]|CB[RZ]|djv?(u)|DJV?(U)|dvi|DVI|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX|fdf|FDF)' evince
complete -f -X '!*.@(okular|@(?(e|x)ps|?(E|X)PS|pdf|PDF|dvi|DVI|cb[rz]|CB[RZ]|djv?(u)|DJV?(U)|dvi|DVI|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX|epub|EPUB|odt|ODT|fb|FB|mobi|MOBI|g3|G3|chm|CHM|fdf|FDF)?(.?(gz|GZ|bz2|BZ2)))' okular
complete -f -X '!*.@(?(e)ps|?(E)PS|pdf|PDF)' ps2pdf ps2pdf12 ps2pdf13 ps2pdf14 ps2pdfwr
complete -f -X '!*.texi*' makeinfo texi2html
complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi
complete -f -X '!*.@(mp3|MP3)' mpg123 mpg321 madplay
complete -f -X '!*@(.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp[234]|MP[234]|m4[pv]|M4[PV]|mkv|MKV|og[gmv]|OG[GMV]|wav|WAV|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9]).@(vdr|VDR))' xine aaxine fbxine kaffeine
complete -f -X '!*.@(avi|asf|wmv)' aviplay
complete -f -X '!*.@(rm?(j)|ra?(m)|smi?(l))' realplay
complete -f -X '!*.@(mpg|mpeg|avi|mov|qt)' xanim
complete -f -X '!*.@(ogg|OGG|m3u|flac|spx)' ogg123
complete -f -X '!*.@(mp3|MP3|ogg|OGG|pls|m3u)' gqmpeg freeamp
complete -f -X '!*.fig' xfig
complete -f -X '!*.@(mid?(i)|MID?(I)|cmf|CMF)' playmidi
complete -f -X '!*.@(mid?(i)|MID?(I)|rmi|RMI|rcp|RCP|[gr]36|[GR]36|g18|G18|mod|MOD|xm|XM|it|IT|x3m|X3M|s[3t]m|S[3T]M|kar|KAR)' timidity
2009-04-14 04:26:22 -07:00
complete -f -X '!*.@(m[eo]d|M[EO]D|s[3t]m|S[3T]M|xm|XM|it|IT)' modplugplay
2008-06-22 10:57:44 -07:00
complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' vi vim gvim rvim view rview rgvim rgview gview
complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' emacs
complete -f -X '!*.@(exe|EXE|com|COM|scr|SCR|exe.so)' wine
complete -f -X '!*.@(zip|ZIP|z|Z|gz|GZ|tgz|TGZ)' bzme
complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx opera galeon curl dillo elinks amaya
complete -f -X '!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|odt|ott|odm)' oowriter
complete -f -X '!*.@(sxi|sti|pps?(x)|ppt?([mx])|pot?([mx])|odp|otp)' ooimpress
2009-07-02 12:57:01 -07:00
complete -f -X '!*.@(sxc|stc|xls?([bmx])|xlw|xlt?([mx])|[ct]sv|ods|ots)' oocalc
complete -f -X '!*.@(sxd|std|sda|sdd|odg|otg)' oodraw
complete -f -X '!*.@(sxm|smf|mml|odf)' oomath
complete -f -X '!*.odb' oobase
complete -f -X '!*.rpm' rpm2cpio
2009-01-11 14:35:56 -08:00
complete -f -X '!*.sqlite' sqlite3
2009-02-03 11:32:07 -08:00
complete -f -X '!*.aux' bibtex
complete -f -X '!*.po' poedit gtranslator kbabel lokalize
complete -f -X '!*.@([Pp][Rr][Gg]|[Cc][Ll][Pp])' harbour gharbour hbpp
complete -f -X '!*.[Hh][Rr][Bb]' hbrun
complete -f -X '!*.ly' lilypond ly2dvi
# FINISH exclude -- do not remove this line
# start of section containing compspecs that can be handled within bash
# user commands see only users
complete -u su passwd write chfn groups slay w sux
# bg completes with stopped jobs
complete -A stopped -P '"%' -S '"' bg
# other job commands
complete -j -P '"%' -S '"' fg jobs disown
# readonly and unset complete with shell variables
complete -v readonly unset
# set completes with set options
complete -A setopt set
# shopt completes with shopt options
complete -A shopt shopt
# helptopics
complete -A helptopic help
# unalias completes with aliases
complete -a unalias
# bind completes with readline bindings (make this more intelligent)
complete -A binding bind
# type and which complete on commands
complete -c command type which
2004-05-11 09:06:08 -07:00
# builtin completes on builtins
complete -b builtin
# start of section containing completion functions called by other functions
# This function checks whether we have a given program on the system.
# No need for bulky functions in memory if we don't.
#
have()
{
2009-10-04 10:42:50 -07:00
unset -v have
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
have="yes"
}
# use GNU sed if we have it, since its extensions are still used in our code
#
[ $USERLAND != GNU ] && have gsed && alias sed=gsed
# This function checks whether a given readline variable
# is `on'.
#
2008-05-06 12:20:14 -07:00
_rl_enabled()
{
[[ "$( bind -v )" = *$1+([[:space:]])on* ]]
}
# This function shell-quotes the argument
quote()
{
2009-10-04 10:42:50 -07:00
echo \'${1//\'/\'\\\'\'}\' #'# Help vim syntax highlighting
}
# @see _quote_readline_by_ref()
quote_readline()
{
local quoted
_quote_readline_by_ref "$1" ret
printf %s "$ret"
} # quote_readline()
# This function shell-dequotes the argument
dequote()
{
2009-10-04 10:46:01 -07:00
eval echo "$1" 2> /dev/null
}
# Reassemble command line words, excluding specified characters from the
# list of word completion separators (COMP_WORDBREAKS).
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
# NOT be considered word breaks. This is useful for things like scp where
# we want to return host:path and not only path, so we would pass the
# colon (:) as $1 here.
# @param $2 words Name of variable to return words to
# @param $3 cword Name of variable to return cword to
#
__reassemble_comp_words_by_ref() {
local exclude i j ref
# Exclude word separator characters?
if [[ $1 ]]; then
# Yes, exclude word separator characters;
# Exclude only those characters, which were really included
exclude="${1//[^$COMP_WORDBREAKS]}"
fi
# Are characters excluded which were former included?
if [[ $exclude ]]; then
# Yes, list of word completion separators has shrunk;
# Re-assemble words to complete
for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
# Is current word not word 0 (the command itself) and is word made up of
# just word separator characters to be excluded?
while [[ $i -gt 0 && ${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]} ]]; do
[ $j -ge 2 ] && ((j--))
# Append word separator to current word
ref="$2[$j]"
eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
# Indicate new cword
[ $i = $COMP_CWORD ] && eval $3=$j
# Indicate next word if available, else end *both* while and for loop
(( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2
done
# Append word to current word
ref="$2[$j]"
eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
# Indicate new cword
[ $i = $COMP_CWORD ] && eval $3=$j
done
else
# No, list of word completions separators hasn't changed;
eval $2=\( \"\${COMP_WORDS[@]}\" \)
eval $3=$COMP_CWORD
fi
} # __reassemble_comp_words_by_ref()
# Get the word to complete.
# This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases
# where the user is completing in the middle of a word.
# (For example, if the line is "ls foobar",
# and the cursor is here --------> ^
# @param $1 string Characters out of $COMP_WORDBREAKS which should NOT be
# considered word breaks. This is useful for things like scp where
# we want to return host:path and not only path, so we would pass the
# colon (:) as $1 in this case. Bash-3 doesn't do word splitting, so this
# ensures we get the same word on both bash-3 and bash-4.
# @param $2 integer Index number of word to return, negatively offset to the
# current word (default is 0, previous is 1), respecting the exclusions
2009-12-24 05:31:19 -08:00
# given at $1. For example, `_get_cword "=:" 1' returns the word left of
# the current word, respecting the exclusions "=:".
#
_get_cword()
{
local cword words
__reassemble_comp_words_by_ref "$1" words cword
# return previous word offset by $2
if [[ ${2//[^0-9]/} ]]; then
printf "%s" "${words[cword-$2]}"
elif [[ "${#words[cword]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then
printf "%s" "${words[cword]}"
2009-10-04 10:42:50 -07:00
else
local i
local cur="$COMP_LINE"
local index="$COMP_POINT"
for (( i = 0; i <= cword; ++i )); do
2009-10-04 10:42:50 -07:00
while [[
# Current word fits in $cur?
"${#cur}" -ge ${#words[i]} &&
# $cur doesn't match cword?
"${cur:0:${#words[i]}}" != "${words[i]}"
]]; do
2009-10-04 10:42:50 -07:00
# Strip first character
cur="${cur:1}"
# Decrease cursor position
((index--))
2009-10-04 10:42:50 -07:00
done
# Does found word matches cword?
if [[ "$i" -lt "$cword" ]]; then
# No, cword lies further;
2009-10-04 10:42:50 -07:00
local old_size="${#cur}"
cur="${cur#${words[i]}}"
2009-10-04 10:42:50 -07:00
local new_size="${#cur}"
index=$(( index - old_size + new_size ))
2009-10-04 10:42:50 -07:00
fi
done
if [[ "${words[cword]:0:${#cur}}" != "$cur" ]]; then
2009-10-04 10:42:50 -07:00
# We messed up! At least return the whole word so things
# keep working
printf "%s" "${words[cword]}"
2009-10-04 10:42:50 -07:00
else
printf "%s" "${cur:0:$index}"
fi
fi
} # _get_cword()
# Get word previous to the current word.
# This is a good alternative to `prev=${COMP_WORDS[COMP_CWORD-1]}' because bash4
# will properly return the previous word with respect to any given exclusions to
# COMP_WORDBREAKS.
# @see _get_cword()
#
_get_pword() { _get_cword "${@:-}" 1; }
# If the word-to-complete contains a colon (:), left-trim COMPREPLY items with
# word-to-complete.
# On bash-3, and bash-4 with a colon in COMP_WORDBREAKS, words containing
# colons are always completed as entire words if the word to complete contains
# a colon. This function fixes this, by removing the colon-containing-prefix
# from COMPREPLY items.
# The preferred solution is to remove the colon (:) from COMP_WORDBREAKS in
# your .bashrc:
#
# # Remove colon (:) from list of word completion separators
# COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
#
# See also: Bash FAQ - E13) Why does filename completion misbehave if a colon
# appears in the filename? - http://tiswww.case.edu/php/chet/bash/FAQ
# @param $1 current word to complete (cur)
# @modifies global array $COMPREPLY
#
__ltrim_colon_completions() {
# If word-to-complete contains a colon,
# and bash-version < 4,
# or bash-version >= 4 and COMP_WORDBREAKS contains a colon
if [[
"$1" == *:* && (
${BASH_VERSINFO[0]} -lt 4 ||
(${BASH_VERSINFO[0]} -ge 4 && "$COMP_WORDBREAKS" == *:*)
)
]]; then
# Remove colon-word prefix from COMPREPLY items
local colon_word=${1%${1##*:}}
local i=${#COMPREPLY[*]}
while [ $((--i)) -ge 0 ]; do
COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
done
fi
} # __ltrim_colon_completions()
# This function quotes the argument in a way so that readline dequoting
# results in the original argument. This is necessary for at least
# `compgen' which requires its arguments quoted/escaped:
#
# $ ls "a'b/"
# c
# $ compgen -f "a'b/" # Wrong, doesn't return output
# $ compgen -f "a\'b/" # Good (bash-4)
# a\'b/c
# $ compgen -f "a\\\\\'b/" # Good (bash-3)
# a\'b/c
#
# See also: http://lists.gnu.org/archive/html/bug-bash/2009-03/msg00155.html
# @param $1 Argument to quote
# @param $2 Name of variable to return result to
_quote_readline_by_ref()
{
# If bash <= 3 and argument starts with single quote ('), double-escape
# if [[ ${BASH_VERSINFO[0]} -le 3 && ${1:0:1} == "'" ]]; then
# local t
# printf -v t %q "${1:1}"
# printf -v $2 %q "$t"
# else
# printf -v $2 %q "$1"
# fi
if [[ ${1:0:1} == "'" ]]; then
# Quote word, leaving out first character
printf -v $2 %q "${1:1}"
if [[ ${BASH_VERSINFO[0]} -le 3 ]]; then
# Double-quote word on bash-3
printf -v $2 %q ${!2}
fi
elif [[ ${BASH_VERSINFO[0]} -le 3 && ${1:0:1} == '"' ]]; then
printf -v $2 %q "${1:1}"
else
printf -v $2 %q "$1"
fi
} # _quote_readline_by_ref()
# This function performs file and directory completion. It's better than
# simply using 'compgen -f', because it honours spaces in filenames.
# If passed -d, it completes only on directories. If passed anything else,
# it's assumed to be a file glob to complete on.
#
_filedir()
{
local i IFS=$'\t\n' xspec
2009-10-04 10:42:50 -07:00
__expand_tilde_by_ref cur
2009-10-04 10:42:50 -07:00
local -a toks
local quoted tmp
2009-10-04 10:42:50 -07:00
2009-12-20 14:09:02 -08:00
# TODO: I've removed a "[ -n $tmp ] &&" before `printf '%s\n' $tmp',
2009-10-04 10:42:50 -07:00
# and everything works again. If this bug
# suddenly appears again (i.e. "cd /b<TAB>"
# becomes "cd /"), remember to check for
# other similar conditionals (here and
# _filedir_xspec()). --David
# NOTE: The comment above has been moved outside of the subshell below,
# because quotes-in-comments-in-a-subshell cause errors on
# bash-3.1. See also:
# http://www.mail-archive.com/bug-bash@gnu.org/msg01667.html
_quote_readline_by_ref "$cur" quoted
2009-10-04 10:42:50 -07:00
toks=( ${toks[@]-} $(
compgen -d -- "$quoted" | {
2009-10-18 03:38:04 -07:00
while read -r tmp; do
2009-12-20 14:09:02 -08:00
printf '%s\n' $tmp
2009-10-18 03:38:04 -07:00
done
}
))
# On bash-3, special characters need to be escaped extra. This is
# unless the first character is a single quote ('). If the single
# quote appears further down the string, bash default completion also
# fails, e.g.:
#
# $ ls 'a&b/'
# f
# $ foo 'a&b/<TAB> # Becomes: foo 'a&b/f'
# $ foo a'&b/<TAB> # Nothing happens
#
2009-10-18 03:38:04 -07:00
if [[ "$1" != -d ]]; then
xspec=${1:+"!*.$1"}
if [[ ${cur:0:1} == "'" && ${BASH_VERSINFO[0]} -ge 4 ]]; then
toks=( ${toks[@]-} $(
eval compgen -f -X \"\$xspec\" -- $quoted
) )
else
toks=( ${toks[@]-} $(
compgen -f -X "$xspec" -- $quoted
) )
fi
if [ ${#toks[@]} -ne 0 ]; then
# If `compopt' is available, set `-o filenames'
compopt &>/dev/null && compopt -o filenames ||
# No, `compopt' isn't available;
# Is `-o filenames' set?
[[ "$(complete -p ${COMP_WORDS[0]})" == *"-o filenames"* ]] || {
# No, `-o filenames' isn't set;
# Emulate `-o filenames'
# NOTE: A side-effect of emulating `-o filenames' is that backslash escape
# characters are visible within the list of presented completions, e.g.
# the completions look like:
#
# $ foo a<TAB>
# a\ b/ a\$b/
#
# whereas with `-o filenames' active the completions look like:
#
# $ ls a<TAB>
# a b/ a$b/
#
for ((i=0; i < ${#toks[@]}; i++)); do
# If directory exists, append slash (/)
if [[ ${cur:0:1} != "'" ]]; then
[[ -d ${toks[i]} ]] && toks[i]="${toks[i]}"/
if [[ ${cur:0:1} == '"' ]]; then
toks[i]=${toks[i]//\\/\\\\}
toks[i]=${toks[i]//\"/\\\"}
toks[i]=${toks[i]//\$/\\\$}
else
toks[i]=$(printf %q ${toks[i]})
fi
fi
2009-10-18 03:38:04 -07:00
done
}
fi
2009-10-04 10:42:50 -07:00
fi
COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )
2009-10-18 03:38:04 -07:00
} # _filedir()
# This function splits $cur=--foo=bar into $prev=--foo, $cur=bar, making it
# easier to support both "--foo bar" and "--foo=bar" style completions.
# Returns 0 if current option was split, 1 otherwise.
#
_split_longopt()
{
2009-10-04 10:42:50 -07:00
if [[ "$cur" == --?*=* ]]; then
# Cut also backslash before '=' in case it ended up there
# for some reason.
prev="${cur%%?(\\)=*}"
cur="${cur#*=}"
return 0
fi
return 1
}
# This function tries to parse the output of $command --help
#
_parse_help() {
2009-10-04 10:42:50 -07:00
local cmd
cmd=$1
$cmd --help | command grep -- "^[[:space:]]*-" | tr "," " " | \
2009-11-03 14:24:28 -08:00
awk '{print $1; if ($2 ~ /-.*/) { print $2 } }' | sed -e "s:=.*::g"
}
# This function completes on signal names
#
_signals()
{
2009-10-04 10:42:50 -07:00
local i
# standard signal completion is rather braindead, so we need
# to hack around to get what we want here, which is to
# complete on a dash, followed by the signal name minus
# the SIG prefix
COMPREPLY=( $( compgen -A signal SIG${cur#-} ))
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=-${COMPREPLY[i]#SIG}
done
}
# This function completes on configured network interfaces
#
_configured_interfaces()
{
2009-10-04 10:42:50 -07:00
if [ -f /etc/debian_version ]; then
# Debian system
2009-11-03 12:04:46 -08:00
COMPREPLY=( $( compgen -W "$( sed -ne 's|^iface \([^ ]\{1,\}\).*$|\1|p'\
/etc/network/interfaces )" -- "$cur" ) )
2009-10-04 10:42:50 -07:00
elif [ -f /etc/SuSE-release ]; then
# SuSE system
2009-12-20 13:44:33 -08:00
COMPREPLY=( $( compgen -W "$( printf '%s\n' \
/etc/sysconfig/network/ifcfg-* | \
sed -ne 's|.*ifcfg-\(.*\)|\1|p' )" -- "$cur" ) )
2009-10-04 10:42:50 -07:00
elif [ -f /etc/pld-release ]; then
# PLD Linux
COMPREPLY=( $( compgen -W "$( command ls -B \
/etc/sysconfig/interfaces | \
sed -ne 's|.*ifcfg-\(.*\)|\1|p' )" -- "$cur" ) )
2009-10-04 10:42:50 -07:00
else
# Assume Red Hat
2009-12-20 13:44:33 -08:00
COMPREPLY=( $( compgen -W "$( printf '%s\n' \
/etc/sysconfig/network-scripts/ifcfg-* | \
sed -ne 's|.*ifcfg-\(.*\)|\1|p' )" -- "$cur" ) )
2009-10-04 10:42:50 -07:00
fi
}
2009-01-25 13:39:09 -08:00
# This function completes on available kernels
#
_kernel_versions()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -W '$( command ls /lib/modules )' -- "$cur" ) )
}
# This function completes on all available network interfaces
# -a: restrict to active interfaces only
# -w: restrict to wireless interfaces only
#
_available_interfaces()
{
2009-10-04 10:42:50 -07:00
local cmd
if [ "${1:-}" = -w ]; then
cmd="iwconfig"
elif [ "${1:-}" = -a ]; then
cmd="ifconfig"
else
cmd="ifconfig -a"
fi
COMPREPLY=( $( eval PATH="$PATH:/sbin" $cmd 2>/dev/null | \
awk '/^[^[:space:]]/ { print $1 }' ) )
COMPREPLY=( $( compgen -W '${COMPREPLY[@]/%[[:punct:]]/}' -- "$cur" ) )
}
# Expand variable starting with tilde (~)
# Only the first portion of the variable from the tilde up to the first slash
# (~../) is expanded. The remainder of the variable, containing for example
# a dollar sign variable ($) or asterisk (*) is not expanded.
# Example usage:
#
# $ v="~"; __expand_tilde v; echo "$v"
#
# Example output:
#
# v output
# -------- ----------------
# ~ /home/user
# ~foo/bar /home/foo/bar
# ~foo/$HOME /home/foo/$HOME
# ~foo/a b /home/foo/a b
# ~foo/* /home/foo/*
#
# @param $1 Name of variable (not the value of the variable) to expand
__expand_tilde_by_ref() {
# Does $1 start with tilde (~)?
if [ "${!1:0:1}" = "~" ]; then
# Does $1 contain slash (/)?
if [ "${!1}" != "${!1//\/}" ]; then
# Yes, $1 contains slash;
# 1: Remove * including and after first slash (/), i.e. "~a/b"
# becomes "~a". Double quotes allow eval.
# 2: Remove * before the first slash (/), i.e. "~a/b"
# becomes "b". Single quotes prevent eval.
# +-----1----+ +---2----+
eval $1="${!1/%\/*}"/'${!1#*/}'
else
# No, $1 doesn't contain slash
eval $1="${!1}"
fi
fi
} # __expand_tilde_by_ref()
# This function expands tildes in pathnames
#
_expand()
{
2009-10-04 10:42:50 -07:00
# FIXME: Why was this here?
#[ "$cur" != "${cur%\\}" ] && cur="$cur\\"
# Expand ~username type directory specifications. We want to expand
# ~foo/... to /home/foo/... to avoid problems when $cur starting with
# a tilde is fed to commands and ending up quoted instead of expanded.
if [[ "$cur" == \~*/* ]]; then
eval cur=$cur
elif [[ "$cur" == \~* ]]; then
cur=${cur#\~}
COMPREPLY=( $( compgen -P '~' -u "$cur" ) )
[ ${#COMPREPLY[@]} -eq 1 ] && eval COMPREPLY[0]=${COMPREPLY[0]}
return ${#COMPREPLY[@]}
fi
}
# This function completes on process IDs.
# AIX and Solaris ps prefers X/Open syntax.
[[ $UNAME == SunOS || $UNAME == AIX ]] &&
_pids()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -W '$( command ps -efo pid | sed 1d )' -- "$cur" ))
} ||
_pids()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -W '$( command ps axo pid= )' -- "$cur" ) )
}
# This function completes on process group IDs.
# AIX and SunOS prefer X/Open, all else should be BSD.
[[ $UNAME == SunOS || $UNAME == AIX ]] &&
_pgids()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -W '$( command ps -efo pgid | sed 1d )' -- "$cur" ))
} ||
_pgids()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -W '$( command ps axo pgid= )' -- "$cur" ))
}
# This function completes on process names.
# AIX and SunOS prefer X/Open, all else should be BSD.
[[ $UNAME == SunOS || $UNAME == AIX ]] &&
_pnames()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -W '$( command ps -efo comm | \
2009-11-03 14:24:28 -08:00
sed -e 1d -e "s:.*/::" -e "s/^-//" -e "s/^<defunct>$//")' -- "$cur" ) )
} ||
_pnames()
{
2009-10-04 10:42:50 -07:00
# FIXME: completes "[kblockd/0]" to "0". Previously it was completed
# to "kblockd" which isn't correct either. "kblockd/0" would be
# arguably most correct, but killall from psmisc 22 treats arguments
# containing "/" specially unless -r is given so that wouldn't quite
# work either. Perhaps it'd be best to not complete these to anything
# for now.
# Not using "ps axo comm" because under some Linux kernels, it
# truncates command names (see e.g. http://bugs.debian.org/497540#19)
COMPREPLY=( $( compgen -W '$( command ps axo command= | \
2009-11-03 14:24:28 -08:00
sed -e "s/ .*//" -e "s:.*/::" -e "s/:$//" -e "s/^[[(-]//" \
-e "s/[])]$//" -e "s/^<defunct>$//")' -- "$cur" ) )
}
# This function completes on user IDs
#
_uids()
{
2009-10-04 10:42:50 -07:00
if type getent &>/dev/null; then
COMPREPLY=( $( compgen -W '$( getent passwd | cut -d: -f3 )' -- "$cur" ) )
elif type perl &>/dev/null; then
COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- "$cur" ) )
else
# make do with /etc/passwd
COMPREPLY=( $( compgen -W '$( cut -d: -f3 /etc/passwd )' -- "$cur" ) )
fi
}
# This function completes on group IDs
#
_gids()
{
2009-10-04 10:42:50 -07:00
if type getent &>/dev/null; then
COMPREPLY=( $( compgen -W '$( getent group | cut -d: -f3 )' \
-- "$cur" ) )
2009-10-04 10:42:50 -07:00
elif type perl &>/dev/null; then
COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- "$cur" ) )
else
# make do with /etc/group
COMPREPLY=( $( compgen -W '$( cut -d: -f3 /etc/group )' -- "$cur" ) )
2009-10-04 10:42:50 -07:00
fi
}
# This function completes on services
#
_services()
{
2009-10-04 10:42:50 -07:00
local sysvdir famdir
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
famdir=/etc/xinetd.d
2009-12-20 14:09:02 -08:00
COMPREPLY=( $( printf '%s\n' \
$sysvdir/!(*.rpm@(orig|new|save)|*~|functions) ) )
2009-10-04 10:42:50 -07:00
if [ -d $famdir ]; then
2009-12-20 14:09:02 -08:00
COMPREPLY=( "${COMPREPLY[@]}" $( printf '%s\n' \
$famdir/!(*.rpm@(orig|new|save)|*~) ) )
2009-10-04 10:42:50 -07:00
fi
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- "$cur" ) )
}
2009-01-25 13:39:09 -08:00
# This function completes on modules
#
_modules()
{
2009-10-04 10:42:50 -07:00
local modpath
modpath=/lib/modules/$1
COMPREPLY=( $( compgen -W "$( command ls -R $modpath | \
sed -ne 's/^\(.*\)\.k\?o\(\|.gz\)$/\1/p' )" -- "$cur" ) )
}
# This function completes on installed modules
#
_installed_modules()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -W "$( PATH="$PATH:/sbin" lsmod | \
awk '{if (NR != 1) print $1}' )" -- "$1" ) )
}
2009-01-25 13:39:09 -08:00
# This function completes on user:group format
#
_usergroup()
{
2009-10-04 10:42:50 -07:00
local IFS=$'\n'
cur=${cur//\\\\ / }
if [[ $cur = *@(\\:|.)* ]]; then
2009-10-04 10:42:50 -07:00
user=${cur%%*([^:.])}
COMPREPLY=( $(compgen -P ${user/\\\\} -g -- ${cur##*[.:]}) )
elif [[ $cur = *:* ]]; then
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -g -- ${cur##*[.:]} ) )
else
type compopt &>/dev/null && compopt -o nospace
2009-10-04 10:42:50 -07:00
COMPREPLY=( $( compgen -S : -u -- "$cur" ) )
fi
}
# This function completes on valid shells
#
_shells()
{
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W \
'$( command grep "^[[:space:]]*/" /etc/shells 2>/dev/null )' \
-- "$cur" ) )
}
# Get real command.
# - arg: $1 Command
# - stdout: Filename of command in PATH with possible symbolic links resolved.
# Empty string if command not found.
# - return: True (0) if command found, False (> 0) if not.
_realcommand() {
2009-10-04 10:42:50 -07:00
type -P "$1" > /dev/null && {
2009-10-18 03:38:04 -07:00
if type -p realpath > /dev/null; then
realpath "$(type -P "$1")"
elif type -p readlink > /dev/null; then
readlink -f "$(type -P "$1")"
else
type -P "$1"
fi
}
}
# This function counts the number of args
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
# NOT be considered word breaks. See __reassemble_comp_words_by_ref.
_count_args()
{
local i cword words
__reassemble_comp_words_by_ref "$1" words cword
2009-10-04 10:42:50 -07:00
args=1
for i in "${words[@]:1:cword-1}"; do
[[ "$i" != -* ]] && args=$(($args+1))
2009-10-04 10:42:50 -07:00
done
}
2009-06-12 10:45:35 -07:00
# This function completes on PCI IDs
#
_pci_ids()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -W \
2009-11-03 14:24:28 -08:00
"$( PATH="$PATH:/sbin" lspci -n | awk '{print $3}')" -- "$cur" ) )
}
2009-06-12 10:45:35 -07:00
# This function completes on USB IDs
#
_usb_ids()
{
2009-10-04 10:42:50 -07:00
COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -W \
2009-11-03 14:24:28 -08:00
"$( PATH="$PATH:/sbin" lsusb | awk '{print $6}' )" -- "$cur" ) )
}
# CD device names
_cd_devices()
{
COMPREPLY=( "${COMPREPLY[@]}"
$( compgen -f -d -X "!*/?([amrs])cd*" -- "${cur:-/dev/}" ) )
}
# DVD device names
_dvd_devices()
{
COMPREPLY=( "${COMPREPLY[@]}"
$( compgen -f -d -X "!*/?(r)dvd*" -- "${cur:-/dev/}" ) )
}
# start of section containing completion functions for external programs
2003-08-03 16:40:25 -07:00
# a little help for FreeBSD ports users
2009-11-03 14:24:28 -08:00
[ $UNAME = FreeBSD ] && complete -W 'index search fetch fetch-list extract \
patch configure build install reinstall deinstall clean clean-depends \
kernel buildworld' make
2003-08-03 16:40:25 -07:00
# This completes on a list of all available service scripts for the
# 'service' command and/or the SysV init.d directory, followed by
# that script's available commands
#
{ have service || [ -d /etc/init.d/ ]; } &&
2009-10-18 03:38:04 -07:00
_service()
{
local cur prev sysvdir
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
COMPREPLY=()
prev=${COMP_WORDS[COMP_CWORD-1]}
cur=`_get_cword`
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# don't complete for things like killall, ssh and mysql if it's
# the standalone command, rather than the init script
[[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# don't complete past 2nd token
[ $COMP_CWORD -gt 2 ] && return 0
2009-10-04 10:42:50 -07:00
2009-11-03 14:24:28 -08:00
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then
_services
else
COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
2009-11-03 14:24:28 -08:00
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
$sysvdir/${prev##*/} 2>/dev/null`' -- "$cur" ) )
2009-10-18 03:38:04 -07:00
fi
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
return 0
} &&
complete -F _service service
[ -d /etc/init.d/ ] && complete -F _service -o default \
2009-12-20 14:09:02 -08:00
$(for i in /etc/init.d/*; do printf '%s\n' ${i##*/}; done)
2009-10-18 03:38:04 -07:00
# chown(1) completion
#
_chown()
{
local cur prev split=false
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
_split_longopt && split=true
case "$prev" in
--from)
_usergroup
return 0
;;
--reference)
_filedir
return 0
;;
esac
$split && return 0
# options completion
if [[ "$cur" == -* ]]; then
2009-11-03 14:24:28 -08:00
COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes --dereference \
--no-dereference --from --silent --quiet --reference --recursive \
--verbose --help --version' -- "$cur" ) )
2009-10-18 03:38:04 -07:00
else
_count_args
case $args in
1)
2009-10-04 10:42:50 -07:00
_usergroup
;;
2009-10-18 03:38:04 -07:00
*)
2009-10-04 10:42:50 -07:00
_filedir
;;
esac
2009-10-18 03:38:04 -07:00
fi
} # _chown()
complete -F _chown -o filenames chown
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# chgrp(1) completion
#
_chgrp()
{
local cur prev split=false
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
COMPREPLY=()
cur=`_get_cword`
cur=${cur//\\\\/}
prev=${COMP_WORDS[COMP_CWORD-1]}
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
_split_longopt && split=true
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
if [[ "$prev" == --reference ]]; then
_filedir
return 0
fi
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
$split && return 0
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# options completion
if [[ "$cur" == -* ]]; then
2009-11-03 14:24:28 -08:00
COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes --dereference \
--no-dereference --silent --quiet --reference --recursive \
--verbose --help --version' -- "$cur" ) )
2009-10-18 03:38:04 -07:00
return 0
fi
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# first parameter on line or first since an option?
if [[ $COMP_CWORD -eq 1 && "$cur" != -* || "$prev" == -* ]]; then
2009-10-18 03:38:04 -07:00
local IFS=$'\n'
COMPREPLY=( $( compgen -g "$cur" 2>/dev/null ) )
else
_filedir || return 0
fi
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
return 0
} # _chgrp()
complete -F _chgrp -o filenames chgrp
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# umount(8) completion. This relies on the mount point being the third
# space-delimited field in the output of mount(8)
#
_umount()
{
local cur IFS=$'\n'
COMPREPLY=()
cur=`_get_cword`
COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- "$cur" ) )
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
return 0
}
complete -F _umount -o dirnames umount
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# mount(8) completion. This will pull a list of possible mounts out of
# /etc/{,v}fstab, unless the word being completed contains a ':', which
# would indicate the specification of an NFS server. In that case, we
# query the server for a list of all available exports and complete on
# that instead.
#
_mount()
{
local cur i sm host prev
COMPREPLY=()
cur=`_get_cword`
[[ "$cur" == \\ ]] && cur="/"
prev=${COMP_WORDS[COMP_CWORD-1]}
for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done
if [[ -n "$sm" && "$cur" == *:* ]]; then
COMPREPLY=( $( compgen -W "$( $sm -e ${cur%%:*} | \
awk 'NR>1 {print $1}' )" -- "$cur" ) )
2009-10-18 03:38:04 -07:00
elif [[ "$cur" == //* ]]; then
host=${cur#//}
host=${host%%/*}
if [ -n "$host" ]; then
COMPREPLY=( $( compgen -P "//$host" -W \
"$( smbclient -d 0 -NL $host 2>/dev/null |
sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' |
sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|/\1|p' )" \
-- "${cur#//$host}" ) )
2009-10-18 03:38:04 -07:00
fi
elif [ -r /etc/vfstab ]; then
# Solaris
COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) )
elif [ ! -e /etc/fstab ]; then
# probably Cygwin
COMPREPLY=( $( compgen -W "$( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) )
else
# probably Linux
if [ $prev = -L ]; then
COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*LABEL=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )
elif [ $prev = -U ]; then
COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )
2009-10-04 10:42:50 -07:00
else
2009-10-18 03:38:04 -07:00
COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab )" -- "$cur" ) )
2009-10-04 10:42:50 -07:00
fi
2009-10-18 03:38:04 -07:00
fi
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
return 0
} # _mount()
complete -F _mount -o default -o dirnames mount
2009-10-18 03:38:04 -07:00
# Linux rmmod(8) completion. This completes on a list of all currently
# installed kernel modules.
#
have rmmod && {
_rmmod()
{
local cur
COMPREPLY=()
cur=`_get_cword`
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
_installed_modules "$cur"
return 0
} # _rmmod()
complete -F _rmmod rmmod
# Linux insmod(8), modprobe(8) and modinfo(8) completion. This completes on a
# list of all available modules for the version of the kernel currently
# running.
#
_insmod()
{
local cur prev modpath
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# behave like lsmod for modprobe -r
if [[ ${1##*/} == modprobe && "${COMP_WORDS[1]}" == -r ]]; then
2009-10-04 10:42:50 -07:00
_installed_modules "$cur"
return 0
2009-10-18 03:38:04 -07:00
fi
2009-10-04 10:42:50 -07:00
2009-10-18 03:38:04 -07:00
# do filename completion if we're giving a path to a module
if [[ "$cur" == */* ]]; then
_filedir '@(?(k)o?(.gz))'
return 0
fi
2009-10-04 10:42:50 -07:00
if [[ $COMP_CWORD -gt 1 && "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then
2009-10-18 03:38:04 -07:00
# do module parameter completion
COMPREPLY=( $( compgen -W "$( /sbin/modinfo -p ${COMP_WORDS[1]} | \
cut -d: -f1 )" -- "$cur" ) )
2009-10-18 03:38:04 -07:00
else
_modules $(uname -r)
fi
return 0
} # _insmod
complete -F _insmod -o filenames insmod modprobe modinfo
2009-10-18 03:38:04 -07:00
} # have rmmod
2009-10-04 10:42:50 -07:00
# renice(8) completion
#
_renice()
{
2009-10-04 10:42:50 -07:00
local command cur curopt i
COMPREPLY=()
cur=`_get_cword`
command=$1
i=0
# walk back through command line and find last option
while [[ $i -le $COMP_CWORD && ${#COMPREPLY[@]} -eq 0 ]]; do
2009-10-04 10:42:50 -07:00
curopt=${COMP_WORDS[COMP_CWORD-$i]}
case "$curopt" in
-u)
COMPREPLY=( $( compgen -u -- "$cur" ) )
;;
-g)
_pgids
;;
-p|$command)
_pids
;;
esac
i=$(( ++i ))
done
}
complete -F _renice renice
2009-10-18 03:38:04 -07:00
# kill(1) completion
#
_kill()
{
2009-10-04 10:42:50 -07:00
local cur
COMPREPLY=()
cur=`_get_cword`
if [[ $COMP_CWORD -eq 1 && "$cur" == -* ]]; then
2009-10-04 10:42:50 -07:00
# return list of available signals
_signals
else
# return list of available PIDs
_pids
fi
}
complete -F _kill kill
# killall(1) (Linux and FreeBSD) and pkill(1) completion.
#
[[ $UNAME == Linux || $UNAME == FreeBSD ]] || have pkill &&
_killall()
{
2009-10-04 10:42:50 -07:00
local cur
2009-10-04 10:42:50 -07:00
COMPREPLY=()
cur=`_get_cword`
if [[ $COMP_CWORD -eq 1 && "$cur" == -* ]]; then
2009-10-04 10:42:50 -07:00
_signals
else
_pnames
fi
2009-10-04 10:42:50 -07:00
return 0
}
[[ $UNAME == Linux || $UNAME == FreeBSD ]] && complete -F _killall killall
have pkill && complete -F _killall pkill
# pgrep(1) completion.
#
[ $UNAME = Linux ] || have pgrep &&
_pgrep()
{
2009-10-04 10:42:50 -07:00
local cur
2009-10-04 10:42:50 -07:00
COMPREPLY=()
cur=`_get_cword`
2009-10-04 10:42:50 -07:00
_pnames
2009-10-04 10:42:50 -07:00
return 0
}
have pgrep && complete -F _pgrep pgrep
# Linux pidof(8) completion.
[ $UNAME = Linux ] && complete -F _pgrep pidof
2009-01-10 14:27:23 -08:00
# Red Hat & Debian GNU/Linux if{up,down} completion
#
[ $USERLAND = GNU ] && { have ifup || have ifdown; } &&
_ifupdown()
{
2009-10-04 10:42:50 -07:00
local cur
2009-10-04 10:42:50 -07:00
COMPREPLY=()
cur=`_get_cword`
2009-10-04 10:42:50 -07:00
if [ $COMP_CWORD -eq 1 ]; then
_configured_interfaces
COMPREPLY=( $(compgen -W '${COMPREPLY[@]}' -- "$cur") )
fi
2009-10-04 10:42:50 -07:00
return 0
} &&
complete -F _ifupdown ifup ifdown
[ $USERLAND = GNU ] && have ifstatus && complete -F _ifupdown ifstatus
# Linux ipsec(8) completion (for FreeS/WAN)
#
[ $UNAME = Linux ] && have ipsec &&
_ipsec()
{
2009-10-04 10:42:50 -07:00
local cur
COMPREPLY=()
cur=`_get_cword`
if [ $COMP_CWORD -eq 1 ]; then
2009-11-03 14:24:28 -08:00
COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look manual \
pluto ranbits rsasigkey setup showdefaults showhostkey spi spigrp \
tncfg whack' -- "$cur" ) )
2009-10-04 10:42:50 -07:00
return 0
fi
case ${COMP_WORDS[1]} in
auto)
COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete \
--replace --down --route --unroute \
--ready --status --rereadsecrets' \
-- "$cur" ) )
;;
manual)
COMPREPLY=( $( compgen -W '--up --down --route --unroute \
--union' -- "$cur" ) )
;;
ranbits)
COMPREPLY=( $( compgen -W '--quick --continuous --bytes' \
-- "$cur" ) )
;;
setup)
COMPREPLY=( $( compgen -W '--start --stop --restart' -- "$cur" ) )
;;
*)
;;
esac
return 0
} &&
complete -F _ipsec ipsec
2002-10-04 22:52:37 -07:00
# This function provides simple user@host completion
#
_user_at_host() {
2009-10-04 10:42:50 -07:00
local cur
2009-10-04 10:42:50 -07:00
COMPREPLY=()
cur=`_get_cword :`
2009-10-04 10:42:50 -07:00
if [[ $cur == *@* ]]; then
_known_hosts_real "$cur"
else
COMPREPLY=( $( compgen -u -- "$cur" ) )
fi
2009-10-04 10:42:50 -07:00
return 0
}
shopt -u hostcomplete && complete -F _user_at_host -o nospace talk ytalk finger
# NOTE: Using this function as a helper function is deprecated. Use
# `_known_hosts_real' instead.
_known_hosts()
{
2009-10-04 10:42:50 -07:00
local options
COMPREPLY=()
# NOTE: Using `_known_hosts' as a helper function and passing options
# to `_known_hosts' is deprecated: Use `_known_hosts_real' instead.
[[ "$1" == -a || "$2" == -a ]] && options=-a
[[ "$1" == -c || "$2" == -c ]] && options="$options -c"
_known_hosts_real $options "$(_get_cword :)"
2009-10-18 03:38:04 -07:00
} # _known_hosts()
# Helper function for completing _known_hosts.
2009-12-13 01:28:14 -08:00
# This function performs host completion based on ssh's config and known_hosts
# files, as well as hostnames reported by avahi-browse. Also hosts from
# HOSTFILE (compgen -A hostname) are added, unless
2009-08-12 13:28:42 -07:00
# COMP_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value.
# Usage: _known_hosts_real [OPTIONS] CWORD
# Options: -a Use aliases
# -c Use `:' suffix
# -F configfile Use `configfile' for configuration settings
# -p PREFIX Use PREFIX
# Return: Completions, starting with CWORD, are added to COMPREPLY[]
_known_hosts_real()
{
2009-10-04 10:42:50 -07:00
local configfile flag prefix
local cur curd awkcur user suffix aliases i host
2009-10-04 10:42:50 -07:00
local -a kh khd config
local OPTIND=1
while getopts "acF:p:" flag "$@"; do
case $flag in
a) aliases='yes' ;;
c) suffix=':' ;;
F) configfile=$OPTARG ;;
p) prefix=$OPTARG ;;
esac
done
[ $# -lt $OPTIND ] && echo "error: $FUNCNAME: missing mandatory argument CWORD"
cur=${!OPTIND}; let "OPTIND += 1"
[ $# -ge $OPTIND ] && echo "error: $FUNCNAME("$@"): unprocessed arguments:"\
2009-12-20 14:09:02 -08:00
$(while [ $# -ge $OPTIND ]; do printf '%s\n' ${!OPTIND}; shift; done)
2009-10-04 10:42:50 -07:00
[[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
kh=()
# ssh config files
if [ -n "$configfile" ]; then
[ -r "$configfile" ] &&
config=( "${config[@]}" "$configfile" )
else
[ -r /etc/ssh/ssh_config ] &&
config=( "${config[@]}" "/etc/ssh/ssh_config" )
[ -r "${HOME}/.ssh/config" ] &&
config=( "${config[@]}" "${HOME}/.ssh/config" )
[ -r "${HOME}/.ssh2/config" ] &&
config=( "${config[@]}" "${HOME}/.ssh2/config" )
fi
# Known hosts files from configs
2009-10-04 10:42:50 -07:00
if [ ${#config[@]} -gt 0 ]; then
local OIFS=$IFS IFS=$'\n'
local -a tmpkh
# expand paths (if present) to global and user known hosts files
# TODO(?): try to make known hosts files with more than one consecutive
# spaces in their name work (watch out for ~ expansion
# breakage! Alioth#311595)
tmpkh=( $( sed -ne 's/^[ \t]*\([Gg][Ll][Oo][Bb][Aa][Ll]\|[Uu][Ss][Ee][Rr]\)[Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\2/p' "${config[@]}" | sort -u ) )
for i in "${tmpkh[@]}"; do
# Remove possible quotes
i=${i//\"}
# Eval/expand possible `~' or `~user'
__expand_tilde_by_ref i
[ -r "$i" ] && kh=( "${kh[@]}" "$i" )
2009-10-04 10:42:50 -07:00
done
IFS=$OIFS
fi
# Global known_hosts files
if [ -z "$configfile" ]; then
[ -r /etc/ssh/ssh_known_hosts ] &&
kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts )
[ -r /etc/ssh/ssh_known_hosts2 ] &&
kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts2 )
[ -r /etc/known_hosts ] &&
kh=( "${kh[@]}" /etc/known_hosts )
[ -r /etc/known_hosts2 ] &&
kh=( "${kh[@]}" /etc/known_hosts2 )
[ -d /etc/ssh2/knownhosts ] &&
khd=( "${khd[@]}" /etc/ssh2/knownhosts/*pub )
fi
# User known_hosts files
if [ -z "$configfile" ]; then
[ -r ~/.ssh/known_hosts ] &&
kh=( "${kh[@]}" ~/.ssh/known_hosts )
[ -r ~/.ssh/known_hosts2 ] &&
kh=( "${kh[@]}" ~/.ssh/known_hosts2 )
[ -d ~/.ssh2/hostkeys ] &&
khd=( "${khd[@]}" ~/.ssh2/hostkeys/*pub )
fi
# If we have known_hosts files to use
if [[ ${#kh[@]} -gt 0 || ${#khd[@]} -gt 0 ]]; then
2009-10-04 10:42:50 -07:00
# Escape slashes and dots in paths for awk
awkcur=${cur//\//\\\/}
awkcur=${awkcur//\./\\\.}
curd=$awkcur
if [[ "$awkcur" == [0-9]*.* ]]; then
# Digits followed by a dot - just search for that
awkcur="^$awkcur.*"
elif [[ "$awkcur" == [0-9]* ]]; then
# Digits followed by no dot - search for digits followed
# by a dot
awkcur="^$awkcur.*\."
elif [ -z "$awkcur" ]; then
# A blank - search for a dot or an alpha character
awkcur="[a-z.]"
else
awkcur="^$awkcur"
fi
if [ ${#kh[@]} -gt 0 ]; then
# FS needs to look for a comma separated list
COMPREPLY=( "${COMPREPLY[@]}" $( awk 'BEGIN {FS=","}
2009-10-04 10:42:50 -07:00
/^\s*[^|\#]/ {for (i=1; i<=2; ++i) { \
gsub(" .*$", "", $i); \
gsub("[\\[\\]]", "", $i); \
gsub(":[0-9]+$", "", $i); \
if ($i ~ /'"$awkcur"'/) {print $i} \
}}' "${kh[@]}" 2>/dev/null ) )
fi
if [ ${#khd[@]} -gt 0 ]; then
# Needs to look for files called
# .../.ssh2/key_22_<hostname>.pub
# dont fork any processes, because in a cluster environment,
# there can be hundreds of hostkeys
for i in "${khd[@]}" ; do
if [[ "$i" == *key_22_$awkcurd*.pub && -r "$i" ]]; then
2009-10-04 10:42:50 -07:00
host=${i/#*key_22_/}
host=${host/%.pub/}
COMPREPLY=( "${COMPREPLY[@]}" $host )
fi
done
fi
# apply suffix and prefix
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=$prefix$user${COMPREPLY[i]}$suffix
done
fi
# append any available aliases from config files
if [[ ${#config[@]} -gt 0 && -n "$aliases" ]]; then
local hosts=$( sed -ne 's/^[ \t]*[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\?['"$'\t '"']\{1,\}\([^#*?]*\)\(#.*\)\?$/\2/p' "${config[@]}" )
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -P "$prefix$user" \
-S "$suffix" -W "$hosts" -- "$cur" ) )
fi
# Add hosts reported by avahi-browse, if it's available.
# The original call to avahi-browse also had "-k", to avoid lookups into
# avahi's services DB. We don't need the name of the service, and if it
# contains ";", it may mistify the result. But on Gentoo (at least),
# -k isn't available (even if mentioned in the manpage), so...
if type avahi-browse >&/dev/null; then
COMPREPLY=( "${COMPREPLY[@]}" $( \
compgen -P "$prefix$user" -S "$suffix" -W \
"$( avahi-browse -cpr _workstation._tcp 2>/dev/null | \
awk -F\; '/^=/ { print $7 }' | sort -u )" -- "$cur" ) )
fi
2009-12-13 01:28:14 -08:00
# Add results of normal hostname completion, unless
# `COMP_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
2009-10-04 10:42:50 -07:00
if [ -n "${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}" ]; then
2009-12-13 01:28:14 -08:00
COMPREPLY=( "${COMPREPLY[@]}"
$( compgen -A hostname -P "$prefix$user" -S "$suffix" -- "$cur" ) )
2009-10-04 10:42:50 -07:00
fi
__ltrim_colon_completions "$prefix$user$cur"
2009-10-04 10:42:50 -07:00
return 0
2009-10-18 03:38:04 -07:00
} # _known_hosts_real()
2009-11-03 14:24:28 -08:00
complete -F _known_hosts traceroute traceroute6 tracepath tracepath6 ping \
ping6 fping fping6 telnet host nslookup rsh rlogin ftp dig mtr \
ssh-installkeys
# This meta-cd function observes the CDPATH variable, so that cd additionally
# completes on directories under those specified in CDPATH.
#
_cd()
{
2009-10-04 10:42:50 -07:00
local IFS=$'\t\n' cur=`_get_cword` i j k
# try to allow variable completion
if [[ "$cur" == ?(\\)\$* ]]; then
COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
return 0
fi
# Enable -o filenames option, see Debian bug #272660
compgen -f /non-existing-dir/ >/dev/null
# Use standard dir completion if no CDPATH or parameter starts with /,
# ./ or ../
if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then
2009-10-04 10:42:50 -07:00
_filedir -d
return 0
fi
local -r mark_dirs=$(_rl_enabled mark-directories && echo y)
local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y)
# we have a CDPATH, so loop on its contents
for i in ${CDPATH//:/$'\t'}; do
# create an array of matched subdirs
k="${#COMPREPLY[@]}"
for j in $( compgen -d $i/$cur ); do
if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
j="${j}/"
fi
COMPREPLY[k++]=${j#$i/}
done
done
_filedir -d
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
i=${COMPREPLY[0]}
if [[ "$i" == "$cur" && $i != "*/" ]]; then
2009-10-04 10:42:50 -07:00
COMPREPLY[0]="${i}/"
fi
fi
return 0
}
if shopt -q cdable_vars; then
complete -v -F _cd -o nospace cd
else
complete -F _cd -o nospace cd
fi
# a wrapper method for the next one, when the offset is unknown
_command()
{
2009-10-04 10:42:50 -07:00
local offset i
# find actual offset, as position of the first non-option
offset=1
for (( i=1; i <= COMP_CWORD; i++ )); do
if [[ "${COMP_WORDS[i]}" != -* ]]; then
offset=$i
break
fi
done
_command_offset $offset
2008-06-23 02:33:52 -07:00
}
# A meta-command completion function for commands like sudo(8), which need to
# first complete on a command, then complete according to that command's own
# completion definition - currently not quite foolproof (e.g. mount and umount
# don't work properly), but still quite useful.
#
_command_offset()
{
2009-10-04 10:42:50 -07:00
local cur func cline cspec noglob cmd i char_offset word_offset \
2009-11-03 14:24:28 -08:00
_COMMAND_FUNC _COMMAND_FUNC_ARGS
2009-10-04 10:42:50 -07:00
word_offset=$1
# rewrite current completion context before invoking
# actual command completion
# find new first word position, then
# rewrite COMP_LINE and adjust COMP_POINT
local first_word=${COMP_WORDS[$word_offset]}
for (( i=0; i <= ${#COMP_LINE}; i++ )); do
if [[ "${COMP_LINE:$i:${#first_word}}" == "$first_word" ]]; then
char_offset=$i
break
fi
done
COMP_LINE=${COMP_LINE:$char_offset}
COMP_POINT=$(( COMP_POINT - $char_offset ))
# shift COMP_WORDS elements and adjust COMP_CWORD
for (( i=0; i <= COMP_CWORD - $word_offset; i++ )); do
COMP_WORDS[i]=${COMP_WORDS[i+$word_offset]}
done
for (( i; i <= COMP_CWORD; i++ )); do
unset COMP_WORDS[i];
done
COMP_CWORD=$(( $COMP_CWORD - $word_offset ))
COMPREPLY=()
cur=`_get_cword`
if [[ $COMP_CWORD -eq 0 ]]; then
COMPREPLY=( $( compgen -c -- "$cur" ) )
else
cmd=${COMP_WORDS[0]}
if complete -p $cmd &>/dev/null; then
cspec=$( complete -p $cmd )
if [ "${cspec#* -F }" != "$cspec" ]; then
# complete -F <function>
# get function name
func=${cspec#*-F }
func=${func%% *}
if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
2009-10-04 10:46:01 -07:00
$func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}" "${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
2009-10-04 10:42:50 -07:00
else
$func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}"
fi
# remove any \: generated by a command that doesn't
# default to filenames or dirnames (e.g. sudo chown)
# FIXME: I'm pretty sure this does not work!
if [ "${cspec#*-o }" != "$cspec" ]; then
cspec=${cspec#*-o }
cspec=${cspec%% *}
if [[ "$cspec" != @(dir|file)names ]]; then
COMPREPLY=("${COMPREPLY[@]//\\\\:/:}")
fi
fi
elif [ -n "$cspec" ]; then
cspec=${cspec#complete};
cspec=${cspec%%$cmd};
COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
fi
fi
fi
[ ${#COMPREPLY[@]} -eq 0 ] && _filedir
}
complete -F _command -o filenames nohup exec nice eval time ltrace then \
2009-10-04 10:42:50 -07:00
else do vsound command xargs tsocks
_root_command()
{
2009-10-04 10:42:50 -07:00
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 $2 $3
}
complete -F _root_command -o filenames sudo fakeroot really gksudo gksu kdesudo
_longopt()
{
2009-10-04 10:42:50 -07:00
local cur prev
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
if _split_longopt; then
case "$prev" in
*[Dd][Ii][Rr]*)
_filedir -d
;;
*[Ff][Ii][Ll][Ee]*)
_filedir
;;
esac
return 0
fi
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$( $1 --help 2>&1 | \
sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}\).*/\1/p' | sort -u )" \
2009-10-04 10:42:50 -07:00
-- "$cur" ) )
elif [[ "$1" == rmdir ]]; then
_filedir -d
else
_filedir
fi
}
# makeinfo and texi2dvi are defined elsewhere.
for i in a2ps autoconf automake bc gprof ld nm objcopy objdump readelf strip \
bison colordiff diff patch enscript cp df dir du ln ls mkfifo mknod mv rm \
2009-10-04 10:42:50 -07:00
touch vdir awk gperf grep grub indent less m4 sed shar date \
tee who texindex cat csplit cut expand fmt fold head \
md5sum nl od paste pr ptx sha1sum sort split tac tail tr unexpand \
uniq wc ldd bash id irb mkdir rmdir; do
have $i && complete -F _longopt -o filenames $i
done
# These commands do not use filenames, so '-o filenames' is not needed.
for i in env netstat seq uname units wget; do
have $i && complete -F _longopt -o default $i
done
unset i
2002-10-23 07:05:16 -07:00
# look(1) completion
#
2008-05-06 12:20:14 -07:00
have look &&
2002-10-23 07:05:16 -07:00
_look()
{
2009-10-04 10:42:50 -07:00
local cur
2008-05-06 12:20:14 -07:00
2009-10-04 10:42:50 -07:00
COMPREPLY=()
cur=`_get_cword`
2002-10-23 07:05:16 -07:00
2009-10-04 10:42:50 -07:00
if [ $COMP_CWORD = 1 ]; then
COMPREPLY=( $( compgen -W '$(look "$cur" 2>/dev/null)' ) )
fi
} &&
complete -F _look -o default look
2002-10-23 07:05:16 -07:00
# id(1) completion
#
2005-07-12 10:13:02 -07:00
have id &&
_id()
{
2009-10-04 10:42:50 -07:00
local cur
2009-10-04 10:42:50 -07:00
COMPREPLY=()
cur=`_get_cword`
2009-10-04 10:42:50 -07:00
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-a -g --group -G --groups -n --name\
-r --real -u --user --help --version' -- "$cur" ) )
else
COMPREPLY=( $( compgen -u "$cur" ) )
fi
} &&
complete -F _id id
_filedir_xspec()
{
2009-10-04 10:42:50 -07:00
local IFS cur xspec
IFS=$'\t\n'
COMPREPLY=()
cur=`_get_cword`
_expand || return 0
# get first exclusion compspec that matches this command
xspec=$( sed -ne $'/^complete .*[ \t]'${1##*/}$'\([ \t]\|$\)/{p;q;}' \
$BASH_COMPLETION )
# prune to leave nothing but the -X spec
xspec=${xspec#*-X }
xspec=${xspec%% *}
local -a toks
local tmp
toks=( ${toks[@]-} $(
compgen -d -- "$(quote_readline "$cur")" | {
while read -r tmp; do
# see long TODO comment in _filedir() --David
2009-12-20 14:09:02 -08:00
printf '%s\n' $tmp
2009-10-04 10:42:50 -07:00
done
}
))
toks=( ${toks[@]-} $(
eval compgen -f -X "$xspec" -- "\$(quote_readline "\$cur")" | {
while read -r tmp; do
2009-12-20 14:09:02 -08:00
[ -n $tmp ] && printf '%s\n' $tmp
2009-10-04 10:42:50 -07:00
done
}
))
COMPREPLY=( "${toks[@]}" )
}
2009-10-04 10:42:50 -07:00
list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' $BASH_COMPLETION | \
# read exclusion compspecs
(
while read line
do
# ignore compspecs that are commented out
if [ "${line#\#}" != "$line" ]; then continue; fi
line=${line%# START exclude*}
line=${line%# FINISH exclude*}
line=${line##*\'}
list=( "${list[@]}" $line )
done
2009-12-20 14:09:02 -08:00
printf '%s ' "${list[@]}"
2009-10-04 10:42:50 -07:00
)
) )
# remove previous compspecs
if [ ${#list[@]} -gt 0 ]; then
eval complete -r ${list[@]}
# install new compspecs
eval complete -F _filedir_xspec -o filenames "${list[@]}"
fi
unset list
# source completion directory definitions
if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
-x $BASH_COMPLETION_COMPAT_DIR ]]; then
for i in $(LC_ALL=C command ls $BASH_COMPLETION_COMPAT_DIR); do
i=$BASH_COMPLETION_COMPAT_DIR/$i
[[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)) \
&& ( -f $i || -h $i ) && -r $i ]] && . $i
2009-10-04 10:42:50 -07:00
done
fi
if [[ $BASH_COMPLETION_DIR != $BASH_COMPLETION_COMPAT_DIR && \
-d $BASH_COMPLETION_DIR && -r $BASH_COMPLETION_DIR && \
-x $BASH_COMPLETION_DIR ]]; then
for i in $(LC_ALL=C command ls $BASH_COMPLETION_DIR); do
i=$BASH_COMPLETION_DIR/$i
[[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)) \
&& ( -f $i || -h $i ) && -r $i ]] && . $i
2009-10-04 10:42:50 -07:00
done
2009-01-29 06:10:18 -08:00
fi
unset i
# source user completion file
[[ $BASH_COMPLETION != ~/.bash_completion && -r ~/.bash_completion ]] \
2009-10-04 10:42:50 -07:00
&& . ~/.bash_completion
unset -f have
unset UNAME USERLAND have
set $BASH_COMPLETION_ORIGINAL_V_VALUE
unset BASH_COMPLETION_ORIGINAL_V_VALUE
# Local variables:
# mode: shell-script
2009-10-04 10:42:50 -07:00
# sh-basic-offset: 4
# sh-indent-comment: t
2009-10-04 10:42:50 -07:00
# indent-tabs-mode: nil
# End:
2009-10-04 10:42:50 -07:00
# ex: ts=4 sw=4 et filetype=sh