Skip to content

Instantly share code, notes, and snippets.

@wdkrnls
Last active March 31, 2018 04:45
Show Gist options
  • Save wdkrnls/33e356b5da02634d24b1f0f6698ff08c to your computer and use it in GitHub Desktop.
Save wdkrnls/33e356b5da02634d24b1f0f6698ff08c to your computer and use it in GitHub Desktop.
dynamically delete hlwm tags with dmenu
#!/bin/bash
### License: GPL3+
#
# Author: Kyle Andrews
#
# This script enables dynamic creation of new tags in hlwm.
#
###
hc() {
herbstclient "$@"
}
# return the first integer index of the value in the array
index_of() {
local x="$1"
local -n xs="${2}"
for i in "${!xs[@]}"; do
if [[ "${xs[$i]}" = "${x}" ]]; then
echo "${i}";
break
fi
done
}
print_array() {
local -n xs="${1}"
printf '%s\n' "${xs[@]}"
}
eval $(hc tag_status | txr -B -c ' @(coll)@{status /[#:.]/}@{tag /[^\t]+/}@(end)')
fidx=$(index_of '#' status)
focused=${tag[$fidx]}
del=$(print_array tag | dmenu -i -p "delete tag:")
Mod=Mod4
idx=$(index_of "$del" tag)
len=${#tag[@]}
keys=({1..9} 0)
if [[ ! -z $idx ]];
then
if [[ $len -gt 1 ]];
then
ntag=("${tag[@]}");
nlen=${#ntag[@]}
unset ntag[$idx]
hc merge_tag "${tag[$idx]}" "${ntag[0]}"
# unset existing keybindings
for i in ${!tag[@]} ; do
key="${keys[$i]}"
hc keyunbind "$Mod-$key"
hc keyunbind "$Mod-Shift-$key"
done
# update keybindings to reflect new tags
for i in ${!ntag[@]} ; do
key="${keys[$i]}"
hc keybind "$Mod-$key" use_index "$i"
hc keybind "$Mod-Shift-$key" use_index "$i"
done
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment