utils

package
v0.0.0-...-99cc010 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src, dst string) error

CopyDir recursively copies the directory at src to dst.

func DeleteDirFiles

func DeleteDirFiles(dir string) error

DeleteDirFiles deletes all files in the specified directory.

func DeleteFile

func DeleteFile(path string) error

DeleteFile deletes a file.

func EnsureDir

func EnsureDir(path string) error

EnsureDir checks if a directory exists at the given path. If it does not exist, it creates the directory.

func GetUserHomeDir

func GetUserHomeDir() (string, error)

GetUserHomeDir returns the user's home directory. On Windows, it handles WSL paths correctly.

func HasWSL

func HasWSL() bool

HasWSL returns true if WSL is available (Windows only).

func HideConsole

func HideConsole(*exec.Cmd)

HideConsole is a no-op outside Windows. See exec_windows.go for the Windows implementation that suppresses the transient console window.

func OpenDirectory

func OpenDirectory(path string) error

OpenDirectory opens the specified directory in the system's file explorer.

func OpenPath

func OpenPath(path string) error

OpenPath opens a local file in the user's default editor / viewer for that file type. Distinct from OpenURL because the WSL path needs a wslpath translation before cmd.exe can hand it off.

func OpenTerminalWithCommand

func OpenTerminalWithCommand(args ...string) error

OpenTerminalWithCommand opens a terminal emulator running the given command.

func OpenURL

func OpenURL(url string) error

OpenURL opens the given URL in the user's default browser.

func PickDirectoryInWSL

func PickDirectoryInWSL() (string, error)

PickDirectoryInWSL opens a directory picker dialog inside WSL using zenity. Returns the selected Linux path (e.g., /home/user/projects).

func RunHostStream

func RunHostStream(ctx context.Context, opts HostExecOptions, onLine HostLineHandler) (int, error)

RunHostStream executes a command on the host shell, streaming stdout and stderr line-by-line through onLine. It blocks until the command exits or ctx is cancelled. Returns the exit code (or -1 if the process never started) and an error for plumbing failures only — a non-zero exit is not returned as an error.

On Unix and inside WSL, the command runs under `bash -c`. On native Windows, it runs under `cmd /C`. WSL detection is automatic: a Linux process running inside WSL takes the bash branch.

Types

type HostExecOptions

type HostExecOptions struct {
	// Command is a single shell-evaluated command line. It is passed to
	// `bash -c` on Unix/WSL or `cmd /C` on native Windows so the user can
	// use pipes, redirections, and ${VAR} expansion. Required.
	Command string
	// Cwd is the working directory the command runs in. Empty inherits the
	// parent process's cwd.
	Cwd string
	// Env is a list of "KEY=VALUE" strings prepended to the inherited
	// environment. Later entries override earlier ones (Go's os/exec
	// semantics).
	Env []string
}

HostExecOptions configures a host-shell command execution.

type HostLineHandler

type HostLineHandler func(line string, stderr bool)

HostLineHandler receives a single line of stdout (stderr=false) or stderr (stderr=true) from a streaming host command. The trailing newline is stripped. The handler must be cheap; it runs on the streaming goroutine.

Jump to

Keyboard shortcuts

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