Scripting Language (Psilo)

Rundown includes a simple concatenative (or stacked) scripting language called Psilo. You use the scripting language to set a default value for inputs or create a list of options for dropdowns.

:[identifier: placeholder]{ Your Psilo script / command goes here }

How does it work?

When you think of building a script in Psilo:

  1. think of data being appended or removed from an array (which we refer to as a stack).

    • When you start, the stack is empty.

  2. think of your script as a list of commands that are split on spaces.

    • Every command is a function. Each function takes in the stack as an input, manipulates it, and then outputs the new stack for the next command to process.

    • This process repeats until the final command manipulates the stack then outputs it

Yes, there are two lists here. One is the "stack" which starts off as empty. The other is the list of your commands split on spaces. These are separate!

Strings, numbers, booleans, an arrays are all functions too. They take in the stack, add themselves to the end of the stack, then output the new stack.

This can be a little confusing, so let's look at a few examples. If you want to see them all, here is the full list of functions.

Examples

Example 1: Strings

This example splits a string by the comma delimiter

Script: "hello,there,my,name,is,Fig" csv

Output: [hello, there, my, name, is, Fig]

Description

There are two function here: string (with parameter "hello,there,my,name,is,Fig") and csv

  • The string function takes in the stack, appends itself to the end of it, then outputs the new stack

    • As it's the first function, the input stack is empty [ ].

    • The output of the new stack is ["hello,there,my,name,is,Fig"]

  • The csv function takes in the stack, gets the last element in the stack, removes it, splits it on the , delimiter, appends it back to the stack, then outputs the new stack

    • The output of the new stack is [hello, there, my, name, is, Fig]

Note: The function lines does the same thing as csv but splits on the newline character

This was a long explanation. The key takeaways are:

  1. The stack starts off empty

  2. Everything is a function

  3. Every function takes in the stack, manipulates it, then outputs it

  4. Strings, numbers, arrays, and booleans are also function: they just append themselves to the end of the stack

Example 2: Numbers

This example adds two numbers

Script:1 4 +

Output: 5

There are three commands here: number, number, and +

  • Number takes in the stack, append the number to the end, and outputs the new stack

  • + takes in the stack, gets the last two elements of the stack, adds them together, removes the last two elements, appends the addition to the end of the stack, outputs the new stack

Example 3: Shell Commands

This example runs a shell command

Script: "pwd" sh

Output: ~/Desktop

There are two commands here: string and sh

  • We saw String in example 1. It appends itself to the end of the stack

  • Sh takes in the stack, executes the last element as a shell command, and appends the output to the end of the stack

We essentially just ran the pwd command here!

Running "your shell command here" sh is how you run shell commands in psilo

Example 4: Object Parsing

This examples gets the "experimental" property from the JSON object in my docker config file

Script: "cat ~/.docker/config.json" sh json "experimental" prop

Output: Disabled

There are 5 functions here: string, sh, json, string, prop

  • The first two functions run the shell command cat ~/.docker/config.json

    • Because we are reading a file, the output of this is a string. The string is added to the stack

  • json takes in the stack, gets the last element, JSON.parses() it, and then outputs the stack

    • Now our stack is just 1 element which is a JSON object

  • "experimental" appends the string "experimental" onto the stack

    • The stack now has two elements: a json object, and a string

  • prop takes in the stack, gets the second last element (the JSON object), and gets the property with the name of the last element of the stack ("experimental"). It removes the last two elements and appends the value of the "experimental" key

This example read a file, JSON.parsed it, then got a specific property from it

Example 5: Loops

Script: "aws ec2 describe-regions" sh json "Regions" prop [ "RegionName" prop ] map

Output: ["eu-north-1, "ap-south-1", "eu-west-3" ...]

There are 7 functions here: string, sh, json, string, prop, function, map

  • The first 5 functions (up until prop) run the specified command, JSON.parse the output, and get the Regions property (which is an array)

    • The stack is now contains just one element: an array

  • The square brackets indicate that everything inside it (even if multiple functions) should be appended to the stack as one element

    • The stack is now two elements: the array from the "Regions prop", and the double function "RegionName" prop

  • map takes in the stack, gets the last two elements, and applies the function from the last element to each element in the array in the second last element. It creates a new array. It removes the last two elements and adds the new array to the stack

    • In this case, it creates a new array which contains the RegionName property from each object in the old array

    • The stack is now just one element, which is an array of strings.

Example 6: Fig Commands

Script: "echo hello world" run

Output: It will run echo hello world in the user's terminal

Special Fig Commands:

  • run inserts and runs the given command in the user's terminal

  • insert inserts (but does not run) the given string in the user's Terminal

  • close closes the Fig window

These Fig commands are often used with buttons.

PS: One of Fig's Co-founders, Matt, built a much more extensive version of Psilo that he codes in.