Nash

From ArchWiki
Revision as of 17:53, 14 September 2016 by I4k (talk | contribs) (Created page with "Category:Command shells [https://github.com/NeowayLabs/nash Nash] is a minimalist and yet powerful shell with focus on readability and security of scripts. It's inspired b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Nash is a minimalist and yet powerful shell with focus on readability and security of scripts. It's inspired by Plan9 rc shell and brings to linux a similar approach to namespace creation. There's a nashfmt program to correctly format nash scripts in a readable manner (much like Golang gofmt program).

Installation

Install the nash-gitAUR package.

Initial configuration

Make sure that nash has been successfull installed issuing the command below in your current shell:

$ nash
λ>

If you got a lambda prompt, the everything is fine.

When first executed, nash will create a .nash directory in $HOME. Enter the command below to discover by yourself what is this directory:

λ> echo $NASHPATH
/home/i4k/.nash

Put a file called init inside this directory to configure it.

Nash only has 2 special variables:

  • PROMPT variable stores the unicode string used for ... you know
  • IFS is a list containing the set of character delimiters used internally to split command output into lists.

Nash doesn't have a cd builtin, but a builtin function chdir. In nash you cannot create aliases by matching string to strings, but only binding function to command names. The init below creates a cd alias:

defPROMPT = "λ> "

fn cd(path) {
        if $path == "" {
                path = $HOME
        }

        chdir($path)
        PROMPT = "("+$path+")"+$defPROMPT
        setenv PROMPT
}

# bind the "cd" function to "cd" command name
bindfn cd cd

After saving the init file, simple start a new shell and now you can use cd as if it were a builtin keyword.

git:(master)λ> nash
λ> cd
(/home/i4k)λ> cd /usr/local
(/usr/local)λ>

For a more elaborated cd or other aliases implementation, see the project dotnash.

Organizing the init

Nash scripts can be modular, but there's no concept of package. You can use the import keyword to load other files inside the current script session. For an example, see dotnash init.

Configuring $PATH

Inside the init put the code below (edit for your needs):

path = (
        "/bin"
        "/usr/bin"
        "/usr/local/bin"
        $HOME+"/bin"
)

PATH = ""

for p in $path {
        PATH = $PATH+":"+$p
}

setenv PATH

Making nash your default shell

See https://wiki.archlinux.org/index.php/Command-line_shell#Changing_your_default_shell

Keybindings

The cli supports emacs and vi modes for common buffer editing. Default mode is emacs and you can change issuing:

λ> set mode vi

See also

nash

dotnash