Skip to content

Instantly share code, notes, and snippets.

@drm
Created Jul 17, 2011
Embed
What would you like to do?
Automate nano sudo
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