Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.34 KB | None | 0 0
  1. $ cat /usr/share/bash-completion/ssh
  2. # ssh(1) completion
  3.  
  4. have ssh && {
  5.  
  6. _ssh_options() {
  7.         COMPREPLY=( $( compgen -W 'AddressFamily BatchMode BindAddress \
  8.                ChallengeResponseAuthentication CheckHostIP Cipher Ciphers \
  9.                ClearAllForwardings Compression CompressionLevel \
  10.                ConnectionAttempts ConnectTimeout ControlMaster ControlPath \
  11.                DynamicForward EscapeChar ExitOnForwardFailure ForwardAgent \
  12.                ForwardX11 ForwardX11Trusted GatewayPorts GlobalKnownHostsFile \
  13.                GSSAPIAuthentication GSSAPIDelegateCredentials HashKnownHosts \
  14.                Host HostbasedAuthentication HostKeyAlgorithms HostKeyAlias \
  15.                HostName IdentityFile IdentitiesOnly KbdInteractiveDevices \
  16.                LocalCommand LocalForward LogLevel MACs \
  17.                NoHostAuthenticationForLocalhost NumberOfPasswordPrompts \
  18.                PasswordAuthentication PermitLocalCommand Port \
  19.                PreferredAuthentications Protocol ProxyCommand \
  20.                PubkeyAuthentication RekeyLimit RemoteForward \
  21.                RhostsRSAAuthentication RSAAuthentication SendEnv \
  22.                ServerAliveInterval ServerAliveCountMax SmartcardDevice \
  23.                StrictHostKeyChecking TCPKeepAlive Tunnel TunnelDevice \
  24.                UsePrivilegedPort User UserKnownHostsFile VerifyHostKeyDNS \
  25.                VisualHostKey XAuthLocation' -- "$cur" ) )
  26. }
  27.  
  28. _ssh()
  29. {
  30.         local cur prev configfile
  31.         local -a config
  32.  
  33.         COMPREPLY=()
  34.         cur=`_get_cword`
  35.         prev=${COMP_WORDS[COMP_CWORD-1]}
  36.  
  37.         case "$prev" in
  38.                 -@(F|i|S))
  39.                         _filedir
  40.                         return 0
  41.                         ;;
  42.                 -c)
  43.                         COMPREPLY=( $( compgen -W '3des-cbc aes128-cbc \
  44.                                aes192-cbc aes256-cbc aes128-ctr aes192-ctr \
  45.                                aes256-ctr arcfour128 arcfour256 arcfour \
  46.                                blowfish-cbc cast128-cbc' -- "$cur" ) )
  47.                         return 0
  48.                         ;;
  49.                 -c)
  50.                         COMPREPLY=( $( compgen -W 'hmac-md5 hmac-sha1 \
  51.                                umac-64@openssh.com hmac-ripemd160 \
  52.                                hmac-sha1-96 hmac-md5-96' -- "$cur" ) )
  53.                         return 0
  54.                         ;;
  55.                 -l)
  56.                         COMPREPLY=( $( compgen -u -- "$cur" ) )
  57.                         return 0
  58.                         ;;
  59.                 -o)
  60.                         _ssh_options
  61.                         return 0
  62.                         ;;
  63.                 -w)
  64.                         _available_interfaces
  65.                         return 0
  66.                         ;;
  67.                 -b)
  68.                         COMPREPLY=( $( compgen -W "$(/sbin/ifconfig | \
  69.                                awk '/adr:/ {print $2}' | \
  70.                                awk -F: '{print $2}' )" -- "$cur" ) )
  71.                         return 0
  72.                         ;;
  73.         esac
  74.  
  75.         if [[ "$cur" == -F* ]]; then
  76.                 cur=${cur#-F}
  77.                 _filedir
  78.                 # Prefix completions with '-F'
  79.                 COMPREPLY=( "${COMPREPLY[@]/#/-F}" )
  80.                 cur=-F$cur  # Restore cur
  81.         elif [[ "$cur" == -* ]]; then
  82.                 COMPREPLY=( $( compgen -W '-1 -2 -4 -6 -A -a -C -f -g -K -k -M \
  83.                        -N -n -q -s -T -t -V -v -X -v -Y -y -b -b -c -D -e -F \
  84.                        -i -L -l -m -O -o -p -R -S -w' -- "$cur" ) )
  85.         else
  86.                 # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
  87.                 set -- "${COMP_WORDS[@]}"
  88.                 while [ $# -gt 0 ]; do
  89.                         if [ "${1:0:2}" = -F ]; then
  90.                                 if [ ${#1} -gt 2 ]; then
  91.                                         configfile="$(dequote "${1:2}")"
  92.                                 else
  93.                                         shift
  94.                                         [ "$1" ] && configfile="$(dequote "$1")"
  95.                                 fi
  96.                                 break
  97.                         fi
  98.                         shift
  99.                 done
  100.                 _known_hosts_real -a -F "$configfile" "$cur"
  101.                 if [ $COMP_CWORD -ne 1 ]; then
  102.                         COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- "$cur" ) )
  103.                 fi
  104.         fi
  105.  
  106.         return 0
  107. }
  108. shopt -u hostcomplete && complete -F _ssh ssh slogin autossh
  109.  
  110. # sftp(1) completion
  111. #
  112. _sftp()
  113. {
  114.         local cur prev configfile
  115.  
  116.         COMPREPLY=()
  117.         cur=`_get_cword`
  118.         prev=${COMP_WORDS[COMP_CWORD-1]}
  119.  
  120.         case "$prev" in
  121.                 -@(b|F|P))
  122.                         _filedir
  123.                         return 0
  124.                         ;;
  125.                 -o)
  126.                         _ssh_options
  127.                         return 0
  128.                         ;;
  129.         esac
  130.  
  131.         if [[ "$cur" == -F* ]]; then
  132.                 cur=${cur#-F}
  133.                 _filedir
  134.                 # Prefix completions with '-F'
  135.                 COMPREPLY=( "${COMPREPLY[@]/#/-F}" )
  136.                 cur=-F$cur  # Restore cur
  137.         elif [[ "$cur" == -* ]]; then
  138.                 COMPREPLY=( $( compgen -W '-1 -C -v -B -b -F -o -P -R -S -s' \
  139.                         -- "$cur" ) )
  140.         else
  141.                 # Search COMP_WORDS for '-F configfile' argument
  142.                 set -- "${COMP_WORDS[@]}"
  143.                 while [ $# -gt 0 ]; do
  144.                         if [ "${1:0:2}" = -F ]; then
  145.                                 if [ ${#1} -gt 2 ]; then
  146.                                         configfile="$(dequote "${1:2}")"
  147.                                 else
  148.                                         shift
  149.                                         [ "$1" ] && configfile="$(dequote "$1")"
  150.                                 fi
  151.                                 break
  152.                         fi
  153.                         shift
  154.                 done
  155.                 _known_hosts_real -a -F "$configfile" "$cur"
  156.         fi
  157.  
  158.         return 0
  159. }
  160. shopt -u hostcomplete && complete -F _sftp sftp
  161.  
  162.  
  163. # scp(1) completion
  164. #
  165. _scp()
  166. {
  167.         local configfile cur userhost path prefix
  168.  
  169.         COMPREPLY=()
  170.         cur=`_get_cword ":"`
  171.  
  172.         _expand || return 0
  173.  
  174.         if [[ "$cur" == *:* ]]; then
  175.                 local IFS=$'\t\n'
  176.                 # remove backslash escape from :
  177.                 cur=${cur/\\:/:}
  178.                 userhost=${cur%%?(\\):*}
  179.                 path=${cur#*:}
  180.                 # unescape spaces
  181.                 path=${path//\\\\\\\\ / }
  182.                 if [ -z "$path" ]; then
  183.                         # default to home dir of specified user on remote host
  184.                         path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
  185.                 fi
  186.                 # escape spaces; remove executables, aliases, pipes and sockets;
  187.                 # add space at end of file names
  188.                 COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
  189.             command ls -aF1d "$path*" 2>/dev/null | \
  190.             sed -e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\\\\\\\\\&/g" \
  191.            -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
  192.                return 0
  193.        fi
  194.  
  195.        if [[ "$cur" = -F* ]]; then
  196.                cur=${cur#-F}
  197.                prefix=-F
  198.        else
  199.                # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
  200.                set -- "${COMP_WORDS[@]}"
  201.                while [ $# -gt 0 ]; do
  202.                        if [ "${1:0:2}" = -F ]; then
  203.                                if [ ${#1} -gt 2 ]; then
  204.                                        configfile="$(dequote "${1:2}")"
  205.                                else
  206.                                        shift
  207.                                        [ "$1" ] && configfile="$(dequote "$1")"
  208.                                fi
  209.                                break
  210.                        fi
  211.                        shift
  212.                done
  213.  
  214.                [[ "$cur" == */* ]] || _known_hosts_real -c -a -F "$configfile" "$cur"
  215.        fi
  216.        # This approach is used instead of _filedir to get a space appended
  217.        # after local file/dir completions, and $nospace retained for others.
  218.        local IFS=$'\t\n'
  219.        COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* 2>/dev/null | sed \
  220.        -e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\&/g" \
  221.         -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' -e "s/^/$prefix/") )
  222.  
  223.         return 0
  224. }
  225. complete -F _scp $nospace scp sshfs
  226.  
  227. # ssh-copy-id(1) completion
  228. #
  229. _ssh_copy_id() {
  230.         local cur prev
  231.  
  232.         COMPREPLY=()
  233.         cur=`_get_cword`
  234.         prev=${COMP_WORDS[COMP_CWORD-1]}
  235.  
  236.         case "$prev" in
  237.                 -i)
  238.                         _filedir
  239.                         return 0
  240.                         ;;
  241.         esac
  242.  
  243.         if [[ "$cur" == -* ]]; then
  244.                 COMPREPLY=( $( compgen -W '-i' -- "$cur" ) )
  245.         else
  246.                 _known_hosts_real -a "$cur"
  247.         fi
  248.  
  249.         return 0
  250. }
  251. complete -F _ssh_copy_id $filenames ssh-copy-id
  252. }
  253.  
  254. # Local variables:
  255. # mode: shell-script
  256. # sh-basic-offset: 4
  257. # sh-indent-comment: t
  258. # indent-tabs-mode: nil
  259. # End:
  260. # ex: ts=4 sw=4 et filetype=sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement