Tag: sed

Check all vim colorschemes for minor issues

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

 

Enhanced by Zemanta

Compare files excluding certain lines.

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:

diff file <(sed 's/ABC/abc/g' file2)
Enhanced by Zemanta

Cont: Get yourself some more conkyrc files.

Table of contents for conkyrc

  1. Get yourself some conkyrc files.
  2. Script to get yourself some conkyrc files
  3. Cont: Get yourself some more conkyrc files.

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