HarveyHunt / howm

A lightweight, X11 tiling window manager that behaves like vim
GNU General Public License v2.0
649 stars 24 forks source link

Commented bar.sh #62

Open Anachron opened 8 years ago

Anachron commented 8 years ago

Maybe this will help newcomers. If I made any mistake, feel free to comment!

#!/bin/bash

# Create a named pipe for howm config output
ff="/tmp/howm.fifo"

# Create a logfile for howm log output
logfile="/home/harvey/.config/howm/log.txt"

# Create the pipe, if not existing
[[ -p $ff ]] || mkfifo -m 666 "$ff"

# Create a few workspaces and store them into an array
ws=("term" "vim" "www" "chat" "media")

# Mapping for layouts and the numbers that come from howm
lay=("▣" "▦" "▥" "▤")

# Set background color mappings
mbg=("#333333" "#5F5F87" "#AFD7AF")
# Set foreground color mappings
mfg=("#DDDDDD" "#333333" "#333333")

# Set background color for bar (dzen)
bg="#333333"

# Read howm pipe as howmout variable
while read -t 10 -r howmout || true; do
    # Check the output for a format that we can use
    if [[ $howmout =~ ^(([[:digit:]]+:)+[[:digit:]]+ ?)+$ ]]; then
        unset r
        # Read all needed howm output to seperate variables (seperated by :)
        IFS=':' read -r m l w s c <<< "$howmout"
        # Set the foreground color using the mappings
        r+='^fg('"${mfg[$m]}"')'
        # Set the background color using the mappings
        r+='^bg('"${mbg[$m]}"')'
        # Display the layout symbol for the current workspace
        r+=" ${lay[$l]} | "
        # Display the workspace name of the current workspace
        r+="${ws[$w - 1]}"
        # Brace expansion 
        r="${r%::*}"
    fi
    # Display the collected bar string and additionally the date on the right side
    printf "%s%s\n" "$r" " | $(date +"%F %R") "
# Pass those things to dzen and display it with specific height, background color, font and more
done < "$ff" | dzen2 -h 20 -y -20 -ta r -bg "$bg" -fn "Inconsolata-dz:size=10" &

# pass output to fifo
/usr/bin/howm -c ~/.config/howm/howmrc 1> "$ff" 2> "$logfile"
HarveyHunt commented 8 years ago

Hey, thanks for commenting the script.

It'd be cool if you could send this as a PR aimed at the develop branch.

Note: As of 2115aa873f4c7d3ed785de73393dbbe0e461517f howm is no longer aware of modes - that functionality has been moved into sxhkd, so the script will need updating to reflect this.

Anachron commented 8 years ago

Hey @HarveyHunt,

sure thing, I can do that!

I just realized you already updated the example accordingly: https://github.com/HarveyHunt/howm/blob/develop/examples/bar.sh

So I will fix my version and do a PR later. Thanks!