mirror of
https://github.com/notwa/rc
synced 2024-11-05 06:49:03 -08:00
18 lines
420 B
Text
18 lines
420 B
Text
|
#!/bin/zsh
|
||
|
# http://unix.stackexchange.com/a/37887
|
||
|
#[ -n "${ZSH_VERSION:-}" ] && local -A EDITOR ${=EDITOR}
|
||
|
# TODO: find actually working way of portably splitting word cmds, zsh/bash
|
||
|
|
||
|
if [ $# -eq 0 ]; then
|
||
|
$=EDITOR
|
||
|
return
|
||
|
fi
|
||
|
|
||
|
local needroot=0
|
||
|
for f in $@; do
|
||
|
[ -e "$f" ] && { [ -w "$f" ] || needroot=1; }
|
||
|
# TODO: check directory permissions too
|
||
|
done
|
||
|
|
||
|
if [ $needroot -eq 0 ]; then $=EDITOR $@; else sudo -e $@; fi
|