-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfish.txt
70 lines (55 loc) · 1.2 KB
/
fish.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Switching shells
* add /opt/local/bin/fish to /etc/shells
chsh -s /opt/local/bin/fish
chsh -s /bin/bash
# Variables
set name 'value'
set -e name // delete variable
set -x name // export variable
set PATH $PATH /extra/path // append
# Lists
set LIST 1 2 3
echo $LIST[1] -> 1 // 1 is first index
echo $LIST[-1] -> 3
echo $LIST[1..2] -> 1 2
echo $LIST[-1..1] -> 3 2 1
## Lists are expanded to cartesian product
set LIST1 1 2 3
set LIST2 a b c
echo $LIST1$LIST2 -> 1a 2a 3a 1b 2b 3b 1c 2c 3c
echo "$LIST1$LIST2" -> 1 2 3abc
echo $LIST1 $LIST2 -> 1 2 3 a b c
# for loops
for val in $MYLIST
echo $val
end
# command substitution
* put in parenthesis: (COMMAND)
set os (uname)
# if else
if grep foo file.txt
foo
else if test $VAE -eq 1
...
else if [ $VAR -eq 2 ]
...
end
## test command
if test STATEMENT
else if [ STATEMENT ]
### comparing numbers
$VAR -eq 1 // equal
$VAR -ne 1 // not equal
$VAR -gt 1 // greater than
$VAR -ge 1 // greater equal
### comparing strings
$VAR = "foo"
$VAR != "foo"
# functions
functions // list all functions
functions ls // show code of function
funcsave ls // save function as file in fish/functions
function my_function
set arg1 $argv[1]
set arg2 $argv[2]
end