sysutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 12 Imported by: 25

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentShell added in v0.1.4

func CurrentShell(onlyName bool) (path string)

CurrentShell get current used shell env file. eg "/bin/zsh" "/bin/bash". if onlyName=true, will return "zsh", "bash"

func ExecCmd added in v0.1.4

func ExecCmd(binName string, args []string, workDir ...string) (string, error)

ExecCmd an command and return output. Usage:

ExecCmd("ls", []string{"-al"})

func ExecLine added in v0.3.12

func ExecLine(cmdLine string, workDir ...string) (string, error)

ExecLine quick exec an command line string

func Executable added in v0.3.12

func Executable(binName string) (string, error)

Executable find in the system

Usage:

Executable("bash")

func ExpandPath added in v0.3.9

func ExpandPath(path string) string

ExpandPath will parse `~` as user home dir path.

func FindExecutable added in v0.3.8

func FindExecutable(binName string) (string, error)

FindExecutable in the system

Usage:

FindExecutable("bash")

func HasExecutable added in v0.3.8

func HasExecutable(binName string) bool

HasExecutable in the system

Usage:

HasExecutable("bash")

func HasShellEnv added in v0.1.4

func HasShellEnv(shell string) bool

HasShellEnv has shell env check.

Usage:

HasShellEnv("sh")
HasShellEnv("bash")

func HomeDir added in v0.3.9

func HomeDir() string

HomeDir get user home dir path.

func Hostname added in v0.3.12

func Hostname() string

Hostname is alias of os.Hostname, but ignore error

func IsConsole added in v0.2.2

func IsConsole(out io.Writer) bool

IsConsole check out is in stderr/stdout/stdin

Usage:

sysutil.IsConsole(os.Stdout)

func IsLinux added in v0.2.2

func IsLinux() bool

IsLinux system

func IsMSys added in v0.2.2

func IsMSys() bool

IsMSys msys(MINGW64) env,不一定支持颜色

func IsMac added in v0.2.2

func IsMac() bool

IsMac system

func IsShellSpecialVar added in v0.3.12

func IsShellSpecialVar(c uint8) bool

IsShellSpecialVar reports whether the character identifies a special shell variable such as $*.

func IsTerminal added in v0.3.9

func IsTerminal(fd uintptr) bool

IsTerminal isatty check

Usage: sysutil.IsTerminal(os.Stdout.Fd())

func IsWin added in v0.2.2

func IsWin() bool

IsWin system. linux windows darwin

func IsWindows added in v0.2.3

func IsWindows() bool

IsWindows system. linux windows darwin

func Kill

func Kill(pid int, signal syscall.Signal) error

Kill process by pid

func LoginUser added in v0.3.13

func LoginUser() *user.User

LoginUser get current user

func ProcessExists

func ProcessExists(pid int) bool

ProcessExists check process exists by pid

func QuickExec added in v0.1.4

func QuickExec(cmdLine string, workDir ...string) (string, error)

QuickExec quick exec an simple command line

func ShellExec added in v0.1.4

func ShellExec(cmdLine string, shells ...string) (string, error)

ShellExec exec command by shell cmdStr eg. "ls -al"

func StdIsTerminal added in v0.3.11

func StdIsTerminal() bool

StdIsTerminal os.Stdout is terminal

func UHomeDir added in v0.3.13

func UHomeDir() string

UHomeDir get user home dir path.

func UserCacheDir added in v0.4.0

func UserCacheDir(subPath string) string

UserCacheDir will prepend user `$HOME/.cache` to subPath

func UserConfigDir added in v0.4.0

func UserConfigDir(subPath string) string

UserConfigDir will prepend user `$HOME/.config` to subPath

func UserDir added in v0.4.0

func UserDir(subPath string) string

UserDir will prepend user home dir to subPath

func UserHomeDir added in v0.3.12

func UserHomeDir() string

UserHomeDir is alias of os.UserHomeDir, but ignore error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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