Skip to content

Commit

Permalink
feat: macOS support improvements (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stealthii authored Apr 13, 2024
1 parent 6fe88ac commit d6fce99
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 75 deletions.
77 changes: 45 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,84 @@ 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
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
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

- `24H`: 18:30
- `12H`: 6:30 PM


#### Now Playing widget

```bash
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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/
22 changes: 22 additions & 0 deletions lib/coreutils-compat.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/battery-widget.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/cmus-tmux-statusbar.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 4 additions & 1 deletion src/custom-number.sh
Original file line number Diff line number Diff line change
@@ -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="🯰🯱🯲🯳🯴🯵🯶🯷🯸🯹"
Expand Down
4 changes: 4 additions & 0 deletions src/datetime-widget.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/git-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down
59 changes: 21 additions & 38 deletions src/music-tmux-statusbar.sh
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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]}"
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/netspeed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# email : [email protected]
#<------------------------------------------------------------------------------------------>

# 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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/path-widget.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/themes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ case $SELECTED_THEME in
)
;;

\
*)
*)
# Default to night theme
declare -A THEME=(
["background"]="#1A1B26"
Expand Down
4 changes: 4 additions & 0 deletions src/wb-git-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down

0 comments on commit d6fce99

Please sign in to comment.