Skip to content

Commit 752b57d

Browse files
Merge pull request #339 from dracula/feature/compact-alt
Feature/compact alt
2 parents 2e176ef + 68f3f7e commit 752b57d

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

docs/CONFIG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Plugins](#Plugins)
1010
- [attached-clients](#attached-clients---up)
1111
- [battery](#battery---up)
12+
- [compact-alt](#compact-alt---up)
1213
- [continuum](#continuum---up)
1314
- [cpu-arch](#cpu-arch---up)
1415
- [cpu-usage](#cpu-usage---up)
@@ -200,6 +201,44 @@ alternatively, if you have no battery and would like a nerdfont icon to indicate
200201
set -g @dracula-no-battery-label ""
201202
```
202203

204+
### compact-alt - [up](#table-of-contents)
205+
This widget allows the user to switch to an alternate list of widgets when the terminal becomes narrow.
206+
Switching only works if the widget is added to `set -g @dracula-plugins "your-plugins-here"`.
207+
208+
to set what widgets should be shown in narrow mode, set the following variable. *make sure to include the compact-alt widget as you won't be able to switch out of narrow mode otherwise.*
209+
210+
```bash
211+
set -g @dracula-narrow-plugins "compact-alt battery network weather"
212+
```
213+
214+
to determine when to switch to narrow mode, set the following variable.
215+
any value below this threshold is considered narrow.
216+
217+
```bash
218+
set -g @dracula-compact-min-width 140
219+
```
220+
221+
the compact-alt widget needs to reload your tmux config to switch from wide to narrow and back.
222+
therefore, you need to make sure to set the right path to your config file.
223+
224+
```bash
225+
set -g @dracula-config-path "$HOME/.config/tmux/tmux.conf"
226+
```
227+
228+
if you want to see your window with and whether narrow mode is active, set the following, which is false per default.
229+
230+
```bash
231+
set -g @dracula-compact-alt-verbose true
232+
```
233+
234+
this widget maintains a global variable informing about whether narrow mode is active.
235+
that variable should never be touched by the user and could potentially be used by other widgets/ plugins.
236+
237+
```bash
238+
# NEVER DO:
239+
set -g @dracula-narrow-mode some-value
240+
```
241+
203242
### continuum - [up](#table-of-contents)
204243

205244
Set the output mode. Options are:

scripts/compact_alt.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
# setting the locale, some users have issues with different locales, this forces the correct one
3+
export LC_ALL=en_US.UTF-8
4+
5+
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
source $current_dir/utils.sh
7+
8+
main()
9+
{
10+
# get options
11+
min_width=$(get_tmux_option "@dracula-compact-min-width" "140")
12+
13+
# get current window with
14+
local window_width
15+
window_width=$(tmux display-message -p "#{window_width}")
16+
17+
# determine whether narrow
18+
if [[ "$window_width" -lt "$min_width" ]]; then
19+
narrow=true
20+
else
21+
narrow=false
22+
fi
23+
24+
# get whether narrow previously
25+
narrow_mode="$(tmux show-option -gqv '@dracula-narrow-mode')"
26+
27+
# if width changed, set global var and reload
28+
if [[ "$narrow" != "$narrow_mode" ]]; then
29+
tmux set -g @dracula-narrow-mode $narrow
30+
tmux source-file "$(get_tmux_option "@dracula-config-path" "$HOME/.config/tmux/tmux.conf")"
31+
fi
32+
33+
# show widget info if verbose
34+
verbose=$(get_tmux_option "@dracula-compact-alt-verbose" false)
35+
if $verbose; then
36+
echo "$window_width - $narrow"
37+
fi
38+
# storing the refresh rate in the variable RATE, default is 5
39+
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
40+
sleep $RATE
41+
}
42+
43+
#run main driver program
44+
main

scripts/dracula.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ main() {
3737
time_format=$(get_tmux_option "@dracula-time-format" "")
3838
show_ssh_session_port=$(get_tmux_option "@dracula-show-ssh-session-port" false)
3939
show_libreview=$(get_tmux_option "@dracula-show-libreview" false)
40-
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather")
4140
show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true)
4241

42+
narrow_mode=$(get_tmux_option "@dracula-narrow-mode" false)
43+
if $narrow_mode; then
44+
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-narrow-plugins" "compact-alt battery network weather")
45+
else
46+
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather")
47+
fi
48+
4349
# Dracula Color Pallette
4450
white="#f8f8f2"
4551
gray="#44475a"
@@ -188,6 +194,11 @@ main() {
188194
script="${script} not found!"
189195
fi
190196

197+
elif [ $plugin = "compact-alt" ]; then
198+
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-compact-alt-colors" "dark_gray white")
199+
tmux set-option -g status-right-length 250
200+
script="#($current_dir/compact_alt.sh)"
201+
191202
elif [ $plugin = "cwd" ]; then
192203
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cwd-colors" "dark_gray white")
193204
tmux set-option -g status-right-length 250

0 commit comments

Comments
 (0)