diff --git a/README.md b/README.md
index 661f9d5..926fbd5 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,9 @@ dwmbar - A Modular Status Bar for dwm
=====================================

+
+
+
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.
@@ -20,8 +23,10 @@ Optional (By module):
See [module prerequisites](#module-prerequisites).
+## Installation Methods
-## Arch Linux
+
+Arch Linux
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.
@@ -29,14 +34,26 @@ 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
```
+
+
+
+Automated install
+
+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.
+
+
# Usage
dwmbar works by setting the root window name, which dwm displays. It does this
diff --git a/config-sync.sh b/config-sync.sh
new file mode 100755
index 0000000..8ffa226
--- /dev/null
+++ b/config-sync.sh
@@ -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
diff --git a/dwmbar b/dwmbar
index 3810ca6..a038c93 100755
--- a/dwmbar
+++ b/dwmbar
@@ -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
@@ -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(){
@@ -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
diff --git a/install.sh b/install.sh
index a36b27b..91a34f0 100755
--- a/install.sh
+++ b/install.sh
@@ -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."
diff --git a/modules/time b/modules/time
index dfd2400..6541329 100755
--- a/modules/time
+++ b/modules/time
@@ -2,11 +2,11 @@
# Prints out the time
-PREFIX=' '
+PREFIX=' '
get_time()
{
- echo "$PREFIX$(date '+%H:%M')"
+ echo "$PREFIX$(date '+%-I:%M %p')"
}
get_time
diff --git a/res/bar.png b/res/bar.png
new file mode 100644
index 0000000..d809dc1
Binary files /dev/null and b/res/bar.png differ