fish-shell: update layout
This commit is contained in:
parent
8da5a96c71
commit
99560e71bc
182
fish-shell.md
182
fish-shell.md
|
@ -1,111 +1,173 @@
|
||||||
---
|
---
|
||||||
title: Fish shell
|
title: Fish shell
|
||||||
category: CLI
|
category: CLI
|
||||||
|
layout: 2017/sheet
|
||||||
|
prism_languages: [fish]
|
||||||
|
updated: 2017-10-16
|
||||||
|
weight: -1
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### Keys
|
||||||
|
|
||||||
|
| Shortcut | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `Alt ←` _/_ `Alt →` | Move word |
|
||||||
|
| `^U` | Delete to beginning |
|
||||||
|
| `^W` | Delete to previous `/` |
|
||||||
|
| `Alt D` | Delete next word |
|
||||||
|
| --- | --- |
|
||||||
|
| `Alt ↑` | Last arguments |
|
||||||
|
{: .-shortcuts}
|
||||||
|
|
||||||
|
### Help
|
||||||
|
|
||||||
|
| `Alt H` | Help on word (man) |
|
||||||
|
| `Alt W` | Help on word (short descriptions) |
|
||||||
|
| `Alt L` | List directory on cursor |
|
||||||
|
{: .-shortcuts}
|
||||||
|
|
||||||
## Function
|
## Function
|
||||||
|
|
||||||
function my_function
|
### Writing functions
|
||||||
..
|
|
||||||
end
|
|
||||||
|
|
||||||
--description "My description"
|
```fish
|
||||||
|
function my_function --description "My description"
|
||||||
|
···
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Conditional
|
### Conditional
|
||||||
|
|
||||||
if test -f foo.txt
|
```fish
|
||||||
else if test -f bar.txt
|
if test -f foo.txt
|
||||||
else
|
···
|
||||||
end
|
else if test -f bar.txt
|
||||||
|
···
|
||||||
|
else
|
||||||
|
···
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
### Combining tests
|
### Combining tests
|
||||||
|
|
||||||
test -f foo.txt -a -f bar.txt
|
```fish
|
||||||
test \( -f foo.txt \) -a -f \( bar.txt \)
|
if test -f foo.txt && test -f bar.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
```fish
|
||||||
|
if test -f foo.txt -a -f bar.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
```fish
|
||||||
|
if test \( -f foo.txt \) -a -f \( bar.txt \)
|
||||||
|
```
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
emit my_event
|
#### Emitting
|
||||||
|
|
||||||
function myhook --on-event my_event
|
```fish
|
||||||
...
|
emit my_event
|
||||||
end
|
```
|
||||||
|
|
||||||
|
#### Listening
|
||||||
|
|
||||||
|
```fish
|
||||||
|
function myhook --on-event my_event
|
||||||
|
···
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
This lets you hook onto events, such as `fish_prompt`.
|
||||||
|
|
||||||
## Completions
|
## Completions
|
||||||
|
|
||||||
### Creating completions
|
### Creating completions
|
||||||
|
|
||||||
# ~/.fish/completions/mycommand.fish
|
#### ~/.fish/completions/mycommand.fish
|
||||||
complete -c mycommand ...
|
|
||||||
complete -c mycommand ...
|
```fish
|
||||||
complete -c mycommand ...
|
complete -c mycommand ...
|
||||||
|
complete -c mycommand ...
|
||||||
|
complete -c mycommand ...
|
||||||
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
-c command
|
```fish
|
||||||
-s short option
|
complete \
|
||||||
-l long option
|
-c # command
|
||||||
|
-s # short option
|
||||||
|
-l # long option
|
||||||
-r, --require-parameter
|
-r, --require-parameter
|
||||||
-f, --no-files
|
-f, --no-files
|
||||||
-x exclusive (-r -f)
|
-x # exclusive (-r -f)
|
||||||
-n '__fish_use_subcommand' condition
|
-n '__fish_use_subcommand' # condition
|
||||||
--description ".."
|
--description ".."
|
||||||
# complete -c $cmd -n '__fish_use_subcommand' -x -a hello --description 'lol'
|
```
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```fish
|
||||||
|
complete -c $cmd \
|
||||||
|
-n '__fish_use_subcommand' \
|
||||||
|
-x -a hello \
|
||||||
|
--description 'lol'
|
||||||
|
```
|
||||||
|
|
||||||
### Conditions
|
### Conditions
|
||||||
|
|
||||||
__fish_complete_directories STRING DESCRIPTION performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION.
|
| Condition | Description
|
||||||
__fish_complete_path STRING DESCRIPTION performs path completion on STRING, giving them the description DESCRIPTION.
|
| --- | ---
|
||||||
__fish_complete_groups prints a list of all user groups with the groups members as description.
|
| `-n __fish_complete_directories STRING DESCRIPTION` | performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION.
|
||||||
__fish_complete_pids prints a list of all processes IDs with the command name as description.
|
| `-n __fish_complete_path STRING DESCRIPTION` | performs path completion on STRING, giving them the description DESCRIPTION.
|
||||||
__fish_complete_suffix SUFFIX performs file completion allowing only files ending in SUFFIX. The mimetype database is used to find a suitable description.
|
| `-n __fish_complete_groups` | prints a list of all user groups with the groups members as description.
|
||||||
__fish_complete_users prints a list of all users with their full name as description.
|
| `-n __fish_complete_pids` | prints a list of all processes IDs with the command name as description.
|
||||||
__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.
|
| `-n __fish_complete_suffix SUFFIX` | performs file completion allowing only files ending in SUFFIX. The mimetype database is used to find a suitable description.
|
||||||
__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.
|
| `-n __fish_complete_users` | prints a list of all users with their full name as description.
|
||||||
__fish_print_interfaces prints a list of all known network interfaces.
|
| `-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.
|
||||||
__fish_print_packages prints a list of all installed packages. This function currently handles Debian, rpm and Gentoo packages.
|
| `-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.
|
||||||
|
| `-n __fish_print_interfaces` | prints a list of all known network interfaces.
|
||||||
|
| `-n __fish_print_packages` | prints a list of all installed packages. This function currently handles Debian, rpm and Gentoo packages.
|
||||||
|
| `-n __fish_use_subcommand` |
|
||||||
|
| `-n __fish_seen_subcommand_from init` |
|
||||||
|
|
||||||
__fish_use_subcommand
|
#### Example
|
||||||
__fish_seen_subcommand_from init
|
|
||||||
|
|
||||||
|
```fish
|
||||||
complete -c ruby -s X -x -a '(__fish_complete_directories (commandline -ct))' --description 'Directory'
|
complete -c ruby -s X -x -a '(__fish_complete_directories (commandline -ct))' --description 'Directory'
|
||||||
|
```
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
Start each example with `complete -c cmdname`
|
Start each example with `complete -c cmdname`
|
||||||
|
|
||||||
-x
|
```fish
|
||||||
|
-x
|
||||||
# no filename completion
|
# no filename completion
|
||||||
|
```
|
||||||
|
|
||||||
-s d -x -a "read skip"
|
```fish
|
||||||
|
-s d -x -a "read skip"
|
||||||
# -d {read|skip}
|
# -d {read|skip}
|
||||||
|
```
|
||||||
|
|
||||||
-s d -x
|
```fish
|
||||||
|
-s d -x
|
||||||
# -d <something>
|
# -d <something>
|
||||||
|
```
|
||||||
|
|
||||||
-s f -r
|
```fish
|
||||||
|
-s f -r
|
||||||
# -f FILE
|
# -f FILE
|
||||||
|
```
|
||||||
|
|
||||||
-s f -l force
|
```fish
|
||||||
|
-s f -l force
|
||||||
# -f, --force
|
# -f, --force
|
||||||
|
```
|
||||||
|
|
||||||
-a "(cat /etc/passwd | cut -d : -f 1)"
|
```fish
|
||||||
|
-a "(cat /etc/passwd | cut -d : -f 1)"
|
||||||
# first argument as filename
|
# first argument as filename
|
||||||
|
```
|
||||||
### Keys
|
|
||||||
|
|
||||||
| `Alt ←` `Alt →` | Move word |
|
|
||||||
| `^U` | delete to beginning |
|
|
||||||
| `^W` | delete to previous `/` |
|
|
||||||
| `Alt D` | delete next word |
|
|
||||||
{:.shortcuts}
|
|
||||||
|
|
||||||
| `Alt H` | help on word (man) |
|
|
||||||
| `Alt W` | help on word (short descriptions) |
|
|
||||||
| `Alt L` | list directory on cursor |
|
|
||||||
{:.shortcuts}
|
|
||||||
|
|
||||||
| `Alt ↑` | search keywords |
|
|
||||||
{:.shortcuts}
|
|
||||||
|
|
Loading…
Reference in New Issue