Skip to content

Commit

Permalink
v1.5.3 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
janoamaral authored May 4, 2024
2 parents 0801746 + 2bc27a9 commit d34f148
Show file tree
Hide file tree
Showing 11 changed files with 402 additions and 68 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/bats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: bats

on:
pull_request:
push:
branches: [master, next]
workflow_dispatch:

jobs:
bats-alpine:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
bash: ["4.2", "4.4", "5.0", "5.2"]
container:
image: bash:${{ matrix.bash }}
steps:
- name: Install packages
run: |
# Pipeline requirements
apk add curl git ncurses parallel sudo tar
# Theme dependencies
apk add bc coreutils gawk jq playerctl sed
# Allow tar to cache system paths
- name: root suid tar
run: sudo chown root:wheel /bin/tar && sudo chmod u+s /bin/tar

- name: Setup Bats and bats libs
uses: stealthii/bats-action@main

- name: Checkout code
uses: actions/checkout@v4

- name: Run tokyo-night-tmux tests
shell: bash -e {0}
run: bats --verbose-run --report-formatter junit test/

- name: Upload Test Report
uses: actions/upload-artifact@v4
if: always()
with:
name: report-alpine-${{ matrix.bash }}
path: report.xml
bats-macos:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
libs: ["gnu", "builtin"]
steps:
- name: Install Homebrew packages
run: |
# Theme dependencies
brew install bash jq nowplaying-cli
if [[ "${{ matrix.libs }}" == "gnu" ]]; then
brew install bc coreutils gawk gsed
fi
- name: Setup Bats and bats libs
run: |
brew install bats-core
brew tap stealthii/bats-core
brew install bats-support bats-assert bats-file bats-detik bats-mock
- name: Checkout code
uses: actions/checkout@v4

- name: Run tokyo-night-tmux tests
run: bats --verbose-run --report-formatter junit test/

- name: Upload Test Report
uses: actions/upload-artifact@v4
if: always()
with:
name: report-macOS-${{ matrix.libs }}
path: report.xml
junit-publish:
needs: [bats-alpine, bats-macos]
runs-on: ubuntu-latest
steps:
- name: Download all workflow run artifacts
uses: actions/download-artifact@v4

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
with:
report_paths: "**/report.xml"
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: pre-commit
on:
pull_request:
push:
branches: [master]
branches: [master, next]

jobs:
pre-commit:
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: report
on:
workflow_run:
workflows: [bats]
types: [completed]

permissions:
checks: write

jobs:
checks:
runs-on: ubuntu-latest
steps:
- name: Download Test Report
uses: dawidd6/action-download-artifact@v3
with:
name: report-.*
name_is_regexp: true
workflow: ${{ github.event.workflow.id }}
run_id: ${{ github.event.workflow_run.id }}

- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
with:
commit: ${{github.event.workflow_run.head_sha}}
report_paths: "**/report.xml"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# JUnit reports
**/report.xml
14 changes: 12 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
repos:
- repo: https://github.com/pecigonzalo/pre-commit-shfmt
rev: v2.1.0
- repo: local
hooks:
- id: shell-fmt-go
name: shfmt
description: Rewrites all shell scripts to a canonical format.
language: golang
additional_dependencies:
- mvdan.cc/sh/v3/cmd/[email protected]
entry: shfmt
types:
- file
- shell
exclude_types:
- zsh
args:
- -w
- -s
Expand Down
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,50 @@ This is a very opinionated project, as I am a Tech Lead, this theme is very deve

## Requirements

This theme requires the following:
This theme has the following hard requirements:

- [Noto Sans] and one of any patched [Nerd Fonts]
- GNU [coreutils] and [bc]
- Bash 4.0 or newer
- Any patched [Nerd Fonts] (v3 or higher)
- Bash 4.2 or newer

The following are recommended for full support of all widgets and features:

- [Noto Sans] Symbols 2 (for segmented digit numbers)
- [bc] (for netspeed and git widgets)
- [jq], [gh], [glab] (for git widgets)
- [playerctl] (Linux) or [nowplaying-cli] (macOS) for music statusbar

### macOS

For macOS, you can install all dependencies via [Homebrew]:
macOS still ships with bash 3.2 so you must provide a newer version.
You can easily install all dependencies via [Homebrew]:

```bash
brew tap homebrew/cask-fonts
brew install --cask font-monaspace-nerd-font font-noto-sans
brew install bash bc coreutils gawk gsed
brew install --cask font-monaspace-nerd-font font-noto-sans-symbols-2
brew install bash bc coreutils gawk gh glab gsed jq nowplaying-cli
```

