Skip to content

Instantly share code, notes, and snippets.

@3735943886
Last active September 20, 2022 07:02
Show Gist options
  • Save 3735943886/64a3fc797c908a1b4408aec59b136ef3 to your computer and use it in GitHub Desktop.
Save 3735943886/64a3fc797c908a1b4408aec59b136ef3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
LOGINUSER="$(who am i | awk '{print $1}')"
HOMEDIR="$(getent passwd $LOGINUSER | cut -d: -f6)"
OTPKEY="$HOMEDIR/.otpkeys"
RCX=0
echo
if [ -f "$OTPKEY" ]
then
while read -r services; do
if [ -z $1 ] || [[ "${services%=*}" =~ $1 ]]
then
((RCX++))
printf "${services%=*} : "
oathtool --totp -b "${services#*=}"
fi
done < "$OTPKEY"
fi
if [ $RCX -eq 0 ]
then
echo "Usage:"
echo " $0 google"
echo
echo "Configuration:"
echo " $OTPKEY"
echo
echo "Format:"
echo " name=key"
fi
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment