Check all vim colorschemes for minor issues

2013-10-10 2 min read Bash Vim Tips

Here is script that checks all the colorschemes in the current directory and corrects them if possible (Processing of the file is done with simple commands like sed, grep)

Checks that the color_name is same as Filename

Here is the script:

#!/bin/bash -
#===============================================================================
#
#          FILE: check_colors.sh
#
#         USAGE: ./check_colors.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka), 
#      REVISION:  ---
#===============================================================================
cd ~/.vim/colors
for i in *vim
do
    #echo "Processing $i"
    if [[ $(grep -c g:colors_name $i ) -eq 0 ]]; then
        if [[ $(grep -c colors_name $i ) -eq 0 ]]; then
            echo "File $i does not have colorname";
            missing=$missing" $i"
        else
            sed -i.bak '/colors_name/ s/.*/let g:colors_name="'${i//.vim}'"/g' $i
        fi
    else
        if [[ $(grep -c colors_name $i|grep let ) -gt 1 ]]; then
            echo "WARN ----->> File $i has more than one colorsname"
        fi
        colorname=$(grep g:colors_name $i|grep let| sed -e 's/"//g' -e 's/.*=//' |tr -d ' ')
        if [[ ${colorname}.vim != $i ]]; then
            echo "Filename $i does not match colorname $colorname .. correcting "
            sed -i.bak '/colors_name/ s/.*/let g:colors_name="'${i//.vim}'"/g' $i
            #sed -i.bak 's/(.*g:colors_name.*=)/1'${i//.vim}'/g' $i
        fi
    fi
done

if [[ x$missing != x ]] ; then
    echo "Missing colornames in $missing"
fi

 

Continue reading

Compare files excluding certain lines.

2011-10-18 1 min read Bash Fedora Learning Linux

Quick tip, you can use any expression for the sed commands in the (). With this trick you can redirect the stdout of 2 commands to the diff command. This might become very useful, if you want to compare 2 files, excluding the first  line.

diff <(sed '1d' file) <(sed '1d' file2)

More interesting example is where the string ABC is converted to abc before comparing in the second file with the following command:

Continue reading

Cont: Get yourself some more conkyrc files.

2011-10-12 1 min read Bash Learning Linux

Last time we got ourselves some conkyrc files from the ubuntu forums. But that scripts gets the files only from the First page of the thread. Lets extend this further and get the script to get all the conkyrc files.

There are some 1048 pages in the thread, I am showing pages 1 to 3 but you can change 3 to whatever number you want 🙂

count=0
for i in {1..3}
do
    >.test
    >conkyrc
	echo "Getting page $i"
	curl http://ubuntuforums.org/showthread.php?t=281865\&page=$i |\\
         sed -n '// d'|\
         sed 's##\n-----------------------------------\n\n\n#' \
         >conkyrc
	dos2unix conkyrc
	cp conkyrc .test
	while [ $(wc -l .test|sed 's/[^0-9]//g') != 0 ]
	do
		sed -n '1,/------------------------/ p' .test|sed '$d' >conkyrc.$count
		diff .test conkyrc.$count |sed 's/^<.//'|sed '1, /---------------------/ d;2d'>.test
		((count++))
	done
	echo "Files so far are : $count"
done
Enhanced by Zemanta

Script to get yourself some conkyrc files

2011-10-08 1 min read Fedora Learning Linux

Continuing from where we left, here is a script that can do all this for you 🙂

curl http://ubuntuforums.org/showthread.php?t=281865\&page=$i | sed -n '/\\/pr/ p'| sed '// d'| sed 's##\n-----------------------------------\n\n\n#' >conkyrc
	dos2unix conkyrc
	cp conkyrc .test
	while [ $(wc -l .test|sed 's/[^0-9]//g') != 0 ]
	do
		sed -n '1,/------------------------/ p' .test|sed '$d' >conkyrc.$count
		diff .test conkyrc.$count |sed 's/^<.//'|sed '1, /---------------------/ d;2d'>.test
		((count++))
	done

This will create couple of conkyrc.files in the current directory. Each of these is one from the web-page that I mentioned earlier. So, enjoy….

Continue reading

Get yourself some conkyrc files.

2011-10-05 2 min read Fedora Linux

If you are looking for some nice conkyrc files, then you can head over to :

Ubuntu Forums

In this thread you can see some very nice conkyrc files with screenshots. You can browse through the thread and get the one that you like. But if you are like me and would like to download all of them to see the features and commands in each of them then you would need to copy each of these files and paste them separately. But if you have to do everything manually then there’s not much of being on Linux 🙂

Continue reading

Handy one-liners for SED

2010-09-14 0 min read Bash Linux
\"A
Image via Wikipedia

Here are some links to sed one liners, pretty useful if you want to use the power of sed.

<a href="http://www.freearchive.org/o/dd1ebea77f64bdef5982d50e868990202b0bf6f21b42e26ebb0ab1011d6ce546">http://www.freearchive.org/o/dd1ebea77f64bdef5982d50e868990202b0bf6f21b42e26ebb0ab1011d6ce546

<a href="http://www.unixguide.net/unix/sedoneliner.shtml">http://www.unixguide.net/unix/sedoneliner.shtml
<a href="http://sed.sourceforge.net/sed1line.txt">http://sed.sourceforge.net/sed1line.txt <a href="http://www.thegeekstuff.com/2010/06/bash-array-tutorial/">

<a href="http://www.thegeekstuff.com/2010/06/bash-array-tutorial/">http://www.thegeekstuff.com/2010/06/bash-array-tutorial/<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://www.ibm.com/developerworks/linux/library/l-sed1.html">imabonehead: Common threads: Sed by example, Part 1 (ibm.com) <li class="zemanta-article-ul-li"><a href="http://www.thegeekstuff.com/2009/11/unix-sed-tutorial-append-insert-replace-and-count-file-lines/">imabonehead: Unix Sed Tutorial: Append, Insert, Replace, and Count File Lines (thegeekstuff.com) <div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=be4d9a3b-c27c-46eb-8b76-2a1aa1900a4e" alt="Enhanced by Zemanta" /><span class="zem-script more-related pretty-attribution">

Continue reading

bash one liner to change/remove test pattern from config file or text file.

2010-06-25 1 min read Bash Fedora Learning Linux

Problem:

I had a directory with a lot of config files in the ini file format, i.e. name and value separated by equals. Some/all of these contained some directory names and other values which had to be replaced. But there were other place where I should not not replace them, if there was no exact match. I also needed to have a backup copy of the file that I was modifying. Since the number of files that I needed to change was multiple so was quite difficult to do it without using some script.

Continue reading
Older posts