Merge branch 'master' into master

This commit is contained in:
Ethan Edwards 2023-09-25 13:30:27 -04:00 committed by GitHub
commit 59e4fe7dbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1106 additions and 171 deletions

View file

@ -48,7 +48,8 @@ To enable plugins set up the `@dracula-plugins` option in you `.tmux.conf` file,
The order that you define the plugins will be the order on the status bar left to right. The order that you define the plugins will be the order on the status bar left to right.
```bash ```bash
# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, network-ping, weather, time # available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, tmux-ram-usage, network, network-bandwidth, network-ping, attached-clients, network-vpn, weather, time, spotify-tui, kubernetes-context, synchronize-panes
set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" set -g @dracula-plugins "cpu-usage gpu-usage ram-usage"
``` ```
@ -111,6 +112,12 @@ Enable high contrast pane border
set -g @dracula-border-contrast true set -g @dracula-border-contrast true
``` ```
Hide empty plugins
```bash
set -g @dracula-show-empty-plugins false
```
#### cpu-usage options #### cpu-usage options
Customize label Customize label
@ -138,6 +145,8 @@ set -g @dracula-battery-label "Battery"
#### gpu-usage options #### gpu-usage options
Note, currently only the Linux NVIDIA Proprietary drivers are supported. Nouveau and AMD Graphics Cards support are still under development.
Customize label Customize label
```bash ```bash
@ -152,6 +161,26 @@ Customize label
set -g @dracula-ram-usage-label "RAM" set -g @dracula-ram-usage-label "RAM"
``` ```
#### tmux-ram-usage options
Customize label
```bash
set -g @dracula-tmux-ram-usage-label "MEM"
```
#### network-bandwidth
You can configure which network interface you want to view the bandwidth,
Displaying of the interface name, The interval between each bandwidth update.
The most common interfaces name are `eth0` for a wired connection and `wlan0` for a wireless connection.
```bash
set -g @dracula-network-bandwidth eth0
set -g @dracula-network-bandwidth-interval 0
set -g @dracula-network-bandwidth-show-interface true
```
#### network-ping options #### network-ping options
You can configure which server (hostname, IP) you want to ping and at which rate (in seconds). Default is google.com at every 5 seconds. You can configure which server (hostname, IP) you want to ping and at which rate (in seconds). Default is google.com at every 5 seconds.
@ -181,6 +210,12 @@ Enable military time
set -g @dracula-military-time true set -g @dracula-military-time true
``` ```
Set custom time format e.g (2023-01-01 14:00)
```bash
set -g @dracula-time-format "%F %R"
```
See [[this page]](https://man7.org/linux/man-pages/man1/date.1.html) for other format symbols.
#### git options #### git options
Hide details of git changes Hide details of git changes
@ -218,6 +253,37 @@ Show remote tracking branch together with diverge/sync state
set -g @dracula-git-show-remote-status true set -g @dracula-git-show-remote-status true
``` ```
#### hg options
Hide details of hg changes
```bash
set -g @dracula-hg-disable-status true
```
Set symbol to use for when branch is up to date with HEAD
```bash
#default is ✓.Avoid using non unicode characters that bash uses like $, * and !
set -g @dracula-hg-show-current-symbol ✓
```
Set symbol to use for when branch diverges from HEAD
```bash
#default is unicode !.Avoid bash special characters
set -g @dracula-hg-show-diff-symbol !
```
Set symbol or message to use when the current pane has no hg repo
```bash
#default is unicode no message
set -g @dracula-hg-no-repo-message ""
```
Hide untracked files from being displayed as local changes
```bash
#default is false
set -g @dracula-hg-no-untracked-files false
```
#### weather options #### weather options
Switch from default fahrenheit to celsius Switch from default fahrenheit to celsius
@ -237,3 +303,68 @@ Hide your location
```bash ```bash
set -g @dracula-show-location false set -g @dracula-show-location false
``` ```
#### synchronize-panes options
Customize label
```bash
set -g @dracula-synchronize-panes-label "Sync"
```
#### attached-clients options
Set the minimum number of clients to show (otherwise, show nothing)
```bash
set -g @dracula-clients-minimum 1
```
Set the label when there is one client, or more than one client
```bash
set -g @dracula-clients-singular client
set -g @dracula-clients-plural clients
```
#### Kubernetes options
Add prefix label before the context
```bash
set -g @dracula-kubernetes-context-label "Some Label"
```
Hide user from the context string
```
set -g @dracula-kubernetes-hide-user true
```
Hide ARN (show only cluster name) - Available for EKS only (only available for cluster names that are ARNs)
```
set -g @dracula-kubernetes-eks-hide-arn true
```
Extract the account as a prefix to the cluster name - Available for EKS only (only available for cluster names that are ARNs)
```
set -g @dracula-kubernetes-eks-extract-account true
#### continuum options
Set the output mode. Options are:
- **countdown**: Show a T- countdown to the next save (default)
- **time**: Show the time since the last save
- **alert**: Hide output if no save has been performed recently
- **interval**: Show the continuum save interval
```bash
set -g @dracula-continuum-mode countdown
```
Show if the last save was performed less than 60 seconds ago (default threshold is 15 seconds)
```bash
set -g @dracula-continuum-time-threshold 60
```

View file

@ -22,15 +22,21 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
- Battery percentage and AC power connection status - Battery percentage and AC power connection status
- Refresh rate control - Refresh rate control
- CPU usage (percentage or load average) - CPU usage (percentage or load average)
- RAM usage - RAM usage (system and/or tmux server)
- GPU usage - GPU usage
- Custom status texts from external scripts
- GPU VRAM usage
- GPU power draw
- Color code based on if prefix is active or not - Color code based on if prefix is active or not
- List of windows with current window highlighted - List of windows with current window highlighted
- When prefix is enabled smiley face turns from green to yellow - When prefix is enabled smiley face turns from green to yellow
- When charging, 'AC' is displayed - When charging, 'AC' is displayed
- If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature - If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature
- Info if the Panes are synchronized
- Spotify playback (needs the tool spotify-tui installed) - Spotify playback (needs the tool spotify-tui installed)
- Current kubernetes context - Current kubernetes context
- Countdown to tmux-continuum save
- Current working directory of tmux pane
## Compatibility ## Compatibility

35
scripts/attached_clients.sh Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
# configuration
# @dracula-clients-minimum 1
# @dracula-clients-singular client
# @dracula-clients-plural clients
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh
count_clients() {
pane=$(tmux list-panes -F "#{session_name}" | head -n 1)
tmux list-clients -t $pane | wc -l | tr -d ' '
}
main() {
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
clients_count=$(count_clients)
clients_minimum=$(get_tmux_option "@dracula-clients-minimum" 1)
if (( $clients_count >= $clients_minimum )); then
if (( $clients_count > 1 )); then
clients_label=$(get_tmux_option "@dracula-clients-plural" "clients")
else
clients_label=$(get_tmux_option "@dracula-clients-singular" "client")
fi
echo "$clients_count $clients_label"
fi
sleep $RATE
}
# run main driver
main

161
scripts/continuum.sh Executable file
View file

@ -0,0 +1,161 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
# configuration
# @dracula-continuum-mode default (countdown|time|alert|interval)
# @dracula-continuum-time-threshold 15
alert_mode="@dracula-continuum-mode"
time_threshold="@dracula-continuum-time-threshold"
warn_threshold=360
first_save="@dracula-continuum-first-save"
# tmux-resurrect and tmux-continuum options
if [ -d "$HOME/.tmux/resurrect" ]; then
default_resurrect_dir="$HOME/.tmux/resurrect"
else
default_resurrect_dir="${XDG_DATA_HOME:-$HOME/.local/share}"/tmux/resurrect
fi
resurrect_dir_option="@resurrect-dir"
last_auto_save_option="@continuum-save-last-timestamp"
auto_save_interval_option="@continuum-save-interval"
auto_save_interval_default="15"
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh
current_timestamp() {
echo "$(date +%s)"
}
file_mtime() {
if [ ! -f "$1" ]; then
echo -1
return
fi
case $(uname -s) in
Linux|Darwin)
date -r "$1" +%s
;;
FreeBSD)
stat -f %m "$1"
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO - windows compatability
;;
esac
}
timestamp_date() {
case $(uname -s) in
Linux)
date -d "@$1" "$2"
;;
Darwin|FreeBSD)
date -r "$1" "$2"
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO - windows compatability
;;
esac
}
set_tmux_option() {
local option="$1"
local value="$2"
tmux set-option -gq "$option" "$value"
}
# tmux-resurrect dir
resurrect_dir() {
if [ -z "$_RESURRECT_DIR" ]; then
local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")"
# expands tilde, $HOME and $HOSTNAME if used in @resurrect-dir
echo "$path" | sed "s,\$HOME,$HOME,g; s,\$HOSTNAME,$(hostname),g; s,\~,$HOME,g"
else
echo "$_RESURRECT_DIR"
fi
}
_RESURRECT_DIR="$(resurrect_dir)"
last_resurrect_file() {
echo "$(resurrect_dir)/last"
}
last_saved_timestamp() {
local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "")"
local first_save_timestamp="$(get_tmux_option "$first_save" "")"
# continuum sets the last save timestamp to the current time on first load if auto_save_option is not set
# so we can outrace it and detect that last_uato_save_option is empty and the timestamp is a dummy save
if [ -z "$first_save_timestamp" ]; then
last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=-1
set_tmux_option "$first_save" "$last_saved_timestamp"
elif [ "$first_save_timestamp" != "done" ]; then
last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=-1
if [ "$last_saved_timestamp" -gt "$first_save_timestamp" ]; then
set_tmux_option "$first_save" "done"
else
last_saved_timestamp="$first_save_timestamp"
fi
fi
echo "$last_saved_timestamp"
}
print_status() {
local mode="$(get_tmux_option "$alert_mode" "countdown")"
local info_threshold="$(get_tmux_option "$time_threshold" "15")"
local save_int="$(get_tmux_option "$auto_save_interval_option" "$auto_save_interval_default")"
local interval_seconds="$((save_int * 60))"
local status=""
local last_timestamp="$(last_saved_timestamp)"
local time_delta="$(($(current_timestamp) - last_timestamp))"
local time_delta_minutes="$((time_delta / 60))"
if [[ $save_int -gt 0 ]]; then
if [[ "$time_delta" -gt $((interval_seconds + warn_threshold)) ]]; then
if [[ "$last_timestamp" == -1 ]]; then
status="no save"
else
status="last save: $(timestamp_date "$last_timestamp" '+%F %T')"
fi
if [[ "$mode" == "countdown" ]]; then
# continuum timestamp may be different than file timestamp on first load
local last_continuum_timestamp="$(get_tmux_option "$last_auto_save_option" "")"
time_delta="$(($(current_timestamp) - last_continuum_timestamp))"
time_delta_minutes="$((time_delta / 60))"
status="$status; T$(printf '%+d' "$((time_delta_minutes - save_int))")min"
fi
elif [[ "$time_delta" -le "$info_threshold" ]]; then
status="saved"
else
case "$mode" in
countdown)
status="T$(printf '%+d' "$((time_delta_minutes - save_int))")min";
;;
time)
status="$time_delta_minutes";
;;
alert)
status=""
;;
interval)
status="$save_int"
;;
esac
fi
else
status="off"
fi
echo "$status"
}
print_status

View file

@ -52,10 +52,10 @@ main() {
# storing the refresh rate in the variable RATE, default is 5 # storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5) RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
cpu_load=$(get_tmux_option "@dracula-cpu-display-load" false) cpu_load=$(get_tmux_option "@dracula-cpu-display-load" false)
if [ "$cpu_load" = true ]; then
echo "$(get_load)"
else
cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU") cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU")
if [ "$cpu_load" = true ]; then
echo "$cpu_label $(get_load)"
else
cpu_percent=$(get_percent) cpu_percent=$(get_percent)
echo "$cpu_label $cpu_percent" echo "$cpu_label $cpu_percent"
fi fi

25
scripts/cwd.sh Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# return current working directory of tmux pane
getPaneDir() {
nextone="false"
ret=""
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); do
[ "$i" == "1" ] && nextone="true" && continue
[ "$i" == "0" ] && nextone="false"
[ "$nextone" == "true" ] && ret+="$i "
done
echo "${ret%?}"
}
main() {
path=$(getPaneDir)
# change '/home/user' to '~'
cwd="${path/"$HOME"/'~'}"
echo "$cwd"
}
#run main driver program
main

View file

@ -7,9 +7,12 @@ source $current_dir/utils.sh
main() main()
{ {
datafile=/tmp/.dracula-tmux-data
# set configuration option variables # set configuration option variables
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
eks_hide_arn=$(get_tmux_option "@dracula-kubernetes-eks-hide-arn" false)
eks_extract_account=$(get_tmux_option "@dracula-kubernetes-eks-extract-account" false)
hide_kubernetes_user=$(get_tmux_option "@dracula-kubernetes-hide-user" false)
terraform_label=$(get_tmux_option "@dracula-terraform-label" "")
show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true)
show_location=$(get_tmux_option "@dracula-show-location" true) show_location=$(get_tmux_option "@dracula-show-location" true)
fixed_location=$(get_tmux_option "@dracula-fixed-location") fixed_location=$(get_tmux_option "@dracula-fixed-location")
@ -25,8 +28,10 @@ main()
show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false)
show_day_month=$(get_tmux_option "@dracula-day-month" false) show_day_month=$(get_tmux_option "@dracula-day-month" false)
show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5)
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "") show_synchronize_panes_label=$(get_tmux_option "@dracula-synchronize-panes-label" "Sync")
time_format=$(get_tmux_option "@dracula-time-format" "")
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather")
show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true)
# Dracula Color Pallette # Dracula Color Pallette
white='#f8f8f2' white='#f8f8f2'
@ -66,11 +71,6 @@ main()
left_sep="$show_left_sep" left_sep="$show_left_sep"
fi fi
# start weather script in background
if [[ "${plugins[@]}" =~ "weather" ]]; then
$current_dir/sleep_weather.sh $show_fahrenheit $show_location $fixed_location &
fi
# Set timezone unless hidden by configuration # Set timezone unless hidden by configuration
if [[ -z "$timezone" ]]; then if [[ -z "$timezone" ]]; then
case $show_timezone in case $show_timezone in
@ -131,93 +131,141 @@ main()
for plugin in "${plugins[@]}"; do for plugin in "${plugins[@]}"; do
if [ $plugin = "fossil" ]; then if case $plugin in custom:*) true;; *) false;; esac; then
script=${plugin#"custom:"}
if [[ -x "${current_dir}/${script}" ]]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-custom-plugin-colors" "cyan dark_gray")
script="#($current_dir/${script})"
else
colors[0]="red"
colors[1]="dark_gray"
script="${script} not found!"
fi
elif [ $plugin = "cwd" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cwd-colors" "dark_gray white")
tmux set-option -g status-right-length 250
script="#($current_dir/cwd.sh)"
elif [ $plugin = "fossil" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-fossil-colors" "green dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-fossil-colors" "green dark_gray")
tmux set-option -g status-right-length 250 tmux set-option -g status-right-length 250
script="#($current_dir/fossil.sh)" script="#($current_dir/fossil.sh)"
fi
if [ $plugin = "git" ]; then elif [ $plugin = "git" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")
tmux set-option -g status-right-length 250 tmux set-option -g status-right-length 250
script="#($current_dir/git.sh)" script="#($current_dir/git.sh)"
fi
if [ $plugin = "battery" ]; then elif [ $plugin = "hg" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-hg-colors" "green dark_gray")
tmux set-option -g status-right-length 250
script="#($current_dir/hg.sh)"
elif [ $plugin = "battery" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-battery-colors" "pink dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-battery-colors" "pink dark_gray")
script="#($current_dir/battery.sh)" script="#($current_dir/battery.sh)"
fi
if [ $plugin = "gpu-usage" ]; then elif [ $plugin = "gpu-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-usage-colors" "pink dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-usage-colors" "pink dark_gray")
script="#($current_dir/gpu_usage.sh)" script="#($current_dir/gpu_usage.sh)"
fi
if [ $plugin = "cpu-usage" ]; then elif [ $plugin = "gpu-ram-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-ram-usage-colors" "cyan dark_gray")
script="#($current_dir/gpu_ram_info.sh)"
elif [ $plugin = "gpu-power-draw" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-power-draw-colors" "green dark_gray")
script="#($current_dir/gpu_power.sh)"
elif [ $plugin = "cpu-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cpu-usage-colors" "orange dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cpu-usage-colors" "orange dark_gray")
script="#($current_dir/cpu_info.sh)" script="#($current_dir/cpu_info.sh)"
fi
if [ $plugin = "ram-usage" ]; then elif [ $plugin = "ram-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ram-usage-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ram-usage-colors" "cyan dark_gray")
script="#($current_dir/ram_info.sh)" script="#($current_dir/ram_info.sh)"
fi
if [ $plugin = "network" ]; then elif [ $plugin = "tmux-ram-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-tmux-ram-usage-colors" "cyan dark_gray")
script="#($current_dir/tmux_ram_info.sh)"
elif [ $plugin = "network" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-colors" "cyan dark_gray")
script="#($current_dir/network.sh)" script="#($current_dir/network.sh)"
fi
if [ $plugin = "network-bandwidth" ]; then elif [ $plugin = "network-bandwidth" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-bandwidth-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-bandwidth-colors" "cyan dark_gray")
tmux set-option -g status-right-length 250 tmux set-option -g status-right-length 250
script="#($current_dir/network_bandwidth.sh)" script="#($current_dir/network_bandwidth.sh)"
fi
if [ $plugin = "network-ping" ]; then elif [ $plugin = "network-ping" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray")
script="#($current_dir/network_ping.sh)" script="#($current_dir/network_ping.sh)"
fi
if [ $plugin = "spotify-tui" ]; then elif [ $plugin = "network-vpn" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-vpn-colors" "cyan dark_gray")
script="#($current_dir/network_vpn.sh)"
elif [ $plugin = "attached-clients" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-attached-clients-colors" "cyan dark_gray")
script="#($current_dir/attached_clients.sh)"
elif [ $plugin = "spotify-tui" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray") IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray")
script="#($current_dir/spotify-tui.sh)" script="#($current_dir/spotify-tui.sh)"
fi
if [ $plugin = "kubernetes-context" ]; then elif [ $plugin = "kubernetes-context" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray")
script="#($current_dir/kubernetes_context.sh $show_kubernetes_context_label)" script="#($current_dir/kubernetes_context.sh $eks_hide_arn $eks_extract_account $hide_kubernetes_user $show_kubernetes_context_label)"
fi
if [ $plugin = "weather" ]; then elif [ $plugin = "terraform" ]; then
# wait unit $datafile exists just to avoid errors IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-terraform-colors" "light_purple dark_gray")
# this should almost never need to wait unless something unexpected occurs script="#($current_dir/terraform.sh $terraform_label)"
while [ ! -f $datafile ]; do
sleep 0.01
done
elif [ $plugin = "continuum" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-continuum-colors" "cyan dark_gray")
script="#($current_dir/continuum.sh)"
elif [ $plugin = "weather" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray")
script="#(cat $datafile)" script="#($current_dir/weather_wrapper.sh $show_fahrenheit $show_location $fixed_location)"
fi
if [ $plugin = "time" ]; then elif [ $plugin = "time" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white")
if $show_day_month && $show_military ; then # military time and dd/mm if [ -n "$time_format" ]; then
script="#(TZ=${timezone} date +'%%a %%d/%%m %%R') ${timezone} " script=${time_format}
elif $show_military; then # only military time
script="#(TZ=${timezone} date +'%%a %%m/%%d %%R') ${timezone} "
elif $show_day_month; then # only dd/mm
script="#(TZ=${timezone} date +'%%a %%d/%%m %%I:%%M %%p') ${timezone} "
else else
script="#(TZ=${timezone} date +'%%a %%m/%%d %%I:%%M %%p') ${timezone} " if $show_day_month && $show_military ; then # military time and dd/mm
script="%a %d/%m %R ${timezone} "
elif $show_military; then # only military time
script="%a %m/%d %R ${timezone} "
elif $show_day_month; then # only dd/mm
script="%a %d/%m %I:%M %p ${timezone} "
else
script="%a %m/%d %I:%M %p ${timezone} "
fi fi
fi fi
elif [ $plugin = "synchronize-panes" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-synchronize-panes-colors" "cyan dark_gray")
script="#($current_dir/synchronize_panes.sh $show_synchronize_panes_label)"
else
continue
fi
if $show_powerline; then if $show_powerline; then
if $show_empty_plugins; then
tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script "
else
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script }"
fi
powerbg=${!colors[0]} powerbg=${!colors[0]}
else else
if $show_empty_plugins; then
tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script " tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script "
else
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[1]},bg=${!colors[0]}] $script }"
fi
fi fi
done done

49
scripts/gpu_power.sh Executable file
View file

@ -0,0 +1,49 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
get_platform()
{
case $(uname -s) in
Linux)
gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}')
echo $gpu
;;
Darwin)
# TODO - Darwin/Mac compatability
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO - windows compatability
;;
esac
}
get_gpu()
{
gpu=$(get_platform)
if [[ "$gpu" == NVIDIA ]]; then
usage=$(nvidia-smi --query-gpu=power.draw,power.limit --format=csv,noheader,nounits | awk '{ draw += $0; max +=$2 } END { printf("%dW/%dW\n", draw, max) }')
else
usage='unknown'
fi
normalize_percent_len $usage
}
main()
{
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
gpu_label=$(get_tmux_option "@dracula-gpu-usage-label" "GPU")
gpu_usage=$(get_gpu)
echo "$gpu_label $gpu_usage"
sleep $RATE
}
# run the main driver
main

48
scripts/gpu_ram_info.sh Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
get_platform()
{
case $(uname -s) in
Linux)
gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}')
echo $gpu
;;
Darwin)
# TODO - Darwin/Mac compatability
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO - windows compatability
;;
esac
}
get_gpu()
{
gpu=$(get_platform)
if [[ "$gpu" == NVIDIA ]]; then
usage=$(nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader,nounits | awk '{ used += $0; total +=$2 } END { printf("%dGB/%dGB\n", used / 1024, total / 1024) }')
else
usage='unknown'
fi
normalize_percent_len $usage
}
main()
{
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
gpu_label=$(get_tmux_option "@dracula-gpu-usage-label" "VRAM")
gpu_usage=$(get_gpu)
echo "$gpu_label $gpu_usage"
sleep $RATE
}
# run the main driver
main

View file

@ -27,7 +27,7 @@ get_gpu()
{ {
gpu=$(get_platform) gpu=$(get_platform)
if [[ "$gpu" == NVIDIA ]]; then if [[ "$gpu" == NVIDIA ]]; then
usage=$(nvidia-smi | grep '%' | awk '{ sum += $13 } END { printf("%d%%\n", sum / NR) }') usage=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits | awk '{ sum += $0 } END { printf("%d%%\n", sum / NR) }')
else else
usage='unknown' usage='unknown'
fi fi

163
scripts/hg.sh Executable file
View file

@ -0,0 +1,163 @@
#!/usr/bin/env bash
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@dracula-hg-disable-status" "false")
IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-hg-show-current-symbol" "✓")
IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-hg-show-diff-symbol" "!")
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-hg-no-repo-message" "")
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-hg-no-untracked-files" "false")
# Get added, modified, and removed files from hg status
getChanges()
{
declare -i added=0;
declare -i deleted=0;
declare -i modified=0;
declare -i removed=0;
declare -i untracked=0;
for i in $(hg -R $path status -admru)
do
case $i in
'A')
added+=1
;;
'!')
deleted+=1
;;
'M')
modified+=1
;;
'R')
removed+=1
;;
'?')
untracked+=1
;;
esac
done
output=""
[ $added -gt 0 ] && output+="${added}A"
[ $modified -gt 0 ] && output+=" ${modified}M"
[ $deleted -gt 0 ] && output+=" ${deleted}D"
[ $removed -gt 0 ] && output+=" ${removed}R"
[ $no_untracked_files == "false" -a $untracked -gt 0 ] && output+=" ${untracked}?"
echo $output
}
# getting the #{pane_current_path} from dracula.sh is no longer possible
getPaneDir()
{
nextone="false"
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}");
do
if [ "$nextone" == "true" ]; then
echo $i
return
fi
if [ "$i" == "1" ]; then
nextone="true"
fi
done
}
# check if the current or diff symbol is empty to remove ugly padding
checkEmptySymbol()
{
symbol=$1
if [ "$symbol" == "" ]; then
echo "true"
else
echo "false"
fi
}
# check to see if the current repo is not up to date with HEAD
checkForChanges()
{
[ $no_untracked_files == "false" ] && no_untracked="-u" || no_untracked=""
if [ "$(checkForHgDir)" == "true" ]; then
if [ "$(hg -R $path status -admr $no_untracked)" != "" ]; then
echo "true"
else
echo "false"
fi
else
echo "false"
fi
}
# check if a hg repo exists in the directory
checkForHgDir()
{
if [ "$(hg -R $path branch)" != "" ]; then
echo "true"
else
echo "false"
fi
}
# return branch name if there is one
getBranch()
{
if [ $(checkForHgDir) == "true" ]; then
echo $(hg -R $path branch)
else
echo $no_repo_message
fi
}
# return the final message for the status bar
getMessage()
{
if [ $(checkForHgDir) == "true" ]; then
branch="$(getBranch)"
output=""
if [ $(checkForChanges) == "true" ]; then
changes="$(getChanges)"
if [ "${hide_status}" == "false" ]; then
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "${changes} $branch")
else
output=$(echo "$diff_symbol ${changes} $branch")
fi
else
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "$branch")
else
output=$(echo "$diff_symbol $branch")
fi
fi
else
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
output=$(echo "$branch")
else
output=$(echo "$current_symbol $branch")
fi
fi
echo "$output"
else
echo $no_repo_message
fi
}
main()
{
path=$(getPaneDir)
getMessage
}
#run main driver program
main

View file

@ -2,7 +2,10 @@
# setting the locale, some users have issues with different locales, this forces the correct one # setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8 export LC_ALL=en_US.UTF-8
label=$1 hide_arn_from_cluster=$1
extract_account=$2
hide_user=$3
label=$4
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh source $current_dir/utils.sh
@ -12,11 +15,30 @@ current_user=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.na
current_cluster=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.cluster}'; echo) current_cluster=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.cluster}'; echo)
current_namespace=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.namespace}'; echo) current_namespace=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.namespace}'; echo)
current_account_id=""
if [[ "$current_cluster" =~ ^arn:aws:eks:[a-z0-9\-]*:[0-9]*:cluster/[a-z0-9\-]*$ ]]; then
if [ "$extract_account" = "true" ]; then
current_account_id=$(echo "$current_cluster" | cut -d':' -f5)
fi
if [ "$hide_arn_from_cluster" = "true" ]; then
current_cluster=${current_cluster##*/}
fi
fi
if [ "$hide_user" = "true" ]; then
current_user=""
fi
main() main()
{ {
# storing the refresh rate in the variable RATE, default is 5 # storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5) RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
OUTPUT_STRING="" OUTPUT_STRING=""
if [ ! -z "$current_account_id" ]
then
OUTPUT_STRING="${current_account_id}/"
fi
if [ ! -z "$current_user" ] if [ ! -z "$current_user" ]
then then
OUTPUT_STRING="${current_user}@" OUTPUT_STRING="${current_user}@"

View file

@ -1,51 +1,103 @@
#!/usr/bin/env bash #!/usr/bin/env bash
INTERVAL="1" # update interval in seconds # INTERVAL is equal to 1s because we want to express the bandwidth in sec
readonly INTERVAL=1
network_name=$(tmux show-option -gqv "@dracula-network-bandwidth") # UPLOAD and DOWNLOAD index
readonly UPLOAD=0
readonly DOWNLOAD=1
# SIZE index are the multiple of the unit byte and value the internationally recommended unit symbol in sec
readonly SIZE=(
[1]='B/s'
[1024]='kB/s'
[1048576]='MB/s'
[1073741824]='GB/s'
)
# interface_get try to automaticaly get the used interface if network_name is empty
interface_get() {
name="$(tmux show-option -gqv "@dracula-network-bandwidth")"
if [[ -z $name ]]; then
case "$(uname -s)" in
Linux)
if type ip >/dev/null; then
name="$(ip -o route get 192.168.0.0 | awk '{print $5}')"
fi
;;
esac
fi
echo "$name"
}
# interface_bytes give interface name and signal tx/rx return Bytes
interface_bytes() {
cat "/sys/class/net/$1/statistics/$2_bytes"
}
# get_bandwidth return the number of bytes exchanged for tx and rx
get_bandwidth() {
upload="$(interface_bytes "$1" "tx")"
download="$(interface_bytes "$1" "rx")"
#wait the interval for Wait for interval to calculate the difference
sleep "$INTERVAL"
upload="$(bc <<<"$(interface_bytes "$1" "tx") - $upload")"
download="$(bc <<<"$(interface_bytes "$1" "rx") - $download")"
#set to 0 by default useful for non-existent interface
echo "${upload:-0} ${download:-0}"
}
# bandwidth_to_unit convert bytes into its highest unit and add unit symbol in sec
bandwidth_to_unit() {
local size=1
for i in "${!SIZE[@]}"; do
if (($1 < i)); then
break
fi
size="$i"
done
local result="0.00"
if (($1 != 0)); then
result="$(bc <<<"scale=2; $1 / $size")"
fi
echo "$result ${SIZE[$size]}"
}
main() { main() {
while true counter=0
do bandwidth=()
output_download=""
output_upload=""
output_download_unit=""
output_upload_unit=""
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes) network_name=""
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes) show_interface="$(tmux show-option -gqv "@dracula-network-bandwidth-show-interface")"
interval_update="$(tmux show-option -gqv "@dracula-network-bandwidth-interval")"
sleep $INTERVAL if [[ -z $interval_update ]]; then
interval_update=0
final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
total_download_bps=$(expr $final_download - $initial_download)
total_upload_bps=$(expr $final_upload - $initial_upload)
if [ $total_download_bps -gt 1073741824 ]; then
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
output_download_unit="gB/s"
elif [ $total_download_bps -gt 1048576 ]; then
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
output_download_unit="mB/s"
else
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/$2}')
output_download_unit="kB/s"
fi fi
if [ $total_upload_bps -gt 1073741824 ]; then while true; do
output_upload=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}') if ((counter == 0)); then
output_upload_unit="gB/s" counter=60
elif [ $total_upload_bps -gt 1048576 ]; then network_name="$(interface_get)"
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
output_upload_unit="mB/s"
else
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/$2}')
output_upload_unit="kB/s"
fi fi
echo "$output_download $output_download_unit • ↑ $output_upload $output_upload_unit" IFS=" " read -ra bandwidth <<<"$(get_bandwidth "$network_name")"
if [[ $show_interface == "true" ]]; then echo -n "[$network_name] "; fi
echo "$(bandwidth_to_unit "${bandwidth[$DOWNLOAD]}") • ↑ $(bandwidth_to_unit "${bandwidth[$UPLOAD]}")"
((counter = counter - 1))
sleep "$interval_update"
done done
} }
#run main driver
main main

0
scripts/network_ping.sh Normal file → Executable file
View file

36
scripts/network_vpn.sh Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh
vpn_function() {
case $(uname -s) in
Linux)
# TODO
;;
Darwin)
vpn=$(scutil --nc list | grep Connected)
if [ -z $vpn ]; then
echo ""
else
echo "VPN"
fi
;;
CYGWIN* | MINGW32* | MSYS* | MINGW*)
# TODO - windows compatability
;;
esac
}
main() {
echo $(vpn_function)
}
# run main driver
main

View file

@ -5,35 +5,26 @@ export LC_ALL=en_US.UTF-8
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh source $current_dir/utils.sh
get_percent() get_ratio()
{ {
case $(uname -s) in case $(uname -s) in
Linux) Linux)
total_mem_gb=$(free -g | awk '/^Mem/ {print $2}') usage="$(free -h | awk 'NR==2 {print $3}')"
used_mem=$(free -g | awk '/^Mem/ {print $3}') total="$(free -h | awk 'NR==2 {print $2}')"
total_mem=$(free -h | awk '/^Mem/ {print $2}') formated="${usage}/${total}"
if (( $total_mem_gb == 0)); then
memory_usage=$(free -m | awk '/^Mem/ {print $3}') echo "${formated//i/B}"
total_mem_mb=$(free -m | awk '/^Mem/ {print $2}')
echo $memory_usage\M\B/$total_mem_mb\M\B
elif (( $used_mem == 0 )); then
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
echo $memory_usage\M\B/$total_mem_gb\G\B
else
memory_usage=$(free -g | awk '/^Mem/ {print $3}')
echo $memory_usage\G\B/$total_mem_gb\G\B
fi
;; ;;
Darwin) Darwin)
# Get used memory blocks with vm_stat, multiply by page size to get size in bytes, then convert to MiB # Get used memory blocks with vm_stat, multiply by page size to get size in bytes, then convert to MiB
used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk -v pagesize=$(pagesize) '{printf "%d\n", ($1+$2) * pagesize / 1048576}') used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk -v pagesize=$(pagesize) '{printf "%d\n", ($1+$2) * pagesize / 1048576}')
total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}')
if (( $used_mem < 1024 )); then if ((used_mem < 1024 )); then
echo $used_mem\M\B/$total_mem echo "${used_mem}MB/$total_mem"
else else
memory=$(($used_mem/1024)) memory=$((used_mem/1024))
echo $memory\G\B/$total_mem echo "${memory}GB/$total_mem"
fi fi
;; ;;
@ -48,11 +39,11 @@ get_percent()
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024)) total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
used_mem=$((total_mem - free_mem)) used_mem=$((total_mem - free_mem))
echo $used_mem echo $used_mem
if (( $used_mem < 1024 )); then if ((used_mem < 1024 )); then
echo $used_mem\M\B/$total_mem echo "${used_mem}MB/$total_mem"
else else
memory=$(($used_mem/1024)) memory=$((used_mem/1024))
echo $memory\G\B/$total_mem echo "${memory}GB/$total_mem"
fi fi
;; ;;
@ -85,12 +76,9 @@ $(vmstat -s | grep "pages zeroed$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
main() main()
{ {
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
ram_label=$(get_tmux_option "@dracula-ram-usage-label" "RAM") ram_label=$(get_tmux_option "@dracula-ram-usage-label" "RAM")
ram_percent=$(get_percent) ram_ratio=$(get_ratio)
echo "$ram_label $ram_percent" echo "$ram_label $ram_ratio"
sleep $RATE
} }
#run main driver #run main driver

View file

@ -1,48 +0,0 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
#wrapper script for running weather on interval
fahrenheit=$1
location=$2
fixedlocation=$3
LOCKFILE=/tmp/.dracula-tmux-weather.lock
DATAFILE=/tmp/.dracula-tmux-data
ensure_single_process()
{
# check for another running instance of this script and terminate it if found
[ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)"
echo $$ > $LOCKFILE
}
main()
{
ensure_single_process
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ ! -f $DATAFILE ]; then
printf "Loading..." > $DATAFILE
fi
$current_dir/weather.sh > $DATAFILE
while tmux has-session &> /dev/null
do
$current_dir/weather.sh $fahrenheit $location $fixedlocation > $DATAFILE
if tmux has-session &> /dev/null
then
sleep 1200
else
break
fi
done
rm $LOCKFILE
}
#run main driver function
main

View file

@ -15,7 +15,8 @@ main()
exit 1 exit 1
fi fi
spotify_playback=$(spt playback) FORMAT=$(get_tmux_option "@dracula-spotify-tui-format" "%f %s %t - %a")
spotify_playback=$(spt playback -f "${FORMAT}")
echo ${spotify_playback} echo ${spotify_playback}
} }

26
scripts/synchronize_panes.sh Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
label=$1
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
get_synchronize_panes_status() {
current_synchronize_panes_status=$(get_tmux_window_option "synchronize-panes" "off")
echo $current_synchronize_panes_status
}
main()
{
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
synchronize_panes_label=$label
synchronize_panes_status=$(get_synchronize_panes_status)
echo "$synchronize_panes_label $synchronize_panes_status"
sleep $RATE
}
# run main driver
main

30
scripts/terraform.sh Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
label=$1
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
main() {
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
OUTPUT_STRING="N/A"
terraform_dir="$(tmux display-message -p '#{pane_current_path}')/.terraform"
if [ -d $terraform_dir ]; then
current_workspace=$(terraform workspace show 2>/dev/null)
OUTPUT_STRING="${current_workspace}"
fi
if [ "$label" = "" ]
then
echo "⚙️ ${OUTPUT_STRING}"
else
echo "⚙️ ${label} ${OUTPUT_STRING}"
fi
sleep $RATE
}
# run the main driver
main

120
scripts/tmux_ram_info.sh Executable file
View file

@ -0,0 +1,120 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$current_dir/utils.sh"
get_cpids_linux() {
local ppid="$1"
local cpids
local cpid
echo "$ppid"
cpids="$(pgrep -P "$ppid")"
for cpid in $cpids; do
get_cpids_linux "$cpid"
done
}
get_cpids_unix() {
local ppid="$1"
local cpids
local cpid
echo "$ppid"
cpids="$(pgrep -aP "$ppid")"
for cpid in $cpids; do
get_cpids_unix "$cpid"
done
}
kb_to_mb() {
if [ $# == 0 ]; then
read -r num
else
num="$1"
fi
bc <<< "scale=3;$num/1024"
}
kb_to_gb() {
if [ $# == 0 ]; then
read -r num
else
num="$1"
fi
bc <<< "scale=6;$num/1048576"
}
round() {
if [ $# == 1 ]; then
read -r num
scale="$1"
elif [ $# == 2 ]; then
num="$1"
scale="$2"
fi
printf "%.${scale}f" "${num}"
}
get_tmux_ram_usage()
{
local pid
local pids
local total_mem_kb=0
local total_mem_mb=0
local total_mem_gb=0
pid="$(tmux display-message -pF '#{pid}')"
case $(uname -s) in
Linux)
if command -v pstree > /dev/null; then
pids="$(pstree -p "$pid" | tr -d '\n' | sed -rn -e 's/[^()]*\(([0-9]+)\)[^()]*/\1,/g' -e 's/,$//p')"
else
pids="$(get_cpids_linux "$pid" | tr '\n' ',')"
fi
total_mem_kb="$(ps -o rss= -p "$pids" | paste -sd+ | bc)"
;;
Darwin)
if command -v pstree > /dev/null; then
pids="$(pstree "$pid" | sed -En 's/[^0-9]+([0-9]+) .*/\1/p' | tr '\n' ',')"
else
pids="$(get_cpids_unix "$pid" | tr '\n' ',')"
fi
total_mem_kb="$(ps -o rss= -p "$pids" | paste -sd+ - | bc)"
;;
FreeBSD)
# TODO check FreeBSD compatibility
if command -v pstree > /dev/null; then
pids="$(pstree "$pid" | sed -En 's/[^0-9]+([0-9]+) .*/\1/p' | tr '\n' ',')"
else
pids="$(get_cpids_unix "$pid" | tr '\n' ',')"
fi
total_mem_kb="$(ps -o rss= -p "$pids" | paste -sd+ - | bc)"
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO - windows compatability
;;
esac
total_mem_mb=$(kb_to_mb "$total_mem_kb" | round 0)
total_mem_gb=$(kb_to_gb "$total_mem_kb" | round 0)
if (( total_mem_gb > 0)); then
echo "${total_mem_gb}GB"
elif (( total_mem_mb > 0 )); then
echo "${total_mem_mb}MB"
else
echo "${total_mem_kb}kB"
fi
}
main()
{
ram_label=$(get_tmux_option "@dracula-tmux-ram-usage-label" "MEM")
ram_usage=$(get_tmux_ram_usage)
echo "$ram_label $ram_usage"
}
#run main driver
main

View file

@ -11,6 +11,17 @@ get_tmux_option() {
fi fi
} }
get_tmux_window_option() {
local option=$1
local default_value=$2
local option_value=$(tmux show-window-options -v "$option")
if [ -z "$option_value" ]; then
echo $default_value
else
echo $option_value
fi
}
# normalize the percentage string to always have a length of 5 # normalize the percentage string to always have a length of 5
normalize_percent_len() { normalize_percent_len() {
# the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%" # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%"

31
scripts/weather_wrapper.sh Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
#wrapper script for running weather on interval
fahrenheit=$1
location=$2
fixedlocation=$3
DATAFILE=/tmp/.dracula-tmux-data
LAST_EXEC_FILE="/tmp/.dracula-tmux-weather-last-exec"
RUN_EACH=1200
TIME_NOW=$(date +%s)
TIME_LAST=$(cat "${LAST_EXEC_FILE}" 2>/dev/null || echo "0")
main()
{
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "$(expr ${TIME_LAST} + ${RUN_EACH})" -lt "${TIME_NOW}" ]; then
# Run weather script here
$current_dir/weather.sh $fahrenheit $location $fixedlocation > "${DATAFILE}"
echo "${TIME_NOW}" > "${LAST_EXEC_FILE}"
fi
cat "${DATAFILE}"
}
#run main driver function
main