From 19fdac41373ac64754c59b1931d507e7a5f44b73 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Wed, 6 Apr 2022 23:50:22 +0200 Subject: [PATCH] Improve edit script --- .local/bin/edit | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.local/bin/edit b/.local/bin/edit index eb253aa..7802b03 100755 --- a/.local/bin/edit +++ b/.local/bin/edit @@ -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"