# bash completion for xrandr -*- shell-script -*- proc _xrandr { var cur = '', prev = '', words = '', cword = '' _init_completion || return match $prev { with -display|-d|-help|-s|--size|-r|--rate|--refresh|--screen|--fb|--fbmm|\ --dpi|--pos|--set|--scale|--transform|--crtc|--panning|--gamma|\ --newmode|--rmmode|--addmode|--delmode return with --output|--left-of|--right-of|--above|--below|--same-as var outputs = $[ $1 | awk '/connected/ {print $1}] setglobal COMPREPLY = '( '$( compgen -W "$outputs" -- "$cur" ) ) return with --mode var i = '', output = '' for (( i=1; i < cword; i++ )); do if [[ "${words[i]}" == --output ]]; then output=${words[i+1]} break fi done if [[ $output ]] { var modes = $[ $1 | sed -e "1,/$output/ d" \ -e "/connected/,$ d" \ -e "s/\([^[:space:]]\)[[:space:]].*/\1/] setglobal COMPREPLY = '( '$( compgen -W "$modes" -- "$cur" ) ) } return with -o|--orientation setglobal COMPREPLY = '( '$( compgen -W 'normal inverted left right 0 1 2 3' -- \ "$cur" ) ) return with --reflect setglobal COMPREPLY = '( '$( compgen -W 'normal x y xy' -- "$cur" ) ) return with --rotate setglobal COMPREPLY = '( '$( compgen -W 'normal inverted left right' -- "$cur" ) ) return with --setprovideroutputsource|--setprovideroffloadsink var providers = $[ $1 --listproviders !2 >/dev/null | sed -ne 's/.* name:\([^ ]*\).*/\1/p] setglobal COMPREPLY = '( '$( compgen -W "$providers" -- "$cur" ) ) # TODO 2nd arg needed, is that a provider as well? return } setglobal COMPREPLY = '( '$( compgen -W '$( "$1" -help 2>&1 | sed -e "s/ or / /g" -e "s/<[^>]*>]//g" | _parse_help - )' -- "$cur" ) ) } && complete -F _xrandr xrandr # ex: ts=4 sw=4 et filetype=sh