X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=fish-shell.md;h=ec4c8b9035129801521cc2c41d05ee2206abdc45;hb=843b7553514be96507efdf2924505dc1654ccf47;hp=ff1ec3e8b78c2de9451570260028e6a0215841d8;hpb=ced9be1c328ceaf3aed57d88be6108223b9dc7c0;p=twpd%2Fmaster.git diff --git a/fish-shell.md b/fish-shell.md index ff1ec3e..ec4c8b9 100644 --- a/fish-shell.md +++ b/fish-shell.md @@ -11,6 +11,7 @@ weight: -1 | Shortcut | Description | | --- | --- | +| `^A ←` _/_ `^E →` | Move to line beginning/end | | `Alt ←` _/_ `Alt →` | Move word | | `^U` | Delete to beginning | | `^W` | Delete to previous `/` | @@ -31,148 +32,200 @@ weight: -1 | `Alt L` | List directory on cursor | {: .-shortcuts} -## Function +## Variables -### Writing functions +### Defining and erasing ```fish -function my_function --description "My description" - ··· -end +set my_variable "Hello from Fish!" ``` -### Conditional - ```fish -if test -f foo.txt - ··· -else if test -f bar.txt - ··· -else - ··· -end +set --erase my_variable ``` -### Combining tests +### Incrementing and decrementing ```fish -if test -f foo.txt && test -f bar.txt +set my_variable (math $my_variable + 1) +set my_variable (math $my_variable - 1) ``` +### Slicing + ```fish -if test -f foo.txt -a -f bar.txt +set my_variable $another_variable[1..10] +set my_variable $another_variable[2..] +set my_variable $another_variable[..-2] ``` +## Arithmetic + ```fish -if test \( -f foo.txt \) -a -f \( bar.txt \) +math 1 + 2 ``` -### Events +| Operator | Performs | +| --- | --- | +| `+` | Addition | +| `-` | Subtraction | +| `*` | Multiplication | +| `/` | Division | +| `%` | Modulo | +| `^` | Exponentiation | +{: .-shortcuts} -#### Emitting +## String manipulation ```fish -emit my_event +string match --regex --entire 'Fish' 'Hello from Fish!' ``` -#### Listening - ```fish -function myhook --on-event my_event - ··· -end +string replace --regex 'Fish' 'fish' 'Hello from Fish!' ``` -This lets you hook onto events, such as `fish_prompt`. - -## Completions +| Pattern | Matches | +| --- | --- | +| `x?` | Zero or one `x` chars | +| `x*` | Any count `x` chars | +| `x+` | One or more `x` chars | +| `x{n}` | n times `x` chars | +| `x{n,m}` | n to m times `x` chars | +| `x{n,}` | n or more times `x` chars | +| `x{n,}` | n or more times `x` chars | +| `[xy] ` | `x` or y char | +| `[^xy]` | not `x` or y char | +{: .-shortcuts} -### Creating completions +| Class | Description | +| --- | --- | +| `\w` | Word character | +| `\d` | Digit character | +| `\W` | Not word character | +| `\D` | Not digit character | +{: .-shortcuts} -#### ~/.fish/completions/mycommand.fish +### Conditionals ```fish -complete -c mycommand ... -complete -c mycommand ... -complete -c mycommand ... +if test $my_variable -lt $another_variable + ··· +else if test $my_variable -eq $another_variable + ··· +else + ··· +end ``` -### Options +| Operator | Meaning | +| --- | --- | +| `-lt` | [L]ess [t]han | +| `-eq` | [Eq]ual | +| `-gt` | [G]reater [t]han | +| `-le` | [L]ess than or [e]qual to | +| `-ge` | [G]reater than or [e]qual to | +| `-f` | [F]ile exists | +| `-d` | [D]irectory exists | +| `-r` | File or directory exists and [r]eadable | +| `-w` | File or directory exists and [w]ritable | +| `-x` | File or directory exists and e[x]ecutable | +{: .-shortcuts} + +## Loops ```fish -complete \ - -c # command - -s # short option - -l # long option - -r, --require-parameter - -f, --no-files - -x # exclusive (-r -f) - -n '__fish_use_subcommand' # condition - --description ".." +for i in (seq 1 10) + ... +end ``` -#### Example +## Command substitution ```fish - complete -c $cmd \ --n '__fish_use_subcommand' \ --x -a hello \ ---description 'lol' +set my_variable (math $my_variable + 1) ``` -### Conditions - -| Condition | Description -| --- | --- -| `-n __fish_complete_directories STRING DESCRIPTION` | performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION. -| `-n __fish_complete_path STRING DESCRIPTION` | performs path completion on STRING, giving them the description DESCRIPTION. -| `-n __fish_complete_groups` | prints a list of all user groups with the groups members as description. -| `-n __fish_complete_pids` | prints a list of all processes IDs with the command name as description. -| `-n __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_users` | prints a list of all users with their full name as description. -| `-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. -| `-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` | +## Functions -#### Example +### Defining and erasing ```fish -complete -c ruby -s X -x -a '(__fish_complete_directories (commandline -ct))' --description 'Directory' +function my_function --description "My description" + ··· +end ``` -### Examples +```fish +functions --erase my_function +``` -Start each example with `complete -c cmdname` +### Event handling ```fish --x - # no filename completion +function my_hook --on-event my_event + ··· +end ``` +## Events + +### Emitting + ```fish --s d -x -a "read skip" - # -d {read|skip} +emit my_event ``` + +## Abbreviations + +### Defining and erasing + ```fish --s d -x - # -d +abbr --add my_abbreviation echo "Hello from Fish!" ``` ```fish --s f -r - # -f FILE +abbr --erase my_abbreviation ``` +## Completions + +### Defining and erasing + ```fish --s f -l force - # -f, --force +complete --command mycommand --arguments 'install uninstall' +complete --command mycommand --short-option 'h' --long-option 'help' --description 'Display help' ``` ```fish --a "(cat /etc/passwd | cut -d : -f 1)" - # first argument as filename +complete --command mycommand --erase ``` + +| Option | Description | +| --- | --- | +| `--arguments` | Arguments to command itself or option | +| `--short-option` | Short option | +| `--long-option` | Long option | +| `--no-files` | Don't suggest files | +| `--force-files` | Suggest files | +| `--condition` | Display hint only when condition is true | +| `--description` | Description | +{: .-shortcuts} + +## Useful built-in functions + +| Condition | Description +| --- | --- +| `-n __fish_complete_directories STRING DESCRIPTION` | performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION. +| `-n __fish_complete_path STRING DESCRIPTION` | performs path completion on STRING, giving them the description DESCRIPTION. +| `-n __fish_complete_groups` | prints a list of all user groups with the groups members as description. +| `-n __fish_complete_pids` | prints a list of all processes IDs with the command name as description. +| `-n __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_users` | prints a list of all users with their full name as description. +| `-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. +| `-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` |