WI - [W]riteable checker for v[I]m - Blog - Open Source - schlitt.info

schlitt.info - php, photography and private stuff

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.

#!/bin/sh VIM=/usr/bin/vim SUDO=/usr/bin/sudo if [ -e $1 ] && [ ! -w $1 ] then read -er -p "The file $1 is not writable. Do you want to edit it as root? [yes/NO] " answer if [[ "$answer" =~ "y|yes|yeah|j|ja" ]] then $SUDO $VIM $* fi else $VIM $* fi

Really nice. Thanks Jakob!

P.S.: Don't forget to install phpDocumentor for VIM! ;)

If you liked this blog post or learned something, please consider using flattr to contribute back: .



Add new comment

Fields with bold names are mandatory.