2021-02-20 22:35:06 +00:00
|
|
|
#!/usr/bin/sh
|
|
|
|
|
|
|
|
priv_cmd="sudo"
|
|
|
|
|
|
|
|
if [ -x "$(command -v doas)" ]
|
|
|
|
then
|
|
|
|
priv_cmd="doas --"
|
|
|
|
fi
|
|
|
|
|
|
|
|
edit_directory="$HOME/.cache/edit/"
|
|
|
|
|
2021-02-28 23:06:49 +00:00
|
|
|
filehash=$(readlink -fn "$1" | md5sum | awk '{ print $1 }')
|
|
|
|
filedirectory="$edit_directory/$filehash/"
|
|
|
|
filedirectory=$(realpath -s "$filedirectory")
|
|
|
|
|
|
|
|
mkdir -p $filedirectory
|
|
|
|
filepath=$(realpath -s "$filedirectory/$(basename $1)")
|
2021-02-20 22:35:06 +00:00
|
|
|
|
|
|
|
user=$(id -un)
|
|
|
|
group=$(id -gn)
|
|
|
|
|
|
|
|
echo "Editing $1 in $filepath as $user:$group"
|
|
|
|
|
|
|
|
$priv_cmd cp "$1" "$filepath"
|
|
|
|
$priv_cmd chown $user:$group "$filepath"
|
|
|
|
|
|
|
|
$EDITOR "$filepath"
|
|
|
|
|
2021-02-21 22:13:41 +00:00
|
|
|
$priv_cmd cp "$filepath" "$1"
|
|
|
|
|
|
|
|
rm "$filepath"
|