Skip to main content
October 5, 2022
Question

How can I use CLI in a GNU Makefile?

  • October 5, 2022
  • 3 replies
  • 444 views

I'd like to set a GNU Make variable as an OP CLI session so that make commands can use 1Password. Any ideas? I know that I can set it as an environment variable before using make. I'm curious if there is a way to set it inside a makefile.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Browser:_ Not Provided
Referrer: forum-search:https://1password.community/search?Search=Using%20CLI%20in%20a%20Makefile

3 replies

MrC
October 5, 2022

@chriskauffman

Try something like:


all:
eval $$(op signin --account https://my.1password.com) && op item list --format json | jq -c '.[]'

MrC
October 5, 2022

Alternatively, you can set a Make variable, set as an export, and it will be available for use in sub-shells created by Make. Pass the --session option to your commands to refer to it.

```
export OPTOKEN := $(shell op signin --raw --account https://my.1password.com)

all:
op --session $$OPTOKEN item list --format json
```

October 31, 2022

Works great! Thank you @MrC