Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e47beef0ec
Fetching contributors…

Cannot retrieve contributors at this time

274 lines (235 sloc) 8.784 kb
#!/bin/bash
[[ -r /usr/share/bash-completion/completions/git ]] &&
. /usr/share/bash-completion/completions/git
# git-commit override
_git_commit() {
local cur ng_set
# do nothing if we're not in a repo
git rev-parse 2>/dev/null || return 0
_get_comp_words_by_ref cur prev
# complete uncommitted files
if [[ $prev = "commit" ]]; then
COMPREPLY=( $(compgen -W "$( git status --porcelain | cut -d' ' -f3-)" -- $cur ) )
fi
}
_git_archprojects()
{
local cur prev
_get_comp_words_by_ref -n =: cur prev
local projects="initscripts mkinitcpio netcfg pyalpm"
if [[ $prev = git-archprojects ]]; then
COMPREPLY=( $(compgen -W "$projects" -- $cur ) )
return
fi
case "$cur" in
--confirm=*)
__gitcomp "
$__git_send_email_confirm_options
" "" "${cur##--confirm=}"
return
;;
--suppress-cc=*)
__gitcomp "
$__git_send_email_suppresscc_options
" "" "${cur##--suppress-cc=}"
return
;;
--smtp-encryption=*)
__gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
return
;;
--*)
__gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
--compose --confirm= --dry-run --envelope-sender
--from --identity
--in-reply-to --no-chain-reply-to --no-signed-off-by-cc
--no-suppress-from --no-thread --quiet
--signed-off-by-cc --smtp-pass --smtp-server
--smtp-server-port --smtp-encryption= --smtp-user
--subject --suppress-cc= --suppress-from --thread --to
--validate --no-validate"
return
;;
esac
COMPREPLY=()
}
complete -F _git_archprojects git-archprojects
# aurcomm
_aurcomm() {
local cur
_get_comp_words_by_ref cur
(( ${#cur} < 2 )) && return
COMPREPLY=( $(compgen -W "$(cower -sq -- $cur)" -- $cur) )
}
complete -F _aurcomm aurcomm
_ghclone() {
local cur
_get_comp_words_by_ref cur
if [[ ${COMP_WORDS[1]} = -p ]]; then
# we can't complete private repos, so don't even try
return 0
fi
if ! type -P json_reformat >/dev/null; then
return 0
fi
COMPREPLY=( $(compgen -W "$(
curl --compressed -sf "http://github.com/api/v2/json/repos/show/${COMP_WORDS[1]}" |
json_reformat 2>/dev/null |
sed -n '/"name":/s|.*: "\([^"]\+\)",|\1|p')" -- $cur)
)
}
complete -F _ghclone ghclone
_known_hosts_real()
{
local configfile flag prefix
local cur curd awkcur user suffix aliases i host
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:"\
$(while [ $# -ge $OPTIND ]; do printf '%s\n' ${!OPTIND}; shift; done)
[[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
kh=()
# ssh config files
if [ -n "$configfile" ]; then
[ -r "$configfile" ] &&
config=( "${config[@]}" "$configfile" )
else
for i in /etc/ssh/ssh_config "${HOME}/.ssh/config" \
"${HOME}/.ssh2/config"; do
[ -r $i ] && config=( "${config[@]}" "$i" )
done
fi
# Known hosts files from configs
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=( $( 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 ) )
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" )
done
IFS=$OIFS
fi
if [ -z "$configfile" ]; then
# Global and user known_hosts files
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; do
[ -r $i ] && kh=( "${kh[@]}" $i )
done
for i in /etc/ssh2/knownhosts ~/.ssh2/hostkeys; do
[ -d $i ] && khd=( "${khd[@]}" $i/*pub )
done
fi
# If we have known_hosts files to use
if [[ ${#kh[@]} -gt 0 || ${#khd[@]} -gt 0 ]]; then
# Escape slashes and dots in paths for awk
awkcur=${cur//\//\\\/}
awkcur=${awkcur//\./\\\.}
curd=$awkcur
if [[ "$awkcur" == [0-9]*[.:]* ]]; then
# Digits followed by a dot or a colon - just search for that
awkcur="^$awkcur[.:]*"
elif [[ "$awkcur" == [0-9]* ]]; then
# Digits followed by no dot or colon - search for digits followed
# by a dot or a colon
awkcur="^$awkcur.*[.:]"
elif [ -z "$awkcur" ]; then
# A blank - search for a dot, a colon, 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=","}
/^\s*[^|\#]/ {for (i=1; i<=2; ++i) { \
sub(" .*$", "", $i); \
sub("^\\[", "", $i); sub("\\](:[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_$curd*.pub && -r "$i" ]]; then
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
# add completion from dnsmasq's lease file
local leasefile='/var/lib/misc/dnsmasq.leases'
if [[ -f $leasefile ]]; then
COMPREPLY+=( $(compgen -P "$prefix$user" \
-S "$suffix" \
-W "$(cut -d' ' -f3,4 "$leasefile")" -- $cur) )
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]\)\{0,1\}['"$'\t '"']\{1,\}\([^#*?]*\)\(#.*\)\{0,1\}$/\2/p' "${config[@]}" )
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -P "$prefix$user" \
-S "$suffix" -W "$hosts" -- "$cur" ) )
fi
# Add hosts reported by avahi-browse, if desired and it's available.
if [[ ${COMP_KNOWN_HOSTS_WITH_AVAHI:-} ]] && \
type avahi-browse &>/dev/null; then
# 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 wasn't available (even if mentioned in the manpage) some
# time ago, so...
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
# Add results of normal hostname completion, unless
# `COMP_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
if [ -n "${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}" ]; then
COMPREPLY=( "${COMPREPLY[@]}"
$( compgen -A hostname -P "$prefix$user" -S "$suffix" -- "$cur" ) )
fi
__ltrim_colon_completions "$prefix$user$cur"
return 0
}
_modules () {
local modpath
modpath=({/usr,}/lib/modules/$1)
COMPREPLY=($( compgen -W "$(command find "${modpath[@]}" -name '*.ko*' -printf '%f\n' 2>/dev/null |
sed -r 's/\.ko(\..z)?$//')" -- "$cur" ))
}
# pacman wrappers
complete -o filenames -F _pacman pp pm
# go
complete -f -X '!*.8' 8l
complete -f -X '!*.6' 6l
complete -f -X '!*.5' 5l
complete -f -X '!*.go' 8g 6g 5g gofmt gccgo
complete -F _known_hosts kssh
Jump to Line
Something went wrong with that request. Please try again.