Skip to content

Instantly share code, notes, and snippets.

@OndraZizka
Created March 7, 2012 23:02
Show Gist options
  • Save OndraZizka/1996990 to your computer and use it in GitHub Desktop.
Save OndraZizka/1996990 to your computer and use it in GitHub Desktop.
#!/bin/bash
function usage {
echo
echo " Usage: testsuite/tools/showSrc.sh <part-of-file-name>"
echo
}
## Determine this script's location ("Tools" home dir).
scriptPath="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
# For the case when called through a symlink
scriptPath=`readlink -f "$scriptPath"`
scriptDir=`dirname $scriptPath`
#############
if [ "$1" = "" ] ; then usage; exit 1; fi
## Pick an IDE.
EDITOR=${EDITOR:-vi}
if [ "$IDE" = "" ] && which netbeans &>/dev/null; then IDE=netbeans; fi
if [ "$IDE" = "" ] && which eclipse &>/dev/null; then IDE=eclipse; fi
if [ "$IDE" = "" ]; then
echo " No \$IDE set, using \$EDITOR - $EDITOR."
IDE=$EDITOR;
fi
## Path restriction.
if [ "$2" != "" ] ; then PATH_MASK="-path \\*$2\\*";
else PATH_MASK="-path 'testsuite/*'";
fi
set -x
FIND="find $scriptDir/../.. -name '*$1*.java' -or -name '*$1*.xml' $PATH_MASK";
echo $FIND;
## Prevent killing the IDE with hundreds of files.
NUM=$( $FIND | wc -l )
echo $NUM
if [[ $NUM -ge 30 ]] ; then
echo " ERROR: More than 30 files found, not passing to the IDE to prevent overload.";
$FIND | head -60
echo "..."
exit 2;
fi
SOURCES=`$FIND`
if [ "" == "$SOURCES" ] ; then
echo "No sources found.";
exit 0;
fi;
echo " Opening $NUM files with $IDE."
$IDE $SOURCES;
@OndraZizka
Copy link
Author

ondra@lenovo:~/work/AS7/ozizka-git$ testsuite/tools/showSrc.sh Cluster

  • FIND='find /home/ondra/work/AS7/ozizka-git/testsuite/tools/../.. -name '''Cluster.java''' -or -name '''Cluster.xml''' -path '''testsuite/*''''
  • echo find /home/ondra/work/AS7/ozizka-git/testsuite/tools/../.. -name ''''Cluster.java'''' -or -name ''''Cluster.xml'''' -path ''''testsuite/''''
    find /home/ondra/work/AS7/ozizka-git/testsuite/tools/../.. -name 'Cluster.java' -or -name 'Cluster.xml' -path 'testsuite/
    '
    ++ wc -l
    ++ find /home/ondra/work/AS7/ozizka-git/testsuite/tools/../.. -name ''''Cluster.java'''' -or -name ''''Cluster.xml'''' -path ''''testsuite/*''''
  • NUM=0
  • echo 0
    0
  • [[ 0 -ge 30 ]]
    ++ find /home/ondra/work/AS7/ozizka-git/testsuite/tools/../.. -name ''''Cluster.java'''' -or -name ''''Cluster.xml'''' -path ''''testsuite/*''''
  • SOURCES=
  • '[' '' == '' ']'
  • echo 'No sources found.'
    No sources found.
  • exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment