Skip to content

Commit

Permalink
Merge pull request #255 from rexberg/master
Browse files Browse the repository at this point in the history
Add krbtgt (Kerberos TGT) plugin
  • Loading branch information
ethancedwards8 authored Oct 18, 2024
2 parents ec85f84 + ac75148 commit 4bad7ad
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
11 changes: 10 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ To enable plugins set up the `@dracula-plugins` option in your `.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, tmux-ram-usage, network, network-bandwidth, network-ping, ssh-session, attached-clients, network-vpn, weather, time, mpc, spotify-tui, playerctl, kubernetes-context, synchronize-panes
# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, tmux-ram-usage, network, network-bandwidth, network-ping, ssh-session, attached-clients, network-vpn, weather, time, mpc, spotify-tui, krbtgt, playerctl, kubernetes-context, synchronize-panes
set -g @dracula-plugins "cpu-usage gpu-usage ram-usage"
```

Expand Down Expand Up @@ -365,6 +365,15 @@ Extract the account as a prefix to the cluster name - Available for EKS only (on

```
set -g @dracula-kubernetes-eks-extract-account true
```

### Kerberos TGT options

Set the principal to check the TGT expiration date for (with or without the REALM)

```
set -g @dracula-krbtgt-principal "principal"
```

#### continuum options

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
- Current kubernetes context
- Countdown to tmux-continuum save
- Current working directory of tmux pane
- Kerberos TGT expiration date
- Show your Libre Freestyle 3 readings [Setup instructions](./scripts/libre.sh)

## Compatibility
Expand Down
6 changes: 6 additions & 0 deletions scripts/dracula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ source $current_dir/utils.sh
main()
{
# set configuration option variables
show_krbtgt_label=$(get_tmux_option "@dracula-krbtgt-context-label" "")
krbtgt_principal=$(get_tmux_option "@dracula-krbtgt-principal" "")
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
show_only_kubernetes_context=$(get_tmux_option "@dracula-show-only-kubernetes-context" "")
eks_hide_arn=$(get_tmux_option "@dracula-kubernetes-eks-hide-arn" false)
Expand Down Expand Up @@ -241,6 +243,10 @@ main()
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray")
script="#($current_dir/spotify-tui.sh)"

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

elif [ $plugin = "playerctl" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-playerctl-colors" "green dark_gray")
script="#($current_dir/playerctl.sh)"
Expand Down
49 changes: 49 additions & 0 deletions scripts/krbtgt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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

principal=$1
label=$2

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh

if [ -n "$principal" ]; then
_principal=$principal
if ! [[ "$_principal" =~ "@" ]]; then
_principal="$_principal@"
fi
krb_principal_tgt_cache=$(klist -lan | awk -v krb_principal="^$_principal" '$0 ~ krb_principal {print $2}')
if [ -n "$krb_principal_tgt_cache" ]; then
krb_tgt_expire=$(date '+%H:%M:%S' -d "$(klist $krb_principal_tgt_cache | awk '/krbtgt/ {print $3,$4}')")
else
krb_tgt_expire=""
fi
fi

main()
{
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
OUTPUT_STRING=""
if [ -z "$principal" ]; then
OUTPUT_STRING="no principal configured"
fi

if [ -z "$krb_tgt_expire" ]; then
OUTPUT_STRING="$principal -"
else
OUTPUT_STRING="${principal} ${krb_tgt_expire}"
fi

if [ "$label" = "" ]; then
echo "${OUTPUT_STRING}"
else
echo "${label} ${OUTPUT_STRING}"
fi

sleep $RATE
}

# run the main driver
main

0 comments on commit 4bad7ad

Please sign in to comment.