Posts Tagged ‘Bash’

Useful Bash Scripts

Tuesday, April 7th, 2009
Bash
Image via Wikipedia

Here’s a couple of bash scripts I’ve written recently that might be of use to someone.They work well under Ubuntu, and should work under any GNU/Linux or Unix system with the suitable software installed.

Improved “svn diff” command (ignores whitespace, colour highlights output, requires colordiff) – I put it in /usr/local/bin/svndiff:

#!/bin/bash svn diff -x -w $@ | colordiff

Improved recursive grep command (greps recursively, ignores files in the .svn folders, ignores temporary files, highlights output in colour) – I put it in /usr/local/bin/grepr:

#!/bin/sh SEARCHTERM=$1; shift; find . -type f -a -not -iname "*~" -a -not -iwholename "*/.svn/*" -exec grep -H --color=auto $@ "$SEARCHTERM" "{}" \;

You might also be interested in my previous “whoops I deleted files without telling svn” post here.

Reblog this post [with Zemanta]
Bookmark and Share

SVN Hint: Automatically removing manually deleted files from SVN

Friday, February 6th, 2009
Bash
Image via Wikipedia

When deleting files in a working copy of an SVN repository you should do it on the command line: svn rm [filename]. If, however, you don’t do this (e.g. delete through a gui, or just do “rm” without the “svn“) then SVN gets confused, and puts a “!” in it’s status before all the deleted files. If you svn update, all the files will be recovered, rendering all your time spent deleting them wasted. Really you should use svn rm, but if it’s already too late for that, you can use this bash fragment to delete the files from SVN:

svn status | grep "^\!" | sed 's/^\! *//g' | xargs svn rm

This command does a status command, finds all lines starting with “!“, and then extracts the filename and runs it through “svn rm” – really deleting the file.

Caveats:

  1. Manually deleted files are not the only things that makes svn use “!” – so beware of this! Ensure you do really want to delete all those files!
  2. This works for filenames which are all_one-word/without/any.spaces but I am not sure if it will work or not for filenames with spaces in.
  3. Use at your own risk. The code is simple enough so you should be able to grok what it does.

Enjoy!

Reblog this post [with Zemanta]
Bookmark and Share