Commands

A list of all Ergonomica builtins and standard library functions.

Note

In all guides, .: represents an Ergonomica prompt—lines without this heading are output of the commands.

Builtins

slice ARRAY INDEX1 [INDEX2]

If only INDEX1 is specified, returns the INDEX1 th element of ARRAY. If ARRAY2 is specified, returns the elements in ARRAY from indices INDEX1 to INDEX2.

Example

.: slice (list 1 2 3) 0
1
.: slice (list 1 3 5 9 10) 2 4
5
9

count ITEM STRING

Returns the number of instances of string ITEM within string STRING.

Example

count aa aabbaba
1

= ARGS...

Returns True if all arguments are equal, False otherwise.

Example

.: = 2 2 2 2
True
.: = 9 10 9 9
False

!= ARGS...

Returns False if all arguments are equal, True otherwise.

Example

.: != 2 3 4 5
True
.: != 2 2 2 2 2
False

~ ARGS...

Returns False if all arguments are equal, True otherwise, ignoring order.

Example

.: = (list 1 2 3) (list 3 2 1)
False
.: ~ (list 1 2 3) (list 3 2 1)
True
.: ~ abba baab
True
.: ~ 123 123
[ergo: ~=]: Non-iterable passed.

not BOOL

Returns not of boolean BOOL (False if Bool is True, True if Bool is False).

Example

.: not #t
False
.: not (= 2 3)
True

repr STRING

Returns all escape sequences necessary for representing STRING.

Example

.: repr 123
123
.: repr " a b c "
u' a b c '
.: repr " a\nb"
u' a\nb'rimt

apply FUNCTION ARGS

Runs FUNCTION with arguments ARGS.

Example

.: set x (list 1 2 3)
.: apply $= $x
False

sleep SECONDS

Sleeps for SECONDS seconds, halting the execution of the program.

Example

.: sleep 5

+ ARGS...

Adds all the arguments (this is done with Python object.__add__, so lists, strings, etc. may be added).

Example

.: + 1 2
3
.: + (list 1 2 3) (list 4 5 6)
1
2
3
4
5
6
.: + testing1 testing2
testing1testing2

* ARGS...

Multiplies all the arguments (this is done with Python object.__mul__, so is not limited to ints/floats).

Example

.: * 3 5
15
.: * (list 1 2) 2
1
2
1
2

- A B

Subtracts B from A (i.e., A-B).

Example

.: - 3 2
1

^ A B

Raises A to the power of B (i.e., A^B or A**B).

Note

^ is not bitwise XOR like Python’s (and other languages’) syntax.

Example

.: ^ 2 8
256

/ A B

Divides A by B (i.e., A/B.)

Example

.: / 2 4
0.5

<= A B

Returns True if A <= B.

Example

.: <= 2 3
True
.: <= 4096 4096
True
.: <= 4 2
False

>= A B

Returns True if A >= B.

Example

.: >= 4 2
True
.: >= 3 3
True
.: >= 2 2048
False

< A B

Returns True if A < B.

Example

.: < 2 3
True
.: < 2 3
False

> A B

Returns True if A > B.

Example

.: > 3 2
True
.: > 1 1337
False

len OBJECT

Returns Python’s len on OBJECT.

Example

.: len (list 1 3 9)
3
.: len string
6

unique ARRAY

Returns an array with one of each element in ARRAY.

Example

.: unique (list 1 1 2 2 3 3 3 4)
1
2
3
4

type OBJECT

Returns the Python type of OBJECT.

Example

.: type 4
int
.: type 4.0
float
.: type (list 1 2 3)
list
.: type example_string
str
.: type $ls
function

str OBJECT

Converts OBJECT to a string.

Example

.: type 1
int
.: type (str 1)
str

or BOOL1 BOOL2

ORs two boolean values.

Example

.: or #t #f
True
.: or #f #f
False
.: or #t #t
True

and BOOL1 BOOL2

ANDs two boolean values.

Example

.: and #t #f
False
.: and #f #f
False
.: and #t #t
True

nor BOOL1 BOOL2

NORs two boolean values.

Example

