diff --git a/README.md b/README.md index 67cd3ad8..6b5594e7 100644 --- a/README.md +++ b/README.md @@ -13,35 +13,46 @@ This is a very opinionated project, as I am a Tech Lead, this theme is very deve ## Requirements -### Nerd Fonts +This theme requires the following: -This theme requires the use of a patched font with Nerd Font. Ensure your terminal is set to use one before installing this theme. Any patched font will do. See -[`nerdfonts.com`](https://www.nerdfonts.com/) for more information. +- [Noto Sans] and one of any patched [Nerd Fonts] +- GNU [coreutils] and [bc] +- Bash 4.0 or newer -### Noto Fonts +### macOS -This theme requires the Noto fonts to be installed on your operating system. Make sure your operating system has the needed font and is configured to use one. +For macOS, you can install all dependencies via [Homebrew]: -### GNU bc -This theme requires the [`GNU bc`](https://www.gnu.org/software/bc/) for precise mathematical calculation of network speed, [Tokyo-night-tmux](https://github.com/janoamaral/tokyo-night-tmux) also shows the real time network speed in right side of status bar. +```bash +brew tap homebrew/cask-fonts +brew install --cask font-monaspace-nerd-font font-noto-sans +brew install bash bc coreutils gawk gsed +``` + +### Linux + +GNU coreutils are already installed on most Linux distributions. You can +install `bc` via your package manager. For example, on Arch Linux: ```bash pacman -S bc ``` -see documentation for installing [`GNU bc`](https://www.gnu.org/software/bc/) in other Operation system. + +Check documentation for installing [bc] on other operating systems. ## Installation using TPM In your `tmux.conf`: + ```bash set -g @plugin "janoamaral/tokyo-night-tmux" ``` ## Configuration -#### Number styles +### Number styles -Run this +Run these commands in your terminal: ```bash tmux set @tokyo-night-tmux_window_id_style digital @@ -49,7 +60,7 @@ tmux set @tokyo-night-tmux_pane_id_style hsquare tmux set @tokyo-night-tmux_zoom_id_style dsquare ``` -or add this lines to your `.tmux.conf` +Alternatively, add these lines to your `.tmux.conf`: ```bash set -g @tokyo-night-tmux_window_id_style digital @@ -57,24 +68,22 @@ set -g @tokyo-night-tmux_pane_id_style hsquare set -g @tokyo-night-tmux_zoom_id_style dsquare ``` - -## Widgets +### Widgets For widgets add following lines in you `.tmux.conf` - #### Date and Time widget -**Widget enabled by default** +This widget is enabled by default. To disable it: -set value 0 to disable ```bash set -g @tokyo-night-tmux_show_datetime 0 set -g @tokyo-night-tmux_date_format MYD set -g @tokyo-night-tmux_time_format 12H ``` -#### Available Options +##### Available Options + - `YMD`: (Year Month Day), 2024-01-31 - `MDY`: (Month Day Year), 01-31-2024 - `DMY`: (Day Month Year), 31-01-2024 @@ -82,7 +91,6 @@ set -g @tokyo-night-tmux_time_format 12H - `24H`: 18:30 - `12H`: 6:30 PM - #### Now Playing widget ```bash @@ -93,7 +101,7 @@ set -g @tokyo-night-tmux_show_music 1 ```bash set -g @tokyo-night-tmux_show_netspeed 1 -set -g @tokyo-night-tmux_netspeed_iface "wlan0" # your network interface, find with ip link +set -g @tokyo-night-tmux_netspeed_iface "wlan0" # find your interface with ip link ``` #### Path Widget @@ -111,30 +119,30 @@ set -g @tokyo-night-tmux_battery_name "BAT1" # some linux distro have 'BAT0' set -g @tokyo-night-tmux_battery_low_threshold 21 # default ``` -set variables value `0` to disable the widget, Remember to restart the `tmux` after changing values. +Set variable value `0` to disable the widget. Remember to restart `tmux` after +changing values. -## The styles: +## Styles - `none`: no style, default font -- `digital`: 7 segment number (🯰...🯹) (needs [Unicode support](https://github.com/janoamaral/tokyo-night-tmux/issues/36#issuecomment-1907072080)) +- `digital`: 7 segment number (🯰...🯹) (needs [Unicode support](https://github.com/janoamaral/tokyo-night-tmux/issues/36#issuecomment-1907072080)) - `roman`: roman numbers (󱂈...󱂐) (needs nerdfont) - `fsquare`: filled square (󰎡...󰎼) (needs nerdfont) - `hsquare`: hollow square (󰎣...󰎾) (needs nerdfont) - `dsquare`: hollow double square (󰎡...󰎼) (needs nerdfont) - `super`: superscript symbol (⁰...⁹) -- `sub`: subscript symbols (₀...₉) - +- `sub`: subscript symbols (₀...₉) ### New tokyonight Highlights ⚡ -Everything works out the box now. No need to modify anything and colors are hardcoded, +Everything works out the box now. No need to modify anything and colors are hardcoded, so it's independent of terminal theme. - Local git stats. - Web based git server (GitHub/GitLab) stats. - - Open PR count - - Open PR reviews count - - Issue count + - Open PR count + - Open PR reviews count + - Issue count - Remote branch sync indicator (you will never forget to push or pull again 🤪). - Great terminal icons. - Prefix highlight incorporated. @@ -168,12 +176,17 @@ Legacy tokyo-night ## Contributing -This project is open to contributions. Please feel free to open an issue or a pull request. - -Ensure your editor is configured appropriately to consider the provided `.editorconfig` file. -[pre-commit] hooks are also provided to ensure code consistency, and will be run against any raised PRs. +Feel free to open an issue or pull request with any suggestions or improvements. +Ensure your editor follows the style guide provided by `.editorconfig`. +[pre-commit] hooks are also provided to ensure code consistency, and will be +run against any raised PRs. [cmus]: https://cmus.github.io/ [nowplaying-cli]: https://github.com/kirtan-shah/nowplaying-cli [pre-commit]: https://pre-commit.com/ +[Noto Sans]: https://fonts.google.com/noto/specimen/Noto+Sans +[Nerd Fonts]: https://www.nerdfonts.com/ +[coreutils]: https://www.gnu.org/software/coreutils/ +[bc]: https://www.gnu.org/software/bc/ +[Homebrew]: https://brew.sh/ diff --git a/lib/coreutils-compat.sh b/lib/coreutils-compat.sh new file mode 100644 index 00000000..c1b7054b --- /dev/null +++ b/lib/coreutils-compat.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Compatibility functions for macOS +if [[ "$(uname)" == "Darwin" ]]; then + HOMEBREW_PREFIX="$(brew --prefix)" + # Use GNU coreutils if available + if [ -d "$HOMEBREW_PREFIX/opt/coreutils" ]; then + export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH" + fi + # Use GNU awk if available + if [ -d "$HOMEBREW_PREFIX/opt/gawk" ]; then + export PATH="$HOMEBREW_PREFIX/opt/gawk/libexec/gnubin:$PATH" + fi + # Use GNU sed if available + if [ -d "$HOMEBREW_PREFIX/opt/gsed" ]; then + export PATH="$HOMEBREW_PREFIX/opt/gsed/libexec/gnubin:$PATH" + fi + # Use Homebrew bc if available + if [ -d "$HOMEBREW_PREFIX/opt/bc" ]; then + export PATH="$HOMEBREW_PREFIX/opt/bc/bin:$PATH" + fi +fi diff --git a/src/battery-widget.sh b/src/battery-widget.sh index 61250244..a1f641bc 100755 --- a/src/battery-widget.sh +++ b/src/battery-widget.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +# Imports +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." +. "${ROOT_DIR}/lib/coreutils-compat.sh" + # check if not enabled SHOW_BATTERY_WIDGET=$(tmux show-option -gv @tokyo-night-tmux_show_battery_widget 2>/dev/null) if [ "${SHOW_BATTERY_WIDGET}" != "1" ]; then diff --git a/src/cmus-tmux-statusbar.sh b/src/cmus-tmux-statusbar.sh index 8cfe8cba..7c4249c4 100755 --- a/src/cmus-tmux-statusbar.sh +++ b/src/cmus-tmux-statusbar.sh @@ -1,4 +1,8 @@ -#!/bin/bash +#!/usr/bin/env bash + +# Imports +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." +. "${ROOT_DIR}/lib/coreutils-compat.sh" ACCENT_COLOR="#7aa2f7" SECONDARY_COLOR="#24283B" diff --git a/src/custom-number.sh b/src/custom-number.sh index 5239e68e..0408d3a7 100755 --- a/src/custom-number.sh +++ b/src/custom-number.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash -# + +# Imports +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." +. "${ROOT_DIR}/lib/coreutils-compat.sh" format_none="0123456789" format_digital="🯰🯱🯲🯳🯴🯵🯶🯷🯸🯹" diff --git a/src/datetime-widget.sh b/src/datetime-widget.sh index b8cf8874..0fd725f9 100755 --- a/src/datetime-widget.sh +++ b/src/datetime-widget.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +# Imports +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." +. "${ROOT_DIR}/lib/coreutils-compat.sh" + # Grab global variable for showing datetime widget, only hide if explicitly disabled SHOW_DATETIME=$(tmux show-option -gv @tokyo-night-tmux_show_datetime 2>/dev/null) if [[ $SHOW_DATETIME == "0" ]]; then diff --git a/src/git-status.sh b/src/git-status.sh index c7b5bb32..edd38600 100755 --- a/src/git-status.sh +++ b/src/git-status.sh @@ -7,6 +7,7 @@ fi CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source $CURRENT_DIR/themes.sh +source $CURRENT_DIR/../lib/coreutils-compat.sh cd $1 RESET="#[fg=${THEME[foreground]},bg=${THEME[background]},nobold,noitalics,nounderscore,nodim]" diff --git a/src/music-tmux-statusbar.sh b/src/music-tmux-statusbar.sh index 5bf7b1dc..e1b9c507 100755 --- a/src/music-tmux-statusbar.sh +++ b/src/music-tmux-statusbar.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +# Imports +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." +. "${ROOT_DIR}/lib/coreutils-compat.sh" + # Check the global value SHOW_MUSIC=$(tmux show-option -gv @tokyo-night-tmux_show_music) @@ -10,11 +14,6 @@ fi CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source $CURRENT_DIR/themes.sh -# Value parser for nowplaying-cli -parse_npcli_value() { - echo "$NPCLI_STATUS" | grep "$1" | awk -F '= ' '{print $2}' | tr -d '";' -} - ACCENT_COLOR="${THEME[blue]}" SECONDARY_COLOR="${THEME[background]}" BG_COLOR="${THEME[background]}" @@ -53,48 +52,32 @@ if command -v playerctl >/dev/null; then # nowplaying-cli elif command -v nowplaying-cli >/dev/null; then - NPCLI_STATUS=$(nowplaying-cli get-raw) - if [ "$(parse_npcli_value PlaybackRate)" = "1" ]; then + NPCLI_PROPERTIES=(title duration elapsedTime playbackRate isAlwaysLive) + mapfile -t NPCLI_OUTPUT < <(nowplaying-cli get "${NPCLI_PROPERTIES[@]}") + declare -A NPCLI_VALUES + for ((i = 0; i < ${#NPCLI_PROPERTIES[@]}; i++)); do + # Handle null values + [ "${NPCLI_OUTPUT[$i]}" = "null" ] && NPCLI_OUTPUT[$i]="" + NPCLI_VALUES[${NPCLI_PROPERTIES[$i]}]="${NPCLI_OUTPUT[$i]}" + done + if [ -n "${NPCLI_VALUES[playbackRate]}" ] && [ "${NPCLI_VALUES[playbackRate]}" -gt 0 ]; then STATUS="playing" else STATUS="paused" fi - TITLE=$(parse_npcli_value Title) - if [ "$(parse_npcli_value IsAlwaysLive)" = "1" ]; then + TITLE="${NPCLI_VALUES[title]}" + if [ "${NPCLI_VALUES[isAlwaysLive]}" = "1" ]; then DURATION=-1 POSITION=0 else - DURATION=$(parse_npcli_value Duration | cut -d. -f1) - POSITION=$(parse_npcli_value ElapsedTime | cut -d. -f1) + DURATION=$(printf "%.0f" "${NPCLI_VALUES[duration]}") + POSITION=$(printf "%.0f" "${NPCLI_VALUES[elapsedTime]}") fi - # If playing media with a duration, calculate POSITION from last update - if [ "$STATUS" = "playing" ] && [ "$DURATION" -gt 0 ]; then - # Assuming BSD date on macOS - update_timestamp=$(date -j -f "%Y-%m-%d %H:%M:%S %z" "$(parse_npcli_value Timestamp)" +"%s") - current_timestamp=$(date -u +"%s") - # Calculate seconds since last update - UPDATE_AGE=$((current_timestamp - update_timestamp)) - POSITION=$((POSITION + UPDATE_AGE)) - # Cap at DURATION - if [ "$POSITION" -gt "$DURATION" ]; then - POSITION=$DURATION - fi - fi -fi -# If POSITION, calculate the progress bar -if [ -n "$POSITION" ]; then - P_MIN=$(printf '%02d' $((POSITION / 60))) - P_SEC=$(printf '%02d' $((POSITION % 60))) fi -if [ -n "$DURATION" ]; then - D_MIN=$(printf '%02d' $((DURATION / 60))) - D_SEC=$(printf '%02d' $((DURATION % 60))) -fi -if [ -n "$DURATION" ] && [ -n "$POSITION" ]; then - TIME="[$P_MIN:$P_SEC / $D_MIN:$D_SEC]" - if [ "$D_SEC" = "-1" ]; then - TIME="[--:--]" - fi + +# Calculate the progress bar for sane durations +if [ -n "$DURATION" ] && [ -n "$POSITION" ] && [ "$DURATION" -gt 0 ] && [ "$DURATION" -lt 3600 ]; then + TIME="[$(date -d@$POSITION -u +%M:%S) / $(date -d@$DURATION -u +%M:%S)]" else TIME="[--:--]" fi diff --git a/src/netspeed.sh b/src/netspeed.sh index a89edc8b..bfeb50a9 100755 --- a/src/netspeed.sh +++ b/src/netspeed.sh @@ -4,6 +4,10 @@ # email : freakybytes@duck.com #<------------------------------------------------------------------------------------------> +# Imports +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." +. "${ROOT_DIR}/lib/coreutils-compat.sh" + # Check the global value SHOW_NETSPEED=$(tmux show-option -gv @tokyo-night-tmux_show_netspeed) if [ "$SHOW_NETSPEED" != "1" ]; then @@ -18,7 +22,15 @@ INTERFACE=$(tmux show-option -gv @tokyo-night-tmux_netspeed_iface 2>/dev/null) # Get network transmit data from /proc/net/dev get_bytes() { - awk -v interface="$1" '$1 == interface ":" {print $2, $10}' /proc/net/dev + local interface="$1" + if [[ "$(uname)" == "Linux" ]]; then + awk -v interface="$interface" '$1 == interface ":" {print $2, $10}' /proc/net/dev + elif [[ "$(uname)" == "Darwin" ]]; then + netstat -ib | awk -v interface="$interface" '/^'${interface}'/ {print $7, $10}' + else + # Unsupported operating system + exit 1 + fi } # Convert into readable format diff --git a/src/path-widget.sh b/src/path-widget.sh index 35551973..1bdc5f84 100755 --- a/src/path-widget.sh +++ b/src/path-widget.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +# Imports +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." +. "${ROOT_DIR}/lib/coreutils-compat.sh" + # get value from tmux config SHOW_PATH=$(tmux show-option -gv @tokyo-night-tmux_show_path 2>/dev/null) PATH_FORMAT=$(tmux show-option -gv @tokyo-night-tmux_path_format 2>/dev/null) # full | relative diff --git a/src/themes.sh b/src/themes.sh index 93ef2898..259b37cc 100644 --- a/src/themes.sh +++ b/src/themes.sh @@ -51,8 +51,7 @@ case $SELECTED_THEME in ) ;; -\ - *) +*) # Default to night theme declare -A THEME=( ["background"]="#1A1B26" diff --git a/src/wb-git-status.sh b/src/wb-git-status.sh index d1fd3ae4..499d4b54 100755 --- a/src/wb-git-status.sh +++ b/src/wb-git-status.sh @@ -7,6 +7,10 @@ fi CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source $CURRENT_DIR/themes.sh +# Imports +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." +. "${ROOT_DIR}/lib/coreutils-compat.sh" + cd $1 BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) PROVIDER=$(git config remote.origin.url | awk -F '@|:' '{print $2}')