bash: Remove tabs

This commit is contained in:
patrick96 2019-06-24 18:21:11 +02:00 committed by Patrick Ziegler
parent 52000c194a
commit 9f7363c9ee

View File

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