### Linux

GNU coreutils are already installed on most Linux distributions. You can
install `bc` via your package manager. For example, on Arch Linux:
#### Alpine Linux

```bash
apk add bash bc coreutils gawk git jq playerctl sed
```

#### Arch Linux

```bash
pacman -S bc
pacman -Sy bash bc coreutils git jq playerctl
```

Check documentation for installing [bc] on other operating systems.
#### Ubuntu

```bash
apt-get install bash bc coreutils gawk git jq playerctl
```

Check documentation for installing on other operating systems.

## Installation using TPM

Expand Down Expand Up @@ -100,10 +118,13 @@ set -g @tokyo-night-tmux_show_music 1
```

#### Netspeed widget
![Snap netspeed](snaps/netspeed.png)

```bash
set -g @tokyo-night-tmux_show_netspeed 1
set -g @tokyo-night-tmux_netspeed_iface "wlan0" # find your interface with ip link
set -g @tokyo-night-tmux_netspeed_iface "wlan0" # Detected via default route
set -g @tokyo-night-tmux_netspeed_showip 1 # Display IPv4 address (default 0)
set -g @tokyo-night-tmux_netspeed_refresh 1 # Update interval in seconds (default 1)
```

#### Path Widget
Expand Down Expand Up @@ -148,7 +169,7 @@ so it's independent of terminal theme.
- Remote branch sync indicator (you will never forget to push or pull again 🤪).
- Great terminal icons.
- Prefix highlight incorporated.
- Now Playing status bar, supporting [cmus]/[nowplaying-cli]
- Now Playing status bar, supporting [playerctl]/[nowplaying-cli]
- Windows has custom pane number indicator.
- Pane zoom mode indicator.
- Date and time.
Expand Down Expand Up @@ -187,11 +208,12 @@ 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/
[jq]: https://jqlang.github.io/jq/
[playerctl]: https://github.com/altdesktop/playerctl
[nowplaying-cli]: https://github.com/kirtan-shah/nowplaying-cli
[Homebrew]: https://brew.sh/
66 changes: 66 additions & 0 deletions lib/netspeed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

# Get network transmit data
function get_bytes() {
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}' | head -n1
else
# Unsupported operating system
exit 1
fi
}

# Convert into readable format
function readable_format() {
local bytes=$1
local secs=${2:-1}

if [[ $bytes -lt 1048576 ]]; then
echo "$(bc -l <<<"scale=1; $bytes / 1024 / $secs")KB/s"
else
echo "$(bc -l <<<"scale=1; $bytes / 1048576 / $secs")MB/s"
fi
}

# Auto-determine interface
function find_interface() {
local interface
if [[ $(uname) == "Linux" ]]; then
interface=$(awk '$2 == 00000000 {print $1}' /proc/net/route)
elif [[ $(uname) == "Darwin" ]]; then
interface=$(route get default 2>/dev/null | grep interface | awk '{print $2}')
# If VPN, fallback to en0
[[ ${interface:0:4} == "utun" ]] && interface="en0"
fi
echo "$interface"
}

# Detect interface IPv4 and status
function interface_ipv4() {
local interface="$1"
local ipv4_addr
local status="up" # Default assumption
if [[ $(uname) == "Darwin" ]]; then
# Check for an IPv4 on macOS
ipv4_addr=$(ipconfig getifaddr "$interface")
[[ -z $ipv4_addr ]] && status="down"
elif [[ $(uname) == "Linux" ]]; then
# Use 'ip' command to check for IPv4 address
if command -v ip >/dev/null 2>&1; then
ipv4_addr=$(ip addr show dev "$interface" 2>/dev/null | grep "inet\b" | awk '{sub("/.*", "", $2); print $2}')
[[ -z $ipv4_addr ]] && status="down"
# Use 'ifconfig' command to check for IPv4 address
elif command -v ifconfig >/dev/null 2>&1; then
ipv4_addr=$(ifconfig "$interface" 2>/dev/null | grep "inet\b" | awk '{print $2}')
[[ -z $ipv4_addr ]] && status="down"
# Fallback to operstate on Linux
elif [[ $(cat "/sys/class/net/$interface/operstate" 2>/dev/null) != "up" ]]; then
status="down"
fi
fi
echo "$ipv4_addr"
[[ $status == "up" ]] && return 0 || return 1
}
Binary file added snaps/netspeed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d34f148

Please sign in to comment.