Trace this

Hire me

Surprise me

Follow this

Read this

Get more

Praise these

Respect this

Conforms to

F**k spammers

WI - [W]riteable checker for v[I]m

Jakob Westhoff (one of my usergroup fellows) created a tiny but very efficient bash script to avoid a big annoyance: I'm using "sudo" on my work station to not have the need to completly switch to root for administrative tasks. Still I usually forget to type "sudo" when I intend to edit a file with is not writeable for my current user. I asume people with similar environments know that problem. WI ([W]riteable checker for v[I]m) wraps around VIM on startup and checks the file permissions. If you may not edit the file, WI asks you if you want to start VI through sudo or quit.

I tried removing the '~' from after the equals sign and the code executes but does nothing after I select yes. Any idea why it might be doing that? I'm running GNU bash, version 2.05b.0(1)-release (powerpc-apple-darwin8.0)

Well, I got it to work, what I had to do was remove the regexp entirely. I can only type 'y' for the script to execute properly but that shouldn't be a problem. Thanks for this script, very useful! Don't know why I didn't think of it before =) Here is what my script looks like now in case you are curious. I commented the lines that I changed from the original.

VIM=/usr/bin/vim # This is where my vim binary is located
SUDO=/usr/bin/sudo

if [ -e $1 ] && [ ! -w $1 ]
then
read -er -p "The file $1 is not writable. Edit it as root? [yes/NO] " answer # This line was to long for my default terminal size, so I shortened it
if [[ "$answer" = "y" ]] # had to remove regex and make it a static comp
arison
then
$SUDO $VIM $*
fi
else
$VIM $*
fi
</pre>