Skip to content

Instantly share code, notes, and snippets.

@wdkrnls
Created March 31, 2018 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdkrnls/4d914da9134dd13bd6f7519a7760e2f1 to your computer and use it in GitHub Desktop.
Save wdkrnls/4d914da9134dd13bd6f7519a7760e2f1 to your computer and use it in GitHub Desktop.
dynamically rename tags in hlwm using 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)')
ren=$(print_array tag | dmenu -i -p "rename tag:")
Mod=Mod4
idx=$(index_of "$ren" tag)
len=${#tag[@]}
keys=({1..9} 0)
if [[ ! -z $idx ]]
then
new=$(echo "$ren" | dmenu -i -p "new tag name:")
nidx=$(index_of "$new" tag)
if [[ -z $nidx ]]
then
hc rename $ren $new
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment