From 09a96946ff2117a80c4fd1ace248600bf73b19ff Mon Sep 17 00:00:00 2001 From: Janno Tjarks Date: Wed, 22 Dec 2021 22:50:05 +0100 Subject: [PATCH 01/16] Added synchronize-panes plugin --- INSTALL.md | 10 +++++++++- README.md | 1 + scripts/dracula.sh | 6 ++++++ scripts/synchronize_panes.sh | 26 ++++++++++++++++++++++++++ scripts/utils.sh | 11 +++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 scripts/synchronize_panes.sh diff --git a/INSTALL.md b/INSTALL.md index f6e915e..c0afd6f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -48,7 +48,7 @@ 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. ```bash -# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, weather, time +# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, weather, time, synchronize-panes set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" ``` @@ -189,3 +189,11 @@ Switch from default fahrenheit to celsius set -g @dracula-show-fahrenheit false ``` + +#### synchronize-panes options + +Customize label + +```bash +set -g @dracula-synchronize-panes-label "Sync" +``` diff --git a/README.md b/README.md index eef0aaa..af093ef 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul * When prefix is enabled smiley face turns from green to yellow * When charging, 'AC' is displayed * If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature +* Info if the Panes are synchronized ## Compatibility diff --git a/scripts/dracula.sh b/scripts/dracula.sh index f530187..d82517b 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -23,6 +23,7 @@ main() show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) + show_synchronize_panes_label=$(get_tmux_option "@dracula-synchronize-panes-label" "Sync") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # Dracula Color Pallette @@ -185,6 +186,11 @@ main() script="%a %m/%d %I:%M %p ${timezone} " fi fi + + if [ $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)" + fi if $show_powerline; then tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " diff --git a/scripts/synchronize_panes.sh b/scripts/synchronize_panes.sh new file mode 100644 index 0000000..078e8a9 --- /dev/null +++ b/scripts/synchronize_panes.sh @@ -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 diff --git a/scripts/utils.sh b/scripts/utils.sh index a296192..b4402e6 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -11,6 +11,17 @@ get_tmux_option() { 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_percent_len() { # the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%" From 311da18dc2a5f5b4260ec3e952bbd49c16b0f70c Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Thu, 10 Nov 2022 22:31:24 -0500 Subject: [PATCH 02/16] Add tmux-ram-usage plugin --- INSTALL.md | 10 ++++- scripts/dracula.sh | 4 ++ scripts/tmux_ram_info.sh | 84 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100755 scripts/tmux_ram_info.sh diff --git a/INSTALL.md b/INSTALL.md index 16fcbbd..b54049e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -48,7 +48,7 @@ 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. ```bash -# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, network-ping, attached-clients, network-vpn, weather, time, spotify-tui, kubernetes-context +# 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 set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" ``` @@ -161,6 +161,14 @@ Customize label 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, diff --git a/scripts/dracula.sh b/scripts/dracula.sh index af0b222..a46f664 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -169,6 +169,10 @@ main() IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ram-usage-colors" "cyan dark_gray") script="#($current_dir/ram_info.sh)" + 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") script="#($current_dir/network.sh)" diff --git a/scripts/tmux_ram_info.sh b/scripts/tmux_ram_info.sh new file mode 100755 index 0000000..8bdd2fe --- /dev/null +++ b/scripts/tmux_ram_info.sh @@ -0,0 +1,84 @@ +#!/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 + +kb_to_mb() { + if [ $# == 0 ]; then + read num + else + num="$1" + fi + bc <<< "scale=3;$num/1024" +} + +kb_to_gb() { + if [ $# == 0 ]; then + read num + else + num="$1" + fi + bc <<< "scale=6;$num/1048576" +} + +round() { + if [ $# == 1 ]; then + read num + scale="$1" + elif [ $# == 2 ]; then + num="$1" + scale="$2" + fi + printf "%.${scale}f" "${num}" +} + +get_tmux_ram_usage() +{ + local pid="$(tmux display-message -pF '#{pid}')" + local total_mem_kb=0 + case $(uname -s) in + Linux) + local pids="$(pstree -p $pid | tr -d '\n' | sed -rn -e 's/[^()]*\(([0-9]+)\)[^()]*/\1,/g' -e 's/,$//p')" + total_mem_kb="$(ps -o rss= -p "$pids" | paste -sd+ | bc)" + ;; + + Darwin) + local pids="$(pstree $pid | sed -En 's/[^0-9]+([0-9]+) .*/\1/p' | tr '\n' ',')" + total_mem_kb="$(ps -o rss= -p "$pids" | paste -sd+ - | bc)" + ;; + + FreeBSD) + # TODO check FreeBSD compatibility + local pids="$(pstree $pid | sed -En 's/[^0-9]+([0-9]+) .*/\1/p' | tr '\n' ',')" + total_mem_kb="$(ps -o rss= -p "$pids" | paste -sd+ - | bc)" + ;; + + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # TODO - windows compatability + ;; + esac + local total_mem_mb=$(echo "$total_mem_kb" | kb_to_mb | round 0) + local total_mem_gb=$(echo "$total_mem_kb" | kb_to_gb | 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() +{ + # 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-tmux-ram-usage-label" "MEM") + ram_usage=$(get_tmux_ram_usage) + echo "$ram_label $ram_usage" +} + +#run main driver +main From 487db8f50cc148e7ce7dab5f398e24856183553b Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 17 Jun 2023 17:17:43 -0400 Subject: [PATCH 03/16] Add tmux-ram-usage feature to README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 630f72e..bbafc3a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul - Battery percentage and AC power connection status - Refresh rate control - CPU usage (percentage or load average) -- RAM usage +- RAM usage (system and/or tmux server) - GPU usage - Custom status texts from external scripts - GPU VRAM usage From 83416ad3f890d8d9dcd77e1f1231fb10046f5dc4 Mon Sep 17 00:00:00 2001 From: Christopher Thompson Date: Tue, 4 Jul 2023 07:26:04 -0500 Subject: [PATCH 04/16] Add mercurial script --- INSTALL.md | 19 ++++++ scripts/dracula.sh | 5 ++ scripts/hg.sh | 163 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100755 scripts/hg.sh diff --git a/INSTALL.md b/INSTALL.md index 16fcbbd..19b587a 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -239,6 +239,25 @@ Show remote tracking branch together with diverge/sync state set -g @dracula-git-show-remote-status true ``` +#### mercurial options + +Hide details of hg changes +```bash +set -g @dracula-hg-disable-status true +``` + +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 true +``` + #### weather options Switch from default fahrenheit to celsius diff --git a/scripts/dracula.sh b/scripts/dracula.sh index af0b222..fc8ebfd 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -145,6 +145,11 @@ main() tmux set-option -g status-right-length 250 script="#($current_dir/git.sh)" + 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") script="#($current_dir/battery.sh)" diff --git a/scripts/hg.sh b/scripts/hg.sh new file mode 100755 index 0000000..c787d1b --- /dev/null +++ b/scripts/hg.sh @@ -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 + ;; + 'D') + 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 From 601696fd7fed6064897d55ddfbbefca5949befbc Mon Sep 17 00:00:00 2001 From: Christopher Thompson Date: Tue, 4 Jul 2023 07:35:30 -0500 Subject: [PATCH 05/16] Fix symbol for deleted files --- scripts/hg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/hg.sh b/scripts/hg.sh index c787d1b..966e110 100755 --- a/scripts/hg.sh +++ b/scripts/hg.sh @@ -24,7 +24,7 @@ for i in $(hg -R $path status -admru) 'A') added+=1 ;; - 'D') + '!') deleted+=1 ;; 'M') From a6aaf65856e85b02c711177f2ec4b68d51cc249d Mon Sep 17 00:00:00 2001 From: Christopher Thompson Date: Sat, 8 Jul 2023 19:04:42 -0500 Subject: [PATCH 06/16] Add missing flags to INSTALL.md --- INSTALL.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 19b587a..f8c7d55 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -239,23 +239,35 @@ Show remote tracking branch together with diverge/sync state set -g @dracula-git-show-remote-status true ``` -#### mercurial options +#### 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 +#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 true +#default is false +set -g @dracula-hg-no-untracked-files false ``` #### weather options @@ -292,3 +304,4 @@ Set the label when there is one client, or more than one client set -g @dracula-clients-singular client set -g @dracula-clients-plural clients ``` + From b6fe033952bf10c199118370d83185f0afbf373f Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 8 Jul 2023 20:51:11 -0400 Subject: [PATCH 07/16] Add fallback for tmux-ram-usage without pstree --- scripts/tmux_ram_info.sh | 44 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/scripts/tmux_ram_info.sh b/scripts/tmux_ram_info.sh index 8bdd2fe..b349d2e 100755 --- a/scripts/tmux_ram_info.sh +++ b/scripts/tmux_ram_info.sh @@ -5,6 +5,28 @@ 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 + cpids="$(pgrep -P "$ppid")" + local cpid + echo "$ppid" + for cpid in $cpids; do + get_cpids_linux "$cpid" + done +} + +get_cpids_unix() { + local ppid="$1" + local cpids + cpids="$(pgrep -aP "$ppid")" + local cpid + echo "$ppid" + for cpid in $cpids; do + get_cpids_unix "$cpid" + done +} + kb_to_mb() { if [ $# == 0 ]; then read num @@ -36,22 +58,36 @@ round() { get_tmux_ram_usage() { - local pid="$(tmux display-message -pF '#{pid}')" + local pid + pid="$(tmux display-message -pF '#{pid}')" + local pids local total_mem_kb=0 case $(uname -s) in Linux) - local pids="$(pstree -p $pid | tr -d '\n' | sed -rn -e 's/[^()]*\(([0-9]+)\)[^()]*/\1,/g' -e 's/,$//p')" + 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) - local pids="$(pstree $pid | sed -En 's/[^0-9]+([0-9]+) .*/\1/p' | tr '\n' ',')" + 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 - local pids="$(pstree $pid | sed -En 's/[^0-9]+([0-9]+) .*/\1/p' | tr '\n' ',')" + 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)" ;; From 640eb4c809c5db54129a68fac72f61a3b89a3c47 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sun, 9 Jul 2023 00:51:44 -0400 Subject: [PATCH 08/16] Fix shellcheck warnings --- scripts/tmux_ram_info.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/tmux_ram_info.sh b/scripts/tmux_ram_info.sh index b349d2e..63d4cf0 100755 --- a/scripts/tmux_ram_info.sh +++ b/scripts/tmux_ram_info.sh @@ -3,14 +3,14 @@ export LC_ALL=en_US.UTF-8 current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $current_dir/utils.sh +source "$current_dir/utils.sh" get_cpids_linux() { local ppid="$1" local cpids - cpids="$(pgrep -P "$ppid")" local cpid echo "$ppid" + cpids="$(pgrep -P "$ppid")" for cpid in $cpids; do get_cpids_linux "$cpid" done @@ -19,9 +19,9 @@ get_cpids_linux() { get_cpids_unix() { local ppid="$1" local cpids - cpids="$(pgrep -aP "$ppid")" local cpid echo "$ppid" + cpids="$(pgrep -aP "$ppid")" for cpid in $cpids; do get_cpids_unix "$cpid" done @@ -29,7 +29,7 @@ get_cpids_unix() { kb_to_mb() { if [ $# == 0 ]; then - read num + read -r num else num="$1" fi @@ -38,7 +38,7 @@ kb_to_mb() { kb_to_gb() { if [ $# == 0 ]; then - read num + read -r num else num="$1" fi @@ -47,7 +47,7 @@ kb_to_gb() { round() { if [ $# == 1 ]; then - read num + read -r num scale="$1" elif [ $# == 2 ]; then num="$1" @@ -59,9 +59,11 @@ round() { get_tmux_ram_usage() { local pid - pid="$(tmux display-message -pF '#{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 @@ -95,12 +97,12 @@ get_tmux_ram_usage() # TODO - windows compatability ;; esac - local total_mem_mb=$(echo "$total_mem_kb" | kb_to_mb | round 0) - local total_mem_gb=$(echo "$total_mem_kb" | kb_to_gb | round 0) + 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 + if (( total_mem_gb > 0)); then echo "${total_mem_gb}GB" - elif (( $total_mem_mb > 0 )); then + elif (( total_mem_mb > 0 )); then echo "${total_mem_mb}MB" else echo "${total_mem_kb}kB" @@ -109,8 +111,6 @@ get_tmux_ram_usage() 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-tmux-ram-usage-label" "MEM") ram_usage=$(get_tmux_ram_usage) echo "$ram_label $ram_usage" From 3ef141f82912073c8d3e0405922b8a2083e47ad0 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Fri, 14 Jul 2023 11:00:47 +0200 Subject: [PATCH 09/16] [fix] 'synchronize-panes' is not runnable --- scripts/dracula.sh | 9 +++------ scripts/synchronize_panes.sh | 0 2 files changed, 3 insertions(+), 6 deletions(-) mode change 100644 => 100755 scripts/synchronize_panes.sh diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 9902754..2354e76 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -231,14 +231,11 @@ main() script="%a %m/%d %I:%M %p ${timezone} " fi fi - - else - continue - fi - - if [ $plugin = "synchronize-panes" ]; then + 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 diff --git a/scripts/synchronize_panes.sh b/scripts/synchronize_panes.sh old mode 100644 new mode 100755 From 5af1faa367d56a70a871c85e3a3f377d11622d98 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Fri, 28 Oct 2022 03:11:39 -0400 Subject: [PATCH 10/16] Add plugin for tmux-continuum status --- INSTALL.md | 23 +++++++++++++- scripts/continuum.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++ scripts/dracula.sh | 4 +++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100755 scripts/continuum.sh diff --git a/INSTALL.md b/INSTALL.md index 6579094..0aadac0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -318,4 +318,25 @@ 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 -``` \ No newline at end of file +``` + +#### continuum options + +Hide output if no save has been performed recently +(otherwise, show the continuum save interval) + +```bash +set -g @dracula-continuum-mode alert +``` + +Show the time since the last continuum save + +```bash +set -g @dracula-continuum-mode time +``` + +In alert mode, show if a the last save was performed less then one minute ago (default is 15 seconds) + +```bash +set -g @dracula-continuum-time-threshold 60 +``` diff --git a/scripts/continuum.sh b/scripts/continuum.sh new file mode 100755 index 0000000..c45c514 --- /dev/null +++ b/scripts/continuum.sh @@ -0,0 +1,75 @@ +#!/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 (default|alert|time) +# @dracula-continuum-time-threshold 15 + +alert_mode="@dracula-continuum-mode" +time_threshold="@dracula-continuum-time-threshold" +warn_threshold=15 + +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)" +} + +time_since_last_run_passed() { + local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "0")" + printf "%s" "$(($(current_timestamp) - last_saved_timestamp))" +} + +print_status() { + local mode="$(get_tmux_option "$alert_mode" "default")" + local 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 time_delta="$(time_since_last_run_passed)" + local time_delta_minutes="$((time_delta / 60))" + + case "$mode" in + time) + if [[ $save_int -gt 0 ]]; then + if [[ "$time_delta" -gt $((interval_seconds+warn_threshold)) ]]; then + status="no save after $time_delta_minutes minutes!" + else + status="$time_delta_minutes" + fi + else + status="off" + fi + ;; + + alert) + if [[ "$time_delta" -gt $((interval_seconds+warn_threshold)) ]]; then + status="no save after $time_delta_minutes minutes!" + elif [[ "$time_delta" -le "$threshold" ]]; then + status="saved" + elif [[ $save_int -gt 0 ]]; then + status="" + else + status="off" + fi + ;; + + *) + if [[ "$time_delta" -le "$threshold" ]]; then + status="saved" + elif [[ $save_int -gt 0 ]]; then + status="$save_int" + else + status="off" + fi + ;; + esac + echo "$status" +} +print_status diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2354e76..0bf19c3 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -212,6 +212,10 @@ main() IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-terraform-colors" "light_purple dark_gray") script="#($current_dir/terraform.sh $terraform_label)" + 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") script="#($current_dir/weather_wrapper.sh $show_fahrenheit $show_location $fixed_location)" From 14300a6e751e3ee169f22847d17fa9610c274f4f Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Fri, 28 Oct 2022 06:34:42 -0400 Subject: [PATCH 11/16] Improve tmux-continuum status plugin --- INSTALL.md | 17 +++--- scripts/continuum.sh | 130 ++++++++++++++++++++++++++++++------------- 2 files changed, 98 insertions(+), 49 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 0aadac0..d91b1d1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -322,20 +322,17 @@ set -g @dracula-clients-plural clients #### continuum options -Hide output if no save has been performed recently -(otherwise, show the continuum save interval) +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 alert +set -g @dracula-continuum-mode countdown ``` -Show the time since the last continuum save - -```bash -set -g @dracula-continuum-mode time -``` - -In alert mode, show if a the last save was performed less then one minute ago (default is 15 seconds) +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 diff --git a/scripts/continuum.sh b/scripts/continuum.sh index c45c514..1e4229f 100755 --- a/scripts/continuum.sh +++ b/scripts/continuum.sh @@ -1,15 +1,28 @@ #!/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 +if command -v gdate &>/dev/null; then + DATE=gdate +else + DATE=date +fi # configuration -# @dracula-continuum-mode default (default|alert|time) +# @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=15 +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" @@ -21,55 +34,94 @@ current_timestamp() { echo "$(date +%s)" } -time_since_last_run_passed() { - local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "0")" - printf "%s" "$(($(current_timestamp) - last_saved_timestamp))" +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="$($DATE -r "$(last_resurrect_file)" +%s)" || last_saved_timestamp=0 + set_tmux_option "$first_save" "$last_saved_timestamp" + elif [ "$first_save_timestamp" != "done" ]; then + last_saved_timestamp="$($DATE -r "$(last_resurrect_file)" +%s)" || last_saved_timestamp=0 + 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" "default")" - local threshold="$(get_tmux_option "$time_threshold" "15")" + 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 time_delta="$(time_since_last_run_passed)" + local last_timestamp="$(last_saved_timestamp)" + local time_delta="$(($(current_timestamp) - last_timestamp))" local time_delta_minutes="$((time_delta / 60))" - case "$mode" in - time) - if [[ $save_int -gt 0 ]]; then - if [[ "$time_delta" -gt $((interval_seconds+warn_threshold)) ]]; then - status="no save after $time_delta_minutes minutes!" - else - status="$time_delta_minutes" - fi - else - status="off" - fi - ;; + if [[ $save_int -gt 0 ]]; then + if [[ "$time_delta" -gt $((interval_seconds + warn_threshold)) ]]; then + 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))" - alert) - if [[ "$time_delta" -gt $((interval_seconds+warn_threshold)) ]]; then - status="no save after $time_delta_minutes minutes!" - elif [[ "$time_delta" -le "$threshold" ]]; then - status="saved" - elif [[ $save_int -gt 0 ]]; then - status="" + status="last save: $($DATE -d "@$last_timestamp" '+%F %T'); next: T$(printf '%+d' "$((time_delta_minutes - save_int)) min")" else - status="off" + status="last save: $($DATE -d "@$last_timestamp" '+%F %T')" 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 - *) - if [[ "$time_delta" -le "$threshold" ]]; then - status="saved" - elif [[ $save_int -gt 0 ]]; then - status="$save_int" - else - status="off" - fi - ;; - esac echo "$status" } print_status From 67cde9d1ae2ac980a7d1f35c03fd09702db3c233 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Fri, 28 Oct 2022 12:14:50 -0400 Subject: [PATCH 12/16] Improve date compat in tmux-continuum status --- scripts/continuum.sh | 49 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/scripts/continuum.sh b/scripts/continuum.sh index 1e4229f..54ba773 100755 --- a/scripts/continuum.sh +++ b/scripts/continuum.sh @@ -1,11 +1,6 @@ #!/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 -if command -v gdate &>/dev/null; then - DATE=gdate -else - DATE=date -fi # configuration # @dracula-continuum-mode default (countdown|time|alert|interval) @@ -34,6 +29,42 @@ current_timestamp() { echo "$(date +%s)" } +file_mtime() { + if [ ! -f "$1" ]; then + echo 0 + 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" @@ -62,10 +93,10 @@ last_saved_timestamp() { # 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="$($DATE -r "$(last_resurrect_file)" +%s)" || last_saved_timestamp=0 + last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=0 set_tmux_option "$first_save" "$last_saved_timestamp" elif [ "$first_save_timestamp" != "done" ]; then - last_saved_timestamp="$($DATE -r "$(last_resurrect_file)" +%s)" || last_saved_timestamp=0 + last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=0 if [ "$last_saved_timestamp" -gt "$first_save_timestamp" ]; then set_tmux_option "$first_save" "done" else @@ -93,9 +124,9 @@ print_status() { time_delta="$(($(current_timestamp) - last_continuum_timestamp))" time_delta_minutes="$((time_delta / 60))" - status="last save: $($DATE -d "@$last_timestamp" '+%F %T'); next: T$(printf '%+d' "$((time_delta_minutes - save_int)) min")" + status="last save: $(timestamp_date "$last_timestamp" '+%F %T'); next: T$(printf '%+d' "$((time_delta_minutes - save_int))")min" else - status="last save: $($DATE -d "@$last_timestamp" '+%F %T')" + status="last save: $(timestamp_date "$last_timestamp" '+%F %T')" fi elif [[ "$time_delta" -le "$info_threshold" ]]; then status="saved" From e0dd39def54e1af2080261f2481e0460ab912998 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Tue, 1 Nov 2022 03:01:33 -0400 Subject: [PATCH 13/16] Improve tmux-continuum status if no save present --- scripts/continuum.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/continuum.sh b/scripts/continuum.sh index 54ba773..a66e897 100755 --- a/scripts/continuum.sh +++ b/scripts/continuum.sh @@ -31,7 +31,7 @@ current_timestamp() { file_mtime() { if [ ! -f "$1" ]; then - echo 0 + echo -1 return fi case $(uname -s) in @@ -93,10 +93,10 @@ last_saved_timestamp() { # 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=0 + 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=0 + 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 @@ -118,15 +118,18 @@ print_status() { 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="last save: $(timestamp_date "$last_timestamp" '+%F %T'); next: T$(printf '%+d' "$((time_delta_minutes - save_int))")min" - else - status="last save: $(timestamp_date "$last_timestamp" '+%F %T')" + status="$status; next: T$(printf '%+d' "$((time_delta_minutes - save_int))")min" fi elif [[ "$time_delta" -le "$info_threshold" ]]; then status="saved" From 7a8c436807358d1273016833ef3ed8d5f1fdc963 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Thu, 10 Nov 2022 22:53:25 -0500 Subject: [PATCH 14/16] Trim tmux-continuum status if no save present --- scripts/continuum.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/continuum.sh b/scripts/continuum.sh index a66e897..189e01b 100755 --- a/scripts/continuum.sh +++ b/scripts/continuum.sh @@ -129,7 +129,7 @@ print_status() { time_delta="$(($(current_timestamp) - last_continuum_timestamp))" time_delta_minutes="$((time_delta / 60))" - status="$status; next: T$(printf '%+d' "$((time_delta_minutes - save_int))")min" + status="$status; T$(printf '%+d' "$((time_delta_minutes - save_int))")min" fi elif [[ "$time_delta" -le "$info_threshold" ]]; then status="saved" From cf474c934260ef82e7da7cf71dbf8a1bf6877b70 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 17 Jun 2023 17:28:39 -0400 Subject: [PATCH 15/16] Add tmux-continuum feature to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6ea0860..6fcd9ef 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul - Info if the Panes are synchronized - Spotify playback (needs the tool spotify-tui installed) - Current kubernetes context +- Countdown to tmux-continuum save - Current working directory of tmux pane ## Compatibility From 73a2bf2b224950722a7225737bbe59ae83470fd5 Mon Sep 17 00:00:00 2001 From: FriendlyTroll Date: Tue, 29 Aug 2023 13:39:09 +0200 Subject: [PATCH 16/16] Update INSTALL.md Add info on how to set custom time format --- INSTALL.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index d91b1d1..c4ba180 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -210,6 +210,12 @@ Enable military time 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 Hide details of git changes