Created
November 16, 2022 14:27
-
-
Save trevor-vaughan/38facd6715a19e96cd2a1954dcc35057 to your computer and use it in GitHub Desktop.
Load and clear tokens from pass
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
# Source this script to load your tokens from `pass` into your current session | |
# | |
# Not brilliant but better than having them hang out forever | |
# Number of seconds to keep your tokens in your session | |
# Suggest making it slightly random so you don't accidentally kill some other sleep | |
keep_seconds=1234 | |
function tokens_clear() { | |
unset TOKEN1 | |
unset TOKEN2 | |
unset YOU_GET_THE_IDEA | |
} | |
test -z "${TOKEN1}" && export TOKEN1=$( pass show services/token1 ) | |
test -z "${TOKEN2}" && export TOKEN2=$( pass show services/token2 ) | |
test -z "${YOU_GET_THE_IDEA}" && export YOU_GET_THE_IDEA=$( pass show other_stuff/ygti ) | |
trap tokens_clear SIGUSR2 | |
current_sleep=$( pstree -pa $$ | grep "sleep,[[:digit:]]\+ ${keep_seconds}" | cut -f2 -d',' | cut -f1 -d' ' ) | |
if [ -n "$current_sleep" ]; then | |
kill $current_sleep | |
fi | |
current_shell=$BASHPID | |
( sleep $keep_seconds; kill -SIGUSR2 $current_shell ) >& /dev/null & disown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment