shell

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

Shell

run powershell and bash easly with go.

Run powershell and bash

import "github.com/abdfnx/shell"

// run a command
shell.Run("git status")

// run a command with output
err, out, errout := shell.RunOut("whoami")

if err != nil {
  log.Printf("error: %v\n", err)
  fmt.Print(errout)
}

fmt.Print(out)

Powershell

import "github.com/abdfnx/shell"

// run a command
shell.PowershellCommand(`Write-Host "hello from powershell"`)

// run a script
shell.PowershellCommand(`
  $git_username = git config user.name
  
  Write-Host $git_username
`)

// run a command with output
err, out, errout := shell.PowerShelloutput(`[System.Environment]::SetEnvironmentVariable("Path", $Env:Path + ";$APP_PATH\bin", [System.EnvironmentVariableTarget]::User)`)

if err != nil {
  log.Printf("error: %v\n", err)
  fmt.Print(errout)
}

fmt.Print(out)

Bash/Shell

import "github.com/abdfnx/shell"

// run a command
shell.ShellCommand(`echo "shell or bash?"`)

// run a script
shell.ShellCommand(`
  mood="👨‍💻"

  if [ $mood != "😪" ]; then
    echo "still coding"
  fi
`)

// run a command with output
err, out, errout := shell.Shelloutput(`curl --silent "https://api.github.com/repos/abdfnx/resto/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`)

if err != nil {
  log.Printf("error: %v\n", err)
  fmt.Print(errout)
}

fmt.Print(out)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PowershellCommand added in v0.3.4

func PowershellCommand(command string)

`PowershellCommand` executes the powershell command.

func PowershellOutput added in v0.3.4

func PowershellOutput(command string) (error, string, string)

`PowershellOutput` returns the output of powershell command, and any errors.

func Run

func Run(cmd string)

`Run` executes the same command for shell and powershell

func RunMulti added in v0.3.4

func RunMulti(unixCmd string, winCmd string)

`RunMulti` executes a command for shell and a command for powershell

func RunMultiOutput added in v0.3.4

func RunMultiOutput(unixCmd string, winCmd string) (error, string, string)

`RunMultiOutput` returns the output of the shell command and the powershell command

func RunOutput added in v0.3.4

func RunOutput(command string) (error, string, string)

`RunOutput` returns the output of the shared command for shell and powershell

func ShellCommand added in v0.3.4

func ShellCommand(command string)

`ShellCommand` executes the shell command.

func ShellOutput added in v0.3.4

func ShellOutput(command string) (error, string, string)

`ShellOutput` returns the output of shell command, and any errors.

Types

This section is empty.

Jump to

Keyboard shortcuts

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