Skip to content

Instantly share code, notes, and snippets.

@Westixy
Last active October 2, 2019 12:03
Show Gist options
  • Save Westixy/e87ca578ae23a85c518d82f70d39dd53 to your computer and use it in GitHub Desktop.
Save Westixy/e87ca578ae23a85c518d82f70d39dd53 to your computer and use it in GitHub Desktop.
bash script to set value inside gopass using vim as editor (this is a little hack, some special chars can break it)
#!/bin/bash
# usage: gset.sh <GOPASS_KEY_PATH> <IDENTIFIER> <VALUE>
# set a unique value on an item
# for password use '-o' as key
GOPASS_KEY=$1
IDENT=$(echo "$2" | sed 's_/_\\\\/_g')
VALUE=$(echo "$3" | sed 's_/_\\\\/_g')
if [[ "$IDENT" = "-o" ]] ;then
export EDITOR="vim '+:1,1 s/.*/$VALUE/' +:wq"
else
# if identifier is found, edit it, else add it at the end
export EDITOR='vim "+if search('\'$2': .*'\'') | s/.*/'$IDENT': '$VALUE'/ | else | \$s/\$/\\r'$IDENT':\ '$VALUE'/ | endif" +:wq'
fi
gopass edit $GOPASS_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment