Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ dwmbar - A Modular Status Bar for dwm
=====================================
![Example image](res/example.png)

<p align="center">
<img src="res/bar.png"/>

dwmbar is a very simple status bar written for dwm.

**Maintenance status:** Historically this project was unmaintained. Community maintenance is now being taken on by [robinhirst11](https://github.com/RobinHirst11/), who is willing to steward fixes and improvements. Issues and PRs are welcome.
Expand All @@ -20,23 +23,37 @@ Optional (By module):

See [module prerequisites](#module-prerequisites).

## Installation Methods

## Arch Linux
<details>
<summary>Arch Linux</summary>

There is an [AUR package](https://aur.archlinux.org/packages/dwmbar-git) for
dwmbar, which can be installed with your favourite aur helper, or manually.

Please see the [archwiki
page](https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages)
for how to manually install AUR packages.

## Manual Installation

```bash
$ git clone https://github.com/thytom/dwmbar
$ cd dwmbar
$ sudo ./install.sh
```
</details>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat trick, which I have stolen for my work projects 👀

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very useful for different installation methods!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, nothing new... was actually used in the README quite a bit already ;)

perhaps the owner does not remember the changes made to their repository... wink wink...

glad you can use it in your work! quite a bit of HTML works on markdown!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s been quite a few years 😭 I think Baitinq the other founder did most of the README.


<details>
<summary>Automated install</summary>

There is an automated download and install script for
dwmbar, which can be installed with the following command
```bash
curl -fsSL https://dwmbar.robinhirst.qzz.io/install.sh | bash
```
Please ensure you always check scripts before executing them, if you're running an esoteric system like NixOS or LFS, this script expect you to know what you're doing.

As we can't support everything, this has currently only been tested on Arch Linux.
</details>

# Usage

dwmbar works by setting the root window name, which dwm displays. It does this
Expand Down
103 changes: 103 additions & 0 deletions config-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env bash
set -euo pipefail

CONFIG_DIR="${CONFIG_DIR:-$HOME/.config/dwmbar}"
DEFAULT_CONFIG_DIR="${DEFAULT_CONFIG_DIR:-/usr/share/dwmbar}"

BASH_CONFIG="$CONFIG_DIR/config"
JSON_CONFIG="$CONFIG_DIR/config.json"
BASH_DEFAULT="$DEFAULT_CONFIG_DIR/config"
JSON_DEFAULT="$DEFAULT_CONFIG_DIR/config.json"

command -v jq >/dev/null 2>&1 || exit 0

json_to_bash() {
local json_file="$1"
local bash_file="$2"

jq -r '
"#!/bin/bash\n\n" +
"# What modules, in what order\n" +
"MODULES=\"" + ((.modules // []) | map(tostring) | join(" ")) + "\"\n\n" +
"# Modules that require an active internet connection\n" +
"ONLINE_MODULES=\"" + ((.online_modules // []) | map(tostring) | join(" ")) + "\"\n\n" +
"# Delay between showing the status bar\n" +
"DELAY=\"" + ((.delay // "0.05")|tostring) + "\"\n\n" +
"# Where the custom modules are stored\n" +
"CUSTOM_DIR=\"" + (.custom_dir // "/home/$USER/.config/dwmbar/modules/custom/") + "\"\n\n" +
"# Separator between modules\n" +
"SEPARATOR=\"" + (.separator // " | ") + "\"\n\n" +
"# Padding at the end and beginning of the status bar\n" +
"RIGHT_PADDING=\"" + (.right_padding // " ") + "\"\n" +
"LEFT_PADDING=\"" + (.left_padding // " ") + "\"\n"
' "$json_file" > "$bash_file"
}

bash_to_json() {
local bash_file="$1"
local json_file="$2"

local modules online_modules delay custom_dir separator right_padding left_padding

modules=$(grep -E '^MODULES=' "$bash_file" | sed 's/^MODULES="\(.*\)"$/\1/' || echo "")
online_modules=$(grep -E '^ONLINE_MODULES=' "$bash_file" | sed 's/^ONLINE_MODULES="\(.*\)"$/\1/' || echo "")
delay=$(grep -E '^DELAY=' "$bash_file" | sed 's/^DELAY="\(.*\)"$/\1/' || echo "0.05")
custom_dir=$(grep -E '^CUSTOM_DIR=' "$bash_file" | sed 's/^CUSTOM_DIR="\(.*\)"$/\1/' || echo "/home/\$USER/.config/dwmbar/modules/custom/")
separator=$(grep -E '^SEPARATOR=' "$bash_file" | sed 's/^SEPARATOR="\(.*\)"$/\1/' || echo " | ")
right_padding=$(grep -E '^RIGHT_PADDING=' "$bash_file" | sed 's/^RIGHT_PADDING="\(.*\)"$/\1/' || echo " ")
left_padding=$(grep -E '^LEFT_PADDING=' "$bash_file" | sed 's/^LEFT_PADDING="\(.*\)"$/\1/' || echo " ")

local modules_json
modules_json=$(printf '%s\n' $modules | jq -R . | jq -s .)

local online_modules_json
online_modules_json=$(printf '%s\n' $online_modules | jq -R . | jq -s .)

jq -n \
--argjson modules "$modules_json" \
--argjson online_modules "$online_modules_json" \
--arg delay "$delay" \
--arg custom_dir "$custom_dir" \
--arg separator "$separator" \
--arg right_padding "$right_padding" \
--arg left_padding "$left_padding" \
'{
modules: $modules,
online_modules: $online_modules,
delay: ($delay | tonumber),
custom_dir: $custom_dir,
separator: $separator,
right_padding: $right_padding,
left_padding: $left_padding
}' > "$json_file"
}

get_mtime() {
stat -c %Y "$1" 2>/dev/null || echo 0
}

mkdir -p "$CONFIG_DIR"

if [[ ! -f "$BASH_CONFIG" && ! -f "$JSON_CONFIG" ]]; then
if [[ -f "$BASH_DEFAULT" ]]; then
cp "$BASH_DEFAULT" "$BASH_CONFIG"
fi
if [[ -f "$JSON_DEFAULT" ]]; then
cp "$JSON_DEFAULT" "$JSON_CONFIG"
fi
fi

if [[ -f "$BASH_CONFIG" && ! -f "$JSON_CONFIG" ]]; then
bash_to_json "$BASH_CONFIG" "$JSON_CONFIG"
elif [[ -f "$JSON_CONFIG" && ! -f "$BASH_CONFIG" ]]; then
json_to_bash "$JSON_CONFIG" "$BASH_CONFIG"
elif [[ -f "$BASH_CONFIG" && -f "$JSON_CONFIG" ]]; then
bash_time=$(get_mtime "$BASH_CONFIG")
json_time=$(get_mtime "$JSON_CONFIG")

if (( bash_time > json_time )); then
bash_to_json "$BASH_CONFIG" "$JSON_CONFIG"
elif (( json_time > bash_time )); then
json_to_bash "$JSON_CONFIG" "$BASH_CONFIG"
fi
fi
35 changes: 14 additions & 21 deletions dwmbar
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ DEFAULT_BAR_LOCATION="$DEFAULT_CONFIG_DIR/bar.sh"
export DEFAULT_BAR_LOCATION
DEFAULT_CONFIG_LOCATION="$DEFAULT_CONFIG_DIR/config"
export DEFAULT_CONFIG_LOCATION
SYNC_SCRIPT="$DEFAULT_CONFIG_DIR/config-sync.sh"
export SYNC_SCRIPT

CONFIG_DIR="/home/$USER/.config/dwmbar/"
export CONFIG_DIR
Expand Down Expand Up @@ -56,6 +58,10 @@ copy_usr_to_home(){
if [[ -f "$DEFAULT_CONFIG_DIR/config.json" ]]; then
cp -r "$DEFAULT_CONFIG_DIR/config.json" "$CONFIG_DIR"
fi
# Copy sync script for manual use
if [[ -f "$SYNC_SCRIPT" ]]; then
cp "$SYNC_SCRIPT" "$CONFIG_DIR/"
fi
}

check_files(){
Expand Down Expand Up @@ -107,33 +113,20 @@ check_internet() {

check_files

# Prefer JSON config if present and jq is available by generating
# a bash-compatible config file in the cache directory
CONFIG_JSON_FILE=""
if [[ -f "$CONFIG_DIR/config.json" ]]; then
CONFIG_JSON_FILE="$CONFIG_DIR/config.json"
elif [[ -f "$DEFAULT_CONFIG_DIR/config.json" ]]; then
CONFIG_JSON_FILE="$DEFAULT_CONFIG_DIR/config.json"
fi

if [[ -n "$CONFIG_JSON_FILE" ]] && command -v jq >/dev/null 2>&1; then
GEN_FILE="$CACHE_DIR/config.from_json"
jq -r --arg home "$HOME" '
def to_bash($name; $value): $name + "=" + @sh($value);
to_bash("MODULES"; ((.modules // []) | map(tostring) | join(" "))),
to_bash("ONLINE_MODULES"; ((.online_modules // []) | map(tostring) | join(" "))),
to_bash("DELAY"; ((.delay // "0.05")|tostring)),
to_bash("CUSTOM_DIR"; (.custom_dir // ($home + "/.config/dwmbar/modules/custom/"))),
to_bash("SEPARATOR"; (.separator // " | ")),
to_bash("RIGHT_PADDING"; (.right_padding // " ")),
to_bash("LEFT_PADDING"; (.left_padding // " "))
' "$CONFIG_JSON_FILE" > "$GEN_FILE" && CONFIG_FILE="$GEN_FILE" && export CONFIG_FILE
# Run config sync once at startup to ensure configs are in sync
if [[ -x "$SYNC_SCRIPT" ]]; then
"$SYNC_SCRIPT" 2>/dev/null || true
fi

while :; do
date=$(date +'%S')
if [ $(( 10#$date % 5 )) -eq 0 ]; then
INTERNET=$(check_internet)
# Sync again periodically in case user edits config
if [[ -x "$SYNC_SCRIPT" ]]; then
"$SYNC_SCRIPT" 2>/dev/null || true
fi
sleep 1
fi
xsetroot -name "$(exec $DEFAULT_BAR_LOCATION)"
done
5 changes: 5 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ if [[ -f "$REPO_ROOT/config.json" ]]; then
install -m 0644 "$REPO_ROOT/config.json" "$SHARE_DIR/config.json"
fi

# Install config sync script if present
if [[ -f "$REPO_ROOT/config-sync.sh" ]]; then
install -m 0755 "$REPO_ROOT/config-sync.sh" "$SHARE_DIR/config-sync.sh"
fi

install -m 0755 "$REPO_ROOT/dwmbar" "$BIN_DEST"

echo "Installation completed successfully."
4 changes: 2 additions & 2 deletions modules/time
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# Prints out the time

PREFIX=' '
PREFIX=' '

get_time()
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I just asked you to squash all your commits down so do not worry this is just advice I'll still happily accept this PR: Commits best organised so that they change one feature at a time. That would mean in this project:

  1. Add config_sync.sh, containing the new file and changes to install.sh and dwmbar + the readme entry that concerns it
  2. Change format in modules/time for the small change to modules/time.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you've done it right in your PR, the order of commits can matter, but not here. I usually organise them with a rebase into:

  • Required Api/infrastructure changes first (if needed)
  • Then add the feature + documentation if required, now that the required infra is committed.

Some people prefer to split up the docs or keep things even smaller, I prefer to have commits that move the code along in single functional chunks, with each commit fully functional.

echo "$PREFIX$(date '+%H:%M')"
echo "$PREFIX$(date '+%-I:%M %p')"
}

get_time
Binary file added res/bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.