Skip to content

Program Examples

Sofia edited this page Jun 6, 2023 · 1 revision

A list of program examples, divided in categories

Prompts

all the code snippets in this page are to be put in a function definition, which must be the very last thing your /home/<user>/.config/config.re config file calls. That is, your file should look like this:

...
let my_prompt ()
    # Pick a prompt you like from this page, or make your own, and put it here.
    # Don't forget the trailing semicolon, which is always included in the snippets found here,
    # So you don't have to care about it, but keep in mind that a semicolon is the very last token
    # that terminates a function definition, or any statement. For more information about it, refer to
    #rewind_split_file() in src/shell/shell.hpp, from the project root.

SwitchAxe's lame, minimal, but effective, prompt

let prompt () s+ (get PWD) " λ ";

Another possible prompt using exclusively lambda functions and function composition

let cyan "\e[1;36m";
let red "\e[1;31m";
let yellow "\e[1;33m";
let blank "\e[0m";
let green "\e[1;32m";
let arrow "➜ ";

let git_branch ()
    sh -c "git branch --show-current 2>/dev/null";

# << PUT HERE A FUNCTION TO FIND THE BATTERY PERCENTAGE ON YOUR SYSTEM >>
let batt () "15";

let find_pwd () basename (-> (echo (get PWD)) (sed "s/\/home\/your_user/~/"));

# The prompt itself. If you have any questions about it, message me on Telegram at @SwitchAxe.

let prompt ()
     tos <<
     (y) => s+ y $green $arrow $blank; <<
     (b) => s+ b [(btt) (< (toi btt) 20) ?=> s+ $red btt "%", ""; (batt)] ; <<
     (x) => s+ x $blank
                 ((s) (!= s "") ?=> s+ " on " $yellow " " s $blank,
                                    @s; (git_branch)); <<
     () => s+ $cyan (find_pwd);;