Skip to content

Instantly share code, notes, and snippets.

@lidgnulinux
Last active May 8, 2022 23:03
Show Gist options
  • Save lidgnulinux/88840b220cc5c3156ece2cf18080a69b to your computer and use it in GitHub Desktop.
Save lidgnulinux/88840b220cc5c3156ece2cf18080a69b to your computer and use it in GitHub Desktop.
Yambar-for-dwl
#!/usr/bin/env bash
# Variables
declare output title layout activetags selectedtags
declare -a tags name
readonly fname=/home/ahmad/.cache/dwltags
_cycle() {
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=()
for tag in "${!tags[@]}"; do
mask=$((1<<tag))
tag_name="tag"
declare "${tag_name}_${tag}"
name[tag]="${name[tag]:-${tags[tag]}}"
printf -- '%s\n' "${tag_name}_${tag}|string|${name[tag]}"
if (( "${selectedtags}" & mask )) 2>/dev/null; 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"
else
printf -- '%s\n' "${tag_name}_${tag}_occupied|bool|false"
fi
done
printf -- '%s\n' "layout|string|${layout}"
#printf -- '%s\n' "title|string|${title}"
printf -- '%s\n' ""
}
# Call the function here so the tags are displayed at dwl launch
_cycle
while true; do
[[ ! -f "${fname}" ]] && printf -- '%s\n' \
"You need to redirect dwl stdout to ~/.cache/dwltags" >&2
inotifywait -qq --event modify "${fname}"
# Get info from the file
# output="$(tail -n6 "${fname}")"
output="$(tail -n6 "${fname}")"
title="$(echo "${output}" | grep title | cut -d ' ' -f 3- )"
#selmon="$(echo "${output}" | grep 'selmon')"
layout="$(echo "${output}" | grep layout | cut -d ' ' -f 3- )"
# Get the tag bit mask as a decimal
activetags="$(echo "${output}" | grep tags | awk '{print $3}')"
selectedtags="$(echo "${output}" | grep tags | awk '{print $4}')"
_cycle
done
unset -v output title layout activetags selectedtags
unset -v tags name
# Typical laptop setup, with wifi, brightness, battery etc, for
# i3/Sway.
# For X11/i3, you'll want to replace calls to swaymsg with i3-msg, and
# the sway-xkb module with the xkb module.
# fonts we'll be re-using here and there
awesome: &awesome Font Awesome 5 Free:style=solid:pixelsize=10
#awesome_brands: &awesome_brands Font Awesome 5 Brands:pixelsize=16
std_underline: &std_underline {underline: { size: 2, color: ff0000ff}}
# This is THE bar configuration
bar:
height: 18
location: top
spacing: 5
margin: 3
# Default font
font: Ubuntu Mono derivative Powerline:style=Bold:pixelsize=12
#Adobe Helvetica
foreground: ffffffff
background: 004c66ff
border:
width: 2
color: 999999cc
margin: 3
top-margin: 3
left:
- label:
content:
string:
on-click: fuzzel -i Papirus -r 0 -b 2b303b80 -w 50 -t ccffffff --line-height=15
text: " Home"
font: *awesome
# - label:
# content:
# string:
# on-click: mlterm-wl
# text: ""
# font: *awesome
# - label:
# content:
# string:
# on-click: pcmanfm-qt
# text: "Folder"
# font: *awesome
- label:
content:
string:
on-click: /home/ahmad/bin/screen-screenshot
text: " Camera"
font: *awesome
- script:
path: /home/ahmad/bin/dwl-tags.sh
args: [1]
anchors:
- occupied: &occupied {foreground: 57bbf4ff}
- focused: &focused {foreground: fc65b0ff}
- default: &default {foreground: d2ccd6ff}
content:
- map:
margin: 4
tag: tag_0_occupied
values:
true:
map:
tag: tag_0_focused
values:
true: {string: {text: "{tag_0}", <<: *focused}}
false: {string: {text: "{tag_0}", <<: *occupied}}
false:
map:
tag: tag_0_focused
values:
true: {string: {text: "{tag_0}", <<: *focused}}
false: {string: {text: "{tag_0}", <<: *default}}
- map:
margin: 4
tag: tag_1_occupied
values:
true:
map:
tag: tag_1_focused
values:
true: {string: {text: "{tag_1}", <<: *focused}}
false: {string: {text: "{tag_1}", <<: *occupied}}
false:
map:
tag: tag_1_focused
values:
true: {string: {text: "{tag_1}", <<: *focused}}
false: {string: {text: "{tag_1}", <<: *default}}
- map:
margin: 4
tag: tag_2_occupied
values:
true:
map:
tag: tag_2_focused
values:
true: {string: {text: "{tag_2}", <<: *focused}}
false: {string: {text: "{tag_2}", <<: *occupied}}
false:
map:
tag: tag_2_focused
values:
true: {string: {text: "{tag_2}", <<: *focused}}
false: {string: {text: "{tag_2}", <<: *default}}
- map:
margin: 4
tag: tag_3_occupied
values:
true:
map:
tag: tag_3_focused
values:
true: {string: {text: "{tag_3}", <<: *focused}}
false: {string: {text: "{tag_3}", <<: *occupied}}
false:
map:
tag: tag_3_focused
values:
true: {string: {text: "{tag_3}", <<: *focused}}
false: {string: {text: "{tag_3}", <<: *default}}
- map:
margin: 4
tag: tag_4_occupied
values:
true:
map:
tag: tag_4_focused
values:
true: {string: {text: "{tag_4}", <<: *focused}}
false: {string: {text: "{tag_4}", <<: *occupied}}
false:
map:
tag: tag_4_focused
values:
true: {string: {text: "{tag_4}", <<: *focused}}
false: {string: {text: "{tag_4}", <<: *default}}
- map:
margin: 4
tag: tag_5_occupied
values:
true:
map:
tag: tag_5_focused
values:
true: {string: {text: "{tag_5}", <<: *focused}}
false: {string: {text: "{tag_5}", <<: *occupied}}
false:
map:
tag: tag_5_focused
values:
true: {string: {text: "{tag_5}", <<: *focused}}
false: {string: {text: "{tag_5}", <<: *default}}
- map:
margin: 4
tag: tag_6_occupied
values:
true:
map:
tag: tag_6_focused
values:
true: {string: {text: "{tag_6}", <<: *focused}}
false: {string: {text: "{tag_6}", <<: *occupied}}
false:
map:
tag: tag_6_focused
values:
true: {string: {text: "{tag_6}", <<: *focused}}
false: {string: {text: "{tag_6}", <<: *default}}
- map:
margin: 4
tag: tag_7_occupied
values:
true:
map:
tag: tag_7_focused
values:
true: {string: {text: "{tag_7}", <<: *focused}}
false: {string: {text: "{tag_7}", <<: *occupied}}
false:
map:
tag: tag_0_focused
values:
true: {string: {text: "{tag_7}", <<: *focused}}
false: {string: {text: "{tag_7}", <<: *default}}
- map:
margin: 4
tag: tag_8_occupied
values:
true:
map:
tag: tag_8_focused
values:
true: {string: {text: "{tag_8}", <<: *focused}}
false: {string: {text: "{tag_8}", <<: *occupied}}
false:
map:
tag: tag_8_focused
values:
true: {string: {text: "{tag_8}", <<: *focused}}
false: {string: {text: "{tag_8}", <<: *default}}
- list:
spacing: 3
items:
- string: {text: "{layout}"}
- string: {text: "{title}", max: 60}
- foreign-toplevel:
content:
map:
tag: activated
values:
false: {empty: {}}
true:
- string: {text: "{app-id}"}
right:
- removables:
anchors:
drive: &drive { text: , font: *awesome}
optical: &optical {text: , font: *awesome}
spacing: 5
content:
map:
tag: mounted
values:
false:
map:
tag: optical
on-click: udisksctl mount -b {device}
values:
false: [{string: *drive}, {string: {text: "{label}"}}]
true: [{string: *optical}, {string: {text: "{label}"}}]
true:
map:
tag: optical
on-click: udisksctl unmount -b {device}
values:
false:
- string: {<<: *drive, deco: *std_underline}
- string: {text: "{label}"}
true:
- string: {<<: *optical, deco: *std_underline}
- string: {text: "{label}"}
- sway-xkb:
identifiers: [1:1:AT_Translated_Set_2_keyboard]
content:
- string: {text: , font: *awesome}
- string: {text: "{layout}"}
- network:
name: enp1s0
content:
map:
tag: carrier
values:
false: {empty: {}}
true:
map:
tag: state
default: {string: {text: , font: *awesome, foreground: ffffff66}}
values:
up:
map:
tag: ipv4
default: {string: {text: , font: *awesome}}
values:
"": {string: {text: , font: *awesome, foreground: ffffff66}}
- network:
name: wlp3s0
content:
map:
tag: state
default: {string: {text: , font: *awesome, foreground: ffffff66}}
values:
down: {string: {text: , font: *awesome, foreground: ff0000ff}}
up:
map:
tag: ipv4
default: {string: {text: , font: *awesome}}
values:
"": {string: {text: , font: *awesome, foreground: ffffff66}}
- alsa:
card: hw:PCH
mixer: Master
content:
map:
on-click: pavucontrol
tag: muted
values:
true: {string: {text: , font: *awesome, foreground: ffffff66}}
false:
ramp:
tag: volume
items:
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- battery:
name: BAT0
poll-interval: 30
content:
map:
tag: state
values:
discharging:
- ramp:
tag: capacity
items:
- string: {text: , foreground: ff0000ff, font: *awesome}
- string: {text: , foreground: ffa600ff, font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , font: *awesome}
- string: {text: , foreground: 00ff00ff, font: *awesome}
- string: {text: "{capacity}% {estimate}"}
charging:
- string: {text: , foreground: 00ff00ff, font: *awesome}
- string: {text: "{capacity}% {estimate}"}
full:
- string: {text: , foreground: 00ff00ff, font: *awesome}
- string: {text: "{capacity}% full"}
- clock:
time-format: "%H:%M %Z"
content:
# - string: {text: , font: *awesome}
- string: {text: "{date}", right-margin: 5}
# - string: {text: , font: *awesome}
- string: {text: "{time}"}
- label:
content:
string:
on-click: wlogout -p layer-shell
text: " "
font: *awesome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment