-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
carlogtt
committed
Jan 12, 2025
1 parent
b988267
commit 1920a28
Showing
6 changed files
with
104 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters