diff --git a/sxhkd/.config/sxhkd/chain-labels.conf b/sxhkd/.config/sxhkd/chain-labels.example.conf similarity index 75% rename from sxhkd/.config/sxhkd/chain-labels.conf rename to sxhkd/.config/sxhkd/chain-labels.example.conf index b081524..f2cef24 100644 --- a/sxhkd/.config/sxhkd/chain-labels.conf +++ b/sxhkd/.config/sxhkd/chain-labels.example.conf @@ -1,7 +1,7 @@ # for sxhkd-chain-labels script # media manipulation mode: playing, pausing, skipping,.. -media:super + alt + m +media:alt + m # academia mode: opening bibtex readings, annotating,.. -academia:super + alt + a +academia:alt + a diff --git a/sxhkd/.config/sxhkd/sxhkdrc b/sxhkd/.config/sxhkd/sxhkdrc index 0efa2b3..06eb67f 100644 --- a/sxhkd/.config/sxhkd/sxhkdrc +++ b/sxhkd/.config/sxhkd/sxhkdrc @@ -44,7 +44,7 @@ super + q ## modes -# media control mode +# mode:media:alt + m # seek +/- 5 seconds alt + m : {h,l} playerctl position {5-,5+} @@ -61,7 +61,7 @@ alt + m : shift + {j,k} alt + m : {_,shift} + p playerctl {play-pause,stop} -# academia mode +# mode:academia:alt + a # due papers this week alt + a : {F1,F2} rofi-bib-due -p{1,3} -u $(date --date='fri this week' +%Y-%m-%d) diff --git a/sxhkd/.local/bin/sxhkd-chain-labels b/sxhkd/.local/bin/sxhkd-chain-labels index 9de6208..287cd80 100755 --- a/sxhkd/.local/bin/sxhkd-chain-labels +++ b/sxhkd/.local/bin/sxhkd-chain-labels @@ -1,18 +1,29 @@ #!/usr/bin/env sh -# output is to stdout unless explicitly set through -o -OUTPUTF="" +# output is to stdout unless explicitly set through -o or env var +OUTPUTF="$SXHKD_OUTPUTF" # set fifo input file, according (somewhat) to xdg -[ -n "$SXHKD_FIFO" ] && FIFO="$SXHKD_FIFO" -[ ! -e "$FIFO" ] && FIFO="${XDG_RUNTIME_DIR}"/sxhkd_fifo -[ ! -e "$FIFO" ] && FIFO="${XDG_CACHE_HOME:-$HOME/.cache}"/sxhkd_fifo -[ ! -e "$FIFO" ] && FIFO="$HOME/.sxhkd_fifo" +if [ -n "$SXHKD_FIFO" ]; then + FIFO="$SXHKD_FIFO" +elif [ -p "${XDG_RUNTIME_DIR}"/sxhkd_fifo ]; then + FIFO="${XDG_RUNTIME_DIR}"/sxhkd_fifo +elif [ -p "${XDG_CACHE_HOME:-$HOME/.cache}"/sxhkd_fifo ]; then + FIFO="${XDG_CACHE_HOME:-$HOME/.cache}"/sxhkd_fifo +elif [ -p "$HOME/.sxhkd_fifo" ]; then + FIFO="$HOME/.sxhkd_fifo" +fi # set label config file, according (somewhat) to xdg -[ -n "$SXHKD_LABELCONFIG" ] && LABELCONFIG="$SXHKD_LABELCONFIG" -[ ! -f "$LABELCONFIG" ] && LABELCONFIG="${XDG_CONFIG_HOME:-$HOME/.config}"/sxhkd/chain-labels.conf -[ ! -f "$LABELCONFIG" ] && LABELCONFIG="$HOME/.chain-labels.conf" +if [ -n "$SXHKD_LABELCONFIG" ]; then + LABELCONFIG="$SXHKD_LABELCONFIG" +elif [ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/sxhkd/chain-labels.conf ]; then + LABELCONFIG="${XDG_CONFIG_HOME:-$HOME/.config}"/sxhkd/chain-labels.conf +elif [ -f "$HOME/.chain-labels.conf" ]; then + LABELCONFIG="$HOME/.chain-labels.conf" +fi + +SXHKDRC_FILE="$XDG_CONFIG_HOME"/sxhkd/sxhkdrc main() { while read -r event; do @@ -62,7 +73,22 @@ ev_chainend() { # read config from file, remove comments (lines starting with #) and empty lines read_config() { - [ -f "$1" ] && LABELS="$(sed -e '/^#/d;/^[[:blank:]]*$/d' <"$1")" || LABELS="" + [ ! -f "$1" ] && return 1 + + parse_labels "$(cat "$1")" +} + +# parse sxhkdrc for mode compatible comments +read_sxhkdrc() { + [ ! -f "$1" ] && return 1 + + _sxhkdrc_content="$(sed -e '/^# mode:/!d;s/^# mode://' <"$1")" + parse_labels "$_sxhkdrc_content" +} + +# append +parse_labels() { + LABELS="${LABELS}$(echo "$1" | sed -e '/^#/d;/^[[:blank:]]*$/d')" } get_help() { @@ -95,19 +121,29 @@ get_help() { \$XDG_CONFIG_HOME/sxhkd/chain-labels.conf ~/.config/sxhkd/chain-labels.conf ~/.chain-labels.conf + \$XDG_CONFIG_HOME/sxhkd/sxhkdrc (parsing) The label configuration file uses the following format: - mode-name:chain activation combination + mode name:key chain - Lines beginning with a # will be ignored. Whitespace is - important, sxhkd will, by default, put a single space - between any component of the key combination. - - An example file: + Lines beginning with a # will be ignored. Whitespace is important, sxhkd will, by + default, put a single space between any component of the key combination. + An example file chain-labels.conf: media:super + alt + m system:super + backspace + Instead of using an explicit configuration file, you can put the chain mode + information into the regular sxhkdrc as comments. They need to follow this exact format: + # mode:mode name:key chain + + They can occur anywhere in the file. The space before mode is necessary, and # needs to + be the first character on the line. The above example file as written into the sxhkdrc: + # mode:media:super + alt + m + # mode:system:super + backspace + + If an explicit configuration file exists, it will supersede any mode information in the + sxhkdrc file. \n" } @@ -150,7 +186,8 @@ shift $((OPTIND - 1)) [ "${1:-}" = "--" ] && shift -# look for default label config +# look for default label config, prefer config file to parsing sxhkdrc [ -z "$LABELS" ] && read_config "$LABELCONFIG" +[ -z "$LABELS" ] && read_sxhkdrc "$SXHKDRC_FILE" main "$@"