Documentation
¶
Overview ¶
Package sysutil provide some system util functions. eg: sysenv, exec, user, process
Index ¶
- func BinDir() string
- func BinFile() string
- func ChangeUserByName(newUname string) (err error)
- func ChangeUserUidGid(newUid int, newGid int) (err error)
- func CurrentShell(onlyName bool) (path string)
- func CurrentUser() *user.User
- func EnvPaths() []string
- func Environ() map[string]string
- func ExecCmd(binName string, args []string, workDir ...string) (string, error)
- func ExecLine(cmdLine string, workDir ...string) (string, error)
- func Executable(binName string) (string, error)
- func ExpandPath(path string) string
- func FindExecutable(binName string) (string, error)
- func FlushExec(bin string, args ...string) error
- func GoVersion() string
- func HasExecutable(binName string) bool
- func HasShellEnv(shell string) bool
- func HomeDir() string
- func Hostname() string
- func IsConsole(out io.Writer) bool
- func IsDarwin() bool
- func IsLinux() bool
- func IsMSys() bool
- func IsMac() bool
- func IsShellSpecialVar(c uint8) bool
- func IsTerminal(fd uintptr) bool
- func IsWin() bool
- func IsWindows() bool
- func Kill(pid int, signal syscall.Signal) error
- func LoginUser() *user.User
- func MustFindUser(uname string) *user.User
- func NewCmd(bin string, args ...string) *cmdr.Cmd
- func OpenBrowser(URL string) error
- func ProcessExists(pid int) bool
- func QuickExec(cmdLine string, workDir ...string) (string, error)
- func SearchPath(keywords string) []string
- func ShellExec(cmdLine string, shells ...string) (string, error)
- func StdIsTerminal() bool
- func UHomeDir() string
- func UserCacheDir(subPath string) string
- func UserConfigDir(subPath string) string
- func UserDir(subPath string) string
- func UserHomeDir() string
- func Workdir() string
- type CallerInfo
- type GoInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeUserByName ¶
ChangeUserByName change work user by new username.
func ChangeUserUidGid ¶
ChangeUserUidGid change work user by new username uid,gid
func CurrentShell ¶
CurrentShell get current used shell env file.
eg "/bin/zsh" "/bin/bash". if onlyName=true, will return "zsh", "bash"
func Executable ¶
Executable find in the system, alias of FindExecutable()
Usage:
sysutil.Executable("bash")
func ExpandPath ¶
ExpandPath will parse `~` as user home dir path.
func IsShellSpecialVar ¶
IsShellSpecialVar reports whether the character identifies a special shell variable such as $*.
func MustFindUser ¶
MustFindUser must find an system user by name
func OpenBrowser ¶
OpenBrowser Open browser URL
Mac:
open 'https://github.com/inhere'
Linux:
xdg-open URL x-www-browser 'https://github.com/inhere'
Windows:
cmd /c start https://github.com/inhere
func SearchPath ¶
SearchPath search executable files in the system $PATH
Usage:
sysutil.SearchPath("go")
func UserCacheDir ¶
UserCacheDir will prepend user `$HOME/.cache` to subPath
func UserConfigDir ¶
UserConfigDir will prepend user `$HOME/.config` to subPath
func UserHomeDir ¶
func UserHomeDir() string
UserHomeDir is alias of os.UserHomeDir, but ignore error
Types ¶
type CallerInfo ¶
CallerInfo struct
func CallersInfos ¶
CallersInfos returns an array of the CallerInfo.
Usage:
cs := sysutil.CallersInfos(3, 2) for _, ci := range cs { fc := runtime.FuncForPC(pc) // maybe need check fc = nil fnName = fc.Name() }
type GoInfo ¶
GoInfo define
On os by:
go env GOVERSION GOOS GOARCH go version // "go version go1.19 darwin/amd64"
func ParseGoVersion ¶
ParseGoVersion get info by parse `go version` results.
Examples:
line, err := sysutil.ExecLine("go version") if err != nil { return err } info, err := sysutil.ParseGoVersion() pretty.P(info)
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package clipboard provide a simple clipboard read and write operations.
|
Package clipboard provide a simple clipboard read and write operations. |
Package cmdr Provide for quick build and run a cmd, batch run multi cmd tasks
|
Package cmdr Provide for quick build and run a cmd, batch run multi cmd tasks |
Package process Provide some process handle util functions
|
Package process Provide some process handle util functions |