From 193c34e1a584a9b762155ccf53fccf53a8f2b3ae Mon Sep 17 00:00:00 2001 From: Benoit Mortgat Date: Tue, 27 Oct 2015 10:18:17 +0100 Subject: [PATCH] Allow passing file list as a file instead of args Instead of calling cindex file1 file2 ... Use cindex -filelist list Where list contains the following: file1 file2 This makes it possible to index many files in a single command when the length of the command line is limited. --- cmd/cindex/cindex.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmd/cindex/cindex.go b/cmd/cindex/cindex.go index 2129f86..5960b48 100644 --- a/cmd/cindex/cindex.go +++ b/cmd/cindex/cindex.go @@ -51,6 +51,8 @@ Options: skip indexing a file if it has more than this ratio of invalid UTF-8 sequences (Default: %v) -exclude FILE path to file containing a list of file patterns to exclude from indexing + -filelist FILE + path to file containing a list of file paths to index cindex prepares the trigram index for use by csearch. The index is the file named by $CSEARCHINDEX, or else $HOME/.csearchindex. @@ -94,6 +96,7 @@ var ( logSkipFlag = flag.Bool("logskip", false, "print why a file was skipped from indexing") noFollowSymlinksFlag = flag.Bool("no-follow-symlinks", false, "do not follow symlinked files and directories") exclude = flag.String("exclude", "", "path to file containing a list of file patterns to exclude from indexing") + fileList = flag.String("filelist", "", "path to file containing a list of file paths to index") // Tuning variables for detecting text files. // A file is assumed not to be text files (and thus not indexed) if // 1) if it contains an invalid UTF-8 sequences @@ -283,6 +286,23 @@ func main() { } } + if *fileList != "" { + var fileListPath string + if (*fileList)[:2] == "~/" { + fileListPath = filepath.Join(index.HomeDir(), (*fileList)[2:]) + } else { + fileListPath = *fileList + } + if *logSkipFlag { + log.Printf("Loading fileList patterns from %s", fileListPath) + } + data, err := ioutil.ReadFile(fileListPath) + if err != nil { + log.Fatal(err) + } + args = append(args, strings.Split(string(data), "\n")...) + } + if len(args) == 0 { ix := index.Open(index.File()) for _, arg := range ix.Paths() {