Skip to content

Commit

Permalink
carlogtt updates
Browse files Browse the repository at this point in the history
  • Loading branch information
carlogtt committed Jan 12, 2025
1 parent b988267 commit 1920a28
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 87 deletions.
7 changes: 6 additions & 1 deletion plugins/catppuccin/status/carlogtt_mw_cookie.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# vim:set ft=tmux:
%hidden MODULE_NAME="carlogtt_mw_cookie"

set -gq @mw_cookie_valid_color "default"
set -gq @mw_cookie_expiring_color "#{E:@thm_yellow}"
set -gq @mw_cookie_expired_color "#{E:@thm_red}"
set -gq @mw_cookie_color_end "default"

set -ogq @catppuccin_carlogtt_mw_cookie_icon "⚿ "
set -ogq @catppuccin_carlogtt_mw_cookie_color "#{E:@thm_red}"
set -ogq @catppuccin_carlogtt_mw_cookie_color "#{E:@thm_rosewater}"
set -ogq @catppuccin_carlogtt_mw_cookie_text " #{l:#{mw_cookie}}"

source -F "#{d:current_file}/../utils/status_module.conf"
29 changes: 4 additions & 25 deletions plugins/tmux-midway/midway.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,10 @@

CURRENT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

cpu_interpolation=(
"\#{mw_cookie}"
)
cpu_commands=(
"#(${CURRENT_DIR}/scripts/midway-helper.sh)"
)
. "$CURRENT_DIR/scripts/helpers.sh"

get_tmux_option() {
local option
local default_value
local option_value
option="$1"
default_value="$2"
option_value="$(tmux show-option -qv "$option")"
if [ -z "$option_value" ]; then
option_value="$(tmux show-option -gqv "$option")"
fi
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
mw_interpolation="\#{mw_cookie}"
mw_command="#(${CURRENT_DIR}/scripts/midway.sh)"

set_tmux_option() {
local option=$1
Expand All @@ -39,9 +20,7 @@ set_tmux_option() {

do_interpolation() {
local all_interpolated="$1"
for ((i = 0; i < ${#cpu_commands[@]}; i++)); do
all_interpolated=${all_interpolated//${cpu_interpolation[$i]}/${cpu_commands[$i]}}
done
all_interpolated=${all_interpolated//${mw_interpolation}/${mw_command}}
echo "$all_interpolated"
}

Expand Down
24 changes: 24 additions & 0 deletions plugins/tmux-midway/scripts/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# __| \ _ \ | _ \ __| __ __| __ __|
# ( _ \ / | ( | (_ | | |
# \___| _/ _\ _|_\ ____| \___/ \___| _| _|


get_tmux_option() {
local option
local default_value
local option_value
option="$1"
default_value="$2"
option_value="$(tmux show-option -qv "$option")"
if [ -z "$option_value" ]; then
option_value="$(tmux show-option -gqv "$option")"
fi
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}

60 changes: 0 additions & 60 deletions plugins/tmux-midway/scripts/midway-helper.sh

This file was deleted.

69 changes: 69 additions & 0 deletions plugins/tmux-midway/scripts/midway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# __| \ _ \ | _ \ __| __ __| __ __|
# ( _ \ / | ( | (_ | | |
# \___| _/ _\ _|_\ ____| \___/ \___| _| _|


CURRENT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

. "$CURRENT_DIR/helpers.sh"

mw_cookie() {
local secs_for_expiring=900 # 20 minutes
local now_timestamp=$(date +%s)
local mw_cookie_text=""

while read -r line; do
local cookie_domain=$(echo "$line" | awk '{print $1}' | awk '{ gsub(/#HttpOnly_\.?/, ""); print }' )
local expiry_timestamp=$(echo "$line" | awk '{print $5}')
local cookie_name=$(echo "$line" | awk '{print $6}')

local time_remaining_sec=$((expiry_timestamp - now_timestamp))
local time_remaining_min=$((time_remaining_sec / 60))

if [[ "${cookie_name}" == "amazon_enterprise_access" ]]; then
if [[ "${cookie_domain}" =~ midway-auth.amazon.com ]]; then
if [[ "${time_remaining_sec}" -gt "${secs_for_expiring}" ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_valid_color),bg=default]AEA ✔#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
elif [[ "${time_remaining_sec}" -le "${secs_for_expiring}" && "${time_remaining_sec}" -gt 0 ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_expiring_color),bg=default]AEA $time_remaining_min#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
elif [[ "${time_remaining_sec}" -le 0 ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_expired_color),bg=default]AEA ✖#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default]"
fi
elif [[ "${cookie_domain}" =~ auth.midway.csphome.adc-e.uk ]]; then
if [[ "${time_remaining_sec}" -gt "${secs_for_expiring}" ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_valid_color),bg=default]AEA-NCL ✔#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
elif [[ "${time_remaining_sec}" -le "${secs_for_expiring}" && "${time_remaining_sec}" -gt 0 ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_expiring_color),bg=default]AEA-NCL $time_remaining_min#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
elif [[ "${time_remaining_sec}" -le 0 ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_expired_color),bg=default]AEA-NCL ✖#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
fi
fi
elif [[ "${cookie_name}" == "session" ]]; then
if [[ "${cookie_domain}" =~ midway-auth.amazon.com ]]; then
if [[ "${time_remaining_sec}" -gt "${secs_for_expiring}" ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_valid_color),bg=default]MW ✔#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
elif [[ "${time_remaining_sec}" -le "${secs_for_expiring}" && "${time_remaining_sec}" -gt 0 ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_expiring_color),bg=default]MW $time_remaining_min#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
elif [[ "${time_remaining_sec}" -le 0 ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_expired_color),bg=default]MW ✖#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
fi
elif [[ "${cookie_domain}" =~ auth.midway.csphome.adc-e.uk ]]; then
if [[ "${time_remaining_sec}" -gt "${secs_for_expiring}" ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_valid_color),bg=default]MW-NCL ✔#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
elif [[ "${time_remaining_sec}" -le "${secs_for_expiring}" && "${time_remaining_sec}" -gt 0 ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_expiring_color),bg=default]MW-NCL $time_remaining_min#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
elif [[ "${time_remaining_sec}" -le 0 ]]; then
mw_cookie_text+="#[fg=$(get_tmux_option @mw_cookie_expired_color),bg=default]MW-NCL ✖#[fg=$(get_tmux_option @mw_cookie_color_end),bg=default] "
fi
fi
fi
done <"${HOME}/.midway/cookie" || printf 'NOT-FOUND'

# Remove trailing whitespace
echo "${mw_cookie_text%"${mw_cookie_text##*[![:space:]]}"}"
}

mw_cookie

2 changes: 1 addition & 1 deletion tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ set-option -g status-left-length 150
set-option -g status-right-length 170

# Update the status bar every X seconds
set-option -g status-interval 1
set-option -g status-interval 2

# Start windows and panes index at 1, not 0
set-option -g base-index 1
Expand Down

0 comments on commit 1920a28

Please sign in to comment.