Skip to content

Instantly share code, notes, and snippets.

@drm
Created July 17, 2011 11:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drm/1087457 to your computer and use it in GitHub Desktop.
Save drm/1087457 to your computer and use it in GitHub Desktop.
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