diff options
Diffstat (limited to 'bash_completion')
-rw-r--r-- | bash_completion | 114 |
1 files changed, 59 insertions, 55 deletions
diff --git a/bash_completion b/bash_completion index d16b10a5..ca84b01d 100644 --- a/bash_completion +++ b/bash_completion @@ -3,7 +3,7 @@ # bash_completion - programmable completion functions for bash 4.1+ # # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org> -# © 2009-2017, Bash Completion Maintainers +# © 2009-2018, Bash Completion Maintainers # # 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 @@ -23,7 +23,7 @@ # # https://github.com/scop/bash-completion -BASH_COMPLETION_VERSINFO=(2 7) +BASH_COMPLETION_VERSINFO=(2 8) if [[ $- == *v* ]]; then BASH_COMPLETION_ORIGINAL_V_VALUE="-v" @@ -938,18 +938,19 @@ _kernel_versions() # _available_interfaces() { - local cmd PATH=$PATH:/sbin - - if [[ ${1:-} == -w ]]; then - cmd="iwconfig" - elif [[ ${1:-} == -a ]]; then - cmd="{ ifconfig || ip link show up; }" - else - cmd="{ ifconfig -a || ip link show; }" - fi + local PATH=$PATH:/sbin - COMPREPLY=( $( eval $cmd 2>/dev/null | awk \ + COMPREPLY=( $( { + if [[ ${1:-} == -w ]]; then + iwconfig + elif [[ ${1:-} == -a ]]; then + ifconfig || ip link show up + else + ifconfig -a || ip link show + fi + } 2>/dev/null | awk \ '/^[^ \t]/ { if ($1 ~ /^[0-9]+:/) { print $2 } else { print $1 } }' ) ) + COMPREPLY=( $( compgen -W '${COMPREPLY[@]/%[[:punct:]]/}' -- "$cur" ) ) } @@ -1004,21 +1005,8 @@ _tilde() # @param $1 Name of variable (not the value of the variable) to expand __expand_tilde_by_ref() { - # Does $1 start with tilde (~)? if [[ ${!1} == \~* ]]; then - # Does $1 contain slash (/)? - if [[ ${!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 + eval $1=$(printf ~%q "${!1#\~}") fi } # __expand_tilde_by_ref() @@ -1027,19 +1015,14 @@ __expand_tilde_by_ref() # _expand() { - # FIXME: Why was this here? - #[ "$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 2>/dev/null + __expand_tilde_by_ref cur elif [[ "$cur" == \~* ]]; then - cur=${cur#\~} - COMPREPLY=( $( compgen -P '~' -u -- "$cur" ) ) - [[ ${#COMPREPLY[@]} -eq 1 ]] && eval COMPREPLY[0]=${COMPREPLY[0]} + _tilde "$cur" || eval COMPREPLY[0]=$(printf ~%q "${COMPREPLY[0]#\~}") return ${#COMPREPLY[@]} fi } @@ -1137,9 +1120,9 @@ _xinetd_services() { local xinetddir=/etc/xinetd.d if [[ -d $xinetddir ]]; then - local restore_nullglob=$(shopt -p nullglob); shopt -s nullglob + local IFS=$' \t\n' reset=$(shopt -p nullglob); shopt -s nullglob local -a svcs=( $( printf '%s\n' $xinetddir/!($_backup_glob) ) ) - $restore_nullglob + $reset COMPREPLY+=( $( compgen -W '${svcs[@]#$xinetddir/}' -- "$cur" ) ) fi } @@ -1151,10 +1134,10 @@ _services() local sysvdirs _sysvdirs - local restore_nullglob=$(shopt -p nullglob); shopt -s nullglob + local IFS=$' \t\n' reset=$(shopt -p nullglob); shopt -s nullglob COMPREPLY=( \ $( printf '%s\n' ${sysvdirs[0]}/!($_backup_glob|functions|README) ) ) - $restore_nullglob + $reset COMPREPLY+=( $( systemctl list-units --full --all 2>/dev/null | \ awk '$1 ~ /\.service$/ { sub("\\.service$", "", $1); print $1 }' ) ) @@ -1490,24 +1473,30 @@ _included_ssh_config_files() # HOSTFILE (compgen -A hostname) are added, unless # COMP_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value. # Usage: _known_hosts_real [OPTIONS] CWORD -# Options: -a Use aliases +# Options: -a Use aliases from ssh config files # -c Use `:' suffix # -F configfile Use `configfile' for configuration settings # -p PREFIX Use PREFIX +# -4 Filter IPv6 addresses from results +# -6 Filter IPv4 addresses from results # Return: Completions, starting with CWORD, are added to COMPREPLY[] _known_hosts_real() { local configfile flag prefix - local cur curd awkcur user suffix aliases i host + local cur curd awkcur user suffix aliases i host ipv4 ipv6 local -a kh khd config + # TODO remove trailing %foo from entries + local OPTIND=1 - while getopts "acF:p:" flag "$@"; do + while getopts "ac46F:p:" flag "$@"; do case $flag in a) aliases='yes' ;; c) suffix=':' ;; F) configfile=$OPTARG ;; p) prefix=$OPTARG ;; + 4) ipv4=1 ;; + 6) ipv6=1 ;; esac done [[ $# -lt $OPTIND ]] && echo "error: $FUNCNAME: missing mandatory argument CWORD" @@ -1622,7 +1611,7 @@ _known_hosts_real() done fi - # append any available aliases from config files + # append any available aliases from ssh config files if [[ ${#config[@]} -gt 0 && -n "$aliases" ]]; then local hosts=$( command sed -ne 's/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]]\{1,\}\([^#*?%]*\)\(#.*\)\{0,1\}$/\1/p' "${config[@]}" ) COMPREPLY+=( $( compgen -P "$prefix$user" \ @@ -1654,6 +1643,18 @@ _known_hosts_real() $( compgen -A hostname -P "$prefix$user" -S "$suffix" -- "$cur" ) ) fi + if [[ $ipv4 ]]; then + COMPREPLY=( "${COMPREPLY[@]/*:*$suffix/}" ) + fi + if [[ $ipv6 ]]; then + COMPREPLY=( "${COMPREPLY[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}" ) + fi + if [[ $ipv4 || $ipv6 ]]; then + for i in ${!COMPREPLY[@]}; do + [[ ${COMPREPLY[i]} ]] || unset -v COMPREPLY[i] + done + fi + __ltrim_colon_completions "$prefix$user$cur" } # _known_hosts_real() @@ -1874,9 +1875,10 @@ _longopt() command sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}=\{0,1\}\).*/\1/p' | sort -u )" \ -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace - elif [[ "$1" == @(@(mk|rm)dir|chroot) ]]; then + elif [[ "$1" == @(rmdir|chroot) ]]; then _filedir -d else + [[ "$1" == mkdir ]] && compopt -o nospace _filedir fi } @@ -1938,11 +1940,10 @@ _install_xspec() for cmd in $@; do _xspecs[$cmd]=$xspec done - complete -F _filedir_xspec $@ } # bzcmp, bzdiff, bz*grep, bzless, bzmore intentionally not here, see Debian: #455510 _install_xspec '!*.?(t)bz?(2)' bunzip2 bzcat pbunzip2 pbzcat lbunzip2 lbzcat -_install_xspec '!*.@(zip|[ejsw]ar|exe|pk3|wsz|zargo|xpi|s[tx][cdiw]|sx[gm]|o[dt][tspgfc]|od[bm]|oxt|epub|apk|ipa|do[ct][xm]|p[op]t[mx]|xl[st][xm]|pyz)' unzip zipinfo +_install_xspec '!*.@(zip|[egjsw]ar|exe|pk3|wsz|zargo|xpi|s[tx][cdiw]|sx[gm]|o[dt][tspgfc]|od[bm]|oxt|epub|apk|ipa|do[ct][xm]|p[op]t[mx]|xl[st][xm]|pyz)' unzip zipinfo _install_xspec '*.Z' compress znew # zcmp, zdiff, z*grep, zless, zmore intentionally not here, see Debian: #455510 _install_xspec '!*.@(Z|[gGd]z|t[ag]z)' gunzip zcat @@ -1967,12 +1968,12 @@ _install_xspec '!*.@(?(e)ps|pdf)' ps2pdf ps2pdf12 ps2pdf13 ps2pdf14 ps2pdfwr _install_xspec '!*.texi*' makeinfo texi2html _install_xspec '!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi xetex xelatex luatex lualatex _install_xspec '!*.mp3' mpg123 mpg321 madplay -_install_xspec '!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|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))?(.part)' xine aaxine fbxine -_install_xspec '!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM|iso|ISO)|+([0-9]).@(vdr|VDR))?(.part)' kaffeine dragon +_install_xspec '!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[agmv]|OG[AGMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|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))?(.part)' xine aaxine fbxine +_install_xspec '!*@(.@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|web[am]|WEB[AM]|mp[234]|MP[234]|m?(p)4[av]|M?(P)4[AV]|mkv|MKV|og[agmv]|OG[AGMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|mts|MTS|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM|iso|ISO)|+([0-9]).@(vdr|VDR))?(.part)' kaffeine dragon _install_xspec '!*.@(avi|asf|wmv)' aviplay _install_xspec '!*.@(rm?(j)|ra?(m)|smi?(l))' realplay _install_xspec '!*.@(mpg|mpeg|avi|mov|qt)' xanim -_install_xspec '!*.@(ogg|m3u|flac|spx)' ogg123 +_install_xspec '!*.@(og[ag]|m3u|flac|spx)' ogg123 _install_xspec '!*.@(mp3|ogg|pls|m3u)' gqmpeg freeamp _install_xspec '!*.fig' xfig _install_xspec '!*.@(mid?(i)|cmf)' playmidi @@ -1983,12 +1984,12 @@ _install_xspec '!*.@(zip|z|gz|tgz)' bzme # konqueror not here on purpose, it's more than a web/html browser _install_xspec '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx galeon dillo elinks amaya epiphany _install_xspec '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL])|[pP][dD][fF])' firefox mozilla-firefox iceweasel google-chrome chromium-browser -_install_xspec '!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm|pdf)' oowriter -_install_xspec '!*.@(sxi|sti|pps?(x)|ppt?([mx])|pot?([mx])|?(f)odp|otp)' ooimpress -_install_xspec '!*.@(sxc|stc|xls?([bmx])|xlw|xlt?([mx])|[ct]sv|?(f)ods|ots)' oocalc -_install_xspec '!*.@(sxd|std|sda|sdd|?(f)odg|otg)' oodraw -_install_xspec '!*.@(sxm|smf|mml|odf)' oomath -_install_xspec '!*.odb' oobase +_install_xspec '!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm|pdf)' oowriter lowriter +_install_xspec '!*.@(sxi|sti|pps?(x)|ppt?([mx])|pot?([mx])|?(f)odp|otp)' ooimpress loimpress +_install_xspec '!*.@(sxc|stc|xls?([bmx])|xlw|xlt?([mx])|[ct]sv|?(f)ods|ots)' oocalc localc +_install_xspec '!*.@(sxd|std|sda|sdd|?(f)odg|otg)' oodraw lodraw +_install_xspec '!*.@(sxm|smf|mml|odf)' oomath lomath +_install_xspec '!*.odb' oobase lobase _install_xspec '!*.[rs]pm' rpm2cpio _install_xspec '!*.aux' bibtex _install_xspec '!*.po' poedit gtranslator kbabel lokalize @@ -2016,7 +2017,7 @@ complete -F _minimal '' __load_completion() { local -a dirs=( ${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions ) - local OIFS=$IFS IFS=: dir cmd="$1" compfile + local OIFS=$IFS IFS=: dir cmd="${1##*/}" compfile for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do dirs+=( $dir/bash-completion/completions ) done @@ -2029,13 +2030,16 @@ __load_completion() fi for dir in "${dirs[@]}"; do - for compfile in "${cmd##*/}" "${cmd##*/}".bash _"${cmd##*/}"; do + for compfile in "$cmd" "$cmd.bash" "_$cmd"; do compfile="$dir/$compfile" # Avoid trying to source dirs; https://bugzilla.redhat.com/903540 [[ -f "$compfile" ]] && . "$compfile" &>/dev/null && return 0 done done + # Look up simple "xspec" completions + [[ "${_xspecs[$cmd]}" ]] && complete -F _filedir_xspec "$cmd" && return 0 + return 1 } |