op and Fish Shell environment

rrossonrrosson
edited September 6 in CLI

Has anyone figured out how to get op cli tool setup to use with the fish shell yet? Also looking for possibilities to pull in passwords to use with iTerm as a side note. :)


_1Password Version:6.8.1
_OS Version:macOS Sierra

Comments

  • cohixcohix

    AgileBits Team Member

    @rrosson Thanks for the interest in the tool :) We're definitely looking to gauge the interest in different shells that our users like. We could theoretically add a --fish flag on the signin command, but we'll be evaluating those one by one. For now, you can either copy the environment variable name and value from the outputted command (and set the variable in the "fish" way), or you can use the --output=raw flag on the signin command and then pass the raw token to any command using the --session=[token] flag on any command.

    You can see all the session management options in our documentation!

    As for use with iTerm, what did you have in mind?

  • @cohix Thanks I will dig deeper in to the fish shell, was just trying to avoid on re-inventing the wheel. :)

    As for iTerm I was wondering if anyone put anything together that would take advantage of calling 1P when ssh'ing to a host.

  • cohixcohix

    AgileBits Team Member

    SSH makes things hard as it uses interactive prompts for non-pubkey authentication, so automating that is a little difficult. We're investigating ways to make this easier. For example, if your SSH key is in a 1Password document and you want to use it on a machine temporarily, you could write a script that:

    • downloads the key into the ~/.ssh directory
    • performs the ssh command with the -i flag to specify the keyfile to use
    • delete the key

    Something to consider :)

  • I think I have figured out what to add to my fish shell environment. Included below:
    ### 1password CLI (op) ###
    set -x OP_SESSION_<shorthand name> $1
    eval (op signin <shorthand name>)

    If anyone has any better solutions please share.
    -Ron

  • cohixcohix

    AgileBits Team Member

    @rrosson Nice! Would that be a shell script? What is the argument being passed into the script ($1) ?

    I'm a zsh man myself so I'm not too familiar with fish.

  • This is added to your config.fish located in ~/.config/fish. The '$1' is the place holder for the token that is given once you have successfully signed into 1P.

    Fish shell does not include export, so a little googling around of converting export to something fish could use led me to what I shared. Hopefully another user who uses the fish shell will comes by and sees it and corrects it if I made any errors or assumptions. :)

  • rickfillionrickfillion Junior Member

    AgileBits Team Member

    @rrosson : regarding iTerm... have you taken a look at how sudolikeaboss works? It's built to work with 1Password for Mac, but if I'm remembering how it works correctly, doing something like it for op would be feasible.

    https://github.com/ravenac95/sudolikeaboss

    Rick

  • smerrellsmerrell
    edited September 18

    I made a function in Fish that looks like this

    function op_signin
          set cmd (op signin $argv | sed '/#/d; s/export/set -gx/; s/=/ /; s/"//g')
          eval $cmd
    end
    

    You could either use it like op_signin <shorthand_name> or replace the $argv with the shorthand name.

    You likely could also put the two lines in the function in your fish.config I just don't want it to prompt me to log into op every time I open a new shell.

  • @smerrell Thank You, Thank you,

  • cohixcohix

    AgileBits Team Member

    That's awesome @smerrell, thank you for posting that!

  • \o/ I never found a tidy solution for this.. awesome!

  • rickfillionrickfillion Junior Member

    AgileBits Team Member

    :)

Leave a Comment