Programmatic login status reporting?

Is there a reliable way to programmatically determine whether a given machine is already logged into an atuin sync server or not?

I’m trying to make my “new machine bootstrapping” script idempotent, so I have a lot of if brew_formula_not_installed; then brew install $formula; fi code to skip redundant commands, and I’m struggling to find the best way to handle this for atuin’s sync login.

Re-running atuin login -u myuser -p mypass -k mykey (values passed in from 1Password’s op cli tool though) on an already-logged-in system produces an error message and exits with 1, so my working approach right now is to just always run the login and swallow the stderr output, but this feels sub-optimal.

In my dream world, my code could look like this:

if ! atuin --quiet logged_in; then
  atuin login -u myuser -p mypass -k mykey
fi

The goal being an atuin command that prints whether it’s logged in already or not (but that output can be silenced– or swallowed to /dev/null, I suppose), and critically returns a comparable exit code (0/1 for logged in/out, or vice-versa, whatever.) That command could take a lot of forms too, of course;

  • atuin sync --status
  • atuin login --status
  • atuin status sync –quiet

The exact theoretical syntax is irrelevant to the question though. Am I overlooking something that already exists? Perhaps even if [ -f "$HOME/.local/share/atuin/key" ] might approximate it, but doesn’t guarantee the login is functional.

Thanks for your time and attention!

I would stick with running login regardless, but otherwise you could check the output of atuin status, which differs depending on login

Alternatively, ~/.local/share/atuin/session will be set if the user is logged in

The only other point I’d like to highlight is that it’s super important you run login vs copy the key + session file across. Part of the login process includes ensuring that the user’s database is correctly encrypted, and skipping this step can lead to issues

1 Like

Heard and understood on not copying keys/sessions. Makes complete sense.

atuin status looks like it fits the bill for returning an appropriate exit code based on whether atuin is already logged into a sync server or not.

Re-running atuin login universally was a bit of a pain because it meant I also have to run atuin import auto and atuin sync on every bootstrap run. None of that is particularly ‘fast’ (for an admittedly completely arbitrary and subjective definition of “fast”), so skipping all three commands when it has already been done is worth it.

I’ll post my final solution for posterity here in case someone at some point in the future lucks into Google results not being a complete AI wasteland.

Thanks for the reply!

1 Like