It’s Cybersecurity Awareness Month! Join our interactive training session, or learn about security and AI from 1Password experts.
Forum Discussion
Former Member
4 years agocli v2.6.0: Editing items with `op item get | jq | op item edit` does not create new fields
I'm reading the output of op item get (v2.6.0) and adding a brand new field to an existing section using jq . It looks like this:
op item get "top-secret" |
jq '.fields + [{
i...
Former Member
4 years agoThanks for adding the feature request Andi!
I think my script above is broken with multiline values, to account for that, I'll be joining fields with the null character (and hope it's both part of the content itself), then using xargs
to pass them as arguments to op item edit
:
```sh
function edit_item_args () {
# reads the existing op item into $remote
# then grabs all field names to delete
jq -j -r --exit-status \
--argjson remote "$(op item get "some-item")" \
'def fields_to_cli($delete_field_names):
map(
(.section.id // "") + (if .section then "." else "" end) + (.label | gsub("\."; "\."))+
"["+(if .purpose == "PASSWORD" then "password" else "text" end)+"]="+.value
) +
($delete_field_names | map((.| gsub("\."; "\."))+"[delete]=")) |
sort |
join("\u0000");
(($remote.fields | map(.id // .label)) - map(.id // .label)) as $to_delete |
fields_to_cli($to_delete)' "$1"
}
finally, call our function, pipe to xargs and hope for the best!
edit_item_args <(jq '.fields + [{
id: "my-new-field",
type: "STRING",
purpose: "",
label: "my-new-field",
value: "very secret",
}]' op item get "some-item") | xargs -0 -r op item edit "some-item" --
```
Still not ideal, but it gets the job done :)