exemples/script: Update dwl-tags

Update dwl-tags to works with dwl main branch
now that the pull request was merged
This commit is contained in:
novakne 2021-03-28 12:50:45 +02:00
parent 4efb7df7db
commit 21a84aed72
No known key found for this signature in database
GPG key ID: 73BBC60F9FE1EE3E

View file

@ -6,9 +6,7 @@
# #
# REQUIREMENTS: # REQUIREMENTS:
# - inotifywait ( 'inotify-tools' on arch ) # - inotifywait ( 'inotify-tools' on arch )
# - 2021/02/25 - dwl pull request: # - Launch dwl with `dwl > ~.cache/dwltags` or change $fname
# 'Interface to display tag information on status bar #91'
# https://github.com/djpohly/dwl/pull/91
# #
# TAGS: # TAGS:
# Name Type Return # Name Type Return
@ -74,9 +72,9 @@
# Variables # Variables
declare titleline tagline title taginfo isactive ctags mtags layout declare output title layout activetags selectedtags
declare -a tags name declare -a tags name
readonly fname=/tmp/dwltags-"$WAYLAND_DISPLAY" readonly fname="$HOME"/.cache/dwltags
_cycle() { _cycle() {
@ -99,21 +97,18 @@ _cycle() {
printf -- '%s\n' "${tag_name}_${tag}|string|${name[tag]}" printf -- '%s\n' "${tag_name}_${tag}|string|${name[tag]}"
# Occupied if (( "${selectedtags}" & mask )) 2>/dev/null; then
if (( "${ctags}" & mask )); then printf -- '%s\n' "${tag_name}_${tag}_focused|bool|true"
printf -- '%s\n' "title|string|${title}"
else
printf '%s\n' "${tag_name}_${tag}_focused|bool|false"
fi
if (( "${activetags}" & mask )) 2>/dev/null; then
printf -- '%s\n' "${tag_name}_${tag}_occupied|bool|true" printf -- '%s\n' "${tag_name}_${tag}_occupied|bool|true"
else else
printf -- '%s\n' "${tag_name}_${tag}_occupied|bool|false" printf -- '%s\n' "${tag_name}_${tag}_occupied|bool|false"
fi fi
# Focused
if (( "${mtags}" & mask )); then
printf -- '%s\n' "${tag_name}_${tag}_focused|bool|true"
printf -- '%s\n' "title|string|${title}"
else
printf -- '%s\n' "${tag_name}_${tag}_focused|bool|false"
fi
done done
printf -- '%s\n' "layout|string|${layout}" printf -- '%s\n' "layout|string|${layout}"
@ -126,28 +121,25 @@ _cycle
while true; do while true; do
# Make sure the file exists [[ ! -f "${fname}" ]] && printf -- '%s\n' \
while [ ! -f "${fname}" ]; do "You need to redirect dwl stdout to ~/.cache/dwltags" >&2
inotifywait -qqe create "$(dirname "${fname}")"
done;
# Wait for dwl to close it after writing inotifywait -qq --event modify "${fname}"
inotifywait -qqe close_write "${fname}"
# Get info from the file # Get info from the file
titleline="$1" output="$(tail -n4 "${fname}")"
tagline=$((titleline+1)) title="$(echo "${output}" | grep title | cut -d ' ' -f 3- )"
title=$(sed "${titleline}!d" "${fname}") #selmon="$(echo "${output}" | grep 'selmon')"
taginfo=$(sed "${tagline}!d" "${fname}") layout="$(echo "${output}" | grep layout | cut -d ' ' -f 3- )"
isactive=$(printf -- '%s\n' "${taginfo}" | cut -d ' ' -f 1)
ctags=$(printf -- '%s\n' "${taginfo}" | cut -d ' ' -f 2) # Get the tag bit mask as a decimal
mtags=$(printf -- '%s\n' "${taginfo}" | cut -d ' ' -f 3) activetags="$(echo "${output}" | grep tags | awk '{print $3}')"
layout=$(printf -- '%s\n' "${taginfo}" | cut -d ' ' -f 4-) selectedtags="$(echo "${output}" | grep tags | awk '{print $4}')"
_cycle _cycle
done done
unset -v titleline tagline title taginfo isactive ctags mtags layout unset -v output title layout activetags selectedtags
unset -v tags name unset -v tags name