2017-05-19 10:30:26 +00:00
|
|
|
_polybar_config_file() {
|
2019-06-24 16:21:11 +00:00
|
|
|
local config_path=${XDG_CONFIG_HOME:-$HOME/.config}/polybar/config
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
for ((i = 0; i < COMP_CWORD; i++)); do
|
|
|
|
case ${COMP_WORDS[i]} in
|
|
|
|
--config)
|
|
|
|
config_path=${COMP_WORDS[i + 2]}
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-c)
|
|
|
|
config_path=${COMP_WORDS[i + 1]}
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
# Use eval + cd for to get bash's parameter/tilde expansion etc
|
|
|
|
(eval cd $(dirname "$config_path"); echo $PWD/$(basename "$config_path"))
|
2017-05-19 10:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_polybar_bars() {
|
2019-06-24 16:21:11 +00:00
|
|
|
local config_file=$(_polybar_config_file)
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
if [ -r "$config_file" ]; then
|
|
|
|
grep -Po '\[bar/\K(.*)(?=\])' "$config_file"
|
|
|
|
fi
|
2017-05-19 10:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_polybar() {
|
2019-06-24 16:21:11 +00:00
|
|
|
local options='-h --help
|
|
|
|
-v --version
|
|
|
|
-l --log=
|
|
|
|
-q --quiet
|
2019-06-24 15:58:40 +00:00
|
|
|
-c --config=
|
2019-06-24 16:21:11 +00:00
|
|
|
-r --reload
|
|
|
|
-d --dump=
|
|
|
|
-m --list-monitors
|
|
|
|
-M --list-all-monitors
|
|
|
|
-w --print-wmname
|
|
|
|
-s --stdout
|
|
|
|
-p --png='
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
local log_levels='error
|
|
|
|
warning
|
2020-04-21 22:12:08 +00:00
|
|
|
notice
|
2019-06-24 16:21:11 +00:00
|
|
|
info
|
|
|
|
trace'
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
COMPREPLY=()
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
|
|
|
case "$cur" in
|
|
|
|
-*)
|
|
|
|
COMPREPLY=( $(compgen -W "$options" -- "$cur") )
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
local prev=${COMP_WORDS[COMP_CWORD - 1]}
|
|
|
|
if [ "$prev" = "=" ]; then
|
|
|
|
prev=${COMP_WORDS[COMP_CWORD - 2]}
|
|
|
|
fi
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
case "$prev" in
|
|
|
|
-l|--log)
|
|
|
|
COMPREPLY=( $(compgen -W "$log_levels" -- "$cur") )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-c|--config)
|
|
|
|
COMPREPLY=( $(compgen -f "$cur") )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
-p|--png)
|
|
|
|
COMPREPLY=( $(compgen -f -X "!*.png" "$cur") )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
# TODO: read properties of the selected bar from config
|
|
|
|
-d|--dump)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
COMPREPLY=( $(compgen -W "$options $(_polybar_bars)" -- "$cur") )
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
esac
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
for ((i = 0; i < ${#COMPREPLY[@]}; i++)); do
|
|
|
|
case ${COMPREPLY[i]} in
|
|
|
|
--*=) ;;
|
|
|
|
-*) COMPREPLY[i]+=" "
|
|
|
|
esac
|
|
|
|
done
|
2017-05-19 10:30:26 +00:00
|
|
|
|
2019-06-24 16:21:11 +00:00
|
|
|
return 0
|
2017-05-19 10:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
complete -o filenames -o noquote -o nospace -F _polybar polybar
|