my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

3 years ago
  1. export OTP_HOME=~/.otp
  2. mkdir -p $OTP_HOME
  3. function ot () {
  4. if ! command -v oathtool > /dev/null 2>&1; then
  5. echo "Note: you need to install oathtool or oath-toolkit, depending on your OS or distribution."
  6. return 1
  7. fi
  8. if ! command -v gpg > /dev/null 2>&1; then
  9. echo "Note: you need to install gpg and create an ID using 'gpg --gen-key', unless you have one already."
  10. return 1
  11. fi
  12. COPY_CMD='true'
  13. if [[ -z "$1" ]]; then
  14. echo "usage: $0 <profile.name>"
  15. return 1
  16. elif [ ! -f $OTP_HOME/$1.otp.asc ]; then
  17. echo "missing profile $1, you might need to create it first using otp_add_device"
  18. return 1
  19. else
  20. totpkey=$(gpg --decrypt $OTP_HOME/$1.otp.asc)
  21. oathtool --totp --b $totpkey | tee /dev/stderr | clipcopy
  22. fi
  23. }
  24. function otp_add_device () {
  25. if [[ "x$1" == "x" ]] then
  26. echo "usage: $0 <profile.name>"
  27. return 1
  28. else
  29. echo "Enter an email address attached to your GPG private key, then paste the secret configuration key followed by ^D"
  30. rm -f $OTP_HOME/$1.otp.asc
  31. gpg --armor --encrypt --output $OTP_HOME/$1.otp.asc /dev/stdin
  32. fi
  33. }
  34. function otp_devices () {
  35. reply=($(find $OTP_HOME -name \*.otp.asc | xargs basename -s .otp.asc))
  36. }
  37. compctl -K otp_devices ot