.: nor #t #f
False
.: nor #f #f
True
.: nor #t #t
False

nand BOOL1 BOOL2

NANDs two boolean values.

Example

.: nand #t #f
True
.: nand #f #f
True
.: nand #t #t
False

xor BOOL1 BOOL2

XORs two boolean values.

Example

.: xor #t #f
True
.: xor #f #f
False
.: xor #t #t
False

int OBJECT

Converts OBJECT to an integer.

Example

.: int "123"
123
.: int 3.104
3

bool OBJECT

Converts OBJECT to a boolean.

Example

.: bool "123123"
True
.: bool ""
False
.: bool 0
False
.: bool 128
True

float OBJECT

Converts OBJECT to a floating-point number.

Example

.: float "1.023"
1.023
.: float 3
3.0

first ARRAY

Returns the first element of an array (equivalent to Lisp’s car).

Example

.: first (list 1 2 3 4 5 6)
1

rest ARRAY

Returns all elements in an array except for the last one (equivalent to Lisp’s cdr).

Example

.: rest (list 1 2 3 4 5 6)
2
3
4
5
6

last ARRAY

Returns the last element in an array.

Example

.: last (list 1 2 3 4 5 6)
6

rrest ARRAY

Returns the r*eversed *r*est—that is, all the elements leading up to the last element *excluding the last element.

Example

.: rrest (list 1 2 3 4 5 6)
1
2
3
4
5

reverse ARRAY

Returns ARRAY, reversed.

Example

.: reverse (list 1 5 9)
9
5
1
.: reverse (reverse (list 1 5 10))
1
5
10

list ARGS...

Returns a list with all the items in ARGS.

Example

.: list 1 3 2
1
3
2

append ARR ITEM

Returns ARR with ITEM appended to the end of it. Equivalent to + $ARR (list $ITEM).

Example

.: append (list 1 2 3) 4
1
2
3
4

edit_func FUNCNAME

Returns a tempfile in which the body of the user-defined function FUNCNAME is dumped. Whever this file is subsequently edited, and a filesystem change is detected, the function will be updated.

Example

.: set example_func (lambda (x) (+ 1 (- $x 2)))
.: example_func 2
1
.: edit_func example_func
/var/folders/b_/3lj8zn3d65jgk9ny110frgyr0000gn/T/tmp186Wbn
.: read /var/folders/b_/3lj8zn3d65jgk9ny110frgyr0000gn/T/tmp186Wbn
+ 1 (- $x 2)
.: write /var/folders/b_/3lj8zn3d65jgk9ny110frgyr0000gn/T/tmp186Wbn "+ 1 (+ $x 2)"
.: example_func 2
3

spawn FUNCTION

Intiate FUNCTION as a background process. This commands returns an integer “process id” between 0 and 1000, which will then be displayed along with the console output of the command.

Note

If the session is ended before the function returns, it will be halted.

Example

.: spawn $big_operation_that_returns_2
532
.: ls
.: cd
.
. (other operations will return output as normal)
.
[ergo: spawn]: 532
2

on_fs_update PATH FUNCTION

Whenever a filesystem change (entry creation/deletion) is detected at PATH, FUNCTION is triggered with the name of the modified file or directory.

Note

The thread spawned by this function is session-specific.

Example

.: on_fs_update . (lambda (x) (+ $x " was modified"))
.:
.
. (normal commands)
.: write a
a was modified

split SEP STRING

Splits STRING by seperator SEP.

Example

.: split , 1,2,3
1
2
3

accum OPERATOR LIST

Notating OPERATOR by #, accum returns

