Skip to content

Instantly share code, notes, and snippets.

@martinos
Created November 26, 2010 20:41
Show Gist options
  • Select an option

  • Save martinos/717195 to your computer and use it in GitHub Desktop.

Select an option

Save martinos/717195 to your computer and use it in GitHub Desktop.
Auto sudo vi
function vi {
LIMIT=$#
local otherfile=0
for (( i=1; i<=$LIMIT; i++ ))
do
eval file='$'$i
if [[ -e $file && ! -O $file ]]
then
otherfile=1
fi
done
if [[ $otherfile == 1 ]]
then
sudo -k
sudo vi "$@"
else
command vi "$@"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment