Skip to content

Commit 16d9cee

Browse files
authored
Merge pull request #1 from m99coder/master
add and sync scripts with Dracula theme
2 parents 3b47354 + 4978537 commit 16d9cee

27 files changed

+1458
-154
lines changed

scripts/attached_clients.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
# configuration
6+
# @monokai-clients-minimum 1
7+
# @monokai-clients-singular client
8+
# @monokai-clients-plural clients
9+
10+
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
source $current_dir/utils.sh
12+
13+
count_clients() {
14+
pane=$(tmux list-panes -F "#{session_name}" | head -n 1)
15+
tmux list-clients -t $pane | wc -l | tr -d ' '
16+
}
17+
18+
main() {
19+
# storing the refresh rate in the variable RATE, default is 5
20+
RATE=$(get_tmux_option "@monokai-refresh-rate" 5)
21+
clients_count=$(count_clients)
22+
clients_minimum=$(get_tmux_option "@monokai-clients-minimum" 1)
23+
if (( $clients_count >= $clients_minimum )); then
24+
if (( $clients_count > 1 )); then
25+
clients_label=$(get_tmux_option "@monokai-clients-plural" "clients")
26+
else
27+
clients_label=$(get_tmux_option "@monokai-clients-singular" "client")
28+
fi
29+
echo "$clients_count $clients_label"
30+
fi
31+
sleep $RATE
32+
}
33+
34+
# run main driver
35+
main

scripts/continuum.sh

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
# configuration
6+
# @monokai-continuum-mode default (countdown|time|alert|interval)
7+
# @monokai-continuum-time-threshold 15
8+
9+
alert_mode="@monokai-continuum-mode"
10+
time_threshold="@monokai-continuum-time-threshold"
11+
warn_threshold=360
12+
first_save="@monokai-continuum-first-save"
13+
14+
# tmux-resurrect and tmux-continuum options
15+
if [ -d "$HOME/.tmux/resurrect" ]; then
16+
default_resurrect_dir="$HOME/.tmux/resurrect"
17+
else
18+
default_resurrect_dir="${XDG_DATA_HOME:-$HOME/.local/share}"/tmux/resurrect
19+
fi
20+
resurrect_dir_option="@resurrect-dir"
21+
last_auto_save_option="@continuum-save-last-timestamp"
22+
auto_save_interval_option="@continuum-save-interval"
23+
auto_save_interval_default="15"
24+
25+
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26+
source $current_dir/utils.sh
27+
28+
current_timestamp() {
29+
echo "$(date +%s)"
30+
}
31+
32+
file_mtime() {
33+
if [ ! -f "$1" ]; then
34+
echo -1
35+
return
36+
fi
37+
case $(uname -s) in
38+
Linux|Darwin)
39+
date -r "$1" +%s
40+
;;
41+
42+
FreeBSD)
43+
stat -f %m "$1"
44+
;;
45+
46+
CYGWIN*|MINGW32*|MSYS*|MINGW*)
47+
# TODO - windows compatability
48+
;;
49+
esac
50+
}
51+
52+
timestamp_date() {
53+
case $(uname -s) in
54+
Linux)
55+
date -d "@$1" "$2"
56+
;;
57+
58+
Darwin|FreeBSD)
59+
date -r "$1" "$2"
60+
;;
61+
62+
CYGWIN*|MINGW32*|MSYS*|MINGW*)
63+
# TODO - windows compatability
64+
;;
65+
esac
66+
}
67+
68+
set_tmux_option() {
69+
local option="$1"
70+
local value="$2"
71+
tmux set-option -gq "$option" "$value"
72+
}
73+
74+
# tmux-resurrect dir
75+
resurrect_dir() {
76+
if [ -z "$_RESURRECT_DIR" ]; then
77+
local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")"
78+
# expands tilde, $HOME and $HOSTNAME if used in @resurrect-dir
79+
echo "$path" | sed "s,\$HOME,$HOME,g; s,\$HOSTNAME,$(hostname),g; s,\~,$HOME,g"
80+
else
81+
echo "$_RESURRECT_DIR"
82+
fi
83+
}
84+
_RESURRECT_DIR="$(resurrect_dir)"
85+
86+
last_resurrect_file() {
87+
echo "$(resurrect_dir)/last"
88+
}
89+
90+
last_saved_timestamp() {
91+
local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "")"
92+
local first_save_timestamp="$(get_tmux_option "$first_save" "")"
93+
# continuum sets the last save timestamp to the current time on first load if auto_save_option is not set
94+
# so we can outrace it and detect that last_uato_save_option is empty and the timestamp is a dummy save
95+
if [ -z "$first_save_timestamp" ]; then
96+
last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=-1
97+
set_tmux_option "$first_save" "$last_saved_timestamp"
98+
elif [ "$first_save_timestamp" != "done" ]; then
99+
last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=-1
100+
if [ "$last_saved_timestamp" -gt "$first_save_timestamp" ]; then
101+
set_tmux_option "$first_save" "done"
102+
else
103+
last_saved_timestamp="$first_save_timestamp"
104+
fi
105+
fi
106+
echo "$last_saved_timestamp"
107+
}
108+
109+
print_status() {
110+
local mode="$(get_tmux_option "$alert_mode" "countdown")"
111+
local info_threshold="$(get_tmux_option "$time_threshold" "15")"
112+
local save_int="$(get_tmux_option "$auto_save_interval_option" "$auto_save_interval_default")"
113+
local interval_seconds="$((save_int * 60))"
114+
local status=""
115+
local last_timestamp="$(last_saved_timestamp)"
116+
local time_delta="$(($(current_timestamp) - last_timestamp))"
117+
local time_delta_minutes="$((time_delta / 60))"
118+
119+
if [[ $save_int -gt 0 ]]; then
120+
if [[ "$time_delta" -gt $((interval_seconds + warn_threshold)) ]]; then
121+
if [[ "$last_timestamp" == -1 ]]; then
122+
status="no save"
123+
else
124+
status="last save: $(timestamp_date "$last_timestamp" '+%F %T')"
125+
fi
126+
if [[ "$mode" == "countdown" ]]; then
127+
# continuum timestamp may be different than file timestamp on first load
128+
local last_continuum_timestamp="$(get_tmux_option "$last_auto_save_option" "")"
129+
time_delta="$(($(current_timestamp) - last_continuum_timestamp))"
130+
time_delta_minutes="$((time_delta / 60))"
131+
132+
status="$status; T$(printf '%+d' "$((time_delta_minutes - save_int))")min"
133+
fi
134+
elif [[ "$time_delta" -le "$info_threshold" ]]; then
135+
status="saved"
136+
else
137+
case "$mode" in
138+
countdown)
139+
status="T$(printf '%+d' "$((time_delta_minutes - save_int))")min";
140+
;;
141+
142+
time)
143+
status="$time_delta_minutes";
144+
;;
145+
146+
alert)
147+
status=""
148+
;;
149+
150+
interval)
151+
status="$save_int"
152+
;;
153+
esac
154+
fi
155+
else
156+
status="off"
157+
fi
158+
159+
echo "$status"
160+
}
161+
print_status

