1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 06:29:02 -08:00

more work on fixing up e

This commit is contained in:
Connor Olding 2021-10-11 19:48:31 -07:00
parent c2c2b7db5f
commit 06647c9d66

16
sh/e
View file

@ -15,7 +15,7 @@ e() { ### @-
### ```
[ -z "$ZSH_OPTIONS" ] || setopt local_options sh_word_split
local f= d= running= editor= needroot=0
local d= f= temp= running= editor= needroot=0
editor="${EDITOR%% *}"
@ -27,8 +27,8 @@ e() { ### @-
fi
done) || return
for f in "$@"; do
f="$(readlink -f "$f")" || continue
for f; do
temp="$(readlink -f "$f")" && f="$temp"
[ -z "$MSYSTEM" ] || f="$(cygpath -u "$f")" || continue
@ -42,21 +42,21 @@ e() { ### @-
d="$f"
while [ "${d%/*}" != "$d" ]; do
d="${d%/*}"
# NOTE: this gets weird with the root directory, not sure how to handle
[ -e "$d" ] && [ ! -w "$d" ] && { needroot=1 && break; }
[ -w "$d" ] && break
[ -e "$d" ] && { needroot=1; break; }
done
[ $needroot -eq 1 ] && break
[ $needroot = 1 ] && break
# easy: file just doesn't exist
done
if [ $needroot -eq 1 ] && [ -n "$MSYSTEM" ]; then
if [ $needroot = 1 ] && [ -n "$MSYSTEM" ]; then
# this pretty much never happens, because permissions are so busted, but...
printf "NOTE: you need root permissions, but this is Windows." >&2
printf " this probably isn't going to work." >&2
pause
$EDITOR "$@"
elif [ $needroot -eq 0 ]; then
elif [ $needroot = 0 ]; then
$EDITOR "$@"
else
sudo -e "$@"