diff --git a/examples/scripts/dwl-tags.sh b/examples/scripts/dwl-tags.sh new file mode 100755 index 0000000..44ade8f --- /dev/null +++ b/examples/scripts/dwl-tags.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash +# +# dwl-tags.sh - display dwl tags +# +# USAGE: dwl-tags.sh 1 +# +# REQUIREMENTS: +# - inotifywait ( 'inotify-tools' on arch ) +# - 2021/02/22 - dwl pull request: +# 'Interface to display tag information on status bar #91' +# https://github.com/djpohly/dwl/pull/91 +# +# TAGS: +# Name Type Return +# ------------------------------------- +# {dwltag} string dwl tags name/state +# +# Exemple configuration: +# - script: +# path: /absolute/path/to/dwl-tags.sh +# args: [1] +# content: {string: {text: "{dwltag}"}} + + +# Variables +declare titleline tagline title taginfo isactive ctags mtags layout +declare symbol_occupied_pre symbol_occupied_post symbol_focused_pre symbol_focused_post +declare -a tags name +readonly fname=/tmp/dwltags-"$WAYLAND_DISPLAY" + + +while true; do + + # Make sure the file exists + while [ ! -f "${fname}" ]; do + inotifywait -qqe create "$(dirname "${fname}")" + done; + + # Wait for dwl to close it after writing + inotifywait -qqe close_write "${fname}" + + # Get info from the file + titleline="$1" + tagline=$((titleline+1)) + title=$(sed "${titleline}!d" "${fname}") + taginfo=$(sed "${tagline}!d" "${fname}") + isactive=$(printf -- '%s\n' "${taginfo}" | cut -d ' ' -f 1) + ctags=$(printf -- '%s\n' "${taginfo}" | cut -d ' ' -f 2) + mtags=$(printf -- '%s\n' "${taginfo}" | cut -d ' ' -f 3) + layout=$(printf -- '%s\n' "${taginfo}" | cut -d ' ' -f 4-) + + tags=( "1" "2" "3" "4" "5" "6" "7" "8" "9" ) + + # Name of tag (optional) + # If there is no name, number are used + # + # Example: + # name=( "" "" "" "Media" ) + # -> return "" "" "" "Media" 5 6 7 8 9) + name=() + + # Symbol for occupied tags + # + # Format: "{symbol_occupied_pre}{TAGNAME}{symbol_occupied_post}" + # You can leave one empty if you don't want to surround the TAGNAME + symbol_occupied_pre="" + symbol_occupied_post="." + + # Symbol for the focused tag + # + # Format: "{symbol_focused_pre}{TAGNAME}{symbol_focused_post}" + # You can leave one empty if you don't want to surround the TAGNAME + symbol_focused_pre="[ " + symbol_focused_post=" ]" + + for i in {0..8}; do + mask=$((1<