Skip to content
145 changes: 72 additions & 73 deletions scripts/dracula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 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 )"
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh

main() {
Expand Down Expand Up @@ -41,9 +41,9 @@ main() {

narrow_mode=$(get_tmux_option "@dracula-narrow-mode" false)
if $narrow_mode; then
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-narrow-plugins" "compact-alt battery network weather")
IFS=' ' read -r -a plugins <<<$(get_tmux_option "@dracula-narrow-plugins" "compact-alt battery network weather")
else
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")
fi

# Dracula Color Pallette
Expand All @@ -67,16 +67,16 @@ main() {

# Set transparency variables - Colors and window dividers
if $transparent_powerline_bg; then
bg_color="default"
if $show_edge_icons; then
window_sep_fg=${dark_purple}
window_sep_bg=default
window_sep="$show_right_sep"
else
window_sep_fg=${dark_purple}
window_sep_bg=default
window_sep="$show_inverse_divider"
fi
bg_color="default"
if $show_edge_icons; then
window_sep_fg=${dark_purple}
window_sep_bg=default
window_sep="$show_right_sep"
else
window_sep_fg=${dark_purple}
window_sep_bg=default
window_sep="$show_inverse_divider"
fi
else
bg_color=${gray}
if $show_edge_icons; then
Expand All @@ -92,18 +92,24 @@ main() {

# Handle left icon configuration
case $show_left_icon in
smiley)
left_icon="☺";;
session)
left_icon="#S";;
window)
left_icon="#W";;
hostname)
left_icon="#H";;
shortname)
left_icon="#h";;
*)
left_icon=$show_left_icon;;
smiley)
left_icon="☺"
;;
session)
left_icon="#S"
;;
window)
left_icon="#W"
;;
hostname)
left_icon="#H"
;;
shortname)
left_icon="#h"
;;
*)
left_icon=$show_left_icon
;;
esac

# Handle left icon padding
Expand All @@ -122,20 +128,24 @@ main() {
# Set timezone unless hidden by configuration
if [[ -z "$timezone" ]]; then
case $show_timezone in
false)
timezone="";;
true)
timezone="#(date +%Z)";;
false)
timezone=""
;;
true)
timezone="#(date +%Z)"
;;
esac
fi

case $show_flags in
false)
flags=""
current_flags="";;
true)
flags="#{?window_flags,#[fg=${dark_purple}]#{window_flags},}"
current_flags="#{?window_flags,#[fg=${light_purple}]#{window_flags},}"
false)
flags=""
current_flags=""
;;
true)
flags="#{?window_flags,#[fg=${dark_purple}]#{window_flags},}"
current_flags="#{?window_flags,#[fg=${light_purple}]#{window_flags},}"
;;
esac

# sets refresh interval to every 5 seconds
Expand Down Expand Up @@ -183,7 +193,7 @@ main() {

for plugin in "${plugins[@]}"; do

if case $plugin in custom:*) true;; *) false;; esac; 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")
Expand All @@ -195,64 +205,64 @@ main() {
fi

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

elif [ $plugin = "cwd" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cwd-colors" "dark_gray white")
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
script="#($current_dir/fossil.sh)"

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
script="#($current_dir/git.sh)"

elif [ $plugin = "hg" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-hg-colors" "green dark_gray")
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)"

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)"

elif [ $plugin = "gpu-ram-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-ram-usage-colors" "cyan dark_gray")
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")
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)"

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)"

elif [ $plugin = "tmux-ram-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-tmux-ram-usage-colors" "cyan dark_gray")
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)"

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
script="#($current_dir/network_bandwidth.sh)"

