Skip to content

Instantly share code, notes, and snippets.



Last active Jul 4, 2017
What would you like to do?
Bash Completion Scripts
# Written: Ashhar Hasan (hashhar_dev at outlook dot com) on 13 April 2017
# If cache file is older than a week or doesn't exist yet, update it.
local last_update=1
[ -e "${_cache_file}" ] && last_update=$(stat -c %Y "${_cache_file}")
# Compare the epoch times of existing file and current date.
if (( $(date +%s) > last_update + 604800 )); then
# Download without any output, timeout early and create destination.
curl --create-dirs --connect-timeout 5 -s -o "${_cache_file}"
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local opts='-V --version -h --help -c --check -v --vote -u --unvote --configure'
case "${prev}" in
# The tail +2 is there to exclude the comment at the start of file
local aur_pkgs=$(gzip -cd ${_cache_file} | tail +2 | sort )
COMPREPLY=( $(compgen -W "${aur_pkgs}" -- "${cur}") )
return 0
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
complete -F _aurvote aurvote
# vim: et sts=4 ts=4 sw=4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment