dracula.sh
1 #!/usr/bin/env bash 2 # setting the locale, some users have issues with different locales, this forces the correct one 3 export LC_ALL=en_US.UTF-8 4 5 current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 6 source $current_dir/utils.sh 7 8 main() 9 { 10 # set configuration option variables 11 show_krbtgt_label=$(get_tmux_option "@dracula-krbtgt-context-label" "") 12 krbtgt_principal=$(get_tmux_option "@dracula-krbtgt-principal" "") 13 show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "") 14 show_only_kubernetes_context=$(get_tmux_option "@dracula-show-only-kubernetes-context" "") 15 eks_hide_arn=$(get_tmux_option "@dracula-kubernetes-eks-hide-arn" false) 16 eks_extract_account=$(get_tmux_option "@dracula-kubernetes-eks-extract-account" false) 17 hide_kubernetes_user=$(get_tmux_option "@dracula-kubernetes-hide-user" false) 18 terraform_label=$(get_tmux_option "@dracula-terraform-label" "") 19 show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) 20 show_location=$(get_tmux_option "@dracula-show-location" true) 21 fixed_location=$(get_tmux_option "@dracula-fixed-location") 22 show_powerline=$(get_tmux_option "@dracula-show-powerline" false) 23 transparent_powerline_bg=$(get_tmux_option "@dracula-transparent-powerline-bg" false) 24 show_flags=$(get_tmux_option "@dracula-show-flags" false) 25 show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) 26 show_left_icon_padding=$(get_tmux_option "@dracula-left-icon-padding" 1) 27 show_military=$(get_tmux_option "@dracula-military-time" false) 28 timezone=$(get_tmux_option "@dracula-set-timezone" "") 29 show_timezone=$(get_tmux_option "@dracula-show-timezone" true) 30 show_left_sep=$(get_tmux_option "@dracula-show-left-sep" ) 31 show_right_sep=$(get_tmux_option "@dracula-show-right-sep" ) 32 show_inverse_divider=$(get_tmux_option "@dracula-inverse-divider" ) 33 show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) 34 show_day_month=$(get_tmux_option "@dracula-day-month" false) 35 show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) 36 show_synchronize_panes_label=$(get_tmux_option "@dracula-synchronize-panes-label" "Sync") 37 time_format=$(get_tmux_option "@dracula-time-format" "") 38 show_ssh_session_port=$(get_tmux_option "@dracula-show-ssh-session-port" false) 39 show_libreview=$(get_tmux_option "@dracula-show-libreview" false) 40 IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") 41 show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true) 42 43 # Dracula Color Pallette 44 white="#f8f8f2" 45 gray="#44475a" 46 dark_gray="#282a36" 47 light_purple="#bd93f9" 48 dark_purple="#6272a4" 49 cyan="#8be9fd" 50 green="#50fa7b" 51 orange="#ffb86c" 52 red="#ff5555" 53 pink="#ff79c6" 54 yellow="#f1fa8c" 55 56 # Override default colors and possibly add more 57 colors="$(get_tmux_option "@dracula-colors" "")" 58 if [ -n "$colors" ]; then 59 eval "$colors" 60 fi 61 62 # Set transparency variables - Colors and window dividers 63 if $transparent_powerline_bg; then 64 bg_color="default" 65 window_sep_fg=${dark_purple} 66 window_sep_bg=default 67 window_sep="$show_inverse_divider" 68 else 69 bg_color=${gray} 70 window_sep_fg=${gray} 71 window_sep_bg=${dark_purple} 72 window_sep="$show_left_sep" 73 fi 74 75 # Handle left icon configuration 76 case $show_left_icon in 77 smiley) 78 left_icon="☺";; 79 session) 80 left_icon="#S";; 81 window) 82 left_icon="#W";; 83 hostname) 84 left_icon="#H";; 85 shortname) 86 left_icon="#h";; 87 *) 88 left_icon=$show_left_icon;; 89 esac 90 91 # Handle left icon padding 92 padding="" 93 if [ "$show_left_icon_padding" -gt "0" ]; then 94 padding="$(printf '%*s' $show_left_icon_padding)" 95 fi 96 left_icon="$left_icon$padding" 97 98 # Handle powerline option 99 if $show_powerline; then 100 right_sep="$show_right_sep" 101 left_sep="$show_left_sep" 102 fi 103 104 # Set timezone unless hidden by configuration 105 if [[ -z "$timezone" ]]; then 106 case $show_timezone in 107 false) 108 timezone="";; 109 true) 110 timezone="#(date +%Z)";; 111 esac 112 fi 113 114 case $show_flags in 115 false) 116 flags="" 117 current_flags="";; 118 true) 119 flags="#{?window_flags,#[fg=${dark_purple}]#{window_flags},}" 120 current_flags="#{?window_flags,#[fg=${light_purple}]#{window_flags},}" 121 esac 122 123 # sets refresh interval to every 5 seconds 124 tmux set-option -g status-interval $show_refresh 125 126 # set the prefix + t time format 127 if $show_military; then 128 tmux set-option -g clock-mode-style 24 129 else 130 tmux set-option -g clock-mode-style 12 131 fi 132 133 # set length 134 tmux set-option -g status-left-length 100 135 tmux set-option -g status-right-length 100 136 137 # pane border styling 138 if $show_border_contrast; then 139 tmux set-option -g pane-active-border-style "fg=${light_purple}" 140 else 141 tmux set-option -g pane-active-border-style "fg=${dark_purple}" 142 fi 143 tmux set-option -g pane-border-style "fg=${gray}" 144 145 # message styling 146 tmux set-option -g message-style "bg=${gray},fg=${white}" 147 148 # status bar 149 tmux set-option -g status-style "bg=${bg_color},fg=${white}" 150 151 # Status left 152 if $show_powerline; then 153 tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${bg_color}]#{?client_prefix,#[fg=${yellow}],}${left_sep}" 154 powerbg=${bg_color} 155 else 156 tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}" 157 fi 158 159 # Status right 160 tmux set-option -g status-right "" 161 162 for plugin in "${plugins[@]}"; do 163 164 if case $plugin in custom:*) true;; *) false;; esac; then 165 script=${plugin#"custom:"} 166 if [[ -x "${current_dir}/${script}" ]]; then 167 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-custom-plugin-colors" "cyan dark_gray") 168 script="#($current_dir/${script})" 169 else 170 colors[0]="red" 171 colors[1]="dark_gray" 172 script="${script} not found!" 173 fi 174 175 elif [ $plugin = "cwd" ]; then 176 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cwd-colors" "dark_gray white") 177 tmux set-option -g status-right-length 250 178 script="#($current_dir/cwd.sh)" 179 180 elif [ $plugin = "fossil" ]; then 181 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-fossil-colors" "green dark_gray") 182 tmux set-option -g status-right-length 250 183 script="#($current_dir/fossil.sh)" 184 185 elif [ $plugin = "git" ]; then 186 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray") 187 tmux set-option -g status-right-length 250 188 script="#($current_dir/git.sh)" 189 190 elif [ $plugin = "hg" ]; then 191 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-hg-colors" "green dark_gray") 192 tmux set-option -g status-right-length 250 193 script="#($current_dir/hg.sh)" 194 195 elif [ $plugin = "battery" ]; then 196 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-battery-colors" "pink dark_gray") 197 script="#($current_dir/battery.sh)" 198 199 elif [ $plugin = "gpu-usage" ]; then 200 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-usage-colors" "pink dark_gray") 201 script="#($current_dir/gpu_usage.sh)" 202 203 elif [ $plugin = "gpu-ram-usage" ]; then 204 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-ram-usage-colors" "cyan dark_gray") 205 script="#($current_dir/gpu_ram_info.sh)" 206 207 elif [ $plugin = "gpu-power-draw" ]; then 208 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-power-draw-colors" "green dark_gray") 209 script="#($current_dir/gpu_power.sh)" 210 211 elif [ $plugin = "cpu-usage" ]; then 212 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cpu-usage-colors" "orange dark_gray") 213 script="#($current_dir/cpu_info.sh)" 214 215 elif [ $plugin = "ram-usage" ]; then 216 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ram-usage-colors" "cyan dark_gray") 217 script="#($current_dir/ram_info.sh)" 218 219 elif [ $plugin = "tmux-ram-usage" ]; then 220 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-tmux-ram-usage-colors" "cyan dark_gray") 221 script="#($current_dir/tmux_ram_info.sh)" 222 223 elif [ $plugin = "network" ]; then 224 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-colors" "cyan dark_gray") 225 script="#($current_dir/network.sh)" 226 227 elif [ $plugin = "network-bandwidth" ]; then 228 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-bandwidth-colors" "cyan dark_gray") 229 tmux set-option -g status-right-length 250 230 script="#($current_dir/network_bandwidth.sh)" 231 232 elif [ $plugin = "network-ping" ]; then 233 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray") 234 script="#($current_dir/network_ping.sh)" 235 236 elif [ $plugin = "network-vpn" ]; then 237 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-vpn-colors" "cyan dark_gray") 238 script="#($current_dir/network_vpn.sh)" 239 240 elif [ $plugin = "attached-clients" ]; then 241 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-attached-clients-colors" "cyan dark_gray") 242 script="#($current_dir/attached_clients.sh)" 243 244 elif [ $plugin = "mpc" ]; then 245 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-mpc-colors" "green dark_gray") 246 script="#($current_dir/mpc.sh)" 247 248 elif [ $plugin = "spotify-tui" ]; then 249 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray") 250 script="#($current_dir/spotify-tui.sh)" 251 252 elif [ $plugin = "krbtgt" ]; then 253 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-krbtgt-colors" "cyan dark_gray") 254 script="#($current_dir/krbtgt.sh $krbtgt_principal $show_krbtgt_label)" 255 256 elif [ $plugin = "playerctl" ]; then 257 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-playerctl-colors" "green dark_gray") 258 script="#($current_dir/playerctl.sh)" 259 260 elif [ $plugin = "kubernetes-context" ]; then 261 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray") 262 script="#($current_dir/kubernetes_context.sh $eks_hide_arn $eks_extract_account $hide_kubernetes_user $show_only_kubernetes_context $show_kubernetes_context_label)" 263 264 elif [ $plugin = "terraform" ]; then 265 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-terraform-colors" "light_purple dark_gray") 266 script="#($current_dir/terraform.sh $terraform_label)" 267 268 elif [ $plugin = "continuum" ]; then 269 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-continuum-colors" "cyan dark_gray") 270 script="#($current_dir/continuum.sh)" 271 272 elif [ $plugin = "weather" ]; then 273 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") 274 script="#($current_dir/weather_wrapper.sh $show_fahrenheit $show_location '$fixed_location')" 275 276 elif [ $plugin = "time" ]; then 277 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white") 278 if [ -n "$time_format" ]; then 279 script=${time_format} 280 else 281 if $show_day_month && $show_military ; then # military time and dd/mm 282 script="%a %d/%m %R ${timezone} " 283 elif $show_military; then # only military time 284 script="%R ${timezone} " 285 elif $show_day_month; then # only dd/mm 286 script="%a %d/%m %I:%M %p ${timezone} " 287 else 288 script="%a %m/%d %I:%M %p ${timezone} " 289 fi 290 fi 291 elif [ $plugin = "synchronize-panes" ]; then 292 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-synchronize-panes-colors" "cyan dark_gray") 293 script="#($current_dir/synchronize_panes.sh $show_synchronize_panes_label)" 294 295 elif [ $plugin = "libreview" ]; then 296 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-libre-colors" "white dark_gray") 297 script="#($current_dir/libre.sh $show_libreview)" 298 299 elif [ $plugin = "ssh-session" ]; then 300 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ssh-session-colors" "green dark_gray") 301 script="#($current_dir/ssh_session.sh $show_ssh_session_port)" 302 303 elif [ $plugin = "network-public-ip" ]; then 304 IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-public-ip-colors" "cyan dark_gray") 305 script="#($current_dir/network-public-ip.sh)" 306 307 else 308 continue 309 fi 310 311 if [ $plugin = "sys-temp" ]; then 312 IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-sys-temp-colors" "green dark_gray") 313 script="#($current_dir/sys_temp.sh)" 314 fi 315 316 if $show_powerline; then 317 if $show_empty_plugins; then 318 tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " 319 else 320 tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script }" 321 fi 322 powerbg=${!colors[0]} 323 else 324 if $show_empty_plugins; then 325 tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script " 326 else 327 tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[1]},bg=${!colors[0]}] $script }" 328 fi 329 fi 330 done 331 332 # Window option 333 if $show_powerline; then 334 tmux set-window-option -g window-status-current-format "#[fg=${window_sep_fg},bg=${window_sep_bg}]${window_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${bg_color}]${left_sep}" 335 else 336 tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} " 337 fi 338 339 tmux set-window-option -g window-status-format "#[fg=${white}]#[bg=${bg_color}] #I #W${flags}" 340 tmux set-window-option -g window-status-activity-style "bold" 341 tmux set-window-option -g window-status-bell-style "bold" 342 } 343 344 # run main function 345 main