Created
July 17, 2011 11:00
-
-
Save drm/1087457 to your computer and use it in GitHub Desktop.
Automate nano sudo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nano() { | |
nano=`which nano`; | |
if ([ -e "$1" ] && ! [ -w "$1" ]) || ( ! [ -e "$1" ] && ! [ -w "`dirname $1`" ]); then | |
read -n 1 -p "$1 is not editable by you. sudo [y/N]? " y | |
[ "$y" == "y" ] || [ "$y" == "Y" ] && echo -e "\n" && sudo $nano $@ | |
else | |
$nano $@ | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment