This is not an elegant solution---it is quick and dirty---but it does work on single files and you can use it as a shell script.
It's a sequence of three commands which perform the following:
- Open file in vim (read only mode):
vim -R
- Save the file in plaintext and quit:
-c ":set key= | sav ${filename}.plain | q
- Cat the plaintext file:
cat ${filename}.plain
- (Optionally) delete the plaintext file:
rm ${filename}.plain
In the end you can have a script that also passes the password to the vim command. As a simple script it would be:
filename=$1
password=$2
vim -R -c ":set key= | sav ${filename}.plain | q" -- ${filename} <<< $password && cat ${filename}.plain && rm ${filename}.plain
where the first argument is the filename and the second is the password.
Of course, there are several things you should keep in mind:
- Make sure you're not overwriting existing files which happen to have the name
${filename}.plain
.
- The password will appear on the command line and be saved in history. If you want to be prompted for a password every time, remove the
<<< $password
part.
:help less
. Unfortunately it does still require pressingq
(no:
needed) to exit.