zsh/rc/verify_nano_rw.rc

48 lines
1013 B
Plaintext

nano () {
if [ -f "$1" ]; then
if [ -w "$1" ]; then
command nano $*
else
echo "Unwritable file, openning through sudoedit"
VISUAL=nano command sudoedit $*
fi
else
if [ -d "`dirname \"$1\"`" ]; then
if [ -w "`dirname \"$1\"`" ]; then
command nano $*
else
echo "Unwritable file, openning through sudoedit"
VISUAL=nano command sudoedit $*
fi
else
echo "Unexpected result..."
read
command nano $*
fi
fi
}
vim () {
if [ -f "$1" ]; then
if [ -w "$1" ]; then
command vim $*
else
echo "Unwritable file, openning through sudoedit"
VISUAL=vim command sudoedit $*
fi
else
if [ -d "`dirname \"$1\"`" ]; then
if [ -w "`dirname \"$1\"`" ]; then
command vim $*
else
echo "Unwritable file, openning through sudoedit"
VISUAL=vim command sudoedit $*
fi
else
echo "Unexpected result..."
read
command vim $*
fi
fi
}