Skip to content

Commit 4bad7ad

Browse files
Merge pull request #255 from rexberg/master
Add krbtgt (Kerberos TGT) plugin
2 parents ec85f84 + ac75148 commit 4bad7ad

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

INSTALL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ To enable plugins set up the `@dracula-plugins` option in your `.tmux.conf` file
4848
The order that you define the plugins will be the order on the status bar left to right.
4949

5050
```bash
51-
# 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
51+
# 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
5252
set -g @dracula-plugins "cpu-usage gpu-usage ram-usage"
5353
```
5454

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

366366
```
367367
set -g @dracula-kubernetes-eks-extract-account true
368+
```
369+
370+
### Kerberos TGT options
371+
372+
Set the principal to check the TGT expiration date for (with or without the REALM)
373+
374+
```
375+
set -g @dracula-krbtgt-principal "principal"
376+
```
368377

369378
#### continuum options
370379

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
4646
- Current kubernetes context
4747
- Countdown to tmux-continuum save
4848
- Current working directory of tmux pane
49+
- Kerberos TGT expiration date
4950
- Show your Libre Freestyle 3 readings [Setup instructions](./scripts/libre.sh)
5051
5152
## Compatibility

scripts/dracula.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ source $current_dir/utils.sh
88
main()
99
{
1010
# set configuration option variables
11+
show_krbtgt_label=$(get_tmux_option "@dracula-krbtgt-context-label" "")
12+
krbtgt_principal=$(get_tmux_option "@dracula-krbtgt-principal" "")
1113
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
1214
show_only_kubernetes_context=$(get_tmux_option "@dracula-show-only-kubernetes-context" "")
1315
eks_hide_arn=$(get_tmux_option "@dracula-kubernetes-eks-hide-arn" false)
@@ -241,6 +243,10 @@ main()
241243
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray")
242244
script="#($current_dir/spotify-tui.sh)"
243245

246+
elif [ $plugin = "krbtgt" ]; then
247+
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-krbtgt-colors" "cyan dark_gray")
248+
script="#($current_dir/krbtgt.sh $krbtgt_principal $show_krbtgt_label)"
249+
244250
elif [ $plugin = "playerctl" ]; then
245251
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-playerctl-colors" "green dark_gray")
246252
script="#($current_dir/playerctl.sh)"

scripts/krbtgt.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
principal=$1
6+
label=$2
7+
8+
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9+
source $current_dir/utils.sh
10+
11+
if [ -n "$principal" ]; then
12+
_principal=$principal
13+
if ! [[ "$_principal" =~ "@" ]]; then
14+
_principal="$_principal@"
15+
fi
16+
krb_principal_tgt_cache=$(klist -lan | awk -v krb_principal="^$_principal" '$0 ~ krb_principal {print $2}')
17+
if [ -n "$krb_principal_tgt_cache" ]; then
18+
krb_tgt_expire=$(date '+%H:%M:%S' -d "$(klist $krb_principal_tgt_cache | awk '/krbtgt/ {print $3,$4}')")
19+
else
20+
krb_tgt_expire=""
21+
fi
22+
fi
23+
24+
main()
25+
{
26+
# storing the refresh rate in the variable RATE, default is 5
27+
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
28+
OUTPUT_STRING=""
29+
if [ -z "$principal" ]; then
30+
OUTPUT_STRING="no principal configured"
31+
fi
32+
33+
if [ -z "$krb_tgt_expire" ]; then
34+
OUTPUT_STRING="$principal -"
35+
else
36+
OUTPUT_STRING="${principal} ${krb_tgt_expire}"
37+
fi
38+
39+
if [ "$label" = "" ]; then
40+
echo "${OUTPUT_STRING}"
41+
else
42+
echo "${label} ${OUTPUT_STRING}"
43+
fi
44+
45+
sleep $RATE
46+
}
47+
48+
# run the main driver
49+
main

0 commit comments

Comments
 (0)