Skip to content

Commit 9ee9359

Browse files
committed
feat: add new uptime segment
1 parent ca95238 commit 9ee9359

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ tmux window list
231231
- `@tmux2k-window-list-format`: Sets the format for the window list. Default: `'#I:#W'`
232232
- `@tmux2k-window-list-compact`: Enables or disables compact mode for the window list. Default: `false`
233233

234+
#### 15. `uptime`
235+
236+
Show current system uptime
237+
238+
- `tmux2k-uptime-icon`: Icon for system uptime, default: `󰀠`
239+
234240
#### 🪆 Add New Plugins
235241

236242
To add a new plugin:

main.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,20 @@ yellow=$(get_tmux_option "@tmux2k-yellow" '#ffd21a')
5353
dark_yellow=$(get_tmux_option "@tmux2k-dark-yellow" '#b8860b')
5454

5555
declare -A plugin_colors=(
56-
["session"]="green text"
57-
["git"]="green text"
56+
["bandwidth"]="purple text"
57+
["battery"]="pink text"
5858
["cpu"]="light_green text"
5959
["cwd"]="blue text"
60-
["ram"]="yellow text"
60+
["git"]="green text"
6161
["gpu"]="red text"
62-
["battery"]="pink text"
6362
["network"]="purple text"
64-
["bandwidth"]="purple text"
6563
["ping"]="purple text"
66-
["weather"]="orange text"
67-
["time"]="light_blue text"
6864
["pomodoro"]="red text"
65+
["ram"]="yellow text"
66+
["session"]="green text"
67+
["time"]="light_blue text"
68+
["uptime"]="light_blue text"
69+
["weather"]="orange text"
6970
["window_list"]="black blue"
7071
["custom"]="red text"
7172
)

plugins/uptime.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
source "$current_dir/../lib/utils.sh"
5+
6+
uptime_icon=$(get_tmux_option "@tmux2k-uptime-icon" "󰀠")
7+
8+
main() {
9+
uptime_output=$(uptime)
10+
uptime_text=$(echo "$uptime_output" | awk -F'up ' '{print $2}' | awk -F',' '{print $1}')
11+
12+
days=0
13+
hours=0
14+
minutes=0
15+
16+
echo "$uptime_text" | awk '
17+
{
18+
for (i = 1; i <= NF; i++) {
19+
if ($i ~ /^[0-9]+$/ && $(i+1) == "days") { days = $i }
20+
if ($i ~ /^[0-9]+:[0-9]+$/) { split($i, t, ":"); hours = t[1]; minutes = t[2] }
21+
if ($i ~ /^[0-9]+$/ && $(i+1) == "hours") { hours = $i }
22+
if ($i ~ /^[0-9]+$/ && $(i+1) == "mins") { minutes = $i }
23+
}
24+
}
25+
END { printf "%d %d %d\n", days, hours, minutes }' | {
26+
read days hours minutes
27+
28+
output=""
29+
[ "$days" -gt 0 ] && output="$output${days}D "
30+
[ "$hours" -gt 0 ] && output="$output${hours}H "
31+
[ "$minutes" -gt 0 ] && output="$output${minutes}M"
32+
33+
echo "$uptime_icon $output"
34+
}
35+
}
36+
37+
main

0 commit comments

Comments
 (0)