scripts/cpu_info.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ get_percent()
2121
normalize_percent_len $percent
2222
;;
2323

24+
OpenBSD)
25+
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
26+
cpucores=$(sysctl -n hw.ncpuonline)
27+
cpuusage=$(( cpuvalue / cpucores ))
28+
percent="$cpuusage%"
29+
normalize_percent_len $percent
30+
;;
31+
2432
CYGWIN*|MINGW32*|MSYS*|MINGW*)
2533
# TODO - windows compatability
2634
;;
@@ -29,7 +37,7 @@ get_percent()
2937

3038
get_load() {
3139
case $(uname -s) in
32-
Linux | Darwin)
40+
Linux | Darwin | OpenBSD)
3341
loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g')
3442
echo $loadavg
3543
;;
@@ -44,10 +52,10 @@ main() {
4452
# storing the refresh rate in the variable RATE, default is 5
4553
RATE=$(get_tmux_option "@monokai-refresh-rate" 5)
4654
cpu_load=$(get_tmux_option "@monokai-cpu-display-load" false)
55+
cpu_label=$(get_tmux_option "@monokai-cpu-usage-label" "CPU")
4756
if [ "$cpu_load" = true ]; then
48-
echo "$(get_load)"
57+
echo "$cpu_label $(get_load)"
4958
else
50-
cpu_label=$(get_tmux_option "@monokai-cpu-usage-label" "CPU")
5159
cpu_percent=$(get_percent)
5260
echo "$cpu_label $cpu_percent"
5361
fi

scripts/cwd.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
# return current working directory of tmux pane
4+
getPaneDir() {
5+
nextone="false"
6+
ret=""
7+
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); do
8+
[ "$i" == "1" ] && nextone="true" && continue
9+
[ "$i" == "0" ] && nextone="false"
10+
[ "$nextone" == "true" ] && ret+="$i "
11+
done
12+
echo "${ret%?}"
13+
}
14+
15+
main() {
16+
path=$(getPaneDir)
17+
18+
# change '/home/user' to '~'
19+
cwd="${path/"$HOME"/'~'}"
20+
21+
echo "$cwd"
22+
}
23+
24+
#run main driver program
25+
main

0 commit comments

Comments
 (0)