dots/.local/bin/sedi
2021-10-02 11:39:16 -04:00

35 lines
379 B
Bash
Executable File

#!/bin/sh
# Edit a file that requires superuser permissions without running the editor as root
# Substitute for sudo -e that uses doas instead.
if [ -z $1 ]
then
exit
fi
FNAME=$(mktemp)
if [ -e $1 ]
then
cp $1 $FNAME
fi
$EDITOR $FNAME
DIFF=""
if [ -e $1 ]
then
DIFF=$(diff $FNAME $1)
else
DIFF=$(cat $FNAME)
fi
if [ -n "$DIFF" ]
then
doas cp $FNAME $1
fi
rm $FNAME