diff --git a/CHANGES.md b/CHANGES.md index a82dcef..9ff16fd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +0.3.7 +===== ++ compress temporary files with gzip (BestSpeed) ++ default to bash instead of sh if it exists and SHELL is not specified + 0.3.6 ===== + output gargs version in help. diff --git a/main.go b/main.go index 3c819f1..8329215 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( ) // Version is the current version -const Version = "0.3.6" +const Version = "0.3.7" // ExitCode is the highest exit code seen in any command var ExitCode = 0 diff --git a/process/process.go b/process/process.go index e259997..7bc01ef 100644 --- a/process/process.go +++ b/process/process.go @@ -3,6 +3,7 @@ package process import ( "bufio" "bytes" + "compress/gzip" "fmt" "io" "io/ioutil" @@ -31,7 +32,11 @@ var prefix = fmt.Sprintf("gargs.%d.", os.Getpid()) func getShell() string { shell := os.Getenv("SHELL") if shell == "" { - shell = "sh" + if _, err := os.Stat("/bin/bash"); err == nil { + shell = "bash" + } else { + shell = "sh" + } } return shell } @@ -219,15 +224,21 @@ func oneRun(command string, callback CallBack, env []string) *Command { if err != nil { return newCommand(bufio.NewReader(bytes.NewReader(res)), tmp, command, err) } - btmp := bufio.NewWriter(tmp) - _, err = io.CopyBuffer(btmp, bpipe, res) + + gtmp, err := gzip.NewWriterLevel(tmp, gzip.BestSpeed) + if err != nil { + return newCommand(bufio.NewReader(bytes.NewReader(res)), tmp, command, err) + } + + _, err = io.CopyBuffer(gtmp, bpipe, res) if err != nil { return newCommand(bufio.NewReader(bytes.NewReader(res)), tmp, command, err) } if c, ok := opipe.(io.ReadCloser); ok { c.Close() } - btmp.Flush() + gtmp.Flush() + gtmp.Close() _, err = tmp.Seek(0, 0) if err == nil { err = cmd.Wait() @@ -237,7 +248,9 @@ func oneRun(command string, callback CallBack, env []string) *Command { err = e } } - return newCommand(bufio.NewReader(tmp), tmp, command, err) + var grdr *gzip.Reader + grdr, err = gzip.NewReader(tmp) + return newCommand(bufio.NewReader(grdr), tmp, command, err) } // istring holds a command and an index.