Documentation ¶
Overview ¶
Package sysutil provide some system util functions. eg: sysenv, exec, user, process
Index ¶
- func BinDir() string
- func BinFile() string
- func BinName() string
- func ChangeUserByName(newUname string) error
- func ChangeUserUIDGid(newUID int, newGid int) (err error)
- func ChangeUserUidGid(newUID int, newGid int) errordeprecated
- func CurrentShell(onlyName bool) (path string)
- func CurrentUser() *user.User
- func EnvMapWith(newEnv map[string]string) map[string]string
- 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 ExpandHome(path string) string
- func ExpandPath(path string) string
- func FindExecutable(binName string) (string, error)
- func FlushExec(bin string, args ...string) error
- func Getenv(name string, def ...string) string
- func GoVersion() string
- func HasExecutable(binName string) bool
- func HasShellEnv(shell string) bool
- func HomeDir() string
- func Hostname() string
- func IsAdmin() bool
- 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 Open(fileOrURL string) error
- func OpenBrowser(fileOrURL string) error
- func OpenFile(path string) error
- func OpenURL(URL string) error
- func ProcessExists(pid int) bool
- func QuickExec(cmdLine string, workDir ...string) (string, error)
- func SearchPath(keywords string, limit int) []string
- func ShellExec(cmdLine string, shells ...string) (string, error)
- func StdIsTerminal() bool
- func UHomeDir() string
- func UserCacheDir(subPaths ...string) string
- func UserConfigDir(subPaths ...string) string
- func UserDir(subPaths ...string) string
- func UserHomeDir() string
- func Workdir() string
- type CallerInfo
- type GoInfo
- type SearchPathOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeUserByName ¶ added in v0.4.2
ChangeUserByName change work user by new username.
func ChangeUserUIDGid ¶ added in v0.6.11
ChangeUserUIDGid change work user by new username uid,gid
func ChangeUserUidGid
deprecated
added in
v0.4.2
func CurrentShell ¶ added in v0.1.4
CurrentShell get current used shell env file.
eg "/bin/zsh" "/bin/bash". if onlyName=true, will return "zsh", "bash"
func CurrentUser ¶ added in v0.4.3
CurrentUser must get current user, will panic if error
func EnvMapWith ¶ added in v0.6.7
EnvMapWith like os.Environ, but will return key-value map[string]string data.
func Environ ¶ added in v0.6.2
Environ like os.Environ, but will returns key-value map[string]string data.
func ExecCmd ¶ added in v0.1.4
ExecCmd a command and return combined output.
Usage:
ExecCmd("ls", []string{"-al"})
func ExecLine ¶ added in v0.3.12
ExecLine quick exec a command line string, return combined output.
NOTE: not support | or ; in cmdLine
func Executable ¶ added in v0.3.12
Executable find in the system, alias of FindExecutable()
Usage:
sysutil.Executable("bash")
func ExpandHome ¶ added in v0.6.8
ExpandHome will parse `~` as user home dir path.
func ExpandPath ¶ added in v0.3.9
ExpandPath will parse `~` as user home dir path.
func FindExecutable ¶ added in v0.3.8
FindExecutable in the system
Usage:
sysutil.FindExecutable("bash")
func GoVersion ¶ added in v0.5.11
func GoVersion() string
GoVersion get go runtime version. eg: "1.18.2"
func HasShellEnv ¶ added in v0.1.4
HasShellEnv has shell env check.
Usage:
HasShellEnv("sh") HasShellEnv("bash")
func Hostname ¶ added in v0.3.12
func Hostname() string
Hostname is alias of os.Hostname, but ignore error
func IsAdmin ¶ added in v0.6.18
func IsAdmin() bool
IsAdmin Determine whether the current user is an administrator(root)
func IsConsole ¶ added in v0.2.2
IsConsole check out is in stderr/stdout/stdin
Usage:
sysutil.IsConsole(os.Stdout)
func IsShellSpecialVar ¶ added in v0.3.12
IsShellSpecialVar reports whether the character identifies a special shell variable such as $*.
func MustFindUser ¶ added in v0.4.2
MustFindUser must find a system user by name
func OpenBrowser ¶ added in v0.5.6
OpenBrowser file or url address
func OpenURL ¶ added in v0.6.6
OpenURL Open file or 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 QuickExec ¶ added in v0.1.4
QuickExec quick exec a simple command line, return combined output.
func SearchPath ¶ added in v0.5.11
SearchPath search executable files in the system $PATH
Usage:
sysutil.SearchPath("go")
func ShellExec ¶ added in v0.1.4
ShellExec exec command by shell cmdLine, return combined output.
shells e.g. "/bin/sh", "bash", "cmd", "cmd.exe", "powershell", "powershell.exe", "pwsh", "pwsh.exe"
eg: ShellExec("ls -al")
func UHomeDir ¶ added in v0.3.13
func UHomeDir() string
UHomeDir get user home dir path, ignore error. (by user.Current)
func UserCacheDir ¶ added in v0.4.0
UserCacheDir will prepend user `$HOME/.cache` to subPaths
func UserConfigDir ¶ added in v0.4.0
UserConfigDir will prepend user `$HOME/.config` to subPath
func UserHomeDir ¶ added in v0.3.12
func UserHomeDir() string
UserHomeDir is alias of os.UserHomeDir, but ignore error.(by os.UserHomeDir)
Types ¶
type CallerInfo ¶ added in v0.5.6
CallerInfo struct
func CallersInfos ¶ added in v0.5.6
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 ¶ added in v0.5.11
GoInfo define. alias of goinfo.GoInfo
func ParseGoVersion ¶ added in v0.5.11
ParseGoVersion get info by parse `go version` results. alias of goinfo.ParseGoVersion()
Examples:
line, err := sysutil.ExecLine("go version") if err != nil { return err } info, err := sysutil.ParseGoVersion() dump.P(info)
type SearchPathOption ¶ added in v0.6.18
type SearchPathOption struct { // 限制的扩展名 LimitExt []string }
SearchPathOption settings for SearchPath
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 |