Compare commits
27
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12b0d3d8b8 | ||
|
|
9c6d49cd5d | ||
|
|
fff9a0e70e | ||
|
|
ecbc266165 | ||
|
|
5dd9b59b90 | ||
|
|
1768a69cf1 | ||
|
|
35e45b9fd5 | ||
|
|
086682194b | ||
|
|
96ddb7a611 | ||
|
|
bd2349c1ba | ||
|
|
b4fd6c1988 | ||
|
|
8d1278b84a | ||
|
|
e4a935de25 | ||
|
|
d8732c5e2e | ||
|
|
ba41c9a054 | ||
|
|
894d2fcabf | ||
|
|
40adefb70c | ||
|
|
faea500177 | ||
|
|
6f74961fc6 | ||
|
|
cc7139c2ff | ||
|
|
bac22a5657 | ||
|
|
20d080e223 | ||
|
|
847c71a194 | ||
|
|
78b8bf177c | ||
|
|
4f8e722f13 | ||
|
|
1f58b9f136 | ||
|
|
4d3aada204 |
@@ -0,0 +1,391 @@
|
||||
# Bash Cheat Sheet
|
||||
|
||||
## Conditionals
|
||||
|
||||
```bash
|
||||
if [[ -z "$string" ]]; then
|
||||
echo "String is empty"
|
||||
elif [[ -n "$string" ]]; then
|
||||
echo "String is not empty"
|
||||
fi
|
||||
```
|
||||
|
||||
### String conditions
|
||||
┌────────────────────────┬──────────────────┐
|
||||
│ `[[ -z STRING ]]` │ Empty string │
|
||||
├────────────────────────┼──────────────────┤
|
||||
│ `[[ -n STRING ]]` │ Not empty string │
|
||||
├────────────────────────┼──────────────────┤
|
||||
│ `[[ STRING == STRING ]]` │ Equal │
|
||||
├────────────────────────┼──────────────────┤
|
||||
│ `[[ STRING != STRING ]]` │ Not Equal │
|
||||
├────────────────────────┼──────────────────┤
|
||||
│ `[[ STRING =~ STRING ]]` │ Regex │
|
||||
└────────────────────────┴──────────────────┘
|
||||
|
||||
### Number conditions
|
||||
┌────────────────────────┬───────────────────────┐
|
||||
│ `[[ NUM1 -eq NUM2 ]]` │ Equal │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -ne NUM2 ]]` │ Not Equal │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -lt NUM2 ]]` │ Less than │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -le NUM2 ]]` │ Less than or equal │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -gt NUM2 ]]` │ Greater than │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -ge NUM2 ]]` │ Greater than or equal │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `(( NUM < NUM ))` │ Numeric conditions │
|
||||
└────────────────────────┴───────────────────────┘
|
||||
|
||||
### File conditions
|
||||
┌───────────────────────┬─────────────────────────┐
|
||||
│ `[[ -e FILE ]]` │ Exists │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -r FILE ]]` │ Readable │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -h FILE ]]` │ Symlink │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -d FILE ]]` │ Directory │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -w FILE ]]` │ Writable │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -s FILE ]]` │ Size is > 0 bytes │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -f FILE ]]` │ File │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -x FILE ]]` │ Executable │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ FILE1 -nt FILE2 ]]` │ 1 is more recent than 2 │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ FILE1 -ot FILE2 ]]` │ 2 is more recent than 1 │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ FILE1 -ef FILE2 ]]` │ Same files │
|
||||
└───────────────────────┴─────────────────────────┘
|
||||
|
||||
### Other conditions
|
||||
┌────────────────────┬────────────────────┐
|
||||
│ `[[ -o noclobber ]]` │ Option enabled │
|
||||
├────────────────────┼────────────────────┤
|
||||
│ `[[ ! EXPR ]]` │ Not │
|
||||
├────────────────────┼────────────────────┤
|
||||
│ `[[ X && Y ]]` │ And │
|
||||
├────────────────────┼────────────────────┤
|
||||
│ `[[ X || Y ]]` │ Or │
|
||||
└────────────────────┴────────────────────┘
|
||||
|
||||
## Parameter manipulation
|
||||
┌─────────────────────────────────┬────────────────────────────────────────────────────────────────┐
|
||||
│ `${foo}` │ Variable │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo/from/to}` │ Replace first match │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo/#from/to}`/`${foo/%from/to}` │ Replace first match anchored to start (default) or end │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo//from/to}` │ Replace all │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:start:length}` │ Slice from `start` to `length` (both optional and can be negative) │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo%suffix}`/`${foo%%suffix}` │ Remove `suffix` (ungreedy/greedy) │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo#prefix}`/`${foo##prefix}` │ Remove `prefix` (ungreedy/greedy) │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${#foo}` │ Length of `foo` │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo,}` │ Lowercase first letter │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo,,}` │ Lowercase all letters │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo^}` │ Uppercase first letter │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo^^}` │ Uppercase all letters │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:-val}` │ Use `val` if `foo` is unset or null │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:=val}` │ Set `foo` to `val` if unset or null │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:+val}` │ Use `val` if `foo` **is** set and not null │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:?message}` │ Print `message` and exit if `foo` is unset or null │
|
||||
└─────────────────────────────────┴────────────────────────────────────────────────────────────────┘
|
||||
> Omitting the `:` for default values will only check if the variable is set, not if it is null.
|
||||
|
||||
### Examples
|
||||
```bash
|
||||
name="John"
|
||||
echo "${name}"
|
||||
echo "${name/J/j}" #=> "john" (substitution)
|
||||
echo "${name:0:2}" #=> "Jo" (slicing)
|
||||
echo "${name::2}" #=> "Jo" (slicing)
|
||||
echo "${name::-1}" #=> "Joh" (slicing)
|
||||
echo "${name:(-1)}" #=> "n" (slicing from right)
|
||||
echo "${name:(-2):1}" #=> "h" (slicing from right)
|
||||
echo "${food:-Cake}" #=> $food or "Cake"
|
||||
|
||||
length=2
|
||||
echo "${name:0:length}" #=> "Jo" (slicing with variable)
|
||||
|
||||
str="/path/to/foo.cpp"
|
||||
echo "${str%.cpp}" # /path/to/foo
|
||||
echo "${str%.cpp}.o" # /path/to/foo.o
|
||||
echo "${str%/*}" # /path/to
|
||||
|
||||
echo "${str##*.}" # cpp (extension)
|
||||
echo "${str##*/}" # foo.cpp (basepath)
|
||||
echo "${str#*o}" # o/foo.cpp (first occurrence of 'o')
|
||||
echo "${str##*o}" # oo.cpp (last occurrence of 'o')
|
||||
|
||||
echo "${str#*/}" # path/to/foo.cpp
|
||||
echo "${str##*/}" # foo.cpp
|
||||
|
||||
echo "${str/foo/bar}" # /path/to/bar.cpp
|
||||
|
||||
str="HELLO WORLD!"
|
||||
echo "${str,}" #=> "hELLO WORLD!" (lowercase 1st letter)
|
||||
echo "${str,,}" #=> "hello world!" (all lowercase)
|
||||
|
||||
str="hello world!"
|
||||
echo "${str^}" #=> "Hello world!" (uppercase 1st letter)
|
||||
echo "${str^^}" #=> "HELLO WORLD!" (all uppercase)
|
||||
```
|
||||
|
||||
## Comments
|
||||
```bash
|
||||
# This is a comment
|
||||
|
||||
: '
|
||||
This is a multi-line comment workaround
|
||||
'
|
||||
```
|
||||
|
||||
## Loops
|
||||
### Basic for loop
|
||||
```bash
|
||||
for i in /etc/rc.*; do
|
||||
echo "$i"
|
||||
done
|
||||
```
|
||||
|
||||
### C-style for loop
|
||||
```bash
|
||||
for (( i = 0; i < 10; i++ )); do
|
||||
echo "$i"
|
||||
done
|
||||
```
|
||||
|
||||
### Ranges
|
||||
```bash
|
||||
for i in {1..10}; do
|
||||
echo "$i"
|
||||
done
|
||||
|
||||
# With step size
|
||||
for i in {1..10..2}; do
|
||||
echo "$i"
|
||||
done
|
||||
```
|
||||
|
||||
### Reading lines
|
||||
```bash
|
||||
while IFS= read -r line; do
|
||||
echo "$line"
|
||||
done < file.txt
|
||||
```
|
||||
|
||||
### Infinite loop
|
||||
```bash
|
||||
while true; do
|
||||
echo "Press [CTRL+C] to stop.."
|
||||
sleep 1
|
||||
done
|
||||
```
|
||||
|
||||
## History
|
||||
┌───────────────┬────────────────────────────────────────────────────────────────┐
|
||||
│ `!!` │ Expand latest command in history │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!$` │ Expand last parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!*` │ Expand all parameters of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!-n` │ Expand nth latest command in history │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!n` │ Expand nth command in history │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!string` │ Expand latest command starting with string │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:s/from/to` │ Replace first occurrence of "from" with "to" in latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:gs/from/to` │ Replace all occurrences of "from" with "to" in latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:p` │ Print latest command without executing it │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!$:t` │ Expand basename of last parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!$:h` │ Expand directory of last parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:n` │ Expand only nth parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!^` │ Expand first parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!$` │ Expand last parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:n-m` │ Expand parameters from nth to mth of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:n-$` │ Expand parameters from nth to last of latest command │
|
||||
└───────────────┴────────────────────────────────────────────────────────────────┘
|
||||
|
||||
## Redirection
|
||||
┌────────────────────────────┬─────────────────────────────────┐
|
||||
│ `SCRIPT > FILE` │ stdout to FILE │
|
||||
├────────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT >> FILE` │ Append stdout to FILE │
|
||||
├────────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT 2> FILE` │ stderr to FILE │
|
||||
├────────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT 2>&1`/`SCRIPT &> FILE` │ stderr to stdout │
|
||||
├────────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT 2> /dev/null` │ stderr to /dev/null │
|
||||
├────────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT > FILE 2>&1` │ stdout and stderr to FILE │
|
||||
├────────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT &> /dev/null` │ stdout and stderr to /dev/null │
|
||||
├────────────────────────────┼─────────────────────────────────┤
|
||||
│ `echo "$0: warning" >&2` │ Print to stderr │
|
||||
├────────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT < FILE` │ stdin from FILE │
|
||||
└────────────────────────────┴─────────────────────────────────┘
|
||||
|
||||
## Switch statement
|
||||
```bash
|
||||
case "$1" in
|
||||
start | up)
|
||||
vagrant up
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|ssh}"
|
||||
;;
|
||||
esac
|
||||
```
|
||||
|
||||
### Options switch statement
|
||||
```bash
|
||||
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
|
||||
-V | --version )
|
||||
echo "$version"
|
||||
exit
|
||||
;;
|
||||
-s | --string )
|
||||
shift; string=$1
|
||||
;;
|
||||
-f | --flag )
|
||||
flag=1
|
||||
;;
|
||||
esac; shift; done
|
||||
if [[ "$1" == '--' ]]; then shift; fi
|
||||
```
|
||||
|
||||
## Functions
|
||||
```bash
|
||||
my_function() {
|
||||
echo "Hello, World!"
|
||||
}
|
||||
```
|
||||
|
||||
### Arguments
|
||||
┌────┬───────────────────────────────────┐
|
||||
│ `$#` │ Number of arguments │
|
||||
├────┼───────────────────────────────────┤
|
||||
│ `$*` │ All arguments │
|
||||
├────┼───────────────────────────────────┤
|
||||
│ `$@` │ All arguments as separate strings │
|
||||
├────┼───────────────────────────────────┤
|
||||
│ `$1` │ First argument │
|
||||
├────┼───────────────────────────────────┤
|
||||
│ `$_` │ Last argument │
|
||||
└────┴───────────────────────────────────┘
|
||||
|
||||
## Arrays
|
||||
```bash
|
||||
# Create an array in one line
|
||||
Fruits=('Apple' 'Banana' 'Orange')
|
||||
|
||||
# Or assign each value
|
||||
Fruits[0]="Apple"
|
||||
Fruits[1]="Banana"
|
||||
Fruits[2]="Orange"
|
||||
|
||||
# Associative array
|
||||
declare -A sounds
|
||||
|
||||
sounds[dog]="bark"
|
||||
sounds[cow]="moo"
|
||||
sounds[bird]="tweet"
|
||||
sounds[wolf]="howl"
|
||||
```
|
||||
|
||||
### Array element expansion
|
||||
┌──────────────────────┬────────────────────────────────────────────────────┐
|
||||
│ `${array[key]}` │ Element at `key` │
|
||||
├──────────────────────┼────────────────────────────────────────────────────┤
|
||||
│ `${array[-1]}` │ Last element (not for associative) │
|
||||
├──────────────────────┼────────────────────────────────────────────────────┤
|
||||
│ `${array[@]}` │ All elements │
|
||||
├──────────────────────┼────────────────────────────────────────────────────┤
|
||||
│ `${#array[@]}` │ Number of elements │
|
||||
├──────────────────────┼────────────────────────────────────────────────────┤
|
||||
│ `${#array}` │ String length of 1st element (not for associative) │
|
||||
├──────────────────────┼────────────────────────────────────────────────────┤
|
||||
│ `${#array[key]}` │ String length of element at `key` │
|
||||
├──────────────────────┼────────────────────────────────────────────────────┤
|
||||
│ `${array[@]:n:length}` │ `length` eements from position `n` │
|
||||
├──────────────────────┼────────────────────────────────────────────────────┤
|
||||
│ `${!array[@]}` │ Keys of all elements │
|
||||
└──────────────────────┴────────────────────────────────────────────────────┘
|
||||
|
||||
### Operations
|
||||
```bash
|
||||
Fruits=("${Fruits[@]}" "Watermelon") # Push
|
||||
Fruits+=('Watermelon') # Also Push
|
||||
Fruits=( "${Fruits[@]/Ap*/}" ) # Remove by regex match
|
||||
unset Fruits[2] # Remove one item
|
||||
Fruits=("${Fruits[@]}") # Duplicate
|
||||
Fruits=("${Fruits[@]}" "${Veggies[@]}") # Concatenate
|
||||
words=($(< datafile)) # From file (split by IFS)
|
||||
```
|
||||
|
||||
### Looping
|
||||
```bash
|
||||
for i in "${Fruits[@]}"; do
|
||||
echo "$i"
|
||||
done
|
||||
|
||||
for key in "${!sounds[@]}"; do
|
||||
echo "$key"
|
||||
done
|
||||
```
|
||||
|
||||
## Misc
|
||||
|
||||
### Directory of script
|
||||
```bash
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
```
|
||||
|
||||
### Special variables
|
||||
┌──────────────────┬────────────────────────────────────────┐
|
||||
│ `$?` │ Exit status of last task │
|
||||
├──────────────────┼────────────────────────────────────────┤
|
||||
│ `$!` │ PID of last background task │
|
||||
├──────────────────┼────────────────────────────────────────┤
|
||||
│ `$$` │ PID of shell │
|
||||
├──────────────────┼────────────────────────────────────────┤
|
||||
│ `$0` │ Filename of the shell script │
|
||||
├──────────────────┼────────────────────────────────────────┤
|
||||
│ `$_` │ Last arugment of altest command │
|
||||
├──────────────────┼────────────────────────────────────────┤
|
||||
│ `${PIPESTATUS[n]}` │ Return value of piped commands (array) │
|
||||
└──────────────────┴────────────────────────────────────────┘
|
||||
@@ -0,0 +1,205 @@
|
||||
# Regex Cheat Sheet
|
||||
|
||||
## Anchors
|
||||
┌────┬─────────────────────────────────────────────────────────┐
|
||||
│ ^ │ Start of string, or start of line in multi-line pattern │
|
||||
├────┼─────────────────────────────────────────────────────────┤
|
||||
│ \A │ Start of string │
|
||||
├────┼─────────────────────────────────────────────────────────┤
|
||||
│ $ │ End of string, or end of line in multi-line pattern │
|
||||
├────┼─────────────────────────────────────────────────────────┤
|
||||
│ \Z │ End of string │
|
||||
├────┼─────────────────────────────────────────────────────────┤
|
||||
│ \b │ Word boundary │
|
||||
├────┼─────────────────────────────────────────────────────────┤
|
||||
│ \B │ Not word boundary │
|
||||
├────┼─────────────────────────────────────────────────────────┤
|
||||
│ \< │ Start of word │
|
||||
├────┼─────────────────────────────────────────────────────────┤
|
||||
│ \> │ End of word │
|
||||
└────┴─────────────────────────────────────────────────────────┘
|
||||
|
||||
## Character Classes
|
||||
┌────┬────────────────────┐
|
||||
│ \c │ Control character │
|
||||
├────┼────────────────────┤
|
||||
│ \s │ White space │
|
||||
├────┼────────────────────┤
|
||||
│ \S │ Not white space │
|
||||
├────┼────────────────────┤
|
||||
│ \d │ Digit │
|
||||
├────┼────────────────────┤
|
||||
│ \D │ Not digit │
|
||||
├────┼────────────────────┤
|
||||
│ \w │ Word │
|
||||
├────┼────────────────────┤
|
||||
│ \W │ Not word │
|
||||
├────┼────────────────────┤
|
||||
│ \x │ Hexadecimal digit │
|
||||
├────┼────────────────────┤
|
||||
│ \O │ Octal digit │
|
||||
└────┴────────────────────┘
|
||||
|
||||
## POSIX
|
||||
┌───────────┬───────────────────────────────┐
|
||||
│ `[:upper:]` │ Upper case letters │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:lower:]` │ Lower case letters │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:alpha:]` │ All letters │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:alnum:]` │ Digits and letters │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:digit:]` │ Digits │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:xdigit:]`│ Hexadecimal digits │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:punct:]` │ Punctuation │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:blank:]` │ Space and tab │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:space:]` │ Blank characters │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:cntrl:]` │ Control characters │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:graph:]` │ Printed characters │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:print:]` │ Printed characters and spaces │
|
||||
├───────────┼───────────────────────────────┤
|
||||
│ `[:word:]` │ Digits, letters and underscore│
|
||||
└───────────┴───────────────────────────────┘
|
||||
|
||||
## Assertions
|
||||
┌──────┬──────────────────────────────┐
|
||||
│ ?= │ Lookahead assertion │
|
||||
├──────┼──────────────────────────────┤
|
||||
│ ?! │ Negative lookahead │
|
||||
├──────┼──────────────────────────────┤
|
||||
│ ?<= │ Lookbehind assertion │
|
||||
├──────┼──────────────────────────────┤
|
||||
│ ?!= │ Negative lookbehind │
|
||||
│ ?<! │ │
|
||||
├──────┼──────────────────────────────┤
|
||||
│ ?> │ Once-only subexpression │
|
||||
├──────┼──────────────────────────────┤
|
||||
│ ?() │ Condition `[if then]` │
|
||||
├──────┼──────────────────────────────┤
|
||||
│ ?()| │ Condition `[if then else]` │
|
||||
├──────┼──────────────────────────────┤
|
||||
│ ?# │ Comment │
|
||||
└──────┴──────────────────────────────┘
|
||||
|
||||
## Quantifiers
|
||||
┌───────┬─────────────┐
|
||||
│ * │ 0 or more │
|
||||
├───────┼─────────────┤
|
||||
│ + │ 1 or more │
|
||||
├───────┼─────────────┤
|
||||
│ ? │ 0 or 1 │
|
||||
├───────┼─────────────┤
|
||||
│ {3} │ Exactly 3 │
|
||||
├───────┼─────────────┤
|
||||
│ {3,} │ 3 or more │
|
||||
├───────┼─────────────┤
|
||||
│ {3,5} │ 3, 4 or 5 │
|
||||
└───────┴─────────────┘
|
||||
> Add a `?` to a quantifier to make it ungreedy.
|
||||
|
||||
## Escape Sequences
|
||||
┌────┬─────────────────────────────┐
|
||||
│ \ │ Escape following character │
|
||||
├────┼─────────────────────────────┤
|
||||
│ \Q │ Begin literal sequence │
|
||||
├────┼─────────────────────────────┤
|
||||
│ \E │ End literal sequence │
|
||||
└────┴─────────────────────────────┘
|
||||
> "Escaping" is a way of treating characters which have a special meaning in regular expressions literally, rather than as special characters.
|
||||
|
||||
## Common Metacharacters
|
||||
┌───┬───┬───┬───┐
|
||||
│ ^ │ [ │ . │ $ │
|
||||
├───┼───┼───┼───┤
|
||||
│ { │ * │ ( │ \ │
|
||||
├───┼───┼───┼───┤
|
||||
│ + │ ) │ | │ ? │
|
||||
├───┼───┼───┼───┤
|
||||
│ < │ > │ │ │
|
||||
└───┴───┴───┴───┘
|
||||
> The escape character is usually `\`.
|
||||
|
||||
## Special Characters
|
||||
┌──────┬────────────────────┐
|
||||
│ \n │ New line │
|
||||
├──────┼────────────────────┤
|
||||
│ \r │ Carriage return │
|
||||
├──────┼────────────────────┤
|
||||
│ \t │ Tab │
|
||||
├──────┼────────────────────┤
|
||||
│ \v │ Vertical tab │
|
||||
├──────┼────────────────────┤
|
||||
│ \f │ Form feed │
|
||||
├──────┼────────────────────┤
|
||||
│ \xxx │ Octal character xxx│
|
||||
├──────┼────────────────────┤
|
||||
│ \xhh │ Hex character hh │
|
||||
└──────┴────────────────────┘
|
||||
|
||||
## Groups and Ranges
|
||||
┌─────────┬────────────────────────────────────┐
|
||||
│ . │ Any character except new line (\n) │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ (a|b) │ a or b │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ (...) │ Group │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ (?:...) │ Passive (non-capturing) group │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ `[abc]` │ Range (a or b or c) │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ `[^abc]` │ Not (a or b or c) │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ `[a-q]` │ Lower case letter from a to q │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ `[A-Q]` │ Upper case letter from A to Q │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ `[0-7]` │ Digit from 0 to 7 │
|
||||
├─────────┼────────────────────────────────────┤
|
||||
│ \x │ Group/subpattern number "x" │
|
||||
└─────────┴────────────────────────────────────┘
|
||||
> Ranges are inclusive.
|
||||
|
||||
## Pattern Modifiers
|
||||
┌────┬────────────────────────────────────┐
|
||||
│ g │ Global match │
|
||||
├────┼────────────────────────────────────┤
|
||||
│ i │ Case-insensitive │
|
||||
├────┼────────────────────────────────────┤
|
||||
│ m │ Multiple lines │
|
||||
├────┼────────────────────────────────────┤
|
||||
│ s │ Treat string as single line │
|
||||
├────┼────────────────────────────────────┤
|
||||
│ x │ Allow comments and whitespace │
|
||||
├────┼────────────────────────────────────┤
|
||||
│ e │ Evaluate replacement │
|
||||
├────┼────────────────────────────────────┤
|
||||
│ U │ Ungreedy pattern │
|
||||
└────┴────────────────────────────────────┘
|
||||
> * PCRE modifier
|
||||
|
||||
## String Replacement
|
||||
┌────┬──────────────────────────────────┐
|
||||
│ `$n` │ nth non-passive group │
|
||||
├────┼──────────────────────────────────┤
|
||||
│ `$2` │ "xyz" in `/^(abc(xyz))$/` │
|
||||
├────┼──────────────────────────────────┤
|
||||
│ `$1` │ "xyz" in `/^(?:abc)(xyz)$/` │
|
||||
├────┼──────────────────────────────────┤
|
||||
│ `$`` │ Before matched string │
|
||||
├────┼──────────────────────────────────┤
|
||||
│ `$'` │ After matched string │
|
||||
├────┼──────────────────────────────────┤
|
||||
│ `$+` │ Last matched string │
|
||||
├────┼──────────────────────────────────┤
|
||||
│ `$&` │ Entire matched string │
|
||||
└────┴──────────────────────────────────┘
|
||||
> Some regex implementations use `\` instead of `$`.
|
||||
@@ -0,0 +1,437 @@
|
||||
# ZSH Cheat Sheet
|
||||
|
||||
## Conditionals
|
||||
|
||||
```zsh
|
||||
if [[ -z "$string" ]]; then
|
||||
echo "String is empty"
|
||||
elif [[ -n "$string" ]]; then
|
||||
echo "String is not empty"
|
||||
fi
|
||||
```
|
||||
|
||||
### String conditions
|
||||
┌────────────────────────┬──────────────────┐
|
||||
│ `[[ -z STRING ]]` │ Empty string │
|
||||
├────────────────────────┼──────────────────┤
|
||||
│ `[[ -n STRING ]]` │ Not empty string │
|
||||
├────────────────────────┼──────────────────┤
|
||||
│ `[[ STRING == STRING ]]` │ Equal │
|
||||
├────────────────────────┼──────────────────┤
|
||||
│ `[[ STRING != STRING ]]` │ Not Equal │
|
||||
├────────────────────────┼──────────────────┤
|
||||
│ `[[ STRING =~ STRING ]]` │ Regex │
|
||||
└────────────────────────┴──────────────────┘
|
||||
|
||||
### Number conditions
|
||||
┌────────────────────────┬───────────────────────┐
|
||||
│ `[[ NUM1 -eq NUM2 ]]` │ Equal │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -ne NUM2 ]]` │ Not Equal │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -lt NUM2 ]]` │ Less than │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -le NUM2 ]]` │ Less than or equal │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -gt NUM2 ]]` │ Greater than │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `[[ NUM1 -ge NUM2 ]]` │ Greater than or equal │
|
||||
├────────────────────────┼───────────────────────┤
|
||||
│ `(( NUM < NUM ))` │ Numeric conditions │
|
||||
└────────────────────────┴───────────────────────┘
|
||||
|
||||
### File conditions
|
||||
┌───────────────────────┬─────────────────────────┐
|
||||
│ `[[ -e FILE ]]` │ Exists │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -r FILE ]]` │ Readable │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -h FILE ]]` │ Symlink │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -d FILE ]]` │ Directory │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -w FILE ]]` │ Writable │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -s FILE ]]` │ Size is > 0 bytes │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -f FILE ]]` │ File │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ -x FILE ]]` │ Executable │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ FILE1 -nt FILE2 ]]` │ 1 is more recent than 2 │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ FILE1 -ot FILE2 ]]` │ 2 is more recent than 1 │
|
||||
├───────────────────────┼─────────────────────────┤
|
||||
│ `[[ FILE1 -ef FILE2 ]]` │ Same files │
|
||||
└───────────────────────┴─────────────────────────┘
|
||||
|
||||
### Other conditions
|
||||
┌────────────────────┬────────────────────┐
|
||||
│ `[[ -o noclobber ]]` │ Option enabled │
|
||||
├────────────────────┼────────────────────┤
|
||||
│ `[[ ! EXPR ]]` │ Not │
|
||||
├────────────────────┼────────────────────┤
|
||||
│ `[[ X && Y ]]` │ And │
|
||||
├────────────────────┼────────────────────┤
|
||||
│ `[[ X || Y ]]` │ Or │
|
||||
└────────────────────┴────────────────────┘
|
||||
|
||||
## Parameter manipulation
|
||||
┌─────────────────────────────────┬────────────────────────────────────────────────────────────────┐
|
||||
│ `${foo}` │ Variable │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo/from/to}` │ Replace first match │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo/#from/to}`/`${foo/%from/to}` │ Replace first match anchored to start (default) or end │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo//from/to}` │ Replace all │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo[start,length]}` │ Slice from `start` to `length` (`length` can be negative) │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo%suffix}`/`${foo%%suffix}` │ Remove `suffix` (ungreedy/greedy) │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo#prefix}`/`${foo##prefix}` │ Remove `prefix` (ungreedy/greedy) │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${#foo}` │ Length of `foo` │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${(L)foo}` │ Lowercase all letters │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${(U)foo}` │ Uppercase all letters │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${(q)foo}` │ Quote safely │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${(qq)foo}` │ Quote more explicitely │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${(s.del.)foo}` │ Split on `del` │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${(j.del.)foo}` │ Join with `del` │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${file:h}` │ Directory of `file` │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${file:t}` │ Filename of `file` │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${file:e}` │ Extension of `file` │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${file:r}` │ Root of `file` (without extension) │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${file:a}` │ Absolute path of `file` │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${file:A}` │ Absolute path of `file` (resolves symlinks) │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:-val}` │ Use `val` if `foo` is unset or null │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:=val}` │ Set `foo` to `val` if unset or null │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:+val}` │ Use `val` if `foo` **is** set and not null │
|
||||
├─────────────────────────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `${foo:?message}` │ Print `message` and exit if `foo` is unset or null │
|
||||
└─────────────────────────────────┴────────────────────────────────────────────────────────────────┘
|
||||
> Omitting the `:` for default values will only check if the variable is set, not if it is null.
|
||||
|
||||
### Examples
|
||||
```zsh
|
||||
name="John"
|
||||
echo "${name}"
|
||||
echo "${name/J/j}" #=> "john" (substitution)
|
||||
echo "${name[0,2]}" #=> "Jo" (slicing)
|
||||
echo "${food:-Cake}" #=> $food or "Cake"
|
||||
|
||||
length=2
|
||||
echo "${name[1,length]}" #=> "Jo" (slicing with variable)
|
||||
|
||||
str="/path/to/foo.cpp"
|
||||
echo "${str%.cpp}" # /path/to/foo
|
||||
echo "${str%.cpp}.o" # /path/to/foo.o
|
||||
echo "${str%/*}" # /path/to
|
||||
|
||||
echo "${str##*.}" # cpp (extension)
|
||||
echo "${str##*/}" # foo.cpp (basepath)
|
||||
echo "${str#*o}" # o/foo.cpp (first occurrence of 'o')
|
||||
echo "${str##*o}" # oo.cpp (last occurrence of 'o')
|
||||
|
||||
echo "${str#*/}" # path/to/foo.cpp
|
||||
echo "${str##*/}" # foo.cpp
|
||||
|
||||
echo "${str/foo/bar}" # /path/to/bar.cpp
|
||||
|
||||
str="HELLO WORLD!"
|
||||
echo "${(L)str}" #=> "hello world!" (all lowercase)
|
||||
|
||||
str="hello world!"
|
||||
echo "${(U)str}" #=> "HELLO WORLD!" (all uppercase)
|
||||
```
|
||||
## Globs
|
||||
┌───────────────┬───────────────────────┐
|
||||
│ `ls **/*.js` │ Recursive expansion │
|
||||
├───────────────┼───────────────────────┤
|
||||
│ `ls *(.)` │ Plain files │
|
||||
├───────────────┼───────────────────────┤
|
||||
│ `ls *(/)` │ Directories │
|
||||
├───────────────┼───────────────────────┤
|
||||
│ `ls *(@)` │ Symlinks │
|
||||
├───────────────┼───────────────────────┤
|
||||
│ `ls *(*)` │ Executables │
|
||||
├───────────────┼───────────────────────┤
|
||||
│ `ls *(L+1M)` │ Files larger than 1MB │
|
||||
├───────────────┼───────────────────────┤
|
||||
│ `ls *(om[1,5])` │ 5 newest files │
|
||||
├───────────────┼───────────────────────┤
|
||||
│ `ls *(.)~*.bak` │ Files except *.bak │
|
||||
└───────────────┴───────────────────────┘
|
||||
|
||||
## Comments
|
||||
```zsh
|
||||
# This is a comment
|
||||
|
||||
: '
|
||||
This is a multi-line comment workaround
|
||||
'
|
||||
```
|
||||
|
||||
## Loops
|
||||
### Basic for loop
|
||||
```zsh
|
||||
for i in /etc/rc.*; do
|
||||
echo "$i"
|
||||
done
|
||||
```
|
||||
|
||||
### C-style for loop
|
||||
```zsh
|
||||
for (( i = 0; i < 10; i++ )); do
|
||||
echo "$i"
|
||||
done
|
||||
```
|
||||
|
||||
### Ranges
|
||||
```zsh
|
||||
for i in {1..10}; do
|
||||
echo "$i"
|
||||
done
|
||||
|
||||
# With step size
|
||||
for i in {1..10..2}; do
|
||||
echo "$i"
|
||||
done
|
||||
```
|
||||
|
||||
### Reading lines
|
||||
```zsh
|
||||
while IFS= read -r line; do
|
||||
print -r -- "$line"
|
||||
done < file.txt
|
||||
```
|
||||
|
||||
### Infinite loop
|
||||
```zsh
|
||||
while true; do
|
||||
echo "Press [CTRL+C] to stop.."
|
||||
sleep 1
|
||||
done
|
||||
```
|
||||
|
||||
## History
|
||||
┌───────────────┬────────────────────────────────────────────────────────────────┐
|
||||
│ `!!` │ Expand latest command in history │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!$` │ Expand last parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!*` │ Expand all parameters of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!-n` │ Expand nth latest command in history │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!n` │ Expand nth command in history │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!string` │ Expand latest command starting with string │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:s/from/to` │ Replace first occurrence of "from" with "to" in latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:gs/from/to` │ Replace all occurrences of "from" with "to" in latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:p` │ Print latest command without executing it │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!$:t` │ Expand basename of last parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!$:h` │ Expand directory of last parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:n` │ Expand only nth parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!^` │ Expand first parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!$` │ Expand last parameter of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:n-m` │ Expand parameters from nth to mth of latest command │
|
||||
├───────────────┼────────────────────────────────────────────────────────────────┤
|
||||
│ `!!:n-$` │ Expand parameters from nth to last of latest command │
|
||||
└───────────────┴────────────────────────────────────────────────────────────────┘
|
||||
|
||||
## Redirection
|
||||
┌────────────────────────┬─────────────────────────────────┐
|
||||
│ `SCRIPT > FILE` │ stdout to FILE │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT >> FILE` │ Append stdout to FILE │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT 2> FILE` │ stderr to FILE │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT 2>&1` │ stderr to stdout │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT &> FILE` │ stderr and stdout to FILE │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT 2> /dev/null` │ stderr to /dev/null │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT > FILE 2>&1` │ stdout and stderr to FILE │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT &> /dev/null` │ stdout and stderr to /dev/null │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `echo "$0: warning" >&2` │ Print to stderr │
|
||||
├────────────────────────┼─────────────────────────────────┤
|
||||
│ `SCRIPT < FILE` │ stdin from FILE │
|
||||
└────────────────────────┴─────────────────────────────────┘
|
||||
|
||||
## Switch statement
|
||||
```zsh
|
||||
case "$1" in
|
||||
start | up)
|
||||
vagrant up
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|ssh}"
|
||||
;;
|
||||
esac
|
||||
```
|
||||
|
||||
### Options switch statement
|
||||
```zsh
|
||||
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
|
||||
-V | --version )
|
||||
echo "$version"
|
||||
exit
|
||||
;;
|
||||
-s | --string )
|
||||
shift; string=$1
|
||||
;;
|
||||
-f | --flag )
|
||||
flag=1
|
||||
;;
|
||||
esac; shift; done
|
||||
if [[ "$1" == '--' ]]; then shift; fi
|
||||
```
|
||||
|
||||
## Functions
|
||||
```zsh
|
||||
my_function() {
|
||||
echo "Hello, World!"
|
||||
}
|
||||
```
|
||||
|
||||
### Arguments
|
||||
┌────┬───────────────────────────────────┐
|
||||
│ `$#` │ Number of arguments │
|
||||
├────┼───────────────────────────────────┤
|
||||
│ `$*` │ All arguments │
|
||||
├────┼───────────────────────────────────┤
|
||||
│ `$@` │ All arguments as separate strings │
|
||||
├────┼───────────────────────────────────┤
|
||||
│ `$1` │ First argument │
|
||||
├────┼───────────────────────────────────┤
|
||||
│ `$_` │ Last argument │
|
||||
└────┴───────────────────────────────────┘
|
||||
|
||||
## Arrays
|
||||
```zsh
|
||||
# Create an array in one line
|
||||
Fruits=('Apple' 'Banana' 'Orange')
|
||||
|
||||
# Or assign each value
|
||||
Fruits[1]="Apple"
|
||||
Fruits[2]="Banana"
|
||||
Fruits[3]="Orange"
|
||||
|
||||
# Associative array
|
||||
typeset -A sounds
|
||||
|
||||
sounds[dog]="bark"
|
||||
sounds[cow]="moo"
|
||||
sounds[bird]="tweet"
|
||||
sounds[wolf]="howl"
|
||||
```
|
||||
|
||||
### Array element expansion
|
||||
┌──────────────────────────────────────┬────────────────────────────────────┐
|
||||
│ `${array[key]}` │ Element at `key` │
|
||||
├──────────────────────────────────────┼────────────────────────────────────┤
|
||||
│ `${array[-1]}` │ Last element (not for associative) │
|
||||
├──────────────────────────────────────┼────────────────────────────────────┤
|
||||
│ `${array[@]}` │ All elements │
|
||||
├──────────────────────────────────────┼────────────────────────────────────┤
|
||||
│ `${#array}` │ Number of elements │
|
||||
├──────────────────────────────────────┼────────────────────────────────────┤
|
||||
│ `${#array[key]}` │ String length of element at `key` │
|
||||
├──────────────────────────────────────┼────────────────────────────────────┤
|
||||
│ `${array:n:length}`/`${array[n,length]}` │ `length` eements from position `n` │
|
||||
├──────────────────────────────────────┼────────────────────────────────────┤
|
||||
│ `${(k)array}` │ Keys of all elements │
|
||||
└──────────────────────────────────────┴────────────────────────────────────┘
|
||||
|
||||
### Operations
|
||||
```zsh
|
||||
Fruits=("${Fruits[@]}" "Watermelon") # Push
|
||||
Fruits+=('Watermelon') # Also Push
|
||||
Fruits=( "${Fruits[@]/Ap*/}" ) # Remove by regex match
|
||||
unset Fruits[3] # Remove one item
|
||||
Fruits=("${Fruits[@]}") # Duplicate
|
||||
Fruits=("${Fruits[@]}" "${Veggies[@]}") # Concatenate
|
||||
words=($(< datafile)) # From file (split by IFS)
|
||||
```
|
||||
|
||||
### Looping
|
||||
```zsh
|
||||
for i in "${Fruits[@]}"; do
|
||||
echo "$i"
|
||||
done
|
||||
|
||||
for val in "${(v)sounds}"; do
|
||||
echo "$val"
|
||||
done
|
||||
|
||||
for key in "${(k)sounds}"; do
|
||||
echo "$key"
|
||||
done
|
||||
```
|
||||
|
||||
## Misc
|
||||
|
||||
### Directory of script
|
||||
```zsh
|
||||
DIR="$( cd "$( dirname "${ZSH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
```
|
||||
|
||||
### Special variables
|
||||
┌──────────────────┬───────────────────────────────────────────────┐
|
||||
│ `$?` │ Exit status of last task │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$!` │ PID of last background task │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$$` │ PID of shell │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$#` │ Number of arguments passed to script │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$0` │ Filename of the shell script │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$_` │ Last arugment of altest command │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$argv` │ Array of all arguments passed to script │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$ARGC` │ Number of arguments passed to script │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `${pipestatus[n]}` │ Return value of piped commands (array) │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$RANDOM` │ Random number between 0 and 32767 │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$SECONDS` │ Number of seconds since the shell was started │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$PWD` │ Current working directory │
|
||||
├──────────────────┼───────────────────────────────────────────────┤
|
||||
│ `$OLDPWD` │ Previous working directory │
|
||||
└──────────────────┴───────────────────────────────────────────────┘
|
||||
+91
-26
@@ -18,12 +18,14 @@ vim.api.nvim_create_autocmd('FocusLost', {
|
||||
group = autosave_group,
|
||||
pattern = '*',
|
||||
command = 'silent! wa', -- Save all files when moving away from the window
|
||||
nested = true, -- Allow other autocommands to run after this one
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('InsertLeave', {
|
||||
vim.api.nvim_create_autocmd('BufLeave', {
|
||||
group = autosave_group,
|
||||
pattern = '*',
|
||||
command = 'silent! wa', -- Save all files when leaving insert mode
|
||||
command = 'silent! wa', -- Save all files when switching buffers
|
||||
nested = true, -- Allow other autocommands to run after this one
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('SwapExists', {
|
||||
@@ -116,32 +118,95 @@ vim.api.nvim_create_autocmd('BufWritePost', {
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = {
|
||||
'bash',
|
||||
'c',
|
||||
'diff',
|
||||
'html',
|
||||
'lua',
|
||||
'luadoc',
|
||||
'markdown',
|
||||
'markdown_inline',
|
||||
'query',
|
||||
'vim',
|
||||
'vimdoc',
|
||||
'php',
|
||||
'javascript',
|
||||
'typescript',
|
||||
'json',
|
||||
local configs = {
|
||||
{
|
||||
path = os.getenv 'HOME' .. '/.config/nixos',
|
||||
worktree = nil,
|
||||
git_dir = nil,
|
||||
track_untracked = false,
|
||||
force_add = false,
|
||||
},
|
||||
{
|
||||
path = os.getenv 'HOME' .. '/.config/nvim',
|
||||
worktree = nil,
|
||||
git_dir = nil,
|
||||
track_untracked = false,
|
||||
force_add = false,
|
||||
},
|
||||
{
|
||||
path = os.getenv 'HOME',
|
||||
worktree = os.getenv 'HOME',
|
||||
git_dir = os.getenv 'HOME' .. '/.config/dotfiles/.git',
|
||||
track_untracked = true,
|
||||
force_add = true, -- Handles ignored files in dotfiles
|
||||
include_dirs = { '.config', '.local/bin', '.local/share' },
|
||||
},
|
||||
}
|
||||
|
||||
local function get_git_status(config)
|
||||
local base = 'git'
|
||||
if config.git_dir and config.worktree then
|
||||
base = string.format('git --git-dir=%s --worktree=%s', config.git_dir, config.worktree)
|
||||
end
|
||||
|
||||
-- Check modified and untracked (including ignored if force_add is true)
|
||||
local cmd = base .. ' status --porcelain'
|
||||
if config.force_add then
|
||||
cmd = cmd .. ' --ignored'
|
||||
end
|
||||
|
||||
local handle = io.popen(cmd)
|
||||
local result = handle:read '*a'
|
||||
handle:close()
|
||||
|
||||
local has_changes = false
|
||||
for line in result:gmatch '[^\r\n]+' do
|
||||
local status = line:sub(1, 2)
|
||||
local file = line:sub(4)
|
||||
|
||||
if status:match '[MAR]' then
|
||||
has_changes = true
|
||||
elseif (status == '??' or status == '!!') and config.track_untracked then
|
||||
if config.include_dirs then
|
||||
for _, dir in ipairs(config.include_dirs) do
|
||||
if file:sub(1, #dir) == dir then
|
||||
has_changes = true
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
has_changes = true
|
||||
end
|
||||
end
|
||||
end
|
||||
return has_changes, base
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd('VimLeavePre', {
|
||||
callback = function()
|
||||
-- syntax highlighting, provided by Neovim
|
||||
vim.treesitter.start()
|
||||
-- folds, provided by Neovim
|
||||
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
||||
vim.wo.foldmethod = 'expr'
|
||||
-- indentation, provided by nvim-treesitter
|
||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
local cwd = vim.fn.getcwd()
|
||||
|
||||
for _, config in ipairs(configs) do
|
||||
if cwd:sub(1, #config.path) == config.path then
|
||||
local has_changes, git_base = get_git_status(config)
|
||||
|
||||
if has_changes then
|
||||
local confirm = vim.fn.confirm('Uncommitted changes in managed path. Commit?', '&Yes\n&No', 2)
|
||||
if confirm == 1 then
|
||||
local msg = vim.fn.input('Commit message: ', 'chore: update files')
|
||||
if msg ~= '' then
|
||||
msg = 'Update files'
|
||||
end
|
||||
local add_cmd = ' add -A'
|
||||
os.execute(git_base .. add_cmd)
|
||||
os.execute(git_base .. ' commit -m ' .. vim.fn.shellescape(msg))
|
||||
os.execute(git_base .. ' push')
|
||||
print '\nChanges committed.'
|
||||
end
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
+51
-1
@@ -51,7 +51,57 @@ helpers.open_term = function(opts)
|
||||
end
|
||||
|
||||
helpers.has_copilot = function()
|
||||
return vim.fn.getenv('COPILOT_API_KEY') ~= vim.NIL
|
||||
return vim.fn.getenv 'COPILOT_API_KEY' ~= vim.NIL
|
||||
end
|
||||
|
||||
helpers.open_file_modal = function(path, title)
|
||||
local width = math.floor(vim.o.columns * 0.85)
|
||||
local height = math.floor(vim.o.lines * 0.85)
|
||||
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
|
||||
vim.api.nvim_open_win(buf, true, {
|
||||
relative = 'editor',
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
style = 'minimal',
|
||||
border = 'rounded',
|
||||
title = ' ' .. title .. ' ',
|
||||
title_pos = 'center',
|
||||
})
|
||||
|
||||
vim.api.nvim_buf_set_name(buf, path)
|
||||
|
||||
local lines = vim.fn.readfile(path)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||
|
||||
vim.bo[buf].filetype = 'markdown'
|
||||
vim.bo[buf].buftype = 'nofile'
|
||||
vim.bo[buf].bufhidden = 'wipe'
|
||||
vim.bo[buf].swapfile = false
|
||||
vim.bo[buf].modifiable = false
|
||||
vim.bo[buf].readonly = true
|
||||
|
||||
vim.wo.wrap = false
|
||||
vim.wo.number = false
|
||||
vim.wo.relativenumber = false
|
||||
vim.wo.cursorline = true
|
||||
|
||||
vim.keymap.set('n', 'q', '<cmd>close<CR>', {
|
||||
buffer = buf,
|
||||
silent = true,
|
||||
desc = 'Close cheatsheet',
|
||||
})
|
||||
vim.keymap.set('n', '<Esc>', '<cmd>close<CR>', {
|
||||
buffer = buf,
|
||||
silent = true,
|
||||
desc = 'Close cheatsheet',
|
||||
})
|
||||
end
|
||||
|
||||
return helpers
|
||||
|
||||
+117
-96
@@ -26,17 +26,17 @@ vim.keymap.set('v', 'p', '"zdP', { desc = 'Paste over selection without yanking
|
||||
-- or just use <C-\><C-n> to exit terminal mode
|
||||
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
|
||||
|
||||
vim.keymap.set('n', '<Leader>c', function()
|
||||
vim.keymap.set('n', '<Leader>z', function()
|
||||
vim.treesitter.inspect_tree()
|
||||
end, { desc = 'Treesitter' })
|
||||
|
||||
-- vim.keymap.set('n', '<C-S-D>', function()
|
||||
-- local node = vim.treesitter.get_node {}
|
||||
-- local range = { vim.treesitter.get_node_range(node) }
|
||||
-- vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
|
||||
-- vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
|
||||
-- vim.cmd.normal 'v`x'
|
||||
-- end, { desc = 'Select surrounding treesitter node' })
|
||||
vim.keymap.set('n', '<C-S-D>', function()
|
||||
local node = vim.treesitter.get_node {}
|
||||
local range = { vim.treesitter.get_node_range(node) }
|
||||
vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
|
||||
vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
|
||||
vim.cmd.normal 'v`x'
|
||||
end, { desc = 'Select surrounding treesitter node' })
|
||||
|
||||
vim.keymap.set('v', '<C-S-D>', function()
|
||||
local start = vim.api.nvim_win_get_cursor(0)
|
||||
@@ -257,101 +257,112 @@ vim.keymap.set('n', '<Leader>sGS', '<CMD>Telescope git_stash<CR>', { desc = 'Sea
|
||||
vim.keymap.set('n', '<Leader>]', '<CMD>cnext<CR>', { desc = 'Next item in quickfix list' })
|
||||
vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item in quickfix list' })
|
||||
vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' })
|
||||
vim.keymap.set('n', '<Leader>r', '<CMD>e!<CR>', { desc = 'Reload buffer' })
|
||||
|
||||
local function open_test()
|
||||
require('neotest').summary.open()
|
||||
require('neotest').output_panel.open()
|
||||
end
|
||||
-- Testing
|
||||
-- local test_maps = {
|
||||
-- {
|
||||
-- keys = { '<F12>', '<Leader>tn' },
|
||||
-- action = function()
|
||||
-- require('neotest').run.run()
|
||||
-- open_test()
|
||||
-- end,
|
||||
-- desc = 'Run nearest test',
|
||||
-- },
|
||||
-- {
|
||||
-- keys = { '<F9>', '<Leader>ta' },
|
||||
-- action = function()
|
||||
-- require('neotest').run.run { suite = true }
|
||||
-- open_test()
|
||||
-- end,
|
||||
-- desc = 'Run all tests in the project',
|
||||
-- },
|
||||
-- {
|
||||
-- keys = { '<F11>', '<Leader>tp' },
|
||||
-- action = function()
|
||||
-- require('neotest').run.run_last()
|
||||
-- open_test()
|
||||
-- end,
|
||||
-- desc = 'Run previous test again',
|
||||
-- },
|
||||
-- {
|
||||
-- keys = { '<F10>', '<Leader>td' },
|
||||
-- action = function()
|
||||
-- local dap = require 'dap'
|
||||
-- if dap.session() == nil then
|
||||
-- dap.continue()
|
||||
-- end
|
||||
-- require('dapui').open()
|
||||
-- local neotest = require 'neotest'
|
||||
-- local bufnr = vim.api.nvim_get_current_buf()
|
||||
-- local row = vim.api.nvim_win_get_cursor(0)[1] - 1
|
||||
--
|
||||
-- local adapters = neotest.state.adapter_ids()
|
||||
-- local found = false
|
||||
--
|
||||
-- for _, adapter_id in ipairs(adapters) do
|
||||
-- local tree = neotest.state.positions(adapter_id, { buffer = bufnr })
|
||||
-- if tree then
|
||||
-- local nearest = require('neotest.lib.positions').nearest(tree, row)
|
||||
-- if nearest and nearest:data().type ~= 'file' then
|
||||
-- neotest.run.run()
|
||||
-- found = true
|
||||
-- break
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- if not found then
|
||||
-- neotest.run.run_last()
|
||||
-- end
|
||||
-- end,
|
||||
-- desc = 'Run last test with debugger',
|
||||
-- },
|
||||
-- }
|
||||
--
|
||||
-- for _, map_info in ipairs(test_maps) do
|
||||
-- for _, key in ipairs(map_info.keys) do
|
||||
-- vim.keymap.set('n', key, map_info.action, { desc = map_info.desc })
|
||||
-- end
|
||||
-- end
|
||||
-- vim.keymap.set('n', '<Leader>tf', function()
|
||||
-- require('neotest').run.run(vim.fn.expand '%')
|
||||
-- open_test()
|
||||
-- end, { desc = 'Run all tests in the current file' })
|
||||
-- vim.keymap.set('n', '<Leader>tc', function()
|
||||
-- require('neotest').summary.close()
|
||||
-- require('neotest').output_panel.close()
|
||||
-- end, { desc = 'Close test panels' })
|
||||
local test_maps = {
|
||||
{
|
||||
keys = { '<Leader>tc' },
|
||||
action = function()
|
||||
require('neotest').summary.close()
|
||||
require('neotest').output_panel.close()
|
||||
end,
|
||||
desc = 'Close [T]est panels',
|
||||
},
|
||||
{
|
||||
keys = { '<Leader>tn' },
|
||||
action = function()
|
||||
require('neotest').run.run()
|
||||
open_test()
|
||||
end,
|
||||
desc = 'Run nearest [T]est',
|
||||
},
|
||||
{
|
||||
keys = { '<Leader>ta' },
|
||||
action = function()
|
||||
require('neotest').run.run { suite = true }
|
||||
open_test()
|
||||
end,
|
||||
desc = 'Run all [T]ests in the project',
|
||||
},
|
||||
{
|
||||
keys = { '<Leader>tp' },
|
||||
action = function()
|
||||
require('neotest').run.run_last()
|
||||
open_test()
|
||||
end,
|
||||
desc = 'Run previous [T]est again',
|
||||
},
|
||||
{
|
||||
keys = { '<Leader>td' },
|
||||
action = function()
|
||||
local dap = require 'dap'
|
||||
if dap.session() == nil then
|
||||
dap.continue()
|
||||
end
|
||||
require('dapui').open()
|
||||
local neotest = require 'neotest'
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1] - 1
|
||||
|
||||
-- vim.keymap.set('i', '<Tab>', function()
|
||||
-- local copilot = require 'copilot.suggestion'
|
||||
-- local ls = require 'luasnip'
|
||||
-- if copilot.is_visible() then
|
||||
-- vim.api.nvim_echo({{'Accepting copilot suggestion'}}, false, {})
|
||||
-- copilot.accept()
|
||||
-- copilot.dismiss()
|
||||
-- elseif ls.jumpable(1) then
|
||||
-- vim.api.nvim_echo({{'Jumping in snippet'}}, false, {})
|
||||
-- ls.jump()
|
||||
-- else
|
||||
-- vim.api.nvim_echo({{'Inserting tab'}}, false, {})
|
||||
-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Tab>', true, true, true), 'n', true)
|
||||
-- end
|
||||
-- end, { desc = 'Luasnip accept copilot or jump forward' })
|
||||
local adapters = neotest.state.adapter_ids()
|
||||
local found = false
|
||||
|
||||
vim.g.neotest_debug = true
|
||||
for _, adapter_id in ipairs(adapters) do
|
||||
local tree = neotest.state.positions(adapter_id, { buffer = bufnr })
|
||||
if tree then
|
||||
local nearest = require('neotest.lib.positions').nearest(tree, row)
|
||||
if nearest and nearest:data().type ~= 'file' then
|
||||
neotest.run.run()
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not found then
|
||||
neotest.run.run_last()
|
||||
end
|
||||
vim.g.neotest_debug = nil
|
||||
end,
|
||||
desc = 'Run last [T]est with debugger',
|
||||
},
|
||||
}
|
||||
|
||||
for _, map_info in ipairs(test_maps) do
|
||||
for _, key in ipairs(map_info.keys) do
|
||||
vim.keymap.set('n', key, map_info.action, { desc = map_info.desc })
|
||||
end
|
||||
end
|
||||
vim.keymap.set('n', '<Leader>tf', function()
|
||||
require('neotest').run.run(vim.fn.expand '%')
|
||||
open_test()
|
||||
end, { desc = 'Run all tests in the current file' })
|
||||
vim.keymap.set('n', '<Leader>tc', function()
|
||||
require('neotest').summary.close()
|
||||
require('neotest').output_panel.close()
|
||||
end, { desc = 'Close test panels' })
|
||||
|
||||
vim.keymap.set('i', '<Tab>', function()
|
||||
local copilot = require 'copilot.suggestion'
|
||||
local ls = require 'luasnip'
|
||||
if copilot.is_visible() then
|
||||
vim.api.nvim_echo({ { 'Accepting copilot suggestion' } }, false, {})
|
||||
copilot.accept()
|
||||
copilot.dismiss()
|
||||
elseif ls.jumpable(1) then
|
||||
vim.api.nvim_echo({ { 'Jumping in snippet' } }, false, {})
|
||||
ls.jump()
|
||||
else
|
||||
vim.api.nvim_echo({ { 'Inserting tab' } }, false, {})
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Tab>', true, true, true), 'n', true)
|
||||
end
|
||||
end, { desc = 'Luasnip accept copilot or jump forward' })
|
||||
|
||||
-- Leaving this commented out, I will try the format command instead
|
||||
-- "A command to properly indent json code
|
||||
@@ -369,4 +380,14 @@ vim.keymap.set('n', '<Leader>es', function()
|
||||
vim.cmd('tabedit ' .. snippets_file)
|
||||
end, { desc = 'Edit snippets file' })
|
||||
|
||||
vim.keymap.set('n', '<Leader>cz', function()
|
||||
require('utils/cheatsheets').open 'zsh'
|
||||
end, { desc = 'Open zsh cheat sheet' })
|
||||
vim.keymap.set('n', '<Leader>cb', function()
|
||||
require('utils/cheatsheets').open 'bash'
|
||||
end, { desc = 'Open bash cheat sheet' })
|
||||
vim.keymap.set('n', '<Leader>cr', function()
|
||||
require('utils/cheatsheets').open 'regex'
|
||||
end, { desc = 'Open RegExp cheat sheet' })
|
||||
|
||||
require('helpers').edit_cf('k', '/lua/keymap.lua')
|
||||
|
||||
@@ -75,6 +75,7 @@ vim.opt.softtabstop = 4
|
||||
vim.opt.expandtab = true
|
||||
-- Automatically indent code
|
||||
vim.opt.smartindent = true
|
||||
vim.opt.autoindent = true
|
||||
|
||||
-- Save the file when switching buffers
|
||||
vim.opt.autowriteall = true
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
return {
|
||||
'ricardoramirezr/blade-nav.nvim',
|
||||
dependencies = { -- totally optional
|
||||
'saghen/blink.cmp', -- if using blink.cmp
|
||||
},
|
||||
ft = { 'blade', 'php' }, -- optional, improves startup time
|
||||
}
|
||||
@@ -56,6 +56,12 @@ return {
|
||||
providers = {
|
||||
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
|
||||
-- avante = { module = 'blink-cmp-avante', name = 'Avante', opts = {} },
|
||||
-- ['blade-nav'] = {
|
||||
-- module = 'blade-nav.blink',
|
||||
-- opts = {
|
||||
-- clost_tag_on_complete = false,
|
||||
-- },
|
||||
-- },
|
||||
},
|
||||
per_filetype = {
|
||||
codecompanion = { 'codecompanion' },
|
||||
|
||||
+13
-8
@@ -4,19 +4,24 @@ return {
|
||||
-- change the command in the config to whatever the name of that colorscheme is.
|
||||
--
|
||||
-- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
|
||||
'AlphaTechnolog/pywal.nvim',
|
||||
dependencies = {
|
||||
'folke/tokyonight.nvim',
|
||||
},
|
||||
priority = 1000, -- Make sure to load this before all the other start plugins.
|
||||
config = function()
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
require('tokyonight').setup {
|
||||
styles = {
|
||||
comments = { italic = false }, -- Disable italics in comments
|
||||
},
|
||||
}
|
||||
require('tokyonight').setup()
|
||||
|
||||
-- Load the colorscheme here.
|
||||
-- Like many other themes, this one has different styles, and you could load
|
||||
-- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'.
|
||||
vim.cmd.colorscheme 'tokyonight-night'
|
||||
|
||||
-- Check if wal directory exists otherwise use tokyo
|
||||
local handle = io.popen 'ls -d $HOME/.cache/wal 2>/dev/null'
|
||||
local result = handle:read '*a'
|
||||
handle:close()
|
||||
|
||||
if result ~= '' then
|
||||
require('pywal').setup()
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ return { -- Autoformat
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
php = { 'pint' },
|
||||
blade = { 'blade-formatter' },
|
||||
-- Conform can also run multiple formatters sequentially
|
||||
-- python = { "isort", "black" },
|
||||
--
|
||||
|
||||
@@ -180,40 +180,6 @@ return {
|
||||
vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl })
|
||||
end
|
||||
|
||||
local function get_php_ini_dir()
|
||||
local handle = io.popen 'php --ini 2>/dev/null'
|
||||
if not handle then
|
||||
return nil
|
||||
end
|
||||
local result = handle:read '*a'
|
||||
handle:close()
|
||||
local dir = result:match 'Scan for additional .ini files in:%s+([^\n]+)'
|
||||
if dir and dir:find '%(none%)' == nil then
|
||||
return vim.trim(dir)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function enable_xdebug()
|
||||
local ini_dir = get_php_ini_dir()
|
||||
if not ini_dir then
|
||||
return
|
||||
end
|
||||
os.execute(string.format('mv "%s/20-xdebug.ini.disabled" "%s/20-xdebug.ini" 2>/dev/null', ini_dir, ini_dir))
|
||||
end
|
||||
|
||||
local function disable_xdebug()
|
||||
local ini_dir = get_php_ini_dir()
|
||||
if not ini_dir then
|
||||
return
|
||||
end
|
||||
os.execute(string.format('mv "%s/20-xdebug.ini" "%s/20-xdebug.ini.disabled" 2>/dev/null', ini_dir, ini_dir))
|
||||
end
|
||||
|
||||
dap.listeners.after.event_initialized['xdebug_enable'] = enable_xdebug
|
||||
dap.listeners.before.event_terminated['xdebug_disable'] = disable_xdebug
|
||||
dap.listeners.before.event_exited['xdebug_disable'] = disable_xdebug
|
||||
|
||||
-- dap.listeners.after.event_output['neotest_display'] = function(_, body)
|
||||
-- require('neotest').output.open { enter = true, last = true }
|
||||
-- end
|
||||
|
||||
+16
-4
@@ -13,9 +13,10 @@ return {
|
||||
'saghen/blink.cmp',
|
||||
'folke/lazydev.nvim',
|
||||
},
|
||||
build = function()
|
||||
vim.fn.system 'composer global require jetbrains/phpstorm-stubs friendsofphp/php-cs-fixer'
|
||||
end,
|
||||
-- Might not be necessary for phpantom
|
||||
-- build = function()
|
||||
-- vim.fn.system 'composer global require jetbrains/phpstorm-stubs friendsofphp/php-cs-fixer'
|
||||
-- end,
|
||||
config = function()
|
||||
-- This function gets run when an LSP attaches to a particular buffer.
|
||||
-- That is to say, every time a new file is opened that is associated with
|
||||
@@ -115,6 +116,12 @@ return {
|
||||
},
|
||||
}
|
||||
|
||||
-- vim.lsp.config['phpantom'] = {
|
||||
-- filetypes = { 'php' },
|
||||
-- cmd = { 'phpantom_lsp' },
|
||||
-- root_markers = { 'composer.json', '.git' },
|
||||
-- }
|
||||
|
||||
-- Enable the following language servers
|
||||
--
|
||||
-- Add any additional override configuration in the following tables. Available keys are:
|
||||
@@ -139,7 +146,11 @@ return {
|
||||
},
|
||||
},
|
||||
},
|
||||
phpactor = {},
|
||||
phpantom_lsp = {
|
||||
filetypes = { 'php' },
|
||||
cmd = { 'phpantom_lsp' },
|
||||
root_markers = { 'composer.json', '.git' },
|
||||
},
|
||||
vtsls = {
|
||||
settings = {
|
||||
vtsls = {
|
||||
@@ -195,6 +206,7 @@ return {
|
||||
local ensure_installed = vim.tbl_keys(servers or {})
|
||||
vim.list_extend(ensure_installed, {
|
||||
'stylua', -- Used to format Lua code
|
||||
'blade-formatter',
|
||||
})
|
||||
|
||||
-- LSP servers and clients are able to communicate to each other what features they support.
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
-- Filesystem manager
|
||||
-- require('helpers').edit_cf('po', '/lua/plugins/oil.lua')
|
||||
--
|
||||
-- vim.keymap.set('n', '-', '<CMD>Oil<CR>', { desc = 'Open parent directory' })
|
||||
vim.keymap.set('n', '-', '<CMD>Oil<CR>', { desc = 'Open parent directory' })
|
||||
|
||||
return {
|
||||
'stevearc/oil.nvim',
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
return {
|
||||
'AlphaTechnolog/pywal.nvim',
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
return {
|
||||
"ThePrimeagen/refactoring.nvim",
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
},
|
||||
lazy = false,
|
||||
opts = {},
|
||||
-- "ThePrimeagen/refactoring.nvim",
|
||||
-- dependencies = {
|
||||
-- "nvim-lua/plenary.nvim",
|
||||
-- "nvim-treesitter/nvim-treesitter",
|
||||
-- },
|
||||
-- lazy = false,
|
||||
-- opts = {},
|
||||
}
|
||||
|
||||
@@ -5,6 +5,16 @@ return {
|
||||
-- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, -- if you prefer nvim-web-devicons
|
||||
---@module 'render-markdown'
|
||||
---@type render.md.UserConfig
|
||||
opts = {},
|
||||
ft = { 'markdown', 'codecompanion' },
|
||||
config = function()
|
||||
require('render-markdown').setup {
|
||||
latex = {
|
||||
enabled = true,
|
||||
render_modes = true,
|
||||
},
|
||||
anti_conceal = {
|
||||
enabled = false,
|
||||
},
|
||||
}
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
require('helpers').edit_cf('pt', '/lua/plugins/test.lua')
|
||||
|
||||
return {
|
||||
'nvim-neotest/neotest',
|
||||
dependencies = {
|
||||
'V13Axel/neotest-pest',
|
||||
},
|
||||
config = function()
|
||||
require('neotest').setup {
|
||||
adapters = {
|
||||
require 'neotest-pest' {
|
||||
sail_enabled = function()
|
||||
return false
|
||||
end,
|
||||
parallel = 8,
|
||||
pest_cmd = function()
|
||||
local cmd = vim.g.neotest_pest_cmd or { 'vendor/bin/pest' }
|
||||
if vim.g.neotest_debug then
|
||||
cmd = { 'sh', '-c', 'XDEBUG_MODE=debug exec ' .. table.concat(cmd, ' ') .. ' "$@"' }
|
||||
end
|
||||
return cmd
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
end,
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
-- Highlight, edit, and navigate code
|
||||
return {
|
||||
-- 'nvim-treesitter/nvim-treesitter-textobjects',
|
||||
-- lazy = true,
|
||||
-- branch = 'main',
|
||||
-- dependencies = {
|
||||
-- 'nvim-treesitter/nvim-treesitter',
|
||||
-- },
|
||||
-- config = function()
|
||||
-- -- configuration
|
||||
-- require('nvim-treesitter-textobjects').setup {
|
||||
-- select = {
|
||||
-- lookahead = true,
|
||||
-- selection_modes = {
|
||||
-- ['@parameter.outer'] = 'v', -- charwise
|
||||
-- ['@function.outer'] = 'V', -- linewise
|
||||
-- ['@class.outer'] = 'V', -- blockwise
|
||||
-- },
|
||||
-- include_surrounding_whitespace = false,
|
||||
-- },
|
||||
-- move = {
|
||||
-- set_jumps = true,
|
||||
-- },
|
||||
-- }
|
||||
|
||||
-- for keys, query in
|
||||
-- {
|
||||
-- -- or you use the queries from supported languages with textobjects.scm
|
||||
-- ['af'] = '@function.outer',
|
||||
-- ['if'] = '@function.inner',
|
||||
-- ['aC'] = '@class.outer',
|
||||
-- ['iC'] = '@class.inner',
|
||||
-- ['ay'] = '@conditional.outer',
|
||||
-- ['iy'] = '@conditional.inner',
|
||||
-- ['aj'] = '@loop.outer',
|
||||
-- ['ij'] = '@loop.inner',
|
||||
-- ['is'] = '@statement.inner',
|
||||
-- ['as'] = '@statement.outer',
|
||||
-- ['ac'] = '@comment.outer',
|
||||
-- ['ic'] = '@comment.inner',
|
||||
-- ['ap'] = '@comment.parameter',
|
||||
-- ['ip'] = '@comment.parameter',
|
||||
-- ['an'] = '@local.scope',
|
||||
-- }
|
||||
-- do
|
||||
-- vim.keymap.set({ 'n', 'x', 'o' }, keys, function()
|
||||
-- require('nvim-treesitter-textobjects.select').select_textobject(query, 'textobjects')
|
||||
-- end)
|
||||
-- end
|
||||
|
||||
-- for keys, query in
|
||||
-- {
|
||||
-- -- or you use the queries from supported languages with textobjects.scm
|
||||
-- [']'] = '@function.outer',
|
||||
-- ['o'] = { '@loop.inner', '@loop.outer' },
|
||||
-- ['n'] = '@local.scope',
|
||||
-- ['y'] = '@conditional.outer',
|
||||
-- ['e'] = '@statement.outer',
|
||||
-- ['/'] = '@comment.outer',
|
||||
-- }
|
||||
-- do
|
||||
-- vim.keymap.set({ 'n', 'x', 'o' }, ']' .. keys, function()
|
||||
-- require('nvim-treesitter-textobjects.move').goto_next_start(query, 'textobjects')
|
||||
-- end)
|
||||
-- vim.keymap.set({ 'n', 'x', 'o' }, '[' .. keys, function()
|
||||
-- require('nvim-treesitter-textobjects.move').goto_previous_start(query, 'textobjects')
|
||||
-- end)
|
||||
-- end
|
||||
-- -- require('nvim-treesitter.configs').setup {
|
||||
-- -- incremental_selection = {
|
||||
-- -- enable = true,
|
||||
-- -- keymaps = {
|
||||
-- -- -- mappings for incremental selection (visual mappings)
|
||||
-- -- init_selection = '<C-S-D>', -- maps in normal mode to init the node/scope selection
|
||||
-- -- node_incremental = '<C-S-D>', -- increment to the upper named parent
|
||||
-- -- scope_incremental = '<C-S-U>', -- increment to the upper scope (as defined in locals.scm)
|
||||
-- -- node_decremental = '<C-S-S>', -- decrement to the previous node
|
||||
-- -- },
|
||||
-- -- },
|
||||
|
||||
-- -- textobjects = {
|
||||
-- -- -- syntax-aware textobjects
|
||||
-- -- enable = true,
|
||||
-- -- keymaps = {
|
||||
-- -- ['iL'] = {
|
||||
-- -- -- you can define your own textobjects directly here
|
||||
-- -- go = '(function_definition) @function',
|
||||
-- -- },
|
||||
-- -- -- or you use the queries from supported languages with textobjects.scm
|
||||
-- -- ['af'] = '@function.outer',
|
||||
-- -- ['if'] = '@function.inner',
|
||||
-- -- ['aC'] = '@class.outer',
|
||||
-- -- ['iC'] = '@class.inner',
|
||||
-- -- ['ay'] = '@conditional.outer',
|
||||
-- -- ['iy'] = '@conditional.inner',
|
||||
-- -- ['aj'] = '@loop.outer',
|
||||
-- -- ['ij'] = '@loop.inner',
|
||||
-- -- ['is'] = '@statement.inner',
|
||||
-- -- ['as'] = '@statement.outer',
|
||||
-- -- ['ac'] = '@comment.outer',
|
||||
-- -- ['ic'] = '@comment.inner',
|
||||
-- -- ['ap'] = '@comment.parameter',
|
||||
-- -- ['ip'] = '@comment.parameter',
|
||||
-- -- },
|
||||
-- -- move = {
|
||||
-- -- enable = true,
|
||||
-- -- set_jumps = true, -- whether to set jumps in the jumplist
|
||||
-- -- goto_next_start = {
|
||||
-- -- [']m'] = '@function.outer',
|
||||
-- -- [']]'] = '@class.outer',
|
||||
-- -- },
|
||||
-- -- goto_next_end = {
|
||||
-- -- [']M'] = '@function.outer',
|
||||
-- -- [']['] = '@class.outer',
|
||||
-- -- },
|
||||
-- -- goto_previous_start = {
|
||||
-- -- ['[m'] = '@function.outer',
|
||||
-- -- ['[['] = '@class.outer',
|
||||
-- -- },
|
||||
-- -- goto_previous_end = {
|
||||
-- -- ['[M'] = '@function.outer',
|
||||
-- -- ['[]'] = '@class.outer',
|
||||
-- -- },
|
||||
-- -- },
|
||||
-- -- select = {
|
||||
-- -- enable = true,
|
||||
-- -- keymaps = {
|
||||
-- -- -- You can use the capture groups defined in textobjects.scm
|
||||
-- -- ['af'] = '@function.outer',
|
||||
-- -- ['if'] = '@function.inner',
|
||||
-- -- ['ac'] = '@class.outer',
|
||||
-- -- ['ic'] = '@class.inner',
|
||||
-- -- -- Or you can define your own textobjects like this
|
||||
-- -- ['iF'] = {
|
||||
-- -- python = '(function_definition) @function',
|
||||
-- -- cpp = '(function_definition) @function',
|
||||
-- -- c = '(function_definition) @function',
|
||||
-- -- java = '(method_declaration) @function',
|
||||
-- -- go = '(method_declaration) @function',
|
||||
-- -- },
|
||||
-- -- },
|
||||
-- -- },
|
||||
-- -- },
|
||||
-- -- }
|
||||
-- end,
|
||||
-- opts = {},
|
||||
-- -- There are additional nvim-treesitter modules that you can use to interact
|
||||
-- -- with nvim-treesitter. You should go explore a few and see what interests you:
|
||||
-- --
|
||||
-- -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
|
||||
-- -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
|
||||
-- -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
|
||||
}
|
||||
+17
-11
@@ -1,16 +1,17 @@
|
||||
-- Highlight, edit, and navigate code
|
||||
return {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
build = ':TSUpdate',
|
||||
branch = 'main',
|
||||
build = ':TSUpdate',
|
||||
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
||||
config = function()
|
||||
require('nvim-treesitter').setup {}
|
||||
require('nvim-treesitter').install {
|
||||
local langs = {
|
||||
'bash',
|
||||
'zsh',
|
||||
'c',
|
||||
'diff',
|
||||
'html',
|
||||
'latex',
|
||||
'lua',
|
||||
'luadoc',
|
||||
'markdown',
|
||||
@@ -19,16 +20,21 @@ return {
|
||||
'vim',
|
||||
'vimdoc',
|
||||
'php',
|
||||
'yaml',
|
||||
'vue',
|
||||
'javascript',
|
||||
'typescript',
|
||||
'json',
|
||||
'css',
|
||||
'blade',
|
||||
}
|
||||
require('nvim-treesitter').install(langs)
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = langs,
|
||||
callback = function()
|
||||
vim.treesitter.start()
|
||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
end,
|
||||
})
|
||||
end,
|
||||
opts = {},
|
||||
-- There are additional nvim-treesitter modules that you can use to interact
|
||||
-- with nvim-treesitter. You should go explore a few and see what interests you:
|
||||
--
|
||||
-- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
|
||||
-- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
|
||||
-- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
|
||||
}
|
||||
|
||||
@@ -8,12 +8,6 @@ return {
|
||||
},
|
||||
keys = {
|
||||
-- 👇 in this section, choose your own keymappings!
|
||||
{
|
||||
'-',
|
||||
mode = { 'n', 'v' },
|
||||
'<cmd>Yazi<cr>',
|
||||
desc = 'Open yazi at the current file',
|
||||
},
|
||||
{
|
||||
-- Open in the current working directory
|
||||
'\\',
|
||||
|
||||
+75
-33
@@ -92,39 +92,39 @@ end
|
||||
|
||||
local function laravel_bookmarks_with_dir(dir)
|
||||
create_bookmark_maps {
|
||||
['e'] = dir .. '/.env',
|
||||
['l'] = dir .. '/storage/logs/laravel.log',
|
||||
['w'] = dir .. '/routes/web.php',
|
||||
['a'] = dir .. '/routes/api.php',
|
||||
['m'] = dir .. '/database/migrations',
|
||||
['e'] = dir .. '.env',
|
||||
['l'] = dir .. 'storage/logs/laravel.log',
|
||||
['w'] = dir .. 'routes/web.php',
|
||||
['a'] = dir .. 'routes/api.php',
|
||||
['m'] = dir .. 'database/migrations',
|
||||
|
||||
['dc'] = dir .. '/app/Core/',
|
||||
['dd'] = dir .. '/app/Data/',
|
||||
['dE'] = dir .. '/app/Enums/',
|
||||
['de'] = dir .. '/app/Events/',
|
||||
['dh'] = dir .. '/app/Http/',
|
||||
['dj'] = dir .. '/app/Jobs/',
|
||||
['dl'] = dir .. '/app/Listeners/',
|
||||
['dM'] = dir .. '/app/Mail/',
|
||||
['dm'] = dir .. '/app/Models/',
|
||||
['dn'] = dir .. '/app/Notifications/',
|
||||
['do'] = dir .. '/app/Observers/',
|
||||
['dp'] = dir .. '/app/Providers/',
|
||||
['dc'] = dir .. 'app/Core/',
|
||||
['dd'] = dir .. 'app/Data/',
|
||||
['dE'] = dir .. 'app/Enums/',
|
||||
['de'] = dir .. 'app/Events/',
|
||||
['dh'] = dir .. 'app/Http/',
|
||||
['dj'] = dir .. 'app/Jobs/',
|
||||
['dl'] = dir .. 'app/Listeners/',
|
||||
['dM'] = dir .. 'app/Mail/',
|
||||
['dm'] = dir .. 'app/Models/',
|
||||
['dn'] = dir .. 'app/Notifications/',
|
||||
['do'] = dir .. 'app/Observers/',
|
||||
['dp'] = dir .. 'app/Providers/',
|
||||
|
||||
['pa'] = dir .. '/app/Providers/AppServiceProvider.php',
|
||||
['pe'] = dir .. '/app/Providers/EventServiceProvider.php',
|
||||
['pa'] = dir .. 'app/Providers/AppServiceProvider.php',
|
||||
['pe'] = dir .. 'app/Providers/EventServiceProvider.php',
|
||||
|
||||
['cA'] = dir .. '/config/app.php',
|
||||
['ca'] = dir .. '/config/auth.php',
|
||||
['cb'] = dir .. '/config/broadcasting.php',
|
||||
['cd'] = dir .. '/config/database.php',
|
||||
['cf'] = dir .. '/config/filesystems.php',
|
||||
['ch'] = dir .. '/config/filesystems.php',
|
||||
['cl'] = dir .. '/config/logging.php',
|
||||
['cm'] = dir .. '/config/mail.php',
|
||||
['cq'] = dir .. '/config/queue.php',
|
||||
['cS'] = dir .. '/config/services.php',
|
||||
['cs'] = dir .. '/config/session.php',
|
||||
['cA'] = dir .. 'config/app.php',
|
||||
['ca'] = dir .. 'config/auth.php',
|
||||
['cb'] = dir .. 'config/broadcasting.php',
|
||||
['cd'] = dir .. 'config/database.php',
|
||||
['cf'] = dir .. 'config/filesystems.php',
|
||||
['ch'] = dir .. 'config/filesystems.php',
|
||||
['cl'] = dir .. 'config/logging.php',
|
||||
['cm'] = dir .. 'config/mail.php',
|
||||
['cq'] = dir .. 'config/queue.php',
|
||||
['cS'] = dir .. 'config/services.php',
|
||||
['cs'] = dir .. 'config/session.php',
|
||||
}
|
||||
end
|
||||
|
||||
@@ -216,8 +216,8 @@ local PROJECTS = {
|
||||
end, { desc = 'Open database manager' })
|
||||
map('s ', '!cd server && ', { desc = 'Run command in server directory' }, 'c')
|
||||
map('c ', '!cd client && ', { desc = 'Run command in client directory' }, 'c')
|
||||
laravel_keymaps 'server'
|
||||
laravel_makes 'server'
|
||||
laravel_keymaps 'server/'
|
||||
laravel_makes 'server/'
|
||||
map('yrn ', '!cd client && yarn ', { desc = 'Run yarn script' }, 'c')
|
||||
map('<Leader>pt', ':!cd server && php artisan typescript:transform --format<CR>', { desc = 'Compile typescript' })
|
||||
require('conform').formatters.pint = {
|
||||
@@ -242,6 +242,46 @@ local PROJECTS = {
|
||||
laravel_makes()
|
||||
map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c')
|
||||
map('<Leader>pm', ':vendor/bin/sail composer migrate<CR>')
|
||||
|
||||
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
|
||||
pattern = { '*.php', '.env', '.graphql' },
|
||||
callback = function()
|
||||
vim.fn.jobstart('vendor/bin/sail artisan octane:reload', { stdout_buffered = true })
|
||||
vim.fn.jobstart('vendor/bin/sail artisan horizon:terminate', { stdout_buffered = true })
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
|
||||
pattern = { '.graphql' },
|
||||
callback = function()
|
||||
vim.fn.jobstart('vendor/bin/sail artisan lighthouse:clear-cache', { stdout_buffered = true })
|
||||
end,
|
||||
})
|
||||
end,
|
||||
['server'] = function(dir)
|
||||
map('<leader>pl', ':cexpr system("vendor/bin/phpstan analyse --no-progress --error-format=raw --memory-limit=2G -vv") <CR>', { desc = 'Run lint' })
|
||||
map('<leader>pd', function()
|
||||
helpers.open_term { cmd = 'lazysql pgsql://homestead:password@localhost:5432/homestead' }
|
||||
end, { desc = 'Open database manager' })
|
||||
laravel_keymaps()
|
||||
laravel_makes()
|
||||
map('yrn ', '!cd frontend && yarn ', { desc = 'Run yarn script' }, 'c')
|
||||
map('<Leader>pm', ':vendor/bin/sail composer migrate<CR>')
|
||||
|
||||
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
|
||||
pattern = { '*.php', '.env', '.graphql' },
|
||||
callback = function()
|
||||
vim.fn.jobstart('vendor/bin/sail artisan octane:reload', { stdout_buffered = true })
|
||||
vim.fn.jobstart('vendor/bin/sail artisan horizon:terminate', { stdout_buffered = true })
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
|
||||
pattern = { '.graphql' },
|
||||
callback = function()
|
||||
vim.fn.jobstart('vendor/bin/sail artisan lighthouse:clear-cache', { stdout_buffered = true })
|
||||
end,
|
||||
})
|
||||
end,
|
||||
|
||||
default = function() end,
|
||||
@@ -257,10 +297,12 @@ function M.apply(cwd)
|
||||
end
|
||||
last_applied = name
|
||||
|
||||
local setup = PROJECTS[name] or PROJECTS.default
|
||||
local setup = PROJECTS[name]
|
||||
if type(setup) == 'function' then
|
||||
setup(dir)
|
||||
vim.notify(('Project config loaded: %s'):format(name), vim.log.levels.INFO, { title = 'projects.lua' })
|
||||
else
|
||||
PROJECTS.default(dir)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+113
-30
@@ -1,45 +1,128 @@
|
||||
local ls = require 'luasnip'
|
||||
local s = ls.snippet
|
||||
local sn = ls.snippet_node
|
||||
local fn = ls.function_node
|
||||
local ms = ls.multi_snippet
|
||||
local t = ls.text_node
|
||||
local c = ls.choice_node
|
||||
local i = ls.insert_node
|
||||
local f = ls.function_node
|
||||
local d = ls.dynamic_node
|
||||
local fmt = require('luasnip.extras.fmt').fmt
|
||||
local rep = require('luasnip.extras').rep
|
||||
local extend_decorator = require 'luasnip.util.extend_decorator'
|
||||
local fmta = extend_decorator.apply(fmt, { delimiters = '#~' })
|
||||
|
||||
local utils = require 'snippets.snip_utils'
|
||||
local tr = utils.tr
|
||||
local etr = utils.etr
|
||||
local atr = utils.atr
|
||||
local ctr = utils.ctr
|
||||
local bs = utils.bs
|
||||
|
||||
return {
|
||||
s('du', { t 'console.log(', i(0), t ');' }),
|
||||
s(etr('du ', 'Dump a variable to the console'), fmta('console.log(#~);', { i(0) })),
|
||||
s(
|
||||
etr('vue', 'Vue Single File Component skeleton'),
|
||||
fmta(
|
||||
[[
|
||||
<template>
|
||||
</template>
|
||||
<script setup>
|
||||
#~
|
||||
</script>
|
||||
<style scoped>
|
||||
</style>
|
||||
]],
|
||||
{ i(0) }
|
||||
)
|
||||
),
|
||||
|
||||
s('vue', {
|
||||
t { '<template>', '' },
|
||||
t { '', '</template>', '', '', '<script setup>', '' },
|
||||
i(0),
|
||||
t { '', '</script>', '', '', '<style scoped>', '', '.o-share-page {', '}', '', '</style>' },
|
||||
-- bs(atr('t ', 'this'), fmta('this.#~', { i(0) })),
|
||||
|
||||
s(etr('return ', 'Add semicolon after return'), fmta('return #~;', { i(0) })),
|
||||
s(etr('rt ', 'return alias'), fmta('return #~;', { i(0) })),
|
||||
|
||||
s(etr('const ', 'const declaration'), {
|
||||
c(1, {
|
||||
sn(nil, fmta('const #~ = #~;', { i(1, 'variableName'), i(2, 'value') })),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
const #~ = (#~) => {
|
||||
#~
|
||||
}
|
||||
]],
|
||||
{ i(1), i(2), i(3) }
|
||||
)
|
||||
),
|
||||
}),
|
||||
}),
|
||||
|
||||
s('fun', {
|
||||
t 'function ',
|
||||
i(1),
|
||||
t '(',
|
||||
i(2),
|
||||
t ') {',
|
||||
t { '', ' ' },
|
||||
i(0),
|
||||
t { '', '}' },
|
||||
s(
|
||||
etr('fn ', 'function block'),
|
||||
fmta(
|
||||
[[
|
||||
function #~(#~) {
|
||||
#~
|
||||
}
|
||||
]],
|
||||
{ i(1), i(2), i(0) }
|
||||
)
|
||||
),
|
||||
|
||||
bs(atr('fn ', 'function block'), {
|
||||
c(1, {
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
(#~) => {
|
||||
#~
|
||||
}
|
||||
]],
|
||||
{ i(1), i(2) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
function (#~) {
|
||||
#~
|
||||
}
|
||||
]],
|
||||
{ i(1), i(2) }
|
||||
)
|
||||
),
|
||||
}),
|
||||
}),
|
||||
|
||||
s('afun', {
|
||||
t 'async function ',
|
||||
i(1),
|
||||
t '(',
|
||||
i(2),
|
||||
t ') {',
|
||||
t { '', ' ' },
|
||||
i(0),
|
||||
t { '', '}' },
|
||||
bs(atr('afn ', 'async function block'), {
|
||||
c(1, {
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
async (#~) => {
|
||||
#~
|
||||
}
|
||||
]],
|
||||
{ i(1), i(2) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
async function (#~) {
|
||||
#~
|
||||
}
|
||||
]],
|
||||
{ i(1), i(2) }
|
||||
)
|
||||
),
|
||||
}),
|
||||
|
||||
s('()', {
|
||||
t '() => {',
|
||||
t { '', ' ' },
|
||||
i(0),
|
||||
t { '', '}' },
|
||||
}),
|
||||
}
|
||||
|
||||
+157
-140
@@ -16,6 +16,7 @@ local fmta = extend_decorator.apply(fmt, { delimiters = '#~' })
|
||||
local utils = require 'snippets.snip_utils'
|
||||
local tr = utils.tr
|
||||
local etr = utils.etr
|
||||
local Etr = utils.Etr
|
||||
local atr = utils.atr
|
||||
local ctr = utils.ctr
|
||||
local bs = utils.bs
|
||||
@@ -69,10 +70,10 @@ return {
|
||||
---------------
|
||||
-- DEBUGGING --
|
||||
---------------
|
||||
s(etr('du ', 'Dump a variable to the dump server'), fmta('dump(#~);', { i(0) })),
|
||||
bs(atr('du ', 'Dump a variable to the dump server'), fmta('dump(#~)', { i(0) })),
|
||||
s(etr('r ', 'ray'), fmta('ray(#~);', { i(0) })),
|
||||
bs(atr('r ', 'ray'), fmta('ray(#~)', { i(0) })),
|
||||
s(etr('du ', 'Dump a variable to the dump server', { priority = 1001 }), fmta('dump(#~);', { i(0) })),
|
||||
bs(etr('du ', 'Dump a variable to the dump server'), fmta('dump(#~)', { i(0) })),
|
||||
s(etr('r ', 'ray', { priority = 1001 }), fmta('ray(#~);', { i(0) })),
|
||||
bs(etr('r ', 'ray'), fmta('ray(#~)', { i(0) })),
|
||||
s(etr('dt ', 'Dump PHPStan type definition'), fmta('\\PhpStan\\dumpType(#~);', { i(0) })),
|
||||
s(
|
||||
etr('ql ', 'Log all queries'),
|
||||
@@ -107,6 +108,7 @@ return {
|
||||
}),
|
||||
s(etr('@v', '@var docblock'), fmta('/** @var #~ $#~ */', { i(1), i(0) })),
|
||||
s(ctr('@v', '@var docblock'), fmta('@var #~ $#~', { i(1), i(0) })),
|
||||
s(Etr('@pi', '@phpstan-ignore'), fmta('// @phpstan-ignore #~ (#~)', { i(1), i(0) })),
|
||||
s(ctr('* @pr', 'Class property docblock'), fmta('* @property #~ $#~', { i(1), i(0) })),
|
||||
s(ctr('* @pb', 'Class boolean property docblock'), fmta('* @property bool $#~', { i(0) })),
|
||||
s(ctr('* @pi', 'Class int property docblock'), fmta('* @property int $#~', { i(0) })),
|
||||
@@ -168,9 +170,9 @@ return {
|
||||
)
|
||||
),
|
||||
s(etr('return ', 'Add semicolon after return'), fmta('return #~;', { i(0) })),
|
||||
s(atr(' use ', 'Add use to function'), fmta(' use (#~)', { i(0) })),
|
||||
-- s(atr(' use ', 'Add use to function'), fmta(' use (#~)', { i(0) })),
|
||||
s(etr('rt ', 'return alias'), fmta('return #~;', { i(0) })),
|
||||
bs(etr('fn ', 'Shorthand function block'), {
|
||||
bs(atr('fn ', 'Shorthand function block'), {
|
||||
c(1, {
|
||||
sn(nil, fmta('fn (#~) => #~', { i(1), i(2) })),
|
||||
sn(
|
||||
@@ -186,7 +188,7 @@ return {
|
||||
),
|
||||
}),
|
||||
}),
|
||||
bs(etr('fun ', 'Shorthand function block'), {
|
||||
bs(atr('fun ', 'Shorthand function block'), {
|
||||
c(1, {
|
||||
sn(
|
||||
nil,
|
||||
@@ -212,36 +214,36 @@ return {
|
||||
),
|
||||
}),
|
||||
}),
|
||||
s(
|
||||
etr('con', 'Constructor function block'),
|
||||
c(1, {
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
public function __construct(#~)
|
||||
{
|
||||
#~
|
||||
}
|
||||
]],
|
||||
{ i(1), i(2) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
public function __construct(
|
||||
#~
|
||||
) {
|
||||
#~
|
||||
}
|
||||
]],
|
||||
{ i(1), i(2) }
|
||||
)
|
||||
),
|
||||
})
|
||||
),
|
||||
-- s(
|
||||
-- etr('con', 'Constructor function block'),
|
||||
-- c(1, {
|
||||
-- sn(
|
||||
-- nil,
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- public function __construct(#~)
|
||||
-- {
|
||||
-- #~
|
||||
-- }
|
||||
-- ]],
|
||||
-- { i(1), i(2) }
|
||||
-- )
|
||||
-- ),
|
||||
-- sn(
|
||||
-- nil,
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- public function __construct(
|
||||
-- #~
|
||||
-- ) {
|
||||
-- #~
|
||||
-- }
|
||||
-- ]],
|
||||
-- { i(1), i(2) }
|
||||
-- )
|
||||
-- ),
|
||||
-- })
|
||||
-- ),
|
||||
bs(atr('function', 'Shorthand function block'), fmta('fun', {})),
|
||||
bs(atr('s%$', 'string type parameter'), fmta('string $#~', { i(0, 'var') })),
|
||||
bs(atr('i%$', 'int type parameter'), fmta('int $#~', { i(0, 'var') })),
|
||||
@@ -358,20 +360,35 @@ return {
|
||||
etr('test', 'Create a test function'),
|
||||
fmta(
|
||||
[[
|
||||
test(#~ function () {
|
||||
test('#~', function () {
|
||||
#~
|
||||
})
|
||||
});
|
||||
]],
|
||||
{ i(1), i(0) }
|
||||
)
|
||||
),
|
||||
s(etr('nn ', 'Assert not null'), fmta('Assert::notNull(#~)', { i(0) })),
|
||||
s(
|
||||
etr('it ', 'Create a test function'),
|
||||
fmta(
|
||||
[[
|
||||
it('#~', function () {
|
||||
#~
|
||||
});
|
||||
]],
|
||||
{ i(1), i(0) }
|
||||
)
|
||||
),
|
||||
s(etr('nn ', 'Assert not null'), fmta('Assert::notNull(#~);', { i(0) })),
|
||||
s(etr('ast ', 'Assert string'), fmta('Assert::string(#~);', { i(0) })),
|
||||
s(etr('ain ', 'Assert integer'), fmta('Assert::integer(#~);', { i(0) })),
|
||||
s(etr('aio ', 'Assert instance of'), fmta('Assert::isInstanceOf(#~);', { i(0) })),
|
||||
s(etr('at ', 'Assert true'), fmta('Assert::true(#~);', { i(0) })),
|
||||
-------------
|
||||
-- LARAVEL --
|
||||
-------------
|
||||
s(
|
||||
etr('bt', 'belongsTo Laravel relationship method'),
|
||||
c(0, {
|
||||
c(1, {
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
@@ -384,7 +401,7 @@ return {
|
||||
return $this->belongsTo(#~::class);
|
||||
}
|
||||
]],
|
||||
{ rep(1), i(0), i(1) }
|
||||
{ rep(1), i(2), i(1) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
@@ -399,14 +416,14 @@ return {
|
||||
return $this->belongsTo(#~::class, #~);
|
||||
}
|
||||
]],
|
||||
{ rep(1), i(2), i(1), i(0) }
|
||||
{ rep(1), i(2), i(1), i(3) }
|
||||
)
|
||||
),
|
||||
})
|
||||
),
|
||||
s(
|
||||
etr('hm', 'hasMany Laravel relationship method'),
|
||||
c(0, {
|
||||
c(1, {
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
@@ -419,7 +436,7 @@ return {
|
||||
return $this->hasOne(#~::class);
|
||||
}
|
||||
]],
|
||||
{ rep(1), i(0), i(1) }
|
||||
{ rep(1), i(2), i(1) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
@@ -434,14 +451,14 @@ return {
|
||||
return $this->hasOne(#~::class, #~);
|
||||
}
|
||||
]],
|
||||
{ rep(1), i(2), i(1), i(0) }
|
||||
{ rep(1), i(2), i(1), i(3) }
|
||||
)
|
||||
),
|
||||
})
|
||||
),
|
||||
s(
|
||||
etr('ho', 'hasOne Laravel relationship method'),
|
||||
c(0, {
|
||||
c(1, {
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
@@ -454,7 +471,7 @@ return {
|
||||
return $this->hasOne(#~::class);
|
||||
}
|
||||
]],
|
||||
{ rep(1), i(0), i(1) }
|
||||
{ rep(1), i(2), i(1) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
@@ -469,14 +486,14 @@ return {
|
||||
return $this->hasOne(#~::class, #~);
|
||||
}
|
||||
]],
|
||||
{ rep(1), i(2), i(1), i(0) }
|
||||
{ rep(1), i(2), i(1), i(3) }
|
||||
)
|
||||
),
|
||||
})
|
||||
),
|
||||
s(
|
||||
etr('bm', 'belongsToMany Laravel relationship method'),
|
||||
c(0, {
|
||||
c(1, {
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
@@ -489,7 +506,7 @@ return {
|
||||
return $this->belongsToMany(#~::class, #~);
|
||||
}
|
||||
]],
|
||||
{ rep(1), i(2), i(1), i(0) }
|
||||
{ rep(1), i(2), i(1), i(3) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
@@ -504,97 +521,97 @@ return {
|
||||
return $this->belongsToMany(#~::class, #~, #~);
|
||||
}
|
||||
]],
|
||||
{ rep(1), i(2), i(1), i(3), i(0) }
|
||||
)
|
||||
),
|
||||
})
|
||||
),
|
||||
s(
|
||||
atr('->wr', 'Eloquent where method'),
|
||||
c(0, {
|
||||
sn(nil, fmta("->where('#~', #~)", { i(1), i(0) })),
|
||||
sn(nil, fmta('->where(fn ($query) => #~)', { i(0) })),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
->where(function ($query) {
|
||||
#~
|
||||
})
|
||||
]],
|
||||
{ i(0) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
->where(function ($query) use (#~) {
|
||||
#~
|
||||
})
|
||||
]],
|
||||
{ i(1), i(0) }
|
||||
)
|
||||
),
|
||||
})
|
||||
),
|
||||
s(atr('->wi', 'Eloquent where in method'), fmta("->whereIn('#~', #~)", { i(1), i(0) })),
|
||||
s(atr('->wn', 'Eloquent where not in method'), fmta("->whereNotIn('#~', #~)", { i(1), i(0) })),
|
||||
s(
|
||||
atr('->wh', 'Eloquent where has method'),
|
||||
c(0, {
|
||||
sn(nil, fmta("->whereHas('#~')", { i(1) })),
|
||||
sn(nil, fmta("->whereHas('#~', fn ($query) => #~)", { i(1), i(0) })),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
->whereHas('#~', function ($query) {
|
||||
#~
|
||||
})
|
||||
]],
|
||||
{ i(1), i(0) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
->whereHas('#~', function ($query) use (#~) {
|
||||
#~
|
||||
})
|
||||
]],
|
||||
{ i(1), i(2), i(0) }
|
||||
)
|
||||
),
|
||||
})
|
||||
),
|
||||
s(
|
||||
atr('->we', 'Eloquent where exists method'),
|
||||
c(0, {
|
||||
sn(nil, fmta('->whereExists(fn ($query) => #~)', { i(0) })),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
->whereExists(function ($query) {
|
||||
#~
|
||||
})
|
||||
]],
|
||||
{ i(0) }
|
||||
)
|
||||
),
|
||||
sn(
|
||||
nil,
|
||||
fmta(
|
||||
[[
|
||||
->whereExists(function ($query) use (#~) {
|
||||
#~
|
||||
})
|
||||
]],
|
||||
{ i(1), i(0) }
|
||||
{ rep(1), i(2), i(1), i(3), i(4) }
|
||||
)
|
||||
),
|
||||
})
|
||||
),
|
||||
-- s(
|
||||
-- atr('->wr', 'Eloquent where method'),
|
||||
-- c(0, {
|
||||
-- sn(nil, fmta("->where('#~', #~)", { i(1), i(0) })),
|
||||
-- sn(nil, fmta('->where(fn ($query) => #~)', { i(0) })),
|
||||
-- sn(
|
||||
-- nil,
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- ->where(function ($query) {
|
||||
-- #~
|
||||
-- })
|
||||
-- ]],
|
||||
-- { i(0) }
|
||||
-- )
|
||||
-- ),
|
||||
-- sn(
|
||||
-- nil,
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- ->where(function ($query) use (#~) {
|
||||
-- #~
|
||||
-- })
|
||||
-- ]],
|
||||
-- { i(1), i(0) }
|
||||
-- )
|
||||
-- ),
|
||||
-- })
|
||||
-- ),
|
||||
-- s(atr('->wi', 'Eloquent where in method'), fmta("->whereIn('#~', #~)", { i(1), i(0) })),
|
||||
-- s(atr('->wn', 'Eloquent where not in method'), fmta("->whereNotIn('#~', #~)", { i(1), i(0) })),
|
||||
-- s(
|
||||
-- atr('->wha', 'Eloquent where has method'),
|
||||
-- c(0, {
|
||||
-- sn(nil, fmta("->whereHas('#~')", { i(1) })),
|
||||
-- sn(nil, fmta("->whereHas('#~', fn ($query) => #~)", { i(1), i(0) })),
|
||||
-- sn(
|
||||
-- nil,
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- ->whereHas('#~', function ($query) {
|
||||
-- #~
|
||||
-- })
|
||||
-- ]],
|
||||
-- { i(1), i(0) }
|
||||
-- )
|
||||
-- ),
|
||||
-- sn(
|
||||
-- nil,
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- ->whereHas('#~', function ($query) use (#~) {
|
||||
-- #~
|
||||
-- })
|
||||
-- ]],
|
||||
-- { i(1), i(2), i(0) }
|
||||
-- )
|
||||
-- ),
|
||||
-- })
|
||||
-- ),
|
||||
-- s(
|
||||
-- atr('->we', 'Eloquent where exists method'),
|
||||
-- c(0, {
|
||||
-- sn(nil, fmta('->whereExists(fn ($query) => #~)', { i(0) })),
|
||||
-- sn(
|
||||
-- nil,
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- ->whereExists(function ($query) {
|
||||
-- #~
|
||||
-- })
|
||||
-- ]],
|
||||
-- { i(0) }
|
||||
-- )
|
||||
-- ),
|
||||
-- sn(
|
||||
-- nil,
|
||||
-- fmta(
|
||||
-- [[
|
||||
-- ->whereExists(function ($query) use (#~) {
|
||||
-- #~
|
||||
-- })
|
||||
-- ]],
|
||||
-- { i(1), i(0) }
|
||||
-- )
|
||||
-- ),
|
||||
-- })
|
||||
-- ),
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ local d = ls.dynamic_node
|
||||
local fmt = require('luasnip.extras.fmt').fmt
|
||||
local rep = require('luasnip.extras').rep
|
||||
local line_begin = require('luasnip.extras.conditions').line_begin
|
||||
local line_end = require('luasnip.extras.conditions').line_end
|
||||
local extend_decorator = require 'luasnip.util.extend_decorator'
|
||||
local fmta = extend_decorator.apply(fmt, { delimiters = '#~' })
|
||||
|
||||
@@ -109,6 +110,21 @@ utils.atr = function(trigger, description, options)
|
||||
)
|
||||
end
|
||||
|
||||
--- Create a trigger for a snippet to expand at the end of a line
|
||||
---@param trigger string
|
||||
---@param description? string
|
||||
---@param options? table
|
||||
---@return table
|
||||
utils.Etr = function(trigger, description, options)
|
||||
return utils.tr(
|
||||
trigger,
|
||||
description,
|
||||
vim.tbl_extend('force', {
|
||||
condition = line_end
|
||||
}, options or {})
|
||||
)
|
||||
end
|
||||
|
||||
--- Create a snippet that will expand anywhere but in the middle of a word
|
||||
---@param trigger any
|
||||
---@param nodes any
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
local M = {}
|
||||
|
||||
function M.open(name)
|
||||
local titles = {
|
||||
zsh = 'ZSH Cheat Sheet',
|
||||
bash = 'Bash Cheat Sheet',
|
||||
regex = 'RegExp Cheat Sheet',
|
||||
}
|
||||
|
||||
local path = vim.fn.stdpath 'config' .. '/cheatsheets/' .. name .. '.md'
|
||||
print('Opening cheat sheet: ' .. path)
|
||||
|
||||
require('../helpers').open_file_modal(path, titles[name] or name)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user