Commit MetaInfo

修订版1d170f7d2da43f11c340c96309c6c811489bf6d3 (tree)
时间2021-12-23 23:55:05
作者Erik <erikgronwal@user...>
CommiterErik

Log Message

Regular updates

更改概述

差异

--- a/fish-shell.md
+++ b/fish-shell.md
@@ -9,41 +9,81 @@ weight: -1
99
1010 ### Keys
1111
12-| Shortcut | Description |
13-| --- | --- |
14-| `^A ←` _/_ `^E →` | Move to line beginning/end |
15-| `Alt ←` _/_ `Alt →` | Move word |
16-| `^U` | Delete to beginning |
17-| `^W` | Delete to previous `/` |
18-| `^D` | Delete next character |
19-| `Alt D` | Delete next word |
20-| `^C` | Cancel line |
21-| `Alt P` | Page output |
22-| --- | --- |
23-| `Alt ↑` _/_ `Alt ↓` | Previous _/_ next arguments |
24-| `Alt E` _/_ `Alt V` | Open in external editor |
25-| `^L` | Repaint screen |
26-{: .-shortcuts}
27-
28-### Help
29-
30-| `Alt H` | Help on word (man) |
31-| `Alt W` | Help on word (short descriptions) |
32-| `Alt L` | List directory on cursor |
33-{: .-shortcuts}
12+| Shortcut | Description |
13+| --- | --- |
14+| `^A ←`/`^E →` | Move to the line beginning/end |
15+| `Alt ←`/`Alt →` | Jump to the previous/next word |
16+| `↑`/`↓` | Switch to the previous/next command |
17+| `Alt ↑`/`Alt ↓` | Switch to the previous/next arguments |
18+| --- | --- |
19+| `^U` | Delete to the beginning |
20+| `^C` | Cancel the line |
21+| --- | --- |
22+| `Alt H` | Show the command man page description |
23+| `Alt W` | Show the short command description |
24+
25+### Sample program
26+
27+```fish
28+#!/usr/bin/env fish
29+
30+echo 'Hello from Fish!'
31+```
32+
33+### Comments
34+
35+```fish
36+# my comment
37+```
38+
39+### Printing text
40+
41+```fish
42+echo 'Hello from Fish!'
43+# or
44+printf '%s\n' 'Hello from Fish!'
45+```
46+
47+Print the string with a trailing `\n`.
48+
49+### Reading from stdin
50+
51+```fish
52+read my_variable
53+```
54+
55+Reads the string to a variable `my_variable`.
56+
57+### Loops
58+
59+```fish
60+for i in (seq 1 10)
61+ ...
62+end
63+```
3464
3565 ## Variables
3666
3767 ### Defining and erasing
3868
3969 ```fish
40-set my_variable "Hello from Fish!"
70+# Declare the global/local variable:
71+set my_variable 'Hello from Fish!'
72+
73+i# Remove the variable:
74+set --erase my_variable
4175 ```
4276
77+### Slicing
78+
4379 ```fish
44-set --erase my_variable
80+echo $my_variable[1..10]
81+echo $my_variable[2..]
82+echo $my_variable[..-2]
4583 ```
4684
85+## Numbers
86+
4787 ### Incrementing and decrementing
4888
4989 ```fish
@@ -51,62 +91,62 @@ set my_variable (math $my_variable + 1)
5191 set my_variable (math $my_variable - 1)
5292 ```
5393
54-### Slicing
94+### Arithmetic
5595
5696 ```fish
57-set my_variable $another_variable[1..10]
58-set my_variable $another_variable[2..]
59-set my_variable $another_variable[..-2]
97+echo (math 1 + 2)
6098 ```
6199
62-## Arithmetic
100+| Operator | Performs |
101+| --- | --- |
102+| `+` | Addition |
103+| `-` | Subtraction |
104+| `*` | Multiplication |
105+| `/` | Division |
106+| `%` | Modulo |
107+| `^` | Exponentiation |
63108
64-```fish
65-math 1 + 2
66-```
109+## Strings
67110
68-| Operator | Performs |
69-| --- | --- |
70-| `+` | Addition |
71-| `-` | Subtraction |
72-| `*` | Multiplication |
73-| `/` | Division |
74-| `%` | Modulo |
75-| `^` | Exponentiation |
76-{: .-shortcuts}
111+### Matching
77112
78-## String manipulation
113+Match the string against a regular expresion:
79114
80115 ```fish
81116 string match --regex --entire 'Fish' 'Hello from Fish!'
82117 ```
83118
119+| Pattern | Matches |
120+| --- | --- |
121+| `x?` | Zero or one `x` chars |
122+| `x*` | Any count `x` chars |
123+| `x+` | One or more `x` chars |
124+| `x{n}` | n times `x` chars |
125+| `x{n,m}` | n to m times `x` chars |
126+| `x{n,}` | n or more times `x` chars |
127+| `[xy]` | `x` or y char |
128+| `[^xy]` | not `x` or y char |
129+| --- | --- |
130+| `\w` | Word character |
131+| `\d` | Digit character |
132+| `\W` | Not word character |
133+| `\D` | Not digit character |
134+
135+Perl compatible regular expressions are described here.
136+
137+### Replacing
138+
84139 ```fish
140+# Replaces the first match
85141 string replace --regex 'Fish' 'fish' 'Hello from Fish!'
86-```
87142
88-| Pattern | Matches |
89-| --- | --- |
90-| `x?` | Zero or one `x` chars |
91-| `x*` | Any count `x` chars |
92-| `x+` | One or more `x` chars |
93-| `x{n}` | n times `x` chars |
94-| `x{n,m}` | n to m times `x` chars |
95-| `x{n,}` | n or more times `x` chars |
96-| `x{n,}` | n or more times `x` chars |
97-| `[xy] ` | `x` or y char |
98-| `[^xy]` | not `x` or y char |
99-{: .-shortcuts}
143+# Replaces all matches
144+string replace --regex --all 'Fish' 'fish' 'Hello from Fish!'
145+```
100146
101-| Class | Description |
102-| --- | --- |
103-| `\w` | Word character |
104-| `\d` | Digit character |
105-| `\W` | Not word character |
106-| `\D` | Not digit character |
107-{: .-shortcuts}
147+## Conditionals
108148
109-### Conditionals
149+### If/else
110150
111151 ```fish
112152 if test $my_variable -lt $another_variable
@@ -118,54 +158,86 @@ else
118158 end
119159 ```
120160
121-| Operator | Meaning |
161+### Comparisons
162+
163+#### Numbers
164+
165+| Number operator | Meaning |
122166 | --- | --- |
123167 | `-lt` | [L]ess [t]han |
124168 | `-eq` | [Eq]ual |
125169 | `-gt` | [G]reater [t]han |
126170 | `-le` | [L]ess than or [e]qual to |
127171 | `-ge` | [G]reater than or [e]qual to |
172+| `-ne` | [N]ot [E]qual |
173+
174+#### Strings
175+
176+| String operator | Meaning |
177+| --- | --- |
178+| `==` | [Eq]ual |
179+| `!=` | [N]ot [E]qual |
180+
181+#### Files
182+
183+| File operator | Meaning |
184+| --- | --- |
128185 | `-f` | [F]ile exists |
129186 | `-d` | [D]irectory exists |
130187 | `-r` | File or directory exists and [r]eadable |
131188 | `-w` | File or directory exists and [w]ritable |
132189 | `-x` | File or directory exists and e[x]ecutable |
133-{: .-shortcuts}
134190
135-## Loops
191+
192+## Process communication
193+
194+### Writing to files
136195
137196 ```fish
138-for i in (seq 1 10)
139- ...
140-end
197+# Overwrite file
198+echo 'Hello from Fish!' > my_file
199+
200+# Append to file
201+echo 'Hello from Fish!' >> my_file
141202 ```
142203
143-## Command substitution
204+### Piping
144205
145206 ```fish
146-set my_variable (math $my_variable + 1)
207+my_command | another_command
147208 ```
148209
149-## Functions
210+Passes the first command stdout output as an input to a second command.
150211
151-### Defining and erasing
212+### Command substitution
152213
153214 ```fish
154-function my_function --description "My description"
155- ···
156-end
215+echo (math $my_variable + 1)
157216 ```
158217
218+The `(...)` expression is substituted with the output of the command inside it.
219+
220+
221+### Process substitution
222+
159223 ```fish
160-functions --erase my_function
224+echo (math $my_variable + 1 | psub)
161225 ```
162226
163-### Event handling
227+The `(... | psub)` expression is substituted with a temporary file with the command's output.
228+
229+## Functions
230+
231+### Defining and erasing
164232
165233 ```fish
166-function my_hook --on-event my_event
234+# Declare the function
235+function my_function --description 'My description'
167236 ···
168237 end
238+
239+# Remove the function
240+functions --erase my_function
169241 ```
170242
171243 ## Events
@@ -176,56 +248,74 @@ end
176248 emit my_event
177249 ```
178250
251+Emits an event that can be picked up by other functions.
252+
253+### Event handling
254+
255+```fish
256+function my_hook --on-event my_event
257+ ···
258+end
259+```
260+
261+Reacts to the `my_event` event.
179262
180263 ## Abbreviations
181264
182265 ### Defining and erasing
183266
184267 ```fish
185-abbr --add my_abbreviation echo "Hello from Fish!"
268+# Declare the abbreviation
269+abbr --add grh "git reset --hard HEAD"
186270 ```
187271
272+
188273 ```fish
189-abbr --erase my_abbreviation
274+# Remove the abbreviation
275+abbr --erase grh
190276 ```
191277
192278 ## Completions
193279
194-### Defining and erasing
280+### Defining completions
195281
196282 ```fish
197283 complete --command mycommand --arguments 'install uninstall'
198284 complete --command mycommand --short-option 'h' --long-option 'help' --description 'Display help'
199285 ```
200286
287+| Option | Description |
288+| --- | --- |
289+| `--arguments` | Arguments to the command itself or option |
290+| `--short-option` | Short option |
291+| `--long-option` | Long option |
292+| `--no-files` | Don't suggest files |
293+| `--force-files` | Suggest files |
294+| `--condition` | Display the hint only when a given condition is true |
295+| `--description` | Description |
296+
297+Declares the completion for a command.
298+
299+### Removing completions
300+
201301 ```fish
202302 complete --command mycommand --erase
203303 ```
204304
205-| Option | Description |
206-| --- | --- |
207-| `--arguments` | Arguments to command itself or option |
208-| `--short-option` | Short option |
209-| `--long-option` | Long option |
210-| `--no-files` | Don't suggest files |
211-| `--force-files` | Suggest files |
212-| `--condition` | Display hint only when condition is true |
213-| `--description` | Description |
214-{: .-shortcuts}
215-
216305 ## Useful built-in functions
217306
218-| Condition | Description
219-| --- | ---
220-| `-n __fish_complete_directories STRING DESCRIPTION` | performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION.
221-| `-n __fish_complete_path STRING DESCRIPTION` | performs path completion on STRING, giving them the description DESCRIPTION.
222-| `-n __fish_complete_groups` | prints a list of all user groups with the groups members as description.
223-| `-n __fish_complete_pids` | prints a list of all processes IDs with the command name as description.
224-| `-n __fish_complete_suffix SUFFIX` | performs file completion allowing only files ending in SUFFIX. The mimetype database is used to find a suitable description.
225-| `-n __fish_complete_users` | prints a list of all users with their full name as description.
226-| `-n __fish_print_filesystems` | prints a list of all known file systems. Currently, this is a static list, and not dependent on what file systems the host operating system actually understands.
227-| `-n __fish_print_hostnames` | prints a list of all known hostnames. This functions searches the fstab for nfs servers, ssh for known hosts and checks the /etc/hosts file.
228-| `-n __fish_print_interfaces` | prints a list of all known network interfaces.
229-| `-n __fish_print_packages` | prints a list of all installed packages. This function currently handles Debian, rpm and Gentoo packages.
230-| `-n __fish_use_subcommand` |
231-| `-n __fish_seen_subcommand_from init` |
307+| Function | Description |
308+| --- | --- |
309+| `__fish_seen_argument` | Check whether the specified argument is used |
310+| `__fish_seen_subcommand_from` | Check whether the specified subcommand is used |
311+| `__fish_use_subcommand` | Check whether any subcommand is used |
312+| --- | --- |
313+| `__fish_complete_directories` | Complete directories with the specified letters in their name |
314+| `__fish_complete_suffix` | Complete files with the specified suffix |
315+| --- | --- |
316+| `__fish_complete_users` | List all users |
317+| `__fish_complete_groups` | List all user groups |
318+| `__fish_print_hostnames` | List all host names |
319+| `__fish_complete_pids` | List all PIDs |
320+| `__fish_print_filesystems` | List all known filesystems |
321+| `__fish_print_interfaces` | List all network interfaces |
Show on old repository browser