shell

package module
v0.22.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2025 License: GPL-3.0 Imports: 18 Imported by: 55

README

shell

A way to execute simple commands in a 'shell-like' way

This should correctly capture stdout and stderr in a non-blocking unbuffered way

install

go get -v -t -u go.wit.com/lib/gui/shell

License

The same License as GO itself

Documentation

Index

Constants

This section is empty.

Variables

View Source
var INFO *log.LogFlag

Functions

func Exec

func Exec(args []string) error

func ExecCheck added in v0.22.21

func ExecCheck(args []string) error

func Execname

func Execname(filename string) string

func Exists

func Exists(filename string) bool

return true if the filename exists (cross-platform)

func FormatDuration added in v0.22.4

func FormatDuration(d time.Duration) string

func GetComm

func GetComm(pid int) (string, error)

get comm from proc

func GetDurationStamp added in v0.22.4

func GetDurationStamp(t time.Time) string

func GetPPID

func GetPPID(pid int) (int, error)

get your parent PID

func HumanDuration added in v0.22.18

func HumanDuration(d *time.Duration) string

allows nil

func InitCallback

func InitCallback(f func(interface{}, int))

func IsDir

func IsDir(dirname string) bool

return true if the filename exists (cross-platform)

func Md5sum

func Md5sum(filename string) string

hash thyself: hash_file_md5(os.Args[0])

func OpenBrowser

func OpenBrowser(url string) error

openBrowser opens the specified URL in the default browser of the user.

func Path

func Path(filename string) string

func PathExecVerbose added in v0.22.26

func PathExecVerbose(path string, args []string) error

func PathRun added in v0.22.5

func PathRun(path string, argv []string) cmd.Status

exec the cmd at a filepath. this does not change the working directory sets the exec dir if it's not an empty string combines stdout and stderr echo's output (otherwise use PathRunQuiet() this is basically the exact example from the go-cmd/cmd devs where the have rocked out a proper smart read on both filehandles https://dave.cheney.net/2013/04/30/curious-channels

func PathRunLog added in v0.22.6

func PathRunLog(path string, argv []string, logf *log.LogFlag) cmd.Status

the actual wrapper around go-cmd/cmd adds a log Flag so that echo to stdout can be enabled/disabled

func PathRunQuiet added in v0.22.5

func PathRunQuiet(pwd string, args []string) cmd.Status

uses the 'log' package to disable echo to STDOUT only echos if you enable the shell.INFO log flag

func PathRunRealtime added in v0.22.7

func PathRunRealtime(pwd string, args []string) cmd.Status

echos twice a second if anything sends to STDOUT or STDERR not great, but it's really just for watching things run in real time anyway TODO: fix \r handling for things like git-clone so the terminal doesn't have to do a \n newline each time. TODO: add timeouts and status of things hanging around forever

func PathRunSimple added in v0.22.5

func PathRunSimple(workingpath string, cmd []string) error

func RemoveFirstElement

func RemoveFirstElement(slice []string) (string, []string)

this is stuff from a long time ago that there must be a replacement for

func Run

func Run(argv []string) cmd.Status

shortcut, sends a blank value for pwd which means the exec Dir is not set echos output (otherwise use RunQuiet)

func RunEcho added in v0.22.16

func RunEcho(cmd []string) cmd.Status

func RunQuiet added in v0.22.11

func RunQuiet(args []string) cmd.Status

uses the 'log' package to disable echo to STDOUT only echos if you enable the shell.INFO log flag

func RunRealtime added in v0.22.9

func RunRealtime(args []string) cmd.Status

send blank path == use current golang working directory

func RunSimple added in v0.22.5

func RunSimple(cmd []string) error

run interactively. output from the cmd is in real time shows all the output. For example, 'ping -n localhost' shows the output like you would expect to see

func RunStrict added in v0.22.24

func RunStrict(cmd []string) (*cmd.Status, error)

func RunVerbose added in v0.22.24

func RunVerbose(cmd []string) (*cmd.Status, error)

func RunVerboseOnError added in v0.22.24

func RunVerboseOnError(cmd []string) (*cmd.Status, error)

func Shell

func Shell() string

returns a string of the shell the user is using

func Sudo added in v0.22.25

func Sudo(c []string) error

func SudoRaw added in v0.22.25

func SudoRaw(c []string)

func Terminal

func Terminal() string

returns a string of the xterm the user is using for example, "xterm" or "mate-terminal"

func TestTerminalColor

func TestTerminalColor()

what genius figured this out? originally from github.com/dimasma0305/GoFetch

func Unlink(filename string) bool

func Wget

func Wget(url string) *bytes.Buffer

func WgetToFile

func WgetToFile(filepath string, url string) error

func Write

func Write(filepath string, data string) bool

write out a file. Always be nice and end with '\n' if you are here and want to complain about ending in '\n' then you probably aren't going to like lots of things in this package. I will quote the evilwm man page:

BUGS: The author's idea of friendly may differ to that of many other people.

func XtermCmd

func XtermCmd(path string, cmd []string)

spawns an xterm with something you can run at a command line

func XtermCmdWait

func XtermCmdWait(path string, cmd []string)

runs an xterm waits until xterm exits

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL