Skip to content
Snippets Groups Projects
Commit 285993d4 authored by Jeff Warner's avatar Jeff Warner
Browse files

Reformatted manual based on Rust book (2ed.)

parent ce5a57e7
No related branches found
No related tags found
No related merge requests found
Showing
with 226 additions and 30 deletions
# Table of Contents # Table of Contents
[Introduction](introduction.md) - [Introduction](ch01-00-introduction.md)
- [Summary](./SUMMARY.md) - [Feature Overview](ch02-00-features.md)
- [Feature Overview](./features.md)
- [Miscellanious](./miscellanious.md) - [Miscellaneous](ch03-00-miscellaneous.md)
- Implicit `cd`
- XDG App Directories - [Implicit `cd`](ch03-01-implicitcd.md)
- Quoting Rules - [XDG App Directories](ch03-02-xdg.md)
- Multi-line Arguments - [Quoting Rules](ch03-03-quotation.md)
- Multi-line Comments - [Multi-line Arguments](ch03-04-multiargs.md)
- [Variable Assignments](./variables.md) - [Multi-line Comments](ch03-05-multicomments.md)
- String Variables
- Array Variables - [Variable Assignments](ch04-00-variables.md)
- Aliases
- [Expansions](expansions/index.md) - [String Variables](ch04-01-strings.md)
- [Variable Expansions](expansions/variable.md) - [Tuple Variables](ch04-02-tuples.md)
- [Process Expansions](expansions/process.md) - [Array Variables](ch04-03-arrays.md)
- [Brace Expansions](expansions/brace.md) - [Arithmetic Variables](ch04-04-arithmetic.md)
- [Arithmetic Expansions](expansions/arithmetic.md) - [Exporting Variables](ch04-05-exporting.md)
- [Method Expansions](expansions/methods.md)
- [Slicing Syntax](./slicing.md) - [Expansions](ch05-00-expansions.md)
- [Control Flow](flow/index.md)
- [Conditionals](flow/conditionals.md) - [Variable Expansions](ch05-01-variable.md)
- [Loops](flow/loops.md) - [Process Expansions](ch05-02-process.md)
- [Matches](flow/matches.md) - [Brace Expansions](ch05-03-brace.md)
- [Script Executions](./scripts.md) - [Arithmetic Expansions](ch05-04-arithmetic.md)
- [Signal Handling](./signals.md) - [Method Expansions](ch05-05-methods.md)
- [Job Control](./jobs.md)
- [Builtin Commands](builtins/index.md) - [Slicing Syntax](ch06-00-slicing.md)
- [Ion By Example](./tutorial.md)
- [Control Flow](ch07-00-index.md)
- [Conditionals](ch07-01-conditionals.md)
- [Loops](ch07-02-loops.md)
- [Matches](ch07-03-matches.md)
- [Script Executions](ch08-00-scripts.md)
- [Signal Handling](ch09-00-signals.md)
- [Job Control](ch10-00-jobs.md)
- [Builtin Commands](ch11-00-builtins.md)
- [Ion by Example](ch12-00-examples.md)
File moved
File moved
# Miscellanious Features
These are features of Ion that don't belong to any specific category:
- [Implicit `cd`](ch03-01-implicitcd.md)
- [XDG App Directories](ch03-02-xdg.md)
- [Quoting Rules](ch03-03-quotation.md)
- [Multi-line Arguments](ch03-04-multiargs.md)
- [Multi-line Comments](ch03-05-multicomments.md)
# Implicit `cd`
Like the [Friendly Interactive Shell](), Ion also supports executing the `cd` command automatically
when given a path. Paths are denoted by beginning with `.`/`/`/`~`, or ending with `/`.
```ion
~/Documents # cd ~/Documents
.. # cd ..
.config # cd .config
examples/ # cd examples/
```
# XDG App Dirs Support
All files created by Ion can be found in their respective XDG application directories. In example,
the init file for Ion can be found in **$HOME/.config/ion/initrc** on Linux systems; and the
history file can be found at **$HOME/.local/share/ion/history**. On the first launch of Ion, a
message will be given to indicate the location of these files.
# Quoting Rules
In general, double quotes allow expansions within quoted text, whereas single quotes do not.
An exception to the rule is brace expansions, where double quotes are not allowed. When
arguments are parsed, the general rule is the replace newlines with spaces. When double-quoted
expansions will retain their newlines. Quoting rules are reversed for heredocs and for loops.
# Multi-line Arguments
If a line in your script becomes too long, you may signal to Ion to continue reading the next line
by appending an `\` character at the end of the line. This will ignore newlines.
```ion
command arg arg2 \
arg3 arg4 \
arg 5
```
# Multi-line Comments
If a comment needs to contain newlines, you may do so by having an open quote, as Ion will only
begin parsing supplied commands that are terminated. Either double or single quotes may be used
for this purpose, depending on which quoting rules that you need.
echo "This is the first line
this is the second line
this is the third line"
# General Tips
## Let Arithmetic vs Arithmetic Expansions
Using **let** arithmetic is generally faster than **$(())** expansions. The arithmetic expansions
should be used for increasing readability, or more complex arithmetic; but if speed is important,
multiple let arithmetic statements will tend to be faster than a single arithmetic expansion.
# Variable Assignments
The `let` builtin is used to create local variables within the shell, and apply basic arithmetic
to variables. The `export` keyword may be used to do the same for the creation of external
variables. Variables cannot be created the POSIX way, as the POSIX way is awkard to read/write
and parse.
# String Variables
Using the `let` builtin, a string can easily be created by specifying the name, and an expression
that will be evaluated before assigning it to that variable.
```ion
let git_branch = $(git rev-parse --abbrev-ref HEAD ^> /dev/null)
```
To call a string variable, you may utilize the **$** sigil along with the name of the variable. For more information on expansions, see the expansions section of this manual.
```ion
echo $git_branch
```
## Dropping String Variables
The `drop` command may be used to drop string variables.
```ion
let variable = "testing"
echo $variable
drop variable
echo $variable
```
# Tuple Assignments
Ion also supports assigning multiple variables at once, which can increase readability and save
some precious CPU cycles. The general trend is that the less statements that you execute, the
faster your scripts will execute, but there are some exceptions to the rule -- see the general
tips in the miscellanious section. In addition to assigning multiple variables, this can also
be used to swap variables.
```ion
let a b = 1 2
let a b = [1 2]
let a b = [$b $a]
```
Do note, however, that if you supply too many values, they will be ignored.
```ion
$ let a b = 1 2 3
$ echo $a $b
> 1 2
```
# Variable Assignments # Array Variables
The `let` builtin is used to create local variables within the shell, and apply basic arithmetic
to variables. The `export` keyword may be used to do the same for the creation of external
variables. Variables cannot be created the POSIX way, as the POSIX way is awkard to read/write
and parse.
## String Variables
Using the `let` builtin, a string can easily be created by specifying the name, and an expression
that will be evaluated before assigning it to that variable.
```ion
let git_branch = $(git rev-parse --abbrev-ref HEAD ^> /dev/null)
```
To call a string variable, you may utilize the **$** sigil along with the name of the variable. For more information on expansions, see the expansions section of this manual.
```ion
echo $git_branch
```
## Tuple Assignments
Ion also supports assigning multiple variables at once, which can increase readability and save
some precious CPU cycles. The general trend is that the less statements that you execute, the
faster your scripts will execute, but there are some exceptions to the rule -- see the general
tips in the miscellanious section. In addition to assigning multiple variables, this can also
be used to swap variables.
```ion
let a b = 1 2
let a b = [1 2]
let a b = [$b $a]
```
Do note, however, that if you supply too many values, they will be ignored.
```ion
$ let a b = 1 2 3
$ echo $a $b
> 1 2
```
## Dropping String Variables
The `drop` command may be used to drop string variables.
```ion
let variable = "testing"
echo $variable
drop variable
echo $variable
```
## Array Variables
The **[]** syntax in Ion is utilized to denote that the contents within should be parsed as an The **[]** syntax in Ion is utilized to denote that the contents within should be parsed as an
array expression. Array variables are also created using the same `let` keyword, but `let` makes array expression. Array variables are also created using the same `let` keyword, but `let` makes
...@@ -90,35 +34,3 @@ echo @array ...@@ -90,35 +34,3 @@ echo @array
drop -a array drop -a array
echo @array echo @array
``` ```
## Let Arithmetic
Ion supports applying some basic arithmetic, one operation at a time, to string variables. To
specify to `let` to perform some arithmetic, designate the operation immediately before **=**.
Operators currently supported are:
- [x] Add (**+**)
- [x] Subtract (**-**)
- [x] Multiply (**\***)
- [x] Divide (**/**)
- [ ] Integer Divide (**//**)
- [ ] Modulus (**%**)
- [ ] Powers (not stabilized yet: **^**; subject to change to **\*\***)
```ion
let value = 0
let value += 5
let value -= 2
let value *= 3
let value /= 2
```
## Exporting Variables
The `export` builtin operates identical to the `let` builtin, but it does not support arrays,
and variables are exported to the OS environment.
```ion
export GLOBAL_VAL = "this"
```
# Let Arithmetic
Ion supports applying some basic arithmetic, one operation at a time, to string variables. To
specify to `let` to perform some arithmetic, designate the operation immediately before **=**.
Operators currently supported are:
- [x] Add (**+**)
- [x] Subtract (**-**)
- [x] Multiply (**\***)
- [x] Divide (**/**)
- [ ] Integer Divide (**//**)
- [ ] Modulus (**%**)
- [ ] Powers (not stabilized yet: **^**; subject to change to **\*\***)
```ion
let value = 0
let value += 5
let value -= 2
let value *= 3
let value /= 2
```
# Exporting Variables
The `export` builtin operates identical to the `let` builtin, but it does not support arrays,
and variables are exported to the OS environment.
```ion
export GLOBAL_VAL = "this"
```
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment