Skip to content

Commit dec42b4

Browse files
committed
Merge branch 'master' into music-player-adjustments
2 parents a149f17 + 91a1e09 commit dec42b4

File tree

5 files changed

+255
-34
lines changed

5 files changed

+255
-34
lines changed

docs/CONFIG.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [playerctl](#playerctl---up)
3232
- [ram-usage](#ram-usage---up)
3333
- [spotify-tui](#spotify-tui---up)
34+
- [spr](#spr---up)
3435
- [ssh-session](#ssh-session---up)
3536
- [synchronize-panes](#synchronize-panes---up)
3637
- [sys-temp](#sys-temp---up)
@@ -88,6 +89,18 @@ Hide empty plugins
8889
set -g @dracula-show-empty-plugins false
8990
```
9091

92+
Set plugin padding
93+
Whilst the padding is one space per default, can be whatever you want it to be, whether that's whitespace or other characters.
94+
**If you want to remove any padding, you need to use a zero width space!**
95+
96+
```bash
97+
set -g @dracula-left-pad ' ° '
98+
set -g @dracula-right-pad ' ° '
99+
# no padding with zero width space
100+
set -g @dracula-left-pad ''
101+
set -g @dracula-right-pad ''
102+
```
103+
91104
### Powerline - [up](#table-of-contents)
92105

93106
Enable powerline symbols
@@ -219,6 +232,18 @@ alternatively, if you have no battery and would like a nerdfont icon to indicate
219232
set -g @dracula-no-battery-label ""
220233
```
221234

235+
in case you have multiple batteries:
236+
237+
the default battery label is only displayed in the very front.
238+
you can specify multiple battery labels by splitting them with `\n` like so:
239+
```bash
240+
set -g @dracula-battery-label "1:\n2:"
241+
```
242+
additionally you can specify the separator between each battery like so:
243+
```bash
244+
set -g @dracula-battery-separator "; "
245+
```
246+
222247
### compact-alt - [up](#table-of-contents)
223248

224249
This widget allows the user to switch to an alternate list of widgets when the terminal becomes narrow.
@@ -516,6 +541,7 @@ set -g @dracula-kubernetes-eks-extract-account true
516541
This script retrieves and displays continuous glucose monitoring (CGM) data from the LibreView API.
517542
It caches the data to minimize API requests and displays the latest glucose level along with a trend indicator in a Tmux status bar.
518543

544+
519545
### mac-player - [up](#table-of-contents)
520546

521547
This widget and script displays music information provided by the native macOS players.
@@ -535,8 +561,6 @@ The supported remote players are:
535561
- Spotify
536562
- Music - Apple Music
537563

538-
NOTE: `set -g @dracula-refresh-rate 5` affects this widget
539-
540564
To change player icons:
541565

542566
```bash
@@ -728,8 +752,47 @@ To limit the maximum length (0 means unlimited length):
728752
set -g @dracula-spotify-tui-max-len 30
729753
```
730754

755+
731756
`set -g @dracula-refresh-rate 5` affects this widget
732757

758+
### spr - [up](#table-of-contents)
759+
760+
This widget displays music information provided by [spotify-player](https://github.com/aome510/spotify-player). spotify-player must be installed to use this widget.
761+
762+
To change player icons:
763+
764+
```bash
765+
set -g @dracula-spr-play-icon ""
766+
set -g @dracula-spr-pause-icon "❚❚ "
767+
768+
```
769+
770+
This section includes an experimental remote control feature, but it may limit the widget’s display on macOS.
771+
772+
In order to utilize the remote feature you need to install the [spotify-player-daemon](https://github.com/aome510/spotify-player#daemon)
773+
To activate the remote:
774+
775+
```bash
776+
set -g @dracula-spr-remote true
777+
```
778+
779+
The default keybinds are:
780+
781+
- `<prefix> + P` - Play/Pause
782+
- `<prefix> + R` - Back to position 0/previous track
783+
- `<prefix> + N` - Next track
784+
785+
To change the keybinds:
786+
787+
```bash
788+
set -g @dracula-spr-remote-play-pause "P"
789+
set -g @dracula-spr-remote-back "R"
790+
set -g @dracula-spr-remote-next "N"
791+
```
792+
793+
`set -g @dracula-refresh-rate 5` affects this widget
794+
795+
733796
### ssh-session - [up](#table-of-contents)
734797

735798
This widget displays the current username@host combination, both of the local machine as well as when connected via ssh.

scripts/battery.sh

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ battery_percent()
6161
esac
6262
}
6363

64-
battery_status()
64+
get_battery_status()
6565
{
6666
# Check OS
6767
case $(uname -s) in
@@ -84,9 +84,15 @@ battery_status()
8484
*)
8585
;;
8686
esac
87+
echo "$status"
88+
}
8789

88-
tmp_bat_perc=$(battery_percent)
89-
bat_perc="${tmp_bat_perc%\%}"
90+
parse_battery_status()
91+
{
92+
# $1 is battery_percent
93+
bat_perc="$1"
94+
# $2 is get_battery_status
95+
status="$2"
9096

9197
case $status in
9298
discharging|Discharging)
@@ -153,31 +159,40 @@ battery_status()
153159

154160
main()
155161
{
162+
# get left most custom label
156163
bat_label=$(get_tmux_option "@dracula-battery-label" "")
157164
if [ "$bat_label" == false ]; then
158165
bat_label=""
159166
fi
160167

168+
# get label for when there is no battery
161169
no_bat_label=$(get_tmux_option "@dracula-no-battery-label" "AC")
162170
if [ "$no_bat_label" == false ]; then
163171
no_bat_label=""
164172
fi
165173

166-
show_bat_label=$(get_tmux_option "@dracula-show-battery-status" false)
167-
if $show_bat_label; then
168-
bat_stat=$(battery_status)
169-
else
170-
bat_stat=""
171-
fi
172-
173174
bat_perc=$(battery_percent)
175+
bat_perc="${bat_perc%\%}"
174176

175-
if [ -z "$bat_stat" ]; then # Test if status is empty or not
176-
echo "$bat_label $bat_perc"
177-
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
177+
# display widget
178+
if [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
178179
echo "$no_bat_label"
179180
else
180-
echo "$bat_label$bat_stat $bat_perc"
181+
IFS=$'\n' read -rd '' -a percs <<<"$bat_perc"
182+
IFS=$'\n' read -rd '' -a stats <<<"$(get_battery_status)"
183+
IFS=$'\n' read -rd '' -a lbls <<<"$bat_label"
184+
num_bats=${#percs[@]}
185+
show_bat_label=$(get_tmux_option "@dracula-show-battery-status" false)
186+
for ((i=0; i<num_bats; i++)); do
187+
if [[ i -gt 0 ]]; then
188+
echo -n "$(get_tmux_option "@dracula-battery-separator" "; ")"
189+
fi
190+
echo -n "${lbls[$i]}"
191+
if $show_bat_label; then
192+
echo -n "$(parse_battery_status "${percs[$i]}" "${stats[$i]}") "
193+
fi
194+
echo -n "${percs[$i]}%"
195+
done
181196
fi
182197
}
183198

scripts/dracula.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ main() {
3838
show_ssh_session_port=$(get_tmux_option "@dracula-show-ssh-session-port" false)
3939
show_libreview=$(get_tmux_option "@dracula-show-libreview" false)
4040
show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true)
41+
left_pad=$(get_tmux_option "@dracula-left-pad" " ")
42+
right_pad=$(get_tmux_option "@dracula-right-pad" " ")
4143

4244
narrow_mode=$(get_tmux_option "@dracula-narrow-mode" false)
4345
if $narrow_mode; then
@@ -278,6 +280,10 @@ main() {
278280
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-mpc-colors" "green dark_gray")
279281
script="#($current_dir/mpc.sh)"
280282

283+
elif [ $plugin = "spr" ]; then
284+
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spr-colors" "green dark_gray")
285+
script="#($current_dir/spr.sh)"
286+
281287
elif [ $plugin = "spotify-tui" ]; then
282288
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray")
283289
script="#($current_dir/spotify-tui.sh)"
@@ -361,18 +367,21 @@ main() {
361367
background_color=${powerbg}
362368
fi
363369

370+
# padding
371+
pad_script="$left_pad$script$right_pad"
372+
364373
if $show_powerline; then
365374
if $show_empty_plugins; then
366-
tmux set-option -ga status-right " #[fg=${!colors[0]},bg=${background_color},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script $right_edge_icon"
375+
tmux set-option -ga status-right " #[fg=${!colors[0]},bg=${background_color},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}]$pad_script$right_edge_icon"
367376
else
368-
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics] ${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script $right_edge_icon}"
377+
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}]$pad_script$right_edge_icon}"
369378
fi
370379
powerbg=${!colors[0]}
371380
else
372381
if $show_empty_plugins; then
373-
tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script "
382+
tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}]$pad_script"
374383
else
375-
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[1]},bg=${!colors[0]}] $script }"
384+
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[1]},bg=${!colors[0]}]$pad_script}"
376385
fi
377386
fi
378387

