[sxhkd] Add sxhkdrc parsing to mode script
Can now parse the usual sxhkdrc file in looking for mode chain combinations. Will prefer explicit configuration files if they exist. Read the -h to learn more.
This commit is contained in:
parent
1c789a9e72
commit
7be23bb4b8
3 changed files with 58 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
||||||
# for sxhkd-chain-labels script
|
# for sxhkd-chain-labels script
|
||||||
|
|
||||||
# media manipulation mode: playing, pausing, skipping,..
|
# media manipulation mode: playing, pausing, skipping,..
|
||||||
media:super + alt + m
|
media:alt + m
|
||||||
|
|
||||||
# academia mode: opening bibtex readings, annotating,..
|
# academia mode: opening bibtex readings, annotating,..
|
||||||
academia:super + alt + a
|
academia:alt + a
|
|
@ -44,7 +44,7 @@ super + q
|
||||||
|
|
||||||
## modes
|
## modes
|
||||||
|
|
||||||
# media control mode
|
# mode:media:alt + m
|
||||||
# seek +/- 5 seconds
|
# seek +/- 5 seconds
|
||||||
alt + m : {h,l}
|
alt + m : {h,l}
|
||||||
playerctl position {5-,5+}
|
playerctl position {5-,5+}
|
||||||
|
@ -61,7 +61,7 @@ alt + m : shift + {j,k}
|
||||||
alt + m : {_,shift} + p
|
alt + m : {_,shift} + p
|
||||||
playerctl {play-pause,stop}
|
playerctl {play-pause,stop}
|
||||||
|
|
||||||
# academia mode
|
# mode:academia:alt + a
|
||||||
# due papers this week
|
# due papers this week
|
||||||
alt + a : {F1,F2}
|
alt + a : {F1,F2}
|
||||||
rofi-bib-due -p{1,3} -u $(date --date='fri this week' +%Y-%m-%d)
|
rofi-bib-due -p{1,3} -u $(date --date='fri this week' +%Y-%m-%d)
|
||||||
|
|
|
@ -1,18 +1,29 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
# output is to stdout unless explicitly set through -o
|
# output is to stdout unless explicitly set through -o or env var
|
||||||
OUTPUTF=""
|
OUTPUTF="$SXHKD_OUTPUTF"
|
||||||
|
|
||||||
# set fifo input file, according (somewhat) to xdg
|
# set fifo input file, according (somewhat) to xdg
|
||||||
[ -n "$SXHKD_FIFO" ] && FIFO="$SXHKD_FIFO"
|
if [ -n "$SXHKD_FIFO" ]; then
|
||||||
[ ! -e "$FIFO" ] && FIFO="${XDG_RUNTIME_DIR}"/sxhkd_fifo
|
FIFO="$SXHKD_FIFO"
|
||||||
[ ! -e "$FIFO" ] && FIFO="${XDG_CACHE_HOME:-$HOME/.cache}"/sxhkd_fifo
|
elif [ -p "${XDG_RUNTIME_DIR}"/sxhkd_fifo ]; then
|
||||||
[ ! -e "$FIFO" ] && FIFO="$HOME/.sxhkd_fifo"
|
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
|
# set label config file, according (somewhat) to xdg
|
||||||
[ -n "$SXHKD_LABELCONFIG" ] && LABELCONFIG="$SXHKD_LABELCONFIG"
|
if [ -n "$SXHKD_LABELCONFIG" ]; then
|
||||||
[ ! -f "$LABELCONFIG" ] && LABELCONFIG="${XDG_CONFIG_HOME:-$HOME/.config}"/sxhkd/chain-labels.conf
|
LABELCONFIG="$SXHKD_LABELCONFIG"
|
||||||
[ ! -f "$LABELCONFIG" ] && LABELCONFIG="$HOME/.chain-labels.conf"
|
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() {
|
main() {
|
||||||
while read -r event; do
|
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 from file, remove comments (lines starting with #) and empty lines
|
||||||
read_config() {
|
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() {
|
get_help() {
|
||||||
|
@ -95,19 +121,29 @@ get_help() {
|
||||||
\$XDG_CONFIG_HOME/sxhkd/chain-labels.conf
|
\$XDG_CONFIG_HOME/sxhkd/chain-labels.conf
|
||||||
~/.config/sxhkd/chain-labels.conf
|
~/.config/sxhkd/chain-labels.conf
|
||||||
~/.chain-labels.conf
|
~/.chain-labels.conf
|
||||||
|
\$XDG_CONFIG_HOME/sxhkd/sxhkdrc (parsing)
|
||||||
|
|
||||||
The label configuration file uses the following format:
|
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
|
Lines beginning with a # will be ignored. Whitespace is important, sxhkd will, by
|
||||||
important, sxhkd will, by default, put a single space
|
default, put a single space between any component of the key combination.
|
||||||
between any component of the key combination.
|
|
||||||
|
|
||||||
An example file:
|
|
||||||
|
|
||||||
|
An example file chain-labels.conf:
|
||||||
media:super + alt + m
|
media:super + alt + m
|
||||||
system:super + backspace
|
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"
|
\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +186,8 @@ shift $((OPTIND - 1))
|
||||||
|
|
||||||
[ "${1:-}" = "--" ] && shift
|
[ "${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_config "$LABELCONFIG"
|
||||||
|
[ -z "$LABELS" ] && read_sxhkdrc "$SXHKDRC_FILE"
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
Loading…
Reference in a new issue