dots/.local/bin/sedi

35 lines
380 B
Plaintext
Raw Normal View History

2021-10-01 20:41:38 -04:00
#!/bin/sh
# Edit a file that requires superuser permissions without running the editor as root
# Substitute for sudo -e that uses doas instead.
2021-10-02 11:24:24 -04:00
if [ -z $1 ]
then
exit
fi
FNAME=$(mktemp)
if [ -e $1 ]
then
cp $1 $fname
fi
2021-10-01 20:41:38 -04:00
2021-10-02 11:24:24 -04:00
$EDITOR $FNAME
DIFF=""
if [ -e $1 ]
then
DIFF=$(diff $FNAME $1)
else
DIFF=$(cat $FNAME)
fi
2021-10-01 20:41:38 -04:00
2021-10-02 11:24:24 -04:00
if [ -n "$DIFF" ]
then
doas cp $FNAME $1
2021-10-01 20:41:38 -04:00
fi
2021-10-02 11:24:24 -04:00
rm $FNAME