Improve edit script

This commit is contained in:
Tobias Reisinger 2022-04-06 23:50:22 +02:00
parent 4759667811
commit 19fdac4137
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE

View file

@ -7,20 +7,24 @@ edit_directory="$HOME/.cache/edit/"
filehash=$(readlink -fn "$1" | md5sum | awk '{ print $1 }')
filedirectory="$edit_directory/$filehash/"
mkdir -p $filedirectory
mkdir -p "$filedirectory"
filepath=$(realpath -s "$filedirectory/$(basename $1)")
basename=$(basename "$1")
filepath=$(realpath -s "$filedirectory/$basename")
user=$(id -un)
group=$(id -gn)
echo "Editing $1 in $filepath as $user:$group"
sudo cp "$1" "$filepath"
sudo chown $user:$group "$filepath"
sudo test -e "$1" && (
sudo cp -i "$1" "$filepath"
sudo chown "$user":"$group" "$filepath"
)
$EDITOR "$filepath"
sudo cp "$filepath" "$1"
rm "$filepath"
rm -rd "$filedirectory"