shell

package module
v0.22.5 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: GPL-3.0 Imports: 18 Imported by: 2

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 FileMap map[string]*File
View Source
var INFO *log.LogFlag
View Source
var NOW *log.LogFlag
View Source
var RUN *log.LogFlag
View Source
var SSH *log.LogFlag

Functions

func Cat

func Cat(filename string) string

Cat a file into a string

func Dir

func Dir(dirname string) bool

return true if the filename exists (cross-platform)

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 InitCallback

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

func IsDir

func IsDir(dirname string) bool

func Md5sum

func Md5sum(filename string) string

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

func Mkdir

func Mkdir(dir string) bool

makes the directory

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 PathRun added in v0.22.5

func PathRun(path string, args []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 PathRunQuiet added in v0.22.5

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

absolutely doesn't echo anything

func PathRunSimple added in v0.22.5

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

func Quiet

func Quiet(q bool)

this means it won't copy all the output to STDOUT

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(args []string) cmd.Status

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

func RunHttpOut added in v0.22.4

func RunHttpOut(cmd []string, w http.ResponseWriter, r *http.Request) error

func RunPathHttpOut added in v0.22.4

func RunPathHttpOut(path string, cmd []string, w http.ResponseWriter, r *http.Request) error

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 RunTest added in v0.22.5

func RunTest()

run these to see confirm the sytem behaves as expected

func Shell

func Shell() string

returns a string of the shell the user is using

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 XtermCmdBash

func XtermCmdBash(path string, cmd []string)

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

func XtermCmdWait

func XtermCmdWait(path string, cmd []string)

runs an xterm waits until xterm exits

Types

type File

type File struct {
	Name string
	// BufferSize	int
	// Buffer		*bytes.Buffer
	// Fbytes		[]byte
	TotalCount int
	Empty      bool
	Dead       bool

	Fio    io.ReadCloser // := process.StdoutPipe()
	Fbufio *bufio.Reader // := bufio.NewReader(pOUT)

}

type OldShell

type OldShell struct {
	Cmdline string
	Process *exec.Cmd
	Done    bool
	Quiet   bool
	Fail    bool
	Error   error
	Buffer  *bytes.Buffer

	// which names are really better here?
	// for now I init them both to test out
	// how the code looks and feels
	STDOUT *File
	STDERR *File
	Stdout *File
	Stderr *File
}

early code playground

func New

func New() *OldShell

default values for OldShell

Jump to

Keyboard shortcuts

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