# Scripting
## Check Program Version Matchs
```shell
if [[ "$(/usr/local/bin/tmux -V | sed 's/[[:alpha:]]//g' | tr -d '[:blank:]')" -ge "3.2" ]]; then echo y; fi
```
# Aliases
## Simple
Same as most shells.
```shell
alias ls='ls -la'
```
## Unset
```shell
unset ls
```
## Advanced Alias via Function
```shell
function some_command() {
some_pre_command
ls $@ # The command to run with the command line params $@
some_post_command
}
# Call with
some_command opt1 opt2
```
### Working Example
```shell
function cheat() {
export OLD_PAGER="$PAGER"
export PAGER='less -R'
glow --pager --width 160 $(find "$HOME/.cheats/" -iname "
[email protected]")
glow --width 160 $(find "$HOME/.cheats/" -iname "
[email protected]")
export PAGER=$OLD_PAGER
unset OLD_PAGER
}
```
## "Silent" Background/Disowned Function/Alias
This runs a command detached from the current terminal with no output to the shell.
```
```
# Functions
## [[ZSH#Aliases#Advanced Alias via Function|Functions as Aliases]]
# Arrays
## Declare
```shell
variable=("one" "two")
```
## Create from multiline output
```shell
items=($(ls -1 | tr '\n' ' '));
```
## Check if item in array
```shell
# with variable
chk="value_to_check"
if (($exiting_opts[(I)$chk])); then echo y; f
# without variable
if (($exiting_opts[(I)value_to_check])); then echo y; f
```
# Loca ZSH Options
```shell
function {
setopt localoptions
}
```
# Expressions
| Expression | Example | Description |
| ----------------- | ------------------- | --------------------------------------- |
| `!!` | `sudo !!` | Last command (`sudo !!`) |
| `!*` | `vim !*` | Last command's parameters (`vim !*`) |
| `!^` | | Last command's first parameter |
| `!
| | Last command's last parameter |
| `!?ls` `<tab>` | `sudo !?mv` `<tab>` | Command and params of last `ls` command |
| `!?ls?:*` `<tab>` | | Params of last `ls` command |
| `*(m0)` | `rm *(m0)` | Last modified today |
| `*(m-4)` | | Last modified <4 days ago |
# Change default shell
```bash
chsh -s `which zsh`
```
# Process Substitution
| Expression | Example | Description |
| ------------ | --------------------------------------------- | ----------------------------------------------------------------------- |
| `<(COMMAND)` | `grep "needle" <(curl "https://haystack.io")` | Replace argument with _named pipe/FIFO_ (read-only) with command output |
| `=(COMMAND)` | `vim =(curl "https://haystack.io")` | Replace argument with _file_ (writable) containing command output |