Skip to content

Commit e92a4ef

Browse files
committed
feat: extract all icons to configs
1 parent 8bb1322 commit e92a4ef

File tree

6 files changed

+66
-23
lines changed

6 files changed

+66
-23
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,28 @@ set -g @tmux2k-yellow '#f8c800' # change yellow color
112112
1. `bandwidth`: Show network bandwidth usage
113113

114114
- `tmux2k-bandwidth-network-name`: Network interface to track bandwidth of, default: `en0`
115+
- `tmux2k-bandwidth-up-icon`: Icon for bandwidth upload usage, default: ``
116+
- `tmux2k-bandwidth-down-icon`: Icon for bandwidth download usage, default: ``
115117

116118
2. `battery`: Show battery stats and percentage
119+
120+
- `tmux2k-battery-charging-icon`: Icon for charging status, default: ``
121+
- `tmux2k-battery-missing-icon`: Icon for missing battery, default: `󱉝`
122+
- `tmux2k-battery-percentage-0`: Icon for 0-25% battery, default: ``
123+
- `tmux2k-battery-percentage-1`: Icon for 25-50% battery, default: ``
124+
- `tmux2k-battery-percentage-2`: Icon for 50-75% battery, default: ``
125+
- `tmux2k-battery-percentage-3`: Icon for 75-90% battery, default: ``
126+
- `tmux2k-battery-percentage-4`: Icon for 90-100% battery, default: ``
127+
117128
3. `cpu`: Show CPU usage information
118129

119130
- `tmux2k-cpu-icon`: Icon for CPU usage, default: ``
120131
- `tmux2k-cpu-display-load`: Control CPU load display, default: `false`
121132

122133
4. `cwd`: Show current working directory
134+
135+
- `tmux2k-cwd-icon`: Icon for directory, default: ``
136+
123137
5. `git`: Show Git branch and status information
124138