Expand Down Expand Up @@ -297,50 +307,39 @@ main() {
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="#($current_dir/weather_wrapper.sh $show_fahrenheit $show_location '$fixed_location')"

elif [ $plugin = "time" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white")
if [ -n "$time_format" ]; then
script=${time_format}
else
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="%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
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-time-colors" "dark_purple white")
script="#($current_dir/dual_time.sh)"

elif [ $plugin = "synchronize-panes" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-synchronize-panes-colors" "cyan dark_gray")
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)"

elif [ $plugin = "libreview" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-libre-colors" "white dark_gray")
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-libre-colors" "white dark_gray")
script="#($current_dir/libre.sh $show_libreview)"

elif [ $plugin = "ssh-session" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ssh-session-colors" "green dark_gray")
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-ssh-session-colors" "green dark_gray")
script="#($current_dir/ssh_session.sh $show_ssh_session_port)"

elif [ $plugin = "network-public-ip" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-public-ip-colors" "cyan dark_gray")
script="#($current_dir/network-public-ip.sh)"

elif [ $plugin = "sys-temp" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-sys-temp-colors" "green dark_gray")
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-sys-temp-colors" "green dark_gray")
script="#($current_dir/sys_temp.sh)"

elif [ $plugin = "cpu-arch" ]; then
IFS=$' ' read -r -a colors <<< $(get_tmux_option "@dracula-cpu-arch-colors" "default default")
IFS=$' ' read -r -a colors <<<$(get_tmux_option "@dracula-cpu-arch-colors" "default default")
script="#($current_dir/cpu_arch.sh)"

elif [ $plugin = "uptime" ]; then
IFS=$' ' read -r -a colors <<< $(get_tmux_option "@dracula-uptime-colors" "default default")
IFS=$' ' read -r -a colors <<<$(get_tmux_option "@dracula-uptime-colors" "default default")
script="#($current_dir/uptime.sh)"

else
Expand All @@ -359,8 +358,8 @@ main() {
if $show_empty_plugins; then
tmux set-option -ga status-right " #[fg=${!colors[0]},bg=${background_color},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script $right_edge_icon"
else
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics] ${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script $right_edge_icon}"
fi
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics] ${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script $right_edge_icon}"
fi
powerbg=${!colors[0]}
else
if $show_empty_plugins; then
Expand Down
35 changes: 35 additions & 0 deletions scripts/dual_time.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

military=$(tmux show-option -gqv "@dracula-time-military" | tr '[:upper:]' '[:lower:]')

time_fmt="%I:%M %p"

if [[ "$military" == "true" || "$military" == "1" ]]; then
time_fmt="%H:%M"
fi

timezones=$(tmux show-option -gqv "@dracula-time")
[ -z "$timezones" ] && timezones="UTC"

IFS=',' read -ra TZ_ARRAY <<<"$timezones"

output=()
for tz in "${TZ_ARRAY[@]}"; do
tz=$(echo "$tz" | xargs) # Trim whitespace
label=$(basename "$tz" | tr '_' ' ')
if [ -f "/usr/share/zoneinfo/$tz" ]; then
time=$(env TZ="$tz" /bin/date +"${label} ${time_fmt}")
output+=("$time")
else
output+=("${label} N/A")
fi
done

joined=""
for i in "${!output[@]}"; do
if [ "$i" -gt 0 ]; then
joined+=" | "
fi
joined+="${output[$i]}"
done
echo "$joined"
27 changes: 21 additions & 6 deletions scripts/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-sym
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "")
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false")
IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-git-show-remote-status" "false")
IFS=' ' read -r -a show_repo_name <<<$(get_tmux_option "@dracula-git-show-repo-name" "false")

# Get added, modified, updated and deleted files from git status
getChanges()
Expand Down Expand Up @@ -129,11 +130,25 @@ getRemoteInfo()
echo "$out"
}

getRepoName()
{
if [ "$show_repo_name" = "true" ]; then
if [ $(checkForGitDir) == "true" ]; then
echo "$(basename "$(git -C $path rev-parse --show-toplevel 2>/dev/null)") |"
else
echo ""
fi
else
echo ""
fi
}

# return the final message for the status bar
getMessage()
{
if [ $(checkForGitDir) == "true" ]; then
branch="$(getBranch)"
repo_name="$(getRepoName)"
output=""

if [ $(checkForChanges) == "true" ]; then
Expand All @@ -142,23 +157,23 @@ getMessage()

if [ "${hide_status}" == "false" ]; then
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "${changes} $branch")
output=$(echo "$repo_name ${changes} $branch")
else
output=$(echo "$diff_symbol ${changes} $branch")
output=$(echo "$repo_name $diff_symbol ${changes} $branch")
fi
else
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "$branch")
output=$(echo "$repo_name $branch")
else
output=$(echo "$diff_symbol $branch")
output=$(echo "$repo_name $diff_symbol $branch")
fi
fi

else
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
output=$(echo "$branch")
output=$(echo "$repo_name $branch")
else
output=$(echo "$current_symbol $branch")
output=$(echo "$repo_name $current_symbol $branch")
fi
fi

Expand Down