#!/bin/sh CMD="$1" function check_index() { DIR="$1" if [ ! -f "$DIR/.index/NMZ.version" ] ; then echo "$0: '$DIR' is not indexed, use 'create' first."; exit fi } if [ "$CMD" == "create" ] ; then # only work with current directory DIR=`pwd` if [ ! -d "$DIR" ] ; then echo "$0: '$DIR' is not a directory, cannot index."; exit fi if [ -f "$DIR/.index/NMZ.version" ] ; then echo "$0: '$DIR' is alredy indexed, use 'update' instead."; exit fi mkdir "$DIR/.index" mknmz -a $DIR -O "$DIR/.index" exit; fi if [ "$CMD" == "update" ] ; then # only work with current directory DIR=`pwd` if [ ! -d "$DIR" ] ; then echo "$0: '$DIR' does not exist, cannot update."; exit fi check_index $DIR mknmz -a $DIR --exclude=".index" --update="$DIR/.index"; exit; fi if [ "$CMD" == "search" ] ; then # only work with current directory DIR=`pwd` check_index $DIR shift eval namazu -a "'$@'" "$DIR/.index" exit; fi if [ "$CMD" == "list" ] ; then # only work with current directory DIR=`pwd` check_index $DIR shift eval namazu -a -l "'$@'" "$DIR/.index" exit; fi if [ "$CMD" == "files" ] ; then # only work with current directory DIR=`pwd` shift check_index $DIR eval namazu -a -l "'$@'" "$DIR/.index" | while read line ; do echo "=== $line ===" eval cat '"$line"' echo "" echo "" done; #eval namazu -a -l "'$@'" "$DIR/.index" | xargs -n 1 --replace echo "{}" ; cat "{}" exit; fi echo "Usage: $0 [create|update|search|list|files] " exit;