Skip to content

Instantly share code, notes, and snippets.

@mattcanty
Created November 7, 2020 15:16
Show Gist options
  • Save mattcanty/b5cda46f10539a73ffd7bc574b0b2f3a to your computer and use it in GitHub Desktop.
Save mattcanty/b5cda46f10539a73ffd7bc574b0b2f3a to your computer and use it in GitHub Desktop.
1Password CLI Shell Functions
otp() {
ITEM_NAME=$1
TOTP=$(op get totp $ITEM_NAME --vault Personal 2>&1)
if [[ $TOTP == *"You are not currently signed in"* ]]; then
eval $(op signin my.1password.com)
totp $ITEM_NAME
return
fi
echo $TOTP | xclip -sel clip
echo "TOTP copied to the clipboard ($TOTP)"
}
pass() {
ITEM_NAME=$1
ITEM=$(op get item $ITEM_NAME --vault Personal 2>&1)
if [[ $ITEM == *"You are not currently signed in"* ]]; then
eval $(op signin my.1password.com)
pass $ITEM_NAME
return
fi
PASSWORD=$(echo $ITEM | jq -r '.details.fields[] | select(.name == "password") | .value')
echo $PASSWORD | xclip -sel clip
echo "Password copied to the clipboard"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment