How to check if a session is active? (feature request)

cliKingcliKing
Community Member

In shell scripts I want to check that a session is active and valid and that it will still be active for the next x minutes.

The only output I need is an exit code: 0 or 1

AFAIK there is no built in command to do that so with CLI v1 I was using this:

if ! op list vault >/dev/null 2>&1; then
    printf 'No 1Password session. Run \e[35meval $(op signin "$OP_ACCOUNT")\e[m.\n' >&2
    exit 1
fi

With CLI v2, I'm transforming this as:

if ! op vault list >/dev/null 2>&1; then
    printf 'No 1Password session. Run \e[35meval $(op signin)\e[m.\n' >&2
    exit 1
fi

Is there a better way?

op whoami doesn't check the session.
op account get is slower than op vault list (mesured with time).
op user get --me is slow too.

Feature request: new command op signin --check or op session check


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: macOS
Browser:_ Not Provided

Comments

  • cliKingcliKing
    Community Member
    edited September 22

    Cc: @ringerc (you posted a related question a few months ago)

  • jwhettjwhett
    Community Member

    I know this isn't a built-in, but I've been checking for the presence of OP_SESSION_RANDOMSTRING in the environment. grep returns non-zero when there isn't a match so something like env | grep OP_SESSION would give you the switch you're looking for until something is baked into the CLI.

    Hope this helps.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file