fake-editor-change-password.sh (643B)
1 #!/usr/bin/env bash 2 # Fake editor program for testing 'pass edit'. 3 # Changes password to 'Hello World', leaving rest of file intact. 4 # 5 # Intended use: 6 # export FAKE_EDITOR_PASSWORD="blah blah blah" 7 # export EDITOR=fake-editor-change-password.sh 8 # $EDITOR <password file> 9 # 10 # Arguments: <filename> 11 # Returns: 0 on success, 1 on error 12 13 if [[ $# -ne 1 ]]; then 14 echo "Usage: $0 <filename>" 15 exit 1 16 fi 17 18 filename=$1 ; shift ; 19 new_password="${FAKE_EDITOR_PASSWORD:-Hello World}" 20 21 # And change only first line of file 22 # -i.tmp allows editing file in place. Extension needed on Mac OSX 23 sed -i.tmp "1 s/^.*\$/$new_password/g" "$filename" 24 25 exit 0