125139
- `tmux2k-git-display-status`: Control git status display, default: `false`
@@ -136,6 +150,11 @@ set -g @tmux2k-yellow '#f8c800' # change yellow color
136150
- `tmux2k-gpu-icon`: Icon for GPU usage, default: ```
137151

138152
7. `network`: Show network status and statistics
153+
154+
- `tmux2k-network-ethernet-icon`: Icon for Ethernet connection, default: `󰈀`
155+
- `tmux2k-network-wifi-icon`: Icon for Wi-Fi connection, default: ``
156+
- `tmux2k-network-offline-icon`: Icon for offline status, default: `󰌙`
157+
139158
8. `ping`: Show network ping statistics
140159
9. `pomodoro`: Shows pomodoro timer, needs [tmux-pomodoro-plus](https://github.com/olimorris/tmux-pomodoro-plus) (hit `prefix + p` to start)
141160
10. `ram`: Show RAM usage information

plugins/bandwidth.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ main() {
5454
initial_download=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $7}')
5555
initial_upload=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $10}')
5656

57-
sleep $RATE
57+
sleep "$RATE"
5858

5959
final_download=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $7}')
6060
final_upload=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $10}')
@@ -65,10 +65,13 @@ main() {
6565
total_download_bps=$(expr "$total_download_bytes" / "$RATE")
6666
total_upload_bps=$(expr "$total_upload_bytes" / "$RATE")
6767

68-
output_download=$(get_output_rate $total_download_bps)
69-
output_upload=$(get_output_rate $total_upload_bps)
68+
output_download=$(get_output_rate "$total_download_bps")
69+
output_upload=$(get_output_rate "$total_upload_bps")
70+
71+
up_icon=$(get_tmux_option "@tmux2k-bandwidth-up-icon" "")
72+
down_icon=$(get_tmux_option "@tmux2k-bandwidth-up-icon" "")
7073

71-
echo "${output_upload}${output_download}"
74+
echo "$output_upload $up_icon $output_download $down_icon"
7275
done
7376
}
7477
main

plugins/battery.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
export LC_ALL=en_US.UTF-8
44

5+
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "$current_dir/../lib/utils.sh"
7+
8+
charging_icon=$(get_tmux_option "@tmux2k-battery-charging-icon" "")
9+
battery_missing=$(get_tmux_option "@tmux2k-battery-missing-icon" "󱉝")
10+
percentage_0=$(get_tmux_option "@tmux2k-battery-percentage-0" "")
11+
percentage_1=$(get_tmux_option "@tmux2k-battery-percentage-1" "")
12+
percentage_2=$(get_tmux_option "@tmux2k-battery-percentage-2" "")
13+
percentage_3=$(get_tmux_option "@tmux2k-battery-percentage-3" "")
14+
percentage_4=$(get_tmux_option "@tmux2k-battery-percentage-4" "")
15+
516
linux_acpi() {
617
arg=$1
718
BAT=$(ls -d /sys/class/power_supply/BAT* | head -1)
@@ -44,24 +55,23 @@ battery_status() {
4455
case $status in
4556
discharging | Discharging) echo '' ;;
4657
high) echo '' ;;
47-
charging) echo '' ;;
48-
*) echo '' ;;
58+
charging) echo "$charging_icon" ;;
4959
esac
5060
}
5161

5262
battery_label() {
5363
if [ "$bat_perc" -gt 90 ]; then
54-
echo " "
64+
echo "$percentage_4 "
5565
elif [ "$bat_perc" -gt 75 ]; then
56-
echo " "
66+
echo "$percentage_3 "
5767
elif [ "$bat_perc" -gt 50 ]; then
58-
echo " "
68+
echo "$percentage_2 "
5969
elif [ "$bat_perc" -gt 25 ]; then
60-
echo " "
70+
echo "$percentage_1 "
6171
elif [ "$bat_perc" -gt 10 ]; then
62-
echo " "
72+
echo "$percentage_0 "
6373
else
64-
echo "󱉝 "
74+
echo "$battery_missing "
6575
fi
6676
}
6777

plugins/cwd.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env bash
22

3+
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
source "$current_dir/../lib/utils.sh"
5+
36
# return current working directory of tmux pane
47
get_pane_dir() {
58
nextone="false"
@@ -18,15 +21,15 @@ truncate_path() {
1821

1922
# If path is greater than limit, then truncate parts to 2 characters
2023
[[ ${#path} -le $limit ]] && echo "$path" && return
21-
IFS='/' read -ra parts <<< "$path"
22-
for ((i=0; i<${#parts[@]}-1; i++)); do
24+
IFS='/' read -ra parts <<<"$path"
25+
for ((i = 0; i < ${#parts[@]} - 1; i++)); do
2326
truncated_path+="${parts[i]:0:2}/"
2427
done
2528
truncated_path+="${parts[-1]}"
2629

2730
# If there are more than 4 slashes, then we will truncate the middle part
28-
if [[ $(tr -cd '/' <<< "$truncated_path" | wc -c) -gt 4 ]]; then
29-
IFS='/' read -ra parts <<< "$truncated_path"
31+
if [[ $(tr -cd '/' <<<"$truncated_path" | wc -c) -gt 4 ]]; then
32+
IFS='/' read -ra parts <<<"$truncated_path"
3033
echo "${parts[0]}/${parts[1]}/.../${parts[-2]}/${parts[-1]}"
3134
else
3235
echo "$truncated_path"
@@ -39,8 +42,9 @@ main() {
3942
# Change '/home/user' to '~'
4043
cwd="${path/"$HOME"/'~'}"
4144
truncated_cwd=$(truncate_path "$cwd")
45+
cwd_icon=$(get_tmux_option "@tmux2k-ram-icon" "")
4246

43-
echo " $truncated_cwd"
47+
echo "$cwd_icon $truncated_cwd"
4448
}
4549

4650
#run main driver program

plugins/network.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,31 @@ export LC_ALL=en_US.UTF-8
44

55
HOSTS="google.com github.com example.com"
66

7+
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
source "$current_dir/../lib/utils.sh"
9+
10+
ethernet_icon=$(get_tmux_option "@tmux2k-network-ethernet-icon" "󰈀")
11+
wifi_icon=$(get_tmux_option "@tmux2k-network-wifi-icon" "")
12+
offline_icon=$(get_tmux_option "@tmux2k-network-offline-icon" "󰌙")
13+
714
get_ssid() {
815
case $(uname -s) in
916
Linux)
1017
SSID=$(iwgetid -r)
1118
if [ -n "$SSID" ]; then
12-
printf '%s' " $SSID"
19+
printf '%s' "$wifi_icon $SSID"
1320
else
14-
echo '󰈀 Eth'
21+
echo "$ethernet_icon Eth"
1522
fi
1623
;;
1724

1825
Darwin)
1926
device_name=$(networksetup -listallhardwareports | grep -A 1 Wi-Fi | grep Device | awk '{print $2}')
2027
SSID=$(networksetup -getairportnetwork "$device_name" | awk -F ": " '{print $2}')
2128
if [ -n "$SSID" ]; then
22-
printf '%s' " $SSID"
29+
printf '%s' "$wifi_icon $SSID"
2330
else
24-
echo '󰈀 Eth'
31+
echo "$ethernet_icon Eth"
2532
fi
2633
;;
2734

@@ -30,7 +37,7 @@ get_ssid() {
3037
}
3138

3239
main() {
33-
network="Offline"
40+
network="$offline_icon Offline"
3441
for host in $HOSTS; do
3542
if ping -q -c 1 -W 1 "$host" &>/dev/null; then
3643
network="$(get_ssid)"

plugins/ping.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ping_function() {
1313
echo "$pingtime ms"
1414
;;
1515

16-
CYGWIN* | MINGW32* | MSYS* | MINGW*) ;; # TODO - windows compatability
16+
CYGWIN* | MINGW32* | MSYS* | MINGW*) ;; # TODO - windows compatibility
1717
esac
1818
}
1919

0 commit comments

Comments
 (0)