1

There are config files like wpa_supplicant.conf that can contain plaintext passwords. Sometimes I want to edit such files on my laptop while sitting in a public place, so it would be bad to show my password to everyone.

Is there an editor that can hide the password while I'm editing? Or a wrapper script that takes a regex and a path to a configfile, patches out all lines matching the regex, launches an editor on the resulting copy, patches the lines back in and writes everything back?

thejh
  • 1,457

1 Answers1

0

Something like this should work:

#!/bin/sh
tmpfile="$(mktemp)"
sed "s|$2|###PASSWORDLINE###|" < "$1" > "$tmpfile"
patchfile="$(mktemp)"
diff "$tmpfile" "$1" > "$patchfile"
sensible-editor "$tmpfile"
patch -o "$1" "$tmpfile" "$patchfile"
rm "$patchfile"
rm "$tmpfile"
thejh
  • 1,457