DEV Community

Merlier
Merlier

Posted on

1password cli script

For those using 1password to manage their passwords,there is 1password command-line tool to script the retrieve of your passwords.

Here I'll just share some useful commands to script your password manager.

Requirements:

Log in

login() {
    eval $(op signin my)
}
Enter fullscreen mode Exit fullscreen mode

Log out

login() {
    op signout
}
Enter fullscreen mode Exit fullscreen mode

Retrieve password

To retrieve with jq a password from sections details or field details:

echo "$(op get item MyITEM --vault MyTeamVAULT | jq -r 'if .details.sections[0] == null then .details.fields[] |select(.designation=="password").value else .details.sections[].fields[] | select((.n=="password") or (.t=="Password")).v end'
Enter fullscreen mode Exit fullscreen mode

You can modify this command to retrieve other fields than password.

P.S. jq could be used with curl to parse JSON result and do some interesting scripting tasks.

Have fun
:)

Top comments (0)