bash script to change vim colorscheme based on the available themes

\"MacVim
Image via Wikipedia

Here\’s one script that you may find useful. A little variation or wrapper for this script can make your life colorful 🙂

You can write a wrapper to this to take one of the inputs randomly and then use it in alias to start vim.

#!/bin/bash –
#===============================================================================
#
#          FILE:  change_vim_colorscheme.sh
#
#         USAGE:  ./change_vim_colorscheme.sh
#
#   DESCRIPTION: Change the vim colorscheme from command prompt
#
#       OPTIONS:  —
#  REQUIREMENTS:  —
#          BUGS:  —
#         NOTES:  —
#        AUTHOR:  Amit Agarwal (AKA), [email protected]
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  02/02/2010 10:30:07 PM IST
#      REVISION:  —
#===============================================================================

#Change the directory to where we will find all colors and then print them 🙂
cd ~/.vim/colors
for i in *.vim
do
echo \”${i%.vim}\”
done
#Read the choice of the user

read -p \”Enter one of the colorschemes :: \” choice
file=~/.vim/colors/$choice.vim
if [ ! -f $file ]
then
echo \”Colorscheme file \”$file\” does not exist\”
exit -1
fi

#Do the susbstitution in new file in /tmp
sed \’s#\\(^ *colorscheme\\).*#\\1 \’$choice\’#\’ ~/.vimrc > /tmp/vimrc
diff ~/.vimrc /tmp/vimrc
read -p \”Do you want to make the changes (y/n) :: \” yn
if [ $yn = \”y\” ]
then
echo {/tmp/,~/.}vimrc
cp {/tmp/,~/.}vimrc
else
echo \”Modified changes are available in /tmp/vimrc\”
fi

\"Reblog

5 thoughts on “bash script to change vim colorscheme based on the available themes”