From 3f5402e2687475d83ec98613dc93373620e5ce57 Mon Sep 17 00:00:00 2001 From: Ricky Medina Date: Mon, 24 Jan 2022 09:21:34 -0500 Subject: feat(1password): add plugin for 1password (#8884) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/1password/1password.plugin.zsh | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 plugins/1password/1password.plugin.zsh (limited to 'plugins/1password/1password.plugin.zsh') diff --git a/plugins/1password/1password.plugin.zsh b/plugins/1password/1password.plugin.zsh new file mode 100644 index 000000000..5af5ebb2b --- /dev/null +++ b/plugins/1password/1password.plugin.zsh @@ -0,0 +1,46 @@ +if (( ${+commands[op]} )); then + eval "$(op completion zsh)" + compdef _op op +fi + +# opswd puts the password of the named service into the clipboard. If there's a +# one time password, it will be copied into the clipboard after 5 seconds. The +# clipboard is cleared after another 10 seconds. +function opswd() { + if [[ $# -lt 1 ]]; then + echo "Usage: opswd " + return 1 + fi + + local service=$1 + + # If not logged in, print error and return + op list users > /dev/null || return + + local password + # Copy the password to the clipboard + if ! password=$(op get item "$service" --fields password 2>/dev/null); then + echo "error: could not obtain password for $service" + return 1 + fi + + echo -n "$password" | clipcopy + echo "✔ password for $service copied to clipboard" + + # If there's a one time password, copy it to the clipboard after 5 seconds + local totp + if totp=$(op get totp "$service" 2>/dev/null) && [[ -n "$totp" ]]; then + sleep 10 && echo -n "$totp" | clipcopy + echo "✔ TOTP for $service copied to clipboard" + fi + + (sleep 20 && clipcopy /dev/null) &! +} + +function _opswd() { + local -a services + services=("${(@f)$(op list items --categories Login 2>/dev/null | op get item - --fields title 2>/dev/null)}") + [[ -z "$services" ]] || compadd -a -- services +} + +compdef _opswd opswd -- cgit v1.2.3-70-g09d2 From 11a87eac47c579366620f995330532f47dc651f2 Mon Sep 17 00:00:00 2001 From: Gheritarish Date: Fri, 28 Jan 2022 13:47:41 +0100 Subject: chore(1password): fix comments to follow code (#10634) --- plugins/1password/1password.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/1password/1password.plugin.zsh') diff --git a/plugins/1password/1password.plugin.zsh b/plugins/1password/1password.plugin.zsh index 5af5ebb2b..9398b02b4 100644 --- a/plugins/1password/1password.plugin.zsh +++ b/plugins/1password/1password.plugin.zsh @@ -4,8 +4,8 @@ if (( ${+commands[op]} )); then fi # opswd puts the password of the named service into the clipboard. If there's a -# one time password, it will be copied into the clipboard after 5 seconds. The -# clipboard is cleared after another 10 seconds. +# one time password, it will be copied into the clipboard after 10 seconds. The +# clipboard is cleared after another 20 seconds. function opswd() { if [[ $# -lt 1 ]]; then echo "Usage: opswd " -- cgit v1.2.3-70-g09d2