{"id":15288243,"url":"https://github.com/abdfnx/gosh","last_synced_at":"2025-04-13T06:32:02.116Z","repository":{"id":54174007,"uuid":"344764658","full_name":"abdfnx/gosh","owner":"abdfnx","description":"⌨ A golang library for executing bash \u0026 powershell commands easly.","archived":false,"fork":false,"pushed_at":"2022-11-01T14:55:02.000Z","size":27,"stargazers_count":47,"open_issues_count":3,"forks_count":8,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2025-04-06T07:54:13.727Z","etag":null,"topics":["bash","cli","go","golang","library","linux","macos","powershell","shell","tool","windows"],"latest_commit_sha":null,"homepage":"https://abdfnx.github.io/gosh","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abdfnx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-05T09:48:05.000Z","updated_at":"2025-03-28T10:19:19.000Z","dependencies_parsed_at":"2022-08-13T08:20:35.041Z","dependency_job_id":null,"html_url":"https://github.com/abdfnx/gosh","commit_stats":null,"previous_names":["secman-team/shell","abdfnx/shell","scmn-dev/shell"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdfnx%2Fgosh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdfnx%2Fgosh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdfnx%2Fgosh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdfnx%2Fgosh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abdfnx","download_url":"https://codeload.github.com/abdfnx/gosh/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674659,"owners_count":21143760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","cli","go","golang","library","linux","macos","powershell","shell","tool","windows"],"created_at":"2024-09-30T15:44:53.227Z","updated_at":"2025-04-13T06:32:01.679Z","avatar_url":"https://github.com/abdfnx.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gosh\r\n\r\n\u003e A golang library for executing bash \u0026 powershell commands easly.\r\n\r\n## Install\r\n\r\n```bash\r\ngo get -v github.com/abdfnx/gosh\r\n```\r\n\r\n## Examples\r\n\r\n### Run one command on both shell and powershell\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n  \"fmt\"\r\n  \"log\"\r\n\r\n  \"github.com/abdfnx/gosh\"\r\n)\r\n\r\n// run a command\r\ngosh.Run(\"git status\")\r\n\r\n// run a command with output\r\nerr, out, errout := gosh.RunOutput(\"echo 𝜋\")\r\n\r\nif err != nil {\r\n  log.Printf(\"error: %v\\n\", err)\r\n  fmt.Print(errout)\r\n}\r\n\r\nfmt.Print(out)\r\n```\r\n\r\n### How `gosh.Run(\"COMMAND\")` works ?\r\n\r\n```go\r\n// `Run` executes the same command for shell and powershell\r\nfunc Run(cmd string) {\r\n\terr, out, errout := ShellOutput(\"\")\r\n\r\n\tif runtime.GOOS == \"windows\" {\r\n\t\terr, out, errout = PowershellOutput(cmd)\r\n\t} else {\r\n\t\terr, out, errout = ShellOutput(cmd)\r\n\t}\r\n\r\n\tif err != nil {\r\n\t\tlog.Printf(\"error: %v\\n\", err)\r\n\t\tfmt.Print(errout)\r\n\t}\r\n\r\n\tfmt.Print(out)\r\n}\r\n```\r\n\r\n### Run Powershell Command(s)\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n  \"fmt\"\r\n  \"log\"\r\n\r\n  \"github.com/abdfnx/gosh\"\r\n)\r\n\r\n// run a command\r\ngosh.PowershellCommand(`Write-Host \"hello from powershell\"`)\r\n\r\n// run a script\r\ngosh.PowershellCommand(`\r\n  $git_username = git config user.name\r\n\r\n  Write-Host $git_username\r\n`)\r\n\r\n// run a command with output\r\nerr, out, errout := gosh.PowershellOutput(`[System.Environment]::SetEnvironmentVariable(\"Path\", $Env:Path + \";$APP_PATH\\bin\", [System.EnvironmentVariableTarget]::User)`)\r\n\r\nif err != nil {\r\n  log.Printf(\"error: %v\\n\", err)\r\n  fmt.Print(errout)\r\n}\r\n\r\nfmt.Print(out)\r\n```\r\n\r\n### Run Bash/Shell Command(s)\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n  \"fmt\"\r\n  \"log\"\r\n\r\n  \"github.com/abdfnx/gosh\"\r\n)\r\n\r\n// run a command\r\ngosh.ShellCommand(`echo \"shell or bash?\"`)\r\n\r\n// run a script\r\ngosh.ShellCommand(`\r\n  mood=\"👨‍💻\"\r\n\r\n  if [ $mood != \"😪\" ]; then\r\n    echo \"still coding\"\r\n  fi\r\n`)\r\n\r\n// run a command with output\r\nerr, out, errout := gosh.ShellOutput(`curl --silent \"https://get-latest.onrender.com/docker/compose\"`)\r\n\r\nif err != nil {\r\n  log.Printf(\"error: %v\\n\", err)\r\n  fmt.Print(errout)\r\n}\r\n\r\nfmt.Print(out)\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabdfnx%2Fgosh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabdfnx%2Fgosh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabdfnx%2Fgosh/lists"}