A blog about software development, primarily in Java and about web applications.

Showing posts with label Cygwin. Show all posts
Showing posts with label Cygwin. Show all posts

Friday, March 19, 2010

Cygwin 1.7 Upgrade

I'm a big fan of Cygwin and have used it for years. Without it, it's possible for me to be productive on Windows. The latest version of Cygwin is 1.7. This version changed a few things for.

The first was one they warned about, how Cygwin stores mount points. These are no longer stored in the Windows registry, but are instead read from /etc/fstab. Cygwin comes with a script who's purpose appears to be to create this file for you, but when I ran it nothing happened. So I was left creating my own /etc/fstab. Here's what mine looks like:

C:/cygwin/bin /bin ntfs binary,user 0 0
C:/cygwin/etc /etc ntfs binary,user 0 0
C:/cygwin/home /home ntfs binary,user 0 0
C:/cygwin/var /var ntfs binary,user 0 0
C: /c ntfs binary,user 0 0
C:/Documents\040and\040Settings/don/Application\040Data /n ntfs binary,user 0 0
C:/Documents\040and\040Settings/don/My\040Documents /m ntfs binary,user 0 0
W: /w ntfs binary,user 0 0
Y: /y webdrive binary,user 0

The second issue I ran into was that I didn't have /bin or /usr/bin in my PATH. The previous versions of bash/cygwin did this for me. I actually had a line in my .profile commented out that would have done this. I simply put it back in and was good to go.

So far these are the only issues I've had with the upgrade and they were relatively easy to fix.

Thursday, May 8, 2008

Recursively Adding Files With Subversion

This script is for people who use the command line version of Subversion (SVN). I often use SVN's command line tools in Cygwin rather than in my IDE, eclipse. This is just Bash script that runs the svn stat command, pulls out all of the files whose status line starts with a question mark, and runs the svn add command on them.

You need to be cautious, if you have set up your svn:ignore property or your SVN config file to ingore temporary files this will blindly add them. After that, you can use the svn revert filename command to un-add them.

###
#.Name
# svnadd
#.What
# recursively finds all of the new files via the 'svn stat' command
# and runs the 'svn add' command on each one.
###

case "$1" in
-t) SVN_CMD="echo svn"
;;
-h)
echo Usage: $(basename 0) [-t|-h]
exit 1;
;;
esac

: ${SVN_CMD:=svn}

for f in $(svn stat | awk '/^?/ {print $2}')
do
$SVN_CMD add "$f"
done

Find and Grep with Subversion and Cygwin

Subversion (SVN) creates .svn directories to store information. These get in the way of the Unix/Cywin find command. Here's a Bash shell script that will ignore all of the .svn directories for you.

#!/bin/bash
#
#.Name
# sfind
#.Title
# Find Command for Subversion Workspaces
#.Author
# Don Mitchell (10/2005)
#.What
# Strips out the .svn directories when using the Unix find command.
#

if [ $# -lt 2 ]
then
echo Usage: $(basename $0) [path] [expression...]
fi

path="$1"
shift

find "${path}" ! -wholename '*/.svn/*' -a ! -wholename '*~' \
-a ! -wholename "*/.*.swp" -a "$@"


I put this script in my PATH and then add a few aliases to make it easier to invoke.

alias sf='sfind'

This alias just abbreviates the actual name I gave the shell script. I should have just renamed the shell script. Example: sf . -name "*Foo*.java"

alias sff='sfind . -type f -print0 | xargs -0 grep'

This alias, sff, combines grep with find, grepping for the specified pattern in all files under the current directory. Example: sff SOME_CONSTANT_NAME

alias sfg='sfind . -name "*.java" -print0 | xargs -0 grep'

This alias, does the same thing as my sff alias, but it only greps in Java files and ignores everything else.

  • Example: sfg someMethodName

  • Example: sfg -l someMethodName # list just the file names containing that mehtod



alias sfn='sfind . -name '

This alias is another quick shortcut, but I rarely use it. For example, sfn "*Dao.java" will list all of the files under the current directory that end in Dao.java.