Skip to content

Commit

Permalink
[bin] Fix sudoedit when file doesn't exist yet
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelRobitaille committed Oct 10, 2022
1 parent 6618a97 commit 1cbc578
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/sudoedit
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/zsh

tmp="$(mktemp /tmp/sudoedit_XXXXXXXXXXXX_$(basename $1))"
touch "$tmp"

if [ -f "$1" ]; then
sudo cat "$1" > "$tmp"
fi

sudo cat "$1" > "$tmp"
inotifywait -m "$tmp" -e create -e moved_to -e close_write 2>/dev/null > \
>(sudo sh -c "while read path action file; do cp '$tmp' '$1'; done") &

Expand Down

0 comments on commit 1cbc578

Please sign in to comment.