scripts/mac-player.sh

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,20 @@ function sliceTrack()
159159

160160

161161
function remoteControl() {
162-
toggle_button="$1"
163-
back_button="$2"
164-
next_button="$3"
165-
app_controlled="$4"
162+
local toggle_button="$1"
163+
local back_button="$2"
164+
local next_button="$3"
165+
local app_controlled="$4"
166166

167167
if [[ $app_controlled == "Spotify" ]] || [[ $app_controlled == "Music" ]]; then
168168

169+
if [[ $app_controlled == "Music" ]]; then
170+
back="osascript -e 'tell application \"$app_controlled\" to back track'"
171+
else
172+
back="osascript -e 'tell application \"$app_controlled\" to previous track'"
173+
fi
174+
169175
toggle="osascript -e 'tell application \"$app_controlled\" to playpause'"
170-
back="osascript -e 'tell application \"$app_controlled\" to back track'"
171176
next="osascript -e 'tell application \"$app_controlled\" to play next track'"
172177

173178
tmux unbind-key "$toggle_button"
@@ -177,10 +182,6 @@ function remoteControl() {
177182
tmux bind-key "$toggle_button" run-shell "$toggle"
178183
tmux bind-key "$back_button" run-shell "$back"
179184
tmux bind-key "$next_button" run-shell "$next"
180-
else
181-
tmux unbind-key "$toggle_button"
182-
tmux unbind-key "$back_button"
183-
tmux unbind-key "$next_button"
184185
fi
185186
}
186187

@@ -216,7 +217,7 @@ main() {
216217
MAX_LENGTH=$(get_tmux_option "@dracula-mac-player-length" 25)
217218

218219
# Remote variables
219-
REMOTE_ACCESS=$(get_tmux_option "@dracula-mac-player-remote" false)
220+
REMOTE_ACCESS=$(get_tmux_option "@dracula-mac-player-remote" "false")
220221
REMOTE_APP=$(get_tmux_option "@dracula-mac-player-app" "Spotify")
221222

222223
# Remote Control Buttons Customizations
@@ -230,20 +231,33 @@ main() {
230231

231232
# os checker
232233
if [[ "$OSTYPE" != "darwin"* ]]; then
233-
echo ""
234234
exit 1
235235
fi
236236

237237
# Remote Access
238-
if [[ "$REMOTE_ACCESS" == true ]]; then
238+
if [[ "$REMOTE_ACCESS" == "true" ]]; then
239+
# Remote Control Buttons Customizations
240+
PLAY_PAUSE_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-play-pause" "P")
241+
BACK_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-back" "R")
242+
NEXT_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-next" "N")
243+
239244
remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP"
245+
else
246+
# Clean up when remote is disabled
247+
tmux set -g @dracula-mac-player-remote-play-pause ""
248+
tmux set -g @dracula-mac-player-remote-back ""
249+
tmux set -g @dracula-mac-player-remote-next ""
250+
tmux unbind-key "$PLAY_PAUSE_BUTTON" 2>/dev/null
251+
tmux unbind-key "$BACK_BUTTON" 2>/dev/null
252+
tmux unbind-key "$NEXT_BUTTON" 2>/dev/null
240253
fi
241254

242255
if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then
243-
trackStatus "$PAUSE_ICON" "$PLAY_ICON" >"$cache_file"
256+
local full_track
257+
full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON")
244258

245259
if [ "$SCROLL" = false ]; then
246-
sliceTrack "$(cat $cache_file)" "$MAX_LENGTH" >"$cache_file"
260+
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
247261
fi
248262
fi
249263

0 commit comments

Comments
 (0)