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 |
30 echo 'Hello from Fish!'
42 echo 'Hello from Fish!'
44 printf '%s\n' 'Hello from Fish!'
47 Print the string with a trailing `\n`.
49 ### Reading from stdin
55 Reads the string to a variable `my_variable`.
67 ### Defining and erasing
70 # Declare the global/local variable:
71 set my_variable 'Hello from Fish!'
73 i# Remove the variable:
74 set --erase my_variable
80 echo $my_variable[1..10]
81 echo $my_variable[2..]
82 echo $my_variable[..-2]
87 ### Incrementing and decrementing
90 set my_variable (math $my_variable + 1)
91 set my_variable (math $my_variable - 1)
100 | Operator | Performs |
103 | `-` | Subtraction |
104 | `*` | Multiplication |
107 | `^` | Exponentiation |
113 Match the string against a regular expresion:
116 string match --regex --entire 'Fish' 'Hello from Fish!'
119 | Pattern | Matches |
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 |
130 | `\w` | Word character |
131 | `\d` | Digit character |
132 | `\W` | Not word character |
133 | `\D` | Not digit character |
135 Perl compatible regular expressions are described here.
140 # Replaces the first match
141 string replace --regex 'Fish' 'fish' 'Hello from Fish!'
143 # Replaces all matches
144 string replace --regex --all 'Fish' 'fish' 'Hello from Fish!'
152 if test $my_variable -lt $another_variable
154 else if test $my_variable -eq $another_variable
165 | Number operator | Meaning |
167 | `-lt` | [L]ess [t]han |
169 | `-gt` | [G]reater [t]han |
170 | `-le` | [L]ess than or [e]qual to |
171 | `-ge` | [G]reater than or [e]qual to |
172 | `-ne` | [N]ot [E]qual |
176 | String operator | Meaning |
179 | `!=` | [N]ot [E]qual |
183 | File operator | Meaning |
185 | `-f` | [F]ile exists |
186 | `-d` | [D]irectory exists |
187 | `-r` | File or directory exists and [r]eadable |
188 | `-w` | File or directory exists and [w]ritable |
189 | `-x` | File or directory exists and e[x]ecutable |
192 ## Process communication
198 echo 'Hello from Fish!' > my_file
201 echo 'Hello from Fish!' >> my_file
207 my_command | another_command
210 Passes the first command stdout output as an input to a second command.
212 ### Command substitution
215 echo (math $my_variable + 1)
218 The `(...)` expression is substituted with the output of the command inside it.
221 ### Process substitution
224 echo (math $my_variable + 1 | psub)
227 The `(... | psub)` expression is substituted with a temporary file with the command's output.
231 ### Defining and erasing
234 # Declare the function
235 function my_function --description 'My description'
239 # Remove the function
240 functions --erase my_function
251 Emits an event that can be picked up by other functions.
256 function my_hook --on-event my_event
261 Reacts to the `my_event` event.
265 ### Defining and erasing
268 # Declare the abbreviation
269 abbr --add grh "git reset --hard HEAD"
274 # Remove the abbreviation
280 ### Defining completions
283 complete --command mycommand --arguments 'install uninstall'
284 complete --command mycommand --short-option 'h' --long-option 'help' --description 'Display help'
287 | Option | Description |
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 |
297 Declares the completion for a command.
299 ### Removing completions
302 complete --command mycommand --erase
305 ## Useful built-in functions
307 | Function | Description |
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 |
313 | `__fish_complete_directories` | Complete directories with the specified letters in their name |
314 | `__fish_complete_suffix` | Complete files with the specified suffix |
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 |