From ac9e16112968fe68c1cd1af1ddfc992507d058f9 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Mon, 27 Mar 2023 13:21:42 +0200 Subject: [PATCH] [sway,bin] Better swaybar --- .config/sway/config | 2 +- org/config/bin.org | 56 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/.config/sway/config b/.config/sway/config index 3a114ab..2b8996f 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -283,8 +283,8 @@ bar { # When the status_command prints a new line to stdout, swaybar updates. # The default just shows the current date and time. - status_command while date +'%Y-%m-%d %H:%M:%S'; do sleep 1; done height 20 + status_command while swaybar-cmd; do sleep 1; done font FantasqueSansMono Nerd Font Mono 10 colors { diff --git a/org/config/bin.org b/org/config/bin.org index ae9c7f9..2ce4866 100644 --- a/org/config/bin.org +++ b/org/config/bin.org @@ -2194,10 +2194,10 @@ exec start-newm ** Sway :PROPERTIES: -:HEADER-ARGS: :shebang "#!/usr/bin/env sh" :mkdirp yes :tangle ~/.local/bin/launch-sway +:HEADER-ARGS: :shebang "#!/usr/bin/env sh" :mkdirp yes :tangle ~/.local/bin/swaybar-cmd :CUSTOM_ID: WaylandSway-a8lge8m0arj0 :END: -#+begin_src sh +#+begin_src sh :tangle ~/.local/bin/launch-sway export SDL_VIDEODRIVER=wayland # export XDG_SESSION_TYPE=wayland # export XDG_SESSION_DESKTOP=wlroots @@ -2209,6 +2209,58 @@ systemctl --user import-environment DISPLAY WAYLAND_DISPLAY XDG_CURRENT_DESKTOP exec sway --unsupported-gpu #+end_src +Below is the script I use to display information in sway’s bar. It is +divided by functions that are then called all together. First, getting +the date is quite straightforward. +#+begin_src sh +sb_date() { + echo "$(date +'%Y-%m-%d %H:%M:%S') | " +} +#+end_src + +Then we can get what piece of audio is playing. Note however that +something will be displayed only if something is playing. +#+begin_src sh +sb_playerctl() { + PLAYING="" + if [ "$(playerctl status)" = "Playing" ]; then + PLAYING_ARTIST="$(playerctl metadata xesam:artist)" + PLAYING_TITLE="$(playerctl metadata xesam:title)" + PLAYING=" $PLAYING_ARTIST - $PLAYING_TITLE | " + fi + echo "$PLAYING" +} +#+end_src + +The battery is relatively straightforward too. I should however find +how to get estimates of battery time. I’m sure I can come up with +something, but for now I’m just too lazy. +#+begin_src sh +sb_battery() { + CAPACITY="$(cat /sys/class/power_supply/BAT0/capacity)%" + STATE="$(cat /sys/class/power_supply/BAT0/status)" + echo "$CAPACITY ($STATE)" +} +#+end_src + +Now comes an indicator for Docker containers which will be displayed +only if at least one is running. +#+begin_src sh +sb_docker() { + DOCKER_RUNNING="$(docker ps -q | wc -l)" + # echo "Docker: $DOCKER_RUNNING" + if [ "$DOCKER_RUNNING" = "0" ] + then echo "" + else echo "Docker: $DOCKER_RUNNING | " + fi +} +#+end_src + +Finally, let’s display everything. +#+begin_src sh +echo "$(sb_docker)$(sb_playerctl)$(sb_date)$(sb_battery) " +#+end_src + * Weather :PROPERTIES: :HEADER-ARGS: :shebang "#!/usr/bin/env fish" :mkdirp yes :tangle ~/.local/bin/we