Advertisement
kosx

bash-completion! on Kali

Dec 14th, 2022
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 55.30 KB | Legal | 0 0
  1. __expand_tilde_by_ref ()
  2. {
  3.     if [[ ${!1-} == \~* ]]; then
  4.         eval $1="$(printf ~%q "${!1#\~}")";
  5.     fi
  6. }
  7. __get_cword_at_cursor_by_ref ()
  8. {
  9.     local cword words=();
  10.     __reassemble_comp_words_by_ref "$1" words cword;
  11.     local i cur="" index=$COMP_POINT lead=${COMP_LINE:0:COMP_POINT};
  12.     if [[ $index -gt 0 && ( -n $lead && -n ${lead//[[:space:]]/} ) ]]; then
  13.         cur=$COMP_LINE;
  14.         for ((i = 0; i <= cword; ++i))
  15.         do
  16.             while [[ ${#cur} -ge ${#words[i]} && ${cur:0:${#words[i]}} != "${words[i]-}" ]]; do
  17.                 cur="${cur:1}";
  18.                 ((index > 0)) && ((index--));
  19.             done;
  20.             if ((i < cword)); then
  21.                 local old_size=${#cur};
  22.                 cur="${cur#"${words[i]}"}";
  23.                local new_size=${#cur};
  24.                ((index -= old_size - new_size));
  25.            fi;
  26.        done;
  27.        [[ -n $cur && ! -n ${cur//[[:space:]]/} ]] && cur=;
  28.        ((index < 0)) && index=0;
  29.    fi;
  30.    local "$2" "$3" "$4" && _upvars -a${#words[@]} $2 ${words+"${words[@]}"} -v $3 "$cword" -v $4 "${cur:0:index}"
  31. }
  32. __git_eread ()
  33. {
  34.     test -r "$1" && IFS='
  35. ' read "$2" < "$1"
  36. }
  37. __git_ps1 ()
  38. {
  39.     local exit=$?;
  40.     local pcmode=no;
  41.     local detached=no;
  42.     local ps1pc_start='\u@\h:\w ';
  43.     local ps1pc_end='\$ ';
  44.     local printf_format=' (%s)';
  45.     case "$#" in
  46.         2 | 3)
  47.             pcmode=yes;
  48.             ps1pc_start="$1";
  49.             ps1pc_end="$2";
  50.             printf_format="${3:-$printf_format}";
  51.             PS1="$ps1pc_start$ps1pc_end"
  52.         ;;
  53.         0 | 1)
  54.             printf_format="${1:-$printf_format}"
  55.         ;;
  56.         *)
  57.             return $exit
  58.         ;;
  59.     esac;
  60.     local ps1_expanded=yes;
  61.     [ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no;
  62.     [ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no;
  63.     local repo_info rev_parse_exit_code;
  64.     repo_info="$(git rev-parse --git-dir --is-inside-git-dir --is-bare-repository --is-inside-work-tree --short HEAD 2> /dev/null)";
  65.     rev_parse_exit_code="$?";
  66.     if [ -z "$repo_info" ]; then
  67.         return $exit;
  68.     fi;
  69.     local short_sha="";
  70.     if [ "$rev_parse_exit_code" = "0" ]; then
  71.         short_sha="${repo_info##*'
  72. '}";
  73.         repo_info="${repo_info%'
  74. '*}";
  75.     fi;
  76.     local inside_worktree="${repo_info##*'
  77. '}";
  78.     repo_info="${repo_info%'
  79. '*}";
  80.     local bare_repo="${repo_info##*'
  81. '}";
  82.     repo_info="${repo_info%'
  83. '*}";
  84.     local inside_gitdir="${repo_info##*'
  85. '}";
  86.     local g="${repo_info%'
  87. '*}";
  88.     if [ "true" = "$inside_worktree" ] && [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] && [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] && git check-ignore -q .; then
  89.         return $exit;
  90.     fi;
  91.     local sparse="";
  92.     if [ -z "${GIT_PS1_COMPRESSSPARSESTATE-}" ] && [ -z "${GIT_PS1_OMITSPARSESTATE-}" ] && [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
  93.         sparse="|SPARSE";
  94.     fi;
  95.     local r="";
  96.     local b="";
  97.     local step="";
  98.     local total="";
  99.     if [ -d "$g/rebase-merge" ]; then
  100.         __git_eread "$g/rebase-merge/head-name" b;
  101.         __git_eread "$g/rebase-merge/msgnum" step;
  102.         __git_eread "$g/rebase-merge/end" total;
  103.         r="|REBASE";
  104.     else
  105.         if [ -d "$g/rebase-apply" ]; then
  106.             __git_eread "$g/rebase-apply/next" step;
  107.             __git_eread "$g/rebase-apply/last" total;
  108.             if [ -f "$g/rebase-apply/rebasing" ]; then
  109.                 __git_eread "$g/rebase-apply/head-name" b;
  110.                 r="|REBASE";
  111.             else
  112.                 if [ -f "$g/rebase-apply/applying" ]; then
  113.                     r="|AM";
  114.                 else
  115.                     r="|AM/REBASE";
  116.                 fi;
  117.             fi;
  118.         else
  119.             if [ -f "$g/MERGE_HEAD" ]; then
  120.                 r="|MERGING";
  121.             else
  122.                 if __git_sequencer_status; then
  123.                     :;
  124.                 else
  125.                     if [ -f "$g/BISECT_LOG" ]; then
  126.                         r="|BISECTING";
  127.                     fi;
  128.                 fi;
  129.             fi;
  130.         fi;
  131.         if [ -n "$b" ]; then
  132.             :;
  133.         else
  134.             if [ -h "$g/HEAD" ]; then
  135.                 b="$(git symbolic-ref HEAD 2> /dev/null)";
  136.             else
  137.                 local head="";
  138.                 if ! __git_eread "$g/HEAD" head; then
  139.                     return $exit;
  140.                 fi;
  141.                 b="${head#ref: }";
  142.                 if [ "$head" = "$b" ]; then
  143.                     detached=yes;
  144.                     b="$(case "${GIT_PS1_DESCRIBE_STYLE-}" in
  145.    contains)
  146.        git describe --contains HEAD
  147.    ;;
  148.    branch)
  149.        git describe --contains --all HEAD
  150.    ;;
  151.    tag)
  152.        git describe --tags HEAD
  153.    ;;
  154.    describe)
  155.        git describe HEAD
  156.    ;;
  157.    * | default)
  158.        git describe --tags --exact-match HEAD
  159.    ;;
  160. esac 2> /dev/null)" || b="$short_sha...";
  161.                     b="($b)";
  162.                 fi;
  163.             fi;
  164.         fi;
  165.     fi;
  166.     if [ -n "$step" ] && [ -n "$total" ]; then
  167.         r="$r $step/$total";
  168.     fi;
  169.     local w="";
  170.     local i="";
  171.     local s="";
  172.     local u="";
  173.     local h="";
  174.     local c="";
  175.     local p="";
  176.     if [ "true" = "$inside_gitdir" ]; then
  177.         if [ "true" = "$bare_repo" ]; then
  178.             c="BARE:";
  179.         else
  180.             b="GIT_DIR!";
  181.         fi;
  182.     else
  183.         if [ "true" = "$inside_worktree" ]; then
  184.             if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] && [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
  185.                 git diff --no-ext-diff --quiet || w="*";
  186.                 git diff --no-ext-diff --cached --quiet || i="+";
  187.                 if [ -z "$short_sha" ] && [ -z "$i" ]; then
  188.                     i="#";
  189.                 fi;
  190.             fi;
  191.             if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] && git rev-parse --verify --quiet refs/stash > /dev/null; then
  192.                 s="$";
  193.             fi;
  194.             if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] && [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] && git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' > /dev/null 2> /dev/null; then
  195.                 u="%${ZSH_VERSION+%}";
  196.             fi;
  197.             if [ -n "${GIT_PS1_COMPRESSSPARSESTATE-}" ] && [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
  198.                 h="?";
  199.             fi;
  200.             if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
  201.                 __git_ps1_show_upstream;
  202.             fi;
  203.         fi;
  204.     fi;
  205.     local z="${GIT_PS1_STATESEPARATOR-" "}";
  206.     if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
  207.         if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
  208.             __git_ps1_colorize_gitstring;
  209.         fi;
  210.     fi;
  211.     b=${b##refs/heads/};
  212.     if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
  213.         __git_ps1_branch_name=$b;
  214.         b="\${__git_ps1_branch_name}";
  215.     fi;
  216.     local f="$h$w$i$s$u";
  217.     local gitstring="$c$b${f:+$z$f}${sparse}$r$p";
  218.     if [ $pcmode = yes ]; then
  219.         if [ "${__git_printf_supports_v-}" != yes ]; then
  220.             gitstring=$(printf -- "$printf_format" "$gitstring");
  221.         else
  222.             printf -v gitstring -- "$printf_format" "$gitstring";
  223.         fi;
  224.         PS1="$ps1pc_start$gitstring$ps1pc_end";
  225.     else
  226.         printf -- "$printf_format" "$gitstring";
  227.     fi;
  228.     return $exit
  229. }
  230. __git_ps1_colorize_gitstring ()
  231. {
  232.     if [[ -n ${ZSH_VERSION-} ]]; then
  233.         local c_red='%F{red}';
  234.         local c_green='%F{green}';
  235.         local c_lblue='%F{blue}';
  236.         local c_clear='%f';
  237.     else
  238.         local c_red='\[\e[31m\]';
  239.         local c_green='\[\e[32m\]';
  240.         local c_lblue='\[\e[1;34m\]';
  241.         local c_clear='\[\e[0m\]';
  242.     fi;
  243.     local bad_color=$c_red;
  244.     local ok_color=$c_green;
  245.     local flags_color="$c_lblue";
  246.     local branch_color="";
  247.     if [ $detached = no ]; then
  248.         branch_color="$ok_color";
  249.     else
  250.         branch_color="$bad_color";
  251.     fi;
  252.     c="$branch_color$c";
  253.     z="$c_clear$z";
  254.     if [ "$w" = "*" ]; then
  255.         w="$bad_color$w";
  256.     fi;
  257.     if [ -n "$i" ]; then
  258.         i="$ok_color$i";
  259.     fi;
  260.     if [ -n "$s" ]; then
  261.         s="$flags_color$s";
  262.     fi;
  263.     if [ -n "$u" ]; then
  264.         u="$bad_color$u";
  265.     fi;
  266.     r="$c_clear$r"
  267. }
  268. __git_ps1_show_upstream ()
  269. {
  270.     local key value;
  271.     local svn_remote svn_url_pattern count n;
  272.     local upstream=git legacy="" verbose="" name="";
  273.     svn_remote=();
  274.     local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2> /dev/null | tr '\0\n' '\n ')";
  275.     while read -r key value; do
  276.         case "$key" in
  277.             bash.showupstream)
  278.                 GIT_PS1_SHOWUPSTREAM="$value";
  279.                 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
  280.                     p="";
  281.                     return;
  282.                 fi
  283.             ;;
  284.             svn-remote.*.url)
  285.                 svn_remote[$((${#svn_remote[@]} + 1))]="$value";
  286.                 svn_url_pattern="$svn_url_pattern\\|$value";
  287.                 upstream=svn+git
  288.             ;;
  289.         esac;
  290.     done <<< "$output";
  291.     local option;
  292.     for option in ${GIT_PS1_SHOWUPSTREAM};
  293.     do
  294.         case "$option" in
  295.             git | svn)
  296.                 upstream="$option"
  297.             ;;
  298.             verbose)
  299.                 verbose=1
  300.             ;;
  301.             legacy)
  302.                 legacy=1
  303.             ;;
  304.             name)
  305.                 name=1
  306.             ;;
  307.         esac;
  308.     done;
  309.     case "$upstream" in
  310.         git)
  311.             upstream="@{upstream}"
  312.         ;;
  313.         svn*)
  314.             local -a svn_upstream;
  315.             svn_upstream=($(git log --first-parent -1 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2> /dev/null));
  316.             if [[ 0 -ne ${#svn_upstream[@]} ]]; then
  317.                 svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]};
  318.                 svn_upstream=${svn_upstream%@*};
  319.                 local n_stop="${#svn_remote[@]}";
  320.                 for ((n=1; n <= n_stop; n++))
  321.                 do
  322.                     svn_upstream=${svn_upstream#${svn_remote[$n]}};
  323.                 done;
  324.                 if [[ -z "$svn_upstream" ]]; then
  325.                     upstream=${GIT_SVN_ID:-git-svn};
  326.                 else
  327.                     upstream=${svn_upstream#/};
  328.                 fi;
  329.             else
  330.                 if [[ "svn+git" = "$upstream" ]]; then
  331.                     upstream="@{upstream}";
  332.                 fi;
  333.             fi
  334.         ;;
  335.     esac;
  336.     if [[ -z "$legacy" ]]; then
  337.         count="$(git rev-list --count --left-right "$upstream"...HEAD 2> /dev/null)";
  338.     else
  339.         local commits;
  340.         if commits="$(git rev-list --left-right "$upstream"...HEAD 2> /dev/null)"; then
  341.             local commit behind=0 ahead=0;
  342.             for commit in $commits;
  343.             do
  344.                 case "$commit" in
  345.                     "<"*)
  346.                         ((behind++))
  347.                     ;;
  348.                     *)
  349.                         ((ahead++))
  350.                     ;;
  351.                 esac;
  352.             done;
  353.             count="$behind  $ahead";
  354.         else
  355.             count="";
  356.         fi;
  357.     fi;
  358.     if [[ -z "$verbose" ]]; then
  359.         case "$count" in
  360.             "")
  361.                 p=""
  362.             ;;
  363.             "0  0")
  364.                 p="="
  365.             ;;
  366.             "0  "*)
  367.                 p=">"
  368.             ;;
  369.             *"  0")
  370.                 p="<"
  371.             ;;
  372.             *)
  373.                 p="<>"
  374.             ;;
  375.         esac;
  376.     else
  377.         case "$count" in
  378.             "")
  379.                 p=""
  380.             ;;
  381.             "0  0")
  382.                 p=" u="
  383.             ;;
  384.             "0  "*)
  385.                 p=" u+${count#0 }"
  386.             ;;
  387.             *"  0")
  388.                 p=" u-${count%  0}"
  389.             ;;
  390.             *)
  391.                 p=" u+${count#* }-${count%  *}"
  392.             ;;
  393.         esac;
  394.         if [[ -n "$count" && -n "$name" ]]; then
  395.             __git_ps1_upstream_name=$(git rev-parse --abbrev-ref "$upstream" 2> /dev/null);
  396.             if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
  397.                 p="$p \${__git_ps1_upstream_name}";
  398.             else
  399.                 p="$p ${__git_ps1_upstream_name}";
  400.                 unset __git_ps1_upstream_name;
  401.             fi;
  402.         fi;
  403.     fi
  404. }
  405. __git_sequencer_status ()
  406. {
  407.     local todo;
  408.     if test -f "$g/CHERRY_PICK_HEAD"; then
  409.         r="|CHERRY-PICKING";
  410.         return 0;
  411.     else
  412.         if test -f "$g/REVERT_HEAD"; then
  413.             r="|REVERTING";
  414.             return 0;
  415.         else
  416.             if __git_eread "$g/sequencer/todo" todo; then
  417.                 case "$todo" in
  418.                     p[\ \   ] | pick[\ \    ]*)
  419.                         r="|CHERRY-PICKING";
  420.                         return 0
  421.                     ;;
  422.                     revert[\ \  ]*)
  423.                         r="|REVERTING";
  424.                         return 0
  425.                     ;;
  426.                 esac;
  427.             fi;
  428.         fi;
  429.     fi;
  430.     return 1
  431. }
  432. __load_completion ()
  433. {
  434.     local -a dirs=(${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions);
  435.     local ifs=$IFS IFS=: dir cmd="${1##*/}" compfile;
  436.     [[ -n $cmd ]] || return 1;
  437.     for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share};
  438.     do
  439.         dirs+=($dir/bash-completion/completions);
  440.     done;
  441.     IFS=$ifs;
  442.     if [[ $BASH_SOURCE == */* ]]; then
  443.         dirs+=("${BASH_SOURCE%/*}/completions");
  444.     else
  445.         dirs+=(./completions);
  446.     fi;
  447.     local backslash=;
  448.     if [[ $cmd == \\* ]]; then
  449.         cmd="${cmd:1}";
  450.         $(complete -p "$cmd" 2> /dev/null || echo false) "\\$cmd" && return 0;
  451.         backslash=\\;
  452.     fi;
  453.     for dir in "${dirs[@]}";
  454.     do
  455.         [[ -d $dir ]] || continue;
  456.         for compfile in "$cmd" "$cmd.bash" "_$cmd";
  457.         do
  458.             compfile="$dir/$compfile";
  459.             if [[ -f $compfile ]] && . "$compfile" &> /dev/null; then
  460.                 [[ -n $backslash ]] && $(complete -p "$cmd") "\\$cmd";
  461.                 return 0;
  462.             fi;
  463.         done;
  464.     done;
  465.     [[ -v _xspecs[$cmd] ]] && complete -F _filedir_xspec "$cmd" "$backslash$cmd" && return 0;
  466.     return 1
  467. }
  468. __ltrim_colon_completions ()
  469. {
  470.     if [[ $1 == *:* && $COMP_WORDBREAKS == *:* ]]; then
  471.         local colon_word=${1%"${1##*:}"};
  472.        local i=${#COMPREPLY[*]};
  473.        while ((i-- > 0)); do
  474.            COMPREPLY[i]=${COMPREPLY[i]#"$colon_word"};
  475.        done;
  476.    fi
  477. }
  478. __parse_options ()
  479. {
  480.     local option option2 i IFS='    
  481. ,/|';
  482.    option=;
  483.    local -a array=($1);
  484.    for i in "${array[@]}";
  485.    do
  486.        case "$i" in
  487.            ---*)
  488.                break
  489.            ;;
  490.            --?*)
  491.                option=$i;
  492.                break
  493.            ;;
  494.            -?*)
  495.                [[ -n $option ]] || option=$i
  496.            ;;
  497.            *)
  498.                break
  499.            ;;
  500.        esac;
  501.    done;
  502.    [[ -n $option ]] || return 0;
  503.     IFS='  
  504. ';
  505.    if [[ $option =~ (\[((no|dont)-?)\]). ]]; then
  506.        option2=${option/"${BASH_REMATCH[1]}"/};
  507.         option2=${option2%%[<{().[]*};
  508.         printf '%s\n' "${option2/=*/=}";
  509.         option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"};
  510.    fi;
  511.    option=${option%%[<{().[]*};
  512.    printf '%s\n' "${option/=*/=}"
  513. }
  514. __reassemble_comp_words_by_ref ()
  515. {
  516.    local exclude i j line ref;
  517.    if [[ -n $1 ]]; then
  518.        exclude="[${1//[^$COMP_WORDBREAKS]/}]";
  519.    fi;
  520.    printf -v "$3" %s "$COMP_CWORD";
  521.    if [[ -v exclude ]]; then
  522.        line=$COMP_LINE;
  523.        for ((i = 0, j = 0; i < ${#COMP_WORDS[@]}; i++, j++))
  524.        do
  525.            while [[ $i -gt 0 && ${COMP_WORDS[i]} == +($exclude) ]]; do
  526.                [[ $line != [[:blank:]]* ]] && ((j >= 2)) && ((j--));
  527.                ref="$2[$j]";
  528.                printf -v "$ref" %s "${!ref-}${COMP_WORDS[i]}";
  529.                ((i == COMP_CWORD)) && printf -v "$3" %s "$j";
  530.                line=${line#*"${COMP_WORDS[i]}"};
  531.                 [[ $line == [[:blank:]]* ]] && ((j++));
  532.                 ((i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2;
  533.             done;
  534.             ref="$2[$j]";
  535.             printf -v "$ref" %s "${!ref-}${COMP_WORDS[i]}";
  536.             line=${line#*"${COMP_WORDS[i]}"};
  537.            ((i == COMP_CWORD)) && printf -v "$3" %s "$j";
  538.        done;
  539.        ((i == COMP_CWORD)) && printf -v "$3" %s "$j";
  540.    else
  541.        for i in "${!COMP_WORDS[@]}";
  542.        do
  543.            printf -v "$2[i]" %s "${COMP_WORDS[i]}";
  544.        done;
  545.    fi
  546. }
  547. _allowed_groups ()
  548. {
  549.    if _complete_as_root; then
  550.        local IFS='
  551. ';
  552.        COMPREPLY=($(compgen -g -- "$1"));
  553.    else
  554.        local IFS='
  555. ';
  556.        COMPREPLY=($(compgen -W "$(id -Gn 2> /dev/null || groups 2> /dev/null)" -- "$1"));
  557.     fi
  558. }
  559. _allowed_users ()
  560. {
  561.     if _complete_as_root; then
  562.         local IFS='
  563. ';
  564.         COMPREPLY=($(compgen -u -- "${1:-$cur}"));
  565.     else
  566.         local IFS='
  567. ';
  568.         COMPREPLY=($(compgen -W "$(id -un 2> /dev/null || whoami 2> /dev/null)" -- "${1:-$cur}"));
  569.     fi
  570. }
  571. _available_interfaces ()
  572. {
  573.     local PATH=$PATH:/sbin;
  574.     COMPREPLY=($({ if [[ ${1:-} == -w ]]; then
  575.     iwconfig;
  576. else
  577.     if [[ ${1:-} == -a ]]; then
  578.         ifconfig || ip link show up;
  579.     else
  580.         ifconfig -a || ip link show;
  581.     fi;
  582. fi; } 2> /dev/null | awk '/^[^ \t]/ { if ($1 ~ /^[0-9]+:/) { print $2 } else { print $1 } }'));
  583.     COMPREPLY=($(compgen -W '${COMPREPLY[@]/%[[:punct:]]/}' -- "$cur"))
  584. }
  585. _bashcomp_try_faketty ()
  586. {
  587.     if type unbuffer &> /dev/null; then
  588.         unbuffer -p "$@";
  589.     else
  590.         if script --version 2>&1 | command grep -qF util-linux; then
  591.             script -qaefc "$*" /dev/null;
  592.         else
  593.             "$@";
  594.         fi;
  595.     fi
  596. }
  597. _cd ()
  598. {
  599.     local cur prev words cword;
  600.     _init_completion || return;
  601.     local IFS='
  602. ' i j k;
  603.     compopt -o filenames;
  604.     if [[ -z ${CDPATH:-} || $cur == ?(.)?(.)/* ]]; then
  605.         _filedir -d;
  606.         return;
  607.     fi;
  608.     local -r mark_dirs=$(_rl_enabled mark-directories && echo y);
  609.     local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y);
  610.     for i in ${CDPATH//:/'
  611. '};
  612.     do
  613.         k="${#COMPREPLY[@]}";
  614.         for j in $(compgen -d -- $i/$cur);
  615.         do
  616.             if [[ ( -n $mark_symdirs && -L $j || -n $mark_dirs && ! -L $j ) && ! -d ${j#$i/} ]]; then
  617.                 j+="/";
  618.             fi;
  619.             COMPREPLY[k++]=${j#$i/};
  620.         done;
  621.     done;
  622.     _filedir -d;
  623.     if ((${#COMPREPLY[@]} == 1)); then
  624.         i=${COMPREPLY[0]};
  625.         if [[ $i == "$cur" && $i != "*/" ]]; then
  626.             COMPREPLY[0]="${i}/";
  627.         fi;
  628.     fi;
  629.     return
  630. }
  631. _cd_devices ()
  632. {
  633.     COMPREPLY+=($(compgen -f -d -X "!*/?([amrs])cd*" -- "${cur:-/dev/}"))
  634. }
  635. _command ()
  636. {
  637.     local offset i;
  638.     offset=1;
  639.     for ((i = 1; i <= COMP_CWORD; i++))
  640.     do
  641.         if [[ ${COMP_WORDS[i]} != -* ]]; then
  642.             offset=$i;
  643.             break;
  644.         fi;
  645.     done;
  646.     _command_offset $offset
  647. }
  648. _command_offset ()
  649. {
  650.     local word_offset=$1 i j;
  651.     for ((i = 0; i < word_offset; i++))
  652.     do
  653.         for ((j = 0; j <= ${#COMP_LINE}; j++))
  654.         do
  655.             [[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break;
  656.             COMP_LINE=${COMP_LINE:1};
  657.             ((COMP_POINT--));
  658.         done;
  659.         COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"};
  660.        ((COMP_POINT -= ${#COMP_WORDS[i]}));
  661.    done;
  662.    for ((i = 0; i <= COMP_CWORD - word_offset; i++))
  663.    do
  664.        COMP_WORDS[i]=${COMP_WORDS[i + word_offset]};
  665.    done;
  666.    for ((i; i <= COMP_CWORD; i++))
  667.    do
  668.        unset 'COMP_WORDS[i]';
  669.    done;
  670.    ((COMP_CWORD -= word_offset));
  671.    COMPREPLY=();
  672.    local cur;
  673.    _get_comp_words_by_ref cur;
  674.    if ((COMP_CWORD == 0)); then
  675.        local IFS='
  676. ';
  677.        compopt -o filenames;
  678.        COMPREPLY=($(compgen -d -c -- "$cur"));
  679.    else
  680.        local cmd=${COMP_WORDS[0]} compcmd=${COMP_WORDS[0]};
  681.        local cspec=$(complete -p $cmd 2> /dev/null);
  682.        if [[ ! -n $cspec && $cmd == */* ]]; then
  683.            cspec=$(complete -p ${cmd##*/} 2> /dev/null);
  684.            [[ -n $cspec ]] && compcmd=${cmd##*/};
  685.        fi;
  686.        if [[ ! -n $cspec ]]; then
  687.            compcmd=${cmd##*/};
  688.            _completion_loader $compcmd;
  689.            cspec=$(complete -p $compcmd 2> /dev/null);
  690.        fi;
  691.        if [[ -n $cspec ]]; then
  692.            if [[ ${cspec#* -F } != "$cspec" ]]; then
  693.                local func=${cspec#*-F };
  694.                func=${func%% *};
  695.                if ((${#COMP_WORDS[@]} >= 2)); then
  696.                    $func $cmd "${COMP_WORDS[-1]}" "${COMP_WORDS[-2]}";
  697.                else
  698.                    $func $cmd "${COMP_WORDS[-1]}";
  699.                fi;
  700.                local opt;
  701.                while [[ $cspec == *" -o "* ]]; do
  702.                    cspec=${cspec#*-o };
  703.                    opt=${cspec%% *};
  704.                    compopt -o $opt;
  705.                    cspec=${cspec#$opt};
  706.                done;
  707.            else
  708.                cspec=${cspec#complete};
  709.                cspec=${cspec%%$compcmd};
  710.                COMPREPLY=($(eval compgen "$cspec" -- '$cur'));
  711.            fi;
  712.        else
  713.            if ((${#COMPREPLY[@]} == 0)); then
  714.                _minimal;
  715.            fi;
  716.        fi;
  717.    fi
  718. }
  719. _complete_as_root ()
  720. {
  721.    [[ $EUID -eq 0 || -n ${root_command:-} ]]
  722. }
  723. _completion_loader ()
  724. {
  725.    local cmd="${1:-_EmptycmD_}";
  726.    __load_completion "$cmd" && return 124;
  727.    complete -F _minimal -- "$cmd" && return 124
  728. }
  729. _configured_interfaces ()
  730. {
  731.    if [[ -f /etc/debian_version ]]; then
  732.        COMPREPLY=($(compgen -W "$(command sed -ne 's|^iface \([^ ]\{1,\}\).*$|\1|p' /etc/network/interfaces /etc/network/interfaces.d/* 2> /dev/null)" -- "$cur"));
  733.     else
  734.         if [[ -f /etc/SuSE-release ]]; then
  735.             COMPREPLY=($(compgen -W "$(printf '%s\n' /etc/sysconfig/network/ifcfg-* | command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')" -- "$cur"));
  736.         else
  737.             if [[ -f /etc/pld-release ]]; then
  738.                 COMPREPLY=($(compgen -W "$(command ls -B /etc/sysconfig/interfaces | command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')" -- "$cur"));
  739.             else
  740.                 COMPREPLY=($(compgen -W "$(printf '%s\n' /etc/sysconfig/network-scripts/ifcfg-* | command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p')" -- "$cur"));
  741.             fi;
  742.         fi;
  743.     fi
  744. }
  745. _count_args ()
  746. {
  747.     local i cword words;
  748.     __reassemble_comp_words_by_ref "${1-}" words cword;
  749.     args=1;
  750.     for ((i = 1; i < cword; i++))
  751.     do
  752.         if [[ ${words[i]} != -* && ${words[i - 1]} != ${2-} || ${words[i]} == ${3-} ]]; then
  753.             ((args++));
  754.         fi;
  755.     done
  756. }
  757. _dvd_devices ()
  758. {
  759.     COMPREPLY+=($(compgen -f -d -X "!*/?(r)dvd*" -- "${cur:-/dev/}"))
  760. }
  761. _expand ()
  762. {
  763.     case ${cur-} in
  764.         ~*/*)
  765.             __expand_tilde_by_ref cur
  766.         ;;
  767.         ~*)
  768.             _tilde "$cur" || eval COMPREPLY[0]="$(printf ~%q "${COMPREPLY[0]#\~}")";
  769.             return ${#COMPREPLY[@]}
  770.         ;;
  771.     esac
  772. }
  773. _filedir ()
  774. {
  775.     local IFS='
  776. ';
  777.     _tilde "${cur-}" || return;
  778.     local -a toks;
  779.     local reset arg=${1-};
  780.     if [[ $arg == -d ]]; then
  781.         reset=$(shopt -po noglob);
  782.         set -o noglob;
  783.         toks=($(compgen -d -- "${cur-}"));
  784.         IFS=' ';
  785.         $reset;
  786.         IFS='
  787. ';
  788.     else
  789.         local quoted;
  790.         _quote_readline_by_ref "${cur-}" quoted;
  791.         local xspec=${arg:+"!*.@($arg|${arg^^})"} plusdirs=();
  792.        local opts=(-f -X "$xspec");
  793.        [[ -n $xspec ]] && plusdirs=(-o plusdirs);
  794.        [[ -n ${COMP_FILEDIR_FALLBACK-} || -z ${plusdirs-} ]] || opts+=("${plusdirs[@]}");
  795.        reset=$(shopt -po noglob);
  796.        set -o noglob;
  797.        toks+=($(compgen "${opts[@]}" -- $quoted));
  798.        IFS=' ';
  799.        $reset;
  800.        IFS='
  801. ';
  802.        [[ -n ${COMP_FILEDIR_FALLBACK-} && -n $arg && ${#toks[@]} -lt 1 ]] && {
  803.            reset=$(shopt -po noglob);
  804.            set -o noglob;
  805.            toks+=($(compgen -f ${plusdirs+"${plusdirs[@]}"} -- $quoted));
  806.            IFS=' ';
  807.            $reset;
  808.            IFS='
  809. '
  810.        };
  811.    fi;
  812.    if ((${#toks[@]} != 0)); then
  813.        compopt -o filenames 2> /dev/null;
  814.        COMPREPLY+=("${toks[@]}");
  815.    fi
  816. }
  817. _filedir_xspec ()
  818. {
  819.    local cur prev words cword;
  820.    _init_completion || return;
  821.    _tilde "$cur" || return;
  822.    local IFS='
  823. ' xspec=${_xspecs[${1##*/}]} tmp;
  824.    local -a toks;
  825.    toks=($(compgen -d -- "$(quote_readline "$cur")" | { while read -r tmp; do
  826.     printf '%s\n' $tmp;
  827. done; }));
  828.     eval xspec="${xspec}";
  829.     local matchop=!;
  830.     if [[ $xspec == !* ]]; then
  831.         xspec=${xspec#!};
  832.         matchop=@;
  833.     fi;
  834.     xspec="$matchop($xspec|${xspec^^})";
  835.     toks+=($(eval compgen -f -X "'!$xspec'" -- '$(quote_readline "$cur")' | { while read -r tmp; do
  836.     [[ -n $tmp ]] && printf '%s\n' $tmp;
  837. done; }));
  838.     [[ -n ${COMP_FILEDIR_FALLBACK:-} && ${#toks[@]} -lt 1 ]] && {
  839.         local reset=$(shopt -po noglob);
  840.         set -o noglob;
  841.         toks+=($(compgen -f -- "$(quote_readline "$cur")"));
  842.         IFS=' ';
  843.         $reset;
  844.         IFS='
  845. '
  846.     };
  847.     if ((${#toks[@]} != 0)); then
  848.         compopt -o filenames;
  849.         COMPREPLY=("${toks[@]}");
  850.     fi
  851. }
  852. _fstypes ()
  853. {
  854.     local fss;
  855.     if [[ -e /proc/filesystems ]]; then
  856.         fss="$(cut -d'  ' -f2 /proc/filesystems)
  857.             $(awk '! /\*/ { print $NF }' /etc/filesystems 2> /dev/null)";
  858.     else
  859.         fss="$(awk '/^[ \t]*[^#]/ { print $3 }' /etc/fstab 2> /dev/null)
  860.             $(awk '/^[ \t]*[^#]/ { print $3 }' /etc/mnttab 2> /dev/null)
  861.             $(awk '/^[ \t]*[^#]/ { print $4 }' /etc/vfstab 2> /dev/null)
  862.             $(awk '{ print $1 }' /etc/dfs/fstypes 2> /dev/null)
  863.             $([[ -d /etc/fs ]] && command ls /etc/fs)";
  864.     fi;
  865.     [[ -n $fss ]] && COMPREPLY+=($(compgen -W "$fss" -- "$cur"))
  866. }
  867. _get_comp_words_by_ref ()
  868. {
  869.     local exclude flag i OPTIND=1;
  870.     local cur cword words=();
  871.     local upargs=() upvars=() vcur vcword vprev vwords;
  872.     while getopts "c:i:n:p:w:" flag "$@"; do
  873.         case $flag in
  874.             c)
  875.                 vcur=$OPTARG
  876.             ;;
  877.             i)
  878.                 vcword=$OPTARG
  879.             ;;
  880.             n)
  881.                 exclude=$OPTARG
  882.             ;;
  883.             p)
  884.                 vprev=$OPTARG
  885.             ;;
  886.             w)
  887.                 vwords=$OPTARG
  888.             ;;
  889.             *)
  890.                 echo "bash_completion: $FUNCNAME: usage error" 1>&2;
  891.                 return 1
  892.             ;;
  893.         esac;
  894.     done;
  895.     while [[ $# -ge $OPTIND ]]; do
  896.         case ${!OPTIND} in
  897.             cur)
  898.                 vcur=cur
  899.             ;;
  900.             prev)
  901.                 vprev=prev
  902.             ;;
  903.             cword)
  904.                 vcword=cword
  905.             ;;
  906.             words)
  907.                 vwords=words
  908.             ;;
  909.             *)
  910.                 echo "bash_completion: $FUNCNAME: \`${!OPTIND}':" "unknown argument" 1>&2;
  911.                return 1
  912.            ;;
  913.        esac;
  914.        ((OPTIND += 1));
  915.    done;
  916.    __get_cword_at_cursor_by_ref "${exclude-}" words cword cur;
  917.    [[ -v vcur ]] && {
  918.        upvars+=("$vcur");
  919.        upargs+=(-v $vcur "$cur")
  920.    };
  921.    [[ -v vcword ]] && {
  922.        upvars+=("$vcword");
  923.        upargs+=(-v $vcword "$cword")
  924.    };
  925.    [[ -v vprev && $cword -ge 1 ]] && {
  926.        upvars+=("$vprev");
  927.        upargs+=(-v $vprev "${words[cword - 1]}")
  928.    };
  929.    [[ -v vwords ]] && {
  930.        upvars+=("$vwords");
  931.        upargs+=(-a${#words[@]} $vwords ${words+"${words[@]}"})
  932.    };
  933.    ((${#upvars[@]})) && local "${upvars[@]}" && _upvars "${upargs[@]}"
  934. }
  935. _get_cword ()
  936. {
  937.    local LC_CTYPE=C;
  938.    local cword words;
  939.    __reassemble_comp_words_by_ref "${1-}" words cword;
  940.    if [[ -n ${2-} && -n ${2//[^0-9]/} ]]; then
  941.        printf "%s" "${words[cword - $2]}";
  942.    else
  943.        if ((${#words[cword]} == 0 && COMP_POINT == ${#COMP_LINE})); then
  944.            :;
  945.        else
  946.            local i;
  947.            local cur="$COMP_LINE";
  948.            local index="$COMP_POINT";
  949.            for ((i = 0; i <= cword; ++i))
  950.            do
  951.                while [[ ${#cur} -ge ${#words[i]} && ${cur:0:${#words[i]}} != "${words[i]}" ]]; do
  952.                    cur="${cur:1}";
  953.                    ((index > 0)) && ((index--));
  954.                done;
  955.                if ((i < cword)); then
  956.                    local old_size="${#cur}";
  957.                    cur="${cur#${words[i]}}";
  958.                    local new_size="${#cur}";
  959.                    ((index -= old_size - new_size));
  960.                fi;
  961.            done;
  962.            if [[ ${words[cword]:0:${#cur}} != "$cur" ]]; then
  963.                printf "%s" "${words[cword]}";
  964.            else
  965.                printf "%s" "${cur:0:index}";
  966.            fi;
  967.        fi;
  968.    fi
  969. }
  970. _get_first_arg ()
  971. {
  972.    local i;
  973.    arg=;
  974.    for ((i = 1; i < COMP_CWORD; i++))
  975.    do
  976.        if [[ ${COMP_WORDS[i]} != -* ]]; then
  977.            arg=${COMP_WORDS[i]};
  978.            break;
  979.        fi;
  980.    done
  981. }
  982. _get_pword ()
  983. {
  984.    if ((COMP_CWORD >= 1)); then
  985.        _get_cword "${@:-}" 1;
  986.    fi
  987. }
  988. _gids ()
  989. {
  990.    if type getent &> /dev/null; then
  991.        COMPREPLY=($(compgen -W '$(getent group | cut -d: -f3)' -- "$cur"));
  992.    else
  993.        if type perl &> /dev/null; then
  994.            COMPREPLY=($(compgen -W '$(perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"')' -- "$cur"));
  995.        else
  996.            COMPREPLY=($(compgen -W '$(cut -d: -f3 /etc/group)' -- "$cur"));
  997.        fi;
  998.    fi
  999. }
  1000. _have ()
  1001. {
  1002.    PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type $1 &> /dev/null
  1003. }
  1004. _included_ssh_config_files ()
  1005. {
  1006.    (($# < 1)) && echo "bash_completion: $FUNCNAME: missing mandatory argument CONFIG" 1>&2;
  1007.    local configfile i f;
  1008.    configfile=$1;
  1009.    local reset=$(shopt -po noglob);
  1010.    set -o noglob;
  1011.    local included=($(command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\(.*\)$/\1/p' "${configfile}"));
  1012.    $reset;
  1013.    [[ -n ${included-} ]] || return;
  1014.    for i in "${included[@]}";
  1015.    do
  1016.        if ! [[ $i =~ ^\~.*|^\/.* ]]; then
  1017.            if [[ $configfile =~ ^\/etc\/ssh.* ]]; then
  1018.                i="/etc/ssh/$i";
  1019.            else
  1020.                i="$HOME/.ssh/$i";
  1021.            fi;
  1022.        fi;
  1023.        __expand_tilde_by_ref i;
  1024.        set +o noglob;
  1025.        for f in $i;
  1026.        do
  1027.            if [[ -r $f ]]; then
  1028.                config+=("$f");
  1029.                _included_ssh_config_files $f;
  1030.            fi;
  1031.        done;
  1032.        $reset;
  1033.    done
  1034. }
  1035. _init_completion ()
  1036. {
  1037.    local exclude="" flag outx errx inx OPTIND=1;
  1038.    while getopts "n:e:o:i:s" flag "$@"; do
  1039.        case $flag in
  1040.            n)
  1041.                exclude+=$OPTARG
  1042.            ;;
  1043.            e)
  1044.                errx=$OPTARG
  1045.            ;;
  1046.            o)
  1047.                outx=$OPTARG
  1048.            ;;
  1049.            i)
  1050.                inx=$OPTARG
  1051.            ;;
  1052.            s)
  1053.                split=false;
  1054.                exclude+==
  1055.            ;;
  1056.            *)
  1057.                echo "bash_completion: $FUNCNAME: usage error" 1>&2;
  1058.                return 1
  1059.            ;;
  1060.        esac;
  1061.    done;
  1062.    COMPREPLY=();
  1063.    local redir="@(?([0-9])<|?([0-9&])>?(>)|>&)";
  1064.    _get_comp_words_by_ref -n "$exclude<>&" cur prev words cword;
  1065.    _variables && return 1;
  1066.    if [[ $cur == $redir* || ${prev-} == $redir ]]; then
  1067.        local xspec;
  1068.        case $cur in
  1069.            2'>'*)
  1070.                xspec=${errx-}
  1071.            ;;
  1072.            *'>'*)
  1073.                xspec=${outx-}
  1074.            ;;
  1075.            *'<'*)
  1076.                xspec=${inx-}
  1077.            ;;
  1078.            *)
  1079.                case $prev in
  1080.                    2'>'*)
  1081.                        xspec=${errx-}
  1082.                    ;;
  1083.                    *'>'*)
  1084.                        xspec=${outx-}
  1085.                    ;;
  1086.                    *'<'*)
  1087.                        xspec=${inx-}
  1088.                    ;;
  1089.                esac
  1090.            ;;
  1091.        esac;
  1092.        cur="${cur##$redir}";
  1093.        _filedir $xspec;
  1094.        return 1;
  1095.    fi;
  1096.    local i skip;
  1097.    for ((i = 1; i < ${#words[@]}; 1))
  1098.    do
  1099.        if [[ ${words[i]} == $redir* ]]; then
  1100.            [[ ${words[i]} == $redir ]] && skip=2 || skip=1;
  1101.            words=("${words[@]:0:i}" "${words[@]:i+skip}");
  1102.            ((i <= cword)) && ((cword -= skip));
  1103.        else
  1104.            ((i++));
  1105.        fi;
  1106.    done;
  1107.    ((cword <= 0)) && return 1;
  1108.    prev=${words[cword - 1]};
  1109.    [[ -n ${split-} ]] && _split_longopt && split=true;
  1110.    return 0
  1111. }
  1112. _installed_modules ()
  1113. {
  1114.    COMPREPLY=($(compgen -W "$(PATH="$PATH:/sbin" lsmod | awk '{if (NR != 1) print $1}')" -- "$1"))
  1115. }
  1116. _ip_addresses ()
  1117. {
  1118.    local n;
  1119.    case ${1-} in
  1120.        -a)
  1121.            n='6\?'
  1122.        ;;
  1123.        -6)
  1124.            n='6'
  1125.        ;;
  1126.        *)
  1127.            n=
  1128.        ;;
  1129.    esac;
  1130.    local PATH=$PATH:/sbin;
  1131.    local addrs=$({ LC_ALL=C ifconfig -a || ip addr show; } 2> /dev/null | command sed -e 's/[[:space:]]addr:/ /' -ne "s|.*inet${n}[[:space:]]\{1,\}\([^[:space:]/]*\).*|\1|p");
  1132.    COMPREPLY+=($(compgen -W "$addrs" -- "${cur-}"))
  1133. }
  1134. _kernel_versions ()
  1135. {
  1136.    COMPREPLY=($(compgen -W '$(command ls /lib/modules)' -- "$cur"))
  1137. }
  1138. _known_hosts ()
  1139. {
  1140.    local cur prev words cword;
  1141.    _init_completion -n : || return;
  1142.    local options;
  1143.    [[ ${1-} == -a || ${2-} == -a ]] && options=-a;
  1144.    [[ ${1-} == -c || ${2-} == -c ]] && options+=" -c";
  1145.    _known_hosts_real ${options-} -- "$cur"
  1146. }
  1147. _known_hosts_real ()
  1148. {
  1149.    local configfile flag prefix="" ifs=$IFS;
  1150.    local cur suffix="" aliases i host ipv4 ipv6;
  1151.    local -a kh tmpkh=() khd=() config=();
  1152.    local OPTIND=1;
  1153.    while getopts "ac46F:p:" flag "$@"; do
  1154.        case $flag in
  1155.            a)
  1156.                aliases='yes'
  1157.            ;;
  1158.            c)
  1159.                suffix=':'
  1160.            ;;
  1161.            F)
  1162.                configfile=$OPTARG
  1163.            ;;
  1164.            p)
  1165.                prefix=$OPTARG
  1166.            ;;
  1167.            4)
  1168.                ipv4=1
  1169.            ;;
  1170.            6)
  1171.                ipv6=1
  1172.            ;;
  1173.            *)
  1174.                echo "bash_completion: $FUNCNAME: usage error" 1>&2;
  1175.                return 1
  1176.            ;;
  1177.        esac;
  1178.    done;
  1179.    if (($# < OPTIND)); then
  1180.        echo "bash_completion: $FUNCNAME: missing mandatory argument CWORD" 1>&2;
  1181.        return 1;
  1182.    fi;
  1183.    cur=${!OPTIND};
  1184.    ((OPTIND += 1));
  1185.    if (($# >= OPTIND)); then
  1186.        echo "bash_completion: $FUNCNAME($*): unprocessed arguments:" "$(while (($# >= OPTIND)); do
  1187.    printf '%s ' ${!OPTIND}
  1188. shift;
  1189. done)" 1>&2;
  1190.        return 1;
  1191.    fi;
  1192.    [[ $cur == *@* ]] && prefix=$prefix${cur%@*}@ && cur=${cur#*@};
  1193.    kh=();
  1194.    if [[ -v configfile ]]; then
  1195.        [[ -r $configfile ]] && config+=("$configfile");
  1196.    else
  1197.        for i in /etc/ssh/ssh_config ~/.ssh/config ~/.ssh2/config;
  1198.        do
  1199.            [[ -r $i ]] && config+=("$i");
  1200.        done;
  1201.    fi;
  1202.    local reset=$(shopt -po noglob);
  1203.    set -o noglob;
  1204.    if ((${#config[@]} > 0)); then
  1205.        for i in "${config[@]}";
  1206.        do
  1207.            _included_ssh_config_files "$i";
  1208.        done;
  1209.    fi;
  1210.    if ((${#config[@]} > 0)); then
  1211.        local IFS='
  1212. ';
  1213.        tmpkh=($(awk 'sub("^[ \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]+", "") { print $0 }' "${config[@]}" | sort -u));
  1214.        IFS=$ifs;
  1215.    fi;
  1216.    if ((${#tmpkh[@]} != 0)); then
  1217.        local j;
  1218.        for i in "${tmpkh[@]}";
  1219.        do
  1220.            while [[ $i =~ ^([^\"]*)\"([^\"]*)\"(.*)$ ]]; do
  1221.                i=${BASH_REMATCH[1]}${BASH_REMATCH[3]};
  1222.                j=${BASH_REMATCH[2]};
  1223.                __expand_tilde_by_ref j;
  1224.                [[ -r $j ]] && kh+=("$j");
  1225.            done;
  1226.            for j in $i;
  1227.            do
  1228.                __expand_tilde_by_ref j;
  1229.                [[ -r $j ]] && kh+=("$j");
  1230.            done;
  1231.        done;
  1232.    fi;
  1233.    if [[ ! -v configfile ]]; then
  1234.        for i in /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 /etc/known_hosts /etc/known_hosts2 ~/.ssh/known_hosts ~/.ssh/known_hosts2;
  1235.        do
  1236.            [[ -r $i ]] && kh+=("$i");
  1237.        done;
  1238.        for i in /etc/ssh2/knownhosts ~/.ssh2/hostkeys;
  1239.        do
  1240.            [[ -d $i ]] && khd+=("$i"/*pub);
  1241.        done;
  1242.    fi;
  1243.    if ((${#kh[@]} + ${#khd[@]} > 0)); then
  1244.        if ((${#kh[@]} > 0)); then
  1245.            for i in "${kh[@]}";
  1246.            do
  1247.                while read -ra tmpkh; do
  1248.                    ((${#tmpkh[@]} == 0)) && continue;
  1249.                    set -- "${tmpkh[@]}";
  1250.                    [[ $1 == [\|\#]* ]] && continue;
  1251.                    [[ $1 == @* ]] && shift;
  1252.                    local IFS=,;
  1253.                    for host in $1;
  1254.                    do
  1255.                        [[ $host == *[*?]* ]] && continue;
  1256.                        host="${host#[}";
  1257.                        host="${host%]?(:+([0-9]))}";
  1258.                        COMPREPLY+=($host);
  1259.                    done;
  1260.                    IFS=$ifs;
  1261.                done < "$i";
  1262.            done;
  1263.            COMPREPLY=($(compgen -W '${COMPREPLY[@]}' -- "$cur"));
  1264.        fi;
  1265.        if ((${#khd[@]} > 0)); then
  1266.            for i in "${khd[@]}";
  1267.            do
  1268.                if [[ $i == *key_22_$cur*.pub && -r $i ]]; then
  1269.                    host=${i/#*key_22_/};
  1270.                    host=${host/%.pub/};
  1271.                    COMPREPLY+=($host);
  1272.                fi;
  1273.            done;
  1274.        fi;
  1275.        for i in ${!COMPREPLY[*]};
  1276.        do
  1277.            COMPREPLY[i]=$prefix${COMPREPLY[i]}$suffix;
  1278.        done;
  1279.    fi;
  1280.    if [[ ${#config[@]} -gt 0 && -v aliases ]]; then
  1281.        local -a hosts=($(command sed -ne 's/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]]\(.*\)$/\1/p' "${config[@]}"));
  1282.        if ((${#hosts[@]} != 0)); then
  1283.            COMPREPLY+=($(compgen -P "$prefix" -S "$suffix" -W '${hosts[@]%%[*?%]*}' -X '\!*' -- "$cur"));
  1284.        fi;
  1285.    fi;
  1286.    if [[ -n ${COMP_KNOWN_HOSTS_WITH_AVAHI-} ]] && type avahi-browse &> /dev/null; then
  1287.        COMPREPLY+=($(compgen -P "$prefix" -S "$suffix" -W "$(avahi-browse -cpr _workstation._tcp 2> /dev/null | awk -F';' '/^=/ { print $7 }' | sort -u)" -- "$cur"));
  1288.    fi;
  1289.    if type ruptime &> /dev/null; then
  1290.        COMPREPLY+=($(compgen -W "$(ruptime 2> /dev/null | awk '!/^ruptime:/ { print $1 }')" -- "$cur"));
  1291.    fi;
  1292.    if [[ -n ${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1} ]]; then
  1293.        COMPREPLY+=($(compgen -A hostname -P "$prefix" -S "$suffix" -- "$cur"));
  1294.    fi;
  1295.    $reset;
  1296.    if [[ -v ipv4 ]]; then
  1297.        COMPREPLY=("${COMPREPLY[@]/*:*$suffix/}");
  1298.    fi;
  1299.    if [[ -v ipv6 ]]; then
  1300.        COMPREPLY=("${COMPREPLY[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}");
  1301.    fi;
  1302.    if [[ -v ipv4 || -v ipv6 ]]; then
  1303.        for i in "${!COMPREPLY[@]}";
  1304.        do
  1305.            [[ -n ${COMPREPLY[i]} ]] || unset -v "COMPREPLY[i]";
  1306.        done;
  1307.    fi;
  1308.    __ltrim_colon_completions "$prefix$cur"
  1309. }
  1310. _longopt ()
  1311. {
  1312.    local cur prev words cword split;
  1313.    _init_completion -s || return;
  1314.    case "${prev,,}" in
  1315.        --help | --usage | --version)
  1316.            return
  1317.        ;;
  1318.        --!(no-*)dir*)
  1319.            _filedir -d;
  1320.            return
  1321.        ;;
  1322.        --!(no-*)@(file|path)*)
  1323.            _filedir;
  1324.            return
  1325.        ;;
  1326.        --+([-a-z0-9_]))
  1327.            local argtype=$(LC_ALL=C $1 --help 2>&1 | command sed -ne "s|.*$prev\[\{0,1\}=[<[]\{0,1\}\([-A-Za-z0-9_]\{1,\}\).*|\1|p");
  1328.            case ${argtype,,} in
  1329.                *dir*)
  1330.                    _filedir -d;
  1331.                    return
  1332.                ;;
  1333.                *file* | *path*)
  1334.                    _filedir;
  1335.                    return
  1336.                ;;
  1337.            esac
  1338.        ;;
  1339.    esac;
  1340.    $split && return;
  1341.    if [[ $cur == -* ]]; then
  1342.        COMPREPLY=($(compgen -W "$(LC_ALL=C $1 --help 2>&1 | while read -r line; do
  1343.    [[ $line =~ --[A-Za-z0-9]+([-_][A-Za-z0-9]+)*=? ]] && printf '%s\n' ${BASH_REMATCH[0]};
  1344. done)" -- "$cur"));
  1345.        [[ ${COMPREPLY-} == *= ]] && compopt -o nospace;
  1346.    else
  1347.        if [[ $1 == *@(rmdir|chroot) ]]; then
  1348.            _filedir -d;
  1349.        else
  1350.            [[ $1 == *mkdir ]] && compopt -o nospace;
  1351.            _filedir;
  1352.        fi;
  1353.    fi
  1354. }
  1355. _mac_addresses ()
  1356. {
  1357.    local re='\([A-Fa-f0-9]\{2\}:\)\{5\}[A-Fa-f0-9]\{2\}';
  1358.    local PATH="$PATH:/sbin:/usr/sbin";
  1359.    COMPREPLY+=($({ LC_ALL=C ifconfig -a || ip link show; } 2> /dev/null | command sed -ne "s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($re\)[[:space:]].*/\1/p" -ne "s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($re\)[[:space:]]*$/\1/p" -ne "s|.*[[:space:]]\(link/\)\{0,1\}ether[[:space:]]\{1,\}\($re\)[[:space:]].*|\2|p" -ne "s|.*[[:space:]]\(link/\)\{0,1\}ether[[:space:]]\{1,\}\($re\)[[:space:]]*$|\2|p"));
  1360.    COMPREPLY+=($({ arp -an || ip neigh show; } 2> /dev/null | command sed -ne "s/.*[[:space:]]\($re\)[[:space:]].*/\1/p" -ne "s/.*[[:space:]]\($re\)[[:space:]]*$/\1/p"));
  1361.    COMPREPLY+=($(command sed -ne "s/^[[:space:]]*\($re\)[[:space:]].*/\1/p" /etc/ethers 2> /dev/null));
  1362.    COMPREPLY=($(compgen -W '${COMPREPLY[@]}' -- "$cur"));
  1363.    __ltrim_colon_completions "$cur"
  1364. }
  1365. _minimal ()
  1366. {
  1367.    local cur prev words cword split;
  1368.    _init_completion -s || return;
  1369.    $split && return;
  1370.    _filedir
  1371. }
  1372. _modules ()
  1373. {
  1374.    local modpath;
  1375.    modpath=/lib/modules/$1;
  1376.    COMPREPLY=($(compgen -W "$(command ls -RL $modpath 2> /dev/null | command sed -ne 's/^\(.*\)\.k\{0,1\}o\(\.[gx]z\)\{0,1\}$/\1/p')" -- "$cur"))
  1377. }
  1378. _ncpus ()
  1379. {
  1380.    local var=NPROCESSORS_ONLN;
  1381.    [[ $OSTYPE == *linux* ]] && var=_$var;
  1382.    local n=$(getconf $var 2> /dev/null);
  1383.    printf %s ${n:-1}
  1384. }
  1385. _parse_help ()
  1386. {
  1387.    eval local cmd="$(quote "$1")";
  1388.    local line;
  1389.    {
  1390.        case $cmd in
  1391.            -)
  1392.                cat
  1393.            ;;
  1394.            *)
  1395.                LC_ALL=C "$(dequote "$cmd")" ${2:---help} 2>&1
  1396.            ;;
  1397.        esac
  1398.    } | while read -r line; do
  1399.        [[ $line == *([[:blank:]])-* ]] || continue;
  1400.        while [[ $line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+([,_-]+[A-Z0-9]+)?(\.\.+)?\]? ]]; do
  1401.            line=${line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"};
  1402.        done;
  1403.        __parse_options "${line// or /, }";
  1404.    done
  1405. }
  1406. _parse_usage ()
  1407. {
  1408.    eval local cmd="$(quote "$1")";
  1409.    local line match option i char;
  1410.    {
  1411.        case $cmd in
  1412.            -)
  1413.                cat
  1414.            ;;
  1415.            *)
  1416.                LC_ALL=C "$(dequote "$cmd")" ${2:---usage} 2>&1
  1417.            ;;
  1418.        esac
  1419.    } | while read -r line; do
  1420.        while [[ $line =~ \[[[:space:]]*(-[^]]+)[[:space:]]*\] ]]; do
  1421.            match=${BASH_REMATCH[0]};
  1422.            option=${BASH_REMATCH[1]};
  1423.            case $option in
  1424.                -?(\[)+([a-zA-Z0-9?]))
  1425.                    for ((i = 1; i < ${#option}; i++))
  1426.                    do
  1427.                        char=${option:i:1};
  1428.                        [[ $char != '[' ]] && printf '%s\n' -$char;
  1429.                    done
  1430.                ;;
  1431.                *)
  1432.                    __parse_options "$option"
  1433.                ;;
  1434.            esac;
  1435.            line=${line#*"$match"};
  1436.        done;
  1437.    done
  1438. }
  1439. _pci_ids ()
  1440. {
  1441.    COMPREPLY+=($(compgen -W "$(PATH="$PATH:/sbin" lspci -n | awk '{print $3}')" -- "$cur"))
  1442. }
  1443. _pgids ()
  1444. {
  1445.    COMPREPLY=($(compgen -W '$(command ps axo pgid=)' -- "$cur"))
  1446. }
  1447. _pids ()
  1448. {
  1449.    COMPREPLY=($(compgen -W '$(command ps axo pid=)' -- "$cur"))
  1450. }
  1451. _pnames ()
  1452. {
  1453.    local -a procs;
  1454.    if [[ ${1-} == -s ]]; then
  1455.        procs=($(command ps axo comm | command sed -e 1d));
  1456.    else
  1457.        local line i=-1 ifs=$IFS;
  1458.        IFS='
  1459. ';
  1460.        local -a psout=($(command ps axo command=));
  1461.        IFS=$ifs;
  1462.        for line in "${psout[@]}";
  1463.        do
  1464.            if ((i == -1)); then
  1465.                if [[ $line =~ ^(.*[[:space:]])COMMAND([[:space:]]|$) ]]; then
  1466.                    i=${#BASH_REMATCH[1]};
  1467.                else
  1468.                    break;
  1469.                fi;
  1470.            else
  1471.                line=${line:i};
  1472.                line=${line%% *};
  1473.                procs+=($line);
  1474.            fi;
  1475.        done;
  1476.        if ((i == -1)); then
  1477.            for line in "${psout[@]}";
  1478.            do
  1479.                if [[ $line =~ ^[[(](.+)[])]$ ]]; then
  1480.                    procs+=(${BASH_REMATCH[1]});
  1481.                else
  1482.                    line=${line%% *};
  1483.                    line=${line##@(*/|-)};
  1484.                    procs+=($line);
  1485.                fi;
  1486.            done;
  1487.        fi;
  1488.    fi;
  1489.    COMPREPLY=($(compgen -X "<defunct>" -W '${procs[@]}' -- "$cur"))
  1490. }
  1491. _quote_readline_by_ref ()
  1492. {
  1493.    if [ -z "$1" ]; then
  1494.        printf -v $2 %s "$1";
  1495.    else
  1496.        if [[ $1 == \'* ]]; then
  1497.            printf -v $2 %s "${1:1}";
  1498.        else
  1499.            if [[ $1 == ~* ]]; then
  1500.                printf -v $2 ~%q "${1:1}";
  1501.            else
  1502.                printf -v $2 %q "$1";
  1503.            fi;
  1504.        fi;
  1505.    fi;
  1506.    [[ ${!2} == \$* ]] && eval $2=${!2}
  1507. }
  1508. _realcommand ()
  1509. {
  1510.    type -P "$1" > /dev/null && {
  1511.        if type -p realpath > /dev/null; then
  1512.            realpath "$(type -P "$1")";
  1513.        else
  1514.            if type -p greadlink > /dev/null; then
  1515.                greadlink -f "$(type -P "$1")";
  1516.            else
  1517.                if type -p readlink > /dev/null; then
  1518.                    readlink -f "$(type -P "$1")";
  1519.                else
  1520.                    type -P "$1";
  1521.                fi;
  1522.            fi;
  1523.        fi
  1524.    }
  1525. }
  1526. _rl_enabled ()
  1527. {
  1528.    [[ "$(bind -v)" == *$1+([[:space:]])on* ]]
  1529. }
  1530. _root_command ()
  1531. {
  1532.    local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin;
  1533.    local root_command=$1;
  1534.    _command
  1535. }
  1536. _service ()
  1537. {
  1538.    local cur prev words cword;
  1539.    _init_completion || return;
  1540.    ((cword > 2)) && return;
  1541.    if [[ $cword -eq 1 && $prev == ?(*/)service ]]; then
  1542.        _services;
  1543.        [[ -e /etc/mandrake-release ]] && _xinetd_services;
  1544.    else
  1545.        local sysvdirs;
  1546.        _sysvdirs;
  1547.        COMPREPLY=($(compgen -W '`command sed -e "y/|/ /" \
  1548.            -ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
  1549.            ${sysvdirs[0]}/${prev##*/} 2>/dev/null` start stop' -- "$cur"));
  1550.    fi
  1551. }
  1552. _services ()
  1553. {
  1554.    local sysvdirs;
  1555.    _sysvdirs;
  1556.     local IFS='    
  1557. ' reset=$(shopt -p nullglob);
  1558.    shopt -s nullglob;
  1559.    COMPREPLY=($(printf '%s\n' ${sysvdirs[0]}/!($_backup_glob|functions|README)));
  1560.    $reset;
  1561.    COMPREPLY+=($({ systemctl list-units --full --all || systemctl list-unit-files; } 2> /dev/null | awk '$1 ~ /\.service$/ { sub("\\.service$", "", $1); print $1 }'));
  1562.    if [[ -x /sbin/upstart-udev-bridge ]]; then
  1563.        COMPREPLY+=($(initctl list 2> /dev/null | cut -d' ' -f1));
  1564.    fi;
  1565.    COMPREPLY=($(compgen -W '${COMPREPLY[@]#${sysvdirs[0]}/}' -- "$cur"))
  1566. }
  1567. _shells ()
  1568. {
  1569.    local shell rest;
  1570.    while read -r shell rest; do
  1571.        [[ $shell == /* && $shell == "$cur"* ]] && COMPREPLY+=($shell);
  1572.    done 2> /dev/null < /etc/shells
  1573. }
  1574. _signals ()
  1575. {
  1576.    local -a sigs=($(compgen -P "${1-}" -A signal "SIG${cur#${1-}}"));
  1577.    COMPREPLY+=("${sigs[@]/#${1-}SIG/${1-}}")
  1578. }
  1579. _split_longopt ()
  1580. {
  1581.    if [[ $cur == --?*=* ]]; then
  1582.        prev="${cur%%?(\\)=*}";
  1583.        cur="${cur#*=}";
  1584.        return 0;
  1585.    fi;
  1586.    return 1
  1587. }
  1588. _sysvdirs ()
  1589. {
  1590.    sysvdirs=();
  1591.    [[ -d /etc/rc.d/init.d ]] && sysvdirs+=(/etc/rc.d/init.d);
  1592.    [[ -d /etc/init.d ]] && sysvdirs+=(/etc/init.d);
  1593.    [[ -f /etc/slackware-version ]] && sysvdirs=(/etc/rc.d);
  1594.    return 0
  1595. }
  1596. _terms ()
  1597. {
  1598.    COMPREPLY+=($(compgen -W "$({ command sed -ne 's/^\([^[:space:]#|]\{2,\}\)|.*/\1/p' /etc/termcap
  1599. { toe -a || toe; } | awk '{ print $1 }'
  1600. find /{etc,lib,usr/lib,usr/share}/terminfo/? -type f -maxdepth 1 | awk -F/ '{ print $NF }'; } 2> /dev/null)" -- "$cur"))
  1601. }
  1602. _tilde ()
  1603. {
  1604.    local result=0;
  1605.    if [[ ${1-} == \~* && $1 != */* ]]; then
  1606.        COMPREPLY=($(compgen -P '~' -u -- "${1#\~}"));
  1607.        result=${#COMPREPLY[@]};
  1608.        ((result > 0)) && compopt -o filenames 2> /dev/null;
  1609.    fi;
  1610.    return $result
  1611. }
  1612. _uids ()
  1613. {
  1614.    if type getent &> /dev/null; then
  1615.        COMPREPLY=($(compgen -W '$(getent passwd | cut -d: -f3)' -- "$cur"));
  1616.    else
  1617.        if type perl &> /dev/null; then
  1618.            COMPREPLY=($(compgen -W '$(perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"')' -- "$cur"));
  1619.        else
  1620.            COMPREPLY=($(compgen -W '$(cut -d: -f3 /etc/passwd)' -- "$cur"));
  1621.        fi;
  1622.    fi
  1623. }
  1624. _upvar ()
  1625. {
  1626.    echo "bash_completion: $FUNCNAME: deprecated function," "use _upvars instead" 1>&2;
  1627.    if unset -v "$1"; then
  1628.        if (($# == 2)); then
  1629.            eval $1=\"\$2\";
  1630.        else
  1631.            eval $1=\(\"\$"{@:2}"\"\);
  1632.        fi;
  1633.    fi
  1634. }
  1635. _upvars ()
  1636. {
  1637.    if ! (($#)); then
  1638.        echo "bash_completion: $FUNCNAME: usage: $FUNCNAME" "[-v varname value] | [-aN varname [value ...]] ..." 1>&2;
  1639.        return 2;
  1640.    fi;
  1641.    while (($#)); do
  1642.        case $1 in
  1643.            -a*)
  1644.                [[ -n ${1#-a} ]] || {
  1645.                    echo "bash_completion: $FUNCNAME:" "\`$1': missing number specifier" 1>&2;
  1646.                     return 1
  1647.                 };
  1648.                 printf %d "${1#-a}" &> /dev/null || {
  1649.                     echo bash_completion: "$FUNCNAME: \`$1': invalid number specifier" 1>&2;
  1650.                    return 1
  1651.                };
  1652.                [[ -n "$2" ]] && unset -v "$2" && eval $2=\(\"\$"{@:3:${1#-a}}"\"\) && shift $((${1#-a} + 2)) || {
  1653.                    echo bash_completion: "$FUNCNAME: \`$1${2+ }$2': missing argument(s)" 1>&2;
  1654.                     return 1
  1655.                 }
  1656.             ;;
  1657.             -v)
  1658.                 [[ -n "$2" ]] && unset -v "$2" && eval $2=\"\$3\" && shift 3 || {
  1659.                     echo "bash_completion: $FUNCNAME: $1:" "missing argument(s)" 1>&2;
  1660.                     return 1
  1661.                 }
  1662.             ;;
  1663.             *)
  1664.                 echo "bash_completion: $FUNCNAME: $1: invalid option" 1>&2;
  1665.                 return 1
  1666.             ;;
  1667.         esac;
  1668.     done
  1669. }
  1670. _usb_ids ()
  1671. {
  1672.     COMPREPLY+=($(compgen -W "$(PATH="$PATH:/sbin" lsusb | awk '{print $6}')" -- "$cur"))
  1673. }
  1674. _user_at_host ()
  1675. {
  1676.     local cur prev words cword;
  1677.     _init_completion -n : || return;
  1678.     if [[ $cur == *@* ]]; then
  1679.         _known_hosts_real "$cur";
  1680.     else
  1681.         COMPREPLY=($(compgen -u -S @ -- "$cur"));
  1682.         compopt -o nospace;
  1683.     fi
  1684. }
  1685. _usergroup ()
  1686. {
  1687.     if [[ $cur == *\\\\* || $cur == *:*:* ]]; then
  1688.         return;
  1689.     else
  1690.         if [[ $cur == *\\:* ]]; then
  1691.             local prefix;
  1692.             prefix=${cur%%*([^:])};
  1693.             prefix=${prefix//\\/};
  1694.             local mycur="${cur#*[:]}";
  1695.             if [[ ${1-} == -u ]]; then
  1696.                 _allowed_groups "$mycur";
  1697.             else
  1698.                 local IFS='
  1699. ';
  1700.                 COMPREPLY=($(compgen -g -- "$mycur"));
  1701.             fi;
  1702.             COMPREPLY=($(compgen -P "$prefix" -W "${COMPREPLY[@]}"));
  1703.         else
  1704.             if [[ $cur == *:* ]]; then
  1705.                 local mycur="${cur#*:}";
  1706.                 if [[ ${1-} == -u ]]; then
  1707.                     _allowed_groups "$mycur";
  1708.                 else
  1709.                     local IFS='
  1710. ';
  1711.                     COMPREPLY=($(compgen -g -- "$mycur"));
  1712.                 fi;
  1713.             else
  1714.                 if [[ ${1-} == -u ]]; then
  1715.                     _allowed_users "$cur";
  1716.                 else
  1717.                     local IFS='
  1718. ';
  1719.                     COMPREPLY=($(compgen -u -- "$cur"));
  1720.                 fi;
  1721.             fi;
  1722.         fi;
  1723.     fi
  1724. }
  1725. _userland ()
  1726. {
  1727.     local userland=$(uname -s);
  1728.     [[ $userland == @(Linux|GNU/*) ]] && userland=GNU;
  1729.     [[ $userland == "$1" ]]
  1730. }
  1731. _variable_assignments ()
  1732. {
  1733.     local cur=${1-};
  1734.     if [[ $cur =~ ^([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]]; then
  1735.         prev=${BASH_REMATCH[1]};
  1736.         cur=${BASH_REMATCH[2]};
  1737.     else
  1738.         return 1;
  1739.     fi;
  1740.     case $prev in
  1741.         TZ)
  1742.             cur=/usr/share/zoneinfo/$cur;
  1743.             _filedir;
  1744.             for i in "${!COMPREPLY[@]}";
  1745.             do
  1746.                 if [[ ${COMPREPLY[i]} == *.tab ]]; then
  1747.                     unset 'COMPREPLY[i]';
  1748.                     continue;
  1749.                 else
  1750.                     if [[ -d ${COMPREPLY[i]} ]]; then
  1751.                         COMPREPLY[i]+=/;
  1752.                         compopt -o nospace;
  1753.                     fi;
  1754.                 fi;
  1755.                 COMPREPLY[i]=${COMPREPLY[i]#/usr/share/zoneinfo/};
  1756.             done
  1757.         ;;
  1758.         TERM)
  1759.             _terms
  1760.         ;;
  1761.         LANG | LC_*)
  1762.             COMPREPLY=($(compgen -W '$(locale -a 2>/dev/null)' -- "$cur"))
  1763.         ;;
  1764.         *)
  1765.             _variables && return 0;
  1766.             _filedir
  1767.         ;;
  1768.     esac;
  1769.     return 0
  1770. }
  1771. _variables ()
  1772. {
  1773.     if [[ $cur =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]]; then
  1774.         if [[ $cur == '${'* ]]; then
  1775.             local arrs vars;
  1776.             vars=($(compgen -A variable -P ${BASH_REMATCH[1]} -S '}' -- ${BASH_REMATCH[3]}));
  1777.             arrs=($(compgen -A arrayvar -P ${BASH_REMATCH[1]} -S '[' -- ${BASH_REMATCH[3]}));
  1778.             if ((${#vars[@]} == 1 && ${#arrs[@]} != 0)); then
  1779.                 compopt -o nospace;
  1780.                 COMPREPLY+=(${arrs[*]});
  1781.             else
  1782.                 COMPREPLY+=(${vars[*]});
  1783.             fi;
  1784.         else
  1785.             COMPREPLY+=($(compgen -A variable -P '$' -- "${BASH_REMATCH[3]}"));
  1786.         fi;
  1787.         return 0;
  1788.     else
  1789.         if [[ $cur =~ ^(\$\{[#!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]; then
  1790.             local IFS='
  1791. ';
  1792.             COMPREPLY+=($(compgen -W '$(printf %s\\n "${!'${BASH_REMATCH[2]}'[@]}")' -P "${BASH_REMATCH[1]}${BASH_REMATCH[2]}[" -S ']}' -- "${BASH_REMATCH[3]}"));
  1793.             if [[ ${BASH_REMATCH[3]} == [@*] ]]; then
  1794.                 COMPREPLY+=("${BASH_REMATCH[1]}${BASH_REMATCH[2]}[${BASH_REMATCH[3]}]}");
  1795.             fi;
  1796.             __ltrim_colon_completions "$cur";
  1797.             return 0;
  1798.         else
  1799.             if [[ $cur =~ ^\$\{[#!]?[A-Za-z0-9_]*\[.*\]$ ]]; then
  1800.                 COMPREPLY+=("$cur}");
  1801.                 __ltrim_colon_completions "$cur";
  1802.                 return 0;
  1803.             fi;
  1804.         fi;
  1805.     fi;
  1806.     return 1
  1807. }
  1808. _xfunc ()
  1809. {
  1810.     set -- "$@";
  1811.     local srcfile=$1;
  1812.     shift;
  1813.     declare -F $1 &> /dev/null || __load_completion "$srcfile";
  1814.     "$@"
  1815. }
  1816. _xinetd_services ()
  1817. {
  1818.     local xinetddir=${BASHCOMP_XINETDDIR:-/etc/xinetd.d};
  1819.     if [[ -d $xinetddir ]]; then
  1820.         local IFS='    
  1821. ' reset=$(shopt -p nullglob);
  1822.         shopt -s nullglob;
  1823.         local -a svcs=($(printf '%s\n' $xinetddir/!($_backup_glob)));
  1824.         $reset;
  1825.         ((!${#svcs[@]})) || COMPREPLY+=($(compgen -W '${svcs[@]#$xinetddir/}' -- "${cur-}"));
  1826.     fi
  1827. }
  1828. command_not_found_handle ()
  1829. {
  1830.     if [ -x /usr/lib/command-not-found ]; then
  1831.         /usr/lib/command-not-found -- "$1";
  1832.         return $?;
  1833.     else
  1834.         if [ -x /usr/share/command-not-found/command-not-found ]; then
  1835.             /usr/share/command-not-found/command-not-found -- "$1";
  1836.             return $?;
  1837.         else
  1838.             printf "%s: command not found\n" "$1" 1>&2;
  1839.             return 127;
  1840.         fi;
  1841.     fi
  1842. }
  1843. dequote ()
  1844. {
  1845.     eval printf %s "$1" 2> /dev/null
  1846. }
  1847. quote ()
  1848. {
  1849.     local quoted=${1//\'/\'\\\'\'};
  1850.     printf "'%s'" "$quoted"
  1851. }
  1852. quote_readline ()
  1853. {
  1854.     local ret;
  1855.     _quote_readline_by_ref "$1" ret;
  1856.     printf %s "$ret"
  1857. }
  1858.  
  1859.  
Tags: Iligal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement