.dotfiles/.local/bin/edit

27 lines
450 B
Plaintext
Raw Normal View History

#!/usr/bin/sh
2021-07-09 22:50:17 +00:00
set -e
edit_directory="$HOME/.cache/edit/"
filehash=$(readlink -fn "$1" | md5sum | awk '{ print $1 }')
filedirectory="$edit_directory/$filehash/"
mkdir -p $filedirectory
filepath=$(realpath -s "$filedirectory/$(basename $1)")
user=$(id -un)
group=$(id -gn)
echo "Editing $1 in $filepath as $user:$group"
2021-07-13 00:05:40 +00:00
sudo cp "$1" "$filepath"
sudo chown $user:$group "$filepath"
$EDITOR "$filepath"
2021-07-13 00:05:40 +00:00
sudo cp "$filepath" "$1"
rm "$filepath"