2022-05-15 21:46:53 +00:00
|
|
|
#!/usr/bin/env sh
|
2021-02-20 22:35:06 +00:00
|
|
|
|
2021-07-09 22:50:17 +00:00
|
|
|
set -e
|
|
|
|
|
2021-02-20 22:35:06 +00:00
|
|
|
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/"
|
|
|
|
|
2022-04-06 21:50:22 +00:00
|
|
|
mkdir -p "$filedirectory"
|
2021-03-03 17:22:02 +00:00
|
|
|
|
2022-04-06 21:50:22 +00:00
|
|
|
basename=$(basename "$1")
|
|
|
|
filepath=$(realpath -s "$filedirectory/$basename")
|
2021-02-20 22:35:06 +00:00
|
|
|
|
|
|
|
user=$(id -un)
|
|
|
|
group=$(id -gn)
|
|
|
|
|
|
|
|
echo "Editing $1 in $filepath as $user:$group"
|
|
|
|
|
2022-04-06 21:50:22 +00:00
|
|
|
sudo test -e "$1" && (
|
|
|
|
sudo cp -i "$1" "$filepath"
|
|
|
|
sudo chown "$user":"$group" "$filepath"
|
2022-04-06 21:51:53 +00:00
|
|
|
) || (
|
|
|
|
touch "$filepath"
|
2022-04-06 21:50:22 +00:00
|
|
|
)
|
2021-02-20 22:35:06 +00:00
|
|
|
|
|
|
|
$EDITOR "$filepath"
|
|
|
|
|
2021-07-13 00:05:40 +00:00
|
|
|
sudo cp "$filepath" "$1"
|
2021-02-21 22:13:41 +00:00
|
|
|
|
|
|
|
rm "$filepath"
|
2022-04-06 21:50:22 +00:00
|
|
|
rm -rd "$filedirectory"
|