Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Up | 8,001 | 14 days ago | 6 | April 27, 2021 | 28 | apache-2.0 | Go | |||
Ultimate Plumber is a tool for writing Linux pipes with instant live preview | ||||||||||
Script | 4,569 | 69 | 14 days ago | 43 | April 22, 2023 | 43 | mit | Go | ||
Making it easy to write shell-like scripts in Go | ||||||||||
Ttyplot | 844 | 7 days ago | 1 | March 03, 2021 | 19 | apache-2.0 | C | |||
a realtime plotting utility for terminal/console with data input from stdin | ||||||||||
Go Sh | 842 | 99 | 78 | 3 years ago | March 04, 2014 | 6 | apache-2.0 | Go | ||
like python-sh, for easy call shell with golang. | ||||||||||
Gulp Plumber | 805 | 69,246 | 9,146 | 5 years ago | 29 | November 27, 2018 | 16 | mit | JavaScript | |
Fixing Node pipes | ||||||||||
Syntax_sugar_python | 730 | 2 years ago | 19 | May 23, 2021 | 2 | Python | ||||
A library adding some anti-Pythonic syntatic sugar to Python | ||||||||||
Streamify Your Node Program | 620 | 5 years ago | 1 | mit | JavaScript | |||||
对Node.js中 stream模块的学习积累和理解 | ||||||||||
Mario | 487 | 14 | 1 | 2 years ago | 64 | January 27, 2015 | 42 | other | Python | |
Powerful Python pipelines for your shell | ||||||||||
Pipes | 484 | 3 years ago | 14 | mit | C++ | |||||
Pipelines for expressive code on collections in C++ | ||||||||||
Pipeline | 404 | 2 | 5 years ago | April 23, 2017 | 4 | mit | Go | |||
Pipeline is a package to build multi-staged concurrent workflows with a centralized logging output. |
If you depend on the old api, see tag: v.0.1
install: go get github.com/codeskyblue/go-sh
Pipe Example:
package main
import "github.com/codeskyblue/go-sh"
func main() {
sh.Command("echo", "hello\tworld").Command("cut", "-f2").Run()
}
Because I like os/exec, go-sh
is very much modelled after it. However, go-sh
provides a better experience.
These are some of its features:
Examples are important:
sh: echo hello
go: sh.Command("echo", "hello").Run()
sh: export BUILD_ID=123
go: s = sh.NewSession().SetEnv("BUILD_ID", "123")
sh: alias ll='ls -l'
go: s = sh.NewSession().Alias('ll', 'ls', '-l')
sh: (cd /; pwd)
go: sh.Command("pwd", sh.Dir("/")).Run()
sh: test -d data || mkdir data
go: if ! sh.Test("dir", "data") { sh.Command("mkdir", "data").Run() }
sh: cat first second | awk '{print $1}'
go: sh.Command("cat", "first", "second").Command("awk", "{print $1}").Run()
sh: count=$(echo "one two three" | wc -w)
go: count, err := sh.Echo("one two three").Command("wc", "-w").Output()
sh(in ubuntu): timeout 1s sleep 3
go: c := sh.Command("sleep", "3"); c.Start(); c.WaitTimeout(time.Second) # default SIGKILL
go: out, err := sh.Command("sleep", "3").SetTimeout(time.Second).Output() # set session timeout and get output)
sh: echo hello | cat
go: out, err := sh.Command("cat").SetInput("hello").Output()
sh: cat # read from stdin
go: out, err := sh.Command("cat").SetStdin(os.Stdin).Output()
sh: ls -l > /tmp/listing.txt # write stdout to file
go: err := sh.Command("ls", "-l").WriteStdout("/tmp/listing.txt")
If you need to keep env and dir, it is better to create a session
session := sh.NewSession()
session.SetEnv("BUILD_ID", "123")
session.SetDir("/")
# then call cmd
session.Command("echo", "hello").Run()
# set ShowCMD to true for easily debug
session.ShowCMD = true
By default, pipeline returns error only if the last command exit with a non-zero status. However, you can also enable pipefail
option like bash
. In that case, pipeline returns error if any of the commands fail and for multiple failed commands, it returns the error of rightmost failed command.
session := sh.NewSession()
session.PipeFail = true
session.Command("cat", "unknown-file").Command("echo").Run()
By default, pipelines's std-error is set to last command's std-error. However, you can also combine std-errors of all commands into pipeline's std-error using session.PipeStdErrors = true
.
for more information, it better to see docs.
If you love this project, starring it will encourage the coder. Pull requests are welcome.
support the author: alipay
this project is based on codegangsta/inject. thanks for the author.
Sometimes we need to write shell scripts, but shell scripts are not good at working cross platform, Go, on the other hand, is good at that. Is there a good way to use Go to write shell like scripts? Using go-sh we can do this now.