((LIST[0] # LIST[1]) # LIST[2]) # LIST[3])...

Example

.: accum $- (list 1 2 3 4)
-8

Note

Just using - here wouldn’t be sufficient since any token after the function (accum here) will be interpreted as a string unless it has a $ prefix.

filter OPERATOR LIST

Returns every item in LIST that returns a truthy value under OPERATOR.

.: find all .*
./a
./a/b.txt
./c.jpeg
.: filter $?dir (find all .*)
./a

search REGEX

Searches (and returns) all matches of REGEX in STRING.

Example

.: search "[A-Z][a-z]+" "This is a String."
This
String

replace REGEX SUB STRING

Replaces all matches of REGEX in STRING with SUB.

Example

.: replace "[a-z]" "9" basfdbasdifbas4145
999999999999994145
.: replace silly serious "this is a very silly string"
this is a very serious string

?file FILE

Returns True if FILE is a valid file, False if it isn’t.

Example

.: ?file /etc/fstab
True
.: ?file /etc
False
.: ?file /qj0jq0-9qri0w5i0q9wi0tiw09ti
False

?dir DIR

Returns True if DIR is a valid directory, False if it isn’t.

Example

.: ?dir /etc
True
.: ?dir /etc/fstab
False

?contains ITEM LIST

Returns True if ITEM is within LIST, False if it isn’t.

Example

.: ?contains 123123 (list 123123 44 444)
True
.: ?contains "not contained" (list "it really isn't" "contained")
False

?match REGEX STRING

Returns the match of REGEX in STRING (if it matches), else it returns False.

.: match "[a-c]+" "abababababc"
abababababc
.: match "[a-c]+" "ddddd"
False

flatten LIST

Flattens LIST; in other words, if a list of lists (of arbitrary depth0 were a tree, flatten would return its leaves).

Example

.: list 1 2 (list 3 (list 4))
1
2
[3, [4]]
.: flatten (list 1 2 (list 3 (list 4)))
1
2
3
4

zip ARRAY1 ARRAY2

Returns the mixing of these two lists—[ARRAY1[0], ARRAY2[0], ARRAY1[1], ARRAY2[1].... NOTE: Does not return a list of tuples as Python’s zip does.

.: zip (list 1 3 5) (list 2 4 6)
1
2
3
4
5
6

random

Returns a random floating-point number between 0.0 and 1.0.

Example

.: random
0.18886256048003258
.: random
0.8792308131952493

randint LOWER [UPPER]

Returns a random integer between LOWER and UPPER (inclusive). If only LOWER is specified, the lower bound is set to 0 and the upper limit is set to LOWER.

Example

.: randint 3
1
.: randint 3
3
.: randint 10 20
15

randpick ARRAY

Returns a random element from ARRAY.

Example

.: randpick (list 3 9 list)
list
.: randpick (list 3 9 list)
3

round NUM PRECISION

Rounds NUM to PRECISION decimal places.

Example

.: round 3.1094 2
3.11

Constants

Constants are unchangable values in the Ergonomica runtime. These values are prefixed with a #. The values are:

  • #t: the True boolean value
  • #f: the False boolean value
  • #none: a NoneType Python object
  • #pi: The ratio of the diameter to the circumference of a circle (3.1415...)
  • #e: Euler’s Constant (2.7182...)
  • #j: the imaginary unit (sqrt(-1))

Standard Library

rprompt STRING

Set the text for the Ergonomica rprompt (next next to prompt).

Example

rprompt "hi there :p"

help

The Ergonomica help system.

Example

.: help commands # lists all commands (including user-defined) in Ergonomica namespace
ls
cd
.
.
.

mkdir DIR

Make directory DIR.

temp

Returns a valid temporary file or directory valid for the current operating system.

Example

Example

.: ls
example_file.jpeg
cute_cats.gif
.: mkdir example_directory
.: ls
example_file.jpeg
cute_cats.gif
example_directory

cd DIR

Changes the directory to DIR. If DIR not specified, changes to the user’s home directory.

Example

.: cd
.: pwd
/home/ghopper
.: cd subdir
.: pwd
/home/ghopper/subdir
.: cd
/home/ghopper

pass

Does nothing.

Example

.: pass

download URL

Download a remote file at URL.

Example

.: download http://google.com
.: read google.com
<!doctype html><html itemscope=""
.
.
.

cp SOURCE DESTINATION

Copies the file at SOURCE to DESTINATION.

Example

.: ls
a.txt
.: read a.txt
here is my file!
:) catch you on the flipside!
.: cp a.txt b.txt
.: ls
a.txt
b.txt
.: read b.txt
here is my file!
catch you on the flipside!

find

Find files and patterns within files.

Example

.: find file .*rst # match files with regex
./a/b.rst
./c.rst
./z/example.rst
.: find dir .* # match directories too
./a
./z
.: find all [a-c].* # find files and directories with 'all' directive
./a
./c.rst
.: find -f file .*rst # -f or --flat means search only in current dir
./c.rst
.: find -s file [^z]*rst # -s mandates the regexp must match the full path
./a/b.rst
./c.rst
.: find -sf file [^z]*rst # combine flags
./c.rst
.: find string 2.71828 # find strings in files
./c.rst: return 2.71828 + 3
./z/example.rst: return "My favorite number is 2.71828!!!"
.: find -f string 2.71828 # also limit your search to the current dir
./c.rst: return 2.71828 + 3

quit

Exits the Ergonomica shell.

Example

quit

list_modules

List all installed modules (packages in ~/.ergo/packages).

Example

.: list_modules
epm
vortex

title TITLE

Set the title of the current terminal window to TITLE.

Example

.: title "My Super COOl Terminal!11"

py

Python ergonomica integration.

Example

.: py "1+1" # simple expressions
2
.: py "l = 2" # set variables...
.: print $l   # and get them in the Ergonomica namespace!
2
.: py # open up the PtPython REPL (all variables here are also shared)
>>>
.
.
.

ping

ping: Ping HOSTNAMEs.

Example

Warning

The output won’t be exactly what’s shown here; there’ll likely be some output printed to STDOUT (since this calls a system process); however what is shown here is what is actually returned by this function.

.: ping 8.8.8.8
8.8.8.8 is up # returned on ctrl-c (ping process continues to run)
.: ping -c 2 8.8.8.8 INVALIDADDRESS
8.8.8.8 is up
INVALIDADDRESS is down

write [-a] FILE [LINES...]

Write lines to a file. Will overwrite file unless -a (append) option is called.

Example

.: ls
unrelated.jpeg
.: write test_file 123123 # create a new file
.: ls
test_file
unrelated.jpeg
.: read test_file
123123
.: write test_file -a abcabc # only appends; does not overwrite
.: read test_file
123123
abcabc

mv TARGET DESTINATION

Move a file from TARGET to DESTINATION.

Example

.: ls
a.txt
.: mv a.txt b.txt
.: ls
b.txt

exit

Exits the Ergonomica shell.

Example

exit

trim [head|tail] STRING

Trims surrounding whitespace in STRING.

Example

.: print " a b c "
 a b c
.: trim " a b c "
a b c
.: repr (trim head " a b c ")
u'a b c '
.: repr (trim tail " a b c ")
u' a b c'

ls <directory>[DIR] [-c | –count-files][-d | –date] [-h | –hide-dotfiles]

List files in a directory.

Example

Warning

ls shows dotfiles by default. To disable this, use the -h or --hide-dotfiles flag.

.: ls # list files as you normally would
.example_dotfile
a.txt
b.c
a.out
.: ls -d # list the creation dates
2012-18-03 09:35:21.293598 .example_dotfile
2015-21-04 08:29:46.981327 a.txt
2017-02-09 02:96:93.191238 b.c
2016-13-02 04:38:72.912840 a.out
.: ls -h # hide dotfiles
a.txt
b.c
a.out
.: ls -c # return the number of files in a directory
4
.: ls -ch # count files without dotfiles

net

Various network information commands.

Example

.: net ip local
192.168.0.4
.: net ip global
38.123.71.82
.: net mac INTERFACE
98:e1:d2:a9:c3:e2
.: net interfaces
lo
wlp3s0

size [-u UNIT] FILE...

Return the sizes of files.

Example

.: size VirtualBox.app
VirtualBox.app: 487122 kilobyte(s)
.: size -u MB VirtualBox.app
VirtualBox.app: 475 megabyte(s)

swap FILE1 FILE2

Swap the names/contents of two files.

Example

.: read a.txt
some contents
.: read b.txt
other contents
.: swap a.txt b.txt
.: read a.txt
other contents
.: read b.txt
some contents

join STRING LIST

Returns the result of list LIST joined by string STRING.

Example

.: join "_" (list this is an example string)
this_is_an_example_string

read FILE

Reads the lines of FILE.

Example

.: read a.txt
this is
an example
file!
.: len (read a.txt)
3

time [FORMAT]

Display the current time. FORMAT is in strftime format. Defaults to "%b %d %Y %H:%M:%S".

.: time
Aug 24 2017 04:29:53
.: time "year: %Y time: %H:%M:%S"
year: 2017 time: 04:30:37

pwd

Prints the working directory.

Example

.: pwd
/home/edijkstra

rm FILE

Removes file or directory FILE.

Example

.: ls
example_dir
funny_picture.jpeg
serious_picture.png
.: rm example_dir
.: ls
funny_picture.jpeg
serious_picture.png
.: rm funny_picture.jpeg
.: ls
serious_picture.png

hash ITEMS

Build a hashtable out of ITEMS.

Example

hash (list 1 2 3 4)
{1: 2, 3: 4}

hash-get ITEM HASHTABLE

Returns the item mapped to ITEM in HASHTABLE.

Example

.: set table (hash (list 1 2 3 4))
.: print $table
{1: 2, 3: 4}
.: hash-get 1 $table
2
.: hash-get 3 $table
4

hash-add ITEM VALUE HASHTABLE

Returns a copy of HASHTABLE with ITEM mapped to VALUE.

Example

.: hash-add 'a' 'b' (hash (list 1 2))
{'a': 'b', 1: 2}

hash-rem ITEM HASHTABLE

Returns a copy of HASHTABLE with ITEM removed.

.: set table (hash (list 1 2 3 4 5 6))
.: print $table
{1: 2, 3: 4, 5: 6}
.: hash-rem 5 $table
{1: 2, 3: 4}

sysinfo

Provides system-specific information.

Example

Note

In sysinfo, stat means static (i.e., unchanging information about the system), whereas dyn means dynamic (i.e., values that change).

.: sysinfo stat -a # architecture
64bit,
.: sysinfo stat -p # processor
amdk6
.: sysinfo stat -r # OS
Linux-4.12.3-1-ARCH-x86_64-with-arch
.: sysinfo stat -c # number of cores
8
.: sysinfo dyn -u # individual CPU usage percentage
[1.6, 1.5, 1.8, 1.9]
.: sysinfo stat -ap # combine and flags and get outputs for each
64bit,
amdk6

toolbar STRING

Set the text for the Ergonomica toolbar (bar at bottom of screen).

Example

toolbar "MY SUPER COOL TOOLBAR :)"

license (show w | show c)

Show Ergonomica license information. If show c specified, prints the copyright of Ergonomica. show w displays the full text of the GPLv2 license.

Example

.: show c
Ergonomica  Copyright (C) 2017  Liam Schumm, Andy Merrill, Dhyan Patel, Pavel Golubev
.: show w
                  GNU GENERAL PUBLIC LICENSE
                                       Version 3, 29 June 2007

     Copyright (C) 2007 Free Software Foundation, Inc.
     .
     .
     .

cow STRING

Make a cow say STRING.

.: cow 123
 _____
< 123 >
 -----
    \    ^__^
     \   (oo)\_______
         (__)\        )\/\
              ||----w |
              ||     ||

environment

Configure environment variables. Configuration has more information on what variables may be set.

Example

clear

Clears the screen.

Example

.: clear # clears the screen

whoami

Returns the current user.

Example

.: whoami
kernighan

pyvim [FILES...]

Pure Python Vim clone.

Example

pyvim ergo.py # opens ergo.py in pyvim

epm

Note

epm is not integrated with Ergonomica itself, but is bundled for optional installation with the Ergonomica pip installer.

Ergonomica’s package manager.

Example

.: epm install PACKAGES...     # installs all PACKAGES
.: epm uninstall PACKAGES...   # uninstalls all PACKAGES
.: epm packages (local|remote) # lists packages on machine (local) or in repos (remote)
.: epm repos                   # lists all repos
.: epm update                  # updates all package listings
.: epm add-source NAME URL     # add a new repo with a title and URL to a MANIFEST