summaryrefslogtreecommitdiffstats
path: root/src/core.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-09-15 13:21:51 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-09-15 13:21:51 +0900
commit65d9d416b4300e85304fd158d9df2f6272590849 (patch)
treeed14402021282a9705248bdb46a6d4c7496d14ca /src/core.go
parentfa2f9f1f21bb41ac915a564fbf45b1bf50e40546 (diff)
Change exit status (0: OK, 1: No match, 2: Error/Interrupted)
A la grep. Close #345
Diffstat (limited to 'src/core.go')
-rw-r--r--src/core.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/core.go b/src/core.go
index 96bfdd4c..04b6eab7 100644
--- a/src/core.go
+++ b/src/core.go
@@ -56,7 +56,7 @@ func Run(opts *Options) {
if opts.Version {
fmt.Println(version)
- os.Exit(0)
+ os.Exit(exitOk)
}
// Event channel
@@ -156,12 +156,14 @@ func Run(opts *Options) {
pattern := patternBuilder([]rune(*opts.Filter))
+ found := false
if streamingFilter {
reader := Reader{
func(runes []byte) bool {
item := chunkList.trans(runes, 0)
if item != nil && pattern.MatchItem(item) {
fmt.Println(string(item.text))
+ found = true
}
return false
}, eventBox, opts.ReadZero}
@@ -176,9 +178,13 @@ func Run(opts *Options) {
pattern: pattern})
for i := 0; i < merger.Length(); i++ {
fmt.Println(merger.Get(i).AsString(opts.Ansi))
+ found = true
}
}
- os.Exit(0)
+ if found {
+ os.Exit(exitOk)
+ }
+ os.Exit(exitNoMatch)
}
// Synchronous search
@@ -253,7 +259,10 @@ func Run(opts *Options) {
for i := 0; i < count; i++ {
fmt.Println(val.Get(i).AsString(opts.Ansi))
}
- os.Exit(0)
+ if count > 0 {
+ os.Exit(exitOk)
+ }
+ os.Exit(exitNoMatch)
}
deferred = false
terminal.startChan <- true