add script and update readme
This commit is contained in:
parent
02af830d72
commit
de0ad58d97
@ -1,2 +1,3 @@
|
||||
# doasedit
|
||||
a Bash script replacement for sudoedit using doas
|
||||
a Bash script replacement for sudoedit using doas.
|
||||
[Inspired by this Reddit comment.](https://www.reddit.com/r/linux/comments/l6y7nv/is_doas_a_good_alternative_to_sudo/gl4hs42?utm_source=share&utm_medium=web2x&context=3)
|
||||
|
27
doasedit
Executable file
27
doasedit
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
destfile_pfx="$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32)"
|
||||
|
||||
while [ -d "/tmp/doasedit/$destfile_pfx" ]; do
|
||||
destfile_pfx="$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32)"
|
||||
done
|
||||
|
||||
mkdir -p /tmp/doasedit/$destfile_pfx
|
||||
srcfile="$(realpath $1)"
|
||||
|
||||
doas cp $srcfile /tmp/doasedit/$destfile_pfx/edit
|
||||
doas chown -R $USER:$USER /tmp/doasedit/$destfile_pfx/edit
|
||||
doas cp $srcfile /tmp/doasedit/$destfile_pfx/file
|
||||
|
||||
$EDITOR /tmp/doasedit/$destfile_pfx/edit
|
||||
|
||||
|
||||
cat /tmp/doasedit/$destfile_pfx/edit | doas tee /tmp/doasedit/$destfile_pfx/file 1>/dev/null
|
||||
|
||||
if cmp -s "/tmp/doasedit/$destfile_pfx/file" "$srcfile"; then
|
||||
echo "Skipping write; no changes."
|
||||
else
|
||||
doas mv -f /tmp/doasedit/$destfile_pfx/file $srcfile
|
||||
fi
|
||||
|
||||
rm -rf /tmp/doasedit/$destfile_pfx
|
Loading…
Reference in New Issue
Block a user