3 # opswd puts the password of the named service into the clipboard. If there's a
4 # one time password, it will be copied into the clipboard after 10 seconds. The
5 # clipboard is cleared after another 20 seconds.
7 if [[ $# -lt 1 ]]; then
8 echo "Usage: opswd <service>"
14 # If not logged in, print error and return
15 op user list > /dev/null || return
18 # Copy the password to the clipboard
19 if ! password=$(op item get "$service" --fields password 2>/dev/null); then
20 echo "error: could not obtain password for $service"
24 echo -n "$password" | clipcopy
25 echo "✔ password for $service copied to clipboard"
27 # If there's a one time password, copy it to the clipboard after 10 seconds
29 if totp=$(op item get --otp "$service" 2>/dev/null) && [[ -n "$totp" ]]; then
30 sleep 10 && echo -n "$totp" | clipcopy
31 echo "✔ TOTP for $service copied to clipboard"
34 (sleep 20 && clipcopy </dev/null 2>/dev/null) &!
37 # TODO: 2022-03-26: Remove support for op CLI 1
38 autoload -Uz is-at-least
39 is-at-least 2.0.0 $(op --version) || {
40 print -ru2 ${(%):-"%F{yellow}opswd: usage with op version $(op --version) is deprecated. Upgrade to CLI 2 and reload zsh.
41 For instructions, see https://developer.1password.com/docs/cli/upgrade.%f"}
43 # opswd puts the password of the named service into the clipboard. If there's a
44 # one time password, it will be copied into the clipboard after 10 seconds. The
45 # clipboard is cleared after another 20 seconds.
47 if [[ $# -lt 1 ]]; then
48 echo "Usage: opswd <service>"
54 # If not logged in, print error and return
55 op list users > /dev/null || return
58 # Copy the password to the clipboard
59 if ! password=$(op get item "$service" --fields password 2>/dev/null); then
60 echo "error: could not obtain password for $service"
64 echo -n "$password" | clipcopy
65 echo "✔ password for $service copied to clipboard"
67 # If there's a one time password, copy it to the clipboard after 5 seconds
69 if totp=$(op get totp "$service" 2>/dev/null) && [[ -n "$totp" ]]; then
70 sleep 10 && echo -n "$totp" | clipcopy
71 echo "✔ TOTP for $service copied to clipboard"
74 (sleep 20 && clipcopy </dev/null 2>/dev/null) &!