GithubHelp home page GithubHelp logo

oh's Introduction

Oh, a new Unix shell

Why oh?

Oh is a reimagining of the Unix shell as a programming language.

Oh provides:

  • Lexical scope;
  • Exceptions;
  • First-class channels, pipes, environments and functions;
  • A list type (no word splitting);
  • Rich return values that work with standard shell constructs;
  • Kernel-style fexprs (allowing the definition of new language constructs);
  • Support for modularity;
  • A simplified set of evaluation and quoting rules; and
  • A syntax that deviates as little as possible from established conventions;

Oh's goal is a language that is not only more powerful and more regular but one that respects the conventions established by the Unix shell over the last half-century.

Getting started

Installing

The easiest way to try oh is to download a precompiled binary.

DragonFly BSD

amd64

FreeBSD

386, amd64, arm, arm64

illumos

amd64

Linux

386, amd64, arm, arm64, mips, mips64, mips64le, mipsle, ppc64, ppc64le, riscv64, s390x

macOS

amd64, arm64

OpenBSD

386, amd64, arm, arm64, mips64

Solaris

amd64

You can also build oh from source. With Go 1.16 or later installed, type,

go get github.com/michaelmacinnis/oh

Configuring

When oh starts, it attempts to read a file called .oh-rc in the home directory of the current user. You can override this path by setting the OH_RC environment variable to the full path of an alternative file before invoking oh.

The oh rc file is useful for setting environment variables and defining custom commands. It's also a good place to override oh's default prompt. The command below replaces oh's default prompt method with one that displays the current date.

replace-make-prompt (method (suffix) {
    return `(date)$suffix
})

Oh (thanks to peterh/liner) also provides a searchable command history. By default, this history is stored in a file called .oh-history in your home directory. You can override this by setting the OH_HISTORY environment variable to the full path of an alternative file before invoking oh.

Comparing oh to other Unix shells

Oh is a Unix shell. If you've used other Unix shells, oh should feel familiar. Below are some specific differences you may encounter.

Clobbering

When redirecting output oh will not overwrite an existing file. To force oh to overwrite (clobber) an existing file add a pipe, |, character immediately after the redirection operator. For example,

command >| out.txt

Oh's pipe and redirection syntax is as follows.

Syntax Redirection
< input-from
> output-to
>& output-errors-to
>&| output-errors-clobbers
>> append-output-to
>>& append-output-errors-to
>| output-clobbers
| pipe-output-to
|& pipe-output-errors-to
|< -named-pipe-input-from*
|> -named-pipe-output-to*

* - Used in process substitution.

Command substitution

Many Unix shells support command substitution using the historical backtick syntax,

`command`

or the POSIX syntax,

$(command)

Oh has one syntax for command substitution,

`(command)

This syntax is both nestable and unambiguous.

Here documents

Oh does not have here documents. It does however allow strings to span lines and provides a here command that takes a string argument and can be used to the same effect. For example,

# Build oh for supported BSD platforms
here "
dragonfly amd64
freebsd 386
freebsd amd64
freebsd arm
freebsd arm64
openbsd 386
openbsd amd64
openbsd arm
openbsd arm64
openbsd mips64
" | mill (o a) {
    echo ${o}/${a}
    GOOS=${o} GOARCH=${a} go build -o oh-latest-${o}-${a}
}

Variables

To introduce a new variable, use the define command,

define x 3

To introduce a variable that will be visible to external processes, use the export command,

export GOROOT /usr/local/go

To set the value of an existing variable, use the set command,

set x 4

Variables and implicit concatenation

Like other shells, oh implicitly concatenates adjacent string/symbol values. Unlike other shells, oh allows a larger set of characters to appear in variable names. In addition to letters, numbers, and the underscore character, the following characters,

'!', '%', '*', '+', '-', '?', '[', ']',  and '^' 

can be used in oh variable names. The command,

echo $set!

will cause oh to attempt to resolve a variable called set!. The following characters,

',', '.', '/', ':', '=', '@', and '~'

always result in a symbol of one character. This ensures that commands like,

cd $PWD/$dir

work as expected. When using implicit concatentation, unexpected behavior can be avoided by enclosing variable names in braces.

More detailed comparison

For a detailed comparison to other Unix shells see: Comparing oh to other Unix Shells

Using oh

For more information on using oh, see: Using oh

Contributing to oh

Oh is an ongoing experiment and it needs your help. Try oh. Let me know what works for you and what doesn't.

Pull requests are welcome. For information on contributing, see: CONTRIBUTING

You can also sponsor me through GitHub Sponsors or Patreon.

License

MIT

oh's People

Contributors

michaelmacinnis avatar klaidliadon avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.