Skip to content

cruelandunusual/go-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-shell - a minimal shell written in Go

Linux macOS wsl

Description

A simple shell interpreter written in Go.

This project initially started by following this basic tutorial as a way to learn Go.
So far it mainly executes Linux commands using Go's builtin Run() mechanism from the os/exec package:

	// prepare the command to execute
	cmd := exec.Command(args[0], args[1:]...) // variadic argument expansion

	// set appropriate outputs
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout

	// run the command, returning its results and exit status
	return cmd.Run()

I've enhanced the mechanism for changing directory so that as well as the standard Bash cd command, it now supports analogous commands from other shells, e.g. Set-Location, chdir, among others.

I've added the hostname to the prompt, as well as providing a shell builtin to customise the rest of the prompt string with an arbitrary string; just enter setPrompt followed by your new prompt message without double quotes, e.g.:

setPrompt my custom prompt message

Tip

Builds can be done with Go's own build system, however there is support for Task, a simpler alternative to Make, which allows for more customisable options than Go's build system provides.

Follow the instructions to install Task; then:

  • task will compile an executable called go-shell in bin/, and then launch it.
  • task build will simply compile it.
  • task run will run a previously compiled executable.

About

A minimal shell written in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages