# bash completion for xgamma(1) -*- shell-script -*- proc _xgamma { local cur prev words cword _init_completion -n : || return match $prev { with -screen local screens=$[ xrandr --query !2 >/dev/null | sed -n \ '/^Screen /s|^Screen \{1,\}\(.*\):.*$|\1|p' !2 >/dev/null] setglobal COMPREPLY = ''( $( compgen -W "$screens" -- "$cur" ) ) return with -gamma|-rgamma|-ggamma|-bgamma # expect f.f if [[ $cur && "$cur" != *.* ]] { setglobal COMPREPLY = ''( . ) } setglobal COMPREPLY = ''( $( compgen -W "{0..9}" ) ) compopt -o nospace return with -display # expect hostname:displaynumber.screennumber if [[ "$cur" == :* && "$cur" != :*.* ]] { # FIXME: where to get local display numbers? local display=$(cur#:) setglobal COMPREPLY = ''( $( compgen -W "${display:-0}." ) ) compopt -o nospace } elif [[ "$cur" == :*.* ]] { # local screen numbers local t screens=$[ xrandr --query !2 >/dev/null | sed -ne \ '/^Screen /s|^Screen \{1,\}\(.*\):.*$|\1|p' !2 >/dev/null] setglobal t = $(cur#:) setglobal COMPREPLY = ''( $( compgen -P "${t%.*}." -W "$screens" -- \ "${cur##*.}" ) ) } elif [[ "$cur" != *:* ]] { # complete hostnames _known_hosts_real -c $cur if [[ ! $cur ]] { setglobal COMPREPLY = ''( : ) } compopt -o nospace } # no dislpay completion for remote hosts return } if [[ "$cur" == -* ]] { setglobal COMPREPLY = ''( $( compgen -W '$( _parse_help "$1" -help )' -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace [[ $COMPREPLY ]] && return } } && complete -F _xgamma xgamma # ex: ts=4 sw=4 et filetype=sh