-
Notifications
You must be signed in to change notification settings - Fork 28
Update README with installation instructions #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
581e0c3
13fe763
4737b37
4d91c99
b7163d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,11 @@ | |
|
|
||
| # Prints out the time | ||
|
|
||
| PREFIX=' ' | ||
| PREFIX=' ' | ||
|
|
||
| get_time() | ||
| { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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 | ||
There was a problem hiding this comment.
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 👀
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.