A Summary
GarmScript is a simple programming language with the purpose of automating trivial terminal tasks. Along with this, it has tools and functions to perform more complex tasks such as REST API requests and library support. GarmScript has most of the basic features of a simple language such as bash, but is designed to make it as easy as possible to read and understand without needing too much experience.
The Basics
GarmScript includes many functions and operators to expand apon its goal of optimizing trivial tasks, but the simplest introduction to GarmScript is to automate shell commands. This can accomplished by first cloning the repository to your system and then creating a new "test.garm" file for your program. Once you have a empty file you can start the following tutorial.
First, within your ".garm" file simply type the shell command you want to execute, and then run the file with the command:
python3 garmscript.py test.garm
This will execute whatever shell command you typed into the file, which by itself is not very impressive. However you can use variables and loops to actually use GarmScript to the fullest. Reopen you "test.garm" file and replace your previous command with the following:
setvar sentence HELLO WORLD
loop forever
echo $sentence
wait 1
end
This will say the words "HELLO WORLD" every second. While this is pretty useless, it gives a good starting point for variables and loops. This is because we defined the variable "sentence" with the value "HELLO WORLD" and then looped forever the shell command echo. Within shell commands in GarmScript you can add $ infront of any variable name in the command to use that variable in the command in the place where the variable name is used.
Ok now that we have created a simple program let's look at using some basic functions to expand on our program.
Expanding On The Basics
First, "%" at the start of a line in GarmScript will declare that line as a comment and therefore it will not be executed. Along with this in GarmScript certain builtin functions can be called, for example the "readinput" function will get user input in the terminal. Open back up your "test.garm" file and replace what is in there with this.
setvar sentence ""
loop forever
readinput sentence What to Echo? :
echo $sentence
wait 1
end
This program will ask the user for a sentence and then echo back whatever the user typed in. For more functions consult the reference page of the documentation. Ok, now we are getting somewhere, how about conditional statements? Well the next section will cover those.
Conditional Statements
Ok, in GarmScript conditional statements can be used to check if the value of a variable matches another variable. For example the following code will do ask the user for a word and if it matches the word "HELLO" the program will respond with the word "WORLD".
setvar sentence ""
setvar hello HELLO
readinput sentence Hello? :
if sentence == hello
echo WORLD
end
That is how you can do conditional statements in GarmScript. The next section will cover snippets and some other extra things.
Snippets And Extras
In GarmScript code can be reused similarly to a function but without arguments. This can be done with the "snip" function. For example:
snip testfunc {echo HELLO;;echo WORLD}
&testfunc
This program creates a snippet called "testfunc" and executes it with the "&" operator. Notice how multiple lines can be accomplished with the ;; operator. The ;; operator will create a new line on the same line when in snippets and ; will do the same thing outside snippets. Ok, now that covers the basics of GarmScript, now enjoy!
Final Word
GarmScript is a personal project I have been working on for fun, dont expect many updates however when I can I like to update and improve things with GarmScript. Also note that GarmScript is new and most likely buggy, just know that I am working on that as well as I can.