5 prism_languages: [fish]
12 | Shortcut | Description |
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 |
19 | `^U` | Delete to the beginning |
20 | `^C` | Cancel the line |
22 | `Alt H` | Show the command man page description |
23 | `Alt W` | Show the short command description |
25 | `Alt .` | Repeat last argument |
32 echo 'Hello from Fish!'
44 echo 'Hello from Fish!'
46 printf '%s\n' 'Hello from Fish!'
49 Print the string with a trailing `\n`.
51 ### Reading from stdin
57 Reads the string to a variable `my_variable`.
69 ### Defining and erasing
72 # Declare the global/local variable:
73 set my_variable 'Hello from Fish!'
75 i# Remove the variable:
76 set --erase my_variable
82 echo $my_variable[1..10]
83 echo $my_variable[2..]
84 echo $my_variable[..-2]
89 ### Incrementing and decrementing
92 set my_variable (math $my_variable + 1)
93 set my_variable (math $my_variable - 1)
102 | Operator | Performs |
105 | `-` | Subtraction |
106 | `*` | Multiplication |
109 | `^` | Exponentiation |
115 Match the string against a regular expresion:
118 string match --regex --entire 'Fish' 'Hello from Fish!'
121 | Pattern | Matches |
123 | `x?` | Zero or one `x` chars |
124 | `x*` | Any count `x` chars |
125 | `x+` | One or more `x` chars |
126 | `x{n}` | n times `x` chars |
127 | `x{n,m}` | n to m times `x` chars |
128 | `x{n,}` | n or more times `x` chars |
129 | `[xy]` | `x` or y char |
130 | `[^xy]` | not `x` or y char |
132 | `\w` | Word character |
133 | `\d` | Digit character |
134 | `\W` | Not word character |
135 | `\D` | Not digit character |
137 Perl compatible regular expressions are described here.
142 # Replaces the first match
143 string replace --regex 'Fish' 'fish' 'Hello from Fish!'
145 # Replaces all matches
146 string replace --regex --all 'Fish' 'fish' 'Hello from Fish!'
154 if test $my_variable -lt $another_variable
156 else if test $my_variable -eq $another_variable
167 | Number operator | Meaning |
169 | `-lt` | [L]ess [t]han |
171 | `-gt` | [G]reater [t]han |
172 | `-le` | [L]ess than or [e]qual to |
173 | `-ge` | [G]reater than or [e]qual to |
174 | `-ne` | [N]ot [E]qual |
178 | String operator | Meaning |
181 | `!=` | [N]ot [E]qual |
185 | File operator | Meaning |
187 | `-f` | [F]ile exists |
188 | `-d` | [D]irectory exists |
189 | `-r` | File or directory exists and [r]eadable |
190 | `-w` | File or directory exists and [w]ritable |
191 | `-x` | File or directory exists and e[x]ecutable |
194 ## Process communication
200 echo 'Hello from Fish!' > my_file
203 echo 'Hello from Fish!' >> my_file
209 my_command | another_command
212 Passes the first command stdout output as an input to a second command.
214 ### Command substitution
217 echo (math $my_variable + 1)
220 The `(...)` expression is substituted with the output of the command inside it.
223 ### Process substitution
226 echo (math $my_variable + 1 | psub)
229 The `(... | psub)` expression is substituted with a temporary file with the command's output.
233 ### Defining and erasing
236 # Declare the function
237 function my_function --description 'My description'
241 # Remove the function
242 functions --erase my_function
253 Emits an event that can be picked up by other functions.
258 function my_hook --on-event my_event
263 Reacts to the `my_event` event.
267 ### Defining and erasing
270 # Declare the abbreviation
271 abbr --add grh "git reset --hard HEAD"
276 # Remove the abbreviation
282 ### Defining completions
285 complete --command mycommand --arguments 'install uninstall'
286 complete --command mycommand --short-option 'h' --long-option 'help' --description 'Display help'
289 | Option | Description |
291 | `--arguments` | Arguments to the command itself or option |
292 | `--short-option` | Short option |
293 | `--long-option` | Long option |
294 | `--no-files` | Don't suggest files |
295 | `--force-files` | Suggest files |
296 | `--condition` | Display the hint only when a given condition is true |
297 | `--description` | Description |
299 Declares the completion for a command.
301 ### Removing completions
304 complete --command mycommand --erase
307 ## Useful built-in functions
309 | Function | Description |
311 | `__fish_seen_argument` | Check whether the specified argument is used |
312 | `__fish_seen_subcommand_from` | Check whether the specified subcommand is used |
313 | `__fish_use_subcommand` | Check whether any subcommand is used |
315 | `__fish_complete_directories` | Complete directories with the specified letters in their name |
316 | `__fish_complete_suffix` | Complete files with the specified suffix |
318 | `__fish_complete_users` | List all users |
319 | `__fish_complete_groups` | List all user groups |
320 | `__fish_print_hostnames` | List all host names |
321 | `__fish_complete_pids` | List all PIDs |
322 | `__fish_print_filesystems` | List all known filesystems |
323 | `__fish_print_interfaces` | List all network interfaces |