Skip to content

Instantly share code, notes, and snippets.

@epleterte
Created June 20, 2017 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epleterte/f131452cc8d562249fb172687cb474fc to your computer and use it in GitHub Desktop.
Save epleterte/f131452cc8d562249fb172687cb474fc to your computer and use it in GitHub Desktop.
I sometimes forget to sudo my vim
#!/bin/bash -ue
# Christian Bryn <chr.bryn@gmail.com> 2016
# License: WTFPL
# Easy-to-use wrapper for sudo that helps you remember to launch vim with sudo when needed
# Stick this in ~/bin/
# autodetection of editor:
#cmd=$( which $EDITOR )
#...does not work as soon as this file is in path, right...if it's called the same as EDITOR, of course ('vim')
# default editor path:
[[ -z "${cmd:-}" ]] && cmd="/usr/bin/vim"
for f in "$@";
do
[[ -f "${f}" ]] || continue
if [[ ! -w "${f}" ]]
then
while :;
do
read -p "'${f}' is not writable - launch with sudo? [y/n]"
case $REPLY in
y|Y)
cmd="sudo ${cmd}"
break
;;
n|N)
break
;;
esac
done
fi
[[ "${REPLY:-}" == "" ]] || break
done
${cmd} "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment