From b247c8d9ada92c4d039453a551b83cc0ff40724e Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 12 Feb 2019 19:43:09 -0600 Subject: [PATCH 001/191] Explicitly close input fd to `fish_title` `fish_title` as invoked by fish itself is not running in an interactive context, and attempts to read from the input fd (e.g. via `read`) cause fish to segfault, go into an infinite loop, or hang at the read prompt depending on the exact command line and fish version. This patch addresses that by explicitly closing the input fd when invoking `fish_title`. Reported by @floam in #5629. May close that issue, but situation is unclear. --- src/reader.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/reader.cpp b/src/reader.cpp index 34b0df044..413f6f660 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -829,6 +829,12 @@ void reader_write_title(const wcstring &cmd, bool reset_cursor_position) { fish_title_command.append( escape_string(cmd, ESCAPE_ALL | ESCAPE_NO_QUOTED | ESCAPE_NO_TILDE)); } + + // `fish_title` is executed in a non-interactive context and attempts at reading + // from within that function will cause problems ranging segfaults, SIGTTIN + // deadlocks, or infinite loops - we explicitly close the input fd to safeguard + // against such a scenario. + fish_title_command.append(L"<&-"); } wcstring_list_t lst; From 6e9250425aa2a062eb5ade1ff6119ab81605c490 Mon Sep 17 00:00:00 2001 From: Mrmaxmeier Date: Mon, 11 Feb 2019 17:10:42 +0100 Subject: [PATCH 002/191] src/exec: fix assertion on failed exec redirection Minimal reproducer: `fish -c "exec cat j) { if (j->processes.front()->type == INTERNAL_EXEC) { internal_exec(parser.vars(), j.get(), all_ios); - DIE("this should be unreachable"); + // internal_exec only returns if it failed to set up redirections. + // In case of an successful exec, this code is not reached. + bool status = j->get_flag(job_flag_t::NEGATE) ? 0 : 1; + proc_set_last_status(status); + return false; } // This loop loops over every process_t in the job, starting it as appropriate. This turns out diff --git a/tests/test_exec_fail.err b/tests/test_exec_fail.err new file mode 100644 index 000000000..6a3453fce --- /dev/null +++ b/tests/test_exec_fail.err @@ -0,0 +1,4 @@ + fish: An error occurred while redirecting file 'nosuchfile' +open: No such file or directory + fish: An error occurred while redirecting file 'nosuchfile' +open: No such file or directory diff --git a/tests/test_exec_fail.in b/tests/test_exec_fail.in new file mode 100644 index 000000000..08be53ef4 --- /dev/null +++ b/tests/test_exec_fail.in @@ -0,0 +1,6 @@ +exec cat < nosuchfile +echo "failed: $status" +not exec cat < nosuchfile +echo "neg failed: $status" +exec cat < /dev/null +echo "not reached" diff --git a/tests/test_exec_fail.out b/tests/test_exec_fail.out new file mode 100644 index 000000000..762ca2ce2 --- /dev/null +++ b/tests/test_exec_fail.out @@ -0,0 +1,2 @@ +failed: 1 +neg failed: 0 diff --git a/tests/test_exec_fail.status b/tests/test_exec_fail.status new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/tests/test_exec_fail.status @@ -0,0 +1 @@ +0 From 56309f1c2e8347bebfdc81c9f2660bd4607baf9f Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Mon, 11 Feb 2019 02:18:32 +0900 Subject: [PATCH 003/191] Only invoke path_helper in login shells Matches upstream path_helper which is invoked in /etc/profile and only applies to login shells. Enables running interactive, non-login shells with altered PATH values. Reverts change in c0f832a7, which reverts change in adbaddf. --- CHANGELOG.md | 1 + share/config.fish | 69 +++++++++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c260f80..c22802f5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - New color options for the pager have been added (#5524). - The default escape delay (to differentiate between the escape key and an alt-combination) has been reduced to 30ms, down from 300ms for the default mode and 100ms for vi-mode (#3904). - In the interest of consistency, `builtin -q` and `command -q` can now be used to query if a builtin or command exists (#5631). +- The `path_helper` on macOS now only runs in login shells, matching the bash implementation. --- diff --git a/share/config.fish b/share/config.fish index 7f701d2b4..2aeb4fc7d 100644 --- a/share/config.fish +++ b/share/config.fish @@ -161,47 +161,44 @@ if not set -q __fish_init_2_3_0 set -U __fish_init_2_3_0 end -# macOS-ism: Emulate calling path_helper. -if command -sq /usr/libexec/path_helper - # Adapt construct_path from the macOS /usr/libexec/path_helper - # executable for fish; see - # https://opensource.apple.com/source/shell_cmds/shell_cmds-203/path_helper/path_helper.c.auto.html . - function __fish_macos_set_env -d "set an environment variable like path_helper does (macOS only)" - set -l result - - for path_file in $argv[2] $argv[3]/* - if [ -f $path_file ] - while read -l entry - if not contains $entry $result - set -a result $entry - end - end <$path_file - end - end - - for entry in $$argv[1] - if not contains $entry $result - set result $result $entry - end - end - - set -xg $argv[1] $result - end - - __fish_macos_set_env 'PATH' '/etc/paths' '/etc/paths.d' - if [ -n "$MANPATH" ] - __fish_macos_set_env 'MANPATH' '/etc/manpaths' '/etc/manpaths.d' - end - functions -e __fish_macos_set_env -end - - # # Some things should only be done for login terminals # This used to be in etc/config.fish - keep it here to keep the semantics # - if status --is-login + if command -sq /usr/libexec/path_helper + # Adapt construct_path from the macOS /usr/libexec/path_helper + # executable for fish; see + # https://opensource.apple.com/source/shell_cmds/shell_cmds-203/path_helper/path_helper.c.auto.html . + function __fish_macos_set_env -d "set an environment variable like path_helper does (macOS only)" + set -l result + + for path_file in $argv[2] $argv[3]/* + if [ -f $path_file ] + while read -l entry + if not contains $entry $result + set -a result $entry + end + end <$path_file + end + end + + for entry in $$argv[1] + if not contains $entry $result + set result $result $entry + end + end + + set -xg $argv[1] $result + end + + __fish_macos_set_env 'PATH' '/etc/paths' '/etc/paths.d' + if [ -n "$MANPATH" ] + __fish_macos_set_env 'MANPATH' '/etc/manpaths' '/etc/manpaths.d' + end + functions -e __fish_macos_set_env + end + # # Put linux consoles in unicode mode. # From c5a6d0bfdef27c22e3293b50c1f2e568f8a1cc1f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 12:35:15 +0100 Subject: [PATCH 004/191] Split $fish_user_paths on ":" explicitly It's used with $PATH, so it is _always_ split on ":". We could also force it to be a path variable, but that seems a bit overkill. Fixes #5594. --- share/config.fish | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/share/config.fish b/share/config.fish index 2aeb4fc7d..e3b6b1bd4 100644 --- a/share/config.fish +++ b/share/config.fish @@ -102,7 +102,9 @@ function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" - set -g __fish_added_user_paths if set -q fish_user_paths - for x in $fish_user_paths[-1..1] + # Explicitly split on ":" because $fish_user_paths might not be a path variable, + # but $PATH definitely is. + for x in (string split ":" -- $fish_user_paths[-1..1]) if set -l idx (contains --index -- $x $local_path) set -e local_path[$idx] else From ca5b7c0ec429f4581a9a592c1801bba4a14cb7e9 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 12:54:19 +0100 Subject: [PATCH 005/191] math: Allow --scale=max --- CHANGELOG.md | 1 + doc_src/math.txt | 2 +- src/builtin_math.cpp | 15 ++++++++++----- tests/math.in | 1 + tests/math.out | 1 + 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c22802f5a..646bbe08c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - The default escape delay (to differentiate between the escape key and an alt-combination) has been reduced to 30ms, down from 300ms for the default mode and 100ms for vi-mode (#3904). - In the interest of consistency, `builtin -q` and `command -q` can now be used to query if a builtin or command exists (#5631). - The `path_helper` on macOS now only runs in login shells, matching the bash implementation. +- `math` now accepts `--scale=max` for the maximum scale (#5579). --- diff --git a/doc_src/math.txt b/doc_src/math.txt index 4a53f572a..566b561cd 100644 --- a/doc_src/math.txt +++ b/doc_src/math.txt @@ -17,7 +17,7 @@ Keep in mind that parameter expansion takes before expressions are evaluated. Th The following options are available: -- `-sN` or `--scale=N` sets the scale of the result. `N` must be an integer. A scale of zero causes results to be rounded down to the nearest integer. So `3/2` returns `1` rather than `2` which `1.5` would normally round to. This is for compatibility with `bc` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. +- `-sN` or `--scale=N` sets the scale of the result. `N` must be an integer or the word "max" for the maximum scale. A scale of zero causes results to be rounded down to the nearest integer. So `3/2` returns `1` rather than `2` which `1.5` would normally round to. This is for compatibility with `bc` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. \subsection return-values Return Values diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index 284e47a2b..506f80a5c 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -48,11 +48,16 @@ static int parse_cmd_opts(math_cmd_opts_t &opts, int *optind, //!OCLINT(high nc while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { case 's': { - opts.scale = fish_wcstoi(w.woptarg); - if (errno || opts.scale < 0 || opts.scale > 15) { - streams.err.append_format(_(L"%ls: '%ls' is not a valid scale value\n"), cmd, - w.woptarg); - return STATUS_INVALID_ARGS; + // "max" is the special value that tells us to pick the maximum scale. + if (wcscmp(w.woptarg, L"max") == 0) { + opts.scale = 15; + } else { + opts.scale = fish_wcstoi(w.woptarg); + if (errno || opts.scale < 0 || opts.scale > 15) { + streams.err.append_format(_(L"%ls: '%ls' is not a valid scale value\n"), cmd, + w.woptarg); + return STATUS_INVALID_ARGS; + } } break; } diff --git a/tests/math.in b/tests/math.in index 48c0afd44..2c92ee052 100644 --- a/tests/math.in +++ b/tests/math.in @@ -8,6 +8,7 @@ math '10 % 6' math -s0 '10 % 6' math '23 % 7' math --scale=6 '5 / 3 * 0.3' +math --scale=max '5 / 3' math "7^2" math -1 + 1 math '-2 * -2' diff --git a/tests/math.out b/tests/math.out index 1f385b54c..05aadc40a 100644 --- a/tests/math.out +++ b/tests/math.out @@ -10,6 +10,7 @@ 4 2 0.5 +1.666666666666667 49 0 4 From c62d95e42824dd6db7e88e4028ebeeeb6565b34e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 18 Jan 2019 22:50:38 +0100 Subject: [PATCH 006/191] tests: Move directory redirection test to invocation This tested #1728, where redirecting a directory (`begin; something; end < .`) would cause `status` to misbehave. Unfortunately, on Illumos/OpenIndiana/SunOS, this returns a different error (EINVAL instead of EISDIR), so we can't check that with our test harness, because we can't redirect it. Since it's not important that this gives the same error across systems (and indeed we provide no way of intercepting the error!), use an invocation test instead, because that allows different output per-uname. See #5472. --- tests/invocation/directory-redirect.err | 3 +++ tests/invocation/directory-redirect.err.SunOS | 3 +++ tests/invocation/directory-redirect.invoke | 1 + tests/status.err | 2 -- tests/status.in | 6 ------ 5 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 tests/invocation/directory-redirect.err create mode 100644 tests/invocation/directory-redirect.err.SunOS create mode 100644 tests/invocation/directory-redirect.invoke diff --git a/tests/invocation/directory-redirect.err b/tests/invocation/directory-redirect.err new file mode 100644 index 000000000..ed2330550 --- /dev/null +++ b/tests/invocation/directory-redirect.err @@ -0,0 +1,3 @@ + fish: An error occurred while redirecting file '.' +open: Is a directory +RC: 1 diff --git a/tests/invocation/directory-redirect.err.SunOS b/tests/invocation/directory-redirect.err.SunOS new file mode 100644 index 000000000..e3e6b2534 --- /dev/null +++ b/tests/invocation/directory-redirect.err.SunOS @@ -0,0 +1,3 @@ + fish: An error occurred while redirecting file '.' +open: Invalid argument +RC: 1 diff --git a/tests/invocation/directory-redirect.invoke b/tests/invocation/directory-redirect.invoke new file mode 100644 index 000000000..84a002bea --- /dev/null +++ b/tests/invocation/directory-redirect.invoke @@ -0,0 +1 @@ +-c 'begin; end > . ; status -b; and echo "status -b returned true after bad redirect on a begin block"' diff --git a/tests/status.err b/tests/status.err index 855655277..87e63a330 100644 --- a/tests/status.err +++ b/tests/status.err @@ -1,5 +1,3 @@ - fish: An error occurred while redirecting file '.' -open: Is a directory status: Invalid combination of options, you cannot do both 'is-interactive' and 'is-login' in the same invocation status: Invalid combination of options, diff --git a/tests/status.in b/tests/status.in index 008255027..9f33badd6 100644 --- a/tests/status.in +++ b/tests/status.in @@ -8,12 +8,6 @@ begin or echo '"status -b" unexpectedly returned false inside a begin block' end -# Issue #1728 -# Bad file redirection on a block causes `status --is-block` to return 0 forever. -begin; end >. # . is a directory, it can't be opened for writing -status -b -and echo '"status -b" unexpectedly returned true after bad redirect on a begin block' - status -l and echo '"status -l" unexpectedly returned true for a non-login shell' From 1ee57e92447781b5ff79aaa7c55f6468fc84a37d Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 18 Jan 2019 22:54:09 +0100 Subject: [PATCH 007/191] tests/realpath.in: We want to delete $PWD, darnit! Illumos/OpenIndiana/SunOS/Solaris has an rm/rmdir that tries to protect the user by not allowing them to delete $PWD. Normally, this would be a good thing as deleting $PWD is a stupid thing to do. Except in this case, we absolutely need to do that. So instead we weasel around it by invoking an sh to cd out of the directory to then invoke an `rmdir` to delete it. That should throw off any attempts at protection (we could also have tried $PWD/. or similar, but that's possibly still protected against). This is the last failing test on Illumos/OpenIndiana/SunOS/Solaris/afunnyquip, so: Fixes #5472. --- tests/realpath.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/realpath.in b/tests/realpath.in index fba895f15..fc39889fe 100644 --- a/tests/realpath.in +++ b/tests/realpath.in @@ -35,7 +35,9 @@ builtin realpath /def/// # Verify `realpath .` when cwd is a deleted directory gives a no such file or dir error. set -l tmpdir (mktemp -d) pushd $tmpdir -rmdir $tmpdir +# Solaris rmdir tries to protect against deleting $PWD. +# But that's what we want to test, so we weasel around it. +sh -c "cd ..; rmdir $tmpdir" builtin realpath . popd From 02ca7be416db8d83a62536acddb94d486d3633fe Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 18 Jan 2019 23:40:52 +0100 Subject: [PATCH 008/191] functions/_.fish: Use ggetext if available It turns out the default gettext on the sunny operating system with the many names interprets at least `\n` itself, so we'd end up swallowing it. This allows us to move past the interactive tests and onto the expect ones. See #5472. --- share/functions/_.fish | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/share/functions/_.fish b/share/functions/_.fish index 3c58a73bc..ee4e25b37 100644 --- a/share/functions/_.fish +++ b/share/functions/_.fish @@ -1,7 +1,16 @@ # # Alias for gettext or a fallback if gettext isn't installed. # -if command -sq gettext +# Use ggettext if available. +# This is the case on OpenIndiana, where the default gettext +# interprets `\n` itself, so +# printf (_ 'somemessage\n') +# won't print a newline. +if command -sq ggettext + function _ --description "Alias for the ggettext command" + command ggettext fish $argv + end +else if command -sq gettext function _ --description "Alias for the gettext command" command gettext fish $argv end From 75088653745506444e2c315737c5430ec1a4767e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 13:27:20 +0100 Subject: [PATCH 009/191] Include string.h where we use memset This is needed on Solaris/Illumos/OpenIndiana/SunOS. Presumably it's harmless elsewhere. --- src/io.cpp | 1 + src/iothread.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/io.cpp b/src/io.cpp index 713bc1432..7861d2845 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/src/iothread.cpp b/src/iothread.cpp index c19f69339..7aec8803e 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include From 3e2e44b673bbae2df8f490b94fbc85332dc02b83 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 13:28:13 +0100 Subject: [PATCH 010/191] output: One more unconst-cast for tputs Needed on Solaris/OpenIndiana/Illumos/SunOS. --- src/output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/output.cpp b/src/output.cpp index d0848b3e1..6003229ba 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -550,7 +550,7 @@ rgb_color_t parse_color(const env_var_t &var, bool is_background) { /// Write specified multibyte string. void writembs_check(const char *mbs, const char *mbs_name, bool critical, const char *file, long line) { if (mbs != NULL) { - tputs(mbs, 1, &writeb); + tputs((char *)mbs, 1, &writeb); } else if (critical) { auto term = env_stack_t::globals().get(L"TERM"); const wchar_t *fmt = From 84593e1519fe7392a0e967192cab7f0fba2d8eab Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 18 Jan 2019 23:55:36 +0100 Subject: [PATCH 011/191] tests/invocation: Remove `local` Instead this runs the `test_file` function in a subshell, which is the POSIXy way of doing this. Overly magic? Sure. Standard? Indeed. --- tests/invocation.sh | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/invocation.sh b/tests/invocation.sh index 4f1710c4a..e1f6a8ef2 100755 --- a/tests/invocation.sh +++ b/tests/invocation.sh @@ -147,23 +147,22 @@ filter() { ## # Actual testing of a .invoke file. -test_file() { - local file="$1" - local dir="$(dirname "$file")" - local base="$(basename "$file" .invoke)" - local test_config="${dir}/${base}.config" - local test_stdout="${dir}/${base}.tmp.out" - local test_stderr="${dir}/${base}.tmp.err" - local want_stdout="${dir}/${base}.out" - local grep_stdout="${dir}/${base}.grep" - local want_stderr="${dir}/${base}.err" - local empty="${dir}/${base}.empty" - local filter - local rc=0 - local test_args_literal - local test_args - local out_status=0 - local err_status=0 +test_file() ( + file="$1" + dir="$(dirname "$file")" + base="$(basename "$file" .invoke)" + test_config="${dir}/${base}.config" + test_stdout="${dir}/${base}.tmp.out" + test_stderr="${dir}/${base}.tmp.err" + want_stdout="${dir}/${base}.out" + grep_stdout="${dir}/${base}.grep" + want_stderr="${dir}/${base}.err" + empty="${dir}/${base}.empty" + rc=0 + test_args_literal= + test_args= + out_status=0 + err_status=0 # Literal arguments, for printing test_args_literal="$(cat "$file")" @@ -269,7 +268,7 @@ test_file() { fi return $rc -} +) ######################################################################## From c1d042051c7cb2f0ebfaf1164e0e575b1690c0c9 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 13:33:30 +0100 Subject: [PATCH 012/191] Disable directory redirect test On some systems, this sometimes uses unicode quotation marks. Not on mine, but on Travis it does. The only other workaround I can think of is setting locale to C, but that implies not being able to test anything unicode-related in the entire invocation tests. So for now disable this test. --- ...rectory-redirect.invoke => directory-redirect.invoke.disabled} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/invocation/{directory-redirect.invoke => directory-redirect.invoke.disabled} (100%) diff --git a/tests/invocation/directory-redirect.invoke b/tests/invocation/directory-redirect.invoke.disabled similarity index 100% rename from tests/invocation/directory-redirect.invoke rename to tests/invocation/directory-redirect.invoke.disabled From 2614deb13882520013243bb70ac6d70fd4301606 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 13:49:53 +0100 Subject: [PATCH 013/191] tests/invocation: Use ggrep if available We use grep -o here to filter output, but that's not available on OpenIndiana. It does offer "ggrep" though, which is GNU grep. --- tests/invocation.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/invocation.sh b/tests/invocation.sh index e1f6a8ef2..8ced43e4e 100755 --- a/tests/invocation.sh +++ b/tests/invocation.sh @@ -139,7 +139,13 @@ filter() { if [ -f "$1" ] ; then # grep '-o', '-E' and '-f' are supported by the tools in modern GNU # environments, and on OS X. - grep -oE -f "$1" + # + # But not on OpenIndiana/Illumos, so we use ggrep if available. + if command -v ggrep >/dev/null 2>&1; then + ggrep -oE -f "$1" + else + grep -oE -f "$1" + fi else cat fi From 556ddfa456a5c4fdeb25d61e7899c6702f329767 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 14:08:43 +0100 Subject: [PATCH 014/191] Include stdarg.h again This is needed on NetBSD, and should be harmless elsewhere. --- src/common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common.h b/src/common.h index 95dd176af..49fe0572d 100644 --- a/src/common.h +++ b/src/common.h @@ -5,6 +5,8 @@ #include #include +// Needed for va_list et al. +#include // IWYU pragma: keep #ifdef HAVE_SYS_IOCTL_H #include // IWYU pragma: keep #endif From fdc4246fff324260bcab4570ea6eb1371df45740 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 12 Dec 2018 13:47:29 +0100 Subject: [PATCH 015/191] Use builds.sr.ht Enable builds on builds.sr.ht for freebsd and arch, and alpine (which uses musl). All are built using cmake, as we want to drop the autotools build. --- .builds/alpine.yml | 23 +++++++++++++++++++++++ .builds/arch.yml | 21 +++++++++++++++++++++ .builds/freebsd.yml | 25 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 .builds/alpine.yml create mode 100644 .builds/arch.yml create mode 100644 .builds/freebsd.yml diff --git a/.builds/alpine.yml b/.builds/alpine.yml new file mode 100644 index 000000000..31ebbb364 --- /dev/null +++ b/.builds/alpine.yml @@ -0,0 +1,23 @@ +image: alpine/edge +packages: + - cmake + - ninja + - ncurses-dev + - pcre2-dev + - expect +sources: + - https://git.sr.ht/~faho/fish +tasks: + - build: | + cd fish + mkdir build || : + cd build + cmake -G Ninja .. \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_INSTALL_DATADIR=share \ + -DCMAKE_INSTALL_DOCDIR=share/doc/fish \ + -DCMAKE_INSTALL_SYSCONFDIR=/etc + ninja + - test: | + cd fish/build + env SHOW_INTERACTIVE_LOG=1 ninja test diff --git a/.builds/arch.yml b/.builds/arch.yml new file mode 100644 index 000000000..45fc2500f --- /dev/null +++ b/.builds/arch.yml @@ -0,0 +1,21 @@ +image: archlinux +packages: + - cmake + - ninja + - expect +sources: + - https://git.sr.ht/~faho/fish +tasks: + - build: | + cd fish + mkdir build || : + cd build + cmake -G Ninja .. \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_INSTALL_DATADIR=share \ + -DCMAKE_INSTALL_DOCDIR=share/doc/fish \ + -DCMAKE_INSTALL_SYSCONFDIR=/etc + ninja + - test: | + cd fish/build + env SHOW_INTERACTIVE_LOG=1 ninja test diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml new file mode 100644 index 000000000..c340a364c --- /dev/null +++ b/.builds/freebsd.yml @@ -0,0 +1,25 @@ +image: freebsd/latest +packages: + - ncurses + - gcc + - gettext + - expect + - cmake + - gmake + - pcre2 +sources: + - https://git.sr.ht/~faho/fish +tasks: + - build: | + cd fish + mkdir build || : + cd build + cmake .. \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_INSTALL_DATADIR=share \ + -DCMAKE_INSTALL_DOCDIR=share/doc/fish \ + -DCMAKE_INSTALL_SYSCONFDIR=/etc + gmake -j2 + - test: | + cd fish/build + gmake test SHOW_INTERACTIVE_LOG=1 From 4132bb1a19c73c5d3c9c4d0970096be5f03b78dd Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 13:56:36 +0100 Subject: [PATCH 016/191] gitattributes: Mark CI scripts export-ignore [ci skip] (ironically) --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitattributes b/.gitattributes index d440640bc..95bfe8cf0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18,6 +18,9 @@ /debian/* export-ignore /.github export-ignore /.github/* export-ignore +/.builds export-ignore +/.builds/* export-ignore +/.travis.yml export-ignore # for linguist; let github identify our project as C++ instead of C due to pcre2 /pcre2-10.32/ linguist-vendored From c0dc1870f07f61c306dd3a9276ff4a0a99b059c6 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 20:15:09 +0100 Subject: [PATCH 017/191] io: Return from read even if return == -1 and errno == 0 This happens on OpenIndiana/Solaris/Illumos/SunOS. Elsewhere we use read_blocked, which already returned in this case (and which we might want to use here as well!). --- src/io.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/io.cpp b/src/io.cpp index 7861d2845..6f72c3eb0 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -95,12 +95,17 @@ void io_buffer_t::run_background_fillthread(autoclose_fd_t readfd) { scoped_lock locker(append_lock_); ssize_t ret; do { + errno = 0; char buff[4096]; ret = read(fd, buff, sizeof buff); if (ret > 0) { buffer_.append(&buff[0], &buff[ret]); } else if (ret == 0) { shutdown = true; + } else if (ret == -1 && errno == 0) { + // No specific error. We assume we just return, + // since that's what we do in read_blocked. + return; } else if (errno != EINTR && errno != EAGAIN) { wperror(L"read"); return; From 4562f8f4e37bb4df2836b08d2b944e3a15846d86 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 20:32:07 +0100 Subject: [PATCH 018/191] fallback: Set LC_ALL in wcstod_l fallback Apparently some wcstod's don't care about LC_NUMERIC. --- src/fallback.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fallback.cpp b/src/fallback.cpp index a8d044d31..654eafc09 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -395,7 +395,12 @@ int flock(int fd, int op) { // thread-specific locale. double fish_compat::wcstod_l(const wchar_t *enptr, wchar_t **endptr, locale_t loc) { // Create and use a new, thread-specific locale - locale_t locale = newlocale(LC_NUMERIC, "C", nullptr); + // NOTE: We use "C" whatever the passed locale, + // and we use the LC_ALL category. + // + // Empirically, this fails on OpenIndiana/Illumos/Solaris/SunOS if using LC_NUMERIC. + // Since we reset it afterwards, it shouldn't matter. + locale_t locale = newlocale(LC_ALL, "C", nullptr); locale_t prev_locale = uselocale(locale); double ret = wcstod(enptr, endptr); // Restore the old locale before freeing the locale we created and are still using From 5607bc1396fb3238658336556587150f9613dad7 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Wed, 13 Feb 2019 13:33:12 -0800 Subject: [PATCH 019/191] Update .gitattributes --- .gitattributes | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index 95bfe8cf0..d508777e4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,6 +6,7 @@ # let git show off diff hunk headers, help git diff -L: # https://git-scm.com/docs/gitattributes *.cpp diff=cpp +*.h diff=cpp *.py diff=py # add a [diff "fish"] to git config with pattern *.fish diff=fish @@ -23,10 +24,9 @@ /.travis.yml export-ignore # for linguist; let github identify our project as C++ instead of C due to pcre2 -/pcre2-10.32/ linguist-vendored /pcre2-10.32/* linguist-vendored -/muparser-2.2.5/ linguist-vendored -/muparser-2.2.5/* linguist-vendored +/install-sh linguist-vendored +/m4/* linguist-vendored angular.js linguist-vendored /doc_src/* linguist-documentation *.fish linguist-language=fish From e707c530ee33ed9f7f115965d8897540c907d39f Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Wed, 13 Feb 2019 16:44:28 -0600 Subject: [PATCH 020/191] Add note about b247c8d9ada92c4d039453a551b83cc0ff40724e to CHANGELOG There isn't an issue explicitly associated with this, so it'll probably get lost. [ci skip] --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 646bbe08c..f28ee5c25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - The vcs-prompt functions have been renamed to names without double-underscore, so __fish_git_prompt is now fish_git_prompt, __fish_vcs_prompt is now fish_vcs_prompt, __fish_hg_prompt is now fish_hg_prompt and __fish_svn_prompt is now fish_svn_prompt. Shims at the old names have been added, and the variables have kept their old names (#5586). ## Notable fixes and improvements +- Fixed infinite recursion triggered if a custom `fish_title` function calls `read` interactively + ### Syntax changes and new commands - None yet. From 553bf47191bb25bfd99922eb77b372ff5bab193f Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Wed, 13 Feb 2019 20:55:19 -0600 Subject: [PATCH 021/191] Fix short arg -S for --shell Closes #5660 --- src/builtin_read.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 9c767664f..4c7895882 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -54,7 +54,7 @@ struct read_cmd_opts_t { bool one_line = false; }; -static const wchar_t *const short_options = L":ac:d:ghiLlm:n:p:suxzP:UR:LB"; +static const wchar_t *const short_options = L":ac:d:ghiLlm:n:p:sSuxzP:UR:LB"; static const struct woption long_options[] = { {L"array", no_argument, NULL, 'a'}, {L"command", required_argument, NULL, 'c'}, From f037b0f30fd4db0e27e3ffcd6a6923da4341ec4a Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 13 Feb 2019 22:31:54 +0100 Subject: [PATCH 022/191] fallback: Use passed locale in wcstod_l Strange idea, but it just might work. --- src/fallback.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/fallback.cpp b/src/fallback.cpp index 654eafc09..3f2912551 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -394,18 +394,9 @@ int flock(int fd, int op) { // For platforms without wcstod_l C extension, wrap wcstod after changing the // thread-specific locale. double fish_compat::wcstod_l(const wchar_t *enptr, wchar_t **endptr, locale_t loc) { - // Create and use a new, thread-specific locale - // NOTE: We use "C" whatever the passed locale, - // and we use the LC_ALL category. - // - // Empirically, this fails on OpenIndiana/Illumos/Solaris/SunOS if using LC_NUMERIC. - // Since we reset it afterwards, it shouldn't matter. - locale_t locale = newlocale(LC_ALL, "C", nullptr); - locale_t prev_locale = uselocale(locale); + locale_t prev_locale = uselocale(loc); double ret = wcstod(enptr, endptr); - // Restore the old locale before freeing the locale we created and are still using uselocale(prev_locale); - freelocale(locale); return ret; } #endif // defined(wcstod_l) From 5814b1b8e2bc34affb43aa87fa2982f8991c26f9 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 14 Feb 2019 10:55:41 +0100 Subject: [PATCH 023/191] Fix man function for NetBSD NetBSD's man is unusual in that it doesn't understand an empty $MANPATH component as "the system man path", and doesn't have a `manpath` or `man --path`. It has a `-m` option that would be useful, but other mans also have a `-m` option that isn't, so detecting it is tough. It does have a `-p` option that almost does what one would want here, so we hack around it to make things work. Fixes #5657. [ci skip] --- share/functions/man.fish | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/share/functions/man.fish b/share/functions/man.fish index 313121ddf..c466a1f64 100644 --- a/share/functions/man.fish +++ b/share/functions/man.fish @@ -12,6 +12,18 @@ function man --description "Format and display the on-line manual pages" set -l manpath if set -q MANPATH set manpath $MANPATH + else if set -l p (command man -p 2>/dev/null) + # NetBSD's man uses "-p" to print the path. + # FreeBSD's man also has a "-p" option, but that requires an argument. + # Other mans (men?) don't seem to have it. + # + # Unfortunately NetBSD prints things like "/usr/share/man/man1", + # while not allowing them as $MANPATH components. + # What it needs is just "/usr/share/man". + # + # So we strip the last component. + # This leaves a few wrong directories, but that should be harmless. + set manpath (string replace -r '[^/]+$' '' $p) else set manpath '' end From 13eb01bc97c6d55a953a837f54b6be7f4adbe030 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 14 Feb 2019 11:00:47 +0100 Subject: [PATCH 024/191] share/config: Guard contains against options Fixes #5662. [ci skip] --- share/config.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/config.fish b/share/config.fish index e3b6b1bd4..cbddad1a7 100644 --- a/share/config.fish +++ b/share/config.fish @@ -178,7 +178,7 @@ if status --is-login for path_file in $argv[2] $argv[3]/* if [ -f $path_file ] while read -l entry - if not contains $entry $result + if not contains -- $entry $result set -a result $entry end end <$path_file @@ -186,7 +186,7 @@ if status --is-login end for entry in $$argv[1] - if not contains $entry $result + if not contains -- $entry $result set result $result $entry end end From 8811a10690c7292965a4b9e93fdcc501ef7211c4 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Thu, 14 Feb 2019 02:47:12 -0800 Subject: [PATCH 025/191] Update .gitattributes --- .gitattributes | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index d508777e4..e3b679b63 100644 --- a/.gitattributes +++ b/.gitattributes @@ -25,7 +25,9 @@ # for linguist; let github identify our project as C++ instead of C due to pcre2 /pcre2-10.32/* linguist-vendored -/install-sh linguist-vendored +install-sh linguist-vendored +config.sub linguist-vendored +config.guess linguist-vendored /m4/* linguist-vendored angular.js linguist-vendored /doc_src/* linguist-documentation From 9796a331bca5082dd6cd7de67392eb0a9d62cc22 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 14 Feb 2019 17:53:07 -0600 Subject: [PATCH 026/191] Make WSL detection dynamic rather than statically compiled This resolves the issue where running pre-compiled Linux packages from binary package manager repositories lead fish to think that we are not running under WSL. - Closes #5619. - Ping neovim/neovim#7330 --- src/common.cpp | 31 +++++++++++++++++++++++++++++++ src/common.h | 14 +++----------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 5b8f628b0..d7935218b 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -31,6 +31,12 @@ #include #endif +#ifdef __linux__ +// Includes for WSL detection +#include +#include +#endif + #ifdef __FreeBSD__ #include #elif __APPLE__ @@ -148,6 +154,31 @@ long convert_hex_digit(wchar_t d) { return -1; } +bool is_windows_subsystem_for_linux() { +#if defined(WSL) + return true; +#elif not defined(__linux__) + return false; +#endif + + // We are purposely not using std::call_once as it may invoke locking, which is an unnecessary + // overhead since there's no actual race condition here - even if multiple threads call this + // routine simultaneously the first time around, we just end up needlessly querying uname(2) one + // more time. + + static bool wsl_state = []() { + utsname info; + uname(&info); + + // Sample utsname.release under WSL: 4.4.0-17763-Microsoft + return strstr(info.release, "Microsoft") != nullptr; + }(); + + // Subsequent calls to this function may take place after fork() and before exec() in + // postfork.cpp. Make sure we never dynamically allocate any memory in the fast path! + return wsl_state; +} + #ifdef HAVE_BACKTRACE_SYMBOLS // This function produces a stack backtrace with demangled function & method names. It is based on // https://gist.github.com/fmela/591333 but adapted to the style of the fish project. diff --git a/src/common.h b/src/common.h index 49fe0572d..1433ad151 100644 --- a/src/common.h +++ b/src/common.h @@ -866,18 +866,10 @@ void assert_is_not_forked_child(const char *who); #define ASSERT_IS_NOT_FORKED_CHILD_TRAMPOLINE(x) assert_is_not_forked_child(x) #define ASSERT_IS_NOT_FORKED_CHILD() ASSERT_IS_NOT_FORKED_CHILD_TRAMPOLINE(__FUNCTION__) -/// Detect if we are Windows Subsystem for Linux by inspecting /proc/sys/kernel/osrelease -/// and checking if "Microsoft" is in the first line. +/// Determines if we are running under Microsoft's Windows Subsystem for Linux to work around +/// some known limitations and/or bugs. /// See https://github.com/Microsoft/WSL/issues/423 and Microsoft/WSL#2997 -constexpr bool is_windows_subsystem_for_linux() { - // This function is called after fork() and before exec() in postfork.cpp. Make sure we - // don't allocate any memory here! -#ifdef WSL - return true; -#else - return false; -#endif -} +bool is_windows_subsystem_for_linux(); /// Detect if we are running under Cygwin or Cgywin64 constexpr bool is_cygwin() { From 552af31ab045b63aa7c3cbbad700528b304f75a2 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 14 Feb 2019 18:17:58 -0600 Subject: [PATCH 027/191] Emit warning when running under an unsupported version of WSL Closes #5661. Ping #5298. --- src/common.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/common.cpp b/src/common.cpp index d7935218b..93649e077 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -171,7 +171,17 @@ bool is_windows_subsystem_for_linux() { uname(&info); // Sample utsname.release under WSL: 4.4.0-17763-Microsoft - return strstr(info.release, "Microsoft") != nullptr; + if (strstr(info.release, "Microsoft") != nullptr) { + const char *dash = strchr(info.release, '-'); + if (dash == nullptr || strtod(dash + 1, nullptr) < 17763) { + debug(1, "This version of WSL is not supported and fish will probably not work correctly!\n" + "Please upgrade to Windows 10 1809 (17763) or higher to use fish!"); + } + + return true; + } else { + return false; + } }(); // Subsequent calls to this function may take place after fork() and before exec() in From 828a7042825c0baf746e28f1711191248709746f Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 14 Feb 2019 18:30:10 -0600 Subject: [PATCH 028/191] Fix is_wsl() #ifdef guards on non-Linux platforms --- src/common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 93649e077..2f140d79b 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -159,8 +159,7 @@ bool is_windows_subsystem_for_linux() { return true; #elif not defined(__linux__) return false; -#endif - +#else // We are purposely not using std::call_once as it may invoke locking, which is an unnecessary // overhead since there's no actual race condition here - even if multiple threads call this // routine simultaneously the first time around, we just end up needlessly querying uname(2) one @@ -187,6 +186,7 @@ bool is_windows_subsystem_for_linux() { // Subsequent calls to this function may take place after fork() and before exec() in // postfork.cpp. Make sure we never dynamically allocate any memory in the fast path! return wsl_state; +#endif } #ifdef HAVE_BACKTRACE_SYMBOLS From 619a248a3525b13ccd12f815cdb2d373e7372292 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Thu, 14 Feb 2019 17:01:28 -0800 Subject: [PATCH 029/191] Clean up uvar initialization with a wrapper function Adds __init_uvar --- share/config.fish | 1 + .../functions/__fish_config_interactive.fish | 68 +++++++++++-------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/share/config.fish b/share/config.fish index cbddad1a7..f6176361d 100644 --- a/share/config.fish +++ b/share/config.fish @@ -236,6 +236,7 @@ for jobbltn in bg fg wait disown builtin $jobbltn (__fish_expand_pid_args $argv) end end + function kill command kill (__fish_expand_pid_args $argv) end diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 42cead73f..c9683f2ee 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -35,53 +35,62 @@ function __fish_config_interactive -d "Initializations that should be performed set -g fish_greeting $fish_greeting.\n$line end + # usage: __init_uvar VARIABLE VALUES... + function __init_uvar -d "Sets a universal variable if it's not already set" + if not set --query --universal $argv[1] + set --universal $argv + end + end + # # If we are starting up for the first time, set various defaults. # # bump this to 2_4_0 when rolling release if anything changes after 9/10/2016 if not set -q __fish_init_2_39_8 + # Regular syntax highlighting colors - set -q fish_color_normal || set -U fish_color_normal normal - set -q fish_color_command || set -U fish_color_command 005fd7 - set -q fish_color_param || set -U fish_color_param 00afff - set -q fish_color_redirection || set -U fish_color_redirection 00afff - set -q fish_color_comment || set -U fish_color_comment 990000 - set -q fish_color_error || set -U fish_color_error ff0000 - set -q fish_color_escape || set -U fish_color_escape 00a6b2 - set -q fish_color_operator || set -U fish_color_operator 00a6b2 - set -q fish_color_end || set -U fish_color_end 009900 - set -q fish_color_quote || set -U fish_color_quote 999900 - set -q fish_color_autosuggestion || set -U fish_color_autosuggestion 555 brblack - set -q fish_color_user || set -U fish_color_user brgreen + __init_uvar fish_color_normal normal + __init_uvar fish_color_command 005fd7 + __init_uvar fish_color_param 00afff + __init_uvar fish_color_redirection 00afff + __init_uvar fish_color_comment 990000 + __init_uvar fish_color_error ff0000 + __init_uvar fish_color_escape 00a6b2 + __init_uvar fish_color_operator 00a6b2 + __init_uvar fish_color_end 009900 + __init_uvar fish_color_quote 999900 + __init_uvar fish_color_autosuggestion 555 brblack + __init_uvar fish_color_user brgreen - set -q fish_color_host || set -U fish_color_host normal - set -q fish_color_valid_path || set -U fish_color_valid_path --underline + __init_uvar fish_color_host normal + __init_uvar fish_color_valid_path --underline - set -q fish_color_cwd || set -U fish_color_cwd green - set -q fish_color_cwd_root || set -U fish_color_cwd_root red + __init_uvar fish_color_cwd green + __init_uvar fish_color_cwd_root red # Background color for matching quotes and parenthesis - set -q fish_color_match || set -U fish_color_match --background=brblue + __init_uvar fish_color_match --background=brblue # Background color for search matches - set -q fish_color_search_match || set -U fish_color_search_match bryellow --background=brblack + __init_uvar fish_color_search_match bryellow --background=brblack # Background color for selections - set -q fish_color_selection || set -U fish_color_selection white --bold --background=brblack + __init_uvar fish_color_selection white --bold --background=brblack - # XXX fish_color_cancel was added in 2.6, but this was added to post-2.3 initialization when 2.4 and 2.5 were already released - set -q fish_color_cancel || set -U fish_color_cancel -r + # XXX fish_color_cancel was added in 2.6, but this was added to post-2.3 initialization + # when 2.4 and 2.5 were already released + __init_uvar fish_color_cancel -r # Pager colors - set -q fish_pager_color_prefix || set -U fish_pager_color_prefix white --bold --underline - set -q fish_pager_color_completion || set -U fish_pager_color_completion - set -q fish_pager_color_description || set -U fish_pager_color_description B3A06D yellow - set -q fish_pager_color_progress || set -U fish_pager_color_progress brwhite --background=cyan + __init_uvar fish_pager_color_prefix white --bold --underline + __init_uvar fish_pager_color_completion + __init_uvar fish_pager_color_description B3A06D yellow + __init_uvar fish_pager_color_progress brwhite --background=cyan # # Directory history colors # - set -q fish_color_history_current || set -U fish_color_history_current --bold + __init_uvar fish_color_history_current --bold set -U __fish_init_2_39_8 end @@ -119,7 +128,8 @@ function __fish_config_interactive -d "Initializations that should be performed else # The greeting used to be skipped when fish_greeting was empty (not just undefined) # Keep it that way to not print superfluous newlines on old configuration - test -n "$fish_greeting" && echo $fish_greeting + test -n "$fish_greeting" + and echo $fish_greeting end end @@ -164,9 +174,7 @@ function __fish_config_interactive -d "Initializations that should be performed # Reload key bindings when binding variable change function __fish_reload_key_bindings -d "Reload key bindings when binding variable change" --on-variable fish_key_bindings # Make sure some key bindings are set - if not set -q fish_key_bindings - set -U fish_key_bindings fish_default_key_bindings - end + __init_uvar fish_key_bindings fish_default_key_bindings # Do nothing if the key bindings didn't actually change. # This could be because the variable was set to the existing value From f10c0dde3b7ca3fc6a8a0d684f7b8ae9c5d9b8d8 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Thu, 14 Feb 2019 21:42:42 -0800 Subject: [PATCH 030/191] __init_uvar: match previous behavior query for any set variable, not just universals, lest someone avoiding uvars intentionally has a problem. --- share/functions/__fish_config_interactive.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index c9683f2ee..23ec79d64 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -37,7 +37,7 @@ function __fish_config_interactive -d "Initializations that should be performed # usage: __init_uvar VARIABLE VALUES... function __init_uvar -d "Sets a universal variable if it's not already set" - if not set --query --universal $argv[1] + if not set --query $argv[1] set --universal $argv end end From 2a44517842531c64135d4a11daf6b072fc4f2c5d Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 15 Feb 2019 11:43:00 -0600 Subject: [PATCH 031/191] Update BSDmakefile formatting and add documentation --- BSDmakefile | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/BSDmakefile b/BSDmakefile index 25c23e754..5298a7866 100644 --- a/BSDmakefile +++ b/BSDmakefile @@ -1,15 +1,21 @@ -# by default bmake will cd into ./obj first +# This is a very basic `make` wrapper around the CMake build toolchain. +# +# Supported arguments: +# PREFIX: sets the installation prefix +# GENERATOR: explicitly specifies the CMake generator to use + +# By default, bmake will try to cd into ./obj before anything else. Don't do that. .OBJDIR: ./ +# Before anything else, test for CMake, which is the only requirement to be able to run +# this Makefile CMake will perform the remaining dependency tests on its own. .BEGIN: - # test for cmake, which is the only requirement to be able to run this Makefile - # cmake will perform the remaining dependency tests on its own - @which cmake >/dev/null 2>/dev/null || (echo 'Please install cmake and then re-run the `make` command!' 1>&2 && false) + @which cmake >/dev/null 2>/dev/null || \ + (echo 'Please install CMake and then re-run the `make` command!' 1>&2 && false) -# Use ninja, if it is installed -_GENERATOR!=which ninja 2>/dev/null >/dev/null && echo Ninja || echo "'Unix Makefiles'" +# Prefer to use ninja, if it is installed +_GENERATOR!=which ninja 2>/dev/null >/dev/null && echo Ninja || echo "Unix Makefiles" GENERATOR?=$(_GENERATOR) -PREFIX?=/usr/local .if $(GENERATOR) == "Ninja" BUILDFILE=build/build.ninja @@ -17,7 +23,8 @@ BUILDFILE=build/build.ninja BUILDFILE=build/Makefile .endif -.DEFAULT: build/fish +PREFIX?=/usr/local + build/fish: build/$(BUILDFILE) cmake --build build @@ -25,7 +32,7 @@ build: mkdir -p build build/$(BUILDFILE): build - cd build; cmake .. -G $(GENERATOR) -DCMAKE_INSTALL_PREFIX=$(PREFIX) -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + cd build; cmake .. -G "$(GENERATOR)" -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .PHONY: install install: build/fish From 0f6720ef8e66a5c8a97787ae420d1dd48be9f123 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 15 Feb 2019 11:44:01 -0600 Subject: [PATCH 032/191] Allow override of `cmake` binary in BSDmakefile --- BSDmakefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/BSDmakefile b/BSDmakefile index 5298a7866..85f5ee162 100644 --- a/BSDmakefile +++ b/BSDmakefile @@ -7,10 +7,12 @@ # By default, bmake will try to cd into ./obj before anything else. Don't do that. .OBJDIR: ./ +CMAKE?=cmake + # Before anything else, test for CMake, which is the only requirement to be able to run # this Makefile CMake will perform the remaining dependency tests on its own. .BEGIN: - @which cmake >/dev/null 2>/dev/null || \ + @which $(CMAKE) >/dev/null 2>/dev/null || \ (echo 'Please install CMake and then re-run the `make` command!' 1>&2 && false) # Prefer to use ninja, if it is installed @@ -26,17 +28,17 @@ BUILDFILE=build/Makefile PREFIX?=/usr/local build/fish: build/$(BUILDFILE) - cmake --build build + $(CMAKE) --build build build: mkdir -p build build/$(BUILDFILE): build - cd build; cmake .. -G "$(GENERATOR)" -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + cd build; $(CMAKE) .. -G "$(GENERATOR)" -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .PHONY: install install: build/fish - cmake --build build --target install + $(CMAKE) --build build --target install .PHONY: clean clean: @@ -44,7 +46,7 @@ clean: .PHONY: test test: build/fish - cmake --build build --target test + $(CMAKE) --build build --target test .PHONY: run run: build/fish From f75fe823b8bc7fee31a20d27d3945652092cada6 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Feb 2019 01:20:08 -0800 Subject: [PATCH 033/191] Minor cleanup of process_t --- src/proc.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/proc.h b/src/proc.h index 1620e4e5b..6950a7031 100644 --- a/src/proc.h +++ b/src/proc.h @@ -68,13 +68,13 @@ class process_t { io_chain_t process_io_chain; // No copying. - process_t(const process_t &rhs); - void operator=(const process_t &rhs); + process_t(const process_t &rhs) = delete; + void operator=(const process_t &rhs) = delete; public: process_t(); - // Note whether we are the first and/or last in the job + /// Note whether we are the first and/or last in the job bool is_first_in_job{false}; bool is_last_in_job{false}; @@ -119,13 +119,11 @@ class process_t { /// File descriptor that pipe output should bind to. int pipe_write_fd{0}; /// True if process has completed. - volatile int completed{false}; + volatile bool completed{false}; /// True if process has stopped. - volatile int stopped{false}; + volatile bool stopped{false}; /// Reported status value. volatile int status{0}; - /// Special flag to tell the evaluation function for count to print the help information. - int count_help_magic{0}; #ifdef HAVE__PROC_SELF_STAT /// Last time of cpu time check. struct timeval last_time {}; From b6b7550477657f53009bfed9949f44f901d52f4f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Feb 2019 02:30:21 -0800 Subject: [PATCH 034/191] Restyle redirection.h --- src/redirection.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/redirection.h b/src/redirection.h index 3f1902e8a..64fd60043 100644 --- a/src/redirection.h +++ b/src/redirection.h @@ -2,8 +2,8 @@ #define FISH_REDIRECTION_H #include "common.h" -#include "maybe.h" #include "io.h" +#include "maybe.h" #include @@ -43,7 +43,7 @@ class dup2_list_t { dup2_list_t() = default; -public: + public: ~dup2_list_t(); /// Disable copying because we own our fds. From dbeaa0c8de4f25e6a72a215abc8d4fa0c117c967 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 16 Feb 2019 16:36:06 +0100 Subject: [PATCH 035/191] Add curl completion Mostly copying the autogenerated stuff with some light description cleanup. Fixes #5664. [ci skip] --- share/completions/curl.fish | 238 +++++++++++++++++++++++++++++++++++- 1 file changed, 233 insertions(+), 5 deletions(-) diff --git a/share/completions/curl.fish b/share/completions/curl.fish index 1100e4c29..b8767ec97 100644 --- a/share/completions/curl.fish +++ b/share/completions/curl.fish @@ -1,6 +1,234 @@ -# mqudsi: Given the size and scope of curl's arguments, I don't have the time -# to add proper completions, but want to enable path completion for data file -# parameters, which allow specifying the path to a payload to upload as @path, -# which fish won't complete otherwise. - complete -c curl -n 'string match -qr "^@" -- (commandline -ct)' -xa "(printf '%s\n' -- @(__fish_complete_suffix (commandline -ct | string replace -r '^@' '') ''))" + +# These based on the autogenerated completions. +complete -c curl -l abstract-unix-socket -d '(HTTP) Connect through an abstract Unix domain socket, instead of using the n…' +complete -c curl -l anyauth -d '(HTTP) Use most secure authentication method automatically' +complete -c curl -s a -l append -d '(FTP SFTP) Upload: append to the target file' +complete -c curl -l basic -d '(HTTP) Use HTTP Basic authentication' +complete -c curl -l cacert -d '(TLS) Use the specified certificate file' +complete -c curl -l capath -d '(TLS) Use the specified certificate directory' +complete -c curl -l cert-status -d '(TLS) Use Certificate Status Request (aka OCSP stapling)' +complete -c curl -l cert-type -d '(TLS) Set type of the provided client certificate' -a 'PEM, DER ENG P12' +complete -c curl -s E -l cert -d '(TLS) Use this cert' +complete -c curl -l ciphers -d '(TLS) Specifies which ciphers to use' +complete -c curl -l compressed-ssh -d '(SCP SFTP) Enables built-in SSH compression' +complete -c curl -l compressed -d '(HTTP) Request a compressed response' +complete -c curl -s K -l config -d 'Specify a text file to read curl arguments from' +complete -c curl -l connect-timeout -d 'Maximum time in seconds you allow connection to take' +complete -c curl -l connect-to -d 'For a request to the given HOST1:PORT1 pair, connect to HOST2:PORT2 instead' +complete -c curl -s C -l continue-at -d 'Continue/Resume a previous file transfer at the given offset' +complete -c curl -s c -l cookie-jar -d '(HTTP) Write all cookies to this file' +complete -c curl -s b -l cookie -d '(HTTP) Pass the data to the HTTP server in the Cookie header' +complete -c curl -l create-dirs -d 'Create dirs for -o/--output' +complete -c curl -l crlf -d '(FTP SMTP) Convert LF to CRLF in upload. Useful for MVS (OS/390)' +complete -c curl -l crlfile -d '(TLS) Provide a file using PEM format with a Certificate Revocation List' +complete -c curl -l data-ascii -d '(HTTP) Alias for -d, --data' +complete -c curl -l data-binary -d '(HTTP) Post data exactly as specified with no processing' +complete -c curl -l data-raw -d '(HTTP) Post data like --data but without interpeting "@"' +complete -c curl -l data-urlencode -d '(HTTP) Post data URL-encoded' +complete -c curl -s d -l data -d '(HTTP) Sends the specified data in a POST request to the HTTP server' +complete -c curl -l delegation -d '(GSS/kerberos) Tell the server how much it can delegate for user creds' -xa '( +printf %s\t%s\n \ +none "Don\'t allow any delegation" \ +policy "Delegate only if the OK-AS-DELEGATE flag is set in the Kerberos service ticket" \ +always "Allow the server to delegate")' +complete -c curl -l digest -d '(HTTP) Enables HTTP Digest authentication' +complete -c curl -l disable-eprt -d '(FTP) Don\'t use EPRT and LPRT commands in active FTP' +complete -c curl -l disable-epsv -d '(FTP) Don\'t use EPSV in passive FTP' +complete -c curl -s q -l disable -d 'Disable curlrc' +complete -c curl -l disallow-username-in-url -d '(HTTP) Exit if passed a url containing a username' +complete -c curl -l dns-interface -d '(DNS) Send outgoing DNS requests through ' +complete -c curl -l dns-ipv4-addr -d '(DNS) Bind to when making IPv4 DNS requests' +complete -c curl -l dns-ipv6-addr -d '(DNS) Bind to when making IPv6 DNS requests' +complete -c curl -l dns-servers -d 'Set the list of DNS servers to be used instead of the system default' +complete -c curl -l doh-url -d '(all) Specifies which DNS-over-HTTPS (DOH) server to use to resolve hostnames' +complete -c curl -s D -l dump-header -d '(HTTP FTP) Write the received protocol headers to the specified file' +complete -c curl -l egd-file -d '(TLS) Specify the path name to the Entropy Gathering Daemon socket' +complete -c curl -l engine -d '(TLS) Select the OpenSSL crypto engine to use for cipher operations' +complete -c curl -l expect100-timeout -d '(HTTP) Maximum time in seconds to wait for a 100-continue' +complete -c curl -l fail-early -d 'Fail and exit on the first detected transfer error' +complete -c curl -s f -l fail -d '(HTTP) Fail silently (no output at all) on server errors' +complete -c curl -l false-start -d '(TLS) Tells curl to use false start during the TLS handshake' +complete -c curl -l form-string -d '(HTTP SMTP IMAP) Similar to -F, --form except that the value string for the n…' +complete -c curl -s F -l form -d '(HTTP SMTP IMAP) For HTTP protocol family, this lets curl emulate a filled-in…' +complete -c curl -l ftp-account -d '(FTP) Data for the ACCT command' +complete -c curl -l ftp-alternative-to-user -d '(FTP) If USER and PASS commands fail, send this command' +complete -c curl -l ftp-create-dirs -d '(FTP SFTP) Create missing dirs with ftp' +complete -c curl -l ftp-method -d '(FTP) Control what method curl should use to reach a file on an FTP(S) server' +complete -c curl -l ftp-pasv -d '(FTP) Use passive mode for the data connection' +complete -c curl -s P -l ftp-port -d '(FTP) Reverses the default initiator/listener roles when connecting with FTP' +complete -c curl -l ftp-pret -d '(FTP) Tell curl to send a PRET command before PASV (and EPSV)' +complete -c curl -l ftp-skip-pasv-ip -d '(FTP) Tell curl to not use the IP address the server suggests in its response…' +complete -c curl -l ftp-ssl-ccc-mode -d '(FTP) Sets the CCC mode' +complete -c curl -l ftp-ssl-ccc -d '(FTP) Use CCC (Clear Command Channel) Shuts down the SSL/TLS layer after auth…' +complete -c curl -l ftp-ssl-control -d '(FTP) Require SSL/TLS for the FTP login, clear for transfer' +complete -c curl -s G -l get -d 'When used, this option will make all data specified with -d, --data, --data-b…' +complete -c curl -s g -l globoff -d 'This option switches off the "URL globbing parser"' +complete -c curl -l happy-eyeballs-timeout-ms -d 'Happy eyeballs is an algorithm that attempts to connect to both IPv4 and IPv6…' +complete -c curl -l haproxy-protocol -d '(HTTP) Send a HAProxy PROXY protocol v1 header at the beginning of the connec…' +complete -c curl -s I -l head -d '(HTTP FTP FILE) Fetch the headers only! HTTP-servers feature the command HEAD…' +complete -c curl -s H -l header -d '(HTTP) Extra header to include in the request when sending HTTP to a server' +complete -c curl -s h -l help -d 'Usage help' +complete -c curl -l hostpubmd5 -d '(SFTP SCP) Pass a string containing 32 hexadecimal digits' +complete -c curl -l 'http0.9' -d '(HTTP) Tells curl to be fine with HTTP version 0. 9 response. HTTP/0' +complete -c curl -s 0 -l 'http1.0' -d '(HTTP) Tells curl to use HTTP version 1' +complete -c curl -l 'http1.1' -d '(HTTP) Tells curl to use HTTP version 1. 1' +complete -c curl -l http2-prior-knowledge -d '(HTTP) Tells curl to issue its non-TLS HTTP requests using HTTP/2 without HTT…' +complete -c curl -l http2 -d '(HTTP) Tells curl to use HTTP version 2. See also --no-alpn' +complete -c curl -l ignore-content-length -d '(FTP HTTP) For HTTP, Ignore the Content-Length header' +complete -c curl -s i -l include -d 'Include the HTTP response headers in the output' +complete -c curl -s k -l insecure -d '(TLS) By default, every SSL connection curl makes is verified to be secure' +complete -c curl -l interface -d 'Perform an operation using a specified interface' +complete -c curl -s 4 -l ipv4 -d 'This option tells curl to resolve names to IPv4 addresses only, and not for e…' +complete -c curl -s 6 -l ipv6 -d 'This option tells curl to resolve names to IPv6 addresses only, and not for e…' +complete -c curl -s j -l junk-session-cookies -d '(HTTP) When curl is told to read cookies from a given file, this option will …' +complete -c curl -l keepalive-time -d 'This option sets the time a connection needs to remain idle before sending ke…' +complete -c curl -l key-type -d '(TLS) Private key file type' +complete -c curl -l key -d '(TLS SSH) Private key file name' +complete -c curl -l krb -d '(FTP) Enable Kerberos authentication and use' +complete -c curl -l libcurl -d 'Append this option to any ordinary curl command line, and you will get a libc…' +complete -c curl -l limit-rate -d 'Specify the maximum transfer rate you want curl to use - for both downloads a…' +complete -c curl -s l -l list-only -d '(FTP POP3) (FTP) When listing an FTP directory, this switch forces a name-onl…' +complete -c curl -l local-port -d 'Set a preferred single number or range (FROM-TO) of local port numbers to use…' +complete -c curl -l location-trusted -d '(HTTP) Like -L, --location, but will allow sending the name + password to all…' +complete -c curl -s L -l location -d '(HTTP) Follow redirects' +complete -c curl -l login-options -d '(IMAP POP3 SMTP) Specify the login options' +complete -c curl -l mail-auth -d '(SMTP) Specify a single address' +complete -c curl -l mail-from -d '(SMTP) Specify a single address that the given mail should get sent from' +complete -c curl -l mail-rcpt -d '(SMTP) Specify a single address, user name or mailing list name' +complete -c curl -s M -l manual -d 'Manual. Display the huge help text' +complete -c curl -l max-filesize -d 'Specify the maximum size (in bytes) of a file to download' +complete -c curl -l max-redirs -d '(HTTP) Set maximum number of redirection-followings allowed' +complete -c curl -s m -l max-time -d 'Maximum time in seconds that you allow the whole operation to take' +complete -c curl -l metalink -d 'This option can tell curl to parse and process a given URI as Metalink file (…' +complete -c curl -l negotiate -d '(HTTP) Enables Negotiate (SPNEGO) authentication' +complete -c curl -l netrc-file -d 'This option is similar to -n, --netrc, except that you provide the path (abso…' +complete -c curl -l netrc-optional -d 'Very similar to -n, --netrc, but this option makes the ' +complete -c curl -s n -l netrc -d 'Makes curl scan the ' +complete -c curl -l next -d 'Tells curl to use a separate operation for the following URL and associated o…' +complete -c curl -l no-alpn -d '(HTTPS) Disable the ALPN TLS extension' +complete -c curl -s N -l no-buffer -d 'Disables the buffering of the output stream' +complete -c curl -l no-keepalive -d 'Disables the use of keepalive messages on the TCP connection' +complete -c curl -l no-npn -d '(HTTPS) Disable the NPN TLS extension' +complete -c curl -l no-sessionid -d '(TLS) Disable curl\'s use of SSL session-ID caching' +complete -c curl -l noproxy -d 'Comma-separated list of hosts which do not use a proxy, if one is specified' +complete -c curl -l ntlm-wb -d '(HTTP) Enables NTLM much in the style --ntlm does, but hand over the authenti…' +complete -c curl -l ntlm -d '(HTTP) Enables NTLM authentication' +complete -c curl -l oauth2-bearer -d '(IMAP POP3 SMTP) Specify the Bearer Token for OAUTH 2' +complete -c curl -s o -l output -d 'Write output to instead of stdout' +complete -c curl -l pass -d '(SSH TLS) Passphrase for the private key If this option is used several time…' +complete -c curl -l path-as-is -d 'Tell curl to not handle sequences of /. / or /. / in the given URL path' +complete -c curl -l pinnedpubkey -d '(TLS) Tells curl to use the specified public key file (or hashes) to verify t…' +complete -c curl -l post301 -d '(HTTP) Tells curl to respect RFC 7231/6. 4' +complete -c curl -l post302 -d '(HTTP) Tells curl to respect RFC 7231/6. 4' +complete -c curl -l post303 -d '(HTTP) Tells curl to violate RFC 7231/6. 4' +complete -c curl -l preproxy -d 'Use the specified SOCKS proxy before connecting to an HTTP or HTTPS -x, --pro…' +complete -c curl -s '#' -l progress-bar -d 'Make curl display transfer progress as a simple progress bar instead of the s…' +complete -c curl -l proto-default -d 'Tells curl to use protocol for any URL missing a scheme name' +complete -c curl -l proto-redir -d 'Tells curl to limit what protocols it may use on redirect' +complete -c curl -l proto -d 'Tells curl to limit what protocols it may use in the transfer' +complete -c curl -o ftps -d 'uses the default protocols, but disables ftps' +complete -c curl -o all -d 'only enables http and https' +complete -c curl -l proxy-anyauth -d 'Tells curl to pick a suitable authentication method when communicating with t…' +complete -c curl -l proxy-basic -d 'Tells curl to use HTTP Basic authentication when communicating with the given…' +complete -c curl -l proxy-cacert -d 'Same as --cacert but used in HTTPS proxy context' +complete -c curl -l proxy-capath -d 'Same as --capath but used in HTTPS proxy context' +complete -c curl -l proxy-cert-type -d 'Same as --cert-type but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-cert -d 'Same as -E, --cert but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-ciphers -d 'Same as --ciphers but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-crlfile -d 'Same as --crlfile but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-digest -d 'Tells curl to use HTTP Digest authentication when communicating with the give…' +complete -c curl -l proxy-header -d '(HTTP) Extra header to include in the request when sending HTTP to a proxy' +complete -c curl -l proxy-insecure -d 'Same as -k, --insecure but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-key-type -d 'Same as --key-type but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-key -d 'Same as --key but used in HTTPS proxy context' +complete -c curl -l proxy-negotiate -d 'Tells curl to use HTTP Negotiate (SPNEGO) authentication when communicating w…' +complete -c curl -l proxy-ntlm -d 'Tells curl to use HTTP NTLM authentication when communicating with the given …' +complete -c curl -l proxy-pass -d 'Same as --pass but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-pinnedpubkey -d '(TLS) Tells curl to use the specified public key file (or hashes) to verify t…' +complete -c curl -l proxy-service-name -d 'This option allows you to change the service name for proxy negotiation' +complete -c curl -l proxy-ssl-allow-beast -d 'Same as --ssl-allow-beast but used in HTTPS proxy context. Added in 7. 52' +complete -c curl -l proxy-tls13-ciphers -d '(TLS) Specifies which cipher suites to use in the connection to your HTTPS pr…' +complete -c curl -l proxy-tlsauthtype -d 'Same as --tlsauthtype but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-tlspassword -d 'Same as --tlspassword but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-tlsuser -d 'Same as --tlsuser but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -l proxy-tlsv1 -d 'Same as -1, --tlsv1 but used in HTTPS proxy context. Added in 7. 52. 0' +complete -c curl -s U -l proxy-user -d 'Specify the user name and password to use for proxy authentication' +complete -c curl -s x -l proxy -d 'Use the specified proxy' +complete -c curl -l 'proxy1.0' -d 'Use the specified HTTP 1. 0 proxy' +complete -c curl -s p -l proxytunnel -d 'When an HTTP proxy is used -x, --proxy, this option will cause non-HTTP proto…' +complete -c curl -l pubkey -d '(SFTP SCP) Public key file name' +complete -c curl -s Q -l quote -d '(FTP SFTP) Send an arbitrary command to the remote FTP or SFTP server' +complete -c curl -l random-file -d 'Specify the path name to file containing what will be considered as random da…' +complete -c curl -s r -l range -d '(HTTP FTP SFTP FILE) Retrieve a byte range (i. e' +complete -c curl -o 500 -d 'specifies the last 500 bytes' +complete -c curl -s 1 -d 'specifies the first and last byte only(*)(HTTP)' +complete -c curl -l raw -d '(HTTP) When used, it disables all internal HTTP decoding of content or transf…' +complete -c curl -s e -l referer -d '(HTTP) Sends the "Referrer Page" information to the HTTP server' +complete -c curl -s J -l remote-header-name -d '(HTTP) This option tells the -O, --remote-name option to use the server-speci…' +complete -c curl -l remote-name-all -d 'This option changes the default action for all given URLs to be dealt with as…' +complete -c curl -s O -l remote-name -d 'Write output to a local file named like the remote file we get' +complete -c curl -s R -l remote-time -d 'When used, this will make curl attempt to figure out the timestamp of the rem…' +complete -c curl -l request-target -d '(HTTP) Tells curl to use an alternative "target" (path) instead of using the …' +complete -c curl -s X -l request -d '(HTTP) Specifies a custom request method to use when communicating with the H…' +complete -c curl -l resolve -d 'Provide a custom address for a specific host and port pair' +complete -c curl -l retry-connrefused -d 'In addition to the other conditions, consider ECONNREFUSED as a transient err…' +complete -c curl -l retry-delay -d 'Make curl sleep this amount of time before each retry when a transfer has fai…' +complete -c curl -l retry-max-time -d 'The retry timer is reset before the first transfer attempt' +complete -c curl -l retry -d 'If a transient error is returned when curl tries to perform a transfer, it wi…' +complete -c curl -l sasl-ir -d 'Enable initial response in SASL authentication. Added in 7. 31. 0' +complete -c curl -l service-name -d 'This option allows you to change the service name for SPNEGO' +complete -c curl -s S -l show-error -d 'When used with -s, --silent, it makes curl show an error message if it fails' +complete -c curl -s s -l silent -d 'Silent or quiet mode. Don\'t show progress meter or error messages' +complete -c curl -l socks4 -d 'Use the specified SOCKS4 proxy' +complete -c curl -l socks4a -d 'Use the specified SOCKS4a proxy' +complete -c curl -l socks5-basic -d 'Tells curl to use username/password authentication when connecting to a SOCKS…' +complete -c curl -l socks5-gssapi-nec -d 'As part of the GSS-API negotiation a protection mode is negotiated' +complete -c curl -l socks5-gssapi-service -d 'The default service name for a socks server is rcmd/server-fqdn' +complete -c curl -l socks5-gssapi -d 'Tells curl to use GSS-API authentication when connecting to a SOCKS5 proxy' +complete -c curl -l socks5-hostname -d 'Use the specified SOCKS5 proxy (and let the proxy resolve the host name)' +complete -c curl -l socks5 -d 'Use the specified SOCKS5 proxy - but resolve the host name locally' +complete -c curl -s Y -l speed-limit -d 'If a download is slower than this given speed (in bytes per second) for speed…' +complete -c curl -s y -l speed-time -d 'If a download is slower than speed-limit bytes per second during a speed-time…' +complete -c curl -l ssl-allow-beast -d 'This option tells curl to not work around a security flaw in the SSL3 and TLS…' +complete -c curl -l ssl-no-revoke -d '(Schannel) This option tells curl to disable certificate revocation checks' +complete -c curl -l ssl-reqd -d '(FTP IMAP POP3 SMTP) Require SSL/TLS for the connection' +complete -c curl -l ssl -d '(FTP IMAP POP3 SMTP) Try to use SSL/TLS for the connection' +complete -c curl -s 2 -l sslv2 -d '(SSL) Forces curl to use SSL version 2 when negotiating with a remote SSL ser…' +complete -c curl -s 3 -l sslv3 -d '(SSL) Forces curl to use SSL version 3 when negotiating with a remote SSL ser…' +complete -c curl -l stderr -d 'Redirect all writes to stderr to the specified file instead' +complete -c curl -l styled-output -d 'Enables the automatic use of bold font styles when writing HTTP headers to th…' +complete -c curl -l suppress-connect-headers -d 'When -p, --proxytunnel is used and a CONNECT request is made don\'t output pro…' +complete -c curl -l tcp-fastopen -d 'Enable use of TCP Fast Open (RFC7413). Added in 7. 49. 0' +complete -c curl -l tcp-nodelay -d 'Turn on the TCP_NODELAY option' +complete -c curl -s t -l telnet-option -d 'Pass options to the telnet protocol' +complete -c curl -l tftp-blksize -d '(TFTP) Set TFTP BLKSIZE option (must be >512)' +complete -c curl -l tftp-no-options -d '(TFTP) Tells curl not to send TFTP options requests' +complete -c curl -s z -l time-cond -d '(HTTP FTP) Request a file that has been modified later than the given time an…' +complete -c curl -l tls-max -d '(SSL) VERSION defines maximum supported TLS version' +complete -c curl -l tls13-ciphers -d '(TLS) Specifies which cipher suites to use in the connection if it negotiates…' +complete -c curl -l tlsauthtype -d 'Set TLS authentication type' +complete -c curl -l tlspassword -d 'Set password for use with the TLS authentication method' +complete -c curl -l tlsuser -d 'Set username for use with the TLS authentication method' +complete -c curl -l 'tlsv1.0' -d '(TLS) Forces curl to use TLS version 1.0' +complete -c curl -l 'tlsv1.1' -d '(TLS) Forces curl to use TLS version 1.1' +complete -c curl -l 'tlsv1.2' -d '(TLS) Forces curl to use TLS version 1.2' +complete -c curl -l 'tlsv1.3' -d '(TLS) Forces curl to use TLS version 1.3' +complete -c curl -l tlsv1 -d '(SSL) Tells curl to use at least TLS version 1' +complete -c curl -l tr-encoding -d '(HTTP) Request a compressed Transfer-Encoding response using one of the algor…' +complete -c curl -l trace-ascii -d 'Enables a full trace dump of all incoming and outgoing data' +complete -c curl -l trace-time -d 'Prepends a time stamp to each trace or verbose line that curl displays' +complete -c curl -l trace -d 'Enables a full trace dump of all incoming and outgoing data' +complete -c curl -l unix-socket -d '(HTTP) Connect through this Unix domain socket, instead of using the network' +complete -c curl -s T -l upload-file -d 'This transfers the specified local file to the remote URL' +complete -c curl -l url -d 'Specify a URL to fetch' +complete -c curl -s B -l use-ascii -d '(FTP LDAP) Enable ASCII transfer' +complete -c curl -s A -l user-agent -d '(HTTP) Specify the User-Agent string to send to the HTTP server' +complete -c curl -s u -l user -d 'Specify the user name and password to use for server authentication' +complete -c curl -s v -l verbose -d 'Makes curl verbose during the operation' +complete -c curl -s V -l version -d 'Displays information about curl and the libcurl version it uses' +complete -c curl -s w -l write-out -d 'Make curl display information on stdout after a completed transfer' +complete -c curl -l eprt -l no-eprt -d 'for --disable-eprt' +complete -c curl -l epsv -l no-epsv -d 'for --disable-epsv' +complete -c curl -l max-redir -d 'Set maximum number of redirects' +complete -c curl -l xattr -d 'Store metadata in xattrs (like origin URL)' From fdbbe9f69dc1558edb80597763ea58e73598cd27 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 16 Feb 2019 16:39:36 +0100 Subject: [PATCH 036/191] fish_tests: Initialize some collections For some reason this'd crash on NetBSD otherwise. --- src/fish_tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 19172dff3..7b1f5c6c3 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -442,7 +442,7 @@ static char *str2hex(const char *input) { /// comes back through double conversion. static void test_convert() { int i; - std::vector sb; + std::vector sb {}; say(L"Testing wide/narrow string conversion"); @@ -3300,7 +3300,7 @@ class history_tests_t { }; static wcstring random_string() { - wcstring result; + wcstring result = L""; size_t max = 1 + rand() % 32; while (max--) { wchar_t c = 1 + rand() % ESCAPE_TEST_CHAR; From d48eb56aeaa18a121b73079ff51e3ff7a0ed3abe Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 16 Feb 2019 17:00:18 +0100 Subject: [PATCH 037/191] Improve curl completions Just a bunch of rewriting descriptions and some arguments. Most arguments here are uncompleteable, and most of these options will never be used. [ci skip] --- share/completions/curl.fish | 107 ++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/share/completions/curl.fish b/share/completions/curl.fish index b8767ec97..5f10e9c04 100644 --- a/share/completions/curl.fish +++ b/share/completions/curl.fish @@ -40,17 +40,17 @@ complete -c curl -l disallow-username-in-url -d '(HTTP) Exit if passed a url con complete -c curl -l dns-interface -d '(DNS) Send outgoing DNS requests through ' complete -c curl -l dns-ipv4-addr -d '(DNS) Bind to when making IPv4 DNS requests' complete -c curl -l dns-ipv6-addr -d '(DNS) Bind to when making IPv6 DNS requests' -complete -c curl -l dns-servers -d 'Set the list of DNS servers to be used instead of the system default' -complete -c curl -l doh-url -d '(all) Specifies which DNS-over-HTTPS (DOH) server to use to resolve hostnames' +complete -c curl -l dns-servers -d 'Set the list of DNS servers to use' +complete -c curl -l doh-url -d '(all) Specify which DNS-over-HTTPS (DOH) server to use to resolve hostnames' complete -c curl -s D -l dump-header -d '(HTTP FTP) Write the received protocol headers to the specified file' complete -c curl -l egd-file -d '(TLS) Specify the path name to the Entropy Gathering Daemon socket' complete -c curl -l engine -d '(TLS) Select the OpenSSL crypto engine to use for cipher operations' complete -c curl -l expect100-timeout -d '(HTTP) Maximum time in seconds to wait for a 100-continue' complete -c curl -l fail-early -d 'Fail and exit on the first detected transfer error' complete -c curl -s f -l fail -d '(HTTP) Fail silently (no output at all) on server errors' -complete -c curl -l false-start -d '(TLS) Tells curl to use false start during the TLS handshake' -complete -c curl -l form-string -d '(HTTP SMTP IMAP) Similar to -F, --form except that the value string for the n…' -complete -c curl -s F -l form -d '(HTTP SMTP IMAP) For HTTP protocol family, this lets curl emulate a filled-in…' +complete -c curl -l false-start -d '(TLS) Use false start during the TLS handshake' +complete -c curl -l form-string -d '(HTTP SMTP IMAP) Like --form except using value string literally' +complete -c curl -s F -l form -d '(HTTP SMTP IMAP) Emulate pressing submit on filled-in form' complete -c curl -l ftp-account -d '(FTP) Data for the ACCT command' complete -c curl -l ftp-alternative-to-user -d '(FTP) If USER and PASS commands fail, send this command' complete -c curl -l ftp-create-dirs -d '(FTP SFTP) Create missing dirs with ftp' @@ -58,39 +58,39 @@ complete -c curl -l ftp-method -d '(FTP) Control what method curl should use to complete -c curl -l ftp-pasv -d '(FTP) Use passive mode for the data connection' complete -c curl -s P -l ftp-port -d '(FTP) Reverses the default initiator/listener roles when connecting with FTP' complete -c curl -l ftp-pret -d '(FTP) Tell curl to send a PRET command before PASV (and EPSV)' -complete -c curl -l ftp-skip-pasv-ip -d '(FTP) Tell curl to not use the IP address the server suggests in its response…' +complete -c curl -l ftp-skip-pasv-ip -d '(FTP) Use same IP instead of IP the server suggests in response to PASV' complete -c curl -l ftp-ssl-ccc-mode -d '(FTP) Sets the CCC mode' -complete -c curl -l ftp-ssl-ccc -d '(FTP) Use CCC (Clear Command Channel) Shuts down the SSL/TLS layer after auth…' +complete -c curl -l ftp-ssl-ccc -d '(FTP) Use CCC (Clear Command Channel) Shuts down the SSL/TLS layer after auth' complete -c curl -l ftp-ssl-control -d '(FTP) Require SSL/TLS for the FTP login, clear for transfer' -complete -c curl -s G -l get -d 'When used, this option will make all data specified with -d, --data, --data-b…' +complete -c curl -s G -l get -d 'Use GET instead of POST' complete -c curl -s g -l globoff -d 'This option switches off the "URL globbing parser"' -complete -c curl -l happy-eyeballs-timeout-ms -d 'Happy eyeballs is an algorithm that attempts to connect to both IPv4 and IPv6…' -complete -c curl -l haproxy-protocol -d '(HTTP) Send a HAProxy PROXY protocol v1 header at the beginning of the connec…' -complete -c curl -s I -l head -d '(HTTP FTP FILE) Fetch the headers only! HTTP-servers feature the command HEAD…' +complete -c curl -l happy-eyeballs-timeout-ms -d 'Attempt to connect to both IPv4 and IPv6 in parallel' +complete -c curl -l haproxy-protocol -d '(HTTP) Send a HAProxy PROXY protocol v1 header at the beginning of the connection' +complete -c curl -s I -l head -d '(HTTP FTP FILE) Fetch the headers only' complete -c curl -s H -l header -d '(HTTP) Extra header to include in the request when sending HTTP to a server' complete -c curl -s h -l help -d 'Usage help' complete -c curl -l hostpubmd5 -d '(SFTP SCP) Pass a string containing 32 hexadecimal digits' complete -c curl -l 'http0.9' -d '(HTTP) Tells curl to be fine with HTTP version 0. 9 response. HTTP/0' -complete -c curl -s 0 -l 'http1.0' -d '(HTTP) Tells curl to use HTTP version 1' -complete -c curl -l 'http1.1' -d '(HTTP) Tells curl to use HTTP version 1. 1' -complete -c curl -l http2-prior-knowledge -d '(HTTP) Tells curl to issue its non-TLS HTTP requests using HTTP/2 without HTT…' -complete -c curl -l http2 -d '(HTTP) Tells curl to use HTTP version 2. See also --no-alpn' -complete -c curl -l ignore-content-length -d '(FTP HTTP) For HTTP, Ignore the Content-Length header' +complete -c curl -s 0 -l 'http1.0' -d '(HTTP) Use HTTP version 1' +complete -c curl -l 'http1.1' -d '(HTTP) Use HTTP version 1.1' +complete -c curl -l http2-prior-knowledge -d '(HTTP) Use HTTP/2 immediately (without trying HTTP1)' +complete -c curl -l http2 -d '(HTTP) Use HTTP version 2' +complete -c curl -l ignore-content-length -d '(FTP HTTP) Ignore the Content-Length header' complete -c curl -s i -l include -d 'Include the HTTP response headers in the output' -complete -c curl -s k -l insecure -d '(TLS) By default, every SSL connection curl makes is verified to be secure' +complete -c curl -s k -l insecure -d '(TLS) Allow insecure connections' complete -c curl -l interface -d 'Perform an operation using a specified interface' -complete -c curl -s 4 -l ipv4 -d 'This option tells curl to resolve names to IPv4 addresses only, and not for e…' -complete -c curl -s 6 -l ipv6 -d 'This option tells curl to resolve names to IPv6 addresses only, and not for e…' -complete -c curl -s j -l junk-session-cookies -d '(HTTP) When curl is told to read cookies from a given file, this option will …' -complete -c curl -l keepalive-time -d 'This option sets the time a connection needs to remain idle before sending ke…' -complete -c curl -l key-type -d '(TLS) Private key file type' +complete -c curl -s 4 -l ipv4 -d 'Use IPv4 only' +complete -c curl -s 6 -l ipv6 -d 'Use IPv6 only' +complete -c curl -s j -l junk-session-cookies -d '(HTTP) Discard all session cookies' +complete -c curl -l keepalive-time -d 'Specify idle time before keepalive is sent' +complete -c curl -l key-type -d '(TLS) Private key file type' -xa 'DER PEM ENG' complete -c curl -l key -d '(TLS SSH) Private key file name' complete -c curl -l krb -d '(FTP) Enable Kerberos authentication and use' -complete -c curl -l libcurl -d 'Append this option to any ordinary curl command line, and you will get a libc…' -complete -c curl -l limit-rate -d 'Specify the maximum transfer rate you want curl to use - for both downloads a…' -complete -c curl -s l -l list-only -d '(FTP POP3) (FTP) When listing an FTP directory, this switch forces a name-onl…' -complete -c curl -l local-port -d 'Set a preferred single number or range (FROM-TO) of local port numbers to use…' -complete -c curl -l location-trusted -d '(HTTP) Like -L, --location, but will allow sending the name + password to all…' +complete -c curl -l libcurl -d 'Write C-code equivalent to the invocation to the given file' +complete -c curl -l limit-rate -d 'Limit bandwidth (Examples: 200K, 3m and 1G)' +complete -c curl -s l -l list-only -d '(FTP POP3) (FTP) Use name-only view when listing' +complete -c curl -l local-port -d 'Set a preferred single number or range (FROM-TO) of local ports to use' +complete -c curl -l location-trusted -d '(HTTP) Like -L, --location, but allow sending the name + password' complete -c curl -s L -l location -d '(HTTP) Follow redirects' complete -c curl -l login-options -d '(IMAP POP3 SMTP) Specify the login options' complete -c curl -l mail-auth -d '(SMTP) Specify a single address' @@ -100,36 +100,35 @@ complete -c curl -s M -l manual -d 'Manual. Display the huge help text' complete -c curl -l max-filesize -d 'Specify the maximum size (in bytes) of a file to download' complete -c curl -l max-redirs -d '(HTTP) Set maximum number of redirection-followings allowed' complete -c curl -s m -l max-time -d 'Maximum time in seconds that you allow the whole operation to take' -complete -c curl -l metalink -d 'This option can tell curl to parse and process a given URI as Metalink file (…' +complete -c curl -l metalink -d 'Process URI as Metalink file' complete -c curl -l negotiate -d '(HTTP) Enables Negotiate (SPNEGO) authentication' -complete -c curl -l netrc-file -d 'This option is similar to -n, --netrc, except that you provide the path (abso…' -complete -c curl -l netrc-optional -d 'Very similar to -n, --netrc, but this option makes the ' -complete -c curl -s n -l netrc -d 'Makes curl scan the ' -complete -c curl -l next -d 'Tells curl to use a separate operation for the following URL and associated o…' +complete -c curl -l netrc-file -d 'Use this netrc file' +complete -c curl -l netrc-optional -d 'Make netrc optional' +complete -c curl -s n -l netrc -d 'Use ~/.netrc' +complete -c curl -l next -d 'Use a separate operation for the following URL' complete -c curl -l no-alpn -d '(HTTPS) Disable the ALPN TLS extension' -complete -c curl -s N -l no-buffer -d 'Disables the buffering of the output stream' -complete -c curl -l no-keepalive -d 'Disables the use of keepalive messages on the TCP connection' -complete -c curl -l no-npn -d '(HTTPS) Disable the NPN TLS extension' -complete -c curl -l no-sessionid -d '(TLS) Disable curl\'s use of SSL session-ID caching' -complete -c curl -l noproxy -d 'Comma-separated list of hosts which do not use a proxy, if one is specified' -complete -c curl -l ntlm-wb -d '(HTTP) Enables NTLM much in the style --ntlm does, but hand over the authenti…' -complete -c curl -l ntlm -d '(HTTP) Enables NTLM authentication' +complete -c curl -s N -l no-buffer -d 'Disable the buffering of the output stream' +complete -c curl -l no-keepalive -d 'Disable use of keepalive messages on the TCP connection' +complete -c curl -l no-npn -d '(HTTPS) Disable NPN TLS extension' +complete -c curl -l no-sessionid -d '(TLS) Disable use of SSL session-ID caching' +complete -c curl -l noproxy -d 'Comma-separated list of hosts which do not use a proxy' +complete -c curl -l ntlm-wb -d '(HTTP) Enable NTLM, but hand over auth to separate ntlmauth binary' +complete -c curl -l ntlm -d '(HTTP) Enable NTLM authentication' complete -c curl -l oauth2-bearer -d '(IMAP POP3 SMTP) Specify the Bearer Token for OAUTH 2' complete -c curl -s o -l output -d 'Write output to instead of stdout' -complete -c curl -l pass -d '(SSH TLS) Passphrase for the private key If this option is used several time…' -complete -c curl -l path-as-is -d 'Tell curl to not handle sequences of /. / or /. / in the given URL path' -complete -c curl -l pinnedpubkey -d '(TLS) Tells curl to use the specified public key file (or hashes) to verify t…' -complete -c curl -l post301 -d '(HTTP) Tells curl to respect RFC 7231/6. 4' -complete -c curl -l post302 -d '(HTTP) Tells curl to respect RFC 7231/6. 4' -complete -c curl -l post303 -d '(HTTP) Tells curl to violate RFC 7231/6. 4' -complete -c curl -l preproxy -d 'Use the specified SOCKS proxy before connecting to an HTTP or HTTPS -x, --pro…' -complete -c curl -s '#' -l progress-bar -d 'Make curl display transfer progress as a simple progress bar instead of the s…' -complete -c curl -l proto-default -d 'Tells curl to use protocol for any URL missing a scheme name' -complete -c curl -l proto-redir -d 'Tells curl to limit what protocols it may use on redirect' -complete -c curl -l proto -d 'Tells curl to limit what protocols it may use in the transfer' -complete -c curl -o ftps -d 'uses the default protocols, but disables ftps' -complete -c curl -o all -d 'only enables http and https' -complete -c curl -l proxy-anyauth -d 'Tells curl to pick a suitable authentication method when communicating with t…' +complete -c curl -l pass -d '(SSH TLS) Passphrase for the private key' +complete -c curl -l path-as-is -d 'Do not handle sequences of /../ or /./ in the given URL path' +complete -c curl -l pinnedpubkey -d '(TLS) Use the specified public key file (or hashes)' +complete -c curl -l post301 -d '(HTTP) Respect RFC 7231/6.4' +complete -c curl -l post302 -d '(HTTP) Respect RFC 7231/6.4' +complete -c curl -l post303 -d '(HTTP) Violate RFC 7231/6.4' +complete -c curl -l preproxy -d 'Use the specified SOCKS proxy before connecting to HTTP(S) proxy' +complete -c curl -s '#' -l progress-bar -d 'Display progress as a simple progress bar' +complete -c curl -l proto-default -d 'Use this protocol for any URL missing a scheme name' +complete -c curl -l proto-redir -d 'Limit what protocols it may use on redirect' +# TODO: args +complete -c curl -l proto -d 'Limit what protocols it may use in the transfer' +complete -c curl -l proxy-anyauth -d 'Like --anyauth but for the proxy' complete -c curl -l proxy-basic -d 'Tells curl to use HTTP Basic authentication when communicating with the given…' complete -c curl -l proxy-cacert -d 'Same as --cacert but used in HTTPS proxy context' complete -c curl -l proxy-capath -d 'Same as --capath but used in HTTPS proxy context' @@ -155,7 +154,7 @@ complete -c curl -l proxy-tlsuser -d 'Same as --tlsuser but used in HTTPS proxy complete -c curl -l proxy-tlsv1 -d 'Same as -1, --tlsv1 but used in HTTPS proxy context. Added in 7. 52. 0' complete -c curl -s U -l proxy-user -d 'Specify the user name and password to use for proxy authentication' complete -c curl -s x -l proxy -d 'Use the specified proxy' -complete -c curl -l 'proxy1.0' -d 'Use the specified HTTP 1. 0 proxy' +complete -c curl -l 'proxy1.0' -d 'Use the specified HTTP 1.0 proxy' complete -c curl -s p -l proxytunnel -d 'When an HTTP proxy is used -x, --proxy, this option will cause non-HTTP proto…' complete -c curl -l pubkey -d '(SFTP SCP) Public key file name' complete -c curl -s Q -l quote -d '(FTP SFTP) Send an arbitrary command to the remote FTP or SFTP server' From f6974e5a7676d0cd5c4b32300688eb669fe8992b Mon Sep 17 00:00:00 2001 From: Sabine Maennel Date: Sat, 4 Aug 2018 20:42:26 +0200 Subject: [PATCH 038/191] documentation Start issue 740 - changed introduction section - added installation section - added what is a shell section --- doc_src/index.hdr.in | 196 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 1 deletion(-) diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index 5bce40c54..b1e853637 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -17,7 +17,201 @@ \section introduction Introduction -This is the documentation for `fish`, the friendly interactive shell. `fish` is a user friendly commandline shell intended mostly for interactive use. A shell is a program used to execute other programs. For the latest information on `fish`, please visit the `fish` homepage. +This is the documentation for *fish* the f riendly i nteractive sh ell. + +A shell is a commandline interpreter. It reads text input from the commandline and interpretes it as commands to operating system, see: What is a Shell. + +So shells serve as user-interface between applications and the operating system. There are many different shells. They differ on how this interface is implemented. *fish* specializes in the following ways: + +- Extensive UI: *fish* supports the user with syntax highlighting, autosuggestions, tab completions and selections lists, that can be navigated and filtered, see: Autosuggestions and Tab Completions. + +- No further configuration is needed: *fish* comes preconfigured so that it will be an efficient helper on the commandline out of the box. + +- Add new commands easily: in *fish* new commands can be added on the fly. The syntax is easy to learn and there is no administrative overhead, see: Functions. + +- Interactive shell: *fish* focuses on commands that will be run in an interactive session: While it supports job control for external commands, its own commands share the process of the shell, that started them. + +<-
+ + +\section install Installation and Start + +This section is on how to install, uninstall, start and exit a *fish* shell and on how to make *fish* the default shell: + +- Install: How to install *fish* +- Default Shell: How to switch to *fish* as the default shell +- Starting and Exiting: How to start and exit a *fish* shell +- Uninstall: How to uninstall *fish* +- Executing Bash: How to execute *bash* commands in *fish* + +\subsection installation Installation + +Instructions for installing fish are on the fish homepage. Search that page for "Go fish". + +To install the development version of *fish* see the instructions at the project's GitHub page. + +\subsection default-shell Default Shell + +You can make *fish* your default shell by adding *fish*'s executable in two places: +- add `/usr/local/bin/fish` to `/etc/shells` +- change your default shell with `chsh -s` to `/usr/local/bin/fish` + +For for detailed instructions see Switching to *fish*. + +\subsection uninstall Uninstalling + +For uninstalling *fish*: see FAQ: Uninstalling *fish* + +\subsection start Starting and Exiting + +Once *fish* has been installed, open a terminal. If *fish* is not the default shell: + +- Enter `fish` to start a *fish* shell: + +\fish +>fish +\endfish + +- Enter `exit` to exit a *fish* shell: + +\fish +>exit +\endfish + +\subsection bash Executing Bash + +If *fish* is your default shell you can still execute *bash* commands in case you need to: + +- a single command can be executed with: + +\fish +>bash -c SomeBashCommand +\endfish + +- or a *bash* shell can be opened with: + +\fish +>/bin/bash +\endfish + +This might be useful, when copying complicated *bash* commands from a website. Translating them into *fish* syntax can be avoided that way. + +<-
+ +\section shell What is a Shell + +This section is about the basics of shells. *fish* is a shell and shells have a lot in common: + +- Shell Standards: Why shells adjust to standards +- Manual Pages: Commands usually come with a standardized manual page +- Command Syntax: Shell commands have a standard syntax +- Commands versus Programs: Commands differ from normal programs +- Shebang Line: How the shell knows the language of a script + +\subsection shell-standards Shell Standards + +A shell is an interface to the operating system that reads from the commandline of a terminal. A shell's task is to identify and interpret commands. The commands can come from different applications and can be written in different programming languages. + +This can only work smoothly if shells adapt to some common standards. For shells there is the POSIX standard, see Command-line interpreters. `fish` tries to satisfy the POSIX standard wherever it does not get into the way of its own design principles, see `fish` Design. + +\subsection man-page Manual Pages + +There is a common standard on how to receive help on shell commands: applications provide a manual page to their commands that can be opened with the `man` command: + +\fish +>man COMMAND +\endfish + +This convention helps to make sure help can be found on commands no matter where they originate from. *fish*'s internal commands all come with a manual page. + +\subsection shell-syntax Command Syntax + +Shell commands also have some syntax in common, no matter where they originate from: + +Commands consist of three parts: + +\fish +COMMAND [OPTIONS] ARGUMENTS +\endfish + +- `COMMAND`: the name of the executeable + +- `[OPTIONS]`: options can change the behaviour of a command + +- `ARGUMENTS`: input to the command + +For external commands the executable is usually stored on file and the file path must be included in the variable `$PATH`, so that the file can be found: see Special Variables. + +Options come in two forms: a short name, that is a hyphen with a single letter; or a long name, consisting of two hyphens with words connected by hyphens. Example: `-h` and `--help` are common options for opening the manual page of a command. Options are a fixed set, described in the manual pages of the command, see Manual Pages + +Arguments are the arbitrary input part of a command: often it is a file or directory name, sometimes it is a string or a list. + +Example: + +\fish +>echo -s Hallo World! +HalloWorld! +\endfish + +- both `Hallo` and `World!` are arguments to the echo command +- `-s` is an option that suppresses spaces in the output of the command + +\subsection shell-programming Commands versus Programs + +Shell commands differ from other programs in the following way: + +- they cannot return variables + +Instead: + +- They transform an input stream into an output stream. Both of these streams are usually the terminal, but they can be redirected. + +- They return an exit code: this exit code is 0 when the command executes normally and between 1 and 255 otherwise. + +This leads to another way of programming for shell commands: they can directly return variables, but they can pass on content to other commands in following ways: + +Commands can pass on content as a stream: one command takes the output stream of another command as its input stream: + +Example: + +\fish +>ls -l | grep "my topic" +\endfish + +- every line of the `ls` command is immediatelly passed on to the `grep` command and treated separately. + +In this case the two commands execute in parallel. This is called piping, see Piping. + +Commands can pass on all of their output stream as a chunk: + +Example: +\fish +>echo (ls a*) +\endfish + +- the `echo` command takes the output of the `ls` command as a chunk and prints it to the terminal. The `echo` command waits for the `ls` command to finish, before it executes. + +In this case one command waits for the other command to finish, before it executes. This is called command substitution, see Command Substitution. + +\subsection shebang-line Shebang Line + +Since script for shell commands can be written in many different languages, they need to carry information about what interpreter is needed to execute them: For this they are expected to have a first line, the shebang line, which names an executable for this purpose: + +Example: + +A scripts written in `bash` it would need a first line like this: + +``` +#!/bin/bash +``` + +- this line tells the shell to execute the file with the *bash* interpreter, that is located at the path `/bin/bash`. + +For a script, written in another language, just replace the interpreter `/bin/bash` with the language interpreter of that other language (for example `/bin/python` for a `python` script) + +This line is only needed when scripts are executed by another interpreter, so for *fish* internal commands, that are executed by *fish* the shebang line is not necessary. + +<-
\section syntax Syntax overview From 20c51b7da9cf468fd74af3056dceb0701fe60e63 Mon Sep 17 00:00:00 2001 From: Sabine Maennel Date: Wed, 15 Aug 2018 07:47:09 +0200 Subject: [PATCH 039/191] changes according to feedback Changes according to the feedback have been made: - What is a shell section has been moved before Installation and Start section - Content changes have been made as suggested in both of the above sections. --- doc_src/index.hdr.in | 246 +++++++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 124 deletions(-) diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index b1e853637..5defee884 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -34,6 +34,123 @@ So shells serve as user-interface between applications and the operating system. <-
+\section shell What is a Shell + +This section is about the basics of shells. *fish* is a shell and shells have a lot in common: + +- Shell Standards: Why shells adjust to standards +- Manual Pages: Commands usually come with a standardized manual page +- Command Syntax: Shell commands have a standard syntax +- Commands versus Programs: Commands differ from normal programs +- Shebang Line: How the shell knows the language of a script + +\subsection shell-standards Shell Standards + +A shell is an interface to the operating system that reads from the commandline of a terminal. A shell's task is to identify and interpret commands. The commands can come from different applications and can be written in different programming languages. + +This can only work smoothly if shells adapt to some common standards. For shells there is the POSIX standard, see Command-line interpreters. `fish` tries to satisfy the POSIX standard wherever it does not get into the way of its own design principles, see `fish` Design. + +\subsection man-page Manual Pages + +There is a common standard on how to receive help on shell commands: applications provide a manual page to their commands that can be opened with the `man` command: + +\fish +>man COMMAND +\endfish + +This convention helps to make sure help can be found on commands no matter where they originate from. *fish*'s internal commands all come with a manual page. + +\subsection shell-syntax Command Syntax + +Shells also support some common syntax for executing commands. That way a command can be started in the same way, regardless of the application, where it comes from, and the shell, where it is executed in. + +The pattern below is a basic pattern: + +\fish +COMMAND [OPTIONS] ARGUMENTS +\endfish + +- `COMMAND`: the name of the executeable + +- `[OPTIONS]`: options can change the behaviour of a command + +- `ARGUMENTS`: input to the command + +For external commands the executable is usually stored on file and the file path must be included in the variable `$PATH`, so that the file can be found: see Special Variables. + +Options come in two forms: a short name, that is a hyphen with a single letter; or a long name, consisting of two hyphens with words connected by hyphens. Example: `-h` and `--help` are often used to print a help message. Options are a fixed set, described in the manual pages of the command, see Manual Pages + +Arguments are the arbitrary input part of a command: often it is a file or directory name, sometimes it is a string or a list. + +Example: + +\fish +>echo -s Hallo World! +HalloWorld! +\endfish + +- both `Hallo` and `World!` are arguments to the echo command +- `-s` is an option that suppresses spaces in the output of the command + +\subsection shell-programming Commands versus Programs + +Programs in other languages can often be regarded as black boxes: they get complex input and return complex output. Sometimes they produce side effects such as writing to a file or reporting an error, but the emphasis is on: arguments in and return values out: + +Arguments → |Program| → Return Values + +Shell commands are different: + +- the side effects take the center of the stage: they transform an input stream of data into an output stream of data. Both of these streams are usually the terminal, but they can be redirected. +- the arguments become options or switches paired with data: the switches influence the behaviour of the command +- the return value shrinks to an exit code: this exit code is 0 when the command executes normally and between 1 and 255 otherwise. + + +
Input Stream ⇒|Shell Command|⇒ Output Stream +
switch and data as arguments →→ exit code +
+ +This leads to another way of programming and especially of combining commands: + +There are two ways to combine shell commands: + +- Commands can pass on their streams to each other: one command takes the output stream of another command as its input stream and the two commands execute in parallel. This is called piping, see Piping. + +Example: + +\fish +# Every line of the `ls` command is immediatelly passed on to the `grep` command +>ls -l | grep "my topic" +\endfish + +- Commands can pass on all their output as a chunk: the output stream of one command is bundled and taken as data argument for the second command. This is called command substitution, see Command Substitution. + +Example: +\fish +# the output of the inner `ls` command is taken as the input argument for the outer `echo` command +>echo (ls a*) +\endfish + +\subsection shebang-line Shebang Line + +Since script for shell commands can be written in many different languages, they need to carry information about what interpreter is needed to execute them: For this they are expected to have a first line, the shebang line, which names an executable for this purpose: + +Example: + +A scripts written in `bash` it would need a first line like this: + +``` +#!/bin/bash +``` + +- this line tells the shell to execute the file with the *bash* interpreter, that is located at the path `/bin/bash`. + +For a script, written in another language, just replace the interpreter `/bin/bash` with the language interpreter of that other language (for example `/bin/python` for a `python` script) + +This line is only needed when scripts are executed by another interpreter, so for *fish* internal commands, that are executed by *fish* the shebang line is not necessary. + +<-
+ + \section install Installation and Start This section is on how to install, uninstall, start and exit a *fish* shell and on how to make *fish* the default shell: @@ -80,139 +197,20 @@ Once *fish* has been installed, open a terminal. If *fish* is not the default sh \subsection bash Executing Bash -If *fish* is your default shell you can still execute *bash* commands in case you need to: +If *fish* is your default shell and you want to copy commands from the internet, that are written in a different shell language, *bash* for example, you can proceed in the following way: -- a single command can be executed with: +Consider, that `bash` is also a command. With `man bash` you can see that there are two ways to do this: + +- `bash` has a switch `-c` to read from a string: \fish >bash -c SomeBashCommand \endfish -- or a *bash* shell can be opened with: - -\fish ->/bin/bash -\endfish - -This might be useful, when copying complicated *bash* commands from a website. Translating them into *fish* syntax can be avoided that way. +- or `bash` without a switch, opens a *bash* shell that you can use and `exit` afterwards. <-
-\section shell What is a Shell - -This section is about the basics of shells. *fish* is a shell and shells have a lot in common: - -- Shell Standards: Why shells adjust to standards -- Manual Pages: Commands usually come with a standardized manual page -- Command Syntax: Shell commands have a standard syntax -- Commands versus Programs: Commands differ from normal programs -- Shebang Line: How the shell knows the language of a script - -\subsection shell-standards Shell Standards - -A shell is an interface to the operating system that reads from the commandline of a terminal. A shell's task is to identify and interpret commands. The commands can come from different applications and can be written in different programming languages. - -This can only work smoothly if shells adapt to some common standards. For shells there is the POSIX standard, see Command-line interpreters. `fish` tries to satisfy the POSIX standard wherever it does not get into the way of its own design principles, see `fish` Design. - -\subsection man-page Manual Pages - -There is a common standard on how to receive help on shell commands: applications provide a manual page to their commands that can be opened with the `man` command: - -\fish ->man COMMAND -\endfish - -This convention helps to make sure help can be found on commands no matter where they originate from. *fish*'s internal commands all come with a manual page. - -\subsection shell-syntax Command Syntax - -Shell commands also have some syntax in common, no matter where they originate from: - -Commands consist of three parts: - -\fish -COMMAND [OPTIONS] ARGUMENTS -\endfish - -- `COMMAND`: the name of the executeable - -- `[OPTIONS]`: options can change the behaviour of a command - -- `ARGUMENTS`: input to the command - -For external commands the executable is usually stored on file and the file path must be included in the variable `$PATH`, so that the file can be found: see Special Variables. - -Options come in two forms: a short name, that is a hyphen with a single letter; or a long name, consisting of two hyphens with words connected by hyphens. Example: `-h` and `--help` are common options for opening the manual page of a command. Options are a fixed set, described in the manual pages of the command, see Manual Pages - -Arguments are the arbitrary input part of a command: often it is a file or directory name, sometimes it is a string or a list. - -Example: - -\fish ->echo -s Hallo World! -HalloWorld! -\endfish - -- both `Hallo` and `World!` are arguments to the echo command -- `-s` is an option that suppresses spaces in the output of the command - -\subsection shell-programming Commands versus Programs - -Shell commands differ from other programs in the following way: - -- they cannot return variables - -Instead: - -- They transform an input stream into an output stream. Both of these streams are usually the terminal, but they can be redirected. - -- They return an exit code: this exit code is 0 when the command executes normally and between 1 and 255 otherwise. - -This leads to another way of programming for shell commands: they can directly return variables, but they can pass on content to other commands in following ways: - -Commands can pass on content as a stream: one command takes the output stream of another command as its input stream: - -Example: - -\fish ->ls -l | grep "my topic" -\endfish - -- every line of the `ls` command is immediatelly passed on to the `grep` command and treated separately. - -In this case the two commands execute in parallel. This is called piping, see Piping. - -Commands can pass on all of their output stream as a chunk: - -Example: -\fish ->echo (ls a*) -\endfish - -- the `echo` command takes the output of the `ls` command as a chunk and prints it to the terminal. The `echo` command waits for the `ls` command to finish, before it executes. - -In this case one command waits for the other command to finish, before it executes. This is called command substitution, see Command Substitution. - -\subsection shebang-line Shebang Line - -Since script for shell commands can be written in many different languages, they need to carry information about what interpreter is needed to execute them: For this they are expected to have a first line, the shebang line, which names an executable for this purpose: - -Example: - -A scripts written in `bash` it would need a first line like this: - -``` -#!/bin/bash -``` - -- this line tells the shell to execute the file with the *bash* interpreter, that is located at the path `/bin/bash`. - -For a script, written in another language, just replace the interpreter `/bin/bash` with the language interpreter of that other language (for example `/bin/python` for a `python` script) - -This line is only needed when scripts are executed by another interpreter, so for *fish* internal commands, that are executed by *fish* the shebang line is not necessary. - -<-
- \section syntax Syntax overview From 05701a779b97e55728632776475fa6540449cd92 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Sat, 16 Feb 2019 17:14:15 -0800 Subject: [PATCH 040/191] isatty: command [ instead of command test I don't know why but Go users keep having random tools installed into PATH named `test`. Fixes #5665 --- share/functions/isatty.fish | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/share/functions/isatty.fish b/share/functions/isatty.fish index 4d91f9b5c..406e5287c 100644 --- a/share/functions/isatty.fish +++ b/share/functions/isatty.fish @@ -27,5 +27,7 @@ function isatty -d "Tests if a file descriptor is a tty" # Use `command test` because `builtin test` doesn't open the regular fd's. # See https://github.com/fish-shell/fish-shell/issues/1228 - command test -t "$fd" + # Too often `command test` is some bogus Go binary, I don't know why. Use [ because + # it's less likely to be something surprising. See #5665 + command [ -t "$fd" ] end From 8a0be93e50675595f8dc525d79eed27a3e122754 Mon Sep 17 00:00:00 2001 From: Collin Styles Date: Sat, 16 Feb 2019 23:54:32 -0800 Subject: [PATCH 041/191] Add completions for "git remote get-url" --- share/completions/git.fish | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index 869883921..067143253 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -745,7 +745,7 @@ complete -r -c git -n '__fish_git_using_command filter-branch' -s d -d 'Use this complete -c git -n '__fish_git_using_command filter-branch' -s f -l force -d 'Force filter branch to start even w/ refs in refs/original or existing temp directory' ### remote -set -l remotecommands add rm remove show prune update rename set-head set-url set-branches +set -l remotecommands add rm remove show prune update rename set-head set-url set-branches get-url complete -f -c git -n '__fish_git_needs_command' -a remote -d 'Manage set of tracked repositories' complete -f -c git -n '__fish_git_using_command remote' -a '(__fish_git_remotes)' complete -f -c git -n "__fish_git_using_command remote; and not __fish_seen_subcommand_from $remotecommands" -s v -l verbose -d 'Be verbose' @@ -758,6 +758,7 @@ complete -f -c git -n "__fish_git_using_command remote; and not __fish_seen_subc complete -f -c git -n "__fish_git_using_command remote; and not __fish_seen_subcommand_from $remotecommands" -a rename -d 'Renames a remote' complete -f -c git -n "__fish_git_using_command remote; and not __fish_seen_subcommand_from $remotecommands" -a set-head -d 'Sets the default branch for a remote' complete -f -c git -n "__fish_git_using_command remote; and not __fish_seen_subcommand_from $remotecommands" -a set-url -d 'Changes URLs for a remote' +complete -f -c git -n "__fish_git_using_command remote; and not __fish_seen_subcommand_from $remotecommands" -a get-url -d 'Retrieves URLs for a remote' complete -f -c git -n "__fish_git_using_command remote; and not __fish_seen_subcommand_from $remotecommands" -a set-branches -d 'Changes the list of branches tracked by a remote' complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from add " -s f -d 'Once the remote information is set up git fetch is run' complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from add " -l tags -d 'Import every tag from a remote with git fetch ' @@ -767,6 +768,8 @@ complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcomma complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from set-url" -l push -d 'Manipulate push URLs instead of fetch URLs' complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from set-url" -l add -d 'Add new URL instead of changing the existing URLs' complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from set-url" -l delete -d 'Remove URLs that match specified URL' +complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from get-url" -l push -d 'Query push URLs rather than fetch URLs' +complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from get-url" -l all -d 'All URLs for the remote will be listed' complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from show" -s n -d 'Remote heads are not queried, cached information is used instead' complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from prune" -l dry-run -d 'Report what will be pruned but do not actually prune it' complete -f -c git -n "__fish_git_using_command remote; and __fish_seen_subcommand_from update" -l prune -d 'Prune all remotes that are updated' From 78ed659151b8fd33e9a269be6082a8b28738962a Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Feb 2019 14:19:59 -0800 Subject: [PATCH 042/191] Fancify enum_set and introduce enum_iter_t Allow iterating over the values of an enum class. --- src/enum_set.h | 87 ++++++++++++++++++++++++++++++++++++++-------- src/fish_tests.cpp | 33 ++++++++++++++++++ src/proc.h | 7 ++++ 3 files changed, 113 insertions(+), 14 deletions(-) diff --git a/src/enum_set.h b/src/enum_set.h index 6ef6e2c8c..c26f56306 100644 --- a/src/enum_set.h +++ b/src/enum_set.h @@ -1,26 +1,85 @@ #pragma once #include +#include +#include + +/// A type (to specialize) that provides a count for an enum. +/// Example: +/// template<> struct enum_info_t +/// { static constexpr auto count = MyEnum::COUNT; }; +template +struct enum_info_t {}; template -class enum_set_t { +class enum_set_t : private std::bitset(enum_info_t::count)> { private: - using base_type_t = typename std::underlying_type::type; - std::bitset<8 * sizeof(base_type_t)> bitmask{0}; - static int index_of(T t) { return static_cast(t); } + using super = std::bitset(enum_info_t::count)>; + static size_t index_of(T t) { return static_cast(t); } + + explicit enum_set_t(unsigned long raw) : super(raw) {} public: - bool get(T t) const { return bitmask.test(index_of(t)); } + enum_set_t() = default; - void set(T t, bool v) { - if (v) { - bitmask.set(index_of(t)); - } else { - bitmask.reset(index_of(t)); - } - } + explicit enum_set_t(T v) { set(v); } - void set(T t) { bitmask.set(index_of(t)); } + static enum_set_t from_raw(unsigned long v) { return enum_set_t{v}; } - void clear(T t) { bitmask.reset(index_of(t)); } + unsigned long to_raw() const { return super::to_ulong(); } + + bool get(T t) const { return super::test(index_of(t)); } + + void set(T t, bool v = true) { super::set(index_of(t), v); } + + void clear(T t) { super::reset(index_of(t)); } + + bool none() const { return super::none(); } + + bool any() const { return super::any(); } + + bool operator==(const enum_set_t &rhs) const { return super::operator==(rhs); } + + bool operator!=(const enum_set_t &rhs) const { return super::operator!=(rhs); } +}; + +/// A counting iterator for an enum class. +/// This enumerates the values of an enum class from 0 up to (not including) count. +/// Example: +/// for (auto v : enum_iter_t) {...} +template +class enum_iter_t { + using base_type_t = typename std::underlying_type::type; + struct iterator_t { + friend class enum_iter_t; + using iterator_category = std::forward_iterator_tag; + using value_type = T; + using difference_type = long; + + explicit iterator_t(base_type_t v) : v_(v) {} + + T operator*() const { return static_cast(v_); } + const T *operator->() const { return static_cast(v_); } + + iterator_t &operator++() { + v_ += 1; + return *this; + } + + iterator_t operator++(int) { + auto res = *this; + v_ += 1; + return res; + } + + bool operator==(iterator_t rhs) const { return v_ == rhs.v_; } + bool operator!=(iterator_t rhs) const { return v_ != rhs.v_; } + + private: + base_type_t v_{}; + }; + + public: + iterator_t begin() const { return iterator_t{0}; } + iterator_t end() const { return iterator_t{static_cast(enum_info_t::count)}; } }; diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 7b1f5c6c3..f3c49128c 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -286,6 +286,38 @@ static void test_str_to_num() { L"converting invalid num to long did not fail"); } +enum class test_enum { alpha, beta, gamma, COUNT }; + +template <> +struct enum_info_t { + static constexpr auto count = test_enum::COUNT; +}; + +static void test_enum_set() { + say(L"Testing enum set"); + enum_set_t es; + do_test(es.none()); + do_test(!es.any()); + do_test(es.to_raw() == 0); + do_test(es == enum_set_t::from_raw(0)); + do_test(es != enum_set_t::from_raw(1)); + + es.set(test_enum::beta); + do_test(es.to_raw() == 2); + do_test(es == enum_set_t::from_raw(2)); + do_test(es == enum_set_t{test_enum::beta}); + do_test(es != enum_set_t::from_raw(3)); + do_test(es.any()); + do_test(!es.none()); + + unsigned idx = 0; + for (auto v : enum_iter_t{}) { + do_test(static_cast(v) == idx); + idx++; + } + do_test(static_cast(test_enum::COUNT) == idx); +} + /// Test sane escapes. static void test_unescape_sane() { const struct test_t { @@ -5082,6 +5114,7 @@ int main(int argc, char **argv) { if (should_test_function("wcstring_tok")) test_wcstring_tok(); if (should_test_function("env_vars")) test_env_vars(); if (should_test_function("str_to_num")) test_str_to_num(); + if (should_test_function("enum")) test_enum_set(); if (should_test_function("highlighting")) test_highlighting(); if (should_test_function("new_parser_ll2")) test_new_parser_ll2(); if (should_test_function("new_parser_fuzzing")) diff --git a/src/proc.h b/src/proc.h index 6950a7031..03472029d 100644 --- a/src/proc.h +++ b/src/proc.h @@ -153,6 +153,13 @@ enum class job_flag_t { JOB_CONTROL, /// Whether the job wants to own the terminal when in the foreground. TERMINAL, + + JOB_FLAG_COUNT +}; + +template <> +struct enum_info_t { + static constexpr auto count = job_flag_t::JOB_FLAG_COUNT; }; typedef int job_id_t; From ccc45235b0774d4434a578ce3c116401a70cd16b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 11 Feb 2019 20:23:15 -0800 Subject: [PATCH 043/191] Introduce enum_array_t Allows for indexing an array via an enum class. --- src/enum_set.h | 28 +++++++++++++++++++++++++--- src/fish_tests.cpp | 11 +++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/enum_set.h b/src/enum_set.h index c26f56306..ea6e90b40 100644 --- a/src/enum_set.h +++ b/src/enum_set.h @@ -11,10 +11,17 @@ template struct enum_info_t {}; +/// \return the count of an enum. template -class enum_set_t : private std::bitset(enum_info_t::count)> { +constexpr size_t enum_count() { + return static_cast(enum_info_t::count); +} + +/// A bit set indexed by an enum type. +template +class enum_set_t : private std::bitset()> { private: - using super = std::bitset(enum_info_t::count)>; + using super = std::bitset()>; static size_t index_of(T t) { return static_cast(t); } explicit enum_set_t(unsigned long raw) : super(raw) {} @@ -43,6 +50,21 @@ class enum_set_t : private std::bitset(enum_info_t::count bool operator!=(const enum_set_t &rhs) const { return super::operator!=(rhs); } }; +/// An array of Elem indexed by an enum class. +template +class enum_array_t : public std::array()> { + using super = std::array()>; + using base_type_t = typename std::underlying_type::type; + + static int index_of(T t) { return static_cast(t); } + + public: + Elem &at(T t) { return super::at(index_of(t)); } + const Elem &at(T t) const { return super::at(index_of(t)); } + Elem &operator[](T t) { return super::operator[](index_of(t)); } + const Elem &operator[](T t) const { return super::operator[](index_of(t)); } +}; + /// A counting iterator for an enum class. /// This enumerates the values of an enum class from 0 up to (not including) count. /// Example: @@ -81,5 +103,5 @@ class enum_iter_t { public: iterator_t begin() const { return iterator_t{0}; } - iterator_t end() const { return iterator_t{static_cast(enum_info_t::count)}; } + iterator_t end() const { return iterator_t{static_cast(enum_count())}; } }; diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index f3c49128c..7b02115c0 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -318,6 +318,16 @@ static void test_enum_set() { do_test(static_cast(test_enum::COUNT) == idx); } +static void test_enum_array() { + say(L"Testing enum array"); + enum_array_t es{}; + do_test(es.size() == enum_count()); + es[test_enum::beta] = "abc"; + do_test(es[test_enum::beta] == "abc"); + es.at(test_enum::gamma) = "def"; + do_test(es.at(test_enum::gamma) == "def"); +} + /// Test sane escapes. static void test_unescape_sane() { const struct test_t { @@ -5115,6 +5125,7 @@ int main(int argc, char **argv) { if (should_test_function("env_vars")) test_env_vars(); if (should_test_function("str_to_num")) test_str_to_num(); if (should_test_function("enum")) test_enum_set(); + if (should_test_function("enum")) test_enum_array(); if (should_test_function("highlighting")) test_highlighting(); if (should_test_function("new_parser_ll2")) test_new_parser_ll2(); if (should_test_function("new_parser_fuzzing")) From fc9d2386423e418f9df054e98b9a5348c5cb2f10 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 2 Feb 2019 15:39:04 -0800 Subject: [PATCH 044/191] Introduce topic monitoring topic_monitor allows for querying changes posted to one or more topics, initially sigchld. This will eventually replace the waitpid logic in process_mark_finished_children(). Comment from the new header: Topic monitoring support. Topics are conceptually "a thing that can happen." For example, delivery of a SIGINT, a child process exits, etc. It is possible to post to a topic, which means that that thing happened. Associated with each topic is a current generation, which is a 64 bit value. When you query a topic, you get back a generation. If on the next query the generation has increased, then it indicates someone posted to the topic. For example, if you are monitoring a child process, you can query the sigchld topic. If it has increased since your last query, it is possible that your child process has exited. Topic postings may be coalesced. That is there may be two posts to a given topic, yet the generation only increases by 1. The only guarantee is that after a topic post, the current generation value is larger than any value previously queried. Tying this all together is the topic_monitor_t. This provides the current topic generations, and also provides the ability to perform a blocking wait for any topic to change in a particular topic set. This is the real power of topics: you can wait for a sigchld signal OR a thread exit. --- CMakeLists.txt | 2 +- Makefile.in | 2 +- src/enum_set.h | 2 +- src/fish_tests.cpp | 64 ++++++++++++++++ src/iothread.h | 1 + src/signal.cpp | 2 + src/topic_monitor.cpp | 114 +++++++++++++++++++++++++++++ src/topic_monitor.h | 165 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 349 insertions(+), 3 deletions(-) create mode 100644 src/topic_monitor.cpp create mode 100644 src/topic_monitor.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 32dee2061..eb7949f7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,7 +80,7 @@ SET(FISH_SRCS src/postfork.cpp src/proc.cpp src/reader.cpp src/sanity.cpp src/screen.cpp src/signal.cpp src/tinyexpr.cpp src/tnode.cpp src/tokenizer.cpp src/utf8.cpp src/util.cpp src/wcstringutil.cpp src/wgetopt.cpp src/wildcard.cpp src/wutil.cpp - src/future_feature_flags.cpp src/redirection.cpp + src/future_feature_flags.cpp src/redirection.cpp src/topic_monitor.cpp ) # Header files are just globbed. diff --git a/Makefile.in b/Makefile.in index eba0b41be..beb3b9253 100644 --- a/Makefile.in +++ b/Makefile.in @@ -119,7 +119,7 @@ FISH_OBJS := obj/autoload.o obj/builtin.o obj/builtin_bg.o obj/builtin_bind.o ob obj/parser_keywords.o obj/path.o obj/postfork.o obj/proc.o obj/reader.o \ obj/sanity.o obj/screen.o obj/signal.o obj/tinyexpr.o obj/tokenizer.o obj/tnode.o obj/utf8.o \ obj/util.o obj/wcstringutil.o obj/wgetopt.o obj/wildcard.o obj/wutil.o \ - obj/future_feature_flags.o obj/redirection.o + obj/future_feature_flags.o obj/redirection.o obj/topic_monitor.o FISH_INDENT_OBJS := obj/fish_indent.o obj/print_help.o $(FISH_OBJS) diff --git a/src/enum_set.h b/src/enum_set.h index ea6e90b40..22eb8c66d 100644 --- a/src/enum_set.h +++ b/src/enum_set.h @@ -29,7 +29,7 @@ class enum_set_t : private std::bitset()> { public: enum_set_t() = default; - explicit enum_set_t(T v) { set(v); } + /*implicit*/ enum_set_t(T v) { set(v); } static enum_set_t from_raw(unsigned long v) { return enum_set_t{v}; } diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 7b02115c0..dc2522784 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -69,6 +70,7 @@ #include "signal.h" #include "tnode.h" #include "tokenizer.h" +#include "topic_monitor.h" #include "utf8.h" #include "util.h" #include "wcstringutil.h" @@ -5073,6 +5075,66 @@ void test_normalize_path() { do_test(path_normalize_for_cd(L"/abc/def/", L"../ghi/..") == L"/abc/ghi/.."); } +static void test_topic_monitor() { + say(L"Testing topic monitor"); + topic_monitor_t monitor; + generation_list_t gens{}; + constexpr auto t = topic_t::sigchld; + do_test(gens[t] == 0); + do_test(monitor.generation_for_topic(t) == 0); + auto changed = monitor.check(&gens, {t}, false /* wait */); + do_test(changed.none()); + do_test(gens[t] == 0); + + monitor.post(t); + changed = monitor.check(&gens, topic_set_t{t}, true /* wait */); + do_test(changed == topic_set_t{t}); + do_test(gens[t] == 1); + do_test(monitor.generation_for_topic(t) == 1); + + monitor.post(t); + do_test(monitor.generation_for_topic(t) == 2); + changed = monitor.check(&gens, topic_set_t{t}, true /* wait */); + do_test(changed == topic_set_t{t}); +} + +static void test_topic_monitor_torture() { + say(L"Torture-testing topic monitor"); + topic_monitor_t monitor; + const size_t thread_count = 64; + constexpr auto t = topic_t::sigchld; + std::vector gens; + gens.resize(thread_count, generation_list_t{}); + std::atomic post_count{}; + for (auto &gen : gens) { + gen = monitor.current_generations(); + post_count += 1; + monitor.post(t); + } + + std::atomic completed{}; + std::vector threads; + for (size_t i = 0; i < thread_count; i++) { + threads.emplace_back( + [&](size_t i) { + for (size_t j = 0; j < (1 << 11); j++) { + auto before = gens[i]; + auto changed = monitor.check(&gens[i], topic_set_t{t}, true /* wait */); + do_test(before[t] < gens[i][t]); + do_test(gens[i][t] <= post_count); + } + auto amt = completed.fetch_add(1, std::memory_order_relaxed); + }, + i); + } + + while (completed.load(std::memory_order_relaxed) < thread_count) { + post_count += 1; + monitor.post(t); + } + for (auto &t : threads) t.join(); +} + /// Main test. int main(int argc, char **argv) { UNUSED(argc); @@ -5192,6 +5254,8 @@ int main(int argc, char **argv) { if (should_test_function("maybe")) test_maybe(); if (should_test_function("layout_cache")) test_layout_cache(); if (should_test_function("normalize")) test_normalize_path(); + if (should_test_function("topics")) test_topic_monitor(); + if (should_test_function("topics")) test_topic_monitor_torture(); // history_tests_t::test_history_speed(); say(L"Encountered %d errors in low-level tests", err_count); diff --git a/src/iothread.h b/src/iothread.h index 5e677b639..39d99e539 100644 --- a/src/iothread.h +++ b/src/iothread.h @@ -2,6 +2,7 @@ #ifndef FISH_IOTHREAD_H #define FISH_IOTHREAD_H +#include #include #include diff --git a/src/signal.cpp b/src/signal.cpp index f1ab10581..8ca202330 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -15,6 +15,7 @@ #include "parser.h" #include "proc.h" #include "reader.h" +#include "topic_monitor.h" #include "wutil.h" // IWYU pragma: keep /// Struct describing an entry for the lookup table used to convert between signal names and signal @@ -262,6 +263,7 @@ static void handle_chld(int sig, siginfo_t *info, void *context) { if (reraise_if_forked_child(sig)) return; job_handle_signal(sig, info, context); default_handler(sig, info, context); + topic_monitor_t::principal().post(topic_t::sigchld); } // We have a sigalarm handler that does nothing. This is used in the signal torture test, to verify diff --git a/src/topic_monitor.cpp b/src/topic_monitor.cpp new file mode 100644 index 000000000..2c28a7517 --- /dev/null +++ b/src/topic_monitor.cpp @@ -0,0 +1,114 @@ +#include "config.h" // IWYU pragma: keep + +#include "limits.h" +#include "topic_monitor.h" +#include "wutil.h" + +#include + +/// Implementation of the principal monitor. This uses new (and leaks) to avoid registering a +/// pointless at-exit handler for the dtor. +static topic_monitor_t *const s_principal = new topic_monitor_t(); + +topic_monitor_t &topic_monitor_t::principal() { + // Do not attempt to move s_principal to a function-level static, it needs to be accessed from a + // signal handler so it must not be lazily created. + return *s_principal; +} + +topic_monitor_t::topic_monitor_t() { + // Set up our pipes. Assert it succeeds. + auto pipes = make_autoclose_pipes({}); + assert(pipes.has_value() && "Failed to make pubsub pipes"); + pipes_ = pipes.acquire(); + + // Make sure that our write side doesn't block, else we risk hanging in a signal handler. + // The read end must block to avoid spinning in await. + DIE_ON_FAILURE(make_fd_nonblocking(pipes_.write.fd())); +} + +topic_monitor_t::~topic_monitor_t() = default; + +void topic_monitor_t::post(topic_t topic) { + // Beware, we may be in a signal handler! + // Atomically update the pending topics. + auto rawtopics = topic_set_t{topic}.to_raw(); + auto oldtopics = pending_updates_.fetch_or(rawtopics, std::memory_order_relaxed); + if ((oldtopics & rawtopics) == rawtopics) { + // No new bits were set. + return; + } + + // Ok, we changed one or more bits. Ensure the topic change is visible, and announce the change + // by writing a byte to the pipe. + std::atomic_thread_fence(std::memory_order_release); + ssize_t ret; + do { + // write() is async signal safe. + const uint8_t v = 0; + ret = write(pipes_.write.fd(), &v, sizeof v); + } while (ret < 0 && errno == EINTR); + // Ignore EAGAIN and other errors (which conceivably could occur during shutdown). +} + +void topic_monitor_t::await_metagen(generation_t mgen) { + // Fast check of the metagen before taking the lock. If it's changed we're done. + if (mgen != current_metagen()) return; + + // Take the lock (which may take a long time) and then check again. + std::unique_lock locker{wait_queue_lock_}; + if (mgen != current_metagen()) return; + + // Our metagen hasn't changed. Push our metagen onto the queue, then wait until we're the + // lowest. If multiple waiters are the lowest, then anyone can be the observer. + // Note the reason for picking the lowest metagen is to avoid a priority inversion where a lower + // metagen (therefore someone who should see changes) is blocked waiting for a higher metagen + // (who has already seen the changes). + wait_queue_.push(mgen); + while (wait_queue_.top() != mgen) { + wait_queue_notifier_.wait(locker); + } + wait_queue_.pop(); + + // We now have the lowest metagen in the wait queue. Notice we still hold the lock. + // Read until the metagen changes. It may already have changed. + // Note because changes are coalesced, we can read a lot, potentially draining the pipe. + while (mgen == current_metagen()) { + uint8_t ignored[PIPE_BUF]; + (void)read(pipes_.read.fd(), ignored, sizeof ignored); + } + + // Release the lock and wake up the remaining waiters. + locker.unlock(); + wait_queue_notifier_.notify_all(); +} + +topic_set_t topic_monitor_t::check(generation_list_t *gens, topic_set_t topics, bool wait) { + if (topics.none()) return topics; + + topic_set_t changed{}; + for (;;) { + // Load the topic list and see if anything has changed. + generation_list_t current = updated_gens(); + for (topic_t topic : topic_iter_t{}) { + if (topics.get(topic)) { + assert(gens->at(topic) <= current.at(topic) && + "Incoming gen count exceeded published count"); + if (gens->at(topic) < current.at(topic)) { + gens->at(topic) = current.at(topic); + changed.set(topic); + } + } + } + + // If we're not waiting, or something changed, then we're done. + if (!wait || changed.any()) { + break; + } + + // Try again. Note that we use the metagen corresponding to the topic list we just + // inspected, not the current one (which may have updates since we checked). + await_metagen(metagen_for(current)); + } + return changed; +} diff --git a/src/topic_monitor.h b/src/topic_monitor.h new file mode 100644 index 000000000..fb61f06e5 --- /dev/null +++ b/src/topic_monitor.h @@ -0,0 +1,165 @@ +#ifndef FISH_TOPIC_MONITOR_H +#define FISH_TOPIC_MONITOR_H + +#include "common.h" +#include "enum_set.h" +#include "io.h" + +#include +#include +#include +#include +#include +#include +#include + +/** Topic monitoring support. Topics are conceptually "a thing that can happen." For example, + delivery of a SIGINT, a child process exits, etc. It is possible to post to a topic, which means + that that thing happened. + + Associated with each topic is a current generation, which is a 64 bit value. When you query a + topic, you get back a generation. If on the next query the generation has increased, then it + indicates someone posted to the topic. + + For example, if you are monitoring a child process, you can query the sigchld topic. If it has + increased since your last query, it is possible that your child process has exited. + + Topic postings may be coalesced. That is there may be two posts to a given topic, yet the + generation only increases by 1. The only guarantee is that after a topic post, the current + generation value is larger than any value previously queried. + + Tying this all together is the topic_monitor_t. This provides the current topic generations, and + also provides the ability to perform a blocking wait for any topic to change in a particular topic + set. This is the real power of topics: you can wait for a sigchld signal OR a thread exit. + */ + +/// The list of topics that may be observed. +enum class topic_t : uint8_t { + sigchld, // Corresponds to SIGCHLD signal. + COUNT +}; + +/// Allow enum_iter to be used. +template <> +struct enum_info_t { + static constexpr auto count = topic_t::COUNT; +}; + +/// Set of topics. +using topic_set_t = enum_set_t; + +/// Counting iterator for topics. +using topic_iter_t = enum_iter_t; + +/// A generation is a counter incremented every time the value of a topic changes. +/// It is 64 bit so it will never wrap. +using generation_t = uint64_t; + +/// A generation value which is guaranteed to never be set and be larger than any valid generation. +constexpr generation_t invalid_generation = std::numeric_limits::max(); + +/// List of generation values, indexed by topics. +/// The initial value of a generation is always 0. +using generation_list_t = enum_array_t; + +/// Teh topic monitor class. This permits querying the current generation values for topics, +/// optionally blocking until they increase. +class topic_monitor_t { + private: + using topic_set_raw_t = uint8_t; + + static_assert(sizeof(topic_set_raw_t) * CHAR_BIT >= enum_count(), + "topic_set_raw is too small"); + + /// The current topic generation list, protected by a mutex. Note this may be opportunistically + /// updated at the point it is queried. + owning_lock current_gen_{{}}; + + /// The set of topics which have pending increments. + /// This is managed via atomics. + std::atomic pending_updates_{}; + + /// When a topic set is queried in a blocking way, the waiters are put into a queue. The waiter + /// with the smallest metagen is responsible for announcing the change to the rest of the + /// waiters. (The metagen is just the sum of the current generations.) Note that this is a + /// max-heap that defaults to std::less; by using std::greater it becomes a min heap. This is + /// protected by wait_queue_lock_. + std::priority_queue, std::greater> + wait_queue_; + + /// Mutex guarding the wait queue. + std::mutex wait_queue_lock_{}; + + /// Condition variable for broadcasting notifications. + std::condition_variable wait_queue_notifier_{}; + + /// Pipes used to communicate changes from the signal handler. + autoclose_pipes_t pipes_; + + /// \return the metagen for a topic generation list. + /// The metagen is simply the sum of topic generations. Note it is monotone. + static inline generation_t metagen_for(const generation_list_t &lst) { + return std::accumulate(lst.begin(), lst.end(), generation_t{0}); + } + + /// Wait for the current metagen to become different from \p gen. + /// If it is already different, return immediately. + void await_metagen(generation_t gen); + + /// Return the current generation list, opportunistically applying any pending updates. + generation_list_t updated_gens() { + auto current_gens = current_gen_.acquire(); + + // Atomically acquire the pending updates, swapping in 0. + // If there are no pending updates (likely), just return. + // Otherwise CAS in 0 and update our topics. + const auto relaxed = std::memory_order_relaxed; + topic_set_raw_t raw; + bool cas_success; + do { + raw = pending_updates_.load(relaxed); + if (raw == 0) return *current_gens; + cas_success = pending_updates_.compare_exchange_weak(raw, 0, relaxed, relaxed); + } while (!cas_success); + + // Update the current generation with our topics and return it. + auto topics = topic_set_t::from_raw(raw); + for (topic_t topic : topic_iter_t{}) { + current_gens->at(topic) += topics.get(topic) ? 1 : 0; + } + return *current_gens; + } + + /// \return the metagen for the current topic generation list. + inline generation_t current_metagen() { return metagen_for(updated_gens()); } + + public: + topic_monitor_t(); + ~topic_monitor_t(); + + /// topic_monitors should not be copied, and there should be no reason to move one. + void operator=(const topic_monitor_t &) = delete; + topic_monitor_t(const topic_monitor_t &) = delete; + void operator=(topic_monitor_t &&) = delete; + topic_monitor_t(topic_monitor_t &&) = delete; + + /// The principal topic_monitor. This may be fetched from a signal handler. + static topic_monitor_t &principal(); + + /// Post to a topic, potentially from a signal handler. + void post(topic_t topic); + + /// Access the current generations. + generation_list_t current_generations() { return updated_gens(); } + + /// Access the generation for a topic. + generation_t generation_for_topic(topic_t topic) { return current_generations().at(topic); } + + /// See if for any topic (specified in \p topics) has changed from the values in the generation + /// list \p gens. If \p wait is set, then wait if there are no changes; otherwise return + /// immediately. + /// \return the set of topics that changed, updating the generation list \p gens. + topic_set_t check(generation_list_t *gens, topic_set_t topics, bool wait); +}; + +#endif From a4dc04a28e577a13f3748a0193c5e2d5d3792b36 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Thu, 14 Feb 2019 20:55:43 -0800 Subject: [PATCH 045/191] Add sighupint topic This corresponds to SIGHUP and SIGINT. This will be used to break out of process_mark_finished_children(). --- src/enum_set.h | 4 ++++ src/fish_tests.cpp | 14 ++++++++------ src/signal.cpp | 2 ++ src/topic_monitor.h | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/enum_set.h b/src/enum_set.h index 22eb8c66d..cbec399d0 100644 --- a/src/enum_set.h +++ b/src/enum_set.h @@ -31,6 +31,10 @@ class enum_set_t : private std::bitset()> { /*implicit*/ enum_set_t(T v) { set(v); } + /*implicit*/ enum_set_t(std::initializer_list vs) { + for (T v : vs) set(v); + } + static enum_set_t from_raw(unsigned long v) { return enum_set_t{v}; } unsigned long to_raw() const { return super::to_ulong(); } diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index dc2522784..538b05ebd 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -5102,14 +5102,15 @@ static void test_topic_monitor_torture() { say(L"Torture-testing topic monitor"); topic_monitor_t monitor; const size_t thread_count = 64; - constexpr auto t = topic_t::sigchld; + constexpr auto t1 = topic_t::sigchld; + constexpr auto t2 = topic_t::sighupint; std::vector gens; gens.resize(thread_count, generation_list_t{}); std::atomic post_count{}; for (auto &gen : gens) { gen = monitor.current_generations(); post_count += 1; - monitor.post(t); + monitor.post(t1); } std::atomic completed{}; @@ -5119,9 +5120,10 @@ static void test_topic_monitor_torture() { [&](size_t i) { for (size_t j = 0; j < (1 << 11); j++) { auto before = gens[i]; - auto changed = monitor.check(&gens[i], topic_set_t{t}, true /* wait */); - do_test(before[t] < gens[i][t]); - do_test(gens[i][t] <= post_count); + auto changed = monitor.check(&gens[i], topic_set_t{t1, t2}, true /* wait */); + do_test(before[t1] < gens[i][t1]); + do_test(gens[i][t1] <= post_count); + do_test(gens[i][t2] == 0); } auto amt = completed.fetch_add(1, std::memory_order_relaxed); }, @@ -5130,7 +5132,7 @@ static void test_topic_monitor_torture() { while (completed.load(std::memory_order_relaxed) < thread_count) { post_count += 1; - monitor.post(t); + monitor.post(t1); } for (auto &t : threads) t.join(); } diff --git a/src/signal.cpp b/src/signal.cpp index 8ca202330..927eb2dae 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -231,6 +231,7 @@ static void handle_hup(int sig, siginfo_t *info, void *context) { } else { reader_exit(1, 1); } + topic_monitor_t::principal().post(topic_t::sighupint); } /// Handle sigterm. The only thing we do is restore the front process ID, then die. @@ -249,6 +250,7 @@ static void handle_int(int sig, siginfo_t *info, void *context) { if (reraise_if_forked_child(sig)) return; reader_handle_sigint(); default_handler(sig, info, context); + topic_monitor_t::principal().post(topic_t::sighupint); } /// Non-interactive ^C handler. diff --git a/src/topic_monitor.h b/src/topic_monitor.h index fb61f06e5..f74c900ec 100644 --- a/src/topic_monitor.h +++ b/src/topic_monitor.h @@ -35,7 +35,8 @@ /// The list of topics that may be observed. enum class topic_t : uint8_t { - sigchld, // Corresponds to SIGCHLD signal. + sigchld, // Corresponds to SIGCHLD signal. + sighupint, // Corresponds to both SIGHUP and SIGINT signals. COUNT }; From a95bc849c57d02e4bc2b3b04dc504a2d14de9fd8 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Feb 2019 17:39:14 -0800 Subject: [PATCH 046/191] Rewrite process_mark_finished_children using topics This is a big change to how process reaping works, reimplenting it using topics. The idea is to simplify the logic in process_mark_finished_children around blocking, and also prepare for "internal processes" which do not correspond to real processes. Before this change, fish would use waitpid() to wait for a process group, OR would individually poll processes if the process group leader was unreapable. After this change, fish no longer ever calls blocking waitpid(). Instead fish uses the topic mechanism. For each reapable process, fish checks if it has received a SIGCHLD since last poll; if not it waits until the next SIGCHLD, and then polls them all. --- src/proc.cpp | 243 +++++++++---------------------------------------- src/proc.h | 23 ++++- src/signal.cpp | 1 - 3 files changed, 63 insertions(+), 204 deletions(-) diff --git a/src/proc.cpp b/src/proc.cpp index c52cf09dd..0561a60d4 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -361,194 +361,59 @@ void add_disowned_pgid(pid_t pgid) { } } -/// A static value tracking how many SIGCHLDs we have seen, which is used in a heurstic to -/// determine if we should call waitpid() at all in `process_mark_finished_children`. -static volatile process_generation_count_t s_sigchld_generation_cnt = 0; - -/// See if any children of a fully constructed job have exited or been killed, and mark them -/// accordingly. We cannot reap just any child that's exited, (as in, `waitpid(-1,…`) since -/// that may reap a pgrp leader that has exited but in a job with another process that has yet to -/// launch and join its pgrp (#5219). -/// \param block_on_fg when true, blocks waiting for the foreground job to finish. -/// \return whether the operation completed without incident -static bool process_mark_finished_children(bool block_on_fg) { +/// See if any reapable processes have exited, and mark them accordingly. +/// \param block_ok if no reapable processes have exited, block until one is (or until we receive a +/// signal). +static void process_mark_finished_children(bool block_ok) { ASSERT_IS_MAIN_THREAD(); - // We can't always use SIGCHLD to determine if waitpid() should be called since it is not - // strictly one-SIGCHLD-per-one-child-exited (i.e. multiple exits can share a SIGCHLD call) and - // we a) return immediately the first time a dead child is reaped, b) explicitly skip over jobs - // that aren't yet fully constructed, so it's possible that we can get SIGCHLD and even find a - // killed child in the jobs we are reaping, but also have an exited child process in a job that - // hasn't been fully constructed yet - which means we can end up never knowing about the exited - // child process in that job if we use SIGCHLD count as the only metric for whether or not - // waitpid() is called. - // Without this optimization, the slowdown caused by calling waitpid() even just once each time - // `process_mark_finished_children()` is called is rather obvious (see the performance-related - // discussion in #5219), making it worth the complexity of this heuristic. - - /// Tracks whether or not we received SIGCHLD without checking all jobs (due to jobs under - /// construction), forcing a full waitpid loop. - static bool dirty_state = true; - static process_generation_count_t last_sigchld_count = -1; - - // If the last time that we received a SIGCHLD we did not waitpid all jobs, we cannot early out. - if (!dirty_state && last_sigchld_count == s_sigchld_generation_cnt) { - // If we have foreground jobs, we need to block on them below - if (!block_on_fg) { - // We can assume that no children have exited and that all waitpid calls with - // WNOHANG below will confirm that. - return true; + // Get the exit and signal generations of all reapable processes. + // The exit generation tells us if we have an exit; the signal generation allows for detecting + // SIGHUP and SIGINT. + generation_list_t gens{}; + gens.fill(invalid_generation); + job_iterator_t jobs; + while (auto *j = jobs.next()) { + for (const auto &proc : j->processes) { + if (j->can_reap(proc.get())) { + gens[topic_t::sigchld] = + std::min(gens[topic_t::sigchld], proc->gens_[topic_t::sigchld]); + gens[topic_t::sighupint] = + std::min(gens[topic_t::sighupint], proc->gens_[topic_t::sighupint]); + } } } - last_sigchld_count = s_sigchld_generation_cnt; - bool jobs_skipped = false; - bool has_error = false; - job_t *job_fg = nullptr; + if (gens[topic_t::sigchld] == invalid_generation) { + // No reapable processes, nothing to wait for. + return; + } - // Reap only processes belonging to fully-constructed jobs to prevent reaping of processes - // before others in the same process group have a chance to join their pgrp. - job_iterator_t jobs; - while (auto j = jobs.next()) { - // (A job can have pgrp INVALID_PID if it consists solely of builtins that perform no IO) - if (j->pgid == INVALID_PID || !j->is_constructed()) { - debug(5, "Skipping wait on incomplete job %d (%ls)", j->job_id, j->preview().c_str()); - jobs_skipped = true; - continue; - } + // Now check for changes, optionally waiting. + topic_set_t topics{{topic_t::sigchld, topic_t::sighupint}}; + auto changed_topics = topic_monitor_t::principal().check(&gens, topics, block_ok); + if (changed_topics.none()) return; - if (j != job_fg && j->is_foreground() && !j->is_stopped() && !j->is_completed()) { - // Ensure that we don't have multiple fully constructed foreground jobs. - assert((!job_fg || !job_fg->job_chain_is_fully_constructed() || - !j->job_chain_is_fully_constructed()) && - "More than one active, fully-constructed foreground job!"); - job_fg = j; - } + // We got some changes. Since we last checked we received SIGCHLD, and or HUP/INT. + // Update the hup/int generations and reap any reapable processes. + jobs.reset(); + while (auto *j = jobs.next()) { + for (auto &proc : j->processes) { + // Update the signalhupint generation so we don't break on old sighupints. + proc->gens_[topic_t::sighupint] = gens[topic_t::sighupint]; - // Whether we will wait for uncompleted processes depends on the combination of - // `block_on_fg` and the nature of the process. Default is WNOHANG, but if foreground, - // constructed, not stopped, *and* block_on_fg is true, then no WNOHANG (i.e. "HANG"). - int options = WUNTRACED | WNOHANG; - - // We should never block twice in the same go, as `waitpid()' returning could mean one - // process completed or many, and there is a race condition when calling `waitpid()` after - // the process group exits having reaped all children and terminated the process group and - // when a subsequent call to `waitpid()` for the same process group returns immediately if - // that process group no longer exists. i.e. it's possible for all processes to have exited - // but the process group to remain momentarily valid, in which case calling `waitpid()` - // without WNOHANG can cause an infinite wait. Additionally, only wait on external jobs that - // spawned new process groups (i.e. JOB_CONTROL). We do not break or return on error as we - // wait on only one pgrp at a time and we need to check all pgrps before returning, but we - // never wait/block on fg processes after an error has been encountered to give ourselves - // (elsewhere) a chance to handle the fallout from process termination, etc. - if (!has_error && block_on_fg && j == job_fg) { - debug(4, "Waiting on processes from foreground job %d", job_fg->pgid); - options &= ~WNOHANG; - } - - // Child jobs (produced via execution of functions) share job ids with their not-yet- - // fully-constructed parent jobs, so we have to wait on these by individual process id - // and not by the shared pgroup. End result is the same, but it just makes more calls - // to the kernel. - bool wait_by_process = !j->job_chain_is_fully_constructed(); - - // Firejail can result in jobs with pgroup 0, in which case we cannot wait by - // job id. See discussion in #5295. - if (j->pgid == 0) { - wait_by_process = true; - } - - // Cygwin does some voodoo with regards to process management that I do not understand, but - // long story short, we cannot reap processes by their pgroup. The way child processes are - // launched under Cygwin is... weird, and outwardly they do not appear to retain information - // about their parent process when viewed in Task Manager. Waiting on processes by their - // pgroup results in never reaping any, so we just wait on them by process id instead. - if (is_cygwin()) { - wait_by_process = true; - } - - // When waiting on processes individually in a pipeline, we need to enumerate in reverse - // order so that the first process we actually wait on (i.e. ~WNOHANG) is the last process - // in the IO chain, because that's the one that controls the lifetime of the foreground job - // - as long as it is still running, we are in the background and once it exits or is - // killed, all previous jobs in the IO pipeline must necessarily terminate as well. - auto process = j->processes.rbegin(); - // waitpid(2) returns 1 process each time, we need to keep calling it until we've reaped all - // children of the pgrp in question or else we can't reset the dirty_state flag. In all - // cases, calling waitpid(2) is faster than potentially calling select_try() on a process - // that has exited, which will force us to wait the full timeout before coming back here and - // calling waitpid() again. - while (true) { - int status; - pid_t pid; - - if (wait_by_process) { - // If the evaluation of a function resulted in the sharing of a pgroup between the - // real job and the job that shouldn't have been created as a separate job AND the - // parent job is still under construction (which is the case when continue_job() is - // first called on the child job during the recursive call to exec_job() before the - // parent job has been fully constructed), we need to call waitpid(2) on the - // individual processes of the child job instead of using a catch-all waitpid(2) - // call on the job's process group. - if (process == j->processes.rend()) { - break; - } - assert((*process)->pid != INVALID_PID && "Waiting by process on an invalid PID!"); - if ((*process)->completed) { - // This process has already been waited on to completion - process++; - continue; - } - - if ((options & WNOHANG) == 0) { - debug(4, "Waiting on individual process %d: %ls", (*process)->pid, (*process)->argv0()); - } else { - debug(4, "waitpid with WNOHANG on individual process %d", (*process)->pid); - } - pid = waitpid((*process)->pid, &status, options); - - process++; - } else { - // A negative PID passed in to `waitpid()` means wait on any child in that process - // group - pid = waitpid(-1 * j->pgid, &status, options); - } - - if (pid > 0) { - // A child process has been reaped - debug(4, "Reaped PID %d", pid); - handle_child_status(pid, status); - - // Always set WNOHANG (that is, don't hang). Otherwise we might wait on a non-stopped job - // that becomes stopped, but we don't refresh our view of the process state before - // calling waitpid(2) again here. - options |= WNOHANG; - } else if (pid == 0 || errno == ECHILD) { - // No killed/dead children in this particular process group - if (!wait_by_process) { - if ((options & WNOHANG) == 0) { - // This normally implies that the job has completed, but if we try to wait - // on a job that includes a process that changed its own group before we - // enter `waitpid`, we will be waiting forever. See #5596 for such a case. - wait_by_process = true; - continue; + // Try reaping processes whose sigchld count is below what was returned. + if (changed_topics.get(topic_t::sigchld)) { + if (j->can_reap(proc.get()) && + proc->gens_[topic_t::sigchld] < gens[topic_t::sigchld]) { + proc->gens_[topic_t::sigchld] = gens[topic_t::sigchld]; + int status = 0; + auto pid = waitpid(proc->pid, &status, WNOHANG | WUNTRACED); + if (pid > 0) { + debug(4, "Reaped PID %d", pid); + handle_child_status(pid, status); } - break; } - } else { - // pid < 0 indicates an error. One likely failure is ECHILD (no children), which is - // not an error and is ignored in the branch above. The other likely failure is - // EINTR, which means we got a signal, which is considered an error. We absolutely - // do not break or return on error, as we need to iterate over all constructed jobs - // but we only call waitpid for one pgrp at a time. We do bypass future waits in - // case of error, however. - has_error = true; - - // Do not audibly complain on interrupt (see #5293) - if (errno != EINTR) { - wperror(L"waitpid in process_mark_finished_children"); - } - break; } } } @@ -559,28 +424,6 @@ static bool process_mark_finished_children(bool block_on_fg) { s_disowned_pids.erase(std::remove_if(s_disowned_pids.begin(), s_disowned_pids.end(), [&status](pid_t pid) { return waitpid(pid, &status, WNOHANG) > 0; }), s_disowned_pids.end()); - - // Yes, the below can be collapsed to a single line, but it's worth being explicit about it with - // the comments. Fret not, the compiler will optimize it. (It better!) - if (jobs_skipped) { - // We received SIGCHLD but were not able to definitely say whether or not all children were - // reaped. - dirty_state = true; - } else { - // We can safely assume that no SIGCHLD means we can just return next time around - dirty_state = false; - } - - return !has_error; -} - -/// This is called from a signal handler. The signal is always SIGCHLD. -void job_handle_signal(int signal, siginfo_t *info, void *context) { - UNUSED(signal); - UNUSED(info); - UNUSED(context); - // This is the only place that this generation count is modified. It's OK if it overflows. - s_sigchld_generation_cnt += 1; } /// Given a command like "cat file", truncate it to a reasonable length. diff --git a/src/proc.h b/src/proc.h index 03472029d..170346ea1 100644 --- a/src/proc.h +++ b/src/proc.h @@ -20,6 +20,7 @@ #include "io.h" #include "parse_tree.h" #include "tnode.h" +#include "topic_monitor.h" /// Types of processes. enum process_type_t { @@ -114,6 +115,10 @@ class process_t { /// Actual command to pass to exec in case of EXTERNAL or INTERNAL_EXEC. wcstring actual_cmd; + + /// Generation counts for reaping. + generation_list_t gens_{}; + /// Process ID pid_t pid{0}; /// File descriptor that pipe output should bind to. @@ -200,6 +205,21 @@ class job_t { /// Sets the command. void set_command(const wcstring &cmd) { command_str = cmd; } + /// \return whether it is OK to reap a given process. Sometimes we want to defer reaping a + /// process if it is the group leader and the job is not yet constructed, because then we might + /// also reap the process group and then we cannot add new processes to the group. + bool can_reap(const process_t *p) const { + if (p->pid <= 0) { + // Can't reap without a pid. + return false; + } + if (!is_constructed() && pgid > 0 && p->pid == pgid) { + // p is the the group leader in an under-construction job. + return false; + } + return true; + } + /// Returns a truncated version of the job string. Used when a message has already been emitted /// containing the full job string and job id, but using the job id alone would be confusing /// due to reuse of freed job ids. Prevents overloading the debug comments with the full, @@ -359,9 +379,6 @@ int proc_get_last_status(); /// \param interactive whether interactive jobs should be reaped as well bool job_reap(bool interactive); -/// Signal handler for SIGCHLD. Mark any processes with relevant information. -void job_handle_signal(int signal, siginfo_t *info, void *con); - /// Mark a process as failed to execute (and therefore completed). void job_mark_process_as_failed(const std::shared_ptr &job, const process_t *p); diff --git a/src/signal.cpp b/src/signal.cpp index 927eb2dae..8c2886650 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -263,7 +263,6 @@ static void handle_int_notinteractive(int sig, siginfo_t *info, void *context) { /// sigchld handler. Does notification and calls the handler in proc.c. static void handle_chld(int sig, siginfo_t *info, void *context) { if (reraise_if_forked_child(sig)) return; - job_handle_signal(sig, info, context); default_handler(sig, info, context); topic_monitor_t::principal().post(topic_t::sigchld); } From ebe2dc2766cff306f7e2d4b9ebfd851dba038f00 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Feb 2019 17:35:16 -0800 Subject: [PATCH 047/191] Processes to record topic generations before execution The sigchld generation expresses the idea that, if we receive a sigchld signal, the generation will be different than when we last recorded it. A process cannot exit before it has launched, so check the generation count before process launch. This is an optimization that reduces failing waitpid calls. --- src/exec.cpp | 1 + src/proc.cpp | 6 +++++- src/proc.h | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/exec.cpp b/src/exec.cpp index bf311bb74..c9d662464 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -899,6 +899,7 @@ static bool exec_process_in_job(parser_t &parser, process_t *p, std::shared_ptr< } // Execute the process. + p->check_generations_before_launch(); switch (p->type) { case INTERNAL_FUNCTION: case INTERNAL_BLOCK_NODE: { diff --git a/src/proc.cpp b/src/proc.cpp index 0561a60d4..667d76ace 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -324,7 +324,11 @@ static void handle_child_status(pid_t pid, int status) { } } -process_t::process_t() {} +process_t::process_t() = default; + +void process_t::check_generations_before_launch() { + gens_ = topic_monitor_t::principal().current_generations(); +} job_t::job_t(job_id_t jobid, io_chain_t bio, std::shared_ptr parent) : block_io(std::move(bio)), diff --git a/src/proc.h b/src/proc.h index 170346ea1..7379bd065 100644 --- a/src/proc.h +++ b/src/proc.h @@ -113,6 +113,11 @@ class process_t { void set_io_chain(const io_chain_t &chain) { this->process_io_chain = chain; } + /// Store the current topic generations. That is, right before the process is launched, record + /// the generations of all topics; then we can tell which generation values have changed after + /// launch. This helps us avoid spurious waitpid calls. + void check_generations_before_launch(); + /// Actual command to pass to exec in case of EXTERNAL or INTERNAL_EXEC. wcstring actual_cmd; From 061f8f49c6cec400599d41c295598642706a252e Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 2 Feb 2019 12:52:51 -0800 Subject: [PATCH 048/191] Add dup2_list_t::fd_for_target_fd This adds an "in-process" interpretation of dup2s, allowing for fish to output directly to the correct file descriptor without having to perform an in-kernel dup2 sequence. --- src/fish_tests.cpp | 25 +++++++++++++++++++++++++ src/redirection.cpp | 20 ++++++++++++++++++++ src/redirection.h | 5 +++++ 3 files changed, 50 insertions(+) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 538b05ebd..5f83e1c06 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2422,6 +2422,30 @@ static void test_dup2s() { do_test(!list.has_value()); } +static void test_dup2s_fd_for_target_fd() { + using std::make_shared; + io_chain_t chain; + // note io_fd_t params are backwards from dup2. + chain.push_back(make_shared(10)); + chain.push_back(make_shared(9, 10, true)); + chain.push_back(make_shared(5, 8, true)); + chain.push_back(make_shared(1, 4, true)); + chain.push_back(make_shared(3, 5, true)); + auto list = dup2_list_t::resolve_chain(chain); + + do_test(list.has_value()); + do_test(list->fd_for_target_fd(3) == 8); + do_test(list->fd_for_target_fd(5) == 8); + do_test(list->fd_for_target_fd(8) == 8); + do_test(list->fd_for_target_fd(1) == 4); + do_test(list->fd_for_target_fd(4) == 4); + do_test(list->fd_for_target_fd(100) == 100); + do_test(list->fd_for_target_fd(0) == 0); + do_test(list->fd_for_target_fd(-1) == -1); + do_test(list->fd_for_target_fd(9) == -1); + do_test(list->fd_for_target_fd(10) == -1); +} + /// Testing colors. static void test_colors() { say(L"Testing colors"); @@ -5223,6 +5247,7 @@ int main(int argc, char **argv) { if (should_test_function("test")) test_test(); if (should_test_function("wcstod")) test_wcstod(); if (should_test_function("dup2s")) test_dup2s(); + if (should_test_function("dup2s")) test_dup2s_fd_for_target_fd(); if (should_test_function("path")) test_path(); if (should_test_function("pager_navigation")) test_pager_navigation(); if (should_test_function("pager_layout")) test_pager_layout(); diff --git a/src/redirection.cpp b/src/redirection.cpp index 64acdda23..c0c1b6985 100644 --- a/src/redirection.cpp +++ b/src/redirection.cpp @@ -88,3 +88,23 @@ maybe_t dup2_list_t::resolve_chain(const io_chain_t &io_chain) { } return {std::move(result)}; } + +int dup2_list_t::fd_for_target_fd(int target) const { + // Paranoia. + if (target < 0) { + return target; + } + // Note we can simply walk our action list backwards, looking for src -> target dups. + int cursor = target; + for (auto iter = actions_.rbegin(); iter != actions_.rend(); ++iter) { + if (iter->target == cursor) { + // cursor is replaced by iter->src + cursor = iter->src; + } else if (iter->src == cursor && iter->target < 0) { + // cursor is closed. + cursor = -1; + break; + } + } + return cursor; +} diff --git a/src/redirection.h b/src/redirection.h index 64fd60043..16e8c155b 100644 --- a/src/redirection.h +++ b/src/redirection.h @@ -60,6 +60,11 @@ class dup2_list_t { /// The result contains the list of fd actions (dup2 and close), as well as the list /// of fds opened. static maybe_t resolve_chain(const io_chain_t &); + + /// \return the fd ultimately dup'd to a target fd, or -1 if the target is closed. + /// For example, if target fd is 1, and we have a dup2 chain 5->3 and 3->1, then we will return 5. + /// If the target is not referenced in the chain, returns target. + int fd_for_target_fd(int target) const; }; #endif From ada8ea954e0891b9aab9fc8310ba9393aa606ad2 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 13 Feb 2019 15:17:07 -0800 Subject: [PATCH 049/191] Use "internal" processes to write buffered output This introduces "internal processes" which are backed by a pthread instead of a normal process. Internal processes are reaped using the topic machinery, plugging in neatly alongside the sigchld topic; this means that process_mark_finished_children() can wait for internal and external processes simultaneously. Initially internal processes replace the forked process that fish uses to write out the output of blocks and functions. --- src/common.h | 6 +++ src/exec.cpp | 106 ++++++++++++++++++++++++++++++++------------ src/fish_tests.cpp | 2 +- src/io.cpp | 3 +- src/proc.cpp | 60 +++++++++++++++++-------- src/proc.h | 44 ++++++++++++++++-- src/topic_monitor.h | 5 ++- 7 files changed, 171 insertions(+), 55 deletions(-) diff --git a/src/common.h b/src/common.h index 1433ad151..b74d6d98d 100644 --- a/src/common.h +++ b/src/common.h @@ -307,6 +307,12 @@ void vec_append(std::vector &receiver, std::vector &&donator) { std::make_move_iterator(donator.end())); } +/// Move an object into a shared_ptr. +template +std::shared_ptr move_to_sharedptr(T &&v) { + return std::make_shared(std::move(v)); +} + /// Print a stack trace to stderr. void show_stackframe(const wchar_t msg_level, int frame_count = 100, int skip_levels = 0); diff --git a/src/exec.cpp b/src/exec.cpp index c9d662464..dfd7cf8ef 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -34,6 +34,7 @@ #include "fallback.h" // IWYU pragma: keep #include "function.h" #include "io.h" +#include "iothread.h" #include "parse_tree.h" #include "parser.h" #include "postfork.h" @@ -55,16 +56,6 @@ /// Base open mode to pass to calls to open. #define OPEN_MASK 0666 -/// Called in a forked child. -static void exec_write_and_exit(int fd, const char *buff, size_t count, int status) { - if (write_loop(fd, buff, count) == -1) { - debug(0, WRITE_ERROR); - wperror(L"write"); - exit_without_destructors(status); - } - exit_without_destructors(status); -} - void exec_close(int fd) { ASSERT_IS_MAIN_THREAD(); @@ -361,6 +352,80 @@ static void on_process_created(const std::shared_ptr &j, pid_t child_pid) } } +/// Construct an internal process for the process p. In the background, write the data \p outdata to +/// stdout, respecting the io chain \p ios. For example if target_fd is 1 (stdout), and there is a +/// dup2 3->1, then we need to write to fd 3. Then exit the internal process. +static bool run_internal_process(process_t *p, std::string outdata, io_chain_t ios) { + p->check_generations_before_launch(); + + // We want both the dup2s and the io_chain_ts to be kept alive by the background thread, because + // they may own an fd that we want to write to. Move them all to a shared_ptr. The strings as + // well (they may be long). + // Construct a little helper struct to make it simpler to move into our closure without copying. + struct write_fields_t { + int src_outfd{-1}; + std::string outdata{}; + + io_chain_t ios{}; + maybe_t dup2s{}; + std::shared_ptr internal_proc{}; + + int success_status{}; + + bool skip_out() const { return outdata.empty() || src_outfd < 0; } + }; + + auto f = std::make_shared(); + f->outdata = std::move(outdata); + + // Construct and assign the internal process to the real process. + p->internal_proc_ = std::make_shared(); + f->internal_proc = p->internal_proc_; + + // Resolve the IO chain. + // Note it's important we do this even if we have no out or err data, because we may have been + // asked to truncate a file (e.g. `echo -n '' > /tmp/truncateme.txt'). The open() in the dup2 + // list resolution will ensure this happens. + f->dup2s = dup2_list_t::resolve_chain(ios); + if (!f->dup2s) { + return false; + } + + // Figure out which source fds to write to. If they are closed (unlikely) we just exit + // successfully. + f->src_outfd = f->dup2s->fd_for_target_fd(STDOUT_FILENO); + + // If we have nothing to right we can elide the thread. + // TODO: support eliding output to /dev/null. + if (f->skip_out()) { + f->internal_proc->mark_exited(EXIT_SUCCESS); + return true; + } + + // Ensure that ios stays alive, it may own fds. + f->ios = ios; + + // If our process is a builtin, it will have already set its status value. Make sure we + // propagate that if our I/O succeeds and don't read it on a background thread. TODO: have + // builtin_run provide this directly, rather than setting it in the process. + f->success_status = p->status; + + iothread_perform([f]() { + int status = f->success_status; + if (!f->skip_out()) { + ssize_t ret = write_loop(f->src_outfd, f->outdata.data(), f->outdata.size()); + if (ret < 0) { + if (errno != EPIPE) { + wperror(L"write"); + } + if (!status) status = 1; + } + } + f->internal_proc->mark_exited(status); + }); + return true; +} + /// Call fork() as part of executing a process \p p in a job \j. Execute \p child_action in the /// context of the child. Returns true if fork succeeded, false if fork failed. static bool fork_child_for_process(const std::shared_ptr &job, process_t *p, @@ -784,24 +849,9 @@ static bool exec_block_or_func_process(parser_t &parser, std::shared_ptr io_chain.remove(block_output_bufferfill); auto block_output_buffer = io_bufferfill_t::finish(std::move(block_output_bufferfill)); - // Resolve our IO chain to a sequence of dup2s. - auto dup2s = dup2_list_t::resolve_chain(io_chain); - if (!dup2s) { - return false; - } - - const std::string buffer_contents = block_output_buffer->buffer().newline_serialized(); - const char *buffer = buffer_contents.data(); - size_t count = buffer_contents.size(); - if (count > 0) { - // We don't have to drain threads here because our child process is simple. - const char *fork_reason = - p->type == INTERNAL_BLOCK_NODE ? "internal block io" : "internal function io"; - if (!fork_child_for_process(j, p, *dup2s, false, fork_reason, [&] { - exec_write_and_exit(STDOUT_FILENO, buffer, count, status); - })) { - return false; - } + std::string buffer_contents = block_output_buffer->buffer().newline_serialized(); + if (!buffer_contents.empty()) { + return run_internal_process(p, std::move(buffer_contents), io_chain); } else { if (p->is_last_in_job) { proc_set_last_status(j->get_flag(job_flag_t::NEGATE) ? (!status) : status); diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 5f83e1c06..351e49a77 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -5106,7 +5106,7 @@ static void test_topic_monitor() { constexpr auto t = topic_t::sigchld; do_test(gens[t] == 0); do_test(monitor.generation_for_topic(t) == 0); - auto changed = monitor.check(&gens, {t}, false /* wait */); + auto changed = monitor.check(&gens, topic_set_t{t}, false /* wait */); do_test(changed.none()); do_test(gens[t] == 0); diff --git a/src/io.cpp b/src/io.cpp index 6f72c3eb0..67a9c03d5 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -13,6 +13,7 @@ #include "fallback.h" // IWYU pragma: keep #include "io.h" #include "iothread.h" +#include "redirection.h" #include "wutil.h" // IWYU pragma: keep io_data_t::~io_data_t() = default; @@ -122,7 +123,7 @@ void io_buffer_t::begin_background_fillthread(autoclose_fd_t fd) { // We want our background thread to own the fd but it's not easy to move into a std::function. // Use a shared_ptr. - auto fdref = std::make_shared(std::move(fd)); + auto fdref = move_to_sharedptr(std::move(fd)); // Our function to read until the receiver is closed. // It's OK to capture 'this' by value because 'this' owns the background thread and joins it diff --git a/src/proc.cpp b/src/proc.cpp index 667d76ace..a8ebc4793 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -247,6 +247,13 @@ bool job_t::signal(int signal) { return true; } +void internal_proc_t::mark_exited(int status) { + assert(!exited() && "Process is already exited"); + exited_.store(true, std::memory_order_relaxed); + status_.store(status, std::memory_order_release); + topic_monitor_t::principal().post(topic_t::internal_exit); +} + static void mark_job_complete(const job_t *j) { for (auto &p : j->processes) { p->completed = 1; @@ -374,48 +381,63 @@ static void process_mark_finished_children(bool block_ok) { // Get the exit and signal generations of all reapable processes. // The exit generation tells us if we have an exit; the signal generation allows for detecting // SIGHUP and SIGINT. + // Get the gen count of all reapable processes. + topic_set_t reaptopics{}; generation_list_t gens{}; gens.fill(invalid_generation); job_iterator_t jobs; while (auto *j = jobs.next()) { for (const auto &proc : j->processes) { - if (j->can_reap(proc.get())) { - gens[topic_t::sigchld] = - std::min(gens[topic_t::sigchld], proc->gens_[topic_t::sigchld]); + if (auto mtopic = j->reap_topic_for_process(proc.get())) { + topic_t topic = *mtopic; + reaptopics.set(topic); + gens[topic] = std::min(gens[topic], proc->gens_[topic]); + + reaptopics.set(topic_t::sighupint); gens[topic_t::sighupint] = std::min(gens[topic_t::sighupint], proc->gens_[topic_t::sighupint]); } } } - if (gens[topic_t::sigchld] == invalid_generation) { + if (reaptopics.none()) { // No reapable processes, nothing to wait for. return; } // Now check for changes, optionally waiting. - topic_set_t topics{{topic_t::sigchld, topic_t::sighupint}}; - auto changed_topics = topic_monitor_t::principal().check(&gens, topics, block_ok); + auto changed_topics = topic_monitor_t::principal().check(&gens, reaptopics, block_ok); if (changed_topics.none()) return; // We got some changes. Since we last checked we received SIGCHLD, and or HUP/INT. // Update the hup/int generations and reap any reapable processes. jobs.reset(); while (auto *j = jobs.next()) { - for (auto &proc : j->processes) { - // Update the signalhupint generation so we don't break on old sighupints. - proc->gens_[topic_t::sighupint] = gens[topic_t::sighupint]; + for (const auto &proc : j->processes) { + if (auto mtopic = j->reap_topic_for_process(proc.get())) { + // Update the signal hup/int gen. + proc->gens_[topic_t::sighupint] = gens[topic_t::sighupint]; - // Try reaping processes whose sigchld count is below what was returned. - if (changed_topics.get(topic_t::sigchld)) { - if (j->can_reap(proc.get()) && - proc->gens_[topic_t::sigchld] < gens[topic_t::sigchld]) { - proc->gens_[topic_t::sigchld] = gens[topic_t::sigchld]; - int status = 0; - auto pid = waitpid(proc->pid, &status, WNOHANG | WUNTRACED); - if (pid > 0) { - debug(4, "Reaped PID %d", pid); - handle_child_status(pid, status); + if (proc->gens_[*mtopic] < gens[*mtopic]) { + // Potentially reapable. Update its gen count and try reaping it. + proc->gens_[*mtopic] = gens[*mtopic]; + if (proc->internal_proc_) { + // Try reaping an internal process. + if (proc->internal_proc_->exited()) { + proc->status = proc->internal_proc_->get_status(); + proc->completed = true; + } + } else if (proc->pid > 0) { + // Try reaping an external process. + int status = -1; + auto pid = waitpid(proc->pid, &status, WNOHANG | WUNTRACED); + if (pid > 0) { + assert(pid == proc->pid && "Unexpcted waitpid() return"); + debug(4, "Reaped PID %d", pid); + handle_child_status(pid, status); + } + } else { + assert(0 && "Don't know how to reap this process"); } } } diff --git a/src/proc.h b/src/proc.h index 7379bd065..c588cf766 100644 --- a/src/proc.h +++ b/src/proc.h @@ -42,6 +42,28 @@ enum { JOB_CONTROL_NONE, }; +/// A structure representing a "process" internal to fish. This is backed by a pthread instead of a +/// separate process. +class internal_proc_t { + /// Whether the process has exited. + std::atomic exited_{}; + + /// If the process has exited, its status code. + std::atomic status_{}; + + public: + /// \return if this process has exited. + bool exited() const { return exited_.load(std::memory_order_relaxed); } + + /// Mark this process as exited, with the given status. + void mark_exited(int status); + + int get_status() const { + assert(exited() && "Process is not exited"); + return status_.load(std::memory_order_acquire); + } +}; + /// A structure representing a single fish process. Contains variables for tracking process state /// and the process argument list. Actually, a fish process can be either a regular external /// process, an internal builtin which may or may not spawn a fake IO process during execution, a @@ -126,6 +148,10 @@ class process_t { /// Process ID pid_t pid{0}; + + /// If we are an "internal process," that process. + std::shared_ptr internal_proc_{}; + /// File descriptor that pipe output should bind to. int pipe_write_fd{0}; /// True if process has completed. @@ -214,15 +240,25 @@ class job_t { /// process if it is the group leader and the job is not yet constructed, because then we might /// also reap the process group and then we cannot add new processes to the group. bool can_reap(const process_t *p) const { - if (p->pid <= 0) { + // Internal processes can always be reaped. + if (p->internal_proc_) { + return true; + } else if (p->pid <= 0) { // Can't reap without a pid. return false; - } - if (!is_constructed() && pgid > 0 && p->pid == pgid) { + } else if (!is_constructed() && pgid > 0 && p->pid == pgid) { // p is the the group leader in an under-construction job. return false; + } else { + return true; } - return true; + } + + /// \returns the reap topic for a process, which describes the manner in which we are reaped. A + /// none returns means don't reap, or perhaps defer reaping. + maybe_t reap_topic_for_process(const process_t *p) const { + if (p->completed || !can_reap(p)) return none(); + return p->internal_proc_ ? topic_t::internal_exit : topic_t::sigchld; } /// Returns a truncated version of the job string. Used when a message has already been emitted diff --git a/src/topic_monitor.h b/src/topic_monitor.h index f74c900ec..78498c4cc 100644 --- a/src/topic_monitor.h +++ b/src/topic_monitor.h @@ -35,8 +35,9 @@ /// The list of topics that may be observed. enum class topic_t : uint8_t { - sigchld, // Corresponds to SIGCHLD signal. - sighupint, // Corresponds to both SIGHUP and SIGINT signals. + sigchld, // Corresponds to SIGCHLD signal. + sighupint, // Corresponds to both SIGHUP and SIGINT signals. + internal_exit, // Corresponds to an internal process exit. COUNT }; From 4a2fd443b220d0957afe51f69509d8f18100ae74 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 13 Feb 2019 15:17:18 -0800 Subject: [PATCH 050/191] Use internal processes to write builtin output This uses the new internal process mechanism to write output for builtins. After this the only reason fish ever forks is to execute external processes. --- src/exec.cpp | 48 ++++++++++++++++++++++++++---------------------- src/proc.cpp | 23 ++++++++++++++--------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index dfd7cf8ef..3b283b638 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -353,9 +353,11 @@ static void on_process_created(const std::shared_ptr &j, pid_t child_pid) } /// Construct an internal process for the process p. In the background, write the data \p outdata to -/// stdout, respecting the io chain \p ios. For example if target_fd is 1 (stdout), and there is a -/// dup2 3->1, then we need to write to fd 3. Then exit the internal process. -static bool run_internal_process(process_t *p, std::string outdata, io_chain_t ios) { +/// stdout and \p errdata to stderr, respecting the io chain \p ios. For example if target_fd is 1 +/// (stdout), and there is a dup2 3->1, then we need to write to fd 3. Then exit the internal +/// process. +static bool run_internal_process(process_t *p, std::string outdata, std::string errdata, + io_chain_t ios) { p->check_generations_before_launch(); // We want both the dup2s and the io_chain_ts to be kept alive by the background thread, because @@ -366,6 +368,9 @@ static bool run_internal_process(process_t *p, std::string outdata, io_chain_t i int src_outfd{-1}; std::string outdata{}; + int src_errfd{-1}; + std::string errdata{}; + io_chain_t ios{}; maybe_t dup2s{}; std::shared_ptr internal_proc{}; @@ -373,10 +378,13 @@ static bool run_internal_process(process_t *p, std::string outdata, io_chain_t i int success_status{}; bool skip_out() const { return outdata.empty() || src_outfd < 0; } + + bool skip_err() const { return errdata.empty() || src_errfd < 0; } }; auto f = std::make_shared(); f->outdata = std::move(outdata); + f->errdata = std::move(errdata); // Construct and assign the internal process to the real process. p->internal_proc_ = std::make_shared(); @@ -394,10 +402,11 @@ static bool run_internal_process(process_t *p, std::string outdata, io_chain_t i // Figure out which source fds to write to. If they are closed (unlikely) we just exit // successfully. f->src_outfd = f->dup2s->fd_for_target_fd(STDOUT_FILENO); + f->src_errfd = f->dup2s->fd_for_target_fd(STDERR_FILENO); // If we have nothing to right we can elide the thread. // TODO: support eliding output to /dev/null. - if (f->skip_out()) { + if (f->skip_out() && f->skip_err()) { f->internal_proc->mark_exited(EXIT_SUCCESS); return true; } @@ -421,6 +430,15 @@ static bool run_internal_process(process_t *p, std::string outdata, io_chain_t i if (!status) status = 1; } } + if (!f->skip_err()) { + ssize_t ret = write_loop(f->src_errfd, f->errdata.data(), f->errdata.size()); + if (ret < 0) { + if (errno != EPIPE) { + wperror(L"write"); + } + if (!status) status = 1; + } + } f->internal_proc->mark_exited(status); }); return true; @@ -650,26 +668,12 @@ static bool handle_builtin_output(const std::shared_ptr &j, process_t *p, // in the child. // // These strings may contain embedded nulls, so don't treat them as C strings. - const std::string outbuff_str = wcs2string(stdout_stream.contents()); - const char *outbuff = outbuff_str.data(); - size_t outbuff_len = outbuff_str.size(); - - const std::string errbuff_str = wcs2string(stderr_stream.contents()); - const char *errbuff = errbuff_str.data(); - size_t errbuff_len = errbuff_str.size(); - - // Resolve our IO chain to a sequence of dup2s. - auto dup2s = dup2_list_t::resolve_chain(*io_chain); - if (!dup2s) { - return false; - } + std::string outbuff = wcs2string(stdout_stream.contents()); + std::string errbuff = wcs2string(stderr_stream.contents()); fflush(stdout); fflush(stderr); - if (!fork_child_for_process(j, p, *dup2s, false, "internal builtin", [&] { - do_builtin_io(outbuff, outbuff_len, errbuff, errbuff_len); - exit_without_destructors(p->status); - })) { + if (!run_internal_process(p, std::move(outbuff), std::move(errbuff), *io_chain)) { return false; } } @@ -851,7 +855,7 @@ static bool exec_block_or_func_process(parser_t &parser, std::shared_ptr std::string buffer_contents = block_output_buffer->buffer().newline_serialized(); if (!buffer_contents.empty()) { - return run_internal_process(p, std::move(buffer_contents), io_chain); + return run_internal_process(p, std::move(buffer_contents), {} /*errdata*/, io_chain); } else { if (p->is_last_in_job) { proc_set_last_status(j->get_flag(job_flag_t::NEGATE) ? (!status) : status); diff --git a/src/proc.cpp b/src/proc.cpp index a8ebc4793..e0bfff3e9 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -922,15 +922,20 @@ void job_t::continue_job(bool send_sigcont) { } } - if (is_foreground()) { - if (is_completed()) { - // Set $status only if we are in the foreground and the last process in the job has - // finished and is not a short-circuited builtin. - auto &p = processes.back(); - if ((WIFEXITED(p->status) || WIFSIGNALED(p->status)) && p->pid) { - int status = proc_format_status(p->status); - proc_set_last_status(get_flag(job_flag_t::NEGATE) ? !status : status); - } + if (is_foreground() && is_completed()) { + // Set $status only if we are in the foreground and the last process in the job has + // finished and is not a short-circuited builtin. + bool negate = get_flag(job_flag_t::NEGATE); + auto &p = processes.back(); + if (p->internal_proc_) { + // Here the status is synthetic - not associated with a real exited process. + // TODO: clean this up, we shouldn't store the process's exit status in an unparsed + // state. + int status = p->status; + proc_set_last_status(negate ? !status : status); + } else if ((WIFEXITED(p->status) || WIFSIGNALED(p->status)) && p->pid) { + int status = proc_format_status(p->status); + proc_set_last_status(negate ? !status : status); } } } From 0b3eca1743f3a62a15ee6ab3bff4644207ebc6d0 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 17 Feb 2019 14:16:47 -0800 Subject: [PATCH 051/191] Cleanup handle_builtin_output Now that we use an internal process to perform builtin output, simplify the logic around how it is performed. In particular we no longer have to be careful about async-safe functions since we do not fork. Also fix a bunch of comments that no longer apply. --- src/exec.cpp | 137 ++++++++++++++++++++++------------------------- src/io.cpp | 1 + src/io.h | 23 ++++---- src/postfork.cpp | 24 --------- src/postfork.h | 3 -- 5 files changed, 74 insertions(+), 114 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index 3b283b638..9b29ed8f1 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -73,12 +73,11 @@ void exec_close(int fd) { } /// Returns true if the redirection is a file redirection to a file other than /dev/null. -static bool redirection_is_to_real_file(const io_data_t *io) { +static bool redirection_is_to_real_file(const shared_ptr &io) { bool result = false; - if (io != NULL && io->io_mode == io_mode_t::file) { + if (io && io->io_mode == io_mode_t::file) { // It's a file redirection. Compare the path to /dev/null. - const io_file_t *io_file = static_cast(io); - const char *path = io_file->filename_cstr; + const char *path = static_cast(io.get())->filename_cstr; if (strcmp(path, "/dev/null") != 0) { // It's not /dev/null. result = true; @@ -588,71 +587,71 @@ static bool exec_internal_builtin_proc(parser_t &parser, const std::shared_ptr &j, process_t *p, io_chain_t *io_chain, const io_streams_t &builtin_io_streams) { assert(p->type == INTERNAL_BUILTIN && "Process is not a builtin"); - // Handle output from builtin commands. In the general case, this means forking of a - // worker process, that will write out the contents of the stdout and stderr buffers - // to the correct file descriptor. Since forking is expensive, fish tries to avoid - // it when possible. - bool fork_was_skipped = false; - - const shared_ptr stdout_io = io_chain->get_io_for_fd(STDOUT_FILENO); - const shared_ptr stderr_io = io_chain->get_io_for_fd(STDERR_FILENO); const output_stream_t &stdout_stream = builtin_io_streams.out; const output_stream_t &stderr_stream = builtin_io_streams.err; - // If we are outputting to a file, we have to actually do it, even if we have no - // output, so that we can truncate the file. Does not apply to /dev/null. - bool must_fork = redirection_is_to_real_file(stdout_io.get()) || - redirection_is_to_real_file(stderr_io.get()); - if (!must_fork && p->is_last_in_job) { - // We are handling reads directly in the main loop. Note that we may still end - // up forking. - const bool stdout_is_bufferfill = - (stdout_io && stdout_io->io_mode == io_mode_t::bufferfill); - const std::shared_ptr stdout_buffer = - stdout_is_bufferfill ? static_cast(stdout_io.get())->buffer() - : nullptr; - const bool no_stdout_output = stdout_stream.empty(); - const bool no_stderr_output = stderr_stream.empty(); - const bool stdout_discarded = stdout_stream.buffer().discarded(); + // Mark if we discarded output. + if (stdout_stream.buffer().discarded()) p->status = STATUS_READ_TOO_MUCH; - if (!stdout_discarded && no_stdout_output && no_stderr_output) { - // The builtin produced no output and is not inside of a pipeline. No - // need to fork or even output anything. - debug(4, L"Skipping fork: no output for internal builtin '%ls'", p->argv0()); - fork_was_skipped = true; - } else if (no_stderr_output && stdout_buffer) { - // The builtin produced no stderr, and its stdout is going to an - // internal buffer. There is no need to fork. This helps out the - // performance quite a bit in complex completion code. - // TODO: we're sloppy about handling explicitly separated output. - // Theoretically we could have explicitly separated output on stdout and - // also stderr output; in that case we ought to thread the exp-sep output - // through to the io buffer. We're getting away with this because the only - // thing that can output exp-sep output is `string split0` which doesn't - // also produce stderr. - debug(4, L"Skipping fork: buffered output for internal builtin '%ls'", p->argv0()); + // We will try to elide constructing an internal process. However if the output is going to a + // real file, we have to do it. For example in `echo -n > file.txt` we proceed to open file.txt + // even though there is no output, so that it is properly truncated. + const shared_ptr stdout_io = io_chain->get_io_for_fd(STDOUT_FILENO); + const shared_ptr stderr_io = io_chain->get_io_for_fd(STDERR_FILENO); + bool must_use_process = + redirection_is_to_real_file(stdout_io) || redirection_is_to_real_file(stderr_io); - stdout_buffer->append_from_stream(stdout_stream); - fork_was_skipped = true; - } else if (stdout_io.get() == NULL && stderr_io.get() == NULL) { - // We are writing to normal stdout and stderr. Just do it - no need to fork. - debug(4, L"Skipping fork: ordinary output for internal builtin '%ls'", p->argv0()); - const std::string outbuff = wcs2string(stdout_stream.contents()); - const std::string errbuff = wcs2string(stderr_stream.contents()); - bool builtin_io_done = - do_builtin_io(outbuff.data(), outbuff.size(), errbuff.data(), errbuff.size()); - if (!builtin_io_done && errno != EPIPE) { - redirect_tty_output(); // workaround glibc bug - debug(0, "!builtin_io_done and errno != EPIPE"); - show_stackframe(L'E'); - } - if (stdout_discarded) p->status = STATUS_READ_TOO_MUCH; - fork_was_skipped = true; - } + // If we are directing output to a buffer, then we can just transfer it directly without needing + // to write to the bufferfill pipe. Note this is how we handle explicitly separated stdout + // output (i.e. string split0) which can't really be sent through a pipe. + // TODO: we're sloppy about handling explicitly separated output. + // Theoretically we could have explicitly separated output on stdout and also stderr output; in + // that case we ought to thread the exp-sep output through to the io buffer. We're getting away + // with this because the only thing that can output exp-sep output is `string split0` which + // doesn't also produce stderr. Also note that we never send stderr to a buffer, so there's no + // need for a similar check for stderr. + bool stdout_done = false; + if (stdout_io && stdout_io->io_mode == io_mode_t::bufferfill) { + auto stdout_buffer = static_cast(stdout_io.get())->buffer(); + stdout_buffer->append_from_stream(stdout_stream); + stdout_done = true; } - if (fork_was_skipped) { + // Figure out any data remaining to write. We may have none in which case we can short-circuit. + std::string outbuff = stdout_done ? std::string{} : wcs2string(stdout_stream.contents()); + std::string errbuff = wcs2string(stderr_stream.contents()); + + // If we have no redirections for stdout/stderr, just write them directly. + if (!stdout_io && !stderr_io) { + bool did_err = false; + if (write_loop(STDOUT_FILENO, outbuff.data(), outbuff.size()) < 0) { + if (errno != EPIPE) { + did_err = true; + debug(0, "Error while writing to stdout"); + wperror(L"write_loop"); + } + } + if (write_loop(STDERR_FILENO, errbuff.data(), errbuff.size()) < 0) { + if (errno != EPIPE && !did_err) { + did_err = true; + debug(0, "Error while writing to stderr"); + wperror(L"write_loop"); + } + } + if (did_err) { + redirect_tty_output(); // workaround glibc bug + debug(0, "!builtin_io_done and errno != EPIPE"); + show_stackframe(L'E'); + } + // Clear the buffers to indicate we finished. + outbuff.clear(); + errbuff.clear(); + } + + if (!must_use_process && outbuff.empty() && errbuff.empty()) { + // We do not need to construct a background process. + // TODO: factor this job-status-setting stuff into a single place. p->completed = 1; if (p->is_last_in_job) { debug(4, L"Set status of job %d (%ls) to %d using short circuit", j->job_id, @@ -661,23 +660,13 @@ static bool handle_builtin_output(const std::shared_ptr &j, process_t *p, int status = p->status; proc_set_last_status(j->get_flag(job_flag_t::NEGATE) ? (!status) : status); } + return true; } else { - // Ok, unfortunately, we have to do a real fork. Bummer. We work hard to make - // sure we don't have to wait for all our threads to exit, by arranging things - // so that we don't have to allocate memory or do anything except system calls - // in the child. - // - // These strings may contain embedded nulls, so don't treat them as C strings. - std::string outbuff = wcs2string(stdout_stream.contents()); - std::string errbuff = wcs2string(stderr_stream.contents()); - + // Construct and run our background process. fflush(stdout); fflush(stderr); - if (!run_internal_process(p, std::move(outbuff), std::move(errbuff), *io_chain)) { - return false; - } + return run_internal_process(p, std::move(outbuff), std::move(errbuff), *io_chain); } - return true; } /// Executes an external command. diff --git a/src/io.cpp b/src/io.cpp index 67a9c03d5..5dcff30de 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -31,6 +31,7 @@ void io_pipe_t::print() const { void io_bufferfill_t::print() const { fwprintf(stderr, L"bufferfill {%d}\n", write_fd_.fd()); } void io_buffer_t::append_from_stream(const output_stream_t &stream) { + if (stream.empty()) return; scoped_lock locker(append_lock_); if (buffer_.discarded()) return; if (stream.buffer().discarded()) { diff --git a/src/io.h b/src/io.h index 026ce8b36..6f5e12447 100644 --- a/src/io.h +++ b/src/io.h @@ -410,28 +410,25 @@ struct io_streams_t { output_stream_t err; // fd representing stdin. This is not closed by the destructor. - int stdin_fd; + int stdin_fd{-1}; // Whether stdin is "directly redirected," meaning it is the recipient of a pipe (foo | cmd) or // direct redirection (cmd < foo.txt). An "indirect redirection" would be e.g. begin ; cmd ; end // < foo.txt - bool stdin_is_directly_redirected; + bool stdin_is_directly_redirected{false}; // Indicates whether stdout and stderr are redirected (e.g. to a file or piped). - bool out_is_redirected; - bool err_is_redirected; + bool out_is_redirected{false}; + bool err_is_redirected{false}; // Actual IO redirections. This is only used by the source builtin. Unowned. - const io_chain_t *io_chain; + const io_chain_t *io_chain{nullptr}; - io_streams_t(size_t read_limit) - : out(read_limit), - err(read_limit), - stdin_fd(-1), - stdin_is_directly_redirected(false), - out_is_redirected(false), - err_is_redirected(false), - io_chain(NULL) {} + // io_streams_t cannot be copied. + io_streams_t(const io_streams_t &) = delete; + void operator=(const io_streams_t &) = delete; + + explicit io_streams_t(size_t read_limit) : out(read_limit), err(read_limit), stdin_fd(-1) {} }; #if 0 diff --git a/src/postfork.cpp b/src/postfork.cpp index 77d7e04f3..e24b3fd62 100644 --- a/src/postfork.cpp +++ b/src/postfork.cpp @@ -379,27 +379,3 @@ void safe_report_exec_error(int err, const char *actual_cmd, const char *const * } } } - -/// Perform output from builtins. May be called from a forked child, so don't do anything that may -/// allocate memory, etc. -bool do_builtin_io(const char *out, size_t outlen, const char *err, size_t errlen) { - int saved_errno = 0; - bool success = true; - if (out && outlen && write_loop(STDOUT_FILENO, out, outlen) < 0) { - saved_errno = errno; - if (errno != EPIPE) { - debug_safe(0, "Error while writing to stdout"); - errno = saved_errno; - safe_perror("write_loop"); - } - success = false; - } - - if (err && errlen && write_loop(STDERR_FILENO, err, errlen) < 0) { - saved_errno = errno; - success = false; - } - - errno = saved_errno; - return success; -} diff --git a/src/postfork.h b/src/postfork.h index 27c9d57bb..f09efd8af 100644 --- a/src/postfork.h +++ b/src/postfork.h @@ -41,9 +41,6 @@ int setup_child_process(process_t *p, const dup2_list_t &dup2s); /// wait for threads to die. pid_t execute_fork(bool wait_for_threads_to_die); -/// Perform output from builtins. Returns true on success. -bool do_builtin_io(const char *out, size_t outlen, const char *err, size_t errlen); - /// Report an error from failing to exec or posix_spawn a command. void safe_report_exec_error(int err, const char *actual_cmd, const char *const *argv, const char *const *envv); From 7958e1d5c43fb7a99722565f83d23449de4ffd1d Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 18 Feb 2019 14:44:41 +0100 Subject: [PATCH 052/191] fish_tests: s/rand()/random()/g As it turns out, NetBSD's rand(3) is awful - it's possible that in any given run it'll only return odd numbers, which means while (rand() % 10) will never stop. Since random(3) is also standardized and works, let's use that! --- src/fish_tests.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 351e49a77..08d4d08ed 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -377,8 +377,8 @@ static void test_escape_crazy() { bool unescaped_success; for (size_t i = 0; i < ESCAPE_TEST_COUNT; i++) { random_string.clear(); - while (rand() % ESCAPE_TEST_LENGTH) { - random_string.push_back((rand() % ESCAPE_TEST_CHAR) + 1); + while (random() % ESCAPE_TEST_LENGTH) { + random_string.push_back((random() % ESCAPE_TEST_CHAR) + 1); } escaped_string = escape_string(random_string, ESCAPE_ALL); @@ -495,8 +495,8 @@ static void test_convert() { char c; sb.clear(); - while (rand() % ESCAPE_TEST_LENGTH) { - c = rand(); + while (random() % ESCAPE_TEST_LENGTH) { + c = random(); sb.push_back(c); } c = 0; @@ -3369,9 +3369,9 @@ class history_tests_t { static wcstring random_string() { wcstring result = L""; - size_t max = 1 + rand() % 32; + size_t max = 1 + random() % 32; while (max--) { - wchar_t c = 1 + rand() % ESCAPE_TEST_CHAR; + wchar_t c = 1 + random() % ESCAPE_TEST_CHAR; result.push_back(c); } return result; @@ -3467,7 +3467,7 @@ void history_tests_t::test_history() { // Generate some paths. path_list_t paths; - size_t count = rand() % 6; + size_t count = random() % 6; while (count--) { paths.push_back(random_string()); } @@ -5182,7 +5182,7 @@ int main(int argc, char **argv) { } } - srand((unsigned int)time(NULL)); + srandom((unsigned int)time(NULL)); configure_thread_assertions_for_testing(); // Set the program name to this sentinel value From 11009de431fcad5b8e8fc55b3903811290062200 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 18 Feb 2019 15:01:07 +0100 Subject: [PATCH 053/191] Revert "Explicitly close input fd to `fish_title`" This reverts commit b247c8d9ada92c4d039453a551b83cc0ff40724e. It breaks the title entirely. [ci skip] --- src/reader.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 413f6f660..34b0df044 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -829,12 +829,6 @@ void reader_write_title(const wcstring &cmd, bool reset_cursor_position) { fish_title_command.append( escape_string(cmd, ESCAPE_ALL | ESCAPE_NO_QUOTED | ESCAPE_NO_TILDE)); } - - // `fish_title` is executed in a non-interactive context and attempts at reading - // from within that function will cause problems ranging segfaults, SIGTTIN - // deadlocks, or infinite loops - we explicitly close the input fd to safeguard - // against such a scenario. - fish_title_command.append(L"<&-"); } wcstring_list_t lst; From c242469e8b139cf8f634e7907ebed1e83d8f8434 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 18 Feb 2019 15:22:30 +0100 Subject: [PATCH 054/191] cmake: Keep rpath on NetBSD Otherwise it'd fail to find pcre2 in the invocation tests. --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb7949f7e..d7ae17b8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,14 @@ ELSE() SET(FISH_IN_TREE_BUILD FALSE) ENDIF() +# NetBSD does weird things with finding libraries, +# making the tests fail by failing to find pcre. +# +# Keep the rpath used to build. +IF(CMAKE_SYSTEM_NAME STREQUAL NetBSD) + SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +ENDIF() + # All objects that the system needs to build fish, except fish.cpp SET(FISH_SRCS src/autoload.cpp src/builtin.cpp src/builtin_bg.cpp src/builtin_bind.cpp From 7eb6bee793cbbd6f6d1f47354387234054b0f655 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 18 Feb 2019 15:22:47 +0100 Subject: [PATCH 055/191] Add NetBSD on sr.ht --- .builds/netbsd.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .builds/netbsd.yml diff --git a/.builds/netbsd.yml b/.builds/netbsd.yml new file mode 100644 index 000000000..a47dc4137 --- /dev/null +++ b/.builds/netbsd.yml @@ -0,0 +1,24 @@ +image: netbsd/latest +packages: + - ncurses + - gettext + - tcl-expect + - cmake + - gmake + - pcre2 +tasks: + - build: | + # We can't use sources because we don't have the certificate store set up. + git -c http.sslVerify=false clone https://git.sr.ht/~faho/fish + cd fish + mkdir build || : + cd build + cmake .. \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_INSTALL_DATADIR=share \ + -DCMAKE_INSTALL_DOCDIR=share/doc/fish \ + -DCMAKE_INSTALL_SYSCONFDIR=/etc + gmake -j2 + - test: | + cd fish/build + gmake test SHOW_INTERACTIVE_LOG=1 From 18a9141fb40c52ca8e71f645826e6671878e9d1f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 18 Feb 2019 15:25:57 +0100 Subject: [PATCH 056/191] Remove comment in yaml I should actually look up the syntax one of these days. --- .builds/netbsd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.builds/netbsd.yml b/.builds/netbsd.yml index a47dc4137..5756e2745 100644 --- a/.builds/netbsd.yml +++ b/.builds/netbsd.yml @@ -8,7 +8,6 @@ packages: - pcre2 tasks: - build: | - # We can't use sources because we don't have the certificate store set up. git -c http.sslVerify=false clone https://git.sr.ht/~faho/fish cd fish mkdir build || : From 1c3fe7dc66a2c18a3d5c0fd90dd256fa32027179 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 18 Feb 2019 15:39:58 +0100 Subject: [PATCH 057/191] tests/expansion: Use rm instead of unlink unlink(1) is apparently not always installed everywhere. Since there is no real difference, just use rm. --- tests/expansion.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/expansion.in b/tests/expansion.in index 961d811fe..830a1197e 100644 --- a/tests/expansion.in +++ b/tests/expansion.in @@ -130,7 +130,7 @@ set expandedtilde (env HOME=$tmpdir/linkhome ../test/root/bin/fish -c 'echo ~') if test $expandedtilde != $tmpdir/linkhome echo '~ expands to' $expandedtilde ' - expected ' $tmpdir/linkhome end -unlink $tmpdir/linkhome +rm $tmpdir/linkhome rmdir $tmpdir/realhome rmdir $tmpdir From 8e41e3337c4f2685505b82bbdf99d2b04125519e Mon Sep 17 00:00:00 2001 From: Jonathan Revah Date: Mon, 18 Feb 2019 15:50:05 -0500 Subject: [PATCH 058/191] small typo in the tutorial. stderr is redirected using 2> rather than >2 --- doc_src/tutorial.hdr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc_src/tutorial.hdr b/doc_src/tutorial.hdr index 898e43a64..bce1349ab 100644 --- a/doc_src/tutorial.hdr +++ b/doc_src/tutorial.hdr @@ -172,7 +172,7 @@ You can pipe between commands with the usual vertical bar: 1 2 12 \endfish -stdin and stdout can be redirected via the familiar < and >. stderr is redirected with a >2. +stdin and stdout can be redirected via the familiar < and >. stderr is redirected with a 2>. \fish{cli-dark} >_ grep fish < /etc/shells > ~/output.txt 2> ~/errors.txt From 59cb2d02a85a806884a99e39d7b1e5d4d35c129e Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 18 Feb 2019 13:11:01 -0800 Subject: [PATCH 059/191] Only inherit a PWD if it resolves to "." Fixes #5647 --- src/env.cpp | 12 +++++++----- tests/cd.in | 14 ++++++++++++++ tests/cd.out | 2 ++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index 5b840859a..6da436aba 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -1014,11 +1014,13 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { } // initialize the PWD variable if necessary - // Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that. - // Note we treat PWD as read-only so it was not set in vars. - const char *incoming_pwd = getenv("PWD"); - if (incoming_pwd && incoming_pwd[0]) { - vars.set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, str2wcstring(incoming_pwd)); + // Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that + // if and only if it matches getcwd (#5647). Note we treat PWD as read-only so it was not set in + // vars. + const char *incoming_pwd_cstr = getenv("PWD"); + wcstring incoming_pwd = incoming_pwd_cstr ? str2wcstring(incoming_pwd_cstr) : wcstring{}; + if (!incoming_pwd.empty() && paths_are_same_file(incoming_pwd, L".")) { + vars.set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, incoming_pwd); } else { vars.set_pwd_from_getcwd(); } diff --git a/tests/cd.in b/tests/cd.in index a537b1ea8..2d02d269c 100644 --- a/tests/cd.in +++ b/tests/cd.in @@ -47,8 +47,22 @@ mkdir -p $base/realhome set fish_path $PWD/../test/root/bin/fish ln -s $base/realhome $base/linkhome cd $base/linkhome +set -l real_getcwd (pwd -P) env HOME=$base/linkhome $fish_path -c 'echo PWD is $PWD' +# Do not inherit a virtual PWD that fails to resolve to getcwd (#5647) + +env HOME=$base/linkhome PWD=/tmp $fish_path -c 'echo $PWD' | read output_pwd +test (realpath $output_pwd) = $real_getcwd +and echo "BogusPWD test 1 succeeded" +or echo "BogusPWD test 1 failed: $output_pwd vs $real_getcwd" + +env HOME=$base/linkhome PWD=/path/to/nowhere $fish_path -c 'echo $PWD' | read output_pwd +test (realpath $output_pwd) = $real_getcwd +and echo "BogusPWD test 2 succeeded" +or echo "BogusPWD test 2 failed: $output_pwd vs $real_getcwd" + + # cd back before removing the test directory again. cd $oldpwd rm -Rf $base diff --git a/tests/cd.out b/tests/cd.out index 73081263d..8fd581f17 100644 --- a/tests/cd.out +++ b/tests/cd.out @@ -21,3 +21,5 @@ cd: #################### # Virtual PWD inheritance PWD is /tmp/cdcomp_test/linkhome +BogusPWD test 1 succeeded +BogusPWD test 2 succeeded From 5c994b0d474424057c7d36065c56e56066e0e0d4 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 18 Feb 2019 13:11:01 -0800 Subject: [PATCH 060/191] Only inherit a PWD if it resolves to "." Fixes #5647 --- CHANGELOG.md | 9 +++++++++ src/env.cpp | 13 +++++++------ tests/cd.in | 14 ++++++++++++++ tests/cd.out | 2 ++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77a3a4771..590ab59dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# fish 3.0.2 + +This release of fish contains the following ixes: + +### Fixes and improvements + +- The PWD environment variable is now ignored if it does not resolve to the true working directory (#5647). + + # fish 3.0.1 (released February 11, 2019) This release of fish fixes a number of major issues discovered in fish 3.0.0. diff --git a/src/env.cpp b/src/env.cpp index 7c617cb2e..7d0b00679 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -960,12 +960,13 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { } } - // initialize the PWD variable if necessary - // Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that. - // Note we treat PWD as read-only so it was not set in vars. - const char *incoming_pwd = getenv("PWD"); - if (incoming_pwd && incoming_pwd[0]) { - env_set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, str2wcstring(incoming_pwd)); + // Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that + // if and only if it matches getcwd (#5647). Note we treat PWD as read-only so it was not set in + // vars. + const char *incoming_pwd_cstr = getenv("PWD"); + wcstring incoming_pwd = incoming_pwd_cstr ? str2wcstring(incoming_pwd_cstr) : wcstring{}; + if (!incoming_pwd.empty() && paths_are_same_file(incoming_pwd, L".")) { + env_set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, std::move(incoming_pwd)); } else { env_set_pwd_from_getcwd(); } diff --git a/tests/cd.in b/tests/cd.in index fde7cd558..e57124c17 100644 --- a/tests/cd.in +++ b/tests/cd.in @@ -46,8 +46,22 @@ mkdir -p $base/realhome set fish_path $PWD/../test/root/bin/fish ln -s $base/realhome $base/linkhome cd $base/linkhome +set -l real_getcwd (pwd -P) env HOME=$base/linkhome $fish_path -c 'echo PWD is $PWD' +# Do not inherit a virtual PWD that fails to resolve to getcwd (#5647) + +env HOME=$base/linkhome PWD=/tmp $fish_path -c 'echo $PWD' | read output_pwd +test (realpath $output_pwd) = $real_getcwd +and echo "BogusPWD test 1 succeeded" +or echo "BogusPWD test 1 failed: $output_pwd vs $real_getcwd" + +env HOME=$base/linkhome PWD=/path/to/nowhere $fish_path -c 'echo $PWD' | read output_pwd +test (realpath $output_pwd) = $real_getcwd +and echo "BogusPWD test 2 succeeded" +or echo "BogusPWD test 2 failed: $output_pwd vs $real_getcwd" + + # cd back before removing the test directory again. cd $oldpwd rm -Rf $base diff --git a/tests/cd.out b/tests/cd.out index 73081263d..8fd581f17 100644 --- a/tests/cd.out +++ b/tests/cd.out @@ -21,3 +21,5 @@ cd: #################### # Virtual PWD inheritance PWD is /tmp/cdcomp_test/linkhome +BogusPWD test 1 succeeded +BogusPWD test 2 succeeded From c2bc0c67f29384dec1fbc0fd34dfff431ee6b034 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Mon, 18 Feb 2019 23:12:03 -0800 Subject: [PATCH 061/191] Don't use printf("%d") just to convert an int to a string. std::to_string, std::to_wstring are more appropriate --- src/common.cpp | 9 +++------ src/fish_tests.cpp | 2 +- src/reader.cpp | 4 +--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 2f140d79b..ac8705ff8 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1796,16 +1796,13 @@ static void validate_new_termsize(struct winsize *new_termsize, const environmen /// Export the new terminal size as env vars and to the kernel if possible. static void export_new_termsize(struct winsize *new_termsize, env_stack_t &vars) { - wchar_t buf[64]; - auto cols = vars.get(L"COLUMNS", ENV_EXPORT); - swprintf(buf, 64, L"%d", (int)new_termsize->ws_col); vars.set_one(L"COLUMNS", ENV_GLOBAL | (cols.missing_or_empty() ? ENV_DEFAULT : ENV_EXPORT), - buf); + std::to_wstring(int(new_termsize->ws_col))); auto lines = vars.get(L"LINES", ENV_EXPORT); - swprintf(buf, 64, L"%d", (int)new_termsize->ws_row); - vars.set_one(L"LINES", ENV_GLOBAL | (lines.missing_or_empty() ? ENV_DEFAULT : ENV_EXPORT), buf); + vars.set_one(L"LINES", ENV_GLOBAL | (lines.missing_or_empty() ? ENV_DEFAULT : ENV_EXPORT), + std::to_wstring(int(new_termsize->ws_row))); #ifdef HAVE_WINSIZE // Only write the new terminal size if we are in the foreground (#4477) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 08d4d08ed..373381f8b 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1545,7 +1545,7 @@ static void test_lru() { auto commajoin = [](const std::vector &vs) { wcstring ret; for (int v : vs) { - append_format(ret, L"%d,", v); + ret.append(std::to_wstring(v)); } if (!ret.empty()) ret.pop_back(); return ret; diff --git a/src/reader.cpp b/src/reader.cpp index 34b0df044..c18fc7c8e 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2013,15 +2013,13 @@ bool reader_get_selection(size_t *start, size_t *len) { void set_env_cmd_duration(struct timeval *after, struct timeval *before, env_stack_t &vars) { time_t secs = after->tv_sec - before->tv_sec; suseconds_t usecs = after->tv_usec - before->tv_usec; - wchar_t buf[16]; if (after->tv_usec < before->tv_usec) { usecs += 1000000; secs -= 1; } - swprintf(buf, 16, L"%d", (secs * 1000) + (usecs / 1000)); - vars.set_one(ENV_CMD_DURATION, ENV_UNEXPORT, buf); + vars.set_one(ENV_CMD_DURATION, ENV_UNEXPORT, std::to_wstring((secs * 1000) + (usecs / 1000))); } void reader_run_command(parser_t &parser, const wcstring &cmd) { From 6fa8b028fcc52b48704ebc13fbbc4a611f2b9c8b Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Mon, 18 Feb 2019 23:19:57 -0800 Subject: [PATCH 062/191] fish_tests.cpp: fixup: I didn't notice the comma here. --- src/fish_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 373381f8b..08d4d08ed 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1545,7 +1545,7 @@ static void test_lru() { auto commajoin = [](const std::vector &vs) { wcstring ret; for (int v : vs) { - ret.append(std::to_wstring(v)); + append_format(ret, L"%d,", v); } if (!ret.empty()) ret.pop_back(); return ret; From 3fe93535998e4a684832251309dc93cdaf5975e1 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Tue, 19 Feb 2019 01:54:45 -0800 Subject: [PATCH 063/191] style guide: allow multi-line comments (#5670) Closes #5670. --- CONTRIBUTING.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b5dc2e304..d28bbde37 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -165,9 +165,24 @@ However, as I write this there are no places in the code where we use this and I 1. Indent with spaces, not tabs and use four spaces per indent. -1. Comments should always use the C++ style; i.e., each line of the comment should begin with a `//` and should be limited to 100 characters. Comments that do not begin a line should be separated from the previous text by two spaces. - -1. Comments that document the purpose of a function or class should begin with three slashes, `///`, so that OS X Xcode (and possibly other IDEs) will extract the comment and show it in the "Quick Help" window when the cursor is on the symbol. +1. Document the purpose of a function or class with doxygen-style comment blocks. e.g.: +``` +/** + * Sum numbers in a vector. + * + * @param values Container whose values are summed. + * @return sum of `values`, or 0.0 if `values` is empty. + */ +double sum(std::vector & const values) { + ... +} + */ + ``` +or +``` +/// brief description of somefunction() +void somefunction() { +``` ## Testing From 38f37b7abc1f6be83d613d4e6225147a0cb449f8 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 19 Feb 2019 10:04:37 +0100 Subject: [PATCH 064/191] commandline: Remove stray "w" short option Fun fact: `commandline -w` hits an assert and crashes. --- src/builtin_commandline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index 3d22329f7..5890fb1c0 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -201,7 +201,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv) return STATUS_CMD_ERROR; } - static const wchar_t *const short_options = L":abijpctwforhI:CLSsP"; + static const wchar_t *const short_options = L":abijpctforhI:CLSsP"; static const struct woption long_options[] = {{L"append", no_argument, NULL, 'a'}, {L"insert", no_argument, NULL, 'i'}, {L"replace", no_argument, NULL, 'r'}, From 8a93c7d0ea08f7143a4e7f3fa61955addac8ebcf Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 19 Feb 2019 10:06:17 +0100 Subject: [PATCH 065/191] abbr: Add "-q"/"--query" option [ci skip] --- doc_src/abbr.txt | 3 +++ share/functions/abbr.fish | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc_src/abbr.txt b/doc_src/abbr.txt index 76b0cf5c9..b3dd6896e 100644 --- a/doc_src/abbr.txt +++ b/doc_src/abbr.txt @@ -7,6 +7,7 @@ abbr --erase word abbr --rename [SCOPE] OLD_WORD NEW_WORD abbr --show abbr --list +abbr --query WORD.. \endfish \subsection abbr-description Description @@ -29,6 +30,8 @@ The following options are available: - `-e WORD` or `--erase WORD` Erase the abbreviation WORD. +- `-q` or `--query` Return 0 (true) if one of the WORDs is an abbreviation. + In addition, when adding abbreviations: - `-g` or `--global` to use a global variable. diff --git a/share/functions/abbr.fish b/share/functions/abbr.fish index 0ac8b24bd..b328c5120 100644 --- a/share/functions/abbr.fish +++ b/share/functions/abbr.fish @@ -1,7 +1,7 @@ function abbr --description "Manage abbreviations" - set -l options --stop-nonopt --exclusive 'a,r,e,l,s' --exclusive 'g,U' - set -a options 'h/help' 'a/add' 'r/rename' 'e/erase' 'l/list' 's/show' - set -a options 'g/global' 'U/universal' + set -l options --stop-nonopt --exclusive 'a,r,e,l,s,q' --exclusive 'g,U' + set -a options h/help a/add r/rename e/erase l/list s/show q/query + set -a options g/global U/universal argparse -n abbr $options -- $argv or return @@ -20,6 +20,7 @@ function abbr --description "Manage abbreviations" and not set -q _flag_erase[1] and not set -q _flag_list[1] and not set -q _flag_show[1] + and not set -q _flag_query[1] if set -q argv[1] set _flag_add --add else @@ -49,6 +50,17 @@ function abbr --description "Manage abbreviations" else if set -q _flag_show[1] __fish_abbr_show $argv return + else if set -q _flag_query[1] + # "--query": Check if abbrs exist. + # If we don't have an argument, it's an automatic failure. + set -q argv[1]; or return 1 + set -l escaped _fish_abbr_(string escape --style=var -- $argv) + # We return 0 if any arg exists, whereas `set -q` returns the number of undefined arguments. + # But we should be consistent with `type -q` and `command -q`. + for var in $escaped + set -q $escaped; and return 0 + end + return 1 else printf ( _ "%s: Could not figure out what to do!\n" ) abbr >&2 return 127 From 6aa2f299011747b20af9bde4dc129cb572244bfc Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Tue, 19 Feb 2019 04:21:29 -0800 Subject: [PATCH 066/191] Don't increase the width for variation selector 15. See discussion in #5668 and #5583 --- src/fallback.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fallback.cpp b/src/fallback.cpp index 3f2912551..485c93b51 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -282,8 +282,10 @@ int fish_wcswidth(const wchar_t *str, size_t n) { return wcswidth(str, n); } int fish_wcwidth(wchar_t wc) { // Check for VS16 which selects emoji presentation. This "promotes" a character like U+2764 // (width 1) to an emoji (probably width 2). So treat it as width 1 so the sums work. See #2652. - const int variation_selector_16 = 0xFE0F; + // VS15 selects text presentation. + const wchar_t variation_selector_16 = L'\uFE0F', variation_selector_15 = L'\uFE0E'; if (wc == variation_selector_16) return 1; + else if (wc == variation_selector_15) return 0; int width = widechar_wcwidth(wc); switch (width) { From 59955391adfe65b7b68ab44604e40b62118e86af Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 19 Feb 2019 14:23:18 +0100 Subject: [PATCH 067/191] completions/yarn: Allow running scripts as subcommand Fixes #5674. [ci skip] --- share/completions/yarn.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/completions/yarn.fish b/share/completions/yarn.fish index 378d466d8..d9549e071 100644 --- a/share/completions/yarn.fish +++ b/share/completions/yarn.fish @@ -78,7 +78,8 @@ function __fish_yarn_run end end -complete -c yarn -n '__fish_seen_subcommand_from run' -a "(__fish_yarn_run)" +# Scripts can be used like normal subcommands, or with `yarn run SCRIPT`. +complete -c yarn -n '__fish_use_subcommand; or __fish_seen_subcommand_from run' -a "(__fish_yarn_run)" complete -f -c yarn -n '__fish_use_subcommand' -a tag complete -f -c yarn -n '__fish_seen_subcommand_from tag' -a 'add rm ls' From 6e24061468602f33e2d1db925f2cdeff3f782d10 Mon Sep 17 00:00:00 2001 From: David Adam Date: Tue, 19 Feb 2019 21:29:50 +0800 Subject: [PATCH 068/191] CHANGELOG: updates for 3.0.2 --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 590ab59dd..6f3f52cf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ # fish 3.0.2 -This release of fish contains the following ixes: +This release of fish fixes an issue discovered in fish 3.0.1. ### Fixes and improvements -- The PWD environment variable is now ignored if it does not resolve to the true working directory (#5647). +- The PWD environment variable is now ignored if it does not resolve to the true working directory, fixing strange behaviour in terminals started by editors and IDEs (#5647). +If you are upgrading from version 2.7.1 or before, please also review the release notes for 3.0.1, 3.0.0 and 3.0b1 (included below). + +--- # fish 3.0.1 (released February 11, 2019) From d44308388fd73ac213c1f9a2f133ee12b1dfb3ad Mon Sep 17 00:00:00 2001 From: David Adam Date: Tue, 19 Feb 2019 21:20:31 +0800 Subject: [PATCH 069/191] cmake: use the check state stack for __nl_msg_cat_cntr checks --- cmake/gettext.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/gettext.cmake b/cmake/gettext.cmake index 001297bcb..b52a0a975 100644 --- a/cmake/gettext.cmake +++ b/cmake/gettext.cmake @@ -23,12 +23,12 @@ IF(GETTEXT_FOUND) ENDFOREACH() ENDIF() - +CMAKE_PUSH_CHECK_STATE() +SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Intl_INCLUDE_DIR}) +SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${Intl_LIBRARIES}) # libintl.h can be compiled into the stdlib on some GLibC systems IF(Intl_FOUND AND Intl_LIBRARIES) SET(LIBINTL_INCLUDE "#include ") - SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Intl_INCLUDE_DIR}) - SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${Intl_LIBRARIES}) ENDIF() CHECK_CXX_SOURCE_COMPILES(" ${LIBINTL_INCLUDE} @@ -40,3 +40,4 @@ int main () { } " HAVE__NL_MSG_CAT_CNTR) +CMAKE_POP_CHECK_STATE() From 28f57aa8ab6419205993dd440b30d130bf30c3f2 Mon Sep 17 00:00:00 2001 From: David Adam Date: Tue, 19 Feb 2019 21:33:05 +0800 Subject: [PATCH 070/191] Bump version for 3.0.2 --- CHANGELOG.md | 2 +- osx/Info.plist | 2 +- osx/config.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f3f52cf2..debaef037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# fish 3.0.2 +# fish 3.0.2 (released February 19, 2019) This release of fish fixes an issue discovered in fish 3.0.1. diff --git a/osx/Info.plist b/osx/Info.plist index 10b7d27df..7415edb86 100644 --- a/osx/Info.plist +++ b/osx/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 3.0.1 + 3.0.2 CFBundleVersion 0.1 LSApplicationCategoryType diff --git a/osx/config.h b/osx/config.h index 77128ac1e..1828562e4 100644 --- a/osx/config.h +++ b/osx/config.h @@ -209,7 +209,7 @@ #define PACKAGE_NAME "fish" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "fish 3.0.1" +#define PACKAGE_STRING "fish 3.0.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "fish" @@ -218,7 +218,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.0.1" +#define PACKAGE_VERSION "3.0.2" /* The size of `wchar_t', as computed by sizeof. */ #define SIZEOF_WCHAR_T 4 From 11a14032194c77d471b2f7eb642bf4255fd6ab36 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Tue, 19 Feb 2019 16:50:18 -0800 Subject: [PATCH 071/191] Remove extra semicolons --- src/env.h | 2 +- src/lru.h | 4 ++-- src/parse_grammar.h | 6 +++--- src/proc.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/env.h b/src/env.h index 5d2334efc..f5d240b84 100644 --- a/src/env.h +++ b/src/env.h @@ -95,7 +95,7 @@ class env_var_t { env_var_t() = default; - bool empty() const { return vals.empty() || (vals.size() == 1 && vals[0].empty()); }; + bool empty() const { return vals.empty() || (vals.size() == 1 && vals[0].empty()); } bool read_only() const { return flags & flag_read_only; } bool exports() const { return flags & flag_export; } bool is_pathvar() const { return flags & flag_pathvar; } diff --git a/src/lru.h b/src/lru.h index 31e192ba0..f91c63f74 100644 --- a/src/lru.h +++ b/src/lru.h @@ -291,8 +291,8 @@ class lru_cache_t { } }; - iterator begin() const { return iterator(mouth.prev); }; - iterator end() const { return iterator(&mouth); }; + iterator begin() const { return iterator(mouth.prev); } + iterator end() const { return iterator(&mouth); } void check_sanity() const { // Check linked list sanity diff --git a/src/parse_grammar.h b/src/parse_grammar.h index ce2344fdf..b6b1cb2ee 100644 --- a/src/parse_grammar.h +++ b/src/parse_grammar.h @@ -215,7 +215,7 @@ DEF_ALT(job_decorator) { // A job_conjunction is a job followed by a continuation. DEF(job_conjunction) produces_sequence { - BODY(job_conjunction); + BODY(job_conjunction) }; DEF_ALT(job_conjunction_continuation) { @@ -280,7 +280,7 @@ DEF_ALT(case_item_list) { }; DEF(case_item) produces_sequence, argument_list, tok_end, job_list> { - BODY(case_item); + BODY(case_item) }; DEF(block_statement) @@ -298,7 +298,7 @@ DEF_ALT(block_header) { DEF(for_header) produces_sequence, tok_string, keyword, argument_list, tok_end> { - BODY(for_header); + BODY(for_header) }; DEF(while_header) diff --git a/src/proc.h b/src/proc.h index c588cf766..30ed6e921 100644 --- a/src/proc.h +++ b/src/proc.h @@ -304,9 +304,9 @@ class job_t { // Helper functions to check presence of flags on instances of jobs /// The job has been fully constructed, i.e. all its member processes have been launched - bool is_constructed() const { return get_flag(job_flag_t::CONSTRUCTED); }; + bool is_constructed() const { return get_flag(job_flag_t::CONSTRUCTED); } /// The job was launched in the foreground and has control of the terminal - bool is_foreground() const { return get_flag(job_flag_t::FOREGROUND); }; + bool is_foreground() const { return get_flag(job_flag_t::FOREGROUND); } /// The job is complete, i.e. all its member processes have been reaped bool is_completed() const; /// The job is in a stopped state From 334eec94f8aedccbbe04dc07075f9b10f2b23185 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 12:58:59 -0800 Subject: [PATCH 072/191] Define _POSIX_C_SOURCE=200809L This enables thread-safe errno on Solaris and its descendants. Fixes #5611 --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7ae17b8f..af7b28979 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,11 +129,14 @@ SET_SOURCE_FILES_PROPERTIES(src/fish_version.cpp OPTION(INTERNAL_WCWIDTH "use fallback wcwidth" ON) IF(INTERNAL_WCWIDTH) - add_definitions(-DHAVE_BROKEN_WCWIDTH=1) + ADD_DEFINITIONS(-DHAVE_BROKEN_WCWIDTH=1) ELSE() - add_definitions(-DHAVE_BROKEN_WCWIDTH=0) + ADD_DEFINITIONS(-DHAVE_BROKEN_WCWIDTH=0) ENDIF() +# Enable thread-safe errno on Solaris (#5611) +ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200809L) + # Set up PCRE2 INCLUDE(cmake/PCRE2.cmake) From 177adb6837baea3cdf25e038deb355469e3e643e Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 13:28:46 -0800 Subject: [PATCH 073/191] Revert "Define _POSIX_C_SOURCE=200809L" This reverts commit 334eec94f8aedccbbe04dc07075f9b10f2b23185. This broke the Mac build --- CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af7b28979..d7ae17b8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,14 +129,11 @@ SET_SOURCE_FILES_PROPERTIES(src/fish_version.cpp OPTION(INTERNAL_WCWIDTH "use fallback wcwidth" ON) IF(INTERNAL_WCWIDTH) - ADD_DEFINITIONS(-DHAVE_BROKEN_WCWIDTH=1) + add_definitions(-DHAVE_BROKEN_WCWIDTH=1) ELSE() - ADD_DEFINITIONS(-DHAVE_BROKEN_WCWIDTH=0) + add_definitions(-DHAVE_BROKEN_WCWIDTH=0) ENDIF() -# Enable thread-safe errno on Solaris (#5611) -ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200809L) - # Set up PCRE2 INCLUDE(cmake/PCRE2.cmake) From 50f6fa048e850163083e2b392eb6f0408c4a468d Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 20 Feb 2019 22:28:55 +0100 Subject: [PATCH 074/191] completions/sudo: Quote `?` This was treated as a glob where it was still enabled, most likely removing the "-E" option from argparse, which caused `sudo -E` to not be parsed correctly, breaking completion. (There was no error because the glob was used with `set`) Fixes #5675. [ci skip] --- share/completions/sudo.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/completions/sudo.fish b/share/completions/sudo.fish index 3e5bf8b8d..710d557e2 100644 --- a/share/completions/sudo.fish +++ b/share/completions/sudo.fish @@ -7,7 +7,7 @@ function __fish_sudo_print_remaining_args set -e tokens[1] # These are all the options mentioned in the man page for Todd Miller's "sudo.ws" sudo (in that order). # If any other implementation has different options, this should be harmless, since they shouldn't be used anyway. - set -l opts A/askpass b/background C/close-from= E/preserve-env=? + set -l opts A/askpass b/background C/close-from= E/preserve-env='?' # Note that "-h" is both "--host" (which takes an option) and "--help" (which doesn't). # But `-h` as `--help` only counts when it's the only argument (`sudo -h`), # so any argument completion after that should take it as "--host". From e2348561900735b9c564d5d0b932495edd19c90f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 13:41:02 -0800 Subject: [PATCH 075/191] Define _REENTRANT This enables thread-safe errno on Solaris and its descendants. Fixes #5611 --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7ae17b8f..f04abb97d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,11 +129,14 @@ SET_SOURCE_FILES_PROPERTIES(src/fish_version.cpp OPTION(INTERNAL_WCWIDTH "use fallback wcwidth" ON) IF(INTERNAL_WCWIDTH) - add_definitions(-DHAVE_BROKEN_WCWIDTH=1) + ADD_DEFINITIONS(-DHAVE_BROKEN_WCWIDTH=1) ELSE() - add_definitions(-DHAVE_BROKEN_WCWIDTH=0) + ADD_DEFINITIONS(-DHAVE_BROKEN_WCWIDTH=0) ENDIF() +# Enable thread-safe errno on Solaris (#5611) +ADD_DEFINITIONS(-D_REENTRANT) + # Set up PCRE2 INCLUDE(cmake/PCRE2.cmake) From 44ad92ef50a786fedcd00dd1d5b39bc7643564d9 Mon Sep 17 00:00:00 2001 From: Max Nordlund Date: Wed, 20 Feb 2019 15:27:35 +0100 Subject: [PATCH 076/191] Fix typo --- share/functions/fish_git_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/functions/fish_git_prompt.fish b/share/functions/fish_git_prompt.fish index ffa52ea62..cb96b31eb 100644 --- a/share/functions/fish_git_prompt.fish +++ b/share/functions/fish_git_prompt.fish @@ -19,7 +19,7 @@ # script's __git_ps1 function. As such, usage and customization is very # similar, although some extra features are provided in this script. # Due to differences between bash and fish, the PROMPT_COMMAND style where -# passing two or three arguments causes the fucnction to set PS1 is not +# passing two or three arguments causes the function to set PS1 is not # supported. More information on the additional features is found after the # bash-compatable documentation. # From 13b2ff336d45444518fa14bdf0d8ca55e0bd726b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 14:21:31 -0800 Subject: [PATCH 077/191] Make var_dispatch_table const --- src/env.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index 6da436aba..eb510e1c6 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -97,7 +97,8 @@ static bool env_initialized = false; typedef std::unordered_map var_dispatch_table_t; -static var_dispatch_table_t var_dispatch_table; +static var_dispatch_table_t create_var_dispatch_table(); +static const var_dispatch_table_t s_var_dispatch_table = create_var_dispatch_table(); /// List of all locale environment variable names that might trigger (re)initializing the locale /// subsystem. @@ -623,8 +624,8 @@ static void react_to_variable_change(const wchar_t *op, const wcstring &key, env // call the appropriate functions to put the value of the var into effect. if (!env_initialized) return; - auto dispatch = var_dispatch_table.find(key); - if (dispatch != var_dispatch_table.end()) { + auto dispatch = s_var_dispatch_table.find(key); + if (dispatch != s_var_dispatch_table.end()) { (*dispatch->second)(op, key, vars); } else if (string_prefixes_string(L"fish_color_", key)) { reader_react_to_color_change(); @@ -864,7 +865,8 @@ static void handle_curses_change(const wcstring &op, const wcstring &var_name, e /// Populate the dispatch table used by `react_to_variable_change()` to efficiently call the /// appropriate function to handle a change to a variable. -static void setup_var_dispatch_table() { +static var_dispatch_table_t create_var_dispatch_table() { + var_dispatch_table_t var_dispatch_table; for (const auto &var_name : locale_variables) { var_dispatch_table.emplace(var_name, handle_locale_change); } @@ -887,11 +889,10 @@ static void setup_var_dispatch_table() { var_dispatch_table.emplace(L"fish_read_limit", handle_read_limit_change); var_dispatch_table.emplace(L"fish_history", handle_fish_history_change); var_dispatch_table.emplace(L"TZ", handle_tz_change); + return var_dispatch_table; } void env_init(const struct config_paths_t *paths /* or NULL */) { - setup_var_dispatch_table(); - env_stack_t &vars = env_stack_t::globals(); // Import environment variables. Walk backwards so that the first one out of any duplicates wins // (See issue #2784). From 75e83cac29e717fabff23712b181925f19f623fe Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 14:48:28 -0800 Subject: [PATCH 078/191] pwd short_options to be const --- src/builtin_pwd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builtin_pwd.cpp b/src/builtin_pwd.cpp index 1dce15da3..ca668b0ea 100644 --- a/src/builtin_pwd.cpp +++ b/src/builtin_pwd.cpp @@ -13,7 +13,7 @@ #include "wutil.h" // IWYU pragma: keep /// The pwd builtin. Respect -P to resolve symbolic links. Respect -L to not do that (the default). -static const wchar_t *short_options = L"LPh"; +static const wchar_t * const short_options = L"LPh"; static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { From de0b64409cbe5651d345ec206783f234b1ed108b Mon Sep 17 00:00:00 2001 From: George Christou Date: Tue, 19 Feb 2019 21:25:14 +0000 Subject: [PATCH 079/191] Teach autosuggestions to respect `forward-bigword` Closes #5336 --- CHANGELOG.md | 1 + src/reader.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f28ee5c25..6693e19c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - In the interest of consistency, `builtin -q` and `command -q` can now be used to query if a builtin or command exists (#5631). - The `path_helper` on macOS now only runs in login shells, matching the bash implementation. - `math` now accepts `--scale=max` for the maximum scale (#5579). +- The `forward-bigword` binding now interacts correctly with autosuggestions (#5336) --- diff --git a/src/reader.cpp b/src/reader.cpp index c18fc7c8e..c0e6e31fb 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1393,8 +1393,9 @@ static void update_autosuggestion() { } // Accept any autosuggestion by replacing the command line with it. If full is true, take the whole -// thing; if it's false, then take only the first "word". -static void accept_autosuggestion(bool full) { +// thing; if it's false, then respect the passed in style. +static void accept_autosuggestion(bool full, + move_word_style_t style = move_word_style_punctuation) { reader_data_t *data = current_data(); if (!data->autosuggestion.empty()) { // Accepting an autosuggestion clears the pager. @@ -1405,8 +1406,8 @@ static void accept_autosuggestion(bool full) { // Just take the whole thing. data->command_line.text = data->autosuggestion; } else { - // Accept characters up to a word separator. - move_word_state_machine_t state(move_word_style_punctuation); + // Accept characters according to the specified style. + move_word_state_machine_t state(style); for (size_t idx = data->command_line.size(); idx < data->autosuggestion.size(); idx++) { wchar_t wc = data->autosuggestion.at(idx); if (!state.consume_char(wc)) break; @@ -3038,7 +3039,7 @@ const wchar_t *reader_readline(int nchars) { move_word(el, MOVE_DIR_RIGHT, false /* do not erase */, move_style, false); } else { - accept_autosuggestion(false /* accept only one word */); + accept_autosuggestion(false, move_style); } break; } From 38d86acbc3868c4275a04fe2f1df83b06efafe0f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 16:33:54 -0800 Subject: [PATCH 080/191] Fix s_var_dispatch_table initialization It has to be declared after the variables it uses. --- src/env.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index eb510e1c6..ae3725402 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -95,11 +95,6 @@ bool term_has_xn = false; /// found in `TERMINFO_DIRS` we don't to call `handle_curses()` before we've imported the latter. static bool env_initialized = false; -typedef std::unordered_map - var_dispatch_table_t; -static var_dispatch_table_t create_var_dispatch_table(); -static const var_dispatch_table_t s_var_dispatch_table = create_var_dispatch_table(); - /// List of all locale environment variable names that might trigger (re)initializing the locale /// subsystem. static const wcstring_list_t locale_variables({L"LANG", L"LANGUAGE", L"LC_ALL", L"LC_ADDRESS", @@ -112,6 +107,11 @@ static const wcstring_list_t locale_variables({L"LANG", L"LANGUAGE", L"LC_ALL", /// subsystem. static const wcstring_list_t curses_variables({L"TERM", L"TERMINFO", L"TERMINFO_DIRS"}); +typedef std::unordered_map + var_dispatch_table_t; +static var_dispatch_table_t create_var_dispatch_table(); +static const var_dispatch_table_t s_var_dispatch_table = create_var_dispatch_table(); + // Some forward declarations to make it easy to logically group the code. static void init_locale(const environment_t &vars); static void init_curses(const environment_t &vars); From c6ec4235136e82c709e8d7b455f7c463f9714b48 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 22 Feb 2019 19:59:08 +0100 Subject: [PATCH 081/191] completions/systemctl: Harden version comparison Arch changed the version string to include the package rel, so it looks like systemd 241 (241.7-2-arch) which would break our simple `string replace` and `test`. Fixes #5689. [ci skip] --- share/completions/systemctl.fish | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/share/completions/systemctl.fish b/share/completions/systemctl.fish index e42c2aa63..eeeb58cf0 100644 --- a/share/completions/systemctl.fish +++ b/share/completions/systemctl.fish @@ -1,13 +1,13 @@ -set -l systemd_version (systemctl --version | string match "systemd*" | string replace -r "\D*(\d+)" '$1') +set -l systemd_version (systemctl --version | string match "systemd*" | string replace -r "\D*(\d+)\D.*" '$1') set -l commands list-units list-sockets start stop reload restart try-restart reload-or-restart reload-or-try-restart \ isolate kill is-active is-failed status show get-cgroup-attr set-cgroup-attr unset-cgroup-attr set-cgroup help \ reset-failed list-unit-files enable disable is-enabled reenable preset mask unmask link load list-jobs cancel dump \ list-dependencies snapshot delete daemon-reload daemon-reexec show-environment set-environment unset-environment \ default rescue emergency halt poweroff reboot kexec exit suspend hibernate hybrid-sleep switch-root list-timers \ set-property -if test $systemd_version -gt 208 +if test $systemd_version -gt 208 2>/dev/null set commands $commands cat - if test $systemd_version -gt 217 + if test $systemd_version -gt 217 2>/dev/null set commands $commands edit end end @@ -79,7 +79,7 @@ complete -f -c systemctl -l version -d 'Print a short version and exit' complete -f -c systemctl -l no-pager -d 'Do not pipe output into a pager' # New options since systemd 220 -if test $systemd_version -gt 219 +if test $systemd_version -gt 219 2>/dev/null complete -f -c systemctl -l firmware-setup -n "__fish_seen_subcommand_from reboot" -d "Reboot to EFI setup" complete -f -c systemctl -l now -n "__fish_seen_subcommand_from enable" -d "Also start unit" complete -f -c systemctl -l now -n "__fish_seen_subcommand_from disable mask" -d "Also stop unit" From f451499aa6c05146fc25fd0f2325bf13b7c6f84e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 22 Feb 2019 20:03:53 +0100 Subject: [PATCH 082/191] completions/valgrind: Fix option typo Fixes #5688. [ci skip] --- share/completions/valgrind.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/completions/valgrind.fish b/share/completions/valgrind.fish index eabcaf135..4722f3a01 100644 --- a/share/completions/valgrind.fish +++ b/share/completions/valgrind.fish @@ -35,8 +35,8 @@ complete -c valgrind -s q -l quiet -d "Quiet mode" complete -c valgrind -s v -l verbose -d "Verbose mode" complete -xc valgrind -l trace-children -d "Valgrind-ise children" -a "yes no" complete -xc valgrind -l track-fds -d "Track file descriptors" -a "yes no" -complete -xc valgrind -l logfile-fd -d "Log to file descriptor" -a "0 1 2 3 4 5 6 7 8 9" -complete -rc valgrind -l logfile -d "Log to file" +complete -xc valgrind -l log-fd -d "Log to file descriptor" -a "0 1 2 3 4 5 6 7 8 9" +complete -rc valgrind -l log-file -d "Log to file" complete -xc valgrind -l logsocket -d "Log to socket" complete -c valgrind -l demangle -xd "Demangle C++ names" -a "yes no" complete -xc valgrind -l num-callers -d "Callers in stack trace" From da04f757f9858638780a76285cda87ed01bd064f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 16:35:46 -0800 Subject: [PATCH 083/191] Minor cleanup to process_clean_after_marking --- src/proc.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/proc.cpp b/src/proc.cpp index e0bfff3e9..ebef04fc1 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -475,7 +475,7 @@ static wcstring truncate_command(const wcstring &cmd) { /// Format information about job status for the user to look at. typedef enum { JOB_STOPPED, JOB_ENDED } job_status_t; -static void format_job_info(const job_t *j, job_status_t status) { +static void print_job_status(const job_t *j, job_status_t status) { const wchar_t *msg = L"Job %d, '%ls' has ended"; // this is the most common status msg if (status == JOB_STOPPED) msg = L"Job %d, '%ls' has stopped"; @@ -499,7 +499,6 @@ void proc_fire_event(const wchar_t *msg, int type, pid_t pid, int status) { static bool process_clean_after_marking(bool allow_interactive) { ASSERT_IS_MAIN_THREAD(); - job_t *jnext; bool found = false; // this function may fire an event handler, we do not want to call ourselves recursively (to @@ -515,12 +514,8 @@ static bool process_clean_after_marking(bool allow_interactive) { const bool interactive = allow_interactive && cur_term != NULL; job_iterator_t jobs; - const size_t job_count = jobs.count(); - jnext = jobs.next(); - while (jnext) { - job_t *j = jnext; - jnext = jobs.next(); - + const bool only_one_job = jobs.count() == 1; + while (job_t *const j = jobs.next()) { // If we are reaping only jobs who do not need status messages sent to the console, do not // consider reaping jobs that need status messages. if ((!j->get_flag(job_flag_t::SKIP_NOTIFICATION)) && (!interactive) && @@ -572,14 +567,14 @@ static bool process_clean_after_marking(bool allow_interactive) { // We want to report the job number, unless it's the only job, in which case // we don't need to. const wcstring job_number_desc = - (job_count == 1) ? wcstring() : format_string(_(L"Job %d, "), j->job_id); + only_one_job ? wcstring() : format_string(_(L"Job %d, "), j->job_id); fwprintf(stdout, _(L"%ls: %ls\'%ls\' terminated by signal %ls (%ls)"), program_name, job_number_desc.c_str(), truncate_command(j->command()).c_str(), sig2wcs(WTERMSIG(p->status)), signal_get_desc(WTERMSIG(p->status))); } else { const wcstring job_number_desc = - (job_count == 1) ? wcstring() : format_string(L"from job %d, ", j->job_id); + only_one_job ? wcstring() : format_string(L"from job %d, ", j->job_id); const wchar_t *fmt = _(L"%ls: Process %d, \'%ls\' %ls\'%ls\' terminated by signal %ls (%ls)"); fwprintf(stdout, fmt, program_name, p->pid, p->argv0(), job_number_desc.c_str(), @@ -599,7 +594,7 @@ static bool process_clean_after_marking(bool allow_interactive) { if (j->is_completed()) { if (!j->is_foreground() && !j->get_flag(job_flag_t::NOTIFIED) && !j->get_flag(job_flag_t::SKIP_NOTIFICATION)) { - format_job_info(j, JOB_ENDED); + print_job_status(j, JOB_ENDED); found = true; } // TODO: The generic process-exit event is useless and unused. @@ -617,7 +612,7 @@ static bool process_clean_after_marking(bool allow_interactive) { } else if (j->is_stopped() && !j->get_flag(job_flag_t::NOTIFIED)) { // Notify the user about newly stopped jobs. if (!j->get_flag(job_flag_t::SKIP_NOTIFICATION)) { - format_job_info(j, JOB_STOPPED); + print_job_status(j, JOB_STOPPED); found = true; } j->set_flag(job_flag_t::NOTIFIED, true); From 6bddf2c83bc7e958bd58a42f007855f49f5eec12 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 17:07:29 -0800 Subject: [PATCH 084/191] Add basic signal test --- src/signal.cpp | 1 + tests/signal.err | 0 tests/signal.in | 6 ++++++ tests/signal.out | 1 + 4 files changed, 8 insertions(+) create mode 100644 tests/signal.err create mode 100644 tests/signal.in create mode 100644 tests/signal.out diff --git a/src/signal.cpp b/src/signal.cpp index 8c2886650..d48875cad 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -273,6 +273,7 @@ static void handle_sigalarm(int sig, siginfo_t *info, void *context) { UNUSED(info); UNUSED(context); if (reraise_if_forked_child(sig)) return; + default_handler(sig, info, context); } void signal_reset_handlers() { diff --git a/tests/signal.err b/tests/signal.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/signal.in b/tests/signal.in new file mode 100644 index 000000000..99dd46697 --- /dev/null +++ b/tests/signal.in @@ -0,0 +1,6 @@ +function alarm --on-signal ALRM + echo ALRM received +end + +kill -s ALRM $fish_pid + diff --git a/tests/signal.out b/tests/signal.out new file mode 100644 index 000000000..c2652b37d --- /dev/null +++ b/tests/signal.out @@ -0,0 +1 @@ +ALRM received From 0f30f05e167bcdfbc2b590d8ca795b4fb4f4f016 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 23 Feb 2019 12:18:15 -0800 Subject: [PATCH 085/191] Remove EVENT_ANY_SIGNAL This appeared to have been intended to allow functions to handle all signals, but this has not been exposed and it doesn't seem useful. --- src/event.cpp | 13 +------------ src/event.h | 3 --- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/event.cpp b/src/event.cpp index 62db87a9e..adb361389 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -73,7 +73,6 @@ static int event_match(const event_t &classv, const event_t &instance) { switch (classv.type) { case EVENT_SIGNAL: { - if (classv.param1.signal == EVENT_ANY_SIGNAL) return 1; return classv.param1.signal == instance.param1.signal; } case EVENT_VARIABLE: { @@ -177,8 +176,6 @@ static void show_all_handlers(void) { /// function will fire if the \c event is an event handler. static wcstring event_desc_compact(const event_t &event) { wcstring res; - wchar_t const *temp; - int sig; switch (event.type) { case EVENT_ANY: { res = L"EVENT_ANY"; @@ -193,15 +190,7 @@ static wcstring event_desc_compact(const event_t &event) { break; } case EVENT_SIGNAL: { - sig = event.param1.signal; - if (sig == EVENT_ANY_SIGNAL) { - temp = L"[all signals]"; - } else if (sig == 0) { - temp = L"not set"; - } else { - temp = sig2wcs(sig); - } - res = format_string(L"EVENT_SIGNAL(%ls)", temp); + res = format_string(L"EVENT_SIGNAL(%ls)", sig2wcs(event.param1.signal)); break; } case EVENT_EXIT: { diff --git a/src/event.h b/src/event.h index c28328810..e196c2805 100644 --- a/src/event.h +++ b/src/event.h @@ -15,9 +15,6 @@ #include "common.h" #include "io.h" -/// The signal number that is used to match any signal. -#define EVENT_ANY_SIGNAL -1 - /// The process id that is used to match any process id. #define EVENT_ANY_PID 0 From f015f930f1bd2d00e323274d8f9626f835c42738 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 23 Feb 2019 12:41:01 -0800 Subject: [PATCH 086/191] Enhance the signal test --- tests/signal.in | 9 +++++++++ tests/signal.out | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/signal.in b/tests/signal.in index 99dd46697..76db56d2d 100644 --- a/tests/signal.in +++ b/tests/signal.in @@ -2,5 +2,14 @@ function alarm --on-signal ALRM echo ALRM received end + kill -s ALRM $fish_pid +function anychild --on-process-exit 0 + # Type and exit status + echo $argv[1] $argv[3] +end + +command false +command true +command false | command true diff --git a/tests/signal.out b/tests/signal.out index c2652b37d..234258bf5 100644 --- a/tests/signal.out +++ b/tests/signal.out @@ -1 +1,9 @@ ALRM received +PROCESS_EXIT 1 +JOB_EXIT 0 +PROCESS_EXIT 0 +JOB_EXIT 0 +PROCESS_EXIT 1 +PROCESS_EXIT 0 +JOB_EXIT 0 +PROCESS_EXIT 0 From 003998c92112fbf6ccee56e2b0bc68ecee8be952 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 21:41:35 -0800 Subject: [PATCH 087/191] Event blocks just block all events In a galaxy far, far away, event_blockage_t was intended to block only cetain events. But it always just blocked everything. Eliminate the event block mask. --- src/builtin_block.cpp | 1 - src/parser.h | 14 ++------------ tests/signal.in | 12 +++++++++++- tests/signal.out | 8 ++++++++ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/builtin_block.cpp b/src/builtin_block.cpp index 72652e683..dfe8ef046 100644 --- a/src/builtin_block.cpp +++ b/src/builtin_block.cpp @@ -102,7 +102,6 @@ int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) { block_t *block = parser.block_at_index(block_idx); event_blockage_t eb = {}; - eb.typemask = (1 << EVENT_ANY); switch (opts.scope) { case LOCAL: { diff --git a/src/parser.h b/src/parser.h index 6edea461e..17b1f970f 100644 --- a/src/parser.h +++ b/src/parser.h @@ -20,24 +20,14 @@ class io_chain_t; -/// event_blockage_t represents a block on events of the specified type. +/// event_blockage_t represents a block on events. struct event_blockage_t { - /// The types of events to block. This is interpreted as a bitset whete the value is 1 for every - /// bit corresponding to a blocked event type. For example, if EVENT_VARIABLE type events should - /// be blocked, (type & 1< event_blockage_list_t; inline bool event_block_list_blocks_type(const event_blockage_list_t &ebls, int type) { - for (event_blockage_list_t::const_iterator iter = ebls.begin(); iter != ebls.end(); ++iter) { - if (iter->typemask & (1 << EVENT_ANY)) return true; - if (iter->typemask & (1 << type)) return true; - } - return false; + return !ebls.empty(); } /// Types of blocks. diff --git a/tests/signal.in b/tests/signal.in index 76db56d2d..118c1d2e5 100644 --- a/tests/signal.in +++ b/tests/signal.in @@ -2,7 +2,6 @@ function alarm --on-signal ALRM echo ALRM received end - kill -s ALRM $fish_pid function anychild --on-process-exit 0 @@ -10,6 +9,17 @@ function anychild --on-process-exit 0 echo $argv[1] $argv[3] end +echo "command false:" command false +echo "command true:" command true +echo "command false | true:" command false | command true + +function test_blocks + block -l + command echo "This is the process whose exit event shuld be blocked" + echo "This should come before the event handler" +end +test_blocks +echo "Now event handler should have run" diff --git a/tests/signal.out b/tests/signal.out index 234258bf5..10aa9b5f3 100644 --- a/tests/signal.out +++ b/tests/signal.out @@ -1,9 +1,17 @@ ALRM received +command false: PROCESS_EXIT 1 JOB_EXIT 0 +command true: PROCESS_EXIT 0 JOB_EXIT 0 +command false | true: PROCESS_EXIT 1 PROCESS_EXIT 0 JOB_EXIT 0 +This is the process whose exit event shuld be blocked +This should come before the event handler +PROCESS_EXIT 0 +JOB_EXIT 0 +Now event handler should have run PROCESS_EXIT 0 From 1b8ddacfedf5197125899fba1bcdb556d379299c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 19:36:29 -0800 Subject: [PATCH 088/191] Reimplement signal handling event machinery Prior to this fix, fish had a signal_list_t that accumulated signals. Signals were added to an array of integers, with an overflow flag. The event machinery would attempt to atomically "swap in" the other list. After this fix, there is a single list of pending signal events, as an array of atomic booleans. The signal handler sets the boolean corresponding to its signal. --- src/event.cpp | 174 +++++++++++++++++++++++++++---------------------- src/event.h | 5 +- src/proc.cpp | 2 +- src/signal.cpp | 2 +- 4 files changed, 99 insertions(+), 84 deletions(-) diff --git a/src/event.cpp b/src/event.cpp index adb361389..55b116564 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -21,26 +22,65 @@ #include "signal.h" #include "wutil.h" // IWYU pragma: keep -/// Number of signals that can be queued before an overflow occurs. -#define SIG_UNHANDLED_MAX 64 +class pending_signals_t { + static constexpr size_t SIGNAL_COUNT = NSIG; -/// This struct contains a list of generated signals waiting to be dispatched. -typedef struct { - /// Number of delivered signals. - volatile int count; - /// Whether signals have been skipped. - volatile int overflow; - /// Array of signal events. - volatile int signal[SIG_UNHANDLED_MAX]; -} signal_list_t; + /// A counter that is incremented each time a pending signal is received. + std::atomic counter_{0}; -/// The signal event list. Actually two separate lists. One which is active, which is the one that -/// new events is written to. The inactive one contains the events that are currently beeing -/// performed. -static signal_list_t sig_list[2] = {{}, {}}; + /// List of pending signals. + std::array, SIGNAL_COUNT> received_{}; -/// The index of sig_list that is the list of signals currently written to. -static volatile int active_list = 0; + /// The last counter visible in acquire_pending(). + /// This is not accessed from a signal handler. + owning_lock last_counter_{0}; + +public: + pending_signals_t() = default; + + /// No copying. + pending_signals_t(const pending_signals_t &); + void operator=(const pending_signals_t &); + + /// Mark a signal as pending. This may be called from a signal handler. + /// We expect only one signal handler to execute at once. + /// Also note that these may be coalesced. + void mark(int which) { + if (which >= 0 && static_cast(which) < received_.size()) { + // Must mark our received first, then pending. + received_[which].store(true, std::memory_order_relaxed); + uint32_t count = counter_.load(std::memory_order_relaxed); + counter_.store(1 + count, std::memory_order_release); + } + } + + /// \return the list of signals that were set, clearing them. + std::bitset acquire_pending() { + auto current = last_counter_.acquire(); + + // Check the counter first. If it hasn't changed, no signals have been received. + uint32_t count = counter_.load(std::memory_order_acquire); + if (count == *current) { + return {}; + } + + // The signal count has changed. Store the new counter and fetch all the signals that are set. + *current = count; + std::bitset result{}; + uint32_t bit = 0; + for (auto &signal : received_) { + bool val = signal.load(std::memory_order_relaxed); + if (val) { + result.set(bit); + signal.store(false, std::memory_order_relaxed); + } + bit++; + } + return result; + } +}; + +static pending_signals_t s_pending_signals; typedef std::vector> event_list_t; @@ -300,6 +340,10 @@ bool event_is_signal_observed(int sig) { /// event handler, we make sure to optimize the 'no matches' path. This means that nothing is /// allocated/initialized unless needed. static void event_fire_internal(const event_t &event) { + ASSERT_IS_MAIN_THREAD(); + assert(is_event >= 0 && "is_event should not be negative"); + scoped_push inc_event{&is_event, is_event + 1}; + // Iterate over all events, adding events that should be fired to a second list. We need // to do this in a separate step since an event handler might call event_remove or // event_add_handler, which will change the contents of the \c events list. @@ -358,81 +402,53 @@ static void event_fire_internal(const event_t &event) { /// Handle all pending signal events. static void event_fire_delayed() { - // If is_event is one, we are running the event-handler non-recursively. - // - // When the event handler has called a piece of code that triggers another event, we do not want - // to fire delayed events because of concurrency problems. - if (!blocked.empty() && is_event == 1) { - event_list_t local_blocked; - local_blocked.swap(blocked); - for (const shared_ptr &e : local_blocked) { - if (event_is_blocked(*e)) { - blocked.push_back(e); - } else { - event_fire_internal(*e); + ASSERT_IS_MAIN_THREAD(); + // Do not invoke new event handlers from within event handlers. + if (is_event) + return; + + event_list_t to_send; + to_send.swap(blocked); + assert(blocked.empty()); + + // Append all signal events to to_send. + auto signals = s_pending_signals.acquire_pending(); + if (signals.any()) { + for (uint32_t sig=0; sig < signals.size(); sig++) { + if (signals.test(sig)) { + auto e = std::make_shared(EVENT_SIGNAL); + e->param1.signal = sig; + e->arguments.push_back(sig2wcs(sig)); + to_send.push_back(std::move(e)); } } } - int al = active_list; - - while (sig_list[al].count > 0) { - signal_list_t *lst; - - // Switch signal lists. - sig_list[1 - al].count = 0; - sig_list[1 - al].overflow = 0; - al = 1 - al; - active_list = al; - - // Set up. - lst = &sig_list[1 - al]; - if (lst->overflow) { - debug(0, _(L"Signal list overflow. Signals have been ignored.")); - } - - // Send all signals in our private list. - for (int i = 0; i < lst->count; i++) { - shared_ptr e = std::make_shared(EVENT_SIGNAL); - int signal = lst->signal[i]; - e->param1.signal = signal; - e->arguments.push_back(sig2wcs(signal)); - if (event_is_blocked(*e)) { - blocked.push_back(e); - } else { - event_fire_internal(*e); - } + // Fire or re-block all events. + for (const auto &evt : to_send) { + if (event_is_blocked(*evt)) { + blocked.push_back(evt); + } else { + event_fire_internal(*evt); } } } -void event_fire_signal(int signal) { - // This means we are in a signal handler. We must be very careful not do do anything that could - // cause a memory allocation or something else that might be bad when in a signal handler. - if (sig_list[active_list].count < SIG_UNHANDLED_MAX) - sig_list[active_list].signal[sig_list[active_list].count++] = signal; - else - sig_list[active_list].overflow = 1; +void event_enqueue_signal(int signal) { + // Beware, we are in a signal handler + s_pending_signals.mark(signal); } void event_fire(const event_t *event) { - if (event && event->type == EVENT_SIGNAL) { - event_fire_signal(event->param1.signal); - } else { - is_event++; + // Fire events triggered by signals. + event_fire_delayed(); - // Fire events triggered by signals. - event_fire_delayed(); - - if (event) { - if (event_is_blocked(*event)) { - blocked.push_back(std::make_shared(*event)); - } else { - event_fire_internal(*event); - } + if (event) { + if (event_is_blocked(*event)) { + blocked.push_back(std::make_shared(*event)); + } else { + event_fire_internal(*event); } - is_event--; - assert(is_event >= 0); } } diff --git a/src/event.h b/src/event.h index e196c2805..95d787456 100644 --- a/src/event.h +++ b/src/event.h @@ -120,9 +120,8 @@ bool event_is_signal_observed(int signal); /// will be fired. void event_fire(const event_t *event); -/// Like event_fire, but takes a signal directly. -/// May be called from signal handlers -void event_fire_signal(int signal); +/// Enqueue a signal event. Invoked from a signal handler. +void event_enqueue_signal(int signal); /// Print all events. If type_filter is not none(), only output events with that type. void event_print(io_streams_t &streams, maybe_t type_filter); diff --git a/src/proc.cpp b/src/proc.cpp index ebef04fc1..5753f7c2f 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -80,7 +80,7 @@ bool is_subshell = false; bool is_block = false; bool is_breakpoint = false; bool is_login = false; -int is_event = false; +int is_event = 0; int job_control_mode = JOB_CONTROL_INTERACTIVE; int no_exec = 0; diff --git a/src/signal.cpp b/src/signal.cpp index d48875cad..69dadd325 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -205,7 +205,7 @@ static void default_handler(int signal, siginfo_t *info, void *context) { UNUSED(info); UNUSED(context); if (event_is_signal_observed(signal)) { - event_fire_signal(signal); + event_enqueue_signal(signal); } } From 780b53ba73fbe1c9fc8b0571468399e49cb08a4e Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 20 Feb 2019 22:42:58 -0800 Subject: [PATCH 089/191] Convert event_type_t to an enum class --- src/builtin_function.cpp | 8 ++-- src/builtin_functions.cpp | 12 +++--- src/event.cpp | 86 +++++++++++++++++++-------------------- src/event.h | 18 ++++---- src/fish.cpp | 2 +- src/function.cpp | 2 +- src/parser.h | 2 +- src/proc.cpp | 10 ++--- src/proc.h | 3 +- 9 files changed, 72 insertions(+), 71 deletions(-) diff --git a/src/builtin_function.cpp b/src/builtin_function.cpp index b1bccdbfd..bec67bff5 100644 --- a/src/builtin_function.cpp +++ b/src/builtin_function.cpp @@ -87,7 +87,7 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig case 'j': case 'p': { pid_t pid; - event_t e(EVENT_ANY); + event_t e(event_type_t::any); if ((opt == 'j') && (wcscasecmp(w.woptarg, L"caller") == 0)) { job_id_t job_id = -1; @@ -113,11 +113,11 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig _(L"%ls: Cannot find calling job for event handler"), cmd); return STATUS_INVALID_ARGS; } - e.type = EVENT_JOB_ID; + e.type = event_type_t::job_exit; e.param1.job_id = job_id; } else if ((opt == 'p') && (wcscasecmp(w.woptarg, L"%self") == 0)) { pid = getpid(); - e.type = EVENT_EXIT; + e.type = event_type_t::exit; e.param1.pid = pid; } else { pid = fish_wcstoi(w.woptarg); @@ -127,7 +127,7 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig return STATUS_INVALID_ARGS; } - e.type = EVENT_EXIT; + e.type = event_type_t::exit; e.param1.pid = (opt == 'j' ? -1 : 1) * abs(pid); } opts.events.push_back(e); diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 42575b503..1acb4e085 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -126,7 +126,7 @@ static wcstring functions_def(const wcstring &name) { wcstring desc, def; function_get_desc(name, desc); function_get_definition(name, def); - event_t search(EVENT_ANY); + event_t search(event_type_t::any); search.function_name = name; std::vector> ev; event_get(search, &ev); @@ -154,27 +154,27 @@ static wcstring functions_def(const wcstring &name) { for (const auto &next : ev) { switch (next->type) { - case EVENT_SIGNAL: { + case event_type_t::signal: { append_format(out, L" --on-signal %ls", sig2wcs(next->param1.signal)); break; } - case EVENT_VARIABLE: { + case event_type_t::variable: { append_format(out, L" --on-variable %ls", next->str_param1.c_str()); break; } - case EVENT_EXIT: { + case event_type_t::exit: { if (next->param1.pid > 0) append_format(out, L" --on-process-exit %d", next->param1.pid); else append_format(out, L" --on-job-exit %d", -next->param1.pid); break; } - case EVENT_JOB_ID: { + case event_type_t::job_exit: { const job_t *j = job_t::from_job_id(next->param1.job_id); if (j) append_format(out, L" --on-job-exit %d", j->pgid); break; } - case EVENT_GENERIC: { + case event_type_t::generic: { append_format(out, L" --on-event %ls", next->str_param1.c_str()); break; } diff --git a/src/event.cpp b/src/event.cpp index 55b116564..9ebf3b1dc 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -108,24 +108,24 @@ static int event_match(const event_t &classv, const event_t &instance) { return 0; } - if (classv.type == EVENT_ANY) return 1; + if (classv.type == event_type_t::any) return 1; if (classv.type != instance.type) return 0; switch (classv.type) { - case EVENT_SIGNAL: { + case event_type_t::signal: { return classv.param1.signal == instance.param1.signal; } - case EVENT_VARIABLE: { + case event_type_t::variable: { return instance.str_param1 == classv.str_param1; } - case EVENT_EXIT: { + case event_type_t::exit: { if (classv.param1.pid == EVENT_ANY_PID) return 1; return classv.param1.pid == instance.param1.pid; } - case EVENT_JOB_ID: { + case event_type_t::job_exit: { return classv.param1.job_id == instance.param1.job_id; } - case EVENT_GENERIC: { + case event_type_t::generic: { return instance.str_param1 == classv.str_param1; } default: { @@ -146,24 +146,24 @@ static int event_is_blocked(const event_t &e) { size_t idx = 0; while ((block = parser.block_at_index(idx++))) { - if (event_block_list_blocks_type(block->event_blocks, e.type)) return true; + if (event_block_list_blocks_type(block->event_blocks)) return true; } - return event_block_list_blocks_type(parser.global_event_blocks, e.type); + return event_block_list_blocks_type(parser.global_event_blocks); } wcstring event_get_desc(const event_t &e) { wcstring result; switch (e.type) { - case EVENT_SIGNAL: { + case event_type_t::signal: { result = format_string(_(L"signal handler for %ls (%ls)"), sig2wcs(e.param1.signal), signal_get_desc(e.param1.signal)); break; } - case EVENT_VARIABLE: { + case event_type_t::variable: { result = format_string(_(L"handler for variable '%ls'"), e.str_param1.c_str()); break; } - case EVENT_EXIT: { + case event_type_t::exit: { if (e.param1.pid > 0) { result = format_string(_(L"exit handler for process %d"), e.param1.pid); } else { @@ -178,7 +178,7 @@ wcstring event_get_desc(const event_t &e) { } break; } - case EVENT_JOB_ID: { + case event_type_t::job_exit: { job_t *j = job_t::from_job_id(e.param1.job_id); if (j) { result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, @@ -188,7 +188,7 @@ wcstring event_get_desc(const event_t &e) { } break; } - case EVENT_GENERIC: { + case event_type_t::generic: { result = format_string(_(L"handler for generic event '%ls'"), e.str_param1.c_str()); break; } @@ -217,11 +217,11 @@ static void show_all_handlers(void) { static wcstring event_desc_compact(const event_t &event) { wcstring res; switch (event.type) { - case EVENT_ANY: { + case event_type_t::any: { res = L"EVENT_ANY"; break; } - case EVENT_VARIABLE: { + case event_type_t::variable: { if (event.str_param1.c_str()) { res = format_string(L"EVENT_VARIABLE($%ls)", event.str_param1.c_str()); } else { @@ -229,11 +229,11 @@ static wcstring event_desc_compact(const event_t &event) { } break; } - case EVENT_SIGNAL: { + case event_type_t::signal: { res = format_string(L"EVENT_SIGNAL(%ls)", sig2wcs(event.param1.signal)); break; } - case EVENT_EXIT: { + case event_type_t::exit: { if (event.param1.pid == EVENT_ANY_PID) { res = wcstring(L"EVENT_EXIT([all child processes])"); } else if (event.param1.pid > 0) { @@ -249,7 +249,7 @@ static wcstring event_desc_compact(const event_t &event) { } break; } - case EVENT_JOB_ID: { + case event_type_t::job_exit: { job_t *j = job_t::from_job_id(event.param1.job_id); if (j) res = @@ -258,7 +258,7 @@ static wcstring event_desc_compact(const event_t &event) { res = format_string(L"EVENT_JOB_ID(jobid %d)", event.param1.job_id); break; } - case EVENT_GENERIC: { + case event_type_t::generic: { res = format_string(L"EVENT_GENERIC(%ls)", event.str_param1.c_str()); break; } @@ -280,7 +280,7 @@ void event_add_handler(const event_t &event) { } shared_ptr e = std::make_shared(event); - if (e->type == EVENT_SIGNAL) { + if (e->type == event_type_t::signal) { signal_handle(e->param1.signal, 1); set_signal_observed(e->param1.signal, true); } @@ -304,7 +304,7 @@ void event_remove(const event_t &criterion) { // If this event was a signal handler and no other handler handles the specified signal // type, do not handle that type of signal any more. - if (n->type == EVENT_SIGNAL) { + if (n->type == event_type_t::signal) { event_t e = event_t::signal_event(n->param1.signal); if (event_get(e, NULL) == 1) { signal_handle(e.param1.signal, 0); @@ -416,7 +416,7 @@ static void event_fire_delayed() { if (signals.any()) { for (uint32_t sig=0; sig < signals.size(); sig++) { if (signals.test(sig)) { - auto e = std::make_shared(EVENT_SIGNAL); + auto e = std::make_shared(event_type_t::signal); e->param1.signal = sig; e->arguments.push_back(sig2wcs(sig)); to_send.push_back(std::move(e)); @@ -459,13 +459,11 @@ struct event_type_name_t { const wchar_t *name; }; -static const event_type_name_t events_mapping[] = { - {EVENT_SIGNAL, L"signal"}, - {EVENT_VARIABLE, L"variable"}, - {EVENT_EXIT, L"exit"}, - {EVENT_JOB_ID, L"job-id"}, - {EVENT_GENERIC, L"generic"} -}; +static const event_type_name_t events_mapping[] = {{event_type_t::signal, L"signal"}, + {event_type_t::variable, L"variable"}, + {event_type_t::exit, L"exit"}, + {event_type_t::job_exit, L"job-id"}, + {event_type_t::generic, L"generic"}}; maybe_t event_type_for_name(const wcstring &name) { for (const auto &em : events_mapping) { @@ -492,13 +490,15 @@ void event_print(io_streams_t &streams, maybe_t type_filter) { [](const shared_ptr &e1, const shared_ptr &e2) { if (e1->type == e2->type) { switch (e1->type) { - case EVENT_SIGNAL: + case event_type_t::signal: return e1->param1.signal < e2->param1.signal; - case EVENT_JOB_ID: + case event_type_t::exit: + return e1->param1.pid < e2->param1.pid; + case event_type_t::job_exit: return e1->param1.job_id < e2->param1.job_id; - case EVENT_VARIABLE: - case EVENT_ANY: - case EVENT_GENERIC: + case event_type_t::variable: + case event_type_t::any: + case event_type_t::generic: return e1->str_param1 < e2->str_param1; } } @@ -519,16 +519,16 @@ void event_print(io_streams_t &streams, maybe_t type_filter) { streams.out.append_format(L"Event %ls\n", event_name_for_type(*last_type)); } switch (evt->type) { - case EVENT_SIGNAL: + case event_type_t::signal: streams.out.append_format(L"%ls %ls\n", sig2wcs(evt->param1.signal), evt->function_name.c_str()); break; - case EVENT_JOB_ID: + case event_type_t::job_exit: streams.out.append_format(L"%d %ls\n", evt->param1, evt->function_name.c_str()); break; - case EVENT_VARIABLE: - case EVENT_GENERIC: + case event_type_t::variable: + case event_type_t::generic: streams.out.append_format(L"%ls %ls\n", evt->str_param1.c_str(), evt->function_name.c_str()); break; @@ -542,30 +542,30 @@ void event_print(io_streams_t &streams, maybe_t type_filter) { void event_fire_generic(const wchar_t *name, wcstring_list_t *args) { CHECK(name, ); - event_t ev(EVENT_GENERIC); + event_t ev(event_type_t::generic); ev.str_param1 = name; if (args) ev.arguments = *args; event_fire(&ev); } -event_t::event_t(int t) : type(t), param1(), str_param1(), function_name(), arguments() {} +event_t::event_t(event_type_t t) : type(t), param1(), str_param1(), function_name(), arguments() {} event_t::~event_t() = default; event_t event_t::signal_event(int sig) { - event_t event(EVENT_SIGNAL); + event_t event(event_type_t::signal); event.param1.signal = sig; return event; } event_t event_t::variable_event(const wcstring &str) { - event_t event(EVENT_VARIABLE); + event_t event(event_type_t::variable); event.str_param1 = str; return event; } event_t event_t::generic_event(const wcstring &str) { - event_t event(EVENT_GENERIC); + event_t event(event_type_t::generic); event.str_param1 = str; return event; } diff --git a/src/event.h b/src/event.h index 95d787456..a56ee98ce 100644 --- a/src/event.h +++ b/src/event.h @@ -19,20 +19,20 @@ #define EVENT_ANY_PID 0 /// Enumeration of event types. -enum event_type_t { +enum class event_type_t { /// Matches any event type (Not always any event, as the function name may limit the choice as /// well. - EVENT_ANY, + any, /// An event triggered by a signal. - EVENT_SIGNAL, + signal, /// An event triggered by a variable update. - EVENT_VARIABLE, + variable, /// An event triggered by a job or process exit. - EVENT_EXIT, + exit, /// An event triggered by a job exit. - EVENT_JOB_ID, + job_exit, /// A generic event. - EVENT_GENERIC, + generic, }; /// The structure which represents an event. The event_t struct has several event-related use-cases: @@ -47,7 +47,7 @@ enum event_type_t { struct event_t { public: /// Type of event. - int type; + event_type_t type; /// The type-specific parameter. The int types are one of the following: /// @@ -73,7 +73,7 @@ struct event_t { /// situations, the value of this variable is ignored. wcstring_list_t arguments; - explicit event_t(int t); + explicit event_t(event_type_t t); ~event_t(); static event_t signal_event(int sig); diff --git a/src/fish.cpp b/src/fish.cpp index e481cd4cc..d75eaae44 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -434,7 +434,7 @@ int main(int argc, char **argv) { // TODO: The generic process-exit event is useless and unused. // Remove this in future. - proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, getpid(), exit_status); + proc_fire_event(L"PROCESS_EXIT", event_type_t::exit, getpid(), exit_status); // Trigger any exit handlers. wcstring_list_t event_args = {to_string(exit_status)}; diff --git a/src/function.cpp b/src/function.cpp index 9d51d1699..1fae86831 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -224,7 +224,7 @@ static bool function_remove_ignore_autoload(const wcstring &name, bool tombstone if (iter->second.is_autoload && tombstone) function_tombstones.insert(name); loaded_functions.erase(iter); - event_t ev(EVENT_ANY); + event_t ev(event_type_t::any); ev.function_name = name; event_remove(ev); return true; diff --git a/src/parser.h b/src/parser.h index 17b1f970f..92a470f88 100644 --- a/src/parser.h +++ b/src/parser.h @@ -26,7 +26,7 @@ struct event_blockage_t { typedef std::list event_blockage_list_t; -inline bool event_block_list_blocks_type(const event_blockage_list_t &ebls, int type) { +inline bool event_block_list_blocks_type(const event_blockage_list_t &ebls) { return !ebls.empty(); } diff --git a/src/proc.cpp b/src/proc.cpp index 5753f7c2f..9baa1bb00 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -107,7 +107,7 @@ void set_proc_had_barrier(bool flag) { } /// The event variable used to send all process event. -static event_t event(0); +static event_t event{event_type_t::any}; /// A stack containing the values of is_interactive. Used by proc_push_interactive and /// proc_pop_interactive. @@ -486,7 +486,7 @@ static void print_job_status(const job_t *j, job_status_t status) { fwprintf(stdout, L"\n"); } -void proc_fire_event(const wchar_t *msg, int type, pid_t pid, int status) { +void proc_fire_event(const wchar_t *msg, event_type_t type, pid_t pid, int status) { event.type = type; event.param1.pid = pid; @@ -535,7 +535,7 @@ static bool process_clean_after_marking(bool allow_interactive) { // Remove this in future. // Update: This event is used for cleaning up the psub temporary files and folders. // Removing it breaks the psub tests as a result. - proc_fire_event(L"PROCESS_EXIT", EVENT_EXIT, p->pid, + proc_fire_event(L"PROCESS_EXIT", event_type_t::exit, p->pid, (WIFSIGNALED(s) ? -1 : WEXITSTATUS(s))); // Ignore signal SIGPIPE.We issue it ourselves to the pipe writer when the pipe reader @@ -604,9 +604,9 @@ static bool process_clean_after_marking(bool allow_interactive) { // or jobs that consist entirely of builtins (and hence don't have a process). // This causes issues if fish is PID 2, which is quite common on WSL. See #4582. if (j->pgid != INVALID_PID) { - proc_fire_event(L"JOB_EXIT", EVENT_EXIT, -j->pgid, 0); + proc_fire_event(L"JOB_EXIT", event_type_t::exit, -j->pgid, 0); } - proc_fire_event(L"JOB_EXIT", EVENT_JOB_ID, j->job_id, 0); + proc_fire_event(L"JOB_EXIT", event_type_t::job_exit, j->job_id, 0); job_remove(j); } else if (j->is_stopped() && !j->get_flag(job_flag_t::NOTIFIED)) { diff --git a/src/proc.h b/src/proc.h index 30ed6e921..3e986f160 100644 --- a/src/proc.h +++ b/src/proc.h @@ -17,6 +17,7 @@ #include "common.h" #include "enum_set.h" +#include "event.h" #include "io.h" #include "parse_tree.h" #include "tnode.h" @@ -439,7 +440,7 @@ void proc_sanity_check(); /// Send a process/job exit event notification. This function is a convenience wrapper around /// event_fire(). -void proc_fire_event(const wchar_t *msg, int type, pid_t pid, int status); +void proc_fire_event(const wchar_t *msg, event_type_t type, pid_t pid, int status); /// Initializations. void proc_init(); From f1b208997c6c2b90e209a6335178cbaef8adb34b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 23 Feb 2019 01:04:05 -0800 Subject: [PATCH 090/191] Cleanup events Prior to this fix, an "event" was used as both a predicate on which events to match, and also as the event itself. Re-express these concepts distinctly: an event is something that happened, an event_handler is the predicate and name of the function to execute. --- src/builtin_function.cpp | 17 +- src/builtin_functions.cpp | 22 +-- src/env.cpp | 27 +-- src/event.cpp | 388 ++++++++++++++------------------------ src/event.h | 99 +++++----- src/function.cpp | 8 +- src/function.h | 2 +- src/input.cpp | 2 +- src/proc.cpp | 10 +- 9 files changed, 216 insertions(+), 359 deletions(-) diff --git a/src/builtin_function.cpp b/src/builtin_function.cpp index bec67bff5..104a728d8 100644 --- a/src/builtin_function.cpp +++ b/src/builtin_function.cpp @@ -29,7 +29,7 @@ struct function_cmd_opts_t { bool print_help = false; bool shadow_scope = true; wcstring description = L""; - std::vector events; + std::vector events; wcstring_list_t named_arguments; wcstring_list_t inherit_vars; wcstring_list_t wrap_targets; @@ -68,7 +68,7 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig streams.err.append_format(_(L"%ls: Unknown signal '%ls'"), cmd, w.woptarg); return STATUS_INVALID_ARGS; } - opts.events.push_back(event_t::signal_event(sig)); + opts.events.push_back(event_description_t::signal(sig)); break; } case 'v': { @@ -77,17 +77,17 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig return STATUS_INVALID_ARGS; } - opts.events.push_back(event_t::variable_event(w.woptarg)); + opts.events.push_back(event_description_t::variable(w.woptarg)); break; } case 'e': { - opts.events.push_back(event_t::generic_event(w.woptarg)); + opts.events.push_back(event_description_t::generic(w.woptarg)); break; } case 'j': case 'p': { pid_t pid; - event_t e(event_type_t::any); + event_description_t e(event_type_t::any); if ((opt == 'j') && (wcscasecmp(w.woptarg, L"caller") == 0)) { job_id_t job_id = -1; @@ -251,16 +251,11 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis d.name = function_name; if (!opts.description.empty()) d.description = opts.description; // d.description = opts.description; - d.events.swap(opts.events); + d.events = std::move(opts.events); d.props.shadow_scope = opts.shadow_scope; d.props.named_arguments = std::move(opts.named_arguments); d.inherit_vars = std::move(opts.inherit_vars); - for (size_t i = 0; i < d.events.size(); i++) { - event_t &e = d.events.at(i); - e.function_name = d.name; - } - d.props.parsed_source = source; d.props.body_node = body; function_add(std::move(d), parser); diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 1acb4e085..860f675e7 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -126,10 +126,7 @@ static wcstring functions_def(const wcstring &name) { wcstring desc, def; function_get_desc(name, desc); function_get_definition(name, def); - event_t search(event_type_t::any); - search.function_name = name; - std::vector> ev; - event_get(search, &ev); + std::vector> ev = event_get_function_handlers(name); out.append(L"function "); @@ -153,29 +150,30 @@ static wcstring functions_def(const wcstring &name) { } for (const auto &next : ev) { - switch (next->type) { + const event_description_t &d = next->desc; + switch (d.type) { case event_type_t::signal: { - append_format(out, L" --on-signal %ls", sig2wcs(next->param1.signal)); + append_format(out, L" --on-signal %ls", sig2wcs(d.param1.signal)); break; } case event_type_t::variable: { - append_format(out, L" --on-variable %ls", next->str_param1.c_str()); + append_format(out, L" --on-variable %ls", d.str_param1.c_str()); break; } case event_type_t::exit: { - if (next->param1.pid > 0) - append_format(out, L" --on-process-exit %d", next->param1.pid); + if (d.param1.pid > 0) + append_format(out, L" --on-process-exit %d", d.param1.pid); else - append_format(out, L" --on-job-exit %d", -next->param1.pid); + append_format(out, L" --on-job-exit %d", -d.param1.pid); break; } case event_type_t::job_exit: { - const job_t *j = job_t::from_job_id(next->param1.job_id); + const job_t *j = job_t::from_job_id(d.param1.job_id); if (j) append_format(out, L" --on-job-exit %d", j->pgid); break; } case event_type_t::generic: { - append_format(out, L" --on-event %ls", next->str_param1.c_str()); + append_format(out, L" --on-event %ls", d.str_param1.c_str()); break; } default: { diff --git a/src/env.cpp b/src/env.cpp index ae3725402..83cb2cf32 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -639,12 +639,7 @@ static void universal_callback(env_stack_t *stack, const callback_data_t &cb) { react_to_variable_change(op, cb.key, *stack); stack->mark_changed_exported(); - - event_t ev = event_t::variable_event(cb.key); - ev.arguments.push_back(L"VARIABLE"); - ev.arguments.push_back(op); - ev.arguments.push_back(cb.key); - event_fire(&ev); + event_fire(event_t::variable(cb.key, {L"VARIABLE", op, cb.key})); } /// Make sure the PATH variable contains something. @@ -1256,12 +1251,7 @@ int env_stack_t::set_internal(const wcstring &key, env_mode_flags_t input_var_mo } } - event_t ev = event_t::variable_event(key); - ev.arguments.reserve(3); - ev.arguments.push_back(L"VARIABLE"); - ev.arguments.push_back(L"SET"); - ev.arguments.push_back(key); - event_fire(&ev); + event_fire(event_t::variable(key, {L"VARIABLE", L"SET", key})); react_to_variable_change(L"SET", key, *this); return ENV_OK; } @@ -1327,12 +1317,7 @@ int env_stack_t::remove(const wcstring &key, int var_mode) { } if (try_remove(first_node, key.c_str(), var_mode)) { - event_t ev = event_t::variable_event(key); - ev.arguments.push_back(L"VARIABLE"); - ev.arguments.push_back(L"ERASE"); - ev.arguments.push_back(key); - event_fire(&ev); - + event_fire(event_t::variable(key, {L"VARIABLE", L"ERASE", key})); erased = 1; } } @@ -1347,11 +1332,7 @@ int env_stack_t::remove(const wcstring &key, int var_mode) { } if (erased) { env_universal_barrier(); - event_t ev = event_t::variable_event(key); - ev.arguments.push_back(L"VARIABLE"); - ev.arguments.push_back(L"ERASE"); - ev.arguments.push_back(key); - event_fire(&ev); + event_fire(event_t::variable(key, {L"VARIABLE", L"ERASE", key})); } if (is_exported) vars_stack().mark_changed_exported(); diff --git a/src/event.cpp b/src/event.cpp index 9ebf3b1dc..c345edd03 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -82,12 +82,11 @@ public: static pending_signals_t s_pending_signals; -typedef std::vector> event_list_t; - /// List of event handlers. -static event_list_t s_event_handlers; +static event_handler_list_t s_event_handlers; /// List of events that have been sent but have not yet been delivered because they are blocked. +using event_list_t = std::vector>; static event_list_t blocked; /// Variables (one per signal) set when a signal is observed. This is inspected by a signal handler. @@ -99,44 +98,33 @@ static void set_signal_observed(int sig, bool val) { } } -/// Tests if one event instance matches the definition of a event class. If both the class and the -/// instance name a function, they must name the same function. -static int event_match(const event_t &classv, const event_t &instance) { - // If the function names are both non-empty and different, then it's not a match. - if (!classv.function_name.empty() && !instance.function_name.empty() && - classv.function_name != instance.function_name) { - return 0; - } +/// Tests if one event instance matches the definition of a event class. +static bool handler_matches(const event_handler_t &classv, const event_t &instance) { + if (classv.desc.type == event_type_t::any) return true; + if (classv.desc.type != instance.desc.type) return false; - if (classv.type == event_type_t::any) return 1; - if (classv.type != instance.type) return 0; - - switch (classv.type) { + switch (classv.desc.type) { case event_type_t::signal: { - return classv.param1.signal == instance.param1.signal; + return classv.desc.param1.signal == instance.desc.param1.signal; } case event_type_t::variable: { - return instance.str_param1 == classv.str_param1; + return instance.desc.str_param1 == classv.desc.str_param1; } case event_type_t::exit: { - if (classv.param1.pid == EVENT_ANY_PID) return 1; - return classv.param1.pid == instance.param1.pid; + if (classv.desc.param1.pid == EVENT_ANY_PID) return true; + return classv.desc.param1.pid == instance.desc.param1.pid; } case event_type_t::job_exit: { - return classv.param1.job_id == instance.param1.job_id; + return classv.desc.param1.job_id == instance.desc.param1.job_id; } case event_type_t::generic: { - return instance.str_param1 == classv.str_param1; + return classv.desc.str_param1 == instance.desc.str_param1; } default: { DIE("unexpected classv.type"); - break; + return false; } } - - // This should never be reached. - debug(0, "Warning: Unreachable code reached in event_match in event.cpp\n"); - return 0; } /// Test if specified event is blocked. @@ -151,54 +139,52 @@ static int event_is_blocked(const event_t &e) { return event_block_list_blocks_type(parser.global_event_blocks); } -wcstring event_get_desc(const event_t &e) { - wcstring result; - switch (e.type) { +wcstring event_get_desc(const event_t &evt) { + const event_description_t &ed = evt.desc; + switch (ed.type) { case event_type_t::signal: { - result = format_string(_(L"signal handler for %ls (%ls)"), sig2wcs(e.param1.signal), - signal_get_desc(e.param1.signal)); - break; + return format_string(_(L"signal handler for %ls (%ls)"), sig2wcs(ed.param1.signal), + signal_get_desc(ed.param1.signal)); } + case event_type_t::variable: { - result = format_string(_(L"handler for variable '%ls'"), e.str_param1.c_str()); - break; + return format_string(_(L"handler for variable '%ls'"), ed.str_param1.c_str()); } + case event_type_t::exit: { - if (e.param1.pid > 0) { - result = format_string(_(L"exit handler for process %d"), e.param1.pid); + if (ed.param1.pid > 0) { + return format_string(_(L"exit handler for process %d"), ed.param1.pid); } else { // In events, PGIDs are stored as negative PIDs - job_t *j = job_t::from_pid(-e.param1.pid); - if (j) - result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, - j->command_wcstr()); - else - result = format_string(_(L"exit handler for job with process group %d"), - -e.param1.pid); + job_t *j = job_t::from_pid(-ed.param1.pid); + if (j) { + return format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, + j->command_wcstr()); + } else { + return format_string(_(L"exit handler for job with process group %d"), + -ed.param1.pid); + } } - break; + assert(0 && "Unreachable"); } - case event_type_t::job_exit: { - job_t *j = job_t::from_job_id(e.param1.job_id); - if (j) { - result = format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, - j->command_wcstr()); - } else { - result = format_string(_(L"exit handler for job with job id %d"), e.param1.job_id); - } - break; - } - case event_type_t::generic: { - result = format_string(_(L"handler for generic event '%ls'"), e.str_param1.c_str()); - break; - } - default: { - result = format_string(_(L"Unknown event type '0x%x'"), e.type); - break; - } - } - return result; + case event_type_t::job_exit: { + job_t *j = job_t::from_job_id(ed.param1.job_id); + if (j) { + return format_string(_(L"exit handler for job %d, '%ls'"), j->job_id, + j->command_wcstr()); + } else { + return format_string(_(L"exit handler for job with job id %d"), ed.param1.job_id); + } + break; + } + + case event_type_t::generic: { + return format_string(_(L"handler for generic event '%ls'"), ed.str_param1.c_str()); + } + default: + assert(0 && "Unknown event type"); + } } #if 0 @@ -212,119 +198,34 @@ static void show_all_handlers(void) { } #endif -/// Give a more condensed description of \c event compared to \c event_get_desc. It includes what -/// function will fire if the \c event is an event handler. -static wcstring event_desc_compact(const event_t &event) { - wcstring res; - switch (event.type) { - case event_type_t::any: { - res = L"EVENT_ANY"; - break; - } - case event_type_t::variable: { - if (event.str_param1.c_str()) { - res = format_string(L"EVENT_VARIABLE($%ls)", event.str_param1.c_str()); - } else { - res = L"EVENT_VARIABLE([any])"; - } - break; - } - case event_type_t::signal: { - res = format_string(L"EVENT_SIGNAL(%ls)", sig2wcs(event.param1.signal)); - break; - } - case event_type_t::exit: { - if (event.param1.pid == EVENT_ANY_PID) { - res = wcstring(L"EVENT_EXIT([all child processes])"); - } else if (event.param1.pid > 0) { - res = format_string(L"EVENT_EXIT(pid %d)", event.param1.pid); - } else { - // In events, PGIDs are stored as negative PIDs - job_t *j = job_t::from_pid(-event.param1.pid); - if (j) - res = format_string(L"EVENT_EXIT(jobid %d: \"%ls\")", j->job_id, - j->command_wcstr()); - else - res = format_string(L"EVENT_EXIT(pgid %d)", -event.param1.pid); - } - break; - } - case event_type_t::job_exit: { - job_t *j = job_t::from_job_id(event.param1.job_id); - if (j) - res = - format_string(L"EVENT_JOB_ID(job %d: \"%ls\")", j->job_id, j->command_wcstr()); - else - res = format_string(L"EVENT_JOB_ID(jobid %d)", event.param1.job_id); - break; - } - case event_type_t::generic: { - res = format_string(L"EVENT_GENERIC(%ls)", event.str_param1.c_str()); - break; - } - default: { - res = format_string(L"unknown/illegal event(%x)", event.type); - break; - } +void event_add_handler(std::shared_ptr eh) { + if (eh->desc.type == event_type_t::signal) { + signal_handle(eh->desc.param1.signal, 1); + set_signal_observed(eh->desc.param1.signal, true); } - if (event.function_name.size()) { - return format_string(L"%ls: \"%ls\"", res.c_str(), event.function_name.c_str()); - } - return res; + + s_event_handlers.push_back(std::move(eh)); } -void event_add_handler(const event_t &event) { - if (debug_level >= 3) { - wcstring desc = event_desc_compact(event); - debug(3, "register: %ls", desc.c_str()); - } - - shared_ptr e = std::make_shared(event); - if (e->type == event_type_t::signal) { - signal_handle(e->param1.signal, 1); - set_signal_observed(e->param1.signal, true); - } - - s_event_handlers.push_back(std::move(e)); -} - -void event_remove(const event_t &criterion) { - if (debug_level >= 3) { - wcstring desc = event_desc_compact(criterion); - debug(3, "unregister: %ls", desc.c_str()); - } - - event_list_t::iterator iter = s_event_handlers.begin(); - while (iter != s_event_handlers.end()) { - const event_t *n = iter->get(); - if (!event_match(criterion, *n)) { - ++iter; - continue; - } - - // If this event was a signal handler and no other handler handles the specified signal - // type, do not handle that type of signal any more. - if (n->type == event_type_t::signal) { - event_t e = event_t::signal_event(n->param1.signal); - if (event_get(e, NULL) == 1) { - signal_handle(e.param1.signal, 0); - set_signal_observed(e.param1.signal, 0); - } - } - iter = s_event_handlers.erase(iter); - } -} - -int event_get(const event_t &criterion, event_list_t *out) { +void event_remove_function_handlers(const wcstring &name) { ASSERT_IS_MAIN_THREAD(); - int found = 0; - for (const shared_ptr &n : s_event_handlers) { - if (event_match(criterion, *n)) { - found++; - if (out) out->push_back(n); + auto begin = s_event_handlers.begin(), end = s_event_handlers.end(); + s_event_handlers.erase(std::remove_if(begin, end, + [&](const shared_ptr &eh) { + return eh->function_name == name; + }), + end); +} + +event_handler_list_t event_get_function_handlers(const wcstring &name) { + ASSERT_IS_MAIN_THREAD(); + event_handler_list_t result; + for (const shared_ptr &eh : s_event_handlers) { + if (eh->function_name == name) { + result.push_back(eh); } } - return found; + return result; } bool event_is_signal_observed(int sig) { @@ -344,14 +245,12 @@ static void event_fire_internal(const event_t &event) { assert(is_event >= 0 && "is_event should not be negative"); scoped_push inc_event{&is_event, is_event + 1}; - // Iterate over all events, adding events that should be fired to a second list. We need - // to do this in a separate step since an event handler might call event_remove or - // event_add_handler, which will change the contents of the \c events list. - event_list_t fire; - for (shared_ptr &criterion : s_event_handlers) { + // Capture the event handlers that match this event. + event_handler_list_t fire; + for (const auto &handler : s_event_handlers) { // Check if this event is a match. - if (event_match(*criterion, event)) { - fire.push_back(criterion); + if (handler_matches(*handler, event)) { + fire.push_back(handler); } } @@ -359,29 +258,27 @@ static void event_fire_internal(const event_t &event) { if (fire.empty()) return; if (signal_is_blocked()) { - // Fix for https://github.com/fish-shell/fish-shell/issues/608. Don't run event handlers - // while signals are blocked. + // Fix for #608. Don't run event handlers while signals are blocked. input_common_add_callback([event]() { ASSERT_IS_MAIN_THREAD(); - event_fire(&event); + event_fire(event); }); return; } - // Iterate over our list of matching events. - for (shared_ptr &criterion : fire) { + // Iterate over our list of matching events. Fire the ones that are still present. + for (const shared_ptr &handler : fire) { // Only fire if this event is still present - if (!contains(s_event_handlers, criterion)) { + if (!contains(s_event_handlers, handler)) { continue; } - // Fire event. - wcstring buffer = criterion->function_name; - - for (size_t j = 0; j < event.arguments.size(); j++) { - wcstring arg_esc = escape_string(event.arguments.at(j), 1); - buffer += L" "; - buffer += arg_esc; + // Construct a buffer to evaluate, starting with the function name and then all the + // arguments. + wcstring buffer = handler->function_name; + for (const wcstring &arg : event.arguments) { + buffer.push_back(L' '); + buffer.append(escape_string(arg, ESCAPE_ALL)); } // debug( 1, L"Event handler fires command '%ls'", buffer.c_str() ); @@ -401,7 +298,7 @@ static void event_fire_internal(const event_t &event) { } /// Handle all pending signal events. -static void event_fire_delayed() { +void event_fire_delayed() { ASSERT_IS_MAIN_THREAD(); // Do not invoke new event handlers from within event handlers. if (is_event) @@ -417,7 +314,7 @@ static void event_fire_delayed() { for (uint32_t sig=0; sig < signals.size(); sig++) { if (signals.test(sig)) { auto e = std::make_shared(event_type_t::signal); - e->param1.signal = sig; + e->desc.param1.signal = sig; e->arguments.push_back(sig2wcs(sig)); to_send.push_back(std::move(e)); } @@ -439,16 +336,14 @@ void event_enqueue_signal(int signal) { s_pending_signals.mark(signal); } -void event_fire(const event_t *event) { +void event_fire(const event_t &event) { // Fire events triggered by signals. event_fire_delayed(); - if (event) { - if (event_is_blocked(*event)) { - blocked.push_back(std::make_shared(*event)); - } else { - event_fire_internal(*event); - } + if (event_is_blocked(event)) { + blocked.push_back(std::make_shared(event)); + } else { + event_fire_internal(event); } } @@ -485,52 +380,54 @@ static const wchar_t *event_name_for_type(event_type_t type) { void event_print(io_streams_t &streams, maybe_t type_filter) { - std::vector> tmp = s_event_handlers; + event_handler_list_t tmp = s_event_handlers; std::sort(tmp.begin(), tmp.end(), - [](const shared_ptr &e1, const shared_ptr &e2) { - if (e1->type == e2->type) { - switch (e1->type) { - case event_type_t::signal: - return e1->param1.signal < e2->param1.signal; - case event_type_t::exit: - return e1->param1.pid < e2->param1.pid; - case event_type_t::job_exit: - return e1->param1.job_id < e2->param1.job_id; - case event_type_t::variable: - case event_type_t::any: - case event_type_t::generic: - return e1->str_param1 < e2->str_param1; - } - } - return e1->type < e2->type; - }); + [](const shared_ptr &e1, const shared_ptr &e2) { + const event_description_t &d1 = e1->desc; + const event_description_t &d2 = e2->desc; + if (d1.type != d2.type) { + return d1.type < d2.type; + } + switch (d1.type) { + case event_type_t::signal: + return d1.signal < d2.signal; + case event_type_t::exit: + return d1.param1.pid < d2.param1.pid; + case event_type_t::job_exit: + return d1.param1.job_id < d2.param1.job_id; + case event_type_t::variable: + case event_type_t::any: + case event_type_t::generic: + return d1.str_param1 < d2.str_param1; + } + }); maybe_t last_type{}; - for (const shared_ptr &evt : tmp) { + for (const shared_ptr &evt : tmp) { // If we have a filter, skip events that don't match. - if (type_filter && *type_filter != evt->type) { + if (type_filter && *type_filter != evt->desc.type) { continue; } - if (!last_type || *last_type != evt->type) { + if (!last_type || *last_type != evt->desc.type) { if (last_type) streams.out.append(L"\n"); - last_type = static_cast(evt->type); + last_type = static_cast(evt->desc.type); streams.out.append_format(L"Event %ls\n", event_name_for_type(*last_type)); } - switch (evt->type) { + switch (evt->desc.type) { case event_type_t::signal: - streams.out.append_format(L"%ls %ls\n", sig2wcs(evt->param1.signal), - evt->function_name.c_str()); + streams.out.append_format(L"%ls %ls\n", sig2wcs(evt->desc.param1.signal), + evt->function_name.c_str()); break; case event_type_t::job_exit: - streams.out.append_format(L"%d %ls\n", evt->param1, - evt->function_name.c_str()); + streams.out.append_format(L"%d %ls\n", evt->desc.param1, + evt->function_name.c_str()); break; case event_type_t::variable: case event_type_t::generic: - streams.out.append_format(L"%ls %ls\n", evt->str_param1.c_str(), - evt->function_name.c_str()); + streams.out.append_format(L"%ls %ls\n", evt->desc.str_param1.c_str(), + evt->function_name.c_str()); break; default: streams.out.append_format(L"%ls\n", evt->function_name.c_str()); @@ -539,33 +436,36 @@ void event_print(io_streams_t &streams, maybe_t type_filter) { } } -void event_fire_generic(const wchar_t *name, wcstring_list_t *args) { +void event_fire_generic(const wchar_t *name, const wcstring_list_t *args) { CHECK(name, ); event_t ev(event_type_t::generic); - ev.str_param1 = name; + ev.desc.str_param1 = name; if (args) ev.arguments = *args; - event_fire(&ev); + event_fire(ev); } -event_t::event_t(event_type_t t) : type(t), param1(), str_param1(), function_name(), arguments() {} - -event_t::~event_t() = default; - -event_t event_t::signal_event(int sig) { - event_t event(event_type_t::signal); +event_description_t event_description_t::signal(int sig) { + event_description_t event(event_type_t::signal); event.param1.signal = sig; return event; } -event_t event_t::variable_event(const wcstring &str) { - event_t event(event_type_t::variable); - event.str_param1 = str; +event_description_t event_description_t::variable(wcstring str) { + event_description_t event(event_type_t::variable); + event.str_param1 = std::move(str); return event; } -event_t event_t::generic_event(const wcstring &str) { - event_t event(event_type_t::generic); - event.str_param1 = str; +event_description_t event_description_t::generic(wcstring str) { + event_description_t event(event_type_t::generic); + event.str_param1 = std::move(str); return event; } + +event_t event_t::variable(wcstring name, wcstring_list_t args) { + event_t evt{event_type_t::variable}; + evt.desc.str_param1 = std::move(name); + evt.arguments = std::move(args); + return evt; +} diff --git a/src/event.h b/src/event.h index a56ee98ce..7fa7baf8f 100644 --- a/src/event.h +++ b/src/event.h @@ -35,18 +35,9 @@ enum class event_type_t { generic, }; -/// The structure which represents an event. The event_t struct has several event-related use-cases: -/// -/// - When used as a parameter to event_add, it represents a class of events, and function_name is -/// the name of the function which will be called whenever an event matching the specified class -/// occurs. This is also how events are stored internally. -/// -/// - When used as a parameter to event_get, event_remove and event_fire, it represents a class of -/// events, and if the function_name field is non-zero, only events which call the specified -/// function will be returned. -struct event_t { - public: - /// Type of event. +/// Properties of an event. +struct event_description_t { + /// The event type. event_type_t type; /// The type-specific parameter. The int types are one of the following: @@ -58,67 +49,65 @@ struct event_t { int signal; int job_id; pid_t pid; - } param1; + } param1{}; /// The string types are one of the following: /// /// variable: Variable name for variable-type events. /// param: The parameter describing this generic event. - wcstring str_param1; + wcstring str_param1{}; - /// The name of the event handler function. - wcstring function_name; + explicit event_description_t(event_type_t t) : type(t) {} + static event_description_t signal(int sig); + static event_description_t variable(wcstring str); + static event_description_t generic(wcstring str); +}; - /// The argument list. Only used when sending a new event using event_fire. In all other - /// situations, the value of this variable is ignored. - wcstring_list_t arguments; +/// Represents a handler for an event. +struct event_handler_t { + /// Properties of the event to match. + event_description_t desc; - explicit event_t(event_type_t t); - ~event_t(); + /// Name of the function to invoke. + wcstring function_name{}; - static event_t signal_event(int sig); - static event_t variable_event(const wcstring &str); - static event_t generic_event(const wcstring &str); + explicit event_handler_t(event_type_t t) : desc(t) {} + event_handler_t(event_description_t d, wcstring name) + : desc(d), function_name(std::move(name)) {} +}; +using event_handler_list_t = std::vector>; + +/// Represents a event that is fired, or capable of being fired. +struct event_t { + /// Properties of the event. + event_description_t desc; + + /// Arguments to any handler. + wcstring_list_t arguments{}; + + event_t(event_type_t t) : desc(t) {} + + static event_t variable(wcstring name, wcstring_list_t args); }; /// Add an event handler. -/// -/// May not be called by a signal handler, since it may allocate new memory. -void event_add_handler(const event_t &event); +void event_add_handler(std::shared_ptr eh); -/// Remove all events matching the specified criterion. -/// -/// May not be called by a signal handler, since it may free allocated memory. -void event_remove(const event_t &event); +/// Remove all events for the given function name. +void event_remove_function_handlers(const wcstring &name); -/// Return all events which match the specified event class -/// -/// This function is safe to call from a signal handler _ONLY_ if the out parameter is null. -/// -/// \param criterion Is the class of events to return. If the criterion has a non-null -/// function_name, only events which trigger the specified function will return. -/// \param out the list to add events to. May be 0, in which case no events will be added, but the -/// result count will still be valid -/// -/// \return the number of found matches -int event_get(const event_t &criterion, std::vector> *out); +/// Return all event handlers for the given function. +event_handler_list_t event_get_function_handlers(const wcstring &name); /// Returns whether an event listener is registered for the given signal. This is safe to call from /// a signal handler. bool event_is_signal_observed(int signal); -/// Fire the specified event. The function_name field of the event must be set to 0. If the event is -/// of type EVENT_SIGNAL, no the event is queued, and will be dispatched the next time event_fire is -/// called. If event is a null-pointer, all pending events are dispatched. -/// -/// This function is safe to call from a signal handler _ONLY_ if the event parameter is for a -/// signal. Signal events not be fired, by the call to event_fire, instead they will be fired the -/// next time event_fire is called with anull argument. This is needed to make sure that no code -/// evaluation is ever performed by a signal handler. -/// -/// \param event the specific event whose handlers should fire. If null, then all delayed events -/// will be fired. -void event_fire(const event_t *event); +/// Fire the specified event \p event. +void event_fire(const event_t &event); + +/// Fire all delayed eents. +void event_fire_delayed(); /// Enqueue a signal event. Invoked from a signal handler. void event_enqueue_signal(int signal); @@ -130,7 +119,7 @@ void event_print(io_streams_t &streams, maybe_t type_filter); wcstring event_get_desc(const event_t &e); /// Fire a generic event with the specified name. -void event_fire_generic(const wchar_t *name, wcstring_list_t *args = NULL); +void event_fire_generic(const wchar_t *name, const wcstring_list_t *args = NULL); /// Return the event type for a given name, or none. maybe_t event_type_for_name(const wcstring &name); diff --git a/src/function.cpp b/src/function.cpp index 1fae86831..bffa0d8cf 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -175,8 +175,8 @@ void function_add(const function_data_t &data, const parser_t &parser) { loaded_functions.insert(new_pair); // Add event handlers. - for (const event_t &event : data.events) { - event_add_handler(event); + for (const event_description_t &ed : data.events) { + event_add_handler(std::make_shared(ed, data.name)); } } @@ -224,9 +224,7 @@ static bool function_remove_ignore_autoload(const wcstring &name, bool tombstone if (iter->second.is_autoload && tombstone) function_tombstones.insert(name); loaded_functions.erase(iter); - event_t ev(event_type_t::any); - ev.function_name = name; - event_remove(ev); + event_remove_function_handlers(name); return true; } diff --git a/src/function.h b/src/function.h index 9ee7df6eb..fc6529e72 100644 --- a/src/function.h +++ b/src/function.h @@ -44,7 +44,7 @@ struct function_data_t { /// Function's metadata fields function_properties_t props; /// List of all event handlers for this function. - std::vector events; + std::vector events; }; /// Add a function. diff --git a/src/input.cpp b/src/input.cpp index 0a9e9a008..bcbc04fab 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -252,7 +252,7 @@ void input_mapping_add(const wchar_t *sequence, const wchar_t *command, const wc /// reader. static int interrupt_handler() { // Fire any pending events. - event_fire(NULL); + event_fire_delayed(); // Reap stray processes, including printing exit status messages. if (job_reap(true)) reader_repaint_needed(); // Tell the reader an event occured. diff --git a/src/proc.cpp b/src/proc.cpp index 9baa1bb00..81c7d4cab 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -106,9 +106,6 @@ void set_proc_had_barrier(bool flag) { proc_had_barrier = flag; } -/// The event variable used to send all process event. -static event_t event{event_type_t::any}; - /// A stack containing the values of is_interactive. Used by proc_push_interactive and /// proc_pop_interactive. static std::vector interactive_stack; @@ -487,14 +484,13 @@ static void print_job_status(const job_t *j, job_status_t status) { } void proc_fire_event(const wchar_t *msg, event_type_t type, pid_t pid, int status) { - event.type = type; - event.param1.pid = pid; + event_t event{type}; + event.desc.param1.pid = pid; event.arguments.push_back(msg); event.arguments.push_back(to_string(pid)); event.arguments.push_back(to_string(status)); - event_fire(&event); - event.arguments.resize(0); + event_fire(event); } static bool process_clean_after_marking(bool allow_interactive) { From 0ff4046b8cbaeda76d6fec5a26d6a0e774ec7ce4 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 23 Feb 2019 13:44:11 -0800 Subject: [PATCH 091/191] Remove signal blocks from terminal_return_from_job There's nothing justifying having these here. --- src/proc.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/proc.cpp b/src/proc.cpp index 81c7d4cab..1390c027b 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -821,12 +821,10 @@ static bool terminal_return_from_job(job_t *j) { return true; } - signal_block(); if (tcsetpgrp(STDIN_FILENO, getpgrp()) == -1) { if (errno == ENOTTY) redirect_tty_output(); debug(1, _(L"Could not return shell to foreground")); wperror(L"tcsetpgrp"); - signal_unblock(); return false; } @@ -835,7 +833,6 @@ static bool terminal_return_from_job(job_t *j) { if (errno == EIO) redirect_tty_output(); debug(1, _(L"Could not return shell to foreground")); wperror(L"tcgetattr"); - signal_unblock(); return false; } @@ -853,7 +850,6 @@ return false; } #endif - signal_unblock(); return true; } From ec65ba342789bb03f32a05affe163d071a1793d9 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 23 Feb 2019 13:48:16 -0800 Subject: [PATCH 092/191] Remove signal_block_t Bravely removing more signal blocks, now that our signal handling is so simple. --- src/proc.cpp | 4 ---- src/signal.h | 12 ------------ 2 files changed, 16 deletions(-) diff --git a/src/proc.cpp b/src/proc.cpp index 1390c027b..b6117d90f 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -701,10 +701,6 @@ bool terminal_give_to_job(const job_t *j, bool restore_attrs) { return true; } - // RAII wrappers must have a name so that their scope is tied to the function as it is legal for - // the compiler to construct and then immediately deconstruct unnamed objects otherwise. - signal_block_t signal_block; - // It may not be safe to call tcsetpgrp if we've already done so, as at that point we are no // longer the controlling process group for the terminal and no longer have permission to set // the process group that is in control, causing tcsetpgrp to return EPERM, even though that's diff --git a/src/signal.h b/src/signal.h index fa5af8682..be0e1d23b 100644 --- a/src/signal.h +++ b/src/signal.h @@ -41,16 +41,4 @@ bool signal_is_blocked(); /// Returns signals with non-default handlers. void get_signals_with_handlers(sigset_t *set); -/// A RAII wrapper for signal_block/signal_unblock that triggers a signal block on creation, and then -/// automatically releases the block when the object is destroyed, handling control flow and exceptions. -struct signal_block_t { - signal_block_t() { - signal_block(); - } - - ~signal_block_t() { - signal_unblock(); - } -}; - #endif From 130f2266d0764e377f27ae5c13acbdeed5e1b2be Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 23 Feb 2019 14:07:17 -0800 Subject: [PATCH 093/191] Remove the last of the signal blocking and checks fish's signal handlers are now sufficiently innocuous that there should be no reason to block signals (outside of temporarily, when creating a thread and we need to manipulate the signal mask). --- src/autoload.cpp | 1 - src/common.h | 13 ------------- src/event.cpp | 12 ------------ src/input.cpp | 2 -- src/parser.cpp | 3 --- src/signal.cpp | 34 ---------------------------------- src/signal.h | 9 --------- 7 files changed, 74 deletions(-) diff --git a/src/autoload.cpp b/src/autoload.cpp index a3ad207c1..9f13bb8b2 100644 --- a/src/autoload.cpp +++ b/src/autoload.cpp @@ -63,7 +63,6 @@ int autoload_t::unload(const wcstring &cmd) { return this->evict_node(cmd); } int autoload_t::load(const wcstring &cmd, bool reload) { int res; - CHECK_BLOCK(0); ASSERT_IS_MAIN_THREAD(); // TODO: Justify this principal_parser. diff --git a/src/common.h b/src/common.h index b74d6d98d..d99524cd4 100644 --- a/src/common.h +++ b/src/common.h @@ -272,19 +272,6 @@ inline bool is_whitespace(const wchar_t *input) { return is_whitespace(wcstring( [[noreturn]] void __fish_assert(const char *msg, const char *file, size_t line, int error); -/// Check if signals are blocked. If so, print an error message and return from the function -/// performing this check. -#define CHECK_BLOCK(retval) -#if 0 -#define CHECK_BLOCK(retval) \ - if (signal_is_blocked()) { \ - debug(0, "function %s called while blocking signals. ", __func__); \ - bugreport(); \ - show_stackframe(L'E'); \ - return retval; \ - } -#endif - /// Shorthand for wgettext call in situations where a C-style string is needed (e.g., fwprintf()). #define _(wstr) wgettext(wstr).c_str() diff --git a/src/event.cpp b/src/event.cpp index c345edd03..00944d1db 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -254,18 +254,6 @@ static void event_fire_internal(const event_t &event) { } } - // No matches. Time to return. - if (fire.empty()) return; - - if (signal_is_blocked()) { - // Fix for #608. Don't run event handlers while signals are blocked. - input_common_add_callback([event]() { - ASSERT_IS_MAIN_THREAD(); - event_fire(event); - }); - return; - } - // Iterate over our list of matching events. Fire the ones that are still present. for (const shared_ptr &handler : fire) { // Only fire if this event is still present diff --git a/src/input.cpp b/src/input.cpp index bcbc04fab..ea9deb0cb 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -483,8 +483,6 @@ static wchar_t input_read_characters_only() { } wint_t input_readch(bool allow_commands) { - CHECK_BLOCK(R_NULL); - // Clear the interrupted flag. reader_reset_interrupted(); // Search for sequence in mapping tables. diff --git a/src/parser.cpp b/src/parser.cpp index 124fdbb6b..db23ce43c 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -647,7 +647,6 @@ int parser_t::eval(wcstring cmd, const io_chain_t &io, enum block_type_t block_t } void parser_t::eval(parsed_source_ref_t ps, const io_chain_t &io, enum block_type_t block_type) { - CHECK_BLOCK(1); assert(block_type == TOP || block_type == SUBST); if (!ps->tree.empty()) { // Execute the first node. @@ -662,8 +661,6 @@ int parser_t::eval_node(parsed_source_ref_t ps, tnode_t node, const io_chain_ static_assert( std::is_same::value || std::is_same::value, "Unexpected node type"); - CHECK_BLOCK(1); - // Handle cancellation requests. If our block stack is currently empty, then we already did // successfully cancel (or there was nothing to cancel); clear the flag. If our block stack is // not empty, we are still in the process of cancelling; refuse to evaluate anything. diff --git a/src/signal.cpp b/src/signal.cpp index 69dadd325..824e19390 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -29,9 +29,6 @@ struct lookup_entry { const wchar_t *desc; }; -/// The number of signal blocks in place. Increased by signal_block, decreased by signal_unblock. -static int block_count = 0; - /// Lookup table used to convert between signal names and signal ids, etc. static const struct lookup_entry signal_table[] = { #ifdef SIGHUP @@ -413,19 +410,6 @@ void get_signals_with_handlers(sigset_t *set) { } } -void signal_block() { - ASSERT_IS_MAIN_THREAD(); - sigset_t chldset; - - if (!block_count) { - sigfillset(&chldset); - DIE_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, NULL)); - } - - block_count++; - // debug( 0, L"signal block level increased to %d", block_count ); -} - /// Ensure we did not inherit any blocked signals. See issue #3964. void signal_unblock_all() { sigset_t iset; @@ -433,21 +417,3 @@ void signal_unblock_all() { sigprocmask(SIG_SETMASK, &iset, NULL); } -void signal_unblock() { - ASSERT_IS_MAIN_THREAD(); - - block_count--; - if (block_count < 0) { - debug(0, _(L"Signal block mismatch")); - bugreport(); - FATAL_EXIT(); - } - - if (!block_count) { - sigset_t chldset; - sigfillset(&chldset); - DIE_ON_FAILURE(pthread_sigmask(SIG_UNBLOCK, &chldset, 0)); - } -} - -bool signal_is_blocked() { return static_cast(block_count); } diff --git a/src/signal.h b/src/signal.h index be0e1d23b..8980c8dd6 100644 --- a/src/signal.h +++ b/src/signal.h @@ -29,15 +29,6 @@ void signal_handle(int sig, int do_handle); /// Ensure we did not inherit any blocked signals. See issue #3964. void signal_unblock_all(); -/// Block all signals. -void signal_block(); - -/// Unblock all signals. -void signal_unblock(); - -/// Returns true if signals are being blocked. -bool signal_is_blocked(); - /// Returns signals with non-default handlers. void get_signals_with_handlers(sigset_t *set); From 9715db94348d76db9eaa5c2ec672aed08ddc110b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 23 Feb 2019 14:09:17 -0800 Subject: [PATCH 094/191] Fix a "no return value" warning --- src/event.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/event.cpp b/src/event.cpp index 00944d1db..7ff0465af 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -388,6 +388,7 @@ void event_print(io_streams_t &streams, maybe_t type_filter) { case event_type_t::generic: return d1.str_param1 < d2.str_param1; } + DIE("Unreachable"); }); maybe_t last_type{}; From 5134949a14a929997eaddee26c59f6656fa5a420 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 6 Oct 2018 13:32:08 -0700 Subject: [PATCH 095/191] Factor color and terminal sequence outputting into outputter_t Removes some static variables and simplifies the behavior of the tputs singletone receiver. --- src/builtin_set_color.cpp | 53 ++++------- src/fish_indent.cpp | 24 ++--- src/output.cpp | 182 ++++++++++++++++---------------------- src/output.h | 103 ++++++++++++++++++--- src/proc.cpp | 13 +-- src/reader.cpp | 14 +-- src/screen.cpp | 142 +++++++++++------------------ src/screen.h | 13 ++- 8 files changed, 268 insertions(+), 276 deletions(-) diff --git a/src/builtin_set_color.cpp b/src/builtin_set_color.cpp index ae81acbd5..d48d61319 100644 --- a/src/builtin_set_color.cpp +++ b/src/builtin_set_color.cpp @@ -42,14 +42,6 @@ static void print_colors(io_streams_t &streams) { } } -static std::string builtin_set_color_output; -/// Function we set as the output writer. -static int set_color_builtin_outputter(char c) { - ASSERT_IS_MAIN_THREAD(); - builtin_set_color_output.push_back(c); - return 0; -} - static const wchar_t *const short_options = L":b:hvoidrcu"; static const struct woption long_options[] = {{L"background", required_argument, NULL, 'b'}, {L"help", no_argument, NULL, 'h'}, @@ -185,62 +177,53 @@ int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) { if (cur_term == NULL || !exit_attribute_mode) { return STATUS_CMD_ERROR; } - - // Save old output function so we can restore it. - int (*const saved_writer_func)(char) = output_get_writer(); - - // Set our output function, which writes to a std::string. - builtin_set_color_output.clear(); - output_set_writer(set_color_builtin_outputter); + outputter_t outp; if (bold && enter_bold_mode) { - writembs_nofail(tparm((char *)enter_bold_mode)); + writembs_nofail(outp, tparm((char *)enter_bold_mode)); } if (underline && enter_underline_mode) { - writembs_nofail(enter_underline_mode); + writembs_nofail(outp, enter_underline_mode); } if (italics && enter_italics_mode) { - writembs_nofail(enter_italics_mode); + writembs_nofail(outp, enter_italics_mode); } if (dim && enter_dim_mode) { - writembs_nofail(enter_dim_mode); + writembs_nofail(outp, enter_dim_mode); } if (reverse && enter_reverse_mode) { - writembs_nofail(enter_reverse_mode); + writembs_nofail(outp, enter_reverse_mode); } else if (reverse && enter_standout_mode) { - writembs_nofail(enter_standout_mode); + writembs_nofail(outp, enter_standout_mode); } if (bgcolor != NULL && bg.is_normal()) { - writembs_nofail(tparm((char *)exit_attribute_mode)); + writembs_nofail(outp, tparm((char *)exit_attribute_mode)); } if (!fg.is_none()) { if (fg.is_normal() || fg.is_reset()) { - writembs_nofail(tparm((char *)exit_attribute_mode)); - } else if (!write_color(fg, true /* is_fg */)) { - // We need to do *something* or the lack of any output - // with a cartesian product here would make "foo" disappear - // on lame terminals: - // $ env TERM=vt100 fish -c 'echo (set_color red)"foo"' - set_color(rgb_color_t::reset(), rgb_color_t::none()); + writembs_nofail(outp, tparm((char *)exit_attribute_mode)); + } else { + if (!outp.write_color(fg, true /* is_fg */)) { + // We need to do *something* or the lack of any output messes up + // when the cartesian product here would make "foo" disappear: + // $ echo (set_color foo)bar + outp.set_color(rgb_color_t::reset(), rgb_color_t::none()); + } } } if (bgcolor != NULL && !bg.is_normal() && !bg.is_reset()) { - write_color(bg, false /* not is_fg */); + outp.write_color(bg, false /* not is_fg */); } - // Restore saved writer function. - output_set_writer(saved_writer_func); - // Output the collected string. - streams.out.append(str2wcstring(builtin_set_color_output)); - builtin_set_color_output.clear(); + streams.out.append(str2wcstring(outp.contents())); return STATUS_CMD_OK; } diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index f985c4b19..d26c65bc4 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -252,37 +252,25 @@ static wcstring prettify(const wcstring &src, bool do_indent) { return std::move(prettifier.output); } -// Helper for output_set_writer -static std::string output_receiver; -static int write_to_output_receiver(char c) { - output_receiver.push_back(c); - return 0; -} - /// Given a string and list of colors of the same size, return the string with ANSI escape sequences /// representing the colors. static std::string ansi_colorize(const wcstring &text, const std::vector &colors) { assert(colors.size() == text.size()); - assert(output_receiver.empty()); - - int (*saved)(char) = output_get_writer(); - output_set_writer(write_to_output_receiver); + outputter_t outp; + const auto &vars = env_stack_t::globals(); highlight_spec_t last_color = highlight_spec_normal; for (size_t i = 0; i < text.size(); i++) { highlight_spec_t color = colors.at(i); if (color != last_color) { - set_color(highlight_get_color(color, false), rgb_color_t::normal()); + outp.set_color(highlight_get_color(color, false), rgb_color_t::normal()); last_color = color; } - writech(text.at(i)); + outp.writech(text.at(i)); } - set_color(rgb_color_t::normal(), rgb_color_t::normal()); - output_set_writer(saved); - std::string result; - result.swap(output_receiver); - return result; + outp.set_color(rgb_color_t::normal(), rgb_color_t::normal()); + return outp.contents(); } /// Given a string and list of colors of the same size, return the string with HTML span elements diff --git a/src/output.cpp b/src/output.cpp index 6003229ba..c87c142f0 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -30,25 +30,9 @@ #include "output.h" #include "wutil.h" // IWYU pragma: keep -static int writeb_internal(char c); - -/// The function used for output. -static int (*out)(char c) = writeb_internal; //!OCLINT(unused param) - /// Whether term256 and term24bit are supported. static color_support_t color_support = 0; -/// Set the function used for writing in move_cursor, writespace and set_color and all other output -/// functions in this library. By default, the write call is used to give completely unbuffered -/// output to stdout. -void output_set_writer(int (*writer)(char)) { - CHECK(writer, ); - out = writer; -} - -/// Return the current output writer. -int (*output_get_writer())(char) { return out; } - /// Returns true if we think tparm can handle outputting a color index static bool term_supports_color_natively(unsigned int c) { return (unsigned)max_colors >= c + 1; } @@ -63,10 +47,10 @@ unsigned char index_for_color(rgb_color_t c) { return c.to_term256_index(); } -static bool write_color_escape(const char *todo, unsigned char idx, bool is_fg) { +static bool write_color_escape(outputter_t &outp, const char *todo, unsigned char idx, bool is_fg) { if (term_supports_color_natively(idx)) { // Use tparm to emit color escape. - writembs(tparm((char *)todo, idx)); + writembs(outp, tparm((char *)todo, idx)); return true; } @@ -85,45 +69,46 @@ static bool write_color_escape(const char *todo, unsigned char idx, bool is_fg) snprintf(buff, sizeof buff, "\x1B[%d;5;%dm", is_fg ? 38 : 48, idx); } - int (*writer)(char) = output_get_writer(); - if (writer) { - for (size_t i = 0; buff[i]; i++) { - writer(buff[i]); - } - } - + outp.writestr(buff); return true; } -static bool write_foreground_color(unsigned char idx) { +static bool write_foreground_color(outputter_t &outp, unsigned char idx) { if (!cur_term) return false; if (set_a_foreground && set_a_foreground[0]) { - return write_color_escape(set_a_foreground, idx, true); + return write_color_escape(outp, set_a_foreground, idx, true); } else if (set_foreground && set_foreground[0]) { - return write_color_escape(set_foreground, idx, true); + return write_color_escape(outp, set_foreground, idx, true); } return false; } -static bool write_background_color(unsigned char idx) { +static bool write_background_color(outputter_t &outp, unsigned char idx) { if (!cur_term) return false; if (set_a_background && set_a_background[0]) { - return write_color_escape(set_a_background, idx, false); + return write_color_escape(outp, set_a_background, idx, false); } else if (set_background && set_background[0]) { - return write_color_escape(set_background, idx, false); + return write_color_escape(outp, set_background, idx, false); } return false; } +void outputter_t::flush_to(int fd) { + if (fd >= 0 && !contents_.empty()) { + write_loop(fd, contents_.data(), contents_.size()); + contents_.clear(); + } +} + // Exported for builtin_set_color's usage only. -bool write_color(rgb_color_t color, bool is_fg) { +bool outputter_t::write_color(rgb_color_t color, bool is_fg) { if (!cur_term) return false; bool supports_term24bit = static_cast(output_get_color_support() & color_support_term24bit); if (!supports_term24bit || !color.is_rgb()) { // Indexed or non-24 bit color. unsigned char idx = index_for_color(color); - return (is_fg ? write_foreground_color : write_background_color)(idx); + return (is_fg ? write_foreground_color : write_background_color)(*this, idx); } // 24 bit! No tparm here, just ANSI escape sequences. @@ -133,13 +118,7 @@ bool write_color(rgb_color_t color, bool is_fg) { char buff[128]; snprintf(buff, sizeof buff, "\x1B[%d;2;%u;%u;%um", is_fg ? 38 : 48, rgb.rgb[0], rgb.rgb[1], rgb.rgb[2]); - int (*writer)(char) = output_get_writer(); - if (writer) { - for (size_t i = 0; buff[i]; i++) { - writer(buff[i]); - } - } - + writestr(buff); return true; } @@ -162,23 +141,10 @@ bool write_color(rgb_color_t color, bool is_fg) { /// /// \param c Foreground color. /// \param c2 Background color. -void set_color(rgb_color_t c, rgb_color_t c2) { -#if 0 - wcstring tmp = c.description(); - wcstring tmp2 = c2.description(); - debug(3, "set_color %ls : %ls", tmp.c_str(), tmp2.c_str()); -#endif - ASSERT_IS_MAIN_THREAD(); +void outputter_t::set_color(rgb_color_t c, rgb_color_t c2) { if (!cur_term) return; const rgb_color_t normal = rgb_color_t::normal(); - static rgb_color_t last_color = rgb_color_t::normal(); - static rgb_color_t last_color2 = rgb_color_t::normal(); - static bool was_bold = false; - static bool was_underline = false; - static bool was_italics = false; - static bool was_dim = false; - static bool was_reverse = false; bool bg_set = false, last_bg_set = false; bool is_bold = false; bool is_underline = false; @@ -216,14 +182,14 @@ void set_color(rgb_color_t c, rgb_color_t c2) { was_reverse = false; // If we exit attibute mode, we must first set a color, or previously coloured text might // lose it's color. Terminals are weird... - write_foreground_color(0); - writembs(exit_attribute_mode); + write_foreground_color(*this, 0); + writembs(*this, exit_attribute_mode); return; } if (was_bold && !is_bold) { // Only way to exit bold mode is a reset of all attributes. - writembs(exit_attribute_mode); + writembs(*this, exit_attribute_mode); last_color = normal; last_color2 = normal; was_bold = false; @@ -235,7 +201,7 @@ void set_color(rgb_color_t c, rgb_color_t c2) { if (was_dim && !is_dim) { // Only way to exit dim mode is a reset of all attributes. - writembs(exit_attribute_mode); + writembs(*this, exit_attribute_mode); last_color = normal; last_color2 = normal; was_bold = false; @@ -247,7 +213,7 @@ void set_color(rgb_color_t c, rgb_color_t c2) { if (was_reverse && !is_reverse) { // Only way to exit reverse mode is a reset of all attributes. - writembs(exit_attribute_mode); + writembs(*this, exit_attribute_mode); last_color = normal; last_color2 = normal; was_bold = false; @@ -272,18 +238,18 @@ void set_color(rgb_color_t c, rgb_color_t c2) { if (bg_set && !last_bg_set) { // Background color changed and is set, so we enter bold mode to make reading easier. // This means bold mode is _always_ on when the background color is set. - writembs_nofail(enter_bold_mode); + writembs_nofail(*this, enter_bold_mode); } if (!bg_set && last_bg_set) { // Background color changed and is no longer set, so we exit bold mode. - writembs(exit_attribute_mode); + writembs(*this, exit_attribute_mode); was_bold = false; was_underline = false; was_italics = false; was_dim = false; was_reverse = false; // We don't know if exit_attribute_mode resets colors, so we set it to something known. - if (write_foreground_color(0)) { + if (write_foreground_color(*this, 0)) { last_color = rgb_color_t::black(); } } @@ -291,8 +257,8 @@ void set_color(rgb_color_t c, rgb_color_t c2) { if (last_color != c) { if (c.is_normal()) { - write_foreground_color(0); - writembs(exit_attribute_mode); + write_foreground_color(*this, 0); + writembs(*this, exit_attribute_mode); last_color2 = rgb_color_t::normal(); was_bold = false; @@ -309,9 +275,9 @@ void set_color(rgb_color_t c, rgb_color_t c2) { if (last_color2 != c2) { if (c2.is_normal()) { - write_background_color(0); + write_background_color(*this, 0); - writembs(exit_attribute_mode); + writembs(*this, exit_attribute_mode); if (!last_color.is_normal()) { write_color(last_color, true /* foreground */); } @@ -330,66 +296,75 @@ void set_color(rgb_color_t c, rgb_color_t c2) { // Lastly, we set bold, underline, italics, dim, and reverse modes correctly. if (is_bold && !was_bold && enter_bold_mode && strlen(enter_bold_mode) > 0 && !bg_set) { - writembs_nofail(tparm((char *)enter_bold_mode)); + writembs_nofail(*this, tparm(enter_bold_mode)); was_bold = is_bold; } if (was_underline && !is_underline) { - writembs_nofail(exit_underline_mode); + writembs_nofail(*this, exit_underline_mode); } if (!was_underline && is_underline) { - writembs_nofail(enter_underline_mode); + writembs_nofail(*this, enter_underline_mode); } was_underline = is_underline; if (was_italics && !is_italics && enter_italics_mode && strlen(enter_italics_mode) > 0) { - writembs_nofail(exit_italics_mode); + writembs_nofail(*this, exit_italics_mode); was_italics = is_italics; } if (!was_italics && is_italics && enter_italics_mode && strlen(enter_italics_mode) > 0) { - writembs_nofail(enter_italics_mode); + writembs_nofail(*this, enter_italics_mode); was_italics = is_italics; } if (is_dim && !was_dim && enter_dim_mode && strlen(enter_dim_mode) > 0) { - writembs_nofail(enter_dim_mode); + writembs_nofail(*this, enter_dim_mode); was_dim = is_dim; } if (is_reverse && !was_reverse) { // Some terms do not have a reverse mode set, so standout mode is a fallback. if (enter_reverse_mode && strlen(enter_reverse_mode) > 0) { - writembs_nofail(enter_reverse_mode); + writembs_nofail(*this, enter_reverse_mode); was_reverse = is_reverse; } else if (enter_standout_mode && strlen(enter_standout_mode) > 0) { - writembs_nofail(enter_standout_mode); + writembs_nofail(*this, enter_standout_mode); was_reverse = is_reverse; } } } -/// Default output method, simply calls write() on stdout. -static int writeb_internal(char c) { // cppcheck - write_loop(1, &c, 1); +// tputs accepts a function pointer that receives an int only. +// Use the following lock to redirect it to the proper outputter. +// Note we can't use owning_lock because the tputs_writer must access it and owning_lock is not +// recursive. +static std::mutex s_tputs_receiver_lock; +static outputter_t *s_tputs_receiver{nullptr}; + +static int tputs_writer(tputs_arg_t b) { + ASSERT_IS_LOCKED(s_tputs_receiver_lock); + assert(s_tputs_receiver && "null s_tputs_receiver"); + char c = static_cast(b); + s_tputs_receiver->writestr(&c, 1); return 0; } -/// This is for writing process notification messages. Has to write to stdout, so clr_eol and such -/// functions will work correctly. Not an issue since this function is only used in interactive mode -/// anyway. -int writeb(tputs_arg_t b) { - out(b); - return 0; +int outputter_t::term_puts(const char *str, int affcnt) { + // Acquire the lock, use a scoped_push to substitute in our receiver, then call tputs. The + // scoped_push will restore it. + scoped_lock locker{s_tputs_receiver_lock}; + scoped_push push(&s_tputs_receiver, this); + return tputs(str, affcnt, tputs_writer); } -/// Write a wide character using the output method specified using output_set_writer(). This should -/// only be used when writing characters from user supplied strings. This is needed due to our use -/// of the ENCODE_DIRECT_BASE mechanism to allow the user to specify arbitrary byte values to be -/// output. Such as in a `printf` invocation that includes literal byte values such as `\x1B`. -/// This should not be used for writing non-user supplied characters. -int writech(wint_t ch) { +/// Write a wide character to the outputter. This should only be used when writing characters from +/// user supplied strings. This is needed due to our use of the ENCODE_DIRECT_BASE mechanism to +/// allow the user to specify arbitrary byte values to be output. Such as in a `printf` invocation +/// that includes literal byte values such as `\x1B`. This should not be used for writing non-user +/// supplied characters. +int outputter_t::writech(wint_t ch) { char buff[MB_LEN_MAX + 1]; size_t len; @@ -408,10 +383,7 @@ int writech(wint_t ch) { return 1; } } - - for (size_t i = 0; i < len; i++) { - out(buff[i]); - } + this->writestr(buff, len); return 0; } @@ -419,12 +391,12 @@ int writech(wint_t ch) { /// messages; just use debug() or fwprintf() for that. It should only be used to output user /// supplied strings that might contain literal bytes; e.g., "\342\224\214" from issue #1894. This /// is needed because those strings may contain chars specially encoded using ENCODE_DIRECT_BASE. -void writestr(const wchar_t *str) { - CHECK(str, ); +void outputter_t::writestr(const wchar_t *str) { + assert(str && "Empty input string"); if (MB_CUR_MAX == 1) { // Single-byte locale (C/POSIX/ISO-8859). - while (*str) writech(*str++); + this->writestr(str); return; } @@ -443,15 +415,16 @@ void writestr(const wchar_t *str) { buffer = new char[len]; } wcstombs(buffer, str, len); - - // Write the string. - for (char *pos = buffer; *pos; pos++) { - out(*pos); - } - + this->writestr(buffer); if (buffer != static_buffer) delete[] buffer; } +outputter_t &outputter_t::stdoutput() { + ASSERT_IS_MAIN_THREAD(); + static outputter_t res(STDOUT_FILENO); + return res; +} + /// Given a list of rgb_color_t, pick the "best" one, as determined by the color support. Returns /// rgb_color_t::none() if empty. rgb_color_t best_color(const std::vector &candidates, color_support_t support) { @@ -548,9 +521,10 @@ rgb_color_t parse_color(const env_var_t &var, bool is_background) { } /// Write specified multibyte string. -void writembs_check(const char *mbs, const char *mbs_name, bool critical, const char *file, long line) { +void writembs_check(outputter_t &outp, const char *mbs, const char *mbs_name, bool critical, + const char *file, long line) { if (mbs != NULL) { - tputs((char *)mbs, 1, &writeb); + outp.term_puts(mbs, 1); } else if (critical) { auto term = env_stack_t::globals().get(L"TERM"); const wchar_t *fmt = diff --git a/src/output.h b/src/output.h index 17a076814..b0548aeb1 100644 --- a/src/output.h +++ b/src/output.h @@ -14,24 +14,102 @@ class env_var_t; -void set_color(rgb_color_t c, rgb_color_t c2); +class outputter_t { + /// Storage for buffered contents. + std::string contents_; -void writembs_check(const char *mbs, const char *mbs_name, bool critical, const char *file, long line); -#define writembs(mbs) writembs_check((mbs), #mbs, true, __FILE__, __LINE__) -#define writembs_nofail(mbs) writembs_check((mbs), #mbs, false, __FILE__, __LINE__) + /// Count of how many outstanding beginBuffering() calls there are. + uint32_t bufferCount_{0}; -int writech(wint_t ch); + /// fd to output to. + int fd_{-1}; -void writestr(const wchar_t *str); + rgb_color_t last_color = rgb_color_t::normal(); + rgb_color_t last_color2 = rgb_color_t::normal(); + bool was_bold = false; + bool was_underline = false; + bool was_italics = false; + bool was_dim = false; + bool was_reverse = false; + + /// Construct an outputter which outputs to a given fd. + explicit outputter_t(int fd) : fd_(fd) {} + + /// Flush output, if we have a set fd and our buffering count is 0. + void maybe_flush() { + if (fd_ >= 0 && bufferCount_ == 0) flush_to(fd_); + } + + public: + /// Construct an outputter which outputs to its string. + outputter_t() = default; + + /// Unconditionally write the color string to the output. + bool write_color(rgb_color_t color, bool is_fg); + + /// Set the foreground and background color. + void set_color(rgb_color_t c, rgb_color_t c2); + + /// Write a wide character to the receiver. + int writech(wint_t ch); + + /// Write a NUL-terminated wide character string to the receiver. + void writestr(const wchar_t *str); + + /// Write a wide character string to the receiver. + void writestr(const wcstring &str) { writestr(str.c_str()); } + + /// Write the given terminfo string to the receiver, like tputs(). + int term_puts(const char *str, int affcnt); + + /// Write a narrow string of the given length. + void writestr(const char *str, size_t len) { + contents_.append(str, len); + maybe_flush(); + } + + /// Write a narrow NUL-terminated string. + void writestr(const char *str) { writestr(str, strlen(str)); } + + /// Write a narrow character. + void push_back(char c) { + contents_.push_back(c); + maybe_flush(); + } + + /// \return the "output" contents. + const std::string &contents() const { return contents_; } + + /// Output any buffered data to the given \p fd. + void flush_to(int fd); + + /// Begins buffering. Output will not be automatically flushed until a corresponding + /// endBuffering() call. + void beginBuffering() { + bufferCount_++; + assert(bufferCount_ > 0 && "bufferCount_ overflow"); + } + + /// Balance a beginBuffering() call. + void endBuffering() { + assert(bufferCount_ > 0 && "bufferCount_ underflow"); + bufferCount_--; + maybe_flush(); + } + + /// Accesses the singleton stdout outputter. + /// This can only be used from the main thread. + /// This outputter flushes its buffer after every write operation. + static outputter_t &stdoutput(); +}; + +void writembs_check(outputter_t &outp, const char *mbs, const char *mbs_name, bool critical, + const char *file, long line); +#define writembs(outp, mbs) writembs_check((outp), (mbs), #mbs, true, __FILE__, __LINE__) +#define writembs_nofail(outp, mbs) writembs_check((outp), (mbs), #mbs, false, __FILE__, __LINE__) rgb_color_t parse_color(const env_var_t &val, bool is_background); -int writeb(tputs_arg_t b); - -void output_set_writer(int (*writer)(char)); - -int (*output_get_writer())(char); - /// Sets what colors are supported. enum { color_support_term256 = 1 << 0, color_support_term24bit = 1 << 1 }; typedef unsigned int color_support_t; @@ -40,7 +118,6 @@ void output_set_color_support(color_support_t support); rgb_color_t best_color(const std::vector &colors, color_support_t support); -bool write_color(rgb_color_t color, bool is_fg); unsigned char index_for_color(rgb_color_t c); #endif diff --git a/src/proc.cpp b/src/proc.cpp index b6117d90f..19db27d0c 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -475,12 +475,13 @@ typedef enum { JOB_STOPPED, JOB_ENDED } job_status_t; static void print_job_status(const job_t *j, job_status_t status) { const wchar_t *msg = L"Job %d, '%ls' has ended"; // this is the most common status msg if (status == JOB_STOPPED) msg = L"Job %d, '%ls' has stopped"; - - fwprintf(stdout, L"\r"); - fwprintf(stdout, _(msg), j->job_id, truncate_command(j->command()).c_str()); + outputter_t outp; + outp.writestr("\r"); + outp.writestr(format_string(_(msg), j->job_id, truncate_command(j->command()).c_str())); + if (clr_eol) outp.term_puts(clr_eol, 1); + outp.writestr(L"\n"); fflush(stdout); - if (clr_eol) tputs(clr_eol, 1, &writeb); - fwprintf(stdout, L"\n"); + outp.flush_to(STDOUT_FILENO); } void proc_fire_event(const wchar_t *msg, event_type_t type, pid_t pid, int status) { @@ -578,7 +579,7 @@ static bool process_clean_after_marking(bool allow_interactive) { signal_get_desc(WTERMSIG(p->status))); } - if (clr_eol) tputs(clr_eol, 1, &writeb); + if (clr_eol) outputter_t::stdoutput().term_puts(clr_eol, 1); fwprintf(stdout, L"\n"); } found = false; diff --git a/src/reader.cpp b/src/reader.cpp index c0e6e31fb..de601949f 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -458,8 +458,8 @@ static void reader_super_highlight_me_plenty(int highlight_pos_adjust = 0, bool static bool exit_forced; /// Give up control of terminal. -static void term_donate() { - set_color(rgb_color_t::normal(), rgb_color_t::normal()); +static void term_donate(outputter_t &outp) { + outp.set_color(rgb_color_t::normal(), rgb_color_t::normal()); while (1) { if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_modes_for_external_cmds) == -1) { @@ -844,7 +844,7 @@ void reader_write_title(const wcstring &cmd, bool reset_cursor_position) { } proc_pop_interactive(); - set_color(rgb_color_t::reset(), rgb_color_t::reset()); + outputter_t::stdoutput().set_color(rgb_color_t::reset(), rgb_color_t::reset()); if (reset_cursor_position && !lst.empty()) { // Put the cursor back at the beginning of the line (issue #2453). ignore_result(write(STDOUT_FILENO, "\r", 1)); @@ -1844,7 +1844,7 @@ static void reader_interactive_init() { /// Destroy data for interactive use. static void reader_interactive_destroy() { kill_destroy(); - set_color(rgb_color_t::reset(), rgb_color_t::reset()); + outputter_t::stdoutput().set_color(rgb_color_t::reset(), rgb_color_t::reset()); input_destroy(); } @@ -2031,9 +2031,9 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) { // For compatibility with fish 2.0's $_, now replaced with `status current-command` if (!ft.empty()) parser.vars().set_one(L"_", ENV_GLOBAL, ft); + outputter_t &outp = outputter_t::stdoutput(); reader_write_title(cmd); - - term_donate(); + term_donate(outp); gettimeofday(&time_before, NULL); @@ -3358,7 +3358,7 @@ const wchar_t *reader_readline(int nchars) { if (errno == EIO) redirect_tty_output(); wperror(L"tcsetattr"); // return to previous mode } - set_color(rgb_color_t::reset(), rgb_color_t::reset()); + outputter_t::stdoutput().set_color(rgb_color_t::reset(), rgb_color_t::reset()); } return finished ? data->command_line.text.c_str() : NULL; diff --git a/src/screen.cpp b/src/screen.cpp index 1f4058405..edf769352 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -52,29 +52,14 @@ static void invalidate_soft_wrap(screen_t *scr); -/// Ugly kludge. The internal buffer used to store output of tputs. Since tputs external function -/// can only take an integer and not a pointer as parameter we need a static storage buffer. -typedef std::vector data_buffer_t; -static data_buffer_t *s_writeb_buffer = 0; - -static int s_writeb(char character); - -/// Class to temporarily set s_writeb_buffer and the writer function in a scoped way. +/// RAII class to begin and end buffering around stdoutput(). class scoped_buffer_t { - data_buffer_t *const old_buff; - int (*const old_writer)(char); + screen_t &screen_; public: - explicit scoped_buffer_t(data_buffer_t *buff) - : old_buff(s_writeb_buffer), old_writer(output_get_writer()) { - s_writeb_buffer = buff; - output_set_writer(s_writeb); - } + scoped_buffer_t(screen_t &s) : screen_(s) { screen_.outp().beginBuffering(); } - ~scoped_buffer_t() { - s_writeb_buffer = old_buff; - output_set_writer(old_writer); - } + ~scoped_buffer_t() { screen_.outp().endBuffering(); } }; // Singleton of the cached escape sequences seen in prompts and similar strings. @@ -439,12 +424,6 @@ static void s_desired_append_char(screen_t *s, wchar_t b, int c, int indent, siz } } -/// The writeb function offered to tputs. -static int s_writeb(char c) { - s_writeb_buffer->push_back(c); - return 0; -} - /// Write the bytes needed to move screen cursor to the specified position to the specified buffer. /// The actual_cursor field of the specified screen_t will be updated. /// @@ -452,18 +431,20 @@ static int s_writeb(char c) { /// \param b the buffer to send the output escape codes to /// \param new_x the new x position /// \param new_y the new y position -static void s_move(screen_t *s, data_buffer_t *b, int new_x, int new_y) { +static void s_move(screen_t *s, int new_x, int new_y) { if (s->actual.cursor.x == new_x && s->actual.cursor.y == new_y) return; + const scoped_buffer_t buffering(*s); + // If we are at the end of our window, then either the cursor stuck to the edge or it didn't. We // don't know! We can fix it up though. if (s->actual.cursor.x == common_get_width()) { // Either issue a cr to go back to the beginning of this line, or a nl to go to the // beginning of the next one, depending on what we think is more efficient. if (new_y <= s->actual.cursor.y) { - b->push_back('\r'); + s->outp().push_back('\r'); } else { - b->push_back('\n'); + s->outp().push_back('\n'); s->actual.cursor.y++; } // Either way we're not in the first column. @@ -474,7 +455,7 @@ static void s_move(screen_t *s, data_buffer_t *b, int new_x, int new_y) { int x_steps, y_steps; const char *str; - scoped_buffer_t scoped_buffer(b); + auto &outp = s->outp(); y_steps = new_y - s->actual.cursor.y; @@ -492,13 +473,13 @@ static void s_move(screen_t *s, data_buffer_t *b, int new_x, int new_y) { } for (i = 0; i < abs(y_steps); i++) { - writembs(str); + writembs(outp, str); } x_steps = new_x - s->actual.cursor.x; if (x_steps && new_x == 0) { - b->push_back('\r'); + outp.push_back('\r'); x_steps = 0; } @@ -517,10 +498,10 @@ static void s_move(screen_t *s, data_buffer_t *b, int new_x, int new_y) { multi_str != NULL && multi_str[0] != '\0' && abs(x_steps) * strlen(str) > strlen(multi_str); if (use_multi && cur_term) { char *multi_param = tparm((char *)multi_str, abs(x_steps)); - writembs(multi_param); + writembs(outp, multi_param); } else { for (i = 0; i < abs(x_steps); i++) { - writembs(str); + writembs(outp, str); } } @@ -529,20 +510,19 @@ static void s_move(screen_t *s, data_buffer_t *b, int new_x, int new_y) { } /// Set the pen color for the terminal. -static void s_set_color(screen_t *s, data_buffer_t *b, highlight_spec_t c) { +static void s_set_color(screen_t *s, const environment_t &vars, highlight_spec_t c) { UNUSED(s); - scoped_buffer_t scoped_buffer(b); unsigned int uc = (unsigned int)c; - set_color(highlight_get_color(uc & 0xffff, false), - highlight_get_color((uc >> 16) & 0xffff, true)); + s->outp().set_color(highlight_get_color(uc & 0xfff, false), + highlight_get_color((uc >> 16) & 0xffff, true)); } /// Convert a wide character to a multibyte string and append it to the buffer. -static void s_write_char(screen_t *s, data_buffer_t *b, wchar_t c) { - scoped_buffer_t scoped_buffer(b); +static void s_write_char(screen_t *s, wchar_t c) { + scoped_buffer_t outp(*s); s->actual.cursor.x += fish_wcwidth_min_0(c); - writech(c); + s->outp().writech(c); if (s->actual.cursor.x == s->actual_width && allow_soft_wrap()) { s->soft_wrap_location.x = 0; s->soft_wrap_location.y = s->actual.cursor.y + 1; @@ -555,17 +535,11 @@ static void s_write_char(screen_t *s, data_buffer_t *b, wchar_t c) { } } -/// Send the specified string through tputs and append the output to the specified buffer. -static void s_write_mbs(data_buffer_t *b, const char *s) { - scoped_buffer_t scoped_buffer(b); - writembs(s); -} +/// Send the specified string through tputs and append the output to the screen's outputter. +static void s_write_mbs(screen_t *screen, const char *s) { writembs(screen->outp(), s); } /// Convert a wide string to a multibyte string and append it to the buffer. -static void s_write_str(data_buffer_t *b, const wchar_t *s) { - scoped_buffer_t scoped_buffer(b); - writestr(s); -} +static void s_write_str(screen_t *screen, const wchar_t *s) { screen->outp().writestr(s); } /// Returns the length of the "shared prefix" of the two lines, which is the run of matching text /// and colors. If the prefix ends on a combining character, do not include the previous character @@ -608,7 +582,8 @@ static void invalidate_soft_wrap(screen_t *scr) { scr->soft_wrap_location = INVA /// Update the screen to match the desired output. static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring &right_prompt) { - // if (test_stuff(scr)) return; + const environment_t &vars = env_stack_t::principal(); + const scoped_buffer_t buffering(*scr); const size_t left_prompt_width = calc_prompt_layout(left_prompt, cached_layouts).last_line_width; const size_t right_prompt_width = @@ -620,8 +595,6 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring size_t actual_lines_before_reset = scr->actual_lines_before_reset; scr->actual_lines_before_reset = 0; - data_buffer_t output; - bool need_clear_lines = scr->need_clear_lines; bool need_clear_screen = scr->need_clear_screen; bool has_cleared_screen = false; @@ -630,7 +603,7 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring // Ensure we don't issue a clear screen for the very first output, to avoid issue #402. if (scr->actual_width != SCREEN_WIDTH_UNINITIALIZED) { need_clear_screen = true; - s_move(scr, &output, 0, 0); + s_move(scr, 0, 0); s_reset(scr, screen_reset_current_line_contents); need_clear_lines = need_clear_lines || scr->need_clear_lines; @@ -647,8 +620,8 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring const size_t lines_with_stuff = maxi(actual_lines_before_reset, scr->actual.line_count()); if (left_prompt != scr->actual_left_prompt) { - s_move(scr, &output, 0, 0); - s_write_str(&output, left_prompt.c_str()); + s_move(scr, 0, 0); + s_write_str(scr, left_prompt.c_str()); scr->actual_left_prompt = left_prompt; scr->actual.cursor.x = (int)left_prompt_width; } @@ -714,22 +687,22 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring // wrapping. if (j + 1 == (size_t)screen_width && should_clear_screen_this_line && !has_cleared_screen) { - s_move(scr, &output, current_width, (int)i); - s_write_mbs(&output, clr_eos); + s_move(scr, current_width, (int)i); + s_write_mbs(scr, clr_eos); has_cleared_screen = true; } perform_any_impending_soft_wrap(scr, current_width, (int)i); - s_move(scr, &output, current_width, (int)i); - s_set_color(scr, &output, o_line.color_at(j)); - s_write_char(scr, &output, o_line.char_at(j)); + s_move(scr, current_width, (int)i); + s_set_color(scr, vars, o_line.color_at(j)); + s_write_char(scr, o_line.char_at(j)); current_width += fish_wcwidth_min_0(o_line.char_at(j)); } // Clear the screen if we have not done so yet. if (should_clear_screen_this_line && !has_cleared_screen) { - s_move(scr, &output, current_width, (int)i); - s_write_mbs(&output, clr_eos); + s_move(scr, current_width, (int)i); + s_write_mbs(scr, clr_eos); has_cleared_screen = true; } @@ -750,16 +723,16 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring clear_remainder = prev_width > current_width; } if (clear_remainder && clr_eol) { - s_set_color(scr, &output, 0xffffffff); - s_move(scr, &output, current_width, (int)i); - s_write_mbs(&output, clr_eol); + s_set_color(scr, vars, 0xffffffff); + s_move(scr, current_width, (int)i); + s_write_mbs(scr, clr_eol); } // Output any rprompt if this is the first line. if (i == 0 && right_prompt_width > 0) { //!OCLINT(Use early exit/continue) - s_move(scr, &output, (int)(screen_width - right_prompt_width), (int)i); - s_set_color(scr, &output, 0xffffffff); - s_write_str(&output, right_prompt.c_str()); + s_move(scr, (int)(screen_width - right_prompt_width), (int)i); + s_set_color(scr, vars, 0xffffffff); + s_write_str(scr, right_prompt.c_str()); scr->actual.cursor.x += right_prompt_width; // We output in the last column. Some terms (Linux) push the cursor further right, past @@ -770,28 +743,23 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring // wrapped. If so, then a cr will go to the beginning of the following line! So instead // issue a bunch of "move left" commands to get back onto the line, and then jump to the // front of it. - s_move(scr, &output, scr->actual.cursor.x - (int)right_prompt_width, - scr->actual.cursor.y); - s_write_str(&output, L"\r"); + s_move(scr, scr->actual.cursor.x - (int)right_prompt_width, scr->actual.cursor.y); + s_write_str(scr, L"\r"); scr->actual.cursor.x = 0; } } // Clear remaining lines (if any) if we haven't cleared the screen. if (!has_cleared_screen && scr->desired.line_count() < lines_with_stuff && clr_eol) { - s_set_color(scr, &output, 0xffffffff); + s_set_color(scr, vars, 0xffffffff); for (size_t i = scr->desired.line_count(); i < lines_with_stuff; i++) { - s_move(scr, &output, 0, (int)i); - s_write_mbs(&output, clr_eol); + s_move(scr, 0, (int)i); + s_write_mbs(scr, clr_eol); } } - s_move(scr, &output, scr->desired.cursor.x, scr->desired.cursor.y); - s_set_color(scr, &output, 0xffffffff); - - if (!output.empty()) { - write_loop(STDOUT_FILENO, &output.at(0), output.size()); - } + s_move(scr, scr->desired.cursor.x, scr->desired.cursor.y); + s_set_color(scr, vars, 0xffffffff); // We have now synced our actual screen against our desired screen. Note that this is a big // assignment! @@ -1206,21 +1174,15 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) { fstat(2, &s->prev_buff_2); } -bool screen_force_clear_to_end() { - bool result = false; +void screen_force_clear_to_end() { if (clr_eos) { - data_buffer_t output; - s_write_mbs(&output, clr_eos); - if (!output.empty()) { - write_loop(STDOUT_FILENO, &output.at(0), output.size()); - result = true; - } + writembs(outputter_t::stdoutput(), clr_eos); } - return result; } screen_t::screen_t() - : desired(), + : outp_(outputter_t::stdoutput()), + desired(), actual(), actual_left_prompt(), last_right_prompt_width(), diff --git a/src/screen.h b/src/screen.h index 2bb201a2d..01b3266f8 100644 --- a/src/screen.h +++ b/src/screen.h @@ -110,10 +110,14 @@ class screen_data_t { bool empty() const { return line_datas.empty(); } }; +class outputter_t; + /// The class representing the current and desired screen contents. class screen_t { + outputter_t &outp_; + public: - /// Constructor + /// Constructor. screen_t(); /// The internal representation of the desired screen contents. @@ -144,6 +148,9 @@ class screen_t { /// These status buffers are used to check if any output has occurred other than from fish's /// main loop, in which case we need to redraw. struct stat prev_buff_1, prev_buff_2, post_buff_1, post_buff_2; + + /// \return the outputter for this screen. + outputter_t &outp() { return outp_; } }; /// This is the main function for the screen putput library. It is used to define the desired @@ -197,8 +204,8 @@ enum screen_reset_mode_t { void s_reset(screen_t *s, screen_reset_mode_t mode); -/// Issues an immediate clr_eos, returning if it existed. -bool screen_force_clear_to_end(); +/// Issues an immediate clr_eos. +void screen_force_clear_to_end(); /// Returns the length of an escape code. Exposed for testing purposes only. size_t escape_code_length(const wchar_t *code); From 815e20066b5141b67dfea5205ac1ef2240c34b7d Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 12:12:24 -0800 Subject: [PATCH 096/191] parser_t to become enable_shared_from_this --- src/parser.cpp | 6 +++--- src/parser.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index db23ce43c..72a263258 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -105,17 +105,17 @@ parser_t::parser_t() : variables(env_stack_t::principal()) {} // Out of line destructor to enable forward declaration of parse_execution_context_t parser_t::~parser_t() = default; -parser_t parser_t::principal; +std::shared_ptr parser_t::principal{new parser_t()}; parser_t &parser_t::principal_parser() { ASSERT_IS_MAIN_THREAD(); - return principal; + return *principal; } void parser_t::skip_all_blocks() { // Tell all blocks to skip. // This may be called from a signal handler! - principal.cancellation_requested = true; + principal->cancellation_requested = true; } // Given a new-allocated block, push it onto our block stack, acquiring ownership diff --git a/src/parser.h b/src/parser.h index 92a470f88..ac251a4be 100644 --- a/src/parser.h +++ b/src/parser.h @@ -147,7 +147,7 @@ struct profile_item_t { class parse_execution_context_t; class completion_t; -class parser_t { +class parser_t : public std::enable_shared_from_this { friend class parse_execution_context_t; private: @@ -202,7 +202,7 @@ class parser_t { parser_t(); /// The main parser. - static parser_t principal; + static std::shared_ptr principal; public: /// Get the "principal" parser, whatever that is. From a81bfbb8059ff818a69e40af10b7249c593cb153 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 12:20:20 -0800 Subject: [PATCH 097/191] Rename end_loop to noni_end_loop This helps distinguish between the global (noni_)end_loop and the reader specific one. --- src/reader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index de601949f..ad17f6056 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -432,7 +432,7 @@ static reader_data_t *current_data() { static volatile sig_atomic_t is_interactive_read; /// Flag for ending non-interactive shell. -static int end_loop = 0; +static int noni_end_loop = 0; /// The stack containing names of files that are being parsed. static std::stack> current_filename; @@ -975,7 +975,7 @@ void reader_exit(int do_exit, int forced) { if (reader_data_t *data = current_data_or_null()) { data->end_loop = do_exit; } - end_loop = do_exit; + noni_end_loop = do_exit; if (forced) exit_forced = true; } @@ -2118,7 +2118,7 @@ void reader_pop() { if (new_reader == nullptr) { reader_interactive_destroy(); } else { - end_loop = 0; + noni_end_loop = 0; s_reset(&new_reader->screen, screen_reset_abandon_line); } } @@ -2279,7 +2279,7 @@ bool shell_is_exiting() { reader_data_t *data = current_data_or_null(); return job_list_is_empty() && data != NULL && data->end_loop; } - return end_loop; + return noni_end_loop; } void reader_bg_job_warning() { @@ -3520,7 +3520,7 @@ int reader_read(int fd, const io_chain_t &io) { // If the exit command was called in a script, only exit the script, not the program. reader_data_t *data = current_data_or_null(); if (data) data->end_loop = 0; - end_loop = 0; + noni_end_loop = 0; proc_pop_interactive(); return res; From 144e37b8babc8e3d77158709860f3120766b03ee Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 13:14:36 -0800 Subject: [PATCH 098/191] Remove some empty code --- src/kill.cpp | 6 ------ src/kill.h | 9 --------- src/reader.cpp | 2 -- src/sanity.cpp | 1 - 4 files changed, 18 deletions(-) diff --git a/src/kill.cpp b/src/kill.cpp index 8b137a664..b005ba824 100644 --- a/src/kill.cpp +++ b/src/kill.cpp @@ -51,9 +51,3 @@ const wchar_t *kill_yank() { } return kill_list.front().c_str(); } - -void kill_sanity_check() {} - -void kill_init() {} - -void kill_destroy() {} diff --git a/src/kill.h b/src/kill.h index ed0fc112c..e22fb57f6 100644 --- a/src/kill.h +++ b/src/kill.h @@ -19,13 +19,4 @@ const wchar_t *kill_yank_rotate(); /// Paste from the killring. const wchar_t *kill_yank(); -/// Sanity check. -void kill_sanity_check(); - -/// Initialize the killring. -void kill_init(); - -/// Destroy the killring. -void kill_destroy(); - #endif diff --git a/src/reader.cpp b/src/reader.cpp index ad17f6056..2e7cae890 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1729,7 +1729,6 @@ static void reader_interactive_init() { pid_t shell_pgid; if (!input_initialized) init_input(); - kill_init(); shell_pgid = getpgrp(); // This should enable job control on fish, even if our parent process did not enable it for us. @@ -1843,7 +1842,6 @@ static void reader_interactive_init() { /// Destroy data for interactive use. static void reader_interactive_destroy() { - kill_destroy(); outputter_t::stdoutput().set_color(rgb_color_t::reset(), rgb_color_t::reset()); input_destroy(); } diff --git a/src/sanity.cpp b/src/sanity.cpp index 37eeaafee..4019cafea 100644 --- a/src/sanity.cpp +++ b/src/sanity.cpp @@ -21,7 +21,6 @@ void sanity_lose() { bool sanity_check() { if (!insane) reader_sanity_check(); - if (!insane) kill_sanity_check(); if (!insane) proc_sanity_check(); return insane; } From 4b292c777d5eae83856ef3fed90ff1f93a08736c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 13:24:03 -0800 Subject: [PATCH 099/191] Clean up and clarify reader_exit() --- src/builtin_exit.cpp | 2 +- src/fish.cpp | 2 +- src/reader.cpp | 62 +++++++++++++++++++++----------------------- src/reader.h | 7 +++-- src/signal.cpp | 2 +- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/builtin_exit.cpp b/src/builtin_exit.cpp index ce7f1d429..d089598ae 100644 --- a/src/builtin_exit.cpp +++ b/src/builtin_exit.cpp @@ -88,6 +88,6 @@ int builtin_exit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { return STATUS_INVALID_ARGS; } } - reader_exit(1, 0); + reader_set_end_loop(true); return retval; } diff --git a/src/fish.cpp b/src/fish.cpp index d75eaae44..1c8a0aaff 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -395,7 +395,7 @@ int main(int argc, char **argv) { argv + my_optind); } res = run_command_list(&opts.batch_cmds, {}); - reader_exit(0, 0); + reader_set_end_loop(false); } else if (my_optind == argc) { // Implicitly interactive mode. res = reader_read(STDIN_FILENO, {}); diff --git a/src/reader.cpp b/src/reader.cpp index 2e7cae890..94f672b83 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -356,8 +356,6 @@ class reader_data_t { highlight_function_t highlight_func{nullptr}; /// Function for testing if the string can be returned. test_function_t test_func{nullptr}; - /// When this is true, the reader will exit. - bool end_loop{false}; /// If this is true, exit reader even if there are running jobs. This happens if we press e.g. /// ^D twice. bool prev_end_loop{false}; @@ -431,9 +429,6 @@ static reader_data_t *current_data() { /// handled by the fish interrupt handler. static volatile sig_atomic_t is_interactive_read; -/// Flag for ending non-interactive shell. -static int noni_end_loop = 0; - /// The stack containing names of files that are being parsed. static std::stack> current_filename; @@ -454,8 +449,18 @@ static struct termios tty_modes_for_external_cmds; static void reader_super_highlight_me_plenty(int highlight_pos_adjust = 0, bool no_io = false); -/// Variable to keep track of forced exits - see \c reader_exit_forced(); -static bool exit_forced; +/// Tracks a currently pending exit. This may be manipulated from a signal handler. +struct { + /// Whether we should exit the current reader loop. + bool end_current_loop{false}; + + /// Whether we should exit all reader loops. This is set in response to a HUP signal and it + /// latches (once set it is never cleared). This should never be reset to false. + volatile bool force{false}; + + bool should_exit() const { return end_current_loop || force; } + +} s_pending_exit; /// Give up control of terminal. static void term_donate(outputter_t &outp) { @@ -506,7 +511,7 @@ static void term_steal() { invalidate_termsize(); } -bool reader_exit_forced() { return exit_forced; } +bool reader_exit_forced() { return s_pending_exit.force; } /// Given a command line and an autosuggestion, return the string that gets shown to the user. wcstring combine_command_and_autosuggestion(const wcstring &cmdline, @@ -804,7 +809,7 @@ int reader_reading_interrupted() { int res = reader_interrupted(); reader_data_t *data = current_data_or_null(); if (res && data && data->exit_on_interrupt) { - reader_exit(1, 0); + reader_set_end_loop(true); parser_t::skip_all_blocks(); // We handled the interrupt ourselves, our caller doesn't need to handle it. return 0; @@ -971,12 +976,12 @@ void restore_term_mode() { } } -void reader_exit(int do_exit, int forced) { - if (reader_data_t *data = current_data_or_null()) { - data->end_loop = do_exit; - } - noni_end_loop = do_exit; - if (forced) exit_forced = true; +/// Exit the current reader loop. This may be invoked from a signal handler. +void reader_set_end_loop(bool flag) { s_pending_exit.end_current_loop = flag; } + +void reader_force_exit() { + // Beware, we may be in a signal handler. + s_pending_exit.force = true; } void reader_repaint_needed() { @@ -2116,7 +2121,7 @@ void reader_pop() { if (new_reader == nullptr) { reader_interactive_destroy(); } else { - noni_end_loop = 0; + s_pending_exit.end_current_loop = false; s_reset(&new_reader->screen, screen_reset_abandon_line); } } @@ -2272,13 +2277,7 @@ static void reader_super_highlight_me_plenty(int match_highlight_pos_adjust, boo } } -bool shell_is_exiting() { - if (shell_is_interactive()) { - reader_data_t *data = current_data_or_null(); - return job_list_is_empty() && data != NULL && data->end_loop; - } - return noni_end_loop; -} +bool shell_is_exiting() { return s_pending_exit.should_exit(); } void reader_bg_job_warning() { fputws(_(L"There are still jobs active:\n"), stdout); @@ -2320,7 +2319,7 @@ static void handle_end_loop() { reader_data_t *data = current_data(); if (!data->prev_end_loop && bg_jobs) { reader_bg_job_warning(); - reader_exit(0, 0); + reader_set_end_loop(false); data->prev_end_loop = 1; return; } @@ -2361,7 +2360,7 @@ static int read_i() { reader_data_t *data = current_data(); data->prev_end_loop = 0; - while ((!data->end_loop) && (!sanity_check())) { + while (!shell_is_exiting() && (!sanity_check())) { event_fire_generic(L"fish_prompt"); run_count++; @@ -2383,7 +2382,7 @@ static int read_i() { // reader_set_buffer during evaluation. const wchar_t *tmp = reader_readline(0); - if (data->end_loop) { + if (shell_is_exiting()) { handle_end_loop(); } else if (tmp) { const wcstring command = tmp; @@ -2398,7 +2397,7 @@ static int read_i() { if (data->history) { data->history->resolve_pending(); } - if (data->end_loop) { + if (shell_is_exiting()) { handle_end_loop(); } else { data->prev_end_loop = 0; @@ -2501,7 +2500,7 @@ const wchar_t *reader_readline(int nchars) { } } - while (!finished && !data->end_loop) { + while (!finished && !shell_is_exiting()) { if (0 < nchars && (size_t)nchars <= data->command_line.size()) { // We've already hit the specified character limit. finished = 1; @@ -2634,8 +2633,7 @@ const wchar_t *reader_readline(int nchars) { break; } case R_EOF: { - exit_forced = true; - data->end_loop = 1; + reader_force_exit(); break; } case R_COMPLETE: @@ -3516,9 +3514,7 @@ int reader_read(int fd, const io_chain_t &io) { res = shell_is_interactive() ? read_i() : read_ni(fd, io); // If the exit command was called in a script, only exit the script, not the program. - reader_data_t *data = current_data_or_null(); - if (data) data->end_loop = 0; - noni_end_loop = 0; + reader_set_end_loop(false); proc_pop_interactive(); return res; diff --git a/src/reader.h b/src/reader.h index 873b8341d..0c28109b2 100644 --- a/src/reader.h +++ b/src/reader.h @@ -49,8 +49,11 @@ class editable_line_t { /// Read commands from \c fd until encountering EOF. int reader_read(int fd, const io_chain_t &io); -/// Tell the shell that it should exit after the currently running command finishes. -void reader_exit(int do_exit, int force); +/// Tell the shell whether it should exit after the currently running command finishes. +void reader_set_end_loop(bool flag); + +/// Mark that the reader should forcibly exit. This may be invoked from a signal handler. +void reader_force_exit(); /// Check that the reader is in a sane state. void reader_sanity_check(); diff --git a/src/signal.cpp b/src/signal.cpp index 824e19390..f8cb0483e 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -226,7 +226,7 @@ static void handle_hup(int sig, siginfo_t *info, void *context) { if (event_is_signal_observed(SIGHUP)) { default_handler(sig, 0, 0); } else { - reader_exit(1, 1); + reader_force_exit(); } topic_monitor_t::principal().post(topic_t::sighupint); } From 47f1b026e6bfb27123beb50804c13284b807f51d Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 13:39:43 -0800 Subject: [PATCH 100/191] Simplify reader generation count using thread_local Replaces pthread_set_specific --- src/reader.cpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 94f672b83..8308943ec 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -123,15 +123,15 @@ enum class jump_precision_t { till, to }; /// Any time the contents of a buffer changes, we update the generation count. This allows for our /// background threads to notice it and skip doing work that they would otherwise have to do. -static std::atomic s_generation_count; +static std::atomic s_generation; /// This pthreads generation count is set when an autosuggestion background thread starts up, so it /// can easily check if the work it is doing is no longer useful. -static pthread_key_t generation_count_key; +static thread_local unsigned s_thread_generation; /// Helper to get the generation count -static unsigned int read_generation_count() { - return s_generation_count.load(std::memory_order_relaxed); +static inline unsigned read_generation_count() { + return s_generation.load(std::memory_order_relaxed); } static void set_command_line_and_position(editable_line_t *el, const wcstring &new_str, size_t pos); @@ -673,7 +673,7 @@ void reader_data_t::command_line_changed(const editable_line_t *el) { indents.resize(len); // Update the gen count. - s_generation_count++; + s_generation.store(1 + read_generation_count(), std::memory_order_relaxed); } else if (el == &this->pager.search_field_line) { this->pager.refilter_completions(); this->pager_selection_changed(); @@ -819,8 +819,7 @@ int reader_reading_interrupted() { bool reader_thread_job_is_stale() { ASSERT_IS_BACKGROUND_THREAD(); - void *current_count = (void *)(uintptr_t)read_generation_count(); - return current_count != pthread_getspecific(generation_count_key); + return read_generation_count() != s_thread_generation; } void reader_write_title(const wcstring &cmd, bool reset_cursor_position) { @@ -916,8 +915,6 @@ static void exec_prompt() { } void reader_init() { - DIE_ON_FAILURE(pthread_key_create(&generation_count_key, NULL)); - auto &vars = parser_t::principal_parser().vars(); // Ensure this var is present even before an interactive command is run so that if it is used @@ -1306,12 +1303,11 @@ static std::function get_autosuggestion_performer const autosuggestion_result_t nothing = {}; // If the main thread has moved on, skip all the work. + // Otherwise record the generation. if (generation_count != read_generation_count()) { return nothing; } - - DIE_ON_FAILURE( - pthread_setspecific(generation_count_key, (void *)(uintptr_t)generation_count)); + s_thread_generation = generation_count; // Let's make sure we aren't using the empty string. if (search_string.empty()) { @@ -2223,15 +2219,12 @@ static std::function get_highlight_performer(const wcs highlight_function_t highlight_func = no_io ? highlight_shell_no_io : current_data()->highlight_func; return [=]() -> highlight_result_t { + if (text.empty()) return {}; if (generation_count != read_generation_count()) { // The gen count has changed, so don't do anything. return {}; } - if (text.empty()) { - return {}; - } - DIE_ON_FAILURE( - pthread_setspecific(generation_count_key, (void *)(uintptr_t)generation_count)); + s_thread_generation = generation_count; std::vector colors(text.size(), 0); highlight_func(text, colors, match_highlight_pos, NULL /* error */, vars); return {std::move(colors), text}; From 0a29eb314210d7c103d134402364489130e765a0 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 13:59:49 -0800 Subject: [PATCH 101/191] reader_readline to return maybe_t Stop returning a raw pointer. --- src/builtin_read.cpp | 12 +++++------- src/reader.cpp | 8 ++++---- src/reader.h | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 4c7895882..fe4b842ae 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -202,7 +202,6 @@ static int read_interactive(wcstring &buff, int nchars, bool shell, bool silent, const wchar_t *prompt, const wchar_t *right_prompt, const wchar_t *commandline) { int exit_res = STATUS_CMD_OK; - const wchar_t *line; // TODO: rationalize this. const auto &vars = env_stack_t::principal(); @@ -227,17 +226,16 @@ static int read_interactive(wcstring &buff, int nchars, bool shell, bool silent, proc_push_interactive(1); event_fire_generic(L"fish_prompt"); - line = reader_readline(nchars); + auto mline = reader_readline(nchars); proc_pop_interactive(); - if (line) { - if (0 < nchars && (size_t)nchars < wcslen(line)) { + if (mline) { + buff = mline.acquire(); + if (nchars > 0 && (size_t)nchars < buff.size()) { // Line may be longer than nchars if a keybinding used `commandline -i` // note: we're deliberately throwing away the tail of the commandline. // It shouldn't be unread because it was produced with `commandline -i`, // not typed. - buff = wcstring(line, nchars); - } else { - buff = wcstring(line); + buff.resize(nchars); } } else { exit_res = STATUS_CMD_ERROR; diff --git a/src/reader.cpp b/src/reader.cpp index 8308943ec..a370e2719 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2373,12 +2373,12 @@ static int read_i() { // Put buff in temporary string and clear buff, so that we can handle a call to // reader_set_buffer during evaluation. - const wchar_t *tmp = reader_readline(0); + maybe_t tmp = reader_readline(0); if (shell_is_exiting()) { handle_end_loop(); } else if (tmp) { - const wcstring command = tmp; + const wcstring command = tmp.acquire(); update_buff_pos(&data->command_line, 0); data->command_line.text.clear(); data->command_line_changed(&data->command_line); @@ -2448,7 +2448,7 @@ static bool text_ends_in_comment(const wcstring &text) { return token.type == TOK_COMMENT; } -const wchar_t *reader_readline(int nchars) { +maybe_t reader_readline(int nchars) { wint_t c; int last_char = 0; size_t yank_len = 0; @@ -3350,7 +3350,7 @@ const wchar_t *reader_readline(int nchars) { outputter_t::stdoutput().set_color(rgb_color_t::reset(), rgb_color_t::reset()); } - return finished ? data->command_line.text.c_str() : NULL; + return finished ? maybe_t{data->command_line.text} : none(); } bool jump(jump_direction_t dir, jump_precision_t precision, editable_line_t *el, wchar_t target) { diff --git a/src/reader.h b/src/reader.h index 0c28109b2..871547cfd 100644 --- a/src/reader.h +++ b/src/reader.h @@ -144,7 +144,7 @@ bool reader_thread_job_is_stale(); /// characters even if a full line has not yet been read. Note: the returned value may be longer /// than nchars if a single keypress resulted in multiple characters being inserted into the /// commandline. -const wchar_t *reader_readline(int nchars); +maybe_t reader_readline(int nchars); /// Push a new reader environment. void reader_push(const wcstring &name); From c46f02e01ea5e4c3b693db25a93ca64b05be0d6a Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 15 Dec 2018 16:23:36 -0800 Subject: [PATCH 102/191] Initial sphinx file import --- cmake/Docs.cmake | 33 + sphinx_doc_src/conf.py | 189 +++++ sphinx_doc_src/index.rst | 1427 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1649 insertions(+) create mode 100644 sphinx_doc_src/conf.py create mode 100644 sphinx_doc_src/index.rst diff --git a/cmake/Docs.cmake b/cmake/Docs.cmake index 54ff25e81..d7a5907f6 100644 --- a/cmake/Docs.cmake +++ b/cmake/Docs.cmake @@ -1,7 +1,40 @@ FIND_PACKAGE(Doxygen 1.8.7) +FIND_PROGRAM(SPHINX_EXECUTABLE NAMES sphinx-build + HINTS + $ENV{SPHINX_DIR} + PATH_SUFFIXES bin + DOC "Sphinx documentation generator") + INCLUDE(FeatureSummary) +SET(SPHINX_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/sphinx_doc_src") +SET(SPHINX_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/sphinx-root") +SET(SPHINX_BUILD_DIR "${SPHINX_ROOT_DIR}/build") +SET(SPHINX_CACHE_DIR "${SPHINX_ROOT_DIR}/doctrees") +SET(SPHINX_HTML_DIR "${SPHINX_ROOT_DIR}/html") +SET(SPHINX_MANPAGE_DIR "${SPHINX_ROOT_DIR}/man") + +CONFIGURE_FILE("${SPHINX_SRC_DIR}/conf.py" "${SPHINX_BUILD_DIR}/conf.py" @ONLY) + +ADD_CUSTOM_TARGET(sphinx-docs + ${SPHINX_EXECUTABLE} + -q -b html + -c "${SPHINX_SRC_DIR}" + -d "${SPHINX_CACHE_DIR}" + "${SPHINX_SRC_DIR}" + "${SPHINX_HTML_DIR}" + COMMENT "Building HTML documentation with Sphinx") + +ADD_CUSTOM_TARGET(sphinx-manpages + ${SPHINX_EXECUTABLE} + -q -b man + -c "${SPHINX_SRC_DIR}" + -d "${SPHINX_CACHE_DIR}" + "${SPHINX_SRC_DIR}" + "${SPHINX_MANPAGE_DIR}" + COMMENT "Building man pages with Sphinx") + IF(DOXYGEN_FOUND) OPTION(BUILD_DOCS "build documentation (requires Doxygen)" ON) ELSE(DOXYGEN_FOUND) diff --git a/sphinx_doc_src/conf.py b/sphinx_doc_src/conf.py new file mode 100644 index 000000000..2ffcc5f3c --- /dev/null +++ b/sphinx_doc_src/conf.py @@ -0,0 +1,189 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +import glob +import os.path + +# -- Helper functions -------------------------------------------------------- + +def strip_ext(path): + """ Remove the extension from a path. """ + return os.path.splitext(path)[0] + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'fish-shell' +copyright = '2018, fish-shell developers' +author = 'fish-shell developers' + +# The short X.Y version +version = '3.1' +# The full version, including alpha/beta/rc tags +release = '3.1.0' + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = None + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'nature' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'fish-shelldoc' + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'fish-shell.tex', 'fish-shell Documentation', + 'fish-shell developers', 'manual'), +] + + +# -- Options for manual page output ------------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'fish', 'fish-shell Documentation', + [author], 1) +] +for path in sorted(glob.glob('cmds/*')): + docname = strip_ext(path) + cmd = os.path.basename(docname) + man_pages.append((docname, cmd, '', '', 1)) + + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'fish-shell', 'fish-shell Documentation', + author, 'fish-shell', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Options for Epub output ------------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] + +# Disable smart-quotes to prevent double dashes from becoming emdashes. +smartquotes = False diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst new file mode 100644 index 000000000..a0e326e89 --- /dev/null +++ b/sphinx_doc_src/index.rst @@ -0,0 +1,1427 @@ +/** +\mainpage Documentation +\htmlonly[block] +
+ + +
+
+

Documentation

+\endhtmlonly + + +\section introduction Introduction + +This is the documentation for `fish`, the friendly interactive shell. `fish` is a user friendly commandline shell intended mostly for interactive use. A shell is a program used to execute other programs. For the latest information on `fish`, please visit the `fish` homepage. + + +\section syntax Syntax overview + +Shells like fish are used by giving them commands. Every `fish` command follows the same simple syntax. + +A command is executed by writing the name of the command followed by any arguments. + +Example: + +\fish +echo hello world +\endfish + +This calls the `echo` command. `echo` is a command which will write its arguments to the screen. In the example above, the output will be 'hello world'. Everything in fish is done with commands. There are commands for performing a set of commands multiple times, commands for assigning variables, commands for treating a group of commands as a single command, etc.. And every single command follows the same simple syntax. + +If you want to find out more about the echo command used above, read the manual page for the echo command by writing: `man echo` + +`man` is a command for displaying a manual page on a given topic. The man command takes the name of the manual page to display as an argument. There are manual pages for almost every command on most computers. There are also manual pages for many other things, such as system libraries and important files. + +Every program on your computer can be used as a command in `fish`. If the program file is located in one of the directories in the `PATH`, it is sufficient to type the name of the program to use it. Otherwise the whole filename, including the directory (like `/home/me/code/checkers/checkers` or `../checkers`) has to be used. + +Here is a list of some useful commands: + +- `cd`, change the current directory +- `ls`, list files and directories +- `man`, display a manual page on the screen +- `mv`, move (rename) files +- `cp`, copy files +- `open`, open files with the default application associated with each filetype +- `less`, list the contents of files + +Commands and parameters are separated by the space character ' '. Every command ends with either a newline (i.e. by pressing the return key) or a semicolon '`;`'. More than one command can be written on the same line by separating them with semicolons. + +A switch is a very common special type of argument. Switches almost always start with one or more hyphens '`-`' and alter the way a command operates. For example, the '`ls`' command usually lists all the files and directories in the current working directory, but by using the '`-l`' switch, the behavior of '`ls`' is changed to not only display the filename, but also the size, permissions, owner and modification time of each file. + +Switches differ between commands and are documented in the manual page for each command. Some switches are common to most command though, for example '`--help`' will usually display a help text, '`-i`' will often turn on interactive prompting before taking action, while '`-f`' will turn it off. + + +\subsection quotes Quotes + +Sometimes features such as parameter expansion and character escapes get in the way. When that happens, the user can write a parameter within quotes, either `'` (single quote) or `"` (double quote). There is one important difference between single quoted and double quoted strings: When using double quoted string, variable expansion still takes place. Other than that, no other kind of expansion (including brace expansion and parameter expansion) will take place, the parameter may contain spaces, and escape sequences are ignored. The only backslash escape accepted within single quotes is `\'`, which escapes a single quote and `\\`, which escapes the backslash symbol. The only backslash escapes accepted within double quotes are `\"`, which escapes a double quote, `\$`, which escapes a dollar character, `\` followed by a newline, which deletes the backslash and the newline, and lastly `\\`, which escapes the backslash symbol. Single quotes have no special meaning within double quotes and vice versa. + +Example: + +\fish +rm "cumbersome filename.txt" +\endfish + +Will remove the file 'cumbersome filename.txt', while + +\fish +rm cumbersome filename.txt +\endfish + +would remove the two files 'cumbersome' and 'filename.txt'. + + +\subsection escapes Escaping characters + +Some characters can not be written directly on the command line. For these characters, so called escape sequences are provided. These are: + +- '\\a' represents the alert character +- '\\b' represents the backspace character +- '\\e' represents the escape character +- '\\f' represents the form feed character +- '\\n' represents a newline character +- '\\r' represents the carriage return character +- '\\t' represents the tab character +- '\\v' represents the vertical tab character +- '\\ ' escapes the space character +- '\\$' escapes the dollar character +- '\\\\' escapes the backslash character +- '\\*' escapes the star character +- '\\?' escapes the question mark character +- '\\~' escapes the tilde character +- '\\#' escapes the hash character +- '\\(' escapes the left parenthesis character +- '\\)' escapes the right parenthesis character +- '\\{' escapes the left curly bracket character +- '\\}' escapes the right curly bracket character +- '\\[' escapes the left bracket character +- '\\]' escapes the right bracket character +- '\\\<' escapes the less than character +- '\\\>' escapes the more than character +- '\\^' escapes the circumflex character +- '\\&' escapes the ampersand character +- '\\|' escapes the vertical bar character +- '\\;' escapes the semicolon character +- '\\"' escapes the quote character +- '\\'' escapes the apostrophe character + +- '\\xxx', where xx is a hexadecimal number, represents the ascii character with the specified value. For example, `\x9` is the tab character. + +- '\\Xxx', where xx is a hexadecimal number, represents a byte of data with the specified value. If you are using a multibyte encoding, this can be used to enter +invalid strings. Only use this if you know what you are doing. + +- '\\ooo', where ooo is an octal number, represents the ascii character with the specified value. For example, `\011` is the tab character. + +- '\\uxxxx', where xxxx is a hexadecimal number, represents the 16-bit Unicode character with the specified value. For example, `\u9` is the tab character. + +- '\\Uxxxxxxxx', where xxxxxxxx is a hexadecimal number, represents the 32-bit Unicode character with the specified value. For example, `\U9` is the tab character. + +- '\\cx', where x is a letter of the alphabet, represents the control sequence generated by pressing the control key and the specified letter. For example, `\ci` is the tab character + + +\subsection redirects Input/Output (IO) redirection + +Most programs use three input/output (IO) streams, each represented by a number called a file descriptor (FD). These are: + +- Standard input, FD 0, for reading, defaults to reading from the keyboard. + +- Standard output, FD 1, for writing, defaults to writing to the screen. + +- Standard error, FD 2, for writing errors and warnings, defaults to writing to the screen. + +The reason for providing for two output file descriptors is to allow separation of errors and warnings from regular program output. + +Any file descriptor can be directed to a different output than its default through a simple mechanism called a redirection. + +An example of a file redirection is `echo hello > output.txt`, which directs the output of the echo command to the file output.txt. + +- To read standard input from a file, write `DESTINATION` +- To write standard error to a file, write `2>DESTINATION` +- To append standard output to a file, write `>>DESTINATION_FILE` +- To append standard error to a file, write `2>>DESTINATION_FILE` + +- To not overwrite ("clobber") an existing file, write '>?DESTINATION' or '2>?DESTINATION' + +`DESTINATION` can be one of the following: + +- A filename. The output will be written to the specified file. + +- An ampersand (`&`) followed by the number of another file descriptor. The output will be written to that file descriptor instead. + +- An ampersand followed by a minus sign (`&-`). The file descriptor will be closed. + +Example: + +To redirect both standard output and standard error to the file 'all_output.txt', you can write `echo Hello > all_output.txt 2>&1`. + +Any file descriptor can be redirected in an arbitrary way by prefixing the redirection with the file descriptor. + +- To redirect input of FD N, write `NDESTINATION` +- To append the output of FD N to a file, write `N>>DESTINATION_FILE` + +Example: `echo Hello 2>output.stderr` and `echo Hello 2>output.stderr` are equivalent, and write the standard error (file descriptor 2) of the target program to `output.stderr`. + +\subsection piping Piping + +The user can string together multiple commands into a so called pipeline. This means that the standard output of one command will be read in as standard input into the next command. This is done by separating the commands by the pipe character '`|`'. For example + +\fish +cat foo.txt | head +\endfish + +will call the `cat` program with the parameter 'foo.txt', which will print the contents of the file 'foo.txt'. The contents of foo.txt will then be filtered through the program 'head', which will pass on the first ten lines of the file to the screen. For more information on how to combine commands through pipes, read the manual pages of the commands you want to use using the `man` command. If you want to find out more about the `cat` program, type `man cat`. + +Pipes usually connect file descriptor 1 (standard output) of the first process to file descriptor 0 (standard input) of the second process. It is possible to use a different output file descriptor by prepending the desired FD number and then output redirect symbol to the pipe. For example: + +\fish +make fish 2>| less +\endfish + +will attempt to build the fish program, and any errors will be shown using the less pager. + + +\subsection syntax-background Background jobs + +When you start a job in `fish`, `fish` itself will pause, and give control of the terminal to the program just started. Sometimes, you want to continue using the commandline, and have the job run in the background. To create a background job, append an \& (ampersand) to your command. This will tell fish to run the job in the background. Background jobs are very useful when running programs that have a graphical user interface. + +Example: + +\fish +emacs & +\endfish + +will start the emacs text editor in the background. + + +\subsection syntax-job-control Job control + +Most programs allow you to suspend the program's execution and return control to `fish` by pressing @key{Control,Z} (also referred to as `^Z`). Once back at the `fish` commandline, you can start other programs and do anything you want. If you then want you can go back to the suspended command by using the `fg` (foreground) command. + +If you instead want to put a suspended job into the background, use the `bg` command. + +To get a listing of all currently started jobs, use the `jobs` command. + + +\subsection syntax-function Functions + +Functions are programs written in the fish syntax. They group together one or more commands and their arguments using a single name. It can also be used to start a specific command with additional arguments. + +For example, the following is a function definition that calls the command `ls` with the argument '`-l`' to print a detailed listing of the contents of the current directory: + +\fish +function ll + ls -l $argv +end +\endfish + +The first line tells fish that a function by the name of `ll` is to be defined. To use it, simply write `ll` on the commandline. The second line tells fish that the command `ls -l $argv` should be called when `ll` is invoked. '`$argv`' is an array variable, which always contains all arguments sent to the function. In the example above, these are simply passed on to the `ls` command. For more information on functions, see the documentation for the function builtin. + + +\subsubsection syntax-function-wrappers Defining aliases + +One of the most common uses for functions is to slightly alter the behavior of an already existing command. For example, one might want to redefine the `ls` command to display colors. The switch for turning on colors on GNU systems is '`--color=auto`'. An alias, or wrapper, around `ls` might look like this: + +\fish +function ls + command ls --color=auto $argv +end +\endfish + +There are a few important things that need to be noted about aliases: + +- Always take care to add the `$argv` variable to the list of parameters to the wrapped command. This makes sure that if the user specifies any additional parameters to the function, they are passed on to the underlying command. + +- If the alias has the same name as the aliased command, it is necessary to prefix the call to the program with `command` in order to tell fish that the function should not call itself, but rather a command with the same name. Failing to do so will cause infinite recursion bugs. + +- Autoloading isn't applicable to aliases. Since, by definition, the function is created at the time the alias command is executed. You cannot autoload aliases. + +To easily create a function of this form, you can use the alias command. + + +\subsubsection syntax-function-autoloading Autoloading functions + +Functions can be defined on the commandline or in a configuration file, but they can also be automatically loaded. This method of defining functions has several advantages. An autoloaded function becomes available automatically to all running shells. If the function definition is changed, all running shells will automatically reload the altered version. Startup time and memory usage is improved, etc. + +Fish automatically searches through any directories in the array variable `$fish_function_path`, and any functions defined are automatically loaded when needed. A function definition file must have a filename consisting of the name of the function plus the suffix '`.fish`'. + +By default, Fish searches the following for functions, using the first available file that it finds: +- A directory for end-users to keep their own functions, usually `~/.config/fish/functions` (controlled by the `XDG_CONFIG_HOME` environment variable). +- A directory for systems administrators to install functions for all users on the system, usually `/etc/fish/functions`. +- A directory for third-party software vendors to ship their own functions for their software, usually `/usr/share/fish/vendor_functions.d`. +- The functions shipped with fish, usually installed in `/usr/share/fish/functions`. + +These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above. + +This wide search may be confusing. If you are unsure, your functions probably belong in `~/.config/fish/functions`. + +It is very important that function definition files only contain the definition for the specified function and nothing else. Otherwise, it is possible that autoloading a function files requires that the function already be loaded, which creates a circular dependency. + +Autoloading also won't work for event handlers, since fish cannot know that a function is supposed to be executed when an event occurs when it hasn't yet loaded the function. See the event handlers section for more information. + +Autoloading is not applicable to functions created by the `alias` command. For functions simple enough that you prefer to use the `alias` command to define them you'll need to put those commands in your `~/.config/fish/config.fish` script or some other script run when the shell starts. + +If you are developing another program, you may wish to install functions which are available for all users of the fish shell on a system. They can be installed to the "vendor" functions directory. As this path may vary from system to system, the `pkgconfig` framework should be used to discover this path with the output of `pkg-config --variable functionsdir fish`. + + +\subsubsection syntax-conditional Conditional execution of code and flow control + +There are four fish builtins that let you execute commands only if a specific criterion is met. These builtins are `if`, `switch`, `and` and `or`. + +The `switch` command is used to execute one of possibly many blocks of commands depending on the value of a string. See the documentation for switch for more information. + +The other conditionals use the exit status of a command to decide if a command or a block of commands should be executed. See the documentation for `if`, `and` and `or` for more information. + + +\subsection syntax-words Some common words + +This is a short explanation of some of the commonly used words in fish. + +- argument a parameter given to a command + +- builtin a command that is implemented in the shell. Builtins are commands that are so closely tied to the shell that it is impossible to implement them as external commands. + +- command a program that the shell can run. + +- function a block of commands that can be called as if they were a single command. By using functions, it is possible to string together multiple smaller commands into one more advanced command. + +- job a running pipeline or command + +- pipeline a set of commands stringed together so that the output of one command is the input of the next command + +- redirection an operation that changes one of the input/output streams associated with a job + +- switch a special flag sent as an argument to a command that will alter the behavior of the command. A switch almost always begins with one or two hyphens. + + +\section docs Help + +`fish` has an extensive help system. Use the `help` command to obtain help on a specific subject or command. For instance, writing `help syntax` displays the syntax section of this documentation. + +`fish` also has man pages for its commands. For example, `man set` will show the documentation for `set` as a man page. + +Help on a specific builtin can also be obtained with the `-h` parameter. For instance, to obtain help on the `fg` builtin, either type `fg -h` or `help fg`. + + +\section autosuggestions Autosuggestions + +fish suggests commands as you type, based on command history, completions, and valid file paths. As you type commands, you will see a suggestion offered after the cursor, in a muted gray color (which can be changed with the `fish_color_autosuggestion` variable). + +To accept the autosuggestion (replacing the command line contents), press right arrow or @key{Control,F}. To accept the first suggested word, press @key{Alt,→,Right} or @key{Alt,F}. If the autosuggestion is not what you want, just ignore it: it won't execute unless you accept it. + +Autosuggestions are a powerful way to quickly summon frequently entered commands, by typing the first few characters. They are also an efficient technique for navigating through directory hierarchies. + + +\section completion Tab completion + +Tab completion is one of the most time saving features of any modern shell. By tapping the tab key, the user asks `fish` to guess the rest of the command or parameter that the user is currently typing. If `fish` can only find one possible completion, `fish` will write it out. If there is more than one completion, `fish` will write out the longest prefix that all completions have in common. If the completions differ on the first character, a list of all possible completions is printed. The list features descriptions of the completions and if the list doesn't fit the screen, it is scrollable by using the arrow keys, the page up/page down keys, the tab key or the space bar. Once the list has been entered, pressing any other key will start a search. If the list has not been entered, pressing any other key will exit the list and insert the pressed key into the command line. + +These are the general purpose tab completions that `fish` provides: + +- Completion of commands (builtins, functions and regular programs). + +- Completion of shell variable names. + +- Completion of usernames for tilde expansion. + +- Completion of filenames, even on strings with wildcards such as '`*`', '`**`' and '`?`'. + +`fish` provides a large number of program specific completions. Most of these completions are simple options like the `-l` option for `ls`, but some are more advanced. The latter include: + +- The programs `man` and `whatis` show all installed manual pages as completions. + +- The `make` program uses all targets in the Makefile in the current directory as completions. + +- The `mount` command uses all mount points specified in fstab as completions. + +- The `ssh` command uses all hosts that are stored in the known_hosts file as completions. (See the ssh documentation for more information) + +- The `su` command uses all users on the system as completions. + +- The `apt-get`, `rpm` and `yum` commands use all installed packages as completions. + + +\subsection completion-own Writing your own completions + +Specifying your own completions is not difficult. To specify a completion, use the `complete` command. `complete` takes as a parameter the name of the command to specify a completion for. For example, to add a completion for the program `myprog`, one would start the completion command with `complete -c myprog ...` + +To provide a list of possible completions for myprog, use the `-a` switch. If `myprog` accepts the arguments start and stop, this can be specified as `complete -c myprog -a 'start stop'`. The argument to the `-a` switch is always a single string. At completion time, it will be tokenized on spaces and tabs, and variable expansion, command substitution and other forms of parameter expansion will take place. + +`fish` has a special syntax to support specifying switches accepted by a command. The switches `-s`, `-l` and `-o` are used to specify a short switch (single character, such as `-l`), a gnu style long switch (such as '`--color`') and an old-style long switch (like '`-shuffle`'), respectively. If the command 'myprog' has an option '-o' which can also be written as '`--output`', and which can take an additional value of either 'yes' or 'no', this can be specified by writing: + +\fish +complete -c myprog -s o -l output -a "yes no" +\endfish + +There are also special switches for specifying that a switch requires an argument, to disable filename completion, to create completions that are only available in some combinations, etc.. For a complete description of the various switches accepted by the `complete` command, see the documentation for the complete builtin, or write `complete --help` inside the `fish` shell. + +For examples of how to write your own complex completions, study the completions in `/usr/share/fish/completions`. (The exact path depends on your chosen installation prefix and may be slightly different) + + +\subsection completion-func Useful functions for writing completions + +`fish` ships with several functions that are very useful when writing command specific completions. Most of these functions name begins with the string '`__fish_`'. Such functions are internal to `fish` and their name and interface may change in future fish versions. Still, some of them may be very useful when writing completions. A few of these functions are described here. Be aware that they may be removed or changed in future versions of fish. + +Functions beginning with the string `__fish_print_` print a newline separated list of strings. For example, `__fish_print_filesystems` prints a list of all known file systems. Functions beginning with `__fish_complete_` print out a newline separated list of completions with descriptions. The description is separated from the completion by a tab character. + +- `__fish_complete_directories STRING DESCRIPTION` performs path completion on STRING, allowing only directories, and giving them the description 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. + +- `__fish_complete_pids` prints a list of all processes IDs with the command name as description. + +- `__fish_complete_suffix SUFFIX` performs file completion allowing only files ending in SUFFIX, with an optional description. + +- `__fish_complete_users` prints a list of all users with their full 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. + +- `__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. + +- `__fish_print_interfaces` prints a list of all known network interfaces. + +- `__fish_print_packages` prints a list of all installed packages. This function currently handles Debian, rpm and Gentoo packages. + + +\subsection completion-path Where to put completions + +Completions can be defined on the commandline or in a configuration file, but they can also be automatically loaded. Fish automatically searches through any directories in the array variable `$fish_complete_path`, and any completions defined are automatically loaded when needed. A completion file must have a filename consisting of the name of the command to complete and the suffix '`.fish`'. + +By default, Fish searches the following for completions, using the first available file that it finds: +- A directory for end-users to keep their own completions, usually `~/.config/fish/completions` (controlled by the `XDG_CONFIG_HOME` environment variable); +- A directory for systems administrators to install completions for all users on the system, usually `/etc/fish/completions`; +- A directory for third-party software vendors to ship their own completions for their software, usually `/usr/share/fish/vendor_completions.d`; +- The completions shipped with fish, usually installed in `/usr/share/fish/completions`; and +- Completions automatically generated from the operating system's manual, usually stored in `~/.local/share/fish/generated_completions`. + +These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above. + +This wide search may be confusing. If you are unsure, your completions probably belong in `~/.config/fish/completions`. + +If you have written new completions for a common Unix command, please consider sharing your work by submitting it via the instructions in Further help and development. + +If you are developing another program and would like to ship completions with your program, install them to the "vendor" completions directory. As this path may vary from system to system, the `pkgconfig` framework should be used to discover this path with the output of `pkg-config --variable completionsdir fish`. + + +\section expand Parameter expansion (Globbing) + +When an argument for a program is given on the commandline, it undergoes the process of parameter expansion before it is sent on to the command. Parameter expansion is a powerful mechanism that allows you to expand the parameter in various ways, including performing wildcard matching on files, inserting the value of a shell variable into the parameter or even using the output of another command as a parameter list. + + +\subsection expand-wildcard Wildcards + +If a star (`*`) or a question mark (`?`) is present in the parameter, `fish` attempts to match the given parameter to any files in such a way that: + +- `?` can match any single character except '/'. + +- `*` can match any string of characters not containing '/'. This includes matching an empty string. + +- `**` matches any string of characters. This includes matching an empty string. The matched string may include the `/` character; that is, it recurses into subdirectories. Note that augmenting this wildcard with other strings will not match files in the current working directory (`$PWD`) if you separate the strings with a slash ("/"). This is unlike other shells such as zsh. For example, `**\/*.fish` in zsh will match `.fish` files in the PWD but in fish will only match such files in a subdirectory. In fish you should type `***.fish` to match files in the PWD as well as subdirectories. + +Other shells, such as zsh, provide a rich glob syntax for restricting the files matched by globs. For example, `**(.)`, to only match regular files. Fish prefers to defer such features to programs, such as `find`, rather than reinventing the wheel. Thus, if you want to limit the wildcard expansion to just regular files the fish approach is to define and use a function. For example, + +\fish{cli-dark} +function ff --description 'Like ** but only returns plain files.' + # This also ignores .git directories. + find . \( -name .git -type d -prune \) -o -type f | \ + sed -n -e '/^\.\/\.git$/n' -e 's/^\.\///p' +end +\endfish + +You would then use it in place of `**` like this, `my_prog (ff)`, to pass only regular files in or below $PWD to `my_prog`. + +Wildcard matches are sorted case insensitively. When sorting matches containing numbers, consecutive digits are considered to be one element, so that the strings '1' '5' and '12' would be sorted in the order given. + +File names beginning with a dot are not considered when wildcarding unless a dot is specifically given as the first character of the file name. + +Examples: + +- `a*` matches any files beginning with an 'a' in the current directory. + +- `???` matches any file in the current directory whose name is exactly three characters long. + +- `**` matches any files and directories in the current directory and all of its subdirectories. + +Note that for most commands, if any wildcard fails to expand, the command is not executed, `$status` is set to nonzero, and a warning is printed. This behavior is consistent with setting `shopt -s failglob` in bash. There are exactly 3 exceptions, namely `set`, `count` and `for`. Their globs are permitted to expand to zero arguments, as with `shopt -s nullglob` in bash. + +Examples: +\fish +ls *.foo +# Lists the .foo files, or warns if there aren't any. + +set foos *.foo +if count $foos >/dev/null + ls $foos +end +# Lists the .foo files, if any. +\endfish + +\subsection expand-command-substitution Command substitution + +The output of a series of commands can be used as the parameters to another command. If a parameter contains a set of parenthesis, the text enclosed by the parenthesis will be interpreted as a list of commands. On expansion, this list is executed, and substituted by the output. If the output is more than one line long, each line will be expanded to a new parameter. Setting `IFS` to the empty string will disable line splitting. + +The exit status of the last run command substitution is available in the status variable if the substitution occurs in the context of a `set` command. + +Only part of the output can be used, see index range expansion for details. + +Fish has a default limit of 10 MiB on the amount of data a command substitution can output. If the limit is exceeded the entire command, not just the substitution, is failed and `$status` is set to 122. You can modify the limit by setting the `fish_read_limit` variable at any time including in the environment before fish starts running. If you set it to zero then no limit is imposed. This is a safety mechanism to keep the shell from consuming too much memory if a command outputs an unreasonable amount of data. Note that this limit also affects how much data the `read` command will process. + +Examples: + +\fish +echo (basename image.jpg .jpg).png +# Outputs 'image.png'. + +for i in *.jpg; convert $i (basename $i .jpg).png; end +# Convert all JPEG files in the current directory to the +# PNG format using the 'convert' program. + +begin; set -l IFS; set data (cat data.txt); end +# Set the `data` variable to the contents of 'data.txt' +# without splitting it into an array. +\endfish + + +\subsection expand-brace Brace expansion + +A comma separated list of characters enclosed in curly braces will be expanded so each element of the list becomes a new parameter. + +Examples: +\fish +echo input.{c,h,txt} +# Outputs 'input.c input.h input.txt' + +mv *.{c,h} src/ +# Moves all files with the suffix '.c' or '.h' to the subdirectory src. +\endfish + +A literal "{}" will not be used as a brace expansion: + +\fish +echo foo-{} +# Outputs foo-{} + +echo foo-{$undefinedvar} +# Output is an empty line - see the cartesian product section +\endfish + +If there is nothing between a brace and a comma or two commas, it's interpreted as an empty element. + +So: +\fish +echo {,,/usr}/bin +# Output /bin /bin /usr/bin +\endfish + +To use a "," as an element, quote or escape it. + +\subsection expand-variable Variable expansion + +A dollar sign followed by a string of characters is expanded into the value of the shell variable with the same name. For an introduction to the concept of shell variables, read the Shell variables section. + +Undefined and empty variables expand to nothing. + +To separate a variable name from text encase the variable within double-quotes or braces. + +Examples: +\fish +echo $HOME +# Prints the home directory of the current user. + +echo $nonexistentvariable +# Prints no output. + +echo The plural of $WORD is "$WORD"s +# Prints "The plural of cat is cats" when $WORD is set to cat. +echo The plural of $WORD is {$WORD}s +# ditto +\endfish + +Note that without the quotes or braces, fish will try to expand a variable called `$WORDs`, which may not exist. + +The latter syntax `{$WORD}` works by exploiting brace expansion. + + +In these cases, the expansion eliminates the string, as a result of the implicit cartesian product. + +If, in the example above, $WORD is undefined or an empty list, the "s" is not printed. However, it is printed, if $WORD is the empty string. + +Unlike all other expanions, variable expansion also happens in double quoted strings. Inside double quotes (`"these"`), variables will always expand to exactly one argument. If they are empty or undefined, it will result in an empty string. If they have one element, they'll expand to that element. If they have more than that, the elements will be joined with spaces. + +Outside of double quotes, variables will expand to as many arguments as they have elements. That means an empty list will expand to nothing, a variable with one element will expand to that element, and a variable with multiple elements will expand to each of those elements separately. + +When two unquoted expansions directly follow each other, you need to watch out for expansions that expand to nothing. This includes undefined variables and empty lists, but also command substitutions with no output. See the cartesian product section for more information. + +The `$` symbol can also be used multiple times, as a kind of "dereference" operator (the `*` in C or C++), like in the following code: + +\fish +set foo a b c +set a 10; set b 20; set c 30 +for i in (seq (count $$foo)) + echo $$foo[$i] +end + +# Output is: +# 10 +# 20 +# 30 +\endfish + +When using this feature together with array brackets, the brackets will always match the innermost `$` dereference. Thus, `$$foo[5]` will always mean the fifth element of the `foo` variable should be dereferenced, not the fifth element of the doubly dereferenced variable `foo`. The latter can instead be expressed as `$$foo[1][5]`. + + +\subsection cartesian-product Cartesian Products + +Lists adjacent to other lists or strings are expanded as cartesian products: + +Examples: +\fish{cli-dark} +>_ echo {good,bad}" apples" +good apples bad apples + +>_ set -l a x y z +>_ set -l b 1 2 3 + +>_ echo $a$b +x1 y1 z1 x2 y2 z2 x3 y3 z3 + +>_ echo $a"-"$b +x-1 y-1 z-1 x-2 y-2 z-2 x-3 y-3 z-3 + +>_ echo {x,y,z}$b +x1 y1 z1 x2 y2 z2 x3 y3 z3 + +>_ echo {$b}word +1word 2word 3word + +>_ echo {$c}word +# Output is an empty line +\endfish + +Be careful when you try to use braces to separate variable names from text. The problem shown above can be avoided by wrapping the variable in double quotes instead of braces (`echo "$c"word`). + +This also happens after command substitution. Therefore strings might be eliminated. This can be avoided by making the inner command return a trailing newline. + +E.g. + +\fish{cli-dark} +>_ echo (printf '%s' '')banana # the printf prints literally nothing +>_ echo (printf '%s\n' '')banana # the printf prints just a newline, so the command substitution expands to an empty string +banana +# After command substitution, the previous line looks like: +>_ echo ""banana +\endfish + +Examples: +\fish{cli-dark} +>_ set b 1 2 3 +>_ echo (echo x)$b +x1 x2 x3 +\endfish + +\subsection expand-index-range Index range expansion + +Both command substitution and shell variable expansion support accessing only specific items by providing a set of indices in square brackets. It's often needed to access a sequence of elements. To do this, use the range operator '`..`' for this. A range '`a..b`', where range limits 'a' and 'b' are integer numbers, is expanded into a sequence of indices '`a a+1 a+2 ... b`' or '`a a-1 a-2 ... b`' depending on which of 'a' or 'b' is higher. The negative range limits are calculated from the end of the array or command substitution. Note that invalid indexes for either end are silently clamped to one or the size of the array as appropriate. + +Range expansion will go in reverse if the end element is earlier in the list than the start and forward if the end is later than the start, unless exactly one of the given indices is negative. This is to enable clamping without changing direction if the list has fewer elements than expected. + +Some examples: + +\fish +# Limit the command substitution output +echo (seq 10)[2..5] +# Uses elements from 2 to 5 +# Output is: 2 3 4 5 + +# Use overlapping ranges: +echo (seq 10)[2..5 1..3] +# Takes elements from 2 to 5 and then elements from 1 to 3 +# Output is: 2 3 4 5 1 2 3 + +# Reverse output +echo (seq 10)[-1..1] +# Uses elements from the last output line to +# the first one in reverse direction +# Output is: 10 9 8 7 6 5 4 3 2 1 + +# The command substitution has only one line, +# so these will result in empty output: +echo (echo one)[2..-1] +echo (echo one)[-3..1] +\endfish + +The same works when setting or expanding variables: + +\fish +# Reverse path variable +set PATH $PATH[-1..1] +# or +set PATH[-1..1] $PATH + +# Use only n last items of the PATH +set n -3 +echo $PATH[$n..-1] +\endfish + +Variables can be used as indices for expansion of variables, like so: +\fish +set index 2 +set letters a b c d +echo $letters[$index] # returns 'b' +\endfish +However using variables as indices for command substitution is currently not supported, so +\fish +echo (seq 5)[$index] # This won't work + +set sequence (seq 5) # It needs to be written on two lines like this. +echo $sequence[$index] # returns '2' +\endfish + +\subsection expand-home Home directory expansion + +The `~` (tilde) character at the beginning of a parameter, followed by a username, is expanded into the home directory of the specified user. A lone `~`, or a `~` followed by a slash, is expanded into the home directory of the process owner. + + +\subsection combine Combining different expansions + +All of the above expansions can be combined. If several expansions result in more than one parameter, all possible combinations are created. + +When combining multiple parameter expansions, expansions are performed in the following order: + +- Command substitutions +- Variable expansions +- Bracket expansion +- Wildcard expansion + +Expansions are performed from right to left, nested bracket expansions are performed from the inside and out. + +Example: + +If the current directory contains the files 'foo' and 'bar', the command `echo a(ls){1,2,3} ` will output 'abar1 abar2 abar3 afoo1 afoo2 afoo3'. + + +\section identifiers Shell variable and function names + +The names given to shell objects such as variables and function names are known as "identifiers". Each type of identifier has rules that define the valid sequence of characters which compose the identifier. + +A variable name cannot be empty. It can contain only letters, digits, and underscores. It may begin and end with any of those characters. + +A function name cannot be empty. It may not begin with a hyphen ("-") and may not contain a slash ("/"). All other characters, including a space, are valid. + +A bind mode name (e.g., `bind -m abc ...`) is restricted to the rules for valid variable names. + + +\section variables Shell variables + +Shell variables are named pieces of data, which can be created, deleted and their values changed and used by the user. Variables may optionally be "exported", so that a copy of the variable is available to any subprocesses the shell creates. An exported variable is referred to as an "environment variable". + +To set a variable value, use the `set` command. A variable name can not be empty and can contain only letters, digits, and underscores. It may begin and end with any of those characters. + +Example: + +To set the variable `smurf_color` to the value `blue`, use the command `set smurf_color blue`. + +After a variable has been set, you can use the value of a variable in the shell through variable expansion. + +Example: + +To use the value of the variable `smurf_color`, write `$` (dollar symbol) followed by the name of the variable, like `echo Smurfs are usually $smurf_color`, which would print the result 'Smurfs are usually blue'. + + +\subsection variables-scope Variable scope + +There are three kinds of variables in fish: universal, global and local variables. Universal variables are shared between all fish sessions a user is running on one computer. Global variables are specific to the current fish session, but are not associated with any specific block scope, and will never be erased unless the user explicitly requests it using `set -e`. Local variables are specific to the current fish session, and associated with a specific block of commands, and is automatically erased when a specific block goes out of scope. A block of commands is a series of commands that begins with one of the commands `for`, `while` , `if`, `function`, `begin` or `switch`, and ends with the command `end`. The user can specify that a variable should have either global or local scope using the `-g/--global` or `-l/--local` switches. + +Variables can be explicitly set to be universal with the `-U` or `--universal` switch, global with the `-g` or `--global` switch, or local with the `-l` or `--local` switch. The scoping rules when creating or updating a variable are: + +-# If a variable is explicitly set to either universal, global or local, that setting will be honored. If a variable of the same name exists in a different scope, that variable will not be changed. + +-# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the variable scope is not changed. + +-# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the `-l` or `--local` flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global. + +There may be many variables with the same name, but different scopes. When using a variable, the variable scope will be searched from the inside out, i.e. a local variable will be used rather than a global variable with the same name, a global variable will be used rather than a universal variable with the same name. + +Example: + +The following code will not output anything: + +\fish +begin + # This is a nice local scope where all variables will die + set -l pirate 'There be treasure in them thar hills' +end + +echo $pirate +# This will not output anything, since the pirate was local +\endfish + + +\subsection variables-universal More on universal variables + +Universal variables are variables that are shared between all the users' fish sessions on the computer. Fish stores many of its configuration options as universal variables. This means that in order to change fish settings, all you have to do is change the variable value once, and it will be automatically updated for all sessions, and preserved across computer reboots and login/logout. + +To see universal variables in action, start two fish sessions side by side, and issue the following command in one of them `set fish_color_cwd blue`. Since `fish_color_cwd` is a universal variable, the color of the current working directory listing in the prompt will instantly change to blue on both terminals. + +Universal variables are stored in the file `.config/fish/fishd.MACHINE_ID`, where MACHINE_ID is typically your MAC address. Do not edit this file directly, as your edits may be overwritten. Edit them through fish scripts or by using fish interactively instead. + +Do not append to universal variables in config.fish, because these variables will then get longer with each new shell instance. Instead, simply set them once at the command line. + + +\subsection variables-functions Variable scope for functions + +When calling a function, all current local variables temporarily disappear. This shadowing of the local scope is needed since the variable namespace would become cluttered, making it very easy to accidentally overwrite variables from another function. + +For example: + +\fish +function shiver + set phrase 'Shiver me timbers' +end + +function avast + set phrase 'Avast, mateys' + # Calling the shiver function here can not + # change any variables in the local scope + shiver + echo $phrase +end +avast + +# Outputs "Avast, mateys" +\endfish + + +\subsection variables-export Exporting variables + +Variables in fish can be exported. This means the variable will be inherited by any commands started by fish. It is convention that exported variables are in uppercase and unexported variables are in lowercase. + +Variables can be explicitly set to be exported with the `-x` or `--export` switch, or not exported with the `-u` or `--unexport` switch. The exporting rules when creating or updating a variable are identical to the scoping rules for variables: + +-# If a variable is explicitly set to either be exported or not exported, that setting will be honored. + +-# If a variable is not explicitly set to be exported or not exported, but has been previously defined, the previous exporting rule for the variable is kept. + +-# If a variable is not explicitly set to be either exported or not exported and has never before been defined, the variable will not be exported. + +-# If a variable has local scope and is exported, any function called receives a _copy_ of it, so any changes it makes to the variable disappear once the function returns. + +-# If a variable has global scope, it is accessible read-write to functions whether it is exported or not. + +\subsection variables-arrays Arrays + +`fish` can store a list of multiple strings inside of a variable. To access one element of an array, use the index of the element inside of square brackets, like this: + +`echo $PATH[3]` + +Note that array indices start at 1 in `fish`, not 0, as is more common in other languages. This is because many common Unix tools like `seq` are more suited to such use. An invalid index is silently ignored resulting in no value being substituted (not an empty string). + +If you do not use any brackets, all the elements of the array will be written as separate items. This means you can easily iterate over an array using this syntax: + +\fish +for i in $PATH; echo $i is in the path; end +\endfish + +To create a variable `smurf`, containing the items `blue` and `small`, simply write: + +\fish +set smurf blue small +\endfish + +It is also possible to set or erase individual elements of an array: + +\fish +# Set smurf to be an array with the elements 'blue' and 'small' +set smurf blue small + +# Change the second element of smurf to 'evil' +set smurf[2] evil + +# Erase the first element +set -e smurf[1] + +# Output 'evil' +echo $smurf +\endfish + +If you specify a negative index when expanding or assigning to an array variable, the index will be calculated from the end of the array. For example, the index -1 means the last index of an array. + +A range of indices can be specified, see index range expansion for details. + +All arrays are one-dimensional and cannot contain other arrays, although it is possible to fake nested arrays using the dereferencing rules of variable expansion. + +When an array is exported as an environment variable, it is either space or colon delimited, depending on whether it is a path variable: +\fish +set -x smurf blue small +set -x smurf_PATH forest mushroom +env | grep smurf + +# smurf=blue small +# smurf_PATH=forest:mushroom + +\endfish + +`fish` automatically creates arrays from all environment variables whose name ends in PATH, by splitting them on colons. Other variables are not automatically split. + +\subsection variables-path PATH variables + +Path variables are a special kind of variable used to support colon-delimited path lists including PATH, CDPATH, MANPATH, PYTHONPATH, etc. All variables that end in `PATH` (case-sensitive) become PATH variables. + +PATH variables act as normal arrays, except they are are implicitly joined and split on colons. +\fish +set MYPATH 1 2 3 +echo "$MYPATH" +# 1:2:3 +set MYPATH "$MYPATH:4:5" +echo $MYPATH +# 1 2 3 4 5 +echo "$MYPATH" +# 1:2:3:4:5 +\endfish + +Variables can be marked or unmarked as PATH variables via the `--path` and `--unpath` options to `set`. + +\subsection variables-special Special variables + +The user can change the settings of `fish` by changing the values of certain variables. + +- A large number of variable starting with the prefixes `fish_color` and `fish_pager_color.` See Variables for changing highlighting colors for more information. + +- `fish_emoji_width` controls the computed width of certain characters, in particular emoji, whose rendered width varies across terminal emulators. This should be set to 1 if your terminal emulator renders emoji single-width, or 2 if double-width. Set this only if you see graphical glitching when printing emoji. + +- `fish_ambiguous_width` controls the computed width of ambiguous East Asian characters. This should be set to 1 if your terminal emulator renders these characters as single-width (typical), or 2 if double-width. + +- `fish_escape_delay_ms` overrides the default timeout of 300ms (default key bindings) or 10ms (vi key bindings) after seeing an escape character before giving up on matching a key binding. See the documentation for the bind builtin command. This delay facilitates using escape as a meta key. + +- `fish_greeting`, the greeting message printed on startup. + +- `fish_history`, the current history session name. If set, all subsequent commands within an + interactive fish session will be logged to a separate file identified by the value of the + variable. If unset, or set to `default`, the default session name "fish" is used. If set to an + empty string, history is not saved to disk (but is still available within the interactive + session). + +- `fish_user_paths`, an array of directories that are prepended to `PATH`. This can be a universal variable. + +- `umask`, the current file creation mask. The preferred way to change the umask variable is through the umask function. An attempt to set umask to an invalid value will always fail. + +- `BROWSER`, the user's preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation. + +- `CDPATH`, an array of directories in which to search for the new directory for the `cd` builtin. + +- `LANG`, `LC_ALL`, `LC_COLLATE`, `LC_CTYPE`, `LC_MESSAGES`, `LC_MONETARY`, `LC_NUMERIC` and `LC_TIME` set the language option for the shell and subprograms. See the section Locale variables for more information. + +- `PATH`, an array of directories in which to search for commands + +`fish` also sends additional information to the user through the values of certain environment variables. The user cannot change the values of most of these variables. + +- `_`, the name of the currently running command. + +- `argv`, an array of arguments to the shell or function. `argv` is only defined when inside a function call, or if fish was invoked with a list of arguments, like `fish myscript.fish foo bar`. This variable can be changed by the user. + +- `history`, an array containing the last commands that were entered. + +- `HOME`, the user's home directory. This variable can be changed by the user. + +- `IFS`, the internal field separator that is used for word splitting with the read builtin. Setting this to the empty string will also disable line splitting in command substitution. This variable can be changed by the user. + +- `PWD`, the current working directory. + +- `status`, the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number. + +- `USER`, the current username. This variable can be changed by the user. + +- `CMD_DURATION`, the runtime of the last command in milliseconds. + +- `version`, the version of the currently running fish (also available as `FISH_VERSION` for backward compatibility). + +- `SHLVL`, the level of nesting of shells + +- `COLUMNS` and `LINES`, the current size of the terminal in height and width. These values are only used by fish if the operating system does not report the size of the terminal. Both variables must be set in that case otherwise a default of 80x24 will be used. They are updated when the window size changes. + +The names of these variables are mostly derived from the csh family of shells and differ from the ones used by Bourne style shells such as bash. + +Variables whose name are in uppercase are generally exported to the commands started by fish, while those in lowercase are not exported (`CMD_DURATION` is an exception, for historical reasons). This rule is not enforced by fish, but it is good coding practice to use casing to distinguish between exported and unexported variables. `fish` also uses several variables internally. Such variables are prefixed with the string `__FISH` or `__fish.` These should never be used by the user. Changing their value may break fish. + +\subsection variables-status The status variable + +Whenever a process exits, an exit status is returned to the program that started it (usually the shell). This exit status is an integer number, which tells the calling application how the execution of the command went. In general, a zero exit status means that the command executed without problem, but a non-zero exit status means there was some form of problem. + +Fish stores the exit status of the last process in the last job to exit in the `status` variable. + +If `fish` encounters a problem while executing a command, the status variable may also be set to a specific value: + +- 0 is generally the exit status of fish commands if they successfully performed the requested operation. + +- 1 is generally the exit status of fish commands if they failed to perform the requested operation. + +- 121 is generally the exit status of fish commands if they were supplied with invalid arguments. + +- 123 means that the command was not executed because the command name contained invalid characters. + +- 124 means that the command was not executed because none of the wildcards in the command produced any matches. + +- 125 means that while an executable with the specified name was located, the operating system could not actually execute the command. + +- 126 means that while a file with the specified name was located, it was not executable. + +- 127 means that no function, builtin or command with the given name could be located. + +If a process exits through a signal, the exit status will be 128 plus the number of the signal. + + +\subsection variables-color Variables for changing highlighting colors + +The colors used by fish for syntax highlighting can be configured by changing the values of a various variables. The value of these variables can be one of the colors accepted by the set_color command. The `--bold` or `-b` switches accepted by `set_color` are also accepted. + +The following variables are available to change the highlighting colors in fish: + +- `fish_color_normal`, the default color + +- `fish_color_command`, the color for commands + +- `fish_color_quote`, the color for quoted blocks of text + +- `fish_color_redirection`, the color for IO redirections + +- `fish_color_end`, the color for process separators like ';' and '&' + +- `fish_color_error`, the color used to highlight potential errors + +- `fish_color_param`, the color for regular command parameters + +- `fish_color_comment`, the color used for code comments + +- `fish_color_match`, the color used to highlight matching parenthesis + +- `fish_color_selection`, the color used when selecting text (in vi visual mode) + +- `fish_color_search_match`, used to highlight history search matches and the selected pager item (must be a background) + +- `fish_color_operator`, the color for parameter expansion operators like '*' and '~' + +- `fish_color_escape`, the color used to highlight character escapes like '\\n' and '\\x70' + +- `fish_color_cwd`, the color used for the current working directory in the default prompt + +- `fish_color_autosuggestion`, the color used for autosuggestions + +- `fish_color_user`, the color used to print the current username in some of fish default prompts + +- `fish_color_host`, the color used to print the current host system in some of fish default prompts + +- `fish_color_cancel`, the color for the '^C' indicator on a canceled command + +Additionally, the following variables are available to change the highlighting in the completion pager: + +- `fish_pager_color_prefix`, the color of the prefix string, i.e. the string that is to be completed + +- `fish_pager_color_completion`, the color of the completion itself + +- `fish_pager_color_description`, the color of the completion description + +- `fish_pager_color_progress`, the color of the progress bar at the bottom left corner + +- `fish_pager_color_secondary`, the background color of the every second completion + +Example: + +To make errors highlighted and red, use: + +\fish +set fish_color_error red --bold +\endfish + + +\subsection variables-locale Locale variables + +The most common way to set the locale to use a command like 'set -x LANG en_GB.utf8', which sets the current locale to be the English language, as used in Great Britain, using the UTF-8 character set. For a list of available locales, use 'locale -a'. + +`LANG`, `LC_ALL`, `LC_COLLATE`, `LC_CTYPE`, `LC_MESSAGES`, `LC_MONETARY`, `LC_NUMERIC` and `LC_TIME` set the language option for the shell and subprograms. These variables work as follows: `LC_ALL` forces all the aspects of the locale to the specified value. If `LC_ALL` is set, all other locale variables will be ignored. The other `LC_` variables set the specified aspect of the locale information. `LANG` is a fallback value, it will be used if none of the `LC_` variables are specified. + + +\section builtin-overview Builtin commands + +Many other shells have a large library of builtin commands. Most of these commands are also available as standalone commands, but have been implemented in the shell anyway. To avoid code duplication, and to avoid the confusion of subtly differing versions of the same command, `fish` generally only implements builtins for actions which cannot be performed by a regular command. + +For a list of all builtins, functions and commands shipped with fish, see the table of contents. The documentation is also available by using the `--help` switch of the command. + + +\section editor Command line editor + +The `fish` editor features copy and paste, a searchable history and many editor functions that can be bound to special keyboard shortcuts. + +Similar to bash, fish has Emacs and Vi editing modes. The default editing mode is Emacs. You can switch to Vi mode with `fish_vi_key_bindings` and switch back with `fish_default_key_bindings`. You can also make your own key bindings by creating a function and setting $fish_key_bindings to its name. For example: + +\fish +function hybrid_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes" + for mode in default insert visual + fish_default_key_bindings -M $mode + end + fish_vi_key_bindings --no-erase +end +set -g fish_key_bindings hybrid_bindings +\endfish + +\subsection shared-binds Shared bindings + +Some bindings are shared between emacs- and vi-mode because they aren't text editing bindings or because what Vi/Vim does for a particular key doesn't make sense for a shell. + +- @key{Tab} completes the current token. @key{Shift, Tab} completes the current token and starts the pager's search mode. + +- @key{Alt,←,Left} and @key{Alt,→,Right} move the cursor one word left or right, or moves forward/backward in the directory history if the command line is empty. If the cursor is already at the end of the line, and an autosuggestion is available, @key{Alt,→,Right} (or @key{Alt,F}) accepts the first word in the suggestion. + +- @cursor_key{↑,Up} and @cursor_key{↓,Down} (or @key{Control,P} and @key{Control,N} for emacs aficionados) search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the history section for more information on history searching. + +- @key{Alt,↑,Up} and @key{Alt,↓,Down} search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline was not on a token when the search started, all tokens match. See the history section for more information on history searching. + +- @key{Control,C} cancels the entire line. + +- @key{Control,D} delete one character to the right of the cursor. If the command line is empty, @key{Control,D} will exit fish. + +- @key{Control,U} moves contents from the beginning of line to the cursor to the killring. + +- @key{Control,L} clears and repaints the screen. + +- @key{Control,W} moves the previous path component (everything up to the previous "/") to the killring. + +- @key{Control,X} copies the current buffer to the system's clipboard, @key{Control,V} inserts the clipboard contents. + +- @key{Alt,d} moves the next word to the killring. + +- @key{Alt,h} (or @key{F1}) shows the manual page for the current command, if one exists. + +- @key{Alt,l} lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed. + +- @key{Alt,p} adds the string '`| less;`' to the end of the job under the cursor. The result is that the output of the command will be paged. + +- @key{Alt,w} prints a short description of the command under the cursor. + +- @key{Alt,e} edit the current command line in an external editor. The editor is chosen from the first available of the `$VISUAL` or `$EDITOR` variables. + +- @key{Alt,v} Same as @key{Alt,e}. + +\subsection emacs-mode Emacs mode commands + +- @key{Home} or @key{Control,A} moves the cursor to the beginning of the line. + +- @key{End} or @key{Control,E} moves to the end of line. If the cursor is already at the end of the line, and an autosuggestion is available, @key{End} or @key{Control,E} accepts the autosuggestion. + +- @cursor_key{←,Left} (or @key{Control,B}) and @cursor_key{→,Right} (or @key{Control,F}) move the cursor left or right by one character. If the cursor is already at the end of the line, and an autosuggestion is available, the @cursor_key{→,Right} key and the @key{Control,F} combination accept the suggestion. + +- @key{Delete} and @key{Backspace} removes one character forwards or backwards respectively. + +- @key{Control,K} moves contents from the cursor to the end of line to the killring. + +- @key{Alt,c} capitalizes the current word. + +- @key{Alt,u} makes the current word uppercase. + +- @key{Control,t} transposes the last two characters + +- @key{Alt,t} transposes the last two words + + +You can change these key bindings using the bind builtin command. + + +\subsection vi-mode Vi mode commands + +Vi mode allows for the use of Vi-like commands at the prompt. Initially, insert mode is active. @key{Escape} enters command mode. The commands available in command, insert and visual mode are described below. Vi mode shares some bindings with Emacs mode. + +It is also possible to add all emacs-mode bindings to vi-mode by using something like + +\fish +function fish_user_key_bindings + # Execute this once per mode that emacs bindings should be used in + fish_default_key_bindings -M insert + # Without an argument, fish_vi_key_bindings will default to + # resetting all bindings. + # The argument specifies the initial mode (insert, "default" or visual). + fish_vi_key_bindings insert +end +\endfish + +When in vi-mode, the `fish_mode_prompt` function will display a mode indicator to the left of the prompt. The `fish_vi_cursor` function will be used to change the cursor's shape depending on the mode in supported terminals. To disable this feature, override it with an empty function. To display the mode elsewhere (like in your right prompt), use the output of the `fish_default_mode_prompt` function. + +\subsubsection vi-mode-command Command mode + +Command mode is also known as normal mode. + +- @key{h} moves the cursor left. + +- @key{l} moves the cursor right. + +- @key{i} enters insert mode at the current cursor position. + +- @key{v} enters visual mode at the current cursor position. + +- @key{a} enters insert mode after the current cursor position. + +- @key{Shift,A} enters insert mode at the end of the line. + +- @key{0} (zero) moves the cursor to beginning of line (remaining in command mode). + +- @key{d}@key{d} deletes the current line and moves it to the killring. + +- @key{Shift,D} deletes text after the current cursor position and moves it to the killring. + +- @key{p} pastes text from the killring. + +- @key{u} search history backwards. + +- @key{[} and @key{]} search the command history for the previous/next token containing the token under the cursor before the search was started. See the history section for more information on history searching. + +- @key{Backspace} moves the cursor left. + +\subsubsection vi-mode-insert Insert mode + +- @key{Escape} enters command mode. + +- @key{Backspace} removes one character to the left. + +\subsubsection vi-mode-visual Visual mode + +- @cursor_key{←,Left} and @cursor_key{→,Right} extend the selection backward/forward by one character. + +- @key{b} and @key{w} extend the selection backward/forward by one word. + +- @key{d} and @key{x} move the selection to the killring and enter command mode. + +- @key{Escape} and @key{Control,C} enter command mode. + +\subsection killring Copy and paste (Kill Ring) + +`fish` uses an Emacs style kill ring for copy and paste functionality. Use @key{Control,K} to cut from the current cursor position to the end of the line. The string that is cut (a.k.a. killed) is inserted into a linked list of kills, called the kill ring. To paste the latest value from the kill ring use @key{Control,Y}. After pasting, use @key{Alt,Y} to rotate to the previous kill. + +Copy and paste from outside are also supported, both via the @key{Control,X} / @key{Control,V} bindings and via the terminal's paste function, for which fish enables "Bracketed Paste Mode". When pasting inside single quotes, pasted single quotes and backslashes are automatically escaped so that the result can be used as a single token simply by closing the quote after. + +\subsection history-search Searchable history + +After a command has been entered, it is inserted at the end of a history list. Any duplicate history items are automatically removed. By pressing the up and down keys, the user can search forwards and backwards in the history. If the current command line is not empty when starting a history search, only the commands containing the string entered into the command line are shown. + +By pressing @key{Alt,↑,Up} and @key{Alt,↓,Down}, a history search is also performed, but instead of searching for a complete commandline, each commandline is broken into separate elements just like it would be before execution, and the history is searched for an element matching that under the cursor. + +History searches can be aborted by pressing the escape key. + +Prefixing the commandline with a space will prevent the entire line from being stored in the history. + +The command history is stored in the file `~/.local/share/fish/fish_history` (or +`$XDG_DATA_HOME/fish/fish_history` if that variable is set) by default. However, you can set the +`fish_history` environment variable to change the name of the history session (resulting in a +`_history` file); both before starting the shell and while the shell is running. + +Examples: + +To search for previous entries containing the word 'make', type `make` in the console and press the up key. + +If the commandline reads `cd m`, place the cursor over the `m` character and press @key{Alt,↑,Up} to search for previously typed words containing 'm'. + + +\subsection multiline Multiline editing + +The fish commandline editor can be used to work on commands that are several lines long. There are three ways to make a command span more than a single line: + +- Pressing the @key{Enter} key while a block of commands is unclosed, such as when one or more block commands such as `for`, `begin` or `if` do not have a corresponding `end` command. + +- Pressing @key{Alt,Enter} instead of pressing the @key{Enter} key. + +- By inserting a backslash (`\`) character before pressing the @key{Enter} key, escaping the newline. + +The fish commandline editor works exactly the same in single line mode and in multiline mode. To move between lines use the left and right arrow keys and other such keyboard shortcuts. + + +\section job-control Running multiple programs + +Normally when `fish` starts a program, this program will be put in the foreground, meaning it will take control of the terminal and `fish` will be stopped until the program finishes. Sometimes this is not desirable. For example, you may wish to start an application with a graphical user interface from the terminal, and then be able to continue using the shell. In such cases, there are several ways in which the user can change fish's behavior. + +-# By ending a command with the `&` (ampersand) symbol, the user tells `fish` to put the specified command into the background. A background process will be run simultaneous with `fish`. `fish` will retain control of the terminal, so the program will not be able to read from the keyboard. + +-# By pressing @key{Control,Z}, the user stops a currently running foreground program and returns control to `fish`. Some programs do not support this feature, or remap it to another key. GNU Emacs uses @key{Control,X} @key{z} to stop running. + +-# By using the `fg` and `bg` builtin commands, the user can send any currently running job into the foreground or background. + +Note that functions cannot be started in the background. Functions that are stopped and then restarted in the background using the `bg` command will not execute correctly. + + +\section initialization Initialization files + +On startup, Fish evaluates a number of configuration files, which can be used to control the behavior of the shell. The location of these configuration variables is controlled by a number of environment variables, and their default or usual location is given below. + +Configuration files are evaluated in the following order: +- Configuration shipped with fish, which should not be edited, in `$__fish_data_dir/config.fish` (usually `/usr/share/fish/config.fish`). +- System-wide configuration files, where administrators can include initialization that should be run for all users on the system - similar to `/etc/profile` for POSIX-style shells - in `$__fish_sysconf_dir` (usually `/etc/fish/config.fish`); +- Configuration snippets in files ending in `.fish`, in the directories: + - `$__fish_config_dir/conf.d` (by default, `~/.config/fish/conf.d/`) + - `$__fish_sysconf_dir/conf.d` (by default, `/etc/fish/conf.d`) + - `/usr/share/fish/vendor_conf.d` (set at compile time; by default, `$__fish_data_dir/conf.d`) + + If there are multiple files with the same name in these directories, only the first will be executed. + They are executed in order of their filename, sorted (like globs) in a natural order (i.e. "01" sorts before "2"). + +- User initialization, usually in `~/.config/fish/config.fish` (controlled by the `XDG_CONFIG_HOME` environment variable, and accessible as `$__fish_config_dir`). + +These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above. + +This wide search may be confusing. If you are unsure where to put your own customisations, use `~/.config/fish/config.fish`. + +Note that ~/.config/fish/config.fish is sourced _after_ the snippets. This is so users can copy snippets and override some of their behavior. + +These files are all executed on the startup of every shell. If you want to run a command only on starting an interactive shell, use the exit status of the command `status --is-interactive` to determine if the shell is interactive. If you want to run a command only when using a login shell, use `status --is-login` instead. This will speed up the starting of non-interactive or non-login shells. + +If you are developing another program, you may wish to install configuration which is run for all users of the fish shell on a system. This is discouraged; if not carefully written, they may have side-effects or slow the startup of the shell. Additionally, users of other shells will not benefit from the Fish-specific configuration. However, if they are absolutely required, you may install them to the "vendor" configuration directory. As this path may vary from system to system, the `pkgconfig` framework should be used to discover this path with the output of `pkg-config --variable confdir fish`. + +Examples: + +If you want to add the directory `~/linux/bin` to your PATH variable when using a login shell, add the following to your `~/.config/fish/config.fish` file: + +\fish +if status --is-login + set -x PATH $PATH ~/linux/bin +end +\endfish + +If you want to run a set of commands when `fish` exits, use an event handler that is triggered by the exit of the shell: + +\fish +function on_exit --on-event fish_exit + echo fish is now exiting +end +\endfish + +\section featureflags Future feature flags + +Feature flags are how fish stages changes that might break scripts. Breaking changes are introduced as opt-in, in a few releases they become opt-out, and eventually the old behavior is removed. + +You can see the current list of features via `status features`: + +\fish +> status features +stderr-nocaret on 3.0 ^ no longer redirects stderr +qmark-noglob off 3.0 ? no longer globs +\endfish + +There are two breaking changes in fish 3.0: caret `^` no longer redirects stderr, and question mark `?` is no longer a glob. These changes are off by default. They can be enabled on a per session basis: + +\fish +> fish --features qmark-noglob,stderr-nocaret +\endfish + +or opted into globally for a user: + +\fish +> set -U fish_features stderr-nocaret qmark-noglob +\endfish + +\section other Other features + + +\subsection color Syntax highlighting + +`fish` interprets the command line as it is typed and uses syntax highlighting to provide feedback to the user. The most important feedback is the detection of potential errors. By default, errors are marked red. + +Detected errors include: + +- Non existing commands. +- Reading from or appending to a non existing file. +- Incorrect use of output redirects +- Mismatched parenthesis + + +When the cursor is over a parenthesis or a quote, `fish` also highlights its matching quote or parenthesis. + +To customize the syntax highlighting, you can set the environment variables listed in the Variables for changing highlighting colors section. + +\subsection title Programmable title + +When using most virtual terminals, it is possible to set the message displayed in the titlebar of the terminal window. This can be done automatically in fish by defining the `fish_title` function. The `fish_title` function is executed before and after a new command is executed or put into the foreground and the output is used as a titlebar message. The `status current-command` builtin will always return the name of the job to be put into the foreground (or 'fish' if control is returning to the shell) when the `fish_prompt` function is called. The first argument to fish_title will contain the most recently executed foreground command as a string, starting with fish 2.2. + +Examples: +The default `fish` title is + +\fish +function fish_title + echo (status current-command) ' ' + pwd +end +\endfish + +To show the last command in the title: + +\fish +function fish_title + echo $argv[1] +end +\endfish + +\subsection prompt Programmable prompt + +When fish waits for input, it will display a prompt by evaluating the `fish_prompt` and `fish_right_prompt` functions. The output of the former is displayed on the left and the latter's output on the right side of the terminal. The output of `fish_mode_prompt` will be prepended on the left, though the default function only does this when in vi-mode. + +\subsection greeting Configurable greeting + +If a function named `fish_greeting` exists, it will be run when entering interactive mode. Otherwise, if an environment variable named `fish_greeting` exists, it will be printed. + +\subsection private-mode Private mode + +fish supports launching in private mode via `fish --private` (or `fish -P` for short). In private mode, old history is not available and any interactive commands you execute will not be appended to the global history file, making it useful both for avoiding inadvertently leaking personal information (e.g. for screencasts) and when dealing with sensitive information to prevent it being persisted to disk. You can query the global variable `fish_private_mode` (`if set -q fish_private_mode ...`) if you would like to respect the user's wish for privacy and alter the behavior of your own fish scripts. + +\subsection event Event handlers + +When defining a new function in fish, it is possible to make it into an event handler, i.e. a function that is automatically run when a specific event takes place. Events that can trigger a handler currently are: + +- When a signal is delivered +- When a process or job exits +- When the value of a variable is updated +- When the prompt is about to be shown +- When a command lookup fails + +Example: + +To specify a signal handler for the WINCH signal, write: + +\fish +function my_signal_handler --on-signal WINCH + echo Got WINCH signal! +end +\endfish + +Please note that event handlers only become active when a function is loaded, which means you might need to otherwise source or execute a function instead of relying on autoloading. One approach is to put it into your initialization file. + +For more information on how to define new event handlers, see the documentation for the function command. + + +\subsection debugging Debugging fish scripts + +Fish includes a built in debugging facility. The debugger allows you to stop execution of a script at an arbitrary point. When this happens you are presented with an interactive prompt. At this prompt you can execute any fish command (there are no debug commands as such). For example, you can check or change the value of any variables using `printf` and `set`. As another example, you can run `status print-stack-trace` to see how this breakpoint was reached. To resume normal execution of the script, simply type `exit` or [ctrl-D]. + +To start a debug session simply run the builtin command `breakpoint` at the point in a function or script where you wish to gain control. Also, the default action of the TRAP signal is to call this builtin. So a running script can be debugged by sending it the TRAP signal with the `kill` command. Once in the debugger, it is easy to insert new breakpoints by using the funced function to edit the definition of a function. + +Note: At the moment the debug prompt is identical to your normal fish prompt. This can make it hard to recognize that you've entered a debug session. Issue 1310 is open to improve this. + + +\section more-help Further help and development + +If you have a question not answered by this documentation, there are several avenues for help: + +-# The official mailing list at fish-users@lists.sourceforge.net + +-# The Internet Relay Chat channel, \#fish on `irc.oftc.net` + +-# The project GitHub page + + +If you have an improvement for fish, you can submit it via the mailing list or the GitHub page. + +\htmlonly[block] +
+\endhtmlonly +*/ From cb045d5e6afbeef1bc831d3bf4d48f16f3ff9240 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 15 Dec 2018 18:45:16 -0800 Subject: [PATCH 103/191] Migrate index.rst to reStructuredText --- sphinx_doc_src/index.rst | 1529 ++++++++++++++++++++------------------ 1 file changed, 814 insertions(+), 715 deletions(-) diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index a0e326e89..145fbcf8a 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -1,130 +1,121 @@ -/** -\mainpage Documentation -\htmlonly[block] -
- - -
-
-

Documentation

-\endhtmlonly +Introduction +============ +This is the documentation for ``fish``, the friendly interactive shell. fish is a user friendly commandline shell intended mostly for interactive use. A shell is a program used to execute other programs. For the latest information on fish, please visit the `fish homepage `_. -\section introduction Introduction +.. _syntax: -This is the documentation for `fish`, the friendly interactive shell. `fish` is a user friendly commandline shell intended mostly for interactive use. A shell is a program used to execute other programs. For the latest information on `fish`, please visit the `fish` homepage. +Syntax overview +=============== - -\section syntax Syntax overview - -Shells like fish are used by giving them commands. Every `fish` command follows the same simple syntax. +Shells like fish are used by giving them commands. Every ``fish`` command follows the same simple syntax. A command is executed by writing the name of the command followed by any arguments. -Example: +Example:: -\fish -echo hello world -\endfish + echo hello world -This calls the `echo` command. `echo` is a command which will write its arguments to the screen. In the example above, the output will be 'hello world'. Everything in fish is done with commands. There are commands for performing a set of commands multiple times, commands for assigning variables, commands for treating a group of commands as a single command, etc.. And every single command follows the same simple syntax. +This calls the ``echo`` command. ``echo`` is a command which will write its arguments to the screen. In the example above, the output will be 'hello world'. Everything in fish is done with commands. There are commands for performing a set of commands multiple times, commands for assigning variables, commands for treating a group of commands as a single command, etc.. And every single command follows the same simple syntax. -If you want to find out more about the echo command used above, read the manual page for the echo command by writing: `man echo` +If you want to find out more about the echo command used above, read the manual page for the echo command by writing: ``man echo`` -`man` is a command for displaying a manual page on a given topic. The man command takes the name of the manual page to display as an argument. There are manual pages for almost every command on most computers. There are also manual pages for many other things, such as system libraries and important files. +``man`` is a command for displaying a manual page on a given topic. The man command takes the name of the manual page to display as an argument. There are manual pages for almost every command on most computers. There are also manual pages for many other things, such as system libraries and important files. -Every program on your computer can be used as a command in `fish`. If the program file is located in one of the directories in the `PATH`, it is sufficient to type the name of the program to use it. Otherwise the whole filename, including the directory (like `/home/me/code/checkers/checkers` or `../checkers`) has to be used. +Every program on your computer can be used as a command in ``fish``. If the program file is located in one of the directories in the PATH_, it is sufficient to type the name of the program to use it. Otherwise the whole filename, including the directory (like ``/home/me/code/checkers/checkers`` or ``../checkers``) has to be used. Here is a list of some useful commands: -- `cd`, change the current directory -- `ls`, list files and directories -- `man`, display a manual page on the screen -- `mv`, move (rename) files -- `cp`, copy files -- `open`, open files with the default application associated with each filetype -- `less`, list the contents of files +- ``cd``, change the current directory +- ``ls``, list files and directories +- ``man``, display a manual page on the screen +- ``mv``, move (rename) files +- ``cp``, copy files +- ``open``, open files with the default application associated with each filetype +- ``less``, list the contents of files -Commands and parameters are separated by the space character ' '. Every command ends with either a newline (i.e. by pressing the return key) or a semicolon '`;`'. More than one command can be written on the same line by separating them with semicolons. +Commands and parameters are separated by the space character ' '. Every command ends with either a newline (i.e. by pressing the return key) or a semicolon '``;``'. More than one command can be written on the same line by separating them with semicolons. -A switch is a very common special type of argument. Switches almost always start with one or more hyphens '`-`' and alter the way a command operates. For example, the '`ls`' command usually lists all the files and directories in the current working directory, but by using the '`-l`' switch, the behavior of '`ls`' is changed to not only display the filename, but also the size, permissions, owner and modification time of each file. +A switch is a very common special type of argument. Switches almost always start with one or more hyphens '``-``' and alter the way a command operates. For example, the '``ls``' command usually lists all the files and directories in the current working directory, but by using the '``-l``' switch, the behavior of '``ls``' is changed to not only display the filename, but also the size, permissions, owner and modification time of each file. -Switches differ between commands and are documented in the manual page for each command. Some switches are common to most command though, for example '`--help`' will usually display a help text, '`-i`' will often turn on interactive prompting before taking action, while '`-f`' will turn it off. +Switches differ between commands and are documented in the manual page for each command. Some switches are common to most command though, for example '``--help``' will usually display a help text, '``-i``' will often turn on interactive prompting before taking action, while '``-f``' will turn it off. -\subsection quotes Quotes +Quotes +------ -Sometimes features such as parameter expansion and character escapes get in the way. When that happens, the user can write a parameter within quotes, either `'` (single quote) or `"` (double quote). There is one important difference between single quoted and double quoted strings: When using double quoted string, variable expansion still takes place. Other than that, no other kind of expansion (including brace expansion and parameter expansion) will take place, the parameter may contain spaces, and escape sequences are ignored. The only backslash escape accepted within single quotes is `\'`, which escapes a single quote and `\\`, which escapes the backslash symbol. The only backslash escapes accepted within double quotes are `\"`, which escapes a double quote, `\$`, which escapes a dollar character, `\` followed by a newline, which deletes the backslash and the newline, and lastly `\\`, which escapes the backslash symbol. Single quotes have no special meaning within double quotes and vice versa. +Sometimes features such as `parameter expansion <#expand>`_ and `character escapes <#escapes>`_ get in the way. When that happens, the user can write a parameter within quotes, either ``'`` (single quote) or ``"`` (double quote). There is one important difference between single quoted and double quoted strings: When using double quoted string, `variable expansion <#expand-variable>`_ still takes place. Other than that, no other kind of expansion (including `brace expansion <#expand-brace>`_ and parameter expansion) will take place, the parameter may contain spaces, and escape sequences are ignored. The only backslash escape accepted within single quotes is ``\'``, which escapes a single quote and ``\\``, which escapes the backslash symbol. The only backslash escapes accepted within double quotes are ``\"``, which escapes a double quote, ``\$``, which escapes a dollar character, ``\`` followed by a newline, which deletes the backslash and the newline, and lastly ``\\``, which escapes the backslash symbol. Single quotes have no special meaning within double quotes and vice versa. -Example: +Example:: -\fish -rm "cumbersome filename.txt" -\endfish + rm "cumbersome filename.txt" Will remove the file 'cumbersome filename.txt', while -\fish -rm cumbersome filename.txt -\endfish +:: + + rm cumbersome filename.txt + would remove the two files 'cumbersome' and 'filename.txt'. -\subsection escapes Escaping characters +.. _escapes: + +Escaping characters +------------------- Some characters can not be written directly on the command line. For these characters, so called escape sequences are provided. These are: -- '\\a' represents the alert character -- '\\b' represents the backspace character -- '\\e' represents the escape character -- '\\f' represents the form feed character -- '\\n' represents a newline character -- '\\r' represents the carriage return character -- '\\t' represents the tab character -- '\\v' represents the vertical tab character -- '\\ ' escapes the space character -- '\\$' escapes the dollar character -- '\\\\' escapes the backslash character -- '\\*' escapes the star character -- '\\?' escapes the question mark character -- '\\~' escapes the tilde character -- '\\#' escapes the hash character -- '\\(' escapes the left parenthesis character -- '\\)' escapes the right parenthesis character -- '\\{' escapes the left curly bracket character -- '\\}' escapes the right curly bracket character -- '\\[' escapes the left bracket character -- '\\]' escapes the right bracket character -- '\\\<' escapes the less than character -- '\\\>' escapes the more than character -- '\\^' escapes the circumflex character -- '\\&' escapes the ampersand character -- '\\|' escapes the vertical bar character -- '\\;' escapes the semicolon character -- '\\"' escapes the quote character -- '\\'' escapes the apostrophe character +- ``\a`` represents the alert character +- ``\b`` represents the backspace character +- ``\e`` represents the escape character +- ``\f`` represents the form feed character +- ``\n`` represents a newline character +- ``\r`` represents the carriage return character +- ``\t`` represents the tab character +- ``\v`` represents the vertical tab character +- ``\\ `` escapes the space character +- ``\$`` escapes the dollar character +- ``\\`` escapes the backslash character +- ``\*`` escapes the star character +- ``\?`` escapes the question mark character +- ``\~`` escapes the tilde character +- ``\#`` escapes the hash character +- ``\(`` escapes the left parenthesis character +- ``\)`` escapes the right parenthesis character +- ``\{`` escapes the left curly bracket character +- ``\}`` escapes the right curly bracket character +- ``\[`` escapes the left bracket character +- ``\]`` escapes the right bracket character +- ``\\<`` escapes the less than character +- ``\\>`` escapes the more than character +- ``\^`` escapes the circumflex character +- ``\&`` escapes the ampersand character +- ``\|`` escapes the vertical bar character +- ``\;`` escapes the semicolon character +- ``\"`` escapes the quote character +- ``\'`` escapes the apostrophe character -- '\\xxx', where xx is a hexadecimal number, represents the ascii character with the specified value. For example, `\x9` is the tab character. +- ``\xHH``, where *HH* is a hexadecimal number, represents the ascii character with the specified value. For example, ``\x9`` is the tab character. -- '\\Xxx', where xx is a hexadecimal number, represents a byte of data with the specified value. If you are using a multibyte encoding, this can be used to enter -invalid strings. Only use this if you know what you are doing. +- ``\XHH``, where *HH* is a hexadecimal number, represents a byte of data with the specified value. If you are using a multibyte encoding, this can be used to enter invalid strings. Only use this if you know what you are doing. -- '\\ooo', where ooo is an octal number, represents the ascii character with the specified value. For example, `\011` is the tab character. +- ``\ooo``, where *ooo* is an octal number, represents the ascii character with the specified value. For example, ``\011`` is the tab character. -- '\\uxxxx', where xxxx is a hexadecimal number, represents the 16-bit Unicode character with the specified value. For example, `\u9` is the tab character. +- ``\uXXXX``, where *XXXX* is a hexadecimal number, represents the 16-bit Unicode character with the specified value. For example, ``\u9`` is the tab character. -- '\\Uxxxxxxxx', where xxxxxxxx is a hexadecimal number, represents the 32-bit Unicode character with the specified value. For example, `\U9` is the tab character. +- ``\UXXXXXXXX``, where *XXXXXXXX* is a hexadecimal number, represents the 32-bit Unicode character with the specified value. For example, ``\U9`` is the tab character. -- '\\cx', where x is a letter of the alphabet, represents the control sequence generated by pressing the control key and the specified letter. For example, `\ci` is the tab character +- ``\cX``, where *X* is a letter of the alphabet, represents the control sequence generated by pressing the control key and the specified letter. For example, ``\ci`` is the tab character -\subsection redirects Input/Output (IO) redirection +.. _redirects: + +Input/Output (IO) Redirection +----------------------------- Most programs use three input/output (IO) streams, each represented by a number called a file descriptor (FD). These are: @@ -138,191 +129,207 @@ The reason for providing for two output file descriptors is to allow separation Any file descriptor can be directed to a different output than its default through a simple mechanism called a redirection. -An example of a file redirection is `echo hello > output.txt`, which directs the output of the echo command to the file output.txt. +An example of a file redirection is ``echo hello > output.txt``, which directs the output of the echo command to the file output.txt. -- To read standard input from a file, write `DESTINATION` -- To write standard error to a file, write `2>DESTINATION` -- To append standard output to a file, write `>>DESTINATION_FILE` -- To append standard error to a file, write `2>>DESTINATION_FILE` +- To read standard input from a file, write ``DESTINATION`` +- To write standard error to a file, write ``2>DESTINATION`` +- To append standard output to a file, write ``>>DESTINATION_FILE`` +- To append standard error to a file, write ``2>>DESTINATION_FILE`` +- To not overwrite ("clobber") an existing file, write ``>?DESTINATION`` or ``2>?DESTINATION`` -- To not overwrite ("clobber") an existing file, write '>?DESTINATION' or '2>?DESTINATION' - -`DESTINATION` can be one of the following: +``DESTINATION`` can be one of the following: - A filename. The output will be written to the specified file. -- An ampersand (`&`) followed by the number of another file descriptor. The output will be written to that file descriptor instead. +- An ampersand (``&``) followed by the number of another file descriptor. The output will be written to that file descriptor instead. -- An ampersand followed by a minus sign (`&-`). The file descriptor will be closed. +- An ampersand followed by a minus sign (``&-``). The file descriptor will be closed. Example: -To redirect both standard output and standard error to the file 'all_output.txt', you can write `echo Hello > all_output.txt 2>&1`. +To redirect both standard output and standard error to the file 'all_output.txt', you can write ``echo Hello > all_output.txt 2>&1``. Any file descriptor can be redirected in an arbitrary way by prefixing the redirection with the file descriptor. -- To redirect input of FD N, write `NDESTINATION` -- To append the output of FD N to a file, write `N>>DESTINATION_FILE` +- To redirect input of FD N, write ``NDESTINATION`` +- To append the output of FD N to a file, write ``N>>DESTINATION_FILE`` -Example: `echo Hello 2>output.stderr` and `echo Hello 2>output.stderr` are equivalent, and write the standard error (file descriptor 2) of the target program to `output.stderr`. +Example: ``echo Hello 2>output.stderr`` and ``echo Hello 2>output.stderr`` are equivalent, and write the standard error (file descriptor 2) of the target program to ``output.stderr``. -\subsection piping Piping +Piping +------ -The user can string together multiple commands into a so called pipeline. This means that the standard output of one command will be read in as standard input into the next command. This is done by separating the commands by the pipe character '`|`'. For example +The user can string together multiple commands into a so called pipeline. This means that the standard output of one command will be read in as standard input into the next command. This is done by separating the commands by the pipe character '``|``'. For example -\fish -cat foo.txt | head -\endfish +:: -will call the `cat` program with the parameter 'foo.txt', which will print the contents of the file 'foo.txt'. The contents of foo.txt will then be filtered through the program 'head', which will pass on the first ten lines of the file to the screen. For more information on how to combine commands through pipes, read the manual pages of the commands you want to use using the `man` command. If you want to find out more about the `cat` program, type `man cat`. + cat foo.txt | head -Pipes usually connect file descriptor 1 (standard output) of the first process to file descriptor 0 (standard input) of the second process. It is possible to use a different output file descriptor by prepending the desired FD number and then output redirect symbol to the pipe. For example: +will call the ``cat`` program with the parameter 'foo.txt', which will print the contents of the file 'foo.txt'. The contents of foo.txt will then be filtered through the program 'head', which will pass on the first ten lines of the file to the screen. For more information on how to combine commands through pipes, read the manual pages of the commands you want to use using the ``man`` command. If you want to find out more about the ``cat`` program, type ``man cat``. + +Pipes usually connect file descriptor 1 (standard output) of the first process to file descriptor 0 (standard input) of the second process. It is possible to use a different output file descriptor by prepending the desired FD number and then output redirect symbol to the pipe. For example:: + + make fish 2>| less -\fish -make fish 2>| less -\endfish will attempt to build the fish program, and any errors will be shown using the less pager. -\subsection syntax-background Background jobs +.. _syntax-background: -When you start a job in `fish`, `fish` itself will pause, and give control of the terminal to the program just started. Sometimes, you want to continue using the commandline, and have the job run in the background. To create a background job, append an \& (ampersand) to your command. This will tell fish to run the job in the background. Background jobs are very useful when running programs that have a graphical user interface. +Background jobs +--------------- -Example: +When you start a job in ``fish``, ``fish`` itself will pause, and give control of the terminal to the program just started. Sometimes, you want to continue using the commandline, and have the job run in the background. To create a background job, append an \& (ampersand) to your command. This will tell fish to run the job in the background. Background jobs are very useful when running programs that have a graphical user interface. + +Example:: + + emacs & -\fish -emacs & -\endfish will start the emacs text editor in the background. -\subsection syntax-job-control Job control +.. _syntax-job-control: -Most programs allow you to suspend the program's execution and return control to `fish` by pressing @key{Control,Z} (also referred to as `^Z`). Once back at the `fish` commandline, you can start other programs and do anything you want. If you then want you can go back to the suspended command by using the `fg` (foreground) command. +Job control +----------- -If you instead want to put a suspended job into the background, use the `bg` command. +Most programs allow you to suspend the program's execution and return control to ``fish`` by pressing @key{Control,Z} (also referred to as ``^Z``). Once back at the ``fish`` commandline, you can start other programs and do anything you want. If you then want you can go back to the suspended command by using the ``fg`` (foreground) command. -To get a listing of all currently started jobs, use the `jobs` command. +If you instead want to put a suspended job into the background, use the ``bg`` command. + +To get a listing of all currently started jobs, use the ``jobs`` command. -\subsection syntax-function Functions +.. _syntax-function: + +Functions +--------- Functions are programs written in the fish syntax. They group together one or more commands and their arguments using a single name. It can also be used to start a specific command with additional arguments. -For example, the following is a function definition that calls the command `ls` with the argument '`-l`' to print a detailed listing of the contents of the current directory: +For example, the following is a function definition that calls the command ``ls`` with the argument '``-l``' to print a detailed listing of the contents of the current directory:: -\fish -function ll - ls -l $argv -end -\endfish + function ll + ls -l $argv + end -The first line tells fish that a function by the name of `ll` is to be defined. To use it, simply write `ll` on the commandline. The second line tells fish that the command `ls -l $argv` should be called when `ll` is invoked. '`$argv`' is an array variable, which always contains all arguments sent to the function. In the example above, these are simply passed on to the `ls` command. For more information on functions, see the documentation for the function builtin. +The first line tells fish that a function by the name of ``ll`` is to be defined. To use it, simply write ``ll`` on the commandline. The second line tells fish that the command ``ls -l $argv`` should be called when ``ll`` is invoked. '``$argv``' is an array variable, which always contains all arguments sent to the function. In the example above, these are simply passed on to the ``ls`` command. For more information on functions, see the documentation for the function builtin. +.. _syntax-function-wrappers: -\subsubsection syntax-function-wrappers Defining aliases +Defining aliases +---------------- -One of the most common uses for functions is to slightly alter the behavior of an already existing command. For example, one might want to redefine the `ls` command to display colors. The switch for turning on colors on GNU systems is '`--color=auto`'. An alias, or wrapper, around `ls` might look like this: +One of the most common uses for functions is to slightly alter the behavior of an already existing command. For example, one might want to redefine the ``ls`` command to display colors. The switch for turning on colors on GNU systems is '``--color=auto``'. An alias, or wrapper, around ``ls`` might look like this:: -\fish -function ls - command ls --color=auto $argv -end -\endfish + function ls + command ls --color=auto $argv + end There are a few important things that need to be noted about aliases: -- Always take care to add the `$argv` variable to the list of parameters to the wrapped command. This makes sure that if the user specifies any additional parameters to the function, they are passed on to the underlying command. +- Always take care to add the ``$argv`` variable to the list of parameters to the wrapped command. This makes sure that if the user specifies any additional parameters to the function, they are passed on to the underlying command. -- If the alias has the same name as the aliased command, it is necessary to prefix the call to the program with `command` in order to tell fish that the function should not call itself, but rather a command with the same name. Failing to do so will cause infinite recursion bugs. +- If the alias has the same name as the aliased command, it is necessary to prefix the call to the program with ``command`` in order to tell fish that the function should not call itself, but rather a command with the same name. Failing to do so will cause infinite recursion bugs. - Autoloading isn't applicable to aliases. Since, by definition, the function is created at the time the alias command is executed. You cannot autoload aliases. To easily create a function of this form, you can use the alias command. +.. _syntax-function-autoloading: -\subsubsection syntax-function-autoloading Autoloading functions +Autoloading functions +--------------------- Functions can be defined on the commandline or in a configuration file, but they can also be automatically loaded. This method of defining functions has several advantages. An autoloaded function becomes available automatically to all running shells. If the function definition is changed, all running shells will automatically reload the altered version. Startup time and memory usage is improved, etc. -Fish automatically searches through any directories in the array variable `$fish_function_path`, and any functions defined are automatically loaded when needed. A function definition file must have a filename consisting of the name of the function plus the suffix '`.fish`'. +Fish automatically searches through any directories in the array variable ``$fish_function_path``, and any functions defined are automatically loaded when needed. A function definition file must have a filename consisting of the name of the function plus the suffix '``.fish``'. By default, Fish searches the following for functions, using the first available file that it finds: -- A directory for end-users to keep their own functions, usually `~/.config/fish/functions` (controlled by the `XDG_CONFIG_HOME` environment variable). -- A directory for systems administrators to install functions for all users on the system, usually `/etc/fish/functions`. -- A directory for third-party software vendors to ship their own functions for their software, usually `/usr/share/fish/vendor_functions.d`. -- The functions shipped with fish, usually installed in `/usr/share/fish/functions`. +- A directory for end-users to keep their own functions, usually ``~/.config/fish/functions`` (controlled by the ``XDG_CONFIG_HOME`` environment variable). +- A directory for systems administrators to install functions for all users on the system, usually ``/etc/fish/functions``. +- A directory for third-party software vendors to ship their own functions for their software, usually ``/usr/share/fish/vendor_functions.d``. +- The functions shipped with fish, usually installed in ``/usr/share/fish/functions``. These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above. -This wide search may be confusing. If you are unsure, your functions probably belong in `~/.config/fish/functions`. +This wide search may be confusing. If you are unsure, your functions probably belong in ``~/.config/fish/functions``. It is very important that function definition files only contain the definition for the specified function and nothing else. Otherwise, it is possible that autoloading a function files requires that the function already be loaded, which creates a circular dependency. -Autoloading also won't work for event handlers, since fish cannot know that a function is supposed to be executed when an event occurs when it hasn't yet loaded the function. See the event handlers section for more information. +Autoloading also won't work for event handlers, since fish cannot know that a function is supposed to be executed when an event occurs when it hasn't yet loaded the function. See the `event handlers <#event>`_ section for more information. -Autoloading is not applicable to functions created by the `alias` command. For functions simple enough that you prefer to use the `alias` command to define them you'll need to put those commands in your `~/.config/fish/config.fish` script or some other script run when the shell starts. +Autoloading is not applicable to functions created by the ``alias`` command. For functions simple enough that you prefer to use the ``alias`` command to define them you'll need to put those commands in your ``~/.config/fish/config.fish`` script or some other script run when the shell starts. -If you are developing another program, you may wish to install functions which are available for all users of the fish shell on a system. They can be installed to the "vendor" functions directory. As this path may vary from system to system, the `pkgconfig` framework should be used to discover this path with the output of `pkg-config --variable functionsdir fish`. +If you are developing another program, you may wish to install functions which are available for all users of the fish shell on a system. They can be installed to the "vendor" functions directory. As this path may vary from system to system, the ``pkgconfig`` framework should be used to discover this path with the output of ``pkg-config --variable functionsdir fish``. +.. _syntax-conditional: -\subsubsection syntax-conditional Conditional execution of code and flow control +Conditional execution of code and flow control +---------------------------------------------- -There are four fish builtins that let you execute commands only if a specific criterion is met. These builtins are `if`, `switch`, `and` and `or`. +There are four fish builtins that let you execute commands only if a specific criterion is met. These builtins are ``if``, ``switch``, ``and`` and ``or``. -The `switch` command is used to execute one of possibly many blocks of commands depending on the value of a string. See the documentation for switch for more information. +The ``switch`` command is used to execute one of possibly many blocks of commands depending on the value of a string. See the documentation for switch for more information. -The other conditionals use the exit status of a command to decide if a command or a block of commands should be executed. See the documentation for `if`, `and` and `or` for more information. +The other conditionals use the `exit status <#variables-status>`_ of a command to decide if a command or a block of commands should be executed. See the documentation for ``if``, ``and`` and ``or`` for more information. +.. _syntax-words: -\subsection syntax-words Some common words +Some common words +----------------- This is a short explanation of some of the commonly used words in fish. -- argument a parameter given to a command +- **argument** a parameter given to a command -- builtin a command that is implemented in the shell. Builtins are commands that are so closely tied to the shell that it is impossible to implement them as external commands. +- **builtin** a command that is implemented in the shell. Builtins are commands that are so closely tied to the shell that it is impossible to implement them as external commands. -- command a program that the shell can run. +- **command** a program that the shell can run. -- function a block of commands that can be called as if they were a single command. By using functions, it is possible to string together multiple smaller commands into one more advanced command. +- **function** a block of commands that can be called as if they were a single command. By using functions, it is possible to string together multiple smaller commands into one more advanced command. -- job a running pipeline or command +- **job** a running pipeline or command -- pipeline a set of commands stringed together so that the output of one command is the input of the next command +- **pipeline** a set of commands stringed together so that the output of one command is the input of the next command -- redirection an operation that changes one of the input/output streams associated with a job +- **redirection** an operation that changes one of the input/output streams associated with a job -- switch a special flag sent as an argument to a command that will alter the behavior of the command. A switch almost always begins with one or two hyphens. +- **switch** a special flag sent as an argument to a command that will alter the behavior of the command. A switch almost always begins with one or two hyphens. -\section docs Help +Help +==== -`fish` has an extensive help system. Use the `help` command to obtain help on a specific subject or command. For instance, writing `help syntax` displays the syntax section of this documentation. +``fish`` has an extensive help system. Use the ``help`` command to obtain help on a specific subject or command. For instance, writing ``help syntax`` displays the `syntax section <#syntax>`_ of this documentation. -`fish` also has man pages for its commands. For example, `man set` will show the documentation for `set` as a man page. +``fish`` also has man pages for its commands. For example, ``man set`` will show the documentation for ``set`` as a man page. -Help on a specific builtin can also be obtained with the `-h` parameter. For instance, to obtain help on the `fg` builtin, either type `fg -h` or `help fg`. +Help on a specific builtin can also be obtained with the ``-h`` parameter. For instance, to obtain help on the ``fg`` builtin, either type ``fg -h`` or ``help fg``. -\section autosuggestions Autosuggestions +Autosuggestions +=============== -fish suggests commands as you type, based on command history, completions, and valid file paths. As you type commands, you will see a suggestion offered after the cursor, in a muted gray color (which can be changed with the `fish_color_autosuggestion` variable). +fish suggests commands as you type, based on command history, completions, and valid file paths. As you type commands, you will see a suggestion offered after the cursor, in a muted gray color (which can be changed with the ``fish_color_autosuggestion`` variable). To accept the autosuggestion (replacing the command line contents), press right arrow or @key{Control,F}. To accept the first suggested word, press @key{Alt,→,Right} or @key{Alt,F}. If the autosuggestion is not what you want, just ignore it: it won't execute unless you accept it. Autosuggestions are a powerful way to quickly summon frequently entered commands, by typing the first few characters. They are also an efficient technique for navigating through directory hierarchies. -\section completion Tab completion +.. _completion: -Tab completion is one of the most time saving features of any modern shell. By tapping the tab key, the user asks `fish` to guess the rest of the command or parameter that the user is currently typing. If `fish` can only find one possible completion, `fish` will write it out. If there is more than one completion, `fish` will write out the longest prefix that all completions have in common. If the completions differ on the first character, a list of all possible completions is printed. The list features descriptions of the completions and if the list doesn't fit the screen, it is scrollable by using the arrow keys, the page up/page down keys, the tab key or the space bar. Once the list has been entered, pressing any other key will start a search. If the list has not been entered, pressing any other key will exit the list and insert the pressed key into the command line. +Tab Completion +============== -These are the general purpose tab completions that `fish` provides: +Tab completion is one of the most time saving features of any modern shell. By tapping the tab key, the user asks ``fish`` to guess the rest of the command or parameter that the user is currently typing. If ``fish`` can only find one possible completion, ``fish`` will write it out. If there is more than one completion, ``fish`` will write out the longest prefix that all completions have in common. If the completions differ on the first character, a list of all possible completions is printed. The list features descriptions of the completions and if the list doesn't fit the screen, it is scrollable by using the arrow keys, the page up/page down keys, the tab key or the space bar. Once the list has been entered, pressing any other key will start a search. If the list has not been entered, pressing any other key will exit the list and insert the pressed key into the command line. + +These are the general purpose tab completions that ``fish`` provides: - Completion of commands (builtins, functions and regular programs). @@ -330,113 +337,125 @@ These are the general purpose tab completions that `fish` provides: - Completion of usernames for tilde expansion. -- Completion of filenames, even on strings with wildcards such as '`*`', '`**`' and '`?`'. +- Completion of filenames, even on strings with wildcards such as '``*``', '``**``' and '``?``'. -`fish` provides a large number of program specific completions. Most of these completions are simple options like the `-l` option for `ls`, but some are more advanced. The latter include: +``fish`` provides a large number of program specific completions. Most of these completions are simple options like the ``-l`` option for ``ls``, but some are more advanced. The latter include: -- The programs `man` and `whatis` show all installed manual pages as completions. +- The programs ``man`` and ``whatis`` show all installed manual pages as completions. -- The `make` program uses all targets in the Makefile in the current directory as completions. +- The ``make`` program uses all targets in the Makefile in the current directory as completions. -- The `mount` command uses all mount points specified in fstab as completions. +- The ``mount`` command uses all mount points specified in fstab as completions. -- The `ssh` command uses all hosts that are stored in the known_hosts file as completions. (See the ssh documentation for more information) +- The ``ssh`` command uses all hosts that are stored in the known_hosts file as completions. (See the ssh documentation for more information) -- The `su` command uses all users on the system as completions. +- The ``su`` command uses all users on the system as completions. -- The `apt-get`, `rpm` and `yum` commands use all installed packages as completions. +- The ``apt-get``, ``rpm`` and ``yum`` commands use all installed packages as completions. -\subsection completion-own Writing your own completions +.. _completion-own: -Specifying your own completions is not difficult. To specify a completion, use the `complete` command. `complete` takes as a parameter the name of the command to specify a completion for. For example, to add a completion for the program `myprog`, one would start the completion command with `complete -c myprog ...` +Writing your own completions +---------------------------- -To provide a list of possible completions for myprog, use the `-a` switch. If `myprog` accepts the arguments start and stop, this can be specified as `complete -c myprog -a 'start stop'`. The argument to the `-a` switch is always a single string. At completion time, it will be tokenized on spaces and tabs, and variable expansion, command substitution and other forms of parameter expansion will take place. +Specifying your own completions is not difficult. To specify a completion, use the ``complete`` command. ``complete`` takes as a parameter the name of the command to specify a completion for. For example, to add a completion for the program ``myprog``, one would start the completion command with ``complete -c myprog ...`` -`fish` has a special syntax to support specifying switches accepted by a command. The switches `-s`, `-l` and `-o` are used to specify a short switch (single character, such as `-l`), a gnu style long switch (such as '`--color`') and an old-style long switch (like '`-shuffle`'), respectively. If the command 'myprog' has an option '-o' which can also be written as '`--output`', and which can take an additional value of either 'yes' or 'no', this can be specified by writing: +To provide a list of possible completions for myprog, use the ``-a`` switch. If ``myprog`` accepts the arguments start and stop, this can be specified as ``complete -c myprog -a 'start stop'``. The argument to the ``-a`` switch is always a single string. At completion time, it will be tokenized on spaces and tabs, and variable expansion, command substitution and other forms of parameter expansion will take place. -\fish -complete -c myprog -s o -l output -a "yes no" -\endfish +``fish`` has a special syntax to support specifying switches accepted by a command. The switches ``-s``, ``-l`` and ``-o`` are used to specify a short switch (single character, such as ``-l``), a gnu style long switch (such as '``--color``') and an old-style long switch (like '``-shuffle``'), respectively. If the command 'myprog' has an option '-o' which can also be written as '``--output``', and which can take an additional value of either 'yes' or 'no', this can be specified by writing:: -There are also special switches for specifying that a switch requires an argument, to disable filename completion, to create completions that are only available in some combinations, etc.. For a complete description of the various switches accepted by the `complete` command, see the documentation for the complete builtin, or write `complete --help` inside the `fish` shell. - -For examples of how to write your own complex completions, study the completions in `/usr/share/fish/completions`. (The exact path depends on your chosen installation prefix and may be slightly different) + complete -c myprog -s o -l output -a "yes no" -\subsection completion-func Useful functions for writing completions +There are also special switches for specifying that a switch requires an argument, to disable filename completion, to create completions that are only available in some combinations, etc.. For a complete description of the various switches accepted by the ``complete`` command, see the documentation for the complete builtin, or write ``complete --help`` inside the ``fish`` shell. -`fish` ships with several functions that are very useful when writing command specific completions. Most of these functions name begins with the string '`__fish_`'. Such functions are internal to `fish` and their name and interface may change in future fish versions. Still, some of them may be very useful when writing completions. A few of these functions are described here. Be aware that they may be removed or changed in future versions of fish. +For examples of how to write your own complex completions, study the completions in ``/usr/share/fish/completions``. (The exact path depends on your chosen installation prefix and may be slightly different) -Functions beginning with the string `__fish_print_` print a newline separated list of strings. For example, `__fish_print_filesystems` prints a list of all known file systems. Functions beginning with `__fish_complete_` print out a newline separated list of completions with descriptions. The description is separated from the completion by a tab character. +.. _completion-func: -- `__fish_complete_directories STRING DESCRIPTION` performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION. +Useful functions for writing completions +---------------------------------------- -- `__fish_complete_path STRING DESCRIPTION` performs path completion on STRING, giving them the description DESCRIPTION. +``fish`` ships with several functions that are very useful when writing command specific completions. Most of these functions name begins with the string '``__fish_``'. Such functions are internal to ``fish`` and their name and interface may change in future fish versions. Still, some of them may be very useful when writing completions. A few of these functions are described here. Be aware that they may be removed or changed in future versions of fish. -- `__fish_complete_groups` prints a list of all user groups with the groups members as description. +Functions beginning with the string ``__fish_print_`` print a newline separated list of strings. For example, ``__fish_print_filesystems` prints a list of all known file systems. Functions beginning with ``__fish_complete_``` print out a newline separated list of completions with descriptions. The description is separated from the completion by a tab character. -- `__fish_complete_pids` prints a list of all processes IDs with the command name as description. +- ``__fish_complete_directories STRING DESCRIPTION`` performs path completion on STRING, allowing only directories, and giving them the description DESCRIPTION. -- `__fish_complete_suffix SUFFIX` performs file completion allowing only files ending in SUFFIX, with an optional description. +- ``__fish_complete_path STRING DESCRIPTION`` performs path completion on STRING, giving them the description DESCRIPTION. -- `__fish_complete_users` prints a list of all users with their full name as description. +- ``__fish_complete_groups`` prints a list of all user groups with the groups members 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. +- ``__fish_complete_pids`` prints a list of all processes IDs with the command name as 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. +- ``__fish_complete_suffix SUFFIX`` performs file completion allowing only files ending in SUFFIX, with an optional description. -- `__fish_print_interfaces` prints a list of all known network interfaces. +- ``__fish_complete_users`` prints a list of all users with their full name as description. -- `__fish_print_packages` prints a list of all installed packages. This function currently handles Debian, rpm and Gentoo packages. +- ``__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_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. -\subsection completion-path Where to put completions +- ``__fish_print_interfaces`` prints a list of all known network interfaces. -Completions can be defined on the commandline or in a configuration file, but they can also be automatically loaded. Fish automatically searches through any directories in the array variable `$fish_complete_path`, and any completions defined are automatically loaded when needed. A completion file must have a filename consisting of the name of the command to complete and the suffix '`.fish`'. +- ``__fish_print_packages`` prints a list of all installed packages. This function currently handles Debian, rpm and Gentoo packages. + +.. _completion-path: + +Where to put completions +------------------------ + +Completions can be defined on the commandline or in a configuration file, but they can also be automatically loaded. Fish automatically searches through any directories in the array variable ``$fish_complete_path``, and any completions defined are automatically loaded when needed. A completion file must have a filename consisting of the name of the command to complete and the suffix '``.fish``'. By default, Fish searches the following for completions, using the first available file that it finds: -- A directory for end-users to keep their own completions, usually `~/.config/fish/completions` (controlled by the `XDG_CONFIG_HOME` environment variable); -- A directory for systems administrators to install completions for all users on the system, usually `/etc/fish/completions`; -- A directory for third-party software vendors to ship their own completions for their software, usually `/usr/share/fish/vendor_completions.d`; -- The completions shipped with fish, usually installed in `/usr/share/fish/completions`; and -- Completions automatically generated from the operating system's manual, usually stored in `~/.local/share/fish/generated_completions`. +- A directory for end-users to keep their own completions, usually ``~/.config/fish/completions`` (controlled by the ``XDG_CONFIG_HOME`` environment variable); +- A directory for systems administrators to install completions for all users on the system, usually ``/etc/fish/completions``; +- A directory for third-party software vendors to ship their own completions for their software, usually ``/usr/share/fish/vendor_completions.d``; +- The completions shipped with fish, usually installed in ``/usr/share/fish/completions``; and +- Completions automatically generated from the operating system's manual, usually stored in ``~/.local/share/fish/generated_completions``. These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above. -This wide search may be confusing. If you are unsure, your completions probably belong in `~/.config/fish/completions`. +This wide search may be confusing. If you are unsure, your completions probably belong in ``~/.config/fish/completions``. -If you have written new completions for a common Unix command, please consider sharing your work by submitting it via the instructions in Further help and development. +If you have written new completions for a common Unix command, please consider sharing your work by submitting it via the instructions in `Further help and development <#more-help>`_. -If you are developing another program and would like to ship completions with your program, install them to the "vendor" completions directory. As this path may vary from system to system, the `pkgconfig` framework should be used to discover this path with the output of `pkg-config --variable completionsdir fish`. +If you are developing another program and would like to ship completions with your program, install them to the "vendor" completions directory. As this path may vary from system to system, the ``pkgconfig`` framework should be used to discover this path with the output of ``pkg-config --variable completionsdir fish``. -\section expand Parameter expansion (Globbing) +.. _expand: + +Parameter expansion (Globbing) +============================== When an argument for a program is given on the commandline, it undergoes the process of parameter expansion before it is sent on to the command. Parameter expansion is a powerful mechanism that allows you to expand the parameter in various ways, including performing wildcard matching on files, inserting the value of a shell variable into the parameter or even using the output of another command as a parameter list. +.. _expand-wildcard: -\subsection expand-wildcard Wildcards +Wildcards +--------- -If a star (`*`) or a question mark (`?`) is present in the parameter, `fish` attempts to match the given parameter to any files in such a way that: +If a star (``*``) or a question mark (``?``) is present in the parameter, ``fish`` attempts to match the given parameter to any files in such a way that: -- `?` can match any single character except '/'. +- ``?`` can match any single character except '/'. -- `*` can match any string of characters not containing '/'. This includes matching an empty string. +- ``*`` can match any string of characters not containing '/'. This includes matching an empty string. -- `**` matches any string of characters. This includes matching an empty string. The matched string may include the `/` character; that is, it recurses into subdirectories. Note that augmenting this wildcard with other strings will not match files in the current working directory (`$PWD`) if you separate the strings with a slash ("/"). This is unlike other shells such as zsh. For example, `**\/*.fish` in zsh will match `.fish` files in the PWD but in fish will only match such files in a subdirectory. In fish you should type `***.fish` to match files in the PWD as well as subdirectories. +- ``**`` matches any string of characters. This includes matching an empty string. The matched string may include the ``/`` character; that is, it recurses into subdirectories. Note that augmenting this wildcard with other strings will not match files in the current working directory (``$PWD``) if you separate the strings with a slash ("/"). This is unlike other shells such as zsh. For example, ``**\/*.fish`` in zsh will match ``.fish`` files in the PWD but in fish will only match such files in a subdirectory. In fish you should type ``***.fish`` to match files in the PWD as well as subdirectories. -Other shells, such as zsh, provide a rich glob syntax for restricting the files matched by globs. For example, `**(.)`, to only match regular files. Fish prefers to defer such features to programs, such as `find`, rather than reinventing the wheel. Thus, if you want to limit the wildcard expansion to just regular files the fish approach is to define and use a function. For example, +Other shells, such as zsh, provide a rich glob syntax for restricting the files matched by globs. For example, ``**(.)``, to only match regular files. Fish prefers to defer such features to programs, such as ``find``, rather than reinventing the wheel. Thus, if you want to limit the wildcard expansion to just regular files the fish approach is to define and use a function. For example, -\fish{cli-dark} -function ff --description 'Like ** but only returns plain files.' - # This also ignores .git directories. - find . \( -name .git -type d -prune \) -o -type f | \ - sed -n -e '/^\.\/\.git$/n' -e 's/^\.\///p' -end -\endfish -You would then use it in place of `**` like this, `my_prog (ff)`, to pass only regular files in or below $PWD to `my_prog`. +:: + + function ff --description 'Like ** but only returns plain files.' + # This also ignores .git directories. + find . \( -name .git -type d -prune \) -o -type f | \ + sed -n -e '/^\.\/\.git$/n' -e 's/^\.\///p' + end + +You would then use it in place of ``**`` like this, ``my_prog (ff)``, to pass only regular files in or below $PWD to ``my_prog``. Wildcard matches are sorted case insensitively. When sorting matches containing numbers, consecutive digits are considered to be one element, so that the strings '1' '5' and '12' would be sorted in the order given. @@ -444,253 +463,259 @@ File names beginning with a dot are not considered when wildcarding unless a dot Examples: -- `a*` matches any files beginning with an 'a' in the current directory. +- ``a*`` matches any files beginning with an 'a' in the current directory. -- `???` matches any file in the current directory whose name is exactly three characters long. +- ``???`` matches any file in the current directory whose name is exactly three characters long. -- `**` matches any files and directories in the current directory and all of its subdirectories. +- ``**`` matches any files and directories in the current directory and all of its subdirectories. -Note that for most commands, if any wildcard fails to expand, the command is not executed, `$status` is set to nonzero, and a warning is printed. This behavior is consistent with setting `shopt -s failglob` in bash. There are exactly 3 exceptions, namely `set`, `count` and `for`. Their globs are permitted to expand to zero arguments, as with `shopt -s nullglob` in bash. +Note that for most commands, if any wildcard fails to expand, the command is not executed, ```$status`` <#variables-status>`_ is set to nonzero, and a warning is printed. This behavior is consistent with setting ``shopt -s failglob`` in bash. There are exactly 3 exceptions, namely ``set``, ``count`` and ``for``. Their globs are permitted to expand to zero arguments, as with ``shopt -s nullglob`` in bash. -Examples: -\fish -ls *.foo -# Lists the .foo files, or warns if there aren't any. +Examples:: -set foos *.foo -if count $foos >/dev/null - ls $foos -end -# Lists the .foo files, if any. -\endfish + ls *.foo + # Lists the .foo files, or warns if there aren't any. -\subsection expand-command-substitution Command substitution + set foos *.foo + if count $foos >/dev/null + ls $foos + end + # Lists the .foo files, if any. -The output of a series of commands can be used as the parameters to another command. If a parameter contains a set of parenthesis, the text enclosed by the parenthesis will be interpreted as a list of commands. On expansion, this list is executed, and substituted by the output. If the output is more than one line long, each line will be expanded to a new parameter. Setting `IFS` to the empty string will disable line splitting. +.. _expand-command-substitution: -The exit status of the last run command substitution is available in the status variable if the substitution occurs in the context of a `set` command. +Command substitution +-------------------- -Only part of the output can be used, see index range expansion for details. +The output of a series of commands can be used as the parameters to another command. If a parameter contains a set of parenthesis, the text enclosed by the parenthesis will be interpreted as a list of commands. On expansion, this list is executed, and substituted by the output. If the output is more than one line long, each line will be expanded to a new parameter. Setting ``IFS`` to the empty string will disable line splitting. -Fish has a default limit of 10 MiB on the amount of data a command substitution can output. If the limit is exceeded the entire command, not just the substitution, is failed and `$status` is set to 122. You can modify the limit by setting the `fish_read_limit` variable at any time including in the environment before fish starts running. If you set it to zero then no limit is imposed. This is a safety mechanism to keep the shell from consuming too much memory if a command outputs an unreasonable amount of data. Note that this limit also affects how much data the `read` command will process. +The exit status of the last run command substitution is available in the `status <#variables-status>`_ variable if the substitution occurs in the context of a ``set`` command. -Examples: +Only part of the output can be used, see `index range expansion <#expand-index-range>`_ for details. -\fish -echo (basename image.jpg .jpg).png -# Outputs 'image.png'. +Fish has a default limit of 10 MiB on the amount of data a command substitution can output. If the limit is exceeded the entire command, not just the substitution, is failed and ``$status`` is set to 122. You can modify the limit by setting the ``fish_read_limit`` variable at any time including in the environment before fish starts running. If you set it to zero then no limit is imposed. This is a safety mechanism to keep the shell from consuming too much memory if a command outputs an unreasonable amount of data. Note that this limit also affects how much data the ``read`` command will process. -for i in *.jpg; convert $i (basename $i .jpg).png; end -# Convert all JPEG files in the current directory to the -# PNG format using the 'convert' program. +Examples:: -begin; set -l IFS; set data (cat data.txt); end -# Set the `data` variable to the contents of 'data.txt' -# without splitting it into an array. -\endfish + echo (basename image.jpg .jpg).png + # Outputs 'image.png'. + + for i in *.jpg; convert $i (basename $i .jpg).png; end + # Convert all JPEG files in the current directory to the + # PNG format using the 'convert' program. + + begin; set -l IFS; set data (cat data.txt); end + # Set the ``data`` variable to the contents of 'data.txt' + # without splitting it into an array. -\subsection expand-brace Brace expansion +.. _expand-brace: + +Brace expansion +--------------- A comma separated list of characters enclosed in curly braces will be expanded so each element of the list becomes a new parameter. -Examples: -\fish -echo input.{c,h,txt} -# Outputs 'input.c input.h input.txt' +Examples:: -mv *.{c,h} src/ -# Moves all files with the suffix '.c' or '.h' to the subdirectory src. -\endfish + echo input.{c,h,txt} + # Outputs 'input.c input.h input.txt' -A literal "{}" will not be used as a brace expansion: + mv *.{c,h} src/ + # Moves all files with the suffix '.c' or '.h' to the subdirectory src. -\fish -echo foo-{} -# Outputs foo-{} +A literal "{}" will not be used as a brace expansion:: + + echo foo-{} + # Outputs foo-{} + + echo foo-{$undefinedvar} + # Output is an empty line - see `the cartesian product section <#cartesian-product>`_ -echo foo-{$undefinedvar} -# Output is an empty line - see the cartesian product section -\endfish If there is nothing between a brace and a comma or two commas, it's interpreted as an empty element. -So: -\fish -echo {,,/usr}/bin -# Output /bin /bin /usr/bin -\endfish +So:: + echo {,,/usr}/bin + # Output /bin /bin /usr/bin -To use a "," as an element, quote or escape it. +To use a "," as an element, `quote <#quotes>`_ or `escape <#escapes>`_ it. -\subsection expand-variable Variable expansion +.. _expand-variable: -A dollar sign followed by a string of characters is expanded into the value of the shell variable with the same name. For an introduction to the concept of shell variables, read the Shell variables section. +Variable expansion +------------------ + +A dollar sign followed by a string of characters is expanded into the value of the shell variable with the same name. For an introduction to the concept of shell variables, read the `Shell variables <#variables>`_ section. Undefined and empty variables expand to nothing. To separate a variable name from text encase the variable within double-quotes or braces. -Examples: -\fish -echo $HOME -# Prints the home directory of the current user. +Examples:: -echo $nonexistentvariable -# Prints no output. + echo $HOME + # Prints the home directory of the current user. -echo The plural of $WORD is "$WORD"s -# Prints "The plural of cat is cats" when $WORD is set to cat. -echo The plural of $WORD is {$WORD}s -# ditto -\endfish + echo $nonexistentvariable + # Prints no output. -Note that without the quotes or braces, fish will try to expand a variable called `$WORDs`, which may not exist. + echo The plural of $WORD is "$WORD"s + # Prints "The plural of cat is cats" when $WORD is set to cat. + echo The plural of $WORD is {$WORD}s + # ditto -The latter syntax `{$WORD}` works by exploiting brace expansion. +Note that without the quotes or braces, fish will try to expand a variable called ``$WORDs``, which may not exist. + +The latter syntax ``{$WORD}`` works by exploiting `brace expansion <#expand-brace>`_. -In these cases, the expansion eliminates the string, as a result of the implicit cartesian product. +In these cases, the expansion eliminates the string, as a result of the implicit `cartesian product <#cartesian-product>`_. If, in the example above, $WORD is undefined or an empty list, the "s" is not printed. However, it is printed, if $WORD is the empty string. -Unlike all other expanions, variable expansion also happens in double quoted strings. Inside double quotes (`"these"`), variables will always expand to exactly one argument. If they are empty or undefined, it will result in an empty string. If they have one element, they'll expand to that element. If they have more than that, the elements will be joined with spaces. +Unlike all other expanions, variable expansion also happens in double quoted strings. Inside double quotes (``"these"``), variables will always expand to exactly one argument. If they are empty or undefined, it will result in an empty string. If they have one element, they'll expand to that element. If they have more than that, the elements will be joined with spaces. Outside of double quotes, variables will expand to as many arguments as they have elements. That means an empty list will expand to nothing, a variable with one element will expand to that element, and a variable with multiple elements will expand to each of those elements separately. -When two unquoted expansions directly follow each other, you need to watch out for expansions that expand to nothing. This includes undefined variables and empty lists, but also command substitutions with no output. See the cartesian product section for more information. +When two unquoted expansions directly follow each other, you need to watch out for expansions that expand to nothing. This includes undefined variables and empty lists, but also command substitutions with no output. See the `cartesian product <#cartesian-product>`_ section for more information. -The `$` symbol can also be used multiple times, as a kind of "dereference" operator (the `*` in C or C++), like in the following code: +The ``$`` symbol can also be used multiple times, as a kind of "dereference" operator (the ``*`` in C or C++), like in the following code:: -\fish -set foo a b c -set a 10; set b 20; set c 30 -for i in (seq (count $$foo)) - echo $$foo[$i] -end + set foo a b c + set a 10; set b 20; set c 30 + for i in (seq (count $$foo)) + echo $$foo[$i] + end -# Output is: -# 10 -# 20 -# 30 -\endfish + # Output is: + # 10 + # 20 + # 30 -When using this feature together with array brackets, the brackets will always match the innermost `$` dereference. Thus, `$$foo[5]` will always mean the fifth element of the `foo` variable should be dereferenced, not the fifth element of the doubly dereferenced variable `foo`. The latter can instead be expressed as `$$foo[1][5]`. +When using this feature together with array brackets, the brackets will always match the innermost ``$`` dereference. Thus, ``$$foo[5]`` will always mean the fifth element of the ``foo`` variable should be dereferenced, not the fifth element of the doubly dereferenced variable ``foo``. The latter can instead be expressed as ``$$foo[1][5]``. -\subsection cartesian-product Cartesian Products +.. _cartesian-product: + +Cartesian Products +------------------ Lists adjacent to other lists or strings are expanded as cartesian products: -Examples: -\fish{cli-dark} ->_ echo {good,bad}" apples" -good apples bad apples +Examples:: ->_ set -l a x y z ->_ set -l b 1 2 3 + >_ echo {good,bad}" apples" + good apples bad apples ->_ echo $a$b -x1 y1 z1 x2 y2 z2 x3 y3 z3 + >_ set -l a x y z + >_ set -l b 1 2 3 ->_ echo $a"-"$b -x-1 y-1 z-1 x-2 y-2 z-2 x-3 y-3 z-3 + >_ echo $a$b + x1 y1 z1 x2 y2 z2 x3 y3 z3 ->_ echo {x,y,z}$b -x1 y1 z1 x2 y2 z2 x3 y3 z3 + >_ echo $a"-"$b + x-1 y-1 z-1 x-2 y-2 z-2 x-3 y-3 z-3 ->_ echo {$b}word -1word 2word 3word + >_ echo {x,y,z}$b + x1 y1 z1 x2 y2 z2 x3 y3 z3 ->_ echo {$c}word -# Output is an empty line -\endfish + >_ echo {$b}word + 1word 2word 3word -Be careful when you try to use braces to separate variable names from text. The problem shown above can be avoided by wrapping the variable in double quotes instead of braces (`echo "$c"word`). + >_ echo {$c}word + # Output is an empty line -This also happens after command substitution. Therefore strings might be eliminated. This can be avoided by making the inner command return a trailing newline. +Be careful when you try to use braces to separate variable names from text. The problem shown above can be avoided by wrapping the variable in double quotes instead of braces (``echo "$c"word``). + +This also happens after `command substitution <#expand-command-substitution>`_. Therefore strings might be eliminated. This can be avoided by making the inner command return a trailing newline. E.g. -\fish{cli-dark} ->_ echo (printf '%s' '')banana # the printf prints literally nothing ->_ echo (printf '%s\n' '')banana # the printf prints just a newline, so the command substitution expands to an empty string -banana -# After command substitution, the previous line looks like: ->_ echo ""banana -\endfish +:: -Examples: -\fish{cli-dark} ->_ set b 1 2 3 ->_ echo (echo x)$b -x1 x2 x3 -\endfish + >_ echo (printf '%s' '')banana # the printf prints literally nothing + >_ echo (printf '%s\n' '')banana # the printf prints just a newline, so the command substitution expands to an empty string + banana + # After command substitution, the previous line looks like: + >_ echo ""banana -\subsection expand-index-range Index range expansion +Examples:: -Both command substitution and shell variable expansion support accessing only specific items by providing a set of indices in square brackets. It's often needed to access a sequence of elements. To do this, use the range operator '`..`' for this. A range '`a..b`', where range limits 'a' and 'b' are integer numbers, is expanded into a sequence of indices '`a a+1 a+2 ... b`' or '`a a-1 a-2 ... b`' depending on which of 'a' or 'b' is higher. The negative range limits are calculated from the end of the array or command substitution. Note that invalid indexes for either end are silently clamped to one or the size of the array as appropriate. + >_ set b 1 2 3 + >_ echo (echo x)$b + x1 x2 x3 + +.. _expand-index-range: + +Index range expansion +--------------------- + +Both command substitution and shell variable expansion support accessing only specific items by providing a set of indices in square brackets. It's often needed to access a sequence of elements. To do this, use the range operator '``..``' for this. A range '``a..b``', where range limits 'a' and 'b' are integer numbers, is expanded into a sequence of indices '``a a+1 a+2 ... b``' or '``a a-1 a-2 ... b``' depending on which of 'a' or 'b' is higher. The negative range limits are calculated from the end of the array or command substitution. Note that invalid indexes for either end are silently clamped to one or the size of the array as appropriate. Range expansion will go in reverse if the end element is earlier in the list than the start and forward if the end is later than the start, unless exactly one of the given indices is negative. This is to enable clamping without changing direction if the list has fewer elements than expected. -Some examples: - -\fish -# Limit the command substitution output -echo (seq 10)[2..5] -# Uses elements from 2 to 5 -# Output is: 2 3 4 5 - -# Use overlapping ranges: -echo (seq 10)[2..5 1..3] -# Takes elements from 2 to 5 and then elements from 1 to 3 -# Output is: 2 3 4 5 1 2 3 - -# Reverse output -echo (seq 10)[-1..1] -# Uses elements from the last output line to -# the first one in reverse direction -# Output is: 10 9 8 7 6 5 4 3 2 1 - -# The command substitution has only one line, -# so these will result in empty output: -echo (echo one)[2..-1] -echo (echo one)[-3..1] -\endfish - -The same works when setting or expanding variables: - -\fish -# Reverse path variable -set PATH $PATH[-1..1] -# or -set PATH[-1..1] $PATH - -# Use only n last items of the PATH -set n -3 -echo $PATH[$n..-1] -\endfish - -Variables can be used as indices for expansion of variables, like so: -\fish -set index 2 -set letters a b c d -echo $letters[$index] # returns 'b' -\endfish -However using variables as indices for command substitution is currently not supported, so -\fish -echo (seq 5)[$index] # This won't work - -set sequence (seq 5) # It needs to be written on two lines like this. -echo $sequence[$index] # returns '2' -\endfish - -\subsection expand-home Home directory expansion - -The `~` (tilde) character at the beginning of a parameter, followed by a username, is expanded into the home directory of the specified user. A lone `~`, or a `~` followed by a slash, is expanded into the home directory of the process owner. +Some examples:: -\subsection combine Combining different expansions + # Limit the command substitution output + echo (seq 10)[2..5] + # Uses elements from 2 to 5 + # Output is: 2 3 4 5 + + # Use overlapping ranges: + echo (seq 10)[2..5 1..3] + # Takes elements from 2 to 5 and then elements from 1 to 3 + # Output is: 2 3 4 5 1 2 3 + + # Reverse output + echo (seq 10)[-1..1] + # Uses elements from the last output line to + # the first one in reverse direction + # Output is: 10 9 8 7 6 5 4 3 2 1 + + # The command substitution has only one line, + # so these will result in empty output: + echo (echo one)[2..-1] + echo (echo one)[-3..1] + +The same works when setting or expanding variables:: + + + # Reverse path variable + set PATH $PATH[-1..1] + # or + set PATH[-1..1] $PATH + + # Use only n last items of the PATH + set n -3 + echo $PATH[$n..-1] + +Variables can be used as indices for expansion of variables, like so:: + + set index 2 + set letters a b c d + echo $letters[$index] # returns 'b' + +However using variables as indices for command substitution is currently not supported, so:: + + echo (seq 5)[$index] # This won't work + + set sequence (seq 5) # It needs to be written on two lines like this. + echo $sequence[$index] # returns '2' + +.. _expand-home: + +Home directory expansion +------------------------ + +The ``~`` (tilde) character at the beginning of a parameter, followed by a username, is expanded into the home directory of the specified user. A lone ``~``, or a ``~`` followed by a slash, is expanded into the home directory of the process owner. + + +.. _combine: + +Combining different expansions +------------------------------ All of the above expansions can be combined. If several expansions result in more than one parameter, all possible combinations are created. @@ -705,10 +730,12 @@ Expansions are performed from right to left, nested bracket expansions are perfo Example: -If the current directory contains the files 'foo' and 'bar', the command `echo a(ls){1,2,3} ` will output 'abar1 abar2 abar3 afoo1 afoo2 afoo3'. +If the current directory contains the files 'foo' and 'bar', the command ``echo a(ls){1,2,3}`` will output ``abar1 abar2 abar3 afoo1 afoo2 afoo3``. +.. _identifiers: -\section identifiers Shell variable and function names +Shell variable and function names +================================= The names given to shell objects such as variables and function names are known as "identifiers". Each type of identifier has rules that define the valid sequence of characters which compose the identifier. @@ -716,95 +743,104 @@ A variable name cannot be empty. It can contain only letters, digits, and unders A function name cannot be empty. It may not begin with a hyphen ("-") and may not contain a slash ("/"). All other characters, including a space, are valid. -A bind mode name (e.g., `bind -m abc ...`) is restricted to the rules for valid variable names. +A bind mode name (e.g., ``bind -m abc ...``) is restricted to the rules for valid variable names. +.. _variables: -\section variables Shell variables +Shell variables +=============== Shell variables are named pieces of data, which can be created, deleted and their values changed and used by the user. Variables may optionally be "exported", so that a copy of the variable is available to any subprocesses the shell creates. An exported variable is referred to as an "environment variable". -To set a variable value, use the `set` command. A variable name can not be empty and can contain only letters, digits, and underscores. It may begin and end with any of those characters. +To set a variable value, use the ``set`` command. A variable name can not be empty and can contain only letters, digits, and underscores. It may begin and end with any of those characters. Example: -To set the variable `smurf_color` to the value `blue`, use the command `set smurf_color blue`. +To set the variable ``smurf_color`` to the value ``blue``, use the command ``set smurf_color blue``. -After a variable has been set, you can use the value of a variable in the shell through variable expansion. +After a variable has been set, you can use the value of a variable in the shell through `variable expansion <#expand-variable>`_. Example: -To use the value of the variable `smurf_color`, write `$` (dollar symbol) followed by the name of the variable, like `echo Smurfs are usually $smurf_color`, which would print the result 'Smurfs are usually blue'. +To use the value of the variable ``smurf_color``, write ``$`` (dollar symbol) followed by the name of the variable, like ``echo Smurfs are usually $smurf_color``, which would print the result 'Smurfs are usually blue'. +.. _variables-scope: -\subsection variables-scope Variable scope +Variable scope +-------------- -There are three kinds of variables in fish: universal, global and local variables. Universal variables are shared between all fish sessions a user is running on one computer. Global variables are specific to the current fish session, but are not associated with any specific block scope, and will never be erased unless the user explicitly requests it using `set -e`. Local variables are specific to the current fish session, and associated with a specific block of commands, and is automatically erased when a specific block goes out of scope. A block of commands is a series of commands that begins with one of the commands `for`, `while` , `if`, `function`, `begin` or `switch`, and ends with the command `end`. The user can specify that a variable should have either global or local scope using the `-g/--global` or `-l/--local` switches. +There are three kinds of variables in fish: universal, global and local variables. Universal variables are shared between all fish sessions a user is running on one computer. Global variables are specific to the current fish session, but are not associated with any specific block scope, and will never be erased unless the user explicitly requests it using ``set -e``. Local variables are specific to the current fish session, and associated with a specific block of commands, and is automatically erased when a specific block goes out of scope. A block of commands is a series of commands that begins with one of the commands ``for``, ``while`` , ``if``, ``function``, ``begin`` or ``switch``, and ends with the command ``end``. The user can specify that a variable should have either global or local scope using the ``-g/--global`` or ``-l/--local`` switches. -Variables can be explicitly set to be universal with the `-U` or `--universal` switch, global with the `-g` or `--global` switch, or local with the `-l` or `--local` switch. The scoping rules when creating or updating a variable are: +Variables can be explicitly set to be universal with the ``-U`` or ``--universal`` switch, global with the ``-g`` or ``--global`` switch, or local with the ``-l`` or ``--local`` switch. The scoping rules when creating or updating a variable are: -# If a variable is explicitly set to either universal, global or local, that setting will be honored. If a variable of the same name exists in a different scope, that variable will not be changed. -# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the variable scope is not changed. --# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the `-l` or `--local` flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global. +-# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the ``-l`` or ``--local`` flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global. There may be many variables with the same name, but different scopes. When using a variable, the variable scope will be searched from the inside out, i.e. a local variable will be used rather than a global variable with the same name, a global variable will be used rather than a universal variable with the same name. Example: -The following code will not output anything: +The following code will not output anything:: -\fish -begin - # This is a nice local scope where all variables will die - set -l pirate 'There be treasure in them thar hills' -end + begin + # This is a nice local scope where all variables will die + set -l pirate 'There be treasure in them thar hills' + end -echo $pirate -# This will not output anything, since the pirate was local -\endfish + echo $pirate + # This will not output anything, since the pirate was local +.. _variables-universal: -\subsection variables-universal More on universal variables +More on universal variables +--------------------------- Universal variables are variables that are shared between all the users' fish sessions on the computer. Fish stores many of its configuration options as universal variables. This means that in order to change fish settings, all you have to do is change the variable value once, and it will be automatically updated for all sessions, and preserved across computer reboots and login/logout. -To see universal variables in action, start two fish sessions side by side, and issue the following command in one of them `set fish_color_cwd blue`. Since `fish_color_cwd` is a universal variable, the color of the current working directory listing in the prompt will instantly change to blue on both terminals. +To see universal variables in action, start two fish sessions side by side, and issue the following command in one of them ``set fish_color_cwd blue``. Since ``fish_color_cwd`` is a universal variable, the color of the current working directory listing in the prompt will instantly change to blue on both terminals. -Universal variables are stored in the file `.config/fish/fishd.MACHINE_ID`, where MACHINE_ID is typically your MAC address. Do not edit this file directly, as your edits may be overwritten. Edit them through fish scripts or by using fish interactively instead. +`Universal variables <#variables-universal>`_ are stored in the file ``.config/fish/fishd.MACHINE_ID``, where MACHINE_ID is typically your MAC address. Do not edit this file directly, as your edits may be overwritten. Edit them through fish scripts or by using fish interactively instead. Do not append to universal variables in config.fish, because these variables will then get longer with each new shell instance. Instead, simply set them once at the command line. -\subsection variables-functions Variable scope for functions +.. _variables-functions: + +Variable scope for functions +----------------------------- When calling a function, all current local variables temporarily disappear. This shadowing of the local scope is needed since the variable namespace would become cluttered, making it very easy to accidentally overwrite variables from another function. -For example: +For example:: -\fish -function shiver - set phrase 'Shiver me timbers' -end + function shiver + set phrase 'Shiver me timbers' + end -function avast - set phrase 'Avast, mateys' - # Calling the shiver function here can not - # change any variables in the local scope - shiver - echo $phrase -end -avast + function avast + set phrase 'Avast, mateys' + # Calling the shiver function here can not + # change any variables in the local scope + shiver + echo $phrase + end + avast -# Outputs "Avast, mateys" -\endfish + # Outputs "Avast, mateys" -\subsection variables-export Exporting variables + +.. _variables-export: + +Exporting variables +------------------- Variables in fish can be exported. This means the variable will be inherited by any commands started by fish. It is convention that exported variables are in uppercase and unexported variables are in lowercase. -Variables can be explicitly set to be exported with the `-x` or `--export` switch, or not exported with the `-u` or `--unexport` switch. The exporting rules when creating or updating a variable are identical to the scoping rules for variables: +Variables can be explicitly set to be exported with the ``-x`` or ``--export`` switch, or not exported with the ``-u`` or ``--unexport`` switch. The exporting rules when creating or updating a variable are identical to the scoping rules for variables: -# If a variable is explicitly set to either be exported or not exported, that setting will be honored. @@ -816,148 +852,157 @@ Variables can be explicitly set to be exported with the `-x` or `--export` switc -# If a variable has global scope, it is accessible read-write to functions whether it is exported or not. -\subsection variables-arrays Arrays +.. _variables-arrays: -`fish` can store a list of multiple strings inside of a variable. To access one element of an array, use the index of the element inside of square brackets, like this: +Arrays +------- -`echo $PATH[3]` +``fish`` can store a list of multiple strings inside of a variable. To access one element of an array, use the index of the element inside of square brackets, like this: -Note that array indices start at 1 in `fish`, not 0, as is more common in other languages. This is because many common Unix tools like `seq` are more suited to such use. An invalid index is silently ignored resulting in no value being substituted (not an empty string). +``echo $PATH[3]`` -If you do not use any brackets, all the elements of the array will be written as separate items. This means you can easily iterate over an array using this syntax: +Note that array indices start at 1 in ``fish``, not 0, as is more common in other languages. This is because many common Unix tools like ``seq`` are more suited to such use. An invalid index is silently ignored resulting in no value being substituted (not an empty string). -\fish -for i in $PATH; echo $i is in the path; end -\endfish +If you do not use any brackets, all the elements of the array will be written as separate items. This means you can easily iterate over an array using this syntax:: -To create a variable `smurf`, containing the items `blue` and `small`, simply write: + for i in $PATH; echo $i is in the path; end -\fish -set smurf blue small -\endfish +To create a variable ``smurf``, containing the items ``blue`` and ``small``, simply write:: -It is also possible to set or erase individual elements of an array: + set smurf blue small -\fish -# Set smurf to be an array with the elements 'blue' and 'small' -set smurf blue small +It is also possible to set or erase individual elements of an array:: -# Change the second element of smurf to 'evil' -set smurf[2] evil + # Set smurf to be an array with the elements 'blue' and 'small' + set smurf blue small -# Erase the first element -set -e smurf[1] + # Change the second element of smurf to 'evil' + set smurf[2] evil + + # Erase the first element + set -e smurf[1] + + # Output 'evil' + echo $smurf -# Output 'evil' -echo $smurf -\endfish If you specify a negative index when expanding or assigning to an array variable, the index will be calculated from the end of the array. For example, the index -1 means the last index of an array. -A range of indices can be specified, see index range expansion for details. +A range of indices can be specified, see `index range expansion <#expand-index-range>`_ for details. -All arrays are one-dimensional and cannot contain other arrays, although it is possible to fake nested arrays using the dereferencing rules of variable expansion. +All arrays are one-dimensional and cannot contain other arrays, although it is possible to fake nested arrays using the dereferencing rules of `variable expansion <#expand-variable>`_. -When an array is exported as an environment variable, it is either space or colon delimited, depending on whether it is a path variable: -\fish -set -x smurf blue small -set -x smurf_PATH forest mushroom -env | grep smurf - -# smurf=blue small -# smurf_PATH=forest:mushroom - -\endfish +When an array is exported as an environment variable, it is either space or colon delimited, depending on whether it is a path variable:: -`fish` automatically creates arrays from all environment variables whose name ends in PATH, by splitting them on colons. Other variables are not automatically split. + set -x smurf blue small + set -x smurf_PATH forest mushroom + env | grep smurf + + # smurf=blue small + # smurf_PATH=forest:mushroom + -\subsection variables-path PATH variables -Path variables are a special kind of variable used to support colon-delimited path lists including PATH, CDPATH, MANPATH, PYTHONPATH, etc. All variables that end in `PATH` (case-sensitive) become PATH variables. +``fish`` automatically creates arrays from all environment variables whose name ends in PATH, by splitting them on colons. Other variables are not automatically split. + +.. _variables-path: + +PATH variables +-------------- + +Path variables are a special kind of variable used to support colon-delimited path lists including PATH, CDPATH, MANPATH, PYTHONPATH, etc. All variables that end in ``PATH`` (case-sensitive) become PATH variables. PATH variables act as normal arrays, except they are are implicitly joined and split on colons. -\fish -set MYPATH 1 2 3 -echo "$MYPATH" -# 1:2:3 -set MYPATH "$MYPATH:4:5" -echo $MYPATH -# 1 2 3 4 5 -echo "$MYPATH" -# 1:2:3:4:5 -\endfish -Variables can be marked or unmarked as PATH variables via the `--path` and `--unpath` options to `set`. +:: -\subsection variables-special Special variables + set MYPATH 1 2 3 + echo "$MYPATH" + # 1:2:3 + set MYPATH "$MYPATH:4:5" + echo $MYPATH + # 1 2 3 4 5 + echo "$MYPATH" + # 1:2:3:4:5 -The user can change the settings of `fish` by changing the values of certain variables. +Variables can be marked or unmarked as PATH variables via the ``--path`` and ``--unpath`` options to ``set``. -- A large number of variable starting with the prefixes `fish_color` and `fish_pager_color.` See Variables for changing highlighting colors for more information. +.. _variables-special: +.. _PATH: -- `fish_emoji_width` controls the computed width of certain characters, in particular emoji, whose rendered width varies across terminal emulators. This should be set to 1 if your terminal emulator renders emoji single-width, or 2 if double-width. Set this only if you see graphical glitching when printing emoji. +Special variables +----------------- -- `fish_ambiguous_width` controls the computed width of ambiguous East Asian characters. This should be set to 1 if your terminal emulator renders these characters as single-width (typical), or 2 if double-width. +The user can change the settings of ``fish`` by changing the values of certain variables. -- `fish_escape_delay_ms` overrides the default timeout of 300ms (default key bindings) or 10ms (vi key bindings) after seeing an escape character before giving up on matching a key binding. See the documentation for the bind builtin command. This delay facilitates using escape as a meta key. +- A large number of variable starting with the prefixes ``fish_color`` and ``fish_pager_color``. See `Variables for changing highlighting colors <#variables-color>`_ for more information. -- `fish_greeting`, the greeting message printed on startup. +- ``fish_emoji_width`` controls the computed width of certain characters, in particular emoji, whose rendered width varies across terminal emulators. This should be set to 1 if your terminal emulator renders emoji single-width, or 2 if double-width. Set this only if you see graphical glitching when printing emoji. -- `fish_history`, the current history session name. If set, all subsequent commands within an +- ``fish_ambiguous_width`` controls the computed width of ambiguous East Asian characters. This should be set to 1 if your terminal emulator renders these characters as single-width (typical), or 2 if double-width. + +- ``fish_escape_delay_ms`` overrides the default timeout of 300ms (default key bindings) or 10ms (vi key bindings) after seeing an escape character before giving up on matching a key binding. See the documentation for the bind builtin command. This delay facilitates using escape as a meta key. + +- ``fish_greeting``, the greeting message printed on startup. + +- ``fish_history``, the current history session name. If set, all subsequent commands within an interactive fish session will be logged to a separate file identified by the value of the - variable. If unset, or set to `default`, the default session name "fish" is used. If set to an + variable. If unset, or set to ``default``, the default session name "fish" is used. If set to an empty string, history is not saved to disk (but is still available within the interactive session). -- `fish_user_paths`, an array of directories that are prepended to `PATH`. This can be a universal variable. +- ``fish_user_paths``, an array of directories that are prepended to ``PATH``. This can be a universal variable. -- `umask`, the current file creation mask. The preferred way to change the umask variable is through the umask function. An attempt to set umask to an invalid value will always fail. +- ``umask``, the current file creation mask. The preferred way to change the umask variable is through the umask function. An attempt to set umask to an invalid value will always fail. -- `BROWSER`, the user's preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation. +- ``BROWSER``, the user's preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation. -- `CDPATH`, an array of directories in which to search for the new directory for the `cd` builtin. +- ``CDPATH``, an array of directories in which to search for the new directory for the ``cd`` builtin. -- `LANG`, `LC_ALL`, `LC_COLLATE`, `LC_CTYPE`, `LC_MESSAGES`, `LC_MONETARY`, `LC_NUMERIC` and `LC_TIME` set the language option for the shell and subprograms. See the section Locale variables for more information. +- ``LANG``, ``LC_ALL``, ``LC_COLLATE``, ``LC_CTYPE``, ``LC_MESSAGES``, ``LC_MONETARY``, ``LC_NUMERIC`` and ``LC_TIME`` set the language option for the shell and subprograms. See the section `Locale variables <#variables-locale>`_ for more information. -- `PATH`, an array of directories in which to search for commands +- ``PATH``, an array of directories in which to search for commands -`fish` also sends additional information to the user through the values of certain environment variables. The user cannot change the values of most of these variables. +``fish`` also sends additional information to the user through the values of certain environment variables. The user cannot change the values of most of these variables. -- `_`, the name of the currently running command. +- ``_``, the name of the currently running command. -- `argv`, an array of arguments to the shell or function. `argv` is only defined when inside a function call, or if fish was invoked with a list of arguments, like `fish myscript.fish foo bar`. This variable can be changed by the user. +- ``argv``, an array of arguments to the shell or function. ``argv`` is only defined when inside a function call, or if fish was invoked with a list of arguments, like ``fish myscript.fish foo bar``. This variable can be changed by the user. -- `history`, an array containing the last commands that were entered. +- ``history``, an array containing the last commands that were entered. -- `HOME`, the user's home directory. This variable can be changed by the user. +- ``HOME``, the user's home directory. This variable can be changed by the user. -- `IFS`, the internal field separator that is used for word splitting with the read builtin. Setting this to the empty string will also disable line splitting in command substitution. This variable can be changed by the user. +- ``IFS``, the internal field separator that is used for word splitting with the read builtin. Setting this to the empty string will also disable line splitting in `command substitution <#expand-command-substitution>`_. This variable can be changed by the user. -- `PWD`, the current working directory. +- ``PWD``, the current working directory. -- `status`, the exit status of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number. +- ``status``, the `exit status <#variables-status>`_ of the last foreground job to exit. If the job was terminated through a signal, the exit status will be 128 plus the signal number. -- `USER`, the current username. This variable can be changed by the user. +- ``USER``, the current username. This variable can be changed by the user. -- `CMD_DURATION`, the runtime of the last command in milliseconds. +- ``CMD_DURATION``, the runtime of the last command in milliseconds. -- `version`, the version of the currently running fish (also available as `FISH_VERSION` for backward compatibility). +- ``version``, the version of the currently running fish (also available as ``FISH_VERSION`` for backward compatibility). -- `SHLVL`, the level of nesting of shells +- ``SHLVL``, the level of nesting of shells -- `COLUMNS` and `LINES`, the current size of the terminal in height and width. These values are only used by fish if the operating system does not report the size of the terminal. Both variables must be set in that case otherwise a default of 80x24 will be used. They are updated when the window size changes. +- ``COLUMNS`` and ``LINES``, the current size of the terminal in height and width. These values are only used by fish if the operating system does not report the size of the terminal. Both variables must be set in that case otherwise a default of 80x24 will be used. They are updated when the window size changes. The names of these variables are mostly derived from the csh family of shells and differ from the ones used by Bourne style shells such as bash. -Variables whose name are in uppercase are generally exported to the commands started by fish, while those in lowercase are not exported (`CMD_DURATION` is an exception, for historical reasons). This rule is not enforced by fish, but it is good coding practice to use casing to distinguish between exported and unexported variables. `fish` also uses several variables internally. Such variables are prefixed with the string `__FISH` or `__fish.` These should never be used by the user. Changing their value may break fish. +Variables whose name are in uppercase are generally exported to the commands started by fish, while those in lowercase are not exported (``CMD_DURATION`` is an exception, for historical reasons). This rule is not enforced by fish, but it is good coding practice to use casing to distinguish between exported and unexported variables. ``fish`` also uses several variables internally. Such variables are prefixed with the string ``__FISH`` or ``__fish.`` These should never be used by the user. Changing their value may break fish. -\subsection variables-status The status variable +.. _variables-status: + +The status variable +------------------- Whenever a process exits, an exit status is returned to the program that started it (usually the shell). This exit status is an integer number, which tells the calling application how the execution of the command went. In general, a zero exit status means that the command executed without problem, but a non-zero exit status means there was some form of problem. -Fish stores the exit status of the last process in the last job to exit in the `status` variable. +Fish stores the exit status of the last process in the last job to exit in the ``status`` variable. -If `fish` encounters a problem while executing a command, the status variable may also be set to a specific value: +If ``fish`` encounters a problem while executing a command, the status variable may also be set to a specific value: - 0 is generally the exit status of fish commands if they successfully performed the requested operation. @@ -978,138 +1023,153 @@ If `fish` encounters a problem while executing a command, the status variable ma If a process exits through a signal, the exit status will be 128 plus the number of the signal. -\subsection variables-color Variables for changing highlighting colors +.. _variables-color: -The colors used by fish for syntax highlighting can be configured by changing the values of a various variables. The value of these variables can be one of the colors accepted by the set_color command. The `--bold` or `-b` switches accepted by `set_color` are also accepted. +Variables for changing highlighting colors +------------------------------------------ + +The colors used by fish for syntax highlighting can be configured by changing the values of a various variables. The value of these variables can be one of the colors accepted by the set_color command. The ``--bold`` or ``-b`` switches accepted by ``set_color`` are also accepted. The following variables are available to change the highlighting colors in fish: -- `fish_color_normal`, the default color +- ``fish_color_normal``, the default color -- `fish_color_command`, the color for commands +- ``fish_color_command``, the color for commands -- `fish_color_quote`, the color for quoted blocks of text +- ``fish_color_quote``, the color for quoted blocks of text -- `fish_color_redirection`, the color for IO redirections +- ``fish_color_redirection``, the color for IO redirections -- `fish_color_end`, the color for process separators like ';' and '&' +- ``fish_color_end``, the color for process separators like ';' and '&' -- `fish_color_error`, the color used to highlight potential errors +- ``fish_color_error``, the color used to highlight potential errors -- `fish_color_param`, the color for regular command parameters +- ``fish_color_param``, the color for regular command parameters -- `fish_color_comment`, the color used for code comments +- ``fish_color_comment``, the color used for code comments -- `fish_color_match`, the color used to highlight matching parenthesis +- ``fish_color_match``, the color used to highlight matching parenthesis -- `fish_color_selection`, the color used when selecting text (in vi visual mode) +- ``fish_color_selection``, the color used when selecting text (in vi visual mode) -- `fish_color_search_match`, used to highlight history search matches and the selected pager item (must be a background) +- ``fish_color_search_match``, used to highlight history search matches and the selected pager item (must be a background) -- `fish_color_operator`, the color for parameter expansion operators like '*' and '~' +- ``fish_color_operator``, the color for parameter expansion operators like '*' and '~' -- `fish_color_escape`, the color used to highlight character escapes like '\\n' and '\\x70' +- ``fish_color_escape``, the color used to highlight character escapes like '\\n' and '\\x70' -- `fish_color_cwd`, the color used for the current working directory in the default prompt +- ``fish_color_cwd``, the color used for the current working directory in the default prompt -- `fish_color_autosuggestion`, the color used for autosuggestions +- ``fish_color_autosuggestion``, the color used for autosuggestions -- `fish_color_user`, the color used to print the current username in some of fish default prompts +- ``fish_color_user``, the color used to print the current username in some of fish default prompts -- `fish_color_host`, the color used to print the current host system in some of fish default prompts +- ``fish_color_host``, the color used to print the current host system in some of fish default prompts -- `fish_color_cancel`, the color for the '^C' indicator on a canceled command +- ``fish_color_cancel``, the color for the '^C' indicator on a canceled command Additionally, the following variables are available to change the highlighting in the completion pager: -- `fish_pager_color_prefix`, the color of the prefix string, i.e. the string that is to be completed +- ``fish_pager_color_prefix``, the color of the prefix string, i.e. the string that is to be completed -- `fish_pager_color_completion`, the color of the completion itself +- ``fish_pager_color_completion``, the color of the completion itself -- `fish_pager_color_description`, the color of the completion description +- ``fish_pager_color_description``, the color of the completion description -- `fish_pager_color_progress`, the color of the progress bar at the bottom left corner +- ``fish_pager_color_progress``, the color of the progress bar at the bottom left corner -- `fish_pager_color_secondary`, the background color of the every second completion +- ``fish_pager_color_secondary``, the background color of the every second completion Example: -To make errors highlighted and red, use: - -\fish -set fish_color_error red --bold -\endfish +To make errors highlighted and red, use:: -\subsection variables-locale Locale variables + set fish_color_error red --bold + + +.. _variables-locale: + +Locale variables +---------------- The most common way to set the locale to use a command like 'set -x LANG en_GB.utf8', which sets the current locale to be the English language, as used in Great Britain, using the UTF-8 character set. For a list of available locales, use 'locale -a'. -`LANG`, `LC_ALL`, `LC_COLLATE`, `LC_CTYPE`, `LC_MESSAGES`, `LC_MONETARY`, `LC_NUMERIC` and `LC_TIME` set the language option for the shell and subprograms. These variables work as follows: `LC_ALL` forces all the aspects of the locale to the specified value. If `LC_ALL` is set, all other locale variables will be ignored. The other `LC_` variables set the specified aspect of the locale information. `LANG` is a fallback value, it will be used if none of the `LC_` variables are specified. +``LANG``, ``LC_ALL``, ``LC_COLLATE``, ``LC_CTYPE``, ``LC_MESSAGES``, ``LC_MONETARY``, ``LC_NUMERIC`` and ``LC_TIME`` set the language option for the shell and subprograms. These variables work as follows: ``LC_ALL`` forces all the aspects of the locale to the specified value. If ``LC_ALL`` is set, all other locale variables will be ignored. The other ``LC_`` variables set the specified aspect of the locale information. ``LANG`` is a fallback value, it will be used if none of the ``LC_`` variables are specified. + +.. _builtin-overview: + +Builtin commands +================ + +Many other shells have a large library of builtin commands. Most of these commands are also available as standalone commands, but have been implemented in the shell anyway. To avoid code duplication, and to avoid the confusion of subtly differing versions of the same command, ``fish`` generally only implements builtins for actions which cannot be performed by a regular command. + +For a list of all builtins, functions and commands shipped with fish, see the `table of contents <#toc-commands>`_. The documentation is also available by using the ``--help`` switch of the command. + +.. _editor: + +Command line editor +=================== + +The ``fish`` editor features copy and paste, a searchable history and many editor functions that can be bound to special keyboard shortcuts. + +Similar to bash, fish has Emacs and Vi editing modes. The default editing mode is Emacs. You can switch to Vi mode with ``fish_vi_key_bindings`` and switch back with ``fish_default_key_bindings``. You can also make your own key bindings by creating a function and setting $fish_key_bindings to its name. For example:: -\section builtin-overview Builtin commands - -Many other shells have a large library of builtin commands. Most of these commands are also available as standalone commands, but have been implemented in the shell anyway. To avoid code duplication, and to avoid the confusion of subtly differing versions of the same command, `fish` generally only implements builtins for actions which cannot be performed by a regular command. - -For a list of all builtins, functions and commands shipped with fish, see the table of contents. The documentation is also available by using the `--help` switch of the command. - - -\section editor Command line editor - -The `fish` editor features copy and paste, a searchable history and many editor functions that can be bound to special keyboard shortcuts. - -Similar to bash, fish has Emacs and Vi editing modes. The default editing mode is Emacs. You can switch to Vi mode with `fish_vi_key_bindings` and switch back with `fish_default_key_bindings`. You can also make your own key bindings by creating a function and setting $fish_key_bindings to its name. For example: - -\fish -function hybrid_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes" - for mode in default insert visual - fish_default_key_bindings -M $mode + function hybrid_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes" + for mode in default insert visual + fish_default_key_bindings -M $mode + end + fish_vi_key_bindings --no-erase end - fish_vi_key_bindings --no-erase -end -set -g fish_key_bindings hybrid_bindings -\endfish + set -g fish_key_bindings hybrid_bindings -\subsection shared-binds Shared bindings + +.. _shared-binds: + +Shared bindings +--------------- Some bindings are shared between emacs- and vi-mode because they aren't text editing bindings or because what Vi/Vim does for a particular key doesn't make sense for a shell. -- @key{Tab} completes the current token. @key{Shift, Tab} completes the current token and starts the pager's search mode. +- @key{Tab} `completes <#completion>`_ the current token. @key{Shift, Tab} completes the current token and starts the pager's search mode. - @key{Alt,←,Left} and @key{Alt,→,Right} move the cursor one word left or right, or moves forward/backward in the directory history if the command line is empty. If the cursor is already at the end of the line, and an autosuggestion is available, @key{Alt,→,Right} (or @key{Alt,F}) accepts the first word in the suggestion. -- @cursor_key{↑,Up} and @cursor_key{↓,Down} (or @key{Control,P} and @key{Control,N} for emacs aficionados) search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the history section for more information on history searching. +- @cursor_key{↑,Up} and @cursor_key{↓,Down} (or @key{Control,P} and @key{Control,N} for emacs aficionados) search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the `history <#history>`_ section for more information on history searching. -- @key{Alt,↑,Up} and @key{Alt,↓,Down} search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline was not on a token when the search started, all tokens match. See the history section for more information on history searching. +- @key{Alt,↑,Up} and @key{Alt,↓,Down} search the command history for the previous/next token containing the token under the cursor before the search was started. If the commandline was not on a token when the search started, all tokens match. See the `history <#history>`_ section for more information on history searching. - @key{Control,C} cancels the entire line. - @key{Control,D} delete one character to the right of the cursor. If the command line is empty, @key{Control,D} will exit fish. -- @key{Control,U} moves contents from the beginning of line to the cursor to the killring. +- @key{Control,U} moves contents from the beginning of line to the cursor to the `killring <#killring>`_. - @key{Control,L} clears and repaints the screen. -- @key{Control,W} moves the previous path component (everything up to the previous "/") to the killring. +- @key{Control,W} moves the previous path component (everything up to the previous "/") to the `killring <#killring>`_. - @key{Control,X} copies the current buffer to the system's clipboard, @key{Control,V} inserts the clipboard contents. -- @key{Alt,d} moves the next word to the killring. +- @key{Alt,d} moves the next word to the `killring <#killring>`_. - @key{Alt,h} (or @key{F1}) shows the manual page for the current command, if one exists. - @key{Alt,l} lists the contents of the current directory, unless the cursor is over a directory argument, in which case the contents of that directory will be listed. -- @key{Alt,p} adds the string '`| less;`' to the end of the job under the cursor. The result is that the output of the command will be paged. +- @key{Alt,p} adds the string '``| less;``' to the end of the job under the cursor. The result is that the output of the command will be paged. - @key{Alt,w} prints a short description of the command under the cursor. -- @key{Alt,e} edit the current command line in an external editor. The editor is chosen from the first available of the `$VISUAL` or `$EDITOR` variables. +- @key{Alt,e} edit the current command line in an external editor. The editor is chosen from the first available of the ``$VISUAL`` or ``$EDITOR`` variables. - @key{Alt,v} Same as @key{Alt,e}. -\subsection emacs-mode Emacs mode commands +.. _emacs-mode: + +Emacs mode commands +------------------- - @key{Home} or @key{Control,A} moves the cursor to the beginning of the line. @@ -1119,7 +1179,7 @@ Some bindings are shared between emacs- and vi-mode because they aren't text edi - @key{Delete} and @key{Backspace} removes one character forwards or backwards respectively. -- @key{Control,K} moves contents from the cursor to the end of line to the killring. +- @key{Control,K} moves contents from the cursor to the end of line to the `killring <#killring>`_. - @key{Alt,c} capitalizes the current word. @@ -1133,26 +1193,32 @@ Some bindings are shared between emacs- and vi-mode because they aren't text edi You can change these key bindings using the bind builtin command. -\subsection vi-mode Vi mode commands +.. _vi-mode: -Vi mode allows for the use of Vi-like commands at the prompt. Initially, insert mode is active. @key{Escape} enters command mode. The commands available in command, insert and visual mode are described below. Vi mode shares some bindings with Emacs mode. +Vi mode commands +---------------- -It is also possible to add all emacs-mode bindings to vi-mode by using something like +Vi mode allows for the use of Vi-like commands at the prompt. Initially, `insert mode <#vi-mode-insert>`_ is active. @key{Escape} enters `command mode <#vi-mode-command>`_. The commands available in command, insert and visual mode are described below. Vi mode shares `some bindings <#shared-binds>`_ with `Emacs mode <#emacs-mode>`_. -\fish -function fish_user_key_bindings - # Execute this once per mode that emacs bindings should be used in - fish_default_key_bindings -M insert - # Without an argument, fish_vi_key_bindings will default to - # resetting all bindings. - # The argument specifies the initial mode (insert, "default" or visual). - fish_vi_key_bindings insert -end -\endfish +It is also possible to add all emacs-mode bindings to vi-mode by using something like:: -When in vi-mode, the `fish_mode_prompt` function will display a mode indicator to the left of the prompt. The `fish_vi_cursor` function will be used to change the cursor's shape depending on the mode in supported terminals. To disable this feature, override it with an empty function. To display the mode elsewhere (like in your right prompt), use the output of the `fish_default_mode_prompt` function. -\subsubsection vi-mode-command Command mode + function fish_user_key_bindings + # Execute this once per mode that emacs bindings should be used in + fish_default_key_bindings -M insert + # Without an argument, fish_vi_key_bindings will default to + # resetting all bindings. + # The argument specifies the initial mode (insert, "default" or visual). + fish_vi_key_bindings insert + end + + +When in vi-mode, the ``fish_mode_prompt`` function will display a mode indicator to the left of the prompt. The ``fish_vi_cursor`` function will be used to change the cursor's shape depending on the mode in supported terminals. To disable this feature, override it with an empty function. To display the mode elsewhere (like in your right prompt), use the output of the ``fish_default_mode_prompt`` function. + +.. _vi-mode-command: + +Command mode +------------ Command mode is also known as normal mode. @@ -1160,51 +1226,63 @@ Command mode is also known as normal mode. - @key{l} moves the cursor right. -- @key{i} enters insert mode at the current cursor position. +- @key{i} enters `insert mode <#vi-mode-insert>`_ at the current cursor position. -- @key{v} enters visual mode at the current cursor position. +- @key{v} enters `visual mode <#vi-mode-visual>`_ at the current cursor position. -- @key{a} enters insert mode after the current cursor position. +- @key{a} enters `insert mode <#vi-mode-insert>`_ after the current cursor position. -- @key{Shift,A} enters insert mode at the end of the line. +- @key{Shift,A} enters `insert mode <#vi-mode-insert>`_ at the end of the line. - @key{0} (zero) moves the cursor to beginning of line (remaining in command mode). -- @key{d}@key{d} deletes the current line and moves it to the killring. +- @key{d}@key{d} deletes the current line and moves it to the `killring <#killring>`_. -- @key{Shift,D} deletes text after the current cursor position and moves it to the killring. +- @key{Shift,D} deletes text after the current cursor position and moves it to the `killring <#killring>`_. -- @key{p} pastes text from the killring. +- @key{p} pastes text from the `killring <#killring>`_. - @key{u} search history backwards. -- @key{[} and @key{]} search the command history for the previous/next token containing the token under the cursor before the search was started. See the history section for more information on history searching. +- @key{[} and @key{]} search the command history for the previous/next token containing the token under the cursor before the search was started. See the `history <#history>`_ section for more information on history searching. - @key{Backspace} moves the cursor left. -\subsubsection vi-mode-insert Insert mode +.. _vi-mode-insert: -- @key{Escape} enters command mode. +Insert mode +----------- + +- @key{Escape} enters `command mode <#vi-mode-command>`_. - @key{Backspace} removes one character to the left. -\subsubsection vi-mode-visual Visual mode +.. _vi-mode-visual: + +Visual mode +----------- - @cursor_key{←,Left} and @cursor_key{→,Right} extend the selection backward/forward by one character. - @key{b} and @key{w} extend the selection backward/forward by one word. -- @key{d} and @key{x} move the selection to the killring and enter command mode. +- @key{d} and @key{x} move the selection to the `killring <#killring>`_ and enter `command mode <#vi-mode-command>`_. -- @key{Escape} and @key{Control,C} enter command mode. +- @key{Escape} and @key{Control,C} enter `command mode <#vi-mode-command>`_. -\subsection killring Copy and paste (Kill Ring) +.. _killring: -`fish` uses an Emacs style kill ring for copy and paste functionality. Use @key{Control,K} to cut from the current cursor position to the end of the line. The string that is cut (a.k.a. killed) is inserted into a linked list of kills, called the kill ring. To paste the latest value from the kill ring use @key{Control,Y}. After pasting, use @key{Alt,Y} to rotate to the previous kill. +Copy and paste (Kill Ring) +-------------------------- + +``fish`` uses an Emacs style kill ring for copy and paste functionality. Use @key{Control,K} to cut from the current cursor position to the end of the line. The string that is cut (a.k.a. killed) is inserted into a linked list of kills, called the kill ring. To paste the latest value from the kill ring use @key{Control,Y}. After pasting, use @key{Alt,Y} to rotate to the previous kill. Copy and paste from outside are also supported, both via the @key{Control,X} / @key{Control,V} bindings and via the terminal's paste function, for which fish enables "Bracketed Paste Mode". When pasting inside single quotes, pasted single quotes and backslashes are automatically escaped so that the result can be used as a single token simply by closing the quote after. -\subsection history-search Searchable history +.. _history-search: + +Searchable history +------------------ After a command has been entered, it is inserted at the end of a history list. Any duplicate history items are automatically removed. By pressing the up and down keys, the user can search forwards and backwards in the history. If the current command line is not empty when starting a history search, only the commands containing the string entered into the command line are shown. @@ -1214,60 +1292,68 @@ History searches can be aborted by pressing the escape key. Prefixing the commandline with a space will prevent the entire line from being stored in the history. -The command history is stored in the file `~/.local/share/fish/fish_history` (or -`$XDG_DATA_HOME/fish/fish_history` if that variable is set) by default. However, you can set the -`fish_history` environment variable to change the name of the history session (resulting in a -`_history` file); both before starting the shell and while the shell is running. +The command history is stored in the file ``~/.local/share/fish/fish_history`` (or +``$XDG_DATA_HOME/fish/fish_history`` if that variable is set) by default. However, you can set the +``fish_history`` environment variable to change the name of the history session (resulting in a +``_history`` file); both before starting the shell and while the shell is running. Examples: -To search for previous entries containing the word 'make', type `make` in the console and press the up key. +To search for previous entries containing the word 'make', type ``make`` in the console and press the up key. -If the commandline reads `cd m`, place the cursor over the `m` character and press @key{Alt,↑,Up} to search for previously typed words containing 'm'. +If the commandline reads ``cd m``, place the cursor over the ``m`` character and press @key{Alt,↑,Up} to search for previously typed words containing 'm'. -\subsection multiline Multiline editing +.. _multiline: + +Multiline editing +----------------- The fish commandline editor can be used to work on commands that are several lines long. There are three ways to make a command span more than a single line: -- Pressing the @key{Enter} key while a block of commands is unclosed, such as when one or more block commands such as `for`, `begin` or `if` do not have a corresponding `end` command. +- Pressing the @key{Enter} key while a block of commands is unclosed, such as when one or more block commands such as ``for``, ``begin`` or ``if`` do not have a corresponding ``end`` command. - Pressing @key{Alt,Enter} instead of pressing the @key{Enter} key. -- By inserting a backslash (`\`) character before pressing the @key{Enter} key, escaping the newline. +- By inserting a backslash (``\``) character before pressing the @key{Enter} key, escaping the newline. The fish commandline editor works exactly the same in single line mode and in multiline mode. To move between lines use the left and right arrow keys and other such keyboard shortcuts. +.. _job-control: -\section job-control Running multiple programs +Running multiple programs +========================= -Normally when `fish` starts a program, this program will be put in the foreground, meaning it will take control of the terminal and `fish` will be stopped until the program finishes. Sometimes this is not desirable. For example, you may wish to start an application with a graphical user interface from the terminal, and then be able to continue using the shell. In such cases, there are several ways in which the user can change fish's behavior. +Normally when ``fish`` starts a program, this program will be put in the foreground, meaning it will take control of the terminal and ``fish`` will be stopped until the program finishes. Sometimes this is not desirable. For example, you may wish to start an application with a graphical user interface from the terminal, and then be able to continue using the shell. In such cases, there are several ways in which the user can change fish's behavior. --# By ending a command with the `&` (ampersand) symbol, the user tells `fish` to put the specified command into the background. A background process will be run simultaneous with `fish`. `fish` will retain control of the terminal, so the program will not be able to read from the keyboard. +-# By ending a command with the ``&`` (ampersand) symbol, the user tells ``fish`` to put the specified command into the background. A background process will be run simultaneous with ``fish``. ``fish`` will retain control of the terminal, so the program will not be able to read from the keyboard. --# By pressing @key{Control,Z}, the user stops a currently running foreground program and returns control to `fish`. Some programs do not support this feature, or remap it to another key. GNU Emacs uses @key{Control,X} @key{z} to stop running. +-# By pressing @key{Control,Z}, the user stops a currently running foreground program and returns control to ``fish``. Some programs do not support this feature, or remap it to another key. GNU Emacs uses @key{Control,X} @key{z} to stop running. --# By using the `fg` and `bg` builtin commands, the user can send any currently running job into the foreground or background. +-# By using the ``fg`` and ``bg`` builtin commands, the user can send any currently running job into the foreground or background. -Note that functions cannot be started in the background. Functions that are stopped and then restarted in the background using the `bg` command will not execute correctly. +Note that functions cannot be started in the background. Functions that are stopped and then restarted in the background using the ``bg`` command will not execute correctly. -\section initialization Initialization files +.. _initialization: + +Initialization files +==================== On startup, Fish evaluates a number of configuration files, which can be used to control the behavior of the shell. The location of these configuration variables is controlled by a number of environment variables, and their default or usual location is given below. Configuration files are evaluated in the following order: -- Configuration shipped with fish, which should not be edited, in `$__fish_data_dir/config.fish` (usually `/usr/share/fish/config.fish`). -- System-wide configuration files, where administrators can include initialization that should be run for all users on the system - similar to `/etc/profile` for POSIX-style shells - in `$__fish_sysconf_dir` (usually `/etc/fish/config.fish`); -- Configuration snippets in files ending in `.fish`, in the directories: - - `$__fish_config_dir/conf.d` (by default, `~/.config/fish/conf.d/`) - - `$__fish_sysconf_dir/conf.d` (by default, `/etc/fish/conf.d`) - - `/usr/share/fish/vendor_conf.d` (set at compile time; by default, `$__fish_data_dir/conf.d`) +- Configuration shipped with fish, which should not be edited, in ``$__fish_data_dir/config.fish`` (usually ``/usr/share/fish/config.fish`). +- System-wide configuration files, where administrators can include initialization that should be run for all users on the system - similar to ``/etc/profile`` for POSIX-style shells - in ``$__fish_sysconf_dir``` (usually ``/etc/fish/config.fish``); +- Configuration snippets in files ending in ``.fish``, in the directories: + - ``$__fish_config_dir/conf.d`` (by default, ``~/.config/fish/conf.d/``) + - ``$__fish_sysconf_dir/conf.d`` (by default, ``/etc/fish/conf.d``) + - ``/usr/share/fish/vendor_conf.d`` (set at compile time; by default, ``$__fish_data_dir/conf.d``) If there are multiple files with the same name in these directories, only the first will be executed. They are executed in order of their filename, sorted (like globs) in a natural order (i.e. "01" sorts before "2"). -- User initialization, usually in `~/.config/fish/config.fish` (controlled by the `XDG_CONFIG_HOME` environment variable, and accessible as `$__fish_config_dir`). +- User initialization, usually in `~/.config/fish/config.fish` (controlled by the ``XDG_CONFIG_HOME`` environment variable, and accessible as ``$__fish_config_dir``). These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above. @@ -1277,56 +1363,58 @@ Note that ~/.config/fish/config.fish is sourced _after_ the snippets. This is so These files are all executed on the startup of every shell. If you want to run a command only on starting an interactive shell, use the exit status of the command `status --is-interactive` to determine if the shell is interactive. If you want to run a command only when using a login shell, use `status --is-login` instead. This will speed up the starting of non-interactive or non-login shells. -If you are developing another program, you may wish to install configuration which is run for all users of the fish shell on a system. This is discouraged; if not carefully written, they may have side-effects or slow the startup of the shell. Additionally, users of other shells will not benefit from the Fish-specific configuration. However, if they are absolutely required, you may install them to the "vendor" configuration directory. As this path may vary from system to system, the `pkgconfig` framework should be used to discover this path with the output of `pkg-config --variable confdir fish`. +If you are developing another program, you may wish to install configuration which is run for all users of the fish shell on a system. This is discouraged; if not carefully written, they may have side-effects or slow the startup of the shell. Additionally, users of other shells will not benefit from the Fish-specific configuration. However, if they are absolutely required, you may install them to the "vendor" configuration directory. As this path may vary from system to system, the ``pkgconfig`` framework should be used to discover this path with the output of `pkg-config --variable confdir fish`. Examples: -If you want to add the directory `~/linux/bin` to your PATH variable when using a login shell, add the following to your `~/.config/fish/config.fish` file: +If you want to add the directory ``~/linux/bin`` to your PATH variable when using a login shell, add the following to your `~/.config/fish/config.fish` file:: -\fish -if status --is-login - set -x PATH $PATH ~/linux/bin -end -\endfish + if status --is-login + set -x PATH $PATH ~/linux/bin + end -If you want to run a set of commands when `fish` exits, use an event handler that is triggered by the exit of the shell: -\fish -function on_exit --on-event fish_exit - echo fish is now exiting -end -\endfish +If you want to run a set of commands when ``fish`` exits, use an `event handler <#event>`_ that is triggered by the exit of the shell:: -\section featureflags Future feature flags + + function on_exit --on-event fish_exit + echo fish is now exiting + end + +.. _featureflags: + +Future feature flags +==================== Feature flags are how fish stages changes that might break scripts. Breaking changes are introduced as opt-in, in a few releases they become opt-out, and eventually the old behavior is removed. -You can see the current list of features via `status features`: +You can see the current list of features via ``status features``:: -\fish -> status features -stderr-nocaret on 3.0 ^ no longer redirects stderr -qmark-noglob off 3.0 ? no longer globs -\endfish + > status features + stderr-nocaret on 3.0 ^ no longer redirects stderr + qmark-noglob off 3.0 ? no longer globs -There are two breaking changes in fish 3.0: caret `^` no longer redirects stderr, and question mark `?` is no longer a glob. These changes are off by default. They can be enabled on a per session basis: +There are two breaking changes in fish 3.0: caret ``^`` no longer redirects stderr, and question mark ``?`` is no longer a glob. These changes are off by default. They can be enabled on a per session basis:: -\fish -> fish --features qmark-noglob,stderr-nocaret -\endfish - -or opted into globally for a user: - -\fish -> set -U fish_features stderr-nocaret qmark-noglob -\endfish - -\section other Other features + > fish --features qmark-noglob,stderr-nocaret -\subsection color Syntax highlighting +or opted into globally for a user:: -`fish` interprets the command line as it is typed and uses syntax highlighting to provide feedback to the user. The most important feedback is the detection of potential errors. By default, errors are marked red. + + > set -U fish_features stderr-nocaret qmark-noglob + +.. _other: + +Other features +============== + +.. _color: + +Syntax highlighting +------------------- + +``fish`` interprets the command line as it is typed and uses syntax highlighting to provide feedback to the user. The most important feedback is the detection of potential errors. By default, errors are marked red. Detected errors include: @@ -1336,45 +1424,57 @@ Detected errors include: - Mismatched parenthesis -When the cursor is over a parenthesis or a quote, `fish` also highlights its matching quote or parenthesis. +When the cursor is over a parenthesis or a quote, ``fish`` also highlights its matching quote or parenthesis. To customize the syntax highlighting, you can set the environment variables listed in the Variables for changing highlighting colors section. -\subsection title Programmable title +.. _title: -When using most virtual terminals, it is possible to set the message displayed in the titlebar of the terminal window. This can be done automatically in fish by defining the `fish_title` function. The `fish_title` function is executed before and after a new command is executed or put into the foreground and the output is used as a titlebar message. The `status current-command` builtin will always return the name of the job to be put into the foreground (or 'fish' if control is returning to the shell) when the `fish_prompt` function is called. The first argument to fish_title will contain the most recently executed foreground command as a string, starting with fish 2.2. +Programmable title +------------------ + +When using most virtual terminals, it is possible to set the message displayed in the titlebar of the terminal window. This can be done automatically in fish by defining the ``fish_title`` function. The ``fish_title`` function is executed before and after a new command is executed or put into the foreground and the output is used as a titlebar message. The `status current-command` builtin will always return the name of the job to be put into the foreground (or 'fish' if control is returning to the shell) when the ``fish_prompt`` function is called. The first argument to fish_title will contain the most recently executed foreground command as a string, starting with fish 2.2. Examples: -The default `fish` title is +The default ``fish`` title is:: -\fish -function fish_title - echo (status current-command) ' ' - pwd -end -\endfish -To show the last command in the title: + function fish_title + echo (status current-command) ' ' + pwd + end -\fish -function fish_title - echo $argv[1] -end -\endfish +To show the last command in the title:: -\subsection prompt Programmable prompt + function fish_title + echo $argv[1] + end -When fish waits for input, it will display a prompt by evaluating the `fish_prompt` and `fish_right_prompt` functions. The output of the former is displayed on the left and the latter's output on the right side of the terminal. The output of `fish_mode_prompt` will be prepended on the left, though the default function only does this when in vi-mode. +.. _prompt: -\subsection greeting Configurable greeting +Programmable prompt +------------------- -If a function named `fish_greeting` exists, it will be run when entering interactive mode. Otherwise, if an environment variable named `fish_greeting` exists, it will be printed. +When fish waits for input, it will display a prompt by evaluating the ``fish_prompt`` and `fish_right_prompt` functions. The output of the former is displayed on the left and the latter's output on the right side of the terminal. The output of ``fish_mode_prompt`` will be prepended on the left, though the default function only does this when in vi-mode. -\subsection private-mode Private mode +.. _greeting: -fish supports launching in private mode via `fish --private` (or `fish -P` for short). In private mode, old history is not available and any interactive commands you execute will not be appended to the global history file, making it useful both for avoiding inadvertently leaking personal information (e.g. for screencasts) and when dealing with sensitive information to prevent it being persisted to disk. You can query the global variable `fish_private_mode` (`if set -q fish_private_mode ...`) if you would like to respect the user's wish for privacy and alter the behavior of your own fish scripts. +Configurable greeting +--------------------- -\subsection event Event handlers +If a function named ``fish_greeting`` exists, it will be run when entering interactive mode. Otherwise, if an environment variable named ``fish_greeting`` exists, it will be printed. + +.. _private-mode: + +Private mode +------------- + +fish supports launching in private mode via ``fish --private`` (or ``fish -P`` for short). In private mode, old history is not available and any interactive commands you execute will not be appended to the global history file, making it useful both for avoiding inadvertently leaking personal information (e.g. for screencasts) and when dealing with sensitive information to prevent it being persisted to disk. You can query the global variable `fish_private_mode`` (``if set -q fish_private_mode ...`) if you would like to respect the user's wish for privacy and alter the behavior of your own fish scripts. + +.. _event: + +Event handlers +--------------- When defining a new function in fish, it is possible to make it into an event handler, i.e. a function that is automatically run when a specific event takes place. Events that can trigger a handler currently are: @@ -1386,42 +1486,41 @@ When defining a new function in fish, it is possible to make it into an event ha Example: -To specify a signal handler for the WINCH signal, write: +To specify a signal handler for the WINCH signal, write:: -\fish -function my_signal_handler --on-signal WINCH - echo Got WINCH signal! -end -\endfish + function my_signal_handler --on-signal WINCH + echo Got WINCH signal! + end Please note that event handlers only become active when a function is loaded, which means you might need to otherwise source or execute a function instead of relying on autoloading. One approach is to put it into your initialization file. For more information on how to define new event handlers, see the documentation for the function command. -\subsection debugging Debugging fish scripts +.. _debugging: -Fish includes a built in debugging facility. The debugger allows you to stop execution of a script at an arbitrary point. When this happens you are presented with an interactive prompt. At this prompt you can execute any fish command (there are no debug commands as such). For example, you can check or change the value of any variables using `printf` and `set`. As another example, you can run `status print-stack-trace` to see how this breakpoint was reached. To resume normal execution of the script, simply type `exit` or [ctrl-D]. +Debugging fish scripts +----------------------- -To start a debug session simply run the builtin command `breakpoint` at the point in a function or script where you wish to gain control. Also, the default action of the TRAP signal is to call this builtin. So a running script can be debugged by sending it the TRAP signal with the `kill` command. Once in the debugger, it is easy to insert new breakpoints by using the funced function to edit the definition of a function. +Fish includes a built in debugging facility. The debugger allows you to stop execution of a script at an arbitrary point. When this happens you are presented with an interactive prompt. At this prompt you can execute any fish command (there are no debug commands as such). For example, you can check or change the value of any variables using ``printf`` and ``set``. As another example, you can run ``status print-stack-trace`` to see how this breakpoint was reached. To resume normal execution of the script, simply type ``exit`` or [ctrl-D]. + +To start a debug session simply run the builtin command ``breakpoint`` at the point in a function or script where you wish to gain control. Also, the default action of the TRAP signal is to call this builtin. So a running script can be debugged by sending it the TRAP signal with the ``kill`` command. Once in the debugger, it is easy to insert new breakpoints by using the funced function to edit the definition of a function. Note: At the moment the debug prompt is identical to your normal fish prompt. This can make it hard to recognize that you've entered a debug session. Issue 1310 is open to improve this. -\section more-help Further help and development +.. _more-help: + +Further help and development +============================ If you have a question not answered by this documentation, there are several avenues for help: --# The official mailing list at fish-users@lists.sourceforge.net +- The official mailing list at fish-users@lists.sourceforge.net --# The Internet Relay Chat channel, \#fish on `irc.oftc.net` +- The Internet Relay Chat channel, \#fish on ``irc.oftc.net`` --# The project GitHub page +- The `project GitHub page `_ If you have an improvement for fish, you can submit it via the mailing list or the GitHub page. - -\htmlonly[block] -
-\endhtmlonly -*/ From afd035f8cc7e81b4ddd92bddc2eade2401726015 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 16 Dec 2018 13:08:41 -0800 Subject: [PATCH 104/191] Copy doc_src to sphinx_doc_src and add a TOC --- sphinx_doc_src/cmds/abbr.rst | 80 ++++ sphinx_doc_src/cmds/alias.rst | 41 ++ sphinx_doc_src/cmds/and.rst | 23 ++ sphinx_doc_src/cmds/argparse.rst | 131 +++++++ sphinx_doc_src/cmds/begin.rst | 46 +++ sphinx_doc_src/cmds/bg.rst | 25 ++ sphinx_doc_src/cmds/bind.rst | 170 +++++++++ sphinx_doc_src/cmds/block.rst | 46 +++ sphinx_doc_src/cmds/break.rst | 25 ++ sphinx_doc_src/cmds/breakpoint.rst | 14 + sphinx_doc_src/cmds/builtin.rst | 22 ++ sphinx_doc_src/cmds/case.rst | 42 ++ sphinx_doc_src/cmds/cd.rst | 33 ++ sphinx_doc_src/cmds/cdh.rst | 16 + sphinx_doc_src/cmds/command.rst | 30 ++ sphinx_doc_src/cmds/commandline.rst | 82 ++++ sphinx_doc_src/cmds/complete.rst | 131 +++++++ sphinx_doc_src/cmds/contains.rst | 48 +++ sphinx_doc_src/cmds/continue.rst | 26 ++ sphinx_doc_src/cmds/count.rst | 25 ++ sphinx_doc_src/cmds/dirh.rst | 14 + sphinx_doc_src/cmds/dirs.rst | 15 + sphinx_doc_src/cmds/disown.rst | 24 ++ sphinx_doc_src/cmds/echo.rst | 60 +++ sphinx_doc_src/cmds/else.rst | 23 ++ sphinx_doc_src/cmds/emit.rst | 28 ++ sphinx_doc_src/cmds/end.rst | 19 + sphinx_doc_src/cmds/eval.rst | 21 + sphinx_doc_src/cmds/exec.rst | 15 + sphinx_doc_src/cmds/exit.rst | 12 + sphinx_doc_src/cmds/false.rst | 10 + sphinx_doc_src/cmds/fg.rst | 15 + sphinx_doc_src/cmds/fish.rst | 34 ++ .../cmds/fish_breakpoint_prompt.rst | 30 ++ sphinx_doc_src/cmds/fish_config.rst | 18 + sphinx_doc_src/cmds/fish_indent.rst | 28 ++ sphinx_doc_src/cmds/fish_key_reader.rst | 35 ++ sphinx_doc_src/cmds/fish_mode_prompt.rst | 37 ++ sphinx_doc_src/cmds/fish_opt.rst | 54 +++ sphinx_doc_src/cmds/fish_prompt.rst | 29 ++ sphinx_doc_src/cmds/fish_right_prompt.rst | 26 ++ .../cmds/fish_update_completions.rst | 9 + sphinx_doc_src/cmds/fish_vi_mode.rst | 12 + sphinx_doc_src/cmds/for.rst | 36 ++ sphinx_doc_src/cmds/funced.rst | 20 + sphinx_doc_src/cmds/funcsave.rst | 12 + sphinx_doc_src/cmds/function.rst | 101 +++++ sphinx_doc_src/cmds/functions.rst | 69 ++++ sphinx_doc_src/cmds/help.rst | 23 ++ sphinx_doc_src/cmds/history.rst | 79 ++++ sphinx_doc_src/cmds/if.rst | 39 ++ sphinx_doc_src/cmds/isatty.rst | 35 ++ sphinx_doc_src/cmds/jobs.rst | 33 ++ sphinx_doc_src/cmds/math.rst | 104 +++++ sphinx_doc_src/cmds/nextd.rst | 32 ++ sphinx_doc_src/cmds/not.rst | 23 ++ sphinx_doc_src/cmds/open.rst | 17 + sphinx_doc_src/cmds/or.rst | 23 ++ sphinx_doc_src/cmds/popd.rst | 28 ++ sphinx_doc_src/cmds/prevd.rst | 32 ++ sphinx_doc_src/cmds/printf.rst | 70 ++++ sphinx_doc_src/cmds/prompt_pwd.rst | 31 ++ sphinx_doc_src/cmds/psub.rst | 28 ++ sphinx_doc_src/cmds/pushd.rst | 44 +++ sphinx_doc_src/cmds/pwd.rst | 16 + sphinx_doc_src/cmds/random.rst | 44 +++ sphinx_doc_src/cmds/read.rst | 94 +++++ sphinx_doc_src/cmds/realpath.rst | 12 + sphinx_doc_src/cmds/return.rst | 25 ++ sphinx_doc_src/cmds/set.rst | 113 ++++++ sphinx_doc_src/cmds/set_color.rst | 57 +++ sphinx_doc_src/cmds/source.rst | 29 ++ sphinx_doc_src/cmds/status.rst | 67 ++++ sphinx_doc_src/cmds/string.rst | 359 ++++++++++++++++++ sphinx_doc_src/cmds/suspend.rst | 15 + sphinx_doc_src/cmds/switch.rst | 39 ++ sphinx_doc_src/cmds/test.rst | 166 ++++++++ sphinx_doc_src/cmds/trap.rst | 37 ++ sphinx_doc_src/cmds/true.rst | 10 + sphinx_doc_src/cmds/type.rst | 34 ++ sphinx_doc_src/cmds/ulimit.rst | 64 ++++ sphinx_doc_src/cmds/umask.rst | 41 ++ sphinx_doc_src/cmds/vared.rst | 15 + sphinx_doc_src/cmds/wait.rst | 34 ++ sphinx_doc_src/cmds/while.rst | 24 ++ sphinx_doc_src/index.rst | 7 + 86 files changed, 3805 insertions(+) create mode 100644 sphinx_doc_src/cmds/abbr.rst create mode 100644 sphinx_doc_src/cmds/alias.rst create mode 100644 sphinx_doc_src/cmds/and.rst create mode 100644 sphinx_doc_src/cmds/argparse.rst create mode 100644 sphinx_doc_src/cmds/begin.rst create mode 100644 sphinx_doc_src/cmds/bg.rst create mode 100644 sphinx_doc_src/cmds/bind.rst create mode 100644 sphinx_doc_src/cmds/block.rst create mode 100644 sphinx_doc_src/cmds/break.rst create mode 100644 sphinx_doc_src/cmds/breakpoint.rst create mode 100644 sphinx_doc_src/cmds/builtin.rst create mode 100644 sphinx_doc_src/cmds/case.rst create mode 100644 sphinx_doc_src/cmds/cd.rst create mode 100644 sphinx_doc_src/cmds/cdh.rst create mode 100644 sphinx_doc_src/cmds/command.rst create mode 100644 sphinx_doc_src/cmds/commandline.rst create mode 100644 sphinx_doc_src/cmds/complete.rst create mode 100644 sphinx_doc_src/cmds/contains.rst create mode 100644 sphinx_doc_src/cmds/continue.rst create mode 100644 sphinx_doc_src/cmds/count.rst create mode 100644 sphinx_doc_src/cmds/dirh.rst create mode 100644 sphinx_doc_src/cmds/dirs.rst create mode 100644 sphinx_doc_src/cmds/disown.rst create mode 100644 sphinx_doc_src/cmds/echo.rst create mode 100644 sphinx_doc_src/cmds/else.rst create mode 100644 sphinx_doc_src/cmds/emit.rst create mode 100644 sphinx_doc_src/cmds/end.rst create mode 100644 sphinx_doc_src/cmds/eval.rst create mode 100644 sphinx_doc_src/cmds/exec.rst create mode 100644 sphinx_doc_src/cmds/exit.rst create mode 100644 sphinx_doc_src/cmds/false.rst create mode 100644 sphinx_doc_src/cmds/fg.rst create mode 100644 sphinx_doc_src/cmds/fish.rst create mode 100644 sphinx_doc_src/cmds/fish_breakpoint_prompt.rst create mode 100644 sphinx_doc_src/cmds/fish_config.rst create mode 100644 sphinx_doc_src/cmds/fish_indent.rst create mode 100644 sphinx_doc_src/cmds/fish_key_reader.rst create mode 100644 sphinx_doc_src/cmds/fish_mode_prompt.rst create mode 100644 sphinx_doc_src/cmds/fish_opt.rst create mode 100644 sphinx_doc_src/cmds/fish_prompt.rst create mode 100644 sphinx_doc_src/cmds/fish_right_prompt.rst create mode 100644 sphinx_doc_src/cmds/fish_update_completions.rst create mode 100644 sphinx_doc_src/cmds/fish_vi_mode.rst create mode 100644 sphinx_doc_src/cmds/for.rst create mode 100644 sphinx_doc_src/cmds/funced.rst create mode 100644 sphinx_doc_src/cmds/funcsave.rst create mode 100644 sphinx_doc_src/cmds/function.rst create mode 100644 sphinx_doc_src/cmds/functions.rst create mode 100644 sphinx_doc_src/cmds/help.rst create mode 100644 sphinx_doc_src/cmds/history.rst create mode 100644 sphinx_doc_src/cmds/if.rst create mode 100644 sphinx_doc_src/cmds/isatty.rst create mode 100644 sphinx_doc_src/cmds/jobs.rst create mode 100644 sphinx_doc_src/cmds/math.rst create mode 100644 sphinx_doc_src/cmds/nextd.rst create mode 100644 sphinx_doc_src/cmds/not.rst create mode 100644 sphinx_doc_src/cmds/open.rst create mode 100644 sphinx_doc_src/cmds/or.rst create mode 100644 sphinx_doc_src/cmds/popd.rst create mode 100644 sphinx_doc_src/cmds/prevd.rst create mode 100644 sphinx_doc_src/cmds/printf.rst create mode 100644 sphinx_doc_src/cmds/prompt_pwd.rst create mode 100644 sphinx_doc_src/cmds/psub.rst create mode 100644 sphinx_doc_src/cmds/pushd.rst create mode 100644 sphinx_doc_src/cmds/pwd.rst create mode 100644 sphinx_doc_src/cmds/random.rst create mode 100644 sphinx_doc_src/cmds/read.rst create mode 100644 sphinx_doc_src/cmds/realpath.rst create mode 100644 sphinx_doc_src/cmds/return.rst create mode 100644 sphinx_doc_src/cmds/set.rst create mode 100644 sphinx_doc_src/cmds/set_color.rst create mode 100644 sphinx_doc_src/cmds/source.rst create mode 100644 sphinx_doc_src/cmds/status.rst create mode 100644 sphinx_doc_src/cmds/string.rst create mode 100644 sphinx_doc_src/cmds/suspend.rst create mode 100644 sphinx_doc_src/cmds/switch.rst create mode 100644 sphinx_doc_src/cmds/test.rst create mode 100644 sphinx_doc_src/cmds/trap.rst create mode 100644 sphinx_doc_src/cmds/true.rst create mode 100644 sphinx_doc_src/cmds/type.rst create mode 100644 sphinx_doc_src/cmds/ulimit.rst create mode 100644 sphinx_doc_src/cmds/umask.rst create mode 100644 sphinx_doc_src/cmds/vared.rst create mode 100644 sphinx_doc_src/cmds/wait.rst create mode 100644 sphinx_doc_src/cmds/while.rst diff --git a/sphinx_doc_src/cmds/abbr.rst b/sphinx_doc_src/cmds/abbr.rst new file mode 100644 index 000000000..76b0cf5c9 --- /dev/null +++ b/sphinx_doc_src/cmds/abbr.rst @@ -0,0 +1,80 @@ +\section abbr abbr - manage fish abbreviations + +\subsection abbr-synopsis Synopsis +\fish{synopsis} +abbr --add [SCOPE] WORD EXPANSION +abbr --erase word +abbr --rename [SCOPE] OLD_WORD NEW_WORD +abbr --show +abbr --list +\endfish + +\subsection abbr-description Description + +`abbr` manages abbreviations - user-defined words that are replaced with longer phrases after they are entered. + +For example, a frequently-run command like `git checkout` can be abbreviated to `gco`. After entering `gco` and pressing @key{Space} or @key{Enter}, the full text `git checkout` will appear in the command line. + +\subsection abbr-options Options + +The following options are available: + +- `-a WORD EXPANSION` or `--add WORD EXPANSION` Adds a new abbreviation, causing WORD to be expanded to PHRASE. + +- `-r OLD_WORD NEW_WORD` or `--rename OLD_WORD NEW_WORD` Renames an abbreviation, from OLD_WORD to NEW_WORD. + +- `-s` or `--show` Show all abbreviations in a manner suitable for export and import. + +- `-l` or `--list` Lists all abbreviated words. + +- `-e WORD` or `--erase WORD` Erase the abbreviation WORD. + +In addition, when adding abbreviations: + +- `-g` or `--global` to use a global variable. +- `-U` or `--universal` to use a universal variable (default). + +See the "Internals" section for more on them. + +\subsection abbr-example Examples + +\fish +abbr -a -g gco git checkout +\endfish +Add a new abbreviation where `gco` will be replaced with `git checkout` global to the current shell. This abbreviation will not be automatically visible to other shells unless the same command is run in those shells (such as when executing the commands in config.fish). + +\fish +abbr -a -U l less +\endfish +Add a new abbreviation where `l` will be replaced with `less` universal so all shells. Note that you omit the `-U` since it is the default. + +\fish +abbr -r gco gch +\endfish +Renames an existing abbreviation from `gco` to `gch`. + +\fish +abbr -e gco +\endfish +Erase the `gco` abbreviation. + +\fish +ssh another_host abbr -s | source +\endfish +Import the abbreviations defined on another_host over SSH. + +\subsection abbr-internals Internals +Each abbreviation is stored in its own global or universal variable. The name consists of the prefix `_fish_abbr_` followed by the WORD after being transformed by `string escape style=var`. The WORD cannot contain a space but all other characters are legal. + +Defining an abbreviation with global scope is slightly faster than universal scope (which is the default). But in general you'll only want to use the global scope when defining abbreviations in a startup script like `~/.config/fish/config.fish` like this: + +\fish +if status --is-interactive + abbr --add --global first 'echo my first abbreviation' + abbr --add --global second 'echo my second abbreviation' + abbr --add --global gco git checkout + # etcetera +end +\endfish + +You can create abbreviations interactively and they will be visible to other fish sessions if you use the `-U` or `--universal` flag or don't explicitly specify the scope and the abbreviation isn't already defined with global scope. If you want it to be visible only to the current shell use the `-g` or `--global` flag. diff --git a/sphinx_doc_src/cmds/alias.rst b/sphinx_doc_src/cmds/alias.rst new file mode 100644 index 000000000..606a05ec7 --- /dev/null +++ b/sphinx_doc_src/cmds/alias.rst @@ -0,0 +1,41 @@ +\section alias alias - create a function + +\subsection alias-synopsis Synopsis +\fish{synopsis} +alias +alias [OPTIONS] NAME DEFINITION +alias [OPTIONS] NAME=DEFINITION +\endfish + +\subsection alias-description Description + +`alias` is a simple wrapper for the `function` builtin, which creates a function wrapping a command. It has similar syntax to POSIX shell `alias`. For other uses, it is recommended to define a function. + +`fish` marks functions that have been created by `alias` by including the command used to create them in the function description. You can list `alias`-created functions by running `alias` without arguments. They must be erased using `functions -e`. + +- `NAME` is the name of the alias +- `DEFINITION` is the actual command to execute. The string `$argv` will be appended. + +You cannot create an alias to a function with the same name. Note that spaces need to be escaped in the call to `alias` just like at the command line, _even inside quoted parts_. + +The following options are available: + +- `-h` or `--help` displays help about using this command. + +- `-s` or `--save` Automatically save the function created by the alias into your fish configuration directory using funcsave. + +\subsection alias-example Example + +The following code will create `rmi`, which runs `rm` with additional arguments on every invocation. + +\fish +alias rmi="rm -i" + +# This is equivalent to entering the following function: +function rmi --wraps rm --description 'alias rmi=rm -i' + rm -i $argv +end + +# This needs to have the spaces escaped or "Chrome.app..." will be seen as an argument to "/Applications/Google": +alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome banana' +\endfish diff --git a/sphinx_doc_src/cmds/and.rst b/sphinx_doc_src/cmds/and.rst new file mode 100644 index 000000000..3757847de --- /dev/null +++ b/sphinx_doc_src/cmds/and.rst @@ -0,0 +1,23 @@ +\section and and - conditionally execute a command + +\subsection and-synopsis Synopsis +\fish{synopsis} +COMMAND1; and COMMAND2 +\endfish + +\subsection and-description Description + +`and` is used to execute a command if the previous command was successful (returned a status of 0). + +`and` statements may be used as part of the condition in an `if` or `while` block. See the documentation for `if` and `while` for examples. + +`and` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. + +\subsection and-example Example + +The following code runs the `make` command to build a program. If the build succeeds, `make`'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and `make clean` is run, which removes the files created by the build process. + +\fish +make; and make install; or make clean +\endfish + diff --git a/sphinx_doc_src/cmds/argparse.rst b/sphinx_doc_src/cmds/argparse.rst new file mode 100644 index 000000000..70278198a --- /dev/null +++ b/sphinx_doc_src/cmds/argparse.rst @@ -0,0 +1,131 @@ +\section argparse argparse - parse options passed to a fish script or function + +\subsection argparse-synopsis Synopsis +\fish{synopsis} +argparse [OPTIONS] OPTION_SPEC... -- [ARG...] +\endfish + +\subsection argparse-description Description + +This command makes it easy for fish scripts and functions to handle arguments in a manner 100% identical to how fish builtin commands handle their arguments. You pass a sequence of arguments that define the options recognized, followed by a literal `--`, then the arguments to be parsed (which might also include a literal `--`). More on this in the usage section below. + +Each OPTION_SPEC can be written in the domain specific language described below or created using the companion `fish_opt` command. All OPTION_SPECs must appear after any argparse flags and before the `--` that separates them from the arguments to be parsed. + +Each option that is seen in the ARG list will result in a var name of the form `_flag_X`, where `X` is the short flag letter and the long flag name. The OPTION_SPEC always requires a short flag even if it can't be used. So there will always be `_flag_X` var set using the short flag letter if the corresponding short or long flag is seen. The long flag name var (e.g., `_flag_help`) will only be defined, obviously, if the OPTION_SPEC includes a long flag name. + +For example `_flag_h` and `_flag_help` if `-h` or `--help` is seen. The var will be set with local scope (i.e., as if the script had done `set -l _flag_X`). If the flag is a boolean (that is, does not have an associated value) the values are the short and long flags seen. If the option is not a boolean flag the values will be zero or more values corresponding to the values collected when the ARG list is processed. If the flag was not seen the flag var will not be set. + +\subsection argparse-options Options + +The following `argparse` options are available. They must appear before all OPTION_SPECs: + +- `-n` or `--name` is the command name to insert into any error messages. If you don't provide this value `argparse` will be used. + +- `-x` or `--exclusive` should be followed by a comma separated list of short of long options that are mutually exclusive. You can use this option more than once to define multiple sets of mutually exclusive options. + +- `-N` or `--min-args` is followed by an integer that defines the minimum number of acceptable non-option arguments. The default is zero. + +- `-X` or `--max-args` is followed by an integer that defines the maximum number of acceptable non-option arguments. The default is infinity. + +- `-s` or `--stop-nonopt` causes scanning the arguments to stop as soon as the first non-option argument is seen. Using this arg is equivalent to calling the C function `getopt_long()` with the short options starting with a `+` symbol. This is sometimes known as "POSIXLY CORRECT". If this flag is not used then arguments are reordered (i.e., permuted) so that all non-option arguments are moved after option arguments. This mode has several uses but the main one is to implement a command that has subcommands. + +- `-h` or `--help` displays help about using this command. + +\subsection argparse-usage Usage + +Using this command involves passing two sets of arguments separated by `--`. The first set consists of one or more option specifications (`OPTION_SPEC` above) and options that modify the behavior of `argparse`. These must be listed before the `--` argument. The second set are the arguments to be parsed in accordance with the option specifications. They occur after the `--` argument and can be empty. More about this below but here is a simple example that might be used in a function named `my_function`: + +\fish +argparse --name=my_function 'h/help' 'n/name=' -- $argv +or return +\endfish + +If `$argv` is empty then there is nothing to parse and `argparse` returns zero to indicate success. If `$argv` is not empty then it is checked for flags `-h`, `--help`, `-n` and `--name`. If they are found they are removed from the arguments and local variables (more on this below) are set so the script can determine which options were seen. Assuming `$argv` doesn't have any errors, such as a missing mandatory value for an option, then `argparse` exits with status zero. Otherwise it writes appropriate error messages to stderr and exits with a status of one. + +The `--` argument is required. You do not have to include any arguments after the `--` but you must include the `--`. For example, this is acceptable: + +\fish +set -l argv +argparse 'h/help' 'n/name' -- $argv +\endfish + +But this is not: + +\fish +set -l argv +argparse 'h/help' 'n/name' $argv +\endfish + +The first `--` seen is what allows the `argparse` command to reliably separate the option specifications from the command arguments. + +\subsection argparse-option-specs Option Specifications + +Each option specification is a string composed of + +- A short flag letter (which is mandatory). It must be an alphanumeric or "#". The "#" character is special and means that a flag of the form `-123` is valid. The short flag "#" must be followed by "-" (since the short name isn't otherwise valid since `_flag_#` is not a valid var name) and must be followed by a long flag name with no modifiers. + +- A `/` if the short flag can be used by someone invoking your command else `-` if it should not be exposed as a valid short flag. If there is no long flag name these characters should be omitted. You can also specify a '#' to indicate the short and long flag names can be used and the value can be specified as an implicit int; i.e., a flag of the form `-NNN`. + +- A long flag name which is optional. If not present then only the short flag letter can be used. + +- Nothing if the flag is a boolean that takes no argument or is an implicit int flag, else + +- `=` if it requires a value and only the last instance of the flag is saved, else + +- `=?` it takes an optional value and only the last instance of the flag is saved, else + +- `=+` if it requires a value and each instance of the flag is saved. + +- Optionally a `!` followed by fish script to validate the value. Typically this will be a function to run. If the return status is zero the value for the flag is valid. If non-zero the value is invalid. Any error messages should be written to stdout (not stderr). See the section on Flag Value Validation for more information. + +See the `fish_opt` command for a friendlier but more verbose way to create option specifications. + +In the following examples if a flag is not seen when parsing the arguments then the corresponding _flag_X var(s) will not be set. + +\subsection argparse-validation Flag Value Validation + +It is common to want to validate the the value provided for an option satisfies some criteria. For example, that it is a valid integer within a specific range. You can always do this after `argparse` returns but you can also request that `argparse` perform the validation by executing arbitrary fish script. To do so simply append an `!` (exclamation-mark) then the fish script to be run. When that code is executed three vars will be defined: + +- `_argparse_cmd` will be set to the value of the value of the `argparse --name` value. + +- `_flag_name` will be set to the short or long flag that being processed. + +- `_flag_value` will be set to the value associated with the flag being processed. + +If you do this via a function it should be defined with the `--no-scope-shadowing` flag. Otherwise it won't have access to those variables. + +The script should write any error messages to stdout, not stderr. It should return a status of zero if the flag value is valid otherwise a non-zero status to indicate it is invalid. + +Fish ships with a `_validate_int` function that accepts a `--min` and `--max` flag. Let's say your command accepts a `-m` or `--max` flag and the minimum allowable value is zero and the maximum is 5. You would define the option like this: `m/max=!_validate_int --min 0 --max 5`. The default if you just call `_validate_int` without those flags is to simply check that the value is a valid integer with no limits on the min or max value allowed. + +\subsection argparse-optspec-examples Example OPTION_SPECs + +Some OPTION_SPEC examples: + +- `h/help` means that both `-h` and `--help` are valid. The flag is a boolean and can be used more than once. If either flag is used then `_flag_h` and `_flag_help` will be set to the count of how many times either flag was seen. + +- `h-help` means that only `--help` is valid. The flag is a boolean and can be used more than once. If the long flag is used then `_flag_h` and `_flag_help` will be set to the count of how many times the long flag was seen. + +- `n/name=` means that both `-n` and `--name` are valid. It requires a value and can be used at most once. If the flag is seen then `_flag_n` and `_flag_name` will be set with the single mandatory value associated with the flag. + +- `n/name=?` means that both `-n` and `--name` are valid. It accepts an optional value and can be used at most once. If the flag is seen then `_flag_n` and `_flag_name` will be set with the value associated with the flag if one was provided else it will be set with no values. + +- `n-name=+` means that only `--name` is valid. It requires a value and can be used more than once. If the flag is seen then `_flag_n` and `_flag_name` will be set with the values associated with each occurrence of the flag. + +- `x` means that only `-x` is valid. It is a boolean can can be used more than once. If it is seen then `_flag_x` will be set to the count of how many times the flag was seen. + +- `x=`, `x=?`, and `x=+` are similar to the n/name examples above but there is no long flag alternative to the short flag `-x`. + +- `x-` is not valid since there is no long flag name and therefore the short flag, `-x`, has to be usable. + +- `#-max` means that flags matching the regex "^--?\d+$" are valid. When seen they are assigned to the variable `_flag_max`. This allows any valid positive or negative integer to be specified by prefixing it with a single "-". Many commands support this idiom. For example `head -3 /a/file` to emit only the first three lines of /a/file. + +- `n#max` means that flags matching the regex "^--?\d+$" are valid. When seen they are assigned to the variables `_flag_n` and `_flag_max`. This allows any valid positive or negative integer to be specified by prefixing it with a single "-". Many commands support this idiom. For example `head -3 /a/file` to emit only the first three lines of /a/file. You can also specify the value using either flag: `-n NNN` or `--max NNN` in this example. + +After parsing the arguments the `argv` var is set with local scope to any values not already consumed during flag processing. If there are not unbound values the var is set but `count $argv` will be zero. + +If an error occurs during argparse processing it will exit with a non-zero status and print error messages to stderr. + +\subsection argparse-notes Notes + +Prior to the addition of this builtin command in the 2.7.0 release there were two main ways to parse the arguments passed to a fish script or function. One way was to use the OS provided `getopt` command. The problem with that is that the GNU and BSD implementations are not compatible. Which makes using that external command difficult other than in trivial situations. The other way is to iterate over `$argv` and use the fish `switch` statement to decide how to handle the argument. That, however, involves a huge amount of boilerplate code. It is also borderline impossible to implement the same behavior as builtin commands. diff --git a/sphinx_doc_src/cmds/begin.rst b/sphinx_doc_src/cmds/begin.rst new file mode 100644 index 000000000..dd008bda9 --- /dev/null +++ b/sphinx_doc_src/cmds/begin.rst @@ -0,0 +1,46 @@ +\section begin begin - start a new block of code + +\subsection begin-synopsis Synopsis +\fish{synopsis} +begin; [COMMANDS...;] end +\endfish + +\subsection begin-description Description + +`begin` is used to create a new block of code. + +A block allows the introduction of a new variable scope, redirection of the input or output of a set of commands as a group, or to specify precedence when using the conditional commands like `and`. + +The block is unconditionally executed. `begin; ...; end` is equivalent to `if true; ...; end`. + +`begin` does not change the current exit status itself. After the block has completed, `$status` will be set to the status returned by the most recent command. + + +\subsection begin-example Example + +The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends. + +\fish +begin + set -l PIRATE Yarrr + + ... +end + +echo $PIRATE +# This will not output anything, since the PIRATE variable +# went out of scope at the end of the block +\endfish + +In the following code, all output is redirected to the file out.html. + +\fish +begin + echo $xml_header + echo $html_header + if test -e $file + ... + end + ... +end > out.html +\endfish diff --git a/sphinx_doc_src/cmds/bg.rst b/sphinx_doc_src/cmds/bg.rst new file mode 100644 index 000000000..13733f58e --- /dev/null +++ b/sphinx_doc_src/cmds/bg.rst @@ -0,0 +1,25 @@ +\section bg bg - send jobs to background + +\subsection bg-synopsis Synopsis +\fish{synopsis} +bg [PID...] +\endfish + +\subsection bg-description Description + +`bg` sends jobs to the background, resuming them if they are stopped. + +A background job is executed simultaneously with fish, and does not have access to the keyboard. If no job is specified, the last job to be used is put in the background. If PID is specified, the jobs with the specified process group IDs are put in the background. + +When at least one of the arguments isn't a valid job specifier (i.e. PID), +`bg` will print an error without backgrounding anything. + +When all arguments are valid job specifiers, bg will background all matching jobs that exist. + +\subsection bg-example Example + +`bg 123 456 789` will background 123, 456 and 789. + +If only 123 and 789 exist, it will still background them and print an error about 456. + +`bg 123 banana` or `bg banana 123` will complain that "banana" is not a valid job specifier. diff --git a/sphinx_doc_src/cmds/bind.rst b/sphinx_doc_src/cmds/bind.rst new file mode 100644 index 000000000..d778cd31e --- /dev/null +++ b/sphinx_doc_src/cmds/bind.rst @@ -0,0 +1,170 @@ +\section bind bind - handle fish key bindings + +\subsection bind-synopsis Synopsis +\fish{synopsis} +bind [(-M | --mode) MODE] [(-m | --sets-mode) NEW_MODE] + [--preset | --user] + [(-s | --silent)] [(-k | --key)] SEQUENCE COMMAND [COMMAND...] +bind [(-M | --mode) MODE] [(-k | --key)] [--preset] [--user] SEQUENCE +bind (-K | --key-names) [(-a | --all)] [--preset] [--user] +bind (-f | --function-names) +bind (-L | --list-modes) +bind (-e | --erase) [(-M | --mode) MODE] + [--preset] [--user] + (-a | --all | [(-k | --key)] SEQUENCE [SEQUENCE...]) +\endfish + +\subsection bind-description Description + +`bind` adds a binding for the specified key sequence to the specified command. + +SEQUENCE is the character sequence to bind to. These should be written as fish escape sequences. For example, because pressing the Alt key and another character sends that character prefixed with an escape character, Alt-based key bindings can be written using the `\e` escape. For example, @key{Alt,w} can be written as `\ew`. The control character can be written in much the same way using the `\c` escape, for example @key{Control,X} (^X) can be written as `\cx`. Note that Alt-based key bindings are case sensitive and Control-based key bindings are not. This is a constraint of text-based terminals, not `fish`. + +The default key binding can be set by specifying a `SEQUENCE` of the empty string (that is, ```''``` ). It will be used whenever no other binding matches. For most key bindings, it makes sense to use the `self-insert` function (i.e. ```bind '' self-insert```) as the default keybinding. This will insert any keystrokes not specifically bound to into the editor. Non- printable characters are ignored by the editor, so this will not result in control sequences being printable. + +If the `-k` switch is used, the name of the key (such as 'down', 'up' or 'backspace') is used instead of a sequence. The names used are the same as the corresponding curses variables, but without the 'key_' prefix. (See `terminfo(5)` for more information, or use `bind --key-names` for a list of all available named keys.) If used in conjunction with the `-s` switch, `bind` will silently ignore bindings to named keys that are not found in termcap for the current `$TERMINAL`, otherwise a warning is emitted. + +`COMMAND` can be any fish command, but it can also be one of a set of special input functions. These include functions for moving the cursor, operating on the kill-ring, performing tab completion, etc. Use `bind --function-names` for a complete list of these input functions. + +When `COMMAND` is a shellscript command, it is a good practice to put the actual code into a function and simply bind to the function name. This way it becomes significantly easier to test the function while editing, and the result is usually more readable as well. + +If a script produces output, it should finish by calling `commandline -f repaint` to tell fish that a repaint is in order. + +When multiple `COMMAND`s are provided, they are all run in the specified order when the key is pressed. Note that special input functions cannot be combined with ordinary shell script commands. The commands must be entirely a sequence of special input functions (from `bind -f`) or all shell script commands (i.e., valid fish script). + +If no `SEQUENCE` is provided, all bindings (or just the bindings in the specified `MODE`) are printed. If `SEQUENCE` is provided without `COMMAND`, just the binding matching that sequence is printed. + +To save custom keybindings, put the `bind` statements into config.fish. Alternatively, fish also automatically executes a function called `fish_user_key_bindings` if it exists. + +Key bindings may use "modes", which mimics Vi's modal input behavior. The default mode is "default", and every bind applies to a single mode. The mode can be viewed/changed with the `$fish_bind_mode` variable. + +The following parameters are available: + +- `-k` or `--key` Specify a key name, such as 'left' or 'backspace' instead of a character sequence + +- `-K` or `--key-names` Display a list of available key names. Specifying `-a` or `--all` includes keys that don't have a known mapping + +- `-f` or `--function-names` Display a list of available input functions + +- `-L` or `--list-modes` Display a list of defined bind modes + +- `-M MODE` or `--mode MODE` Specify a bind mode that the bind is used in. Defaults to "default" + +- `-m NEW_MODE` or `--sets-mode NEW_MODE` Change the current mode to `NEW_MODE` after this binding is executed + +- `-e` or `--erase` Erase the binding with the given sequence and mode instead of defining a new one. Multiple sequences can be specified with this flag. Specifying `-a` or `--all` with `-M` or `--mode` erases all binds in the given mode regardless of sequence. Specifying `-a` or `--all` without `-M` or `--mode` erases all binds in all modes regardless of sequence. + +- `-a` or `--all` See `--erase` and `--key-names` + +- `--preset` and `--user` specify if bind should operate on user or preset bindings. User bindings take precedence over preset bindings when fish looks up mappings. By default, all `bind` invocations work on the "user" level except for listing, which will show both levels. All invocations except for inserting new bindings can operate on both levels at the same time. `--preset` should only be used in full binding sets (like when working on `fish_vi_key_bindings`). + +\subsection bind-functions Special input functions +The following special input functions are available: + +- `accept-autosuggestion`, accept the current autosuggestion completely + +- `backward-char`, moves one character to the left + +- `backward-bigword`, move one whitespace-delimited word to the left + +- `backward-delete-char`, deletes one character of input to the left of the cursor + +- `backward-kill-bigword`, move the whitespace-delimited word to the left of the cursor to the killring + +- `backward-kill-line`, move everything from the beginning of the line to the cursor to the killring + +- `backward-kill-path-component`, move one path component to the left of the cursor (everything from the last "/" or whitespace exclusive) to the killring + +- `backward-kill-word`, move the word to the left of the cursor to the killring + +- `backward-word`, move one word to the left + +- `beginning-of-buffer`, moves to the beginning of the buffer, i.e. the start of the first line + +- `beginning-of-history`, move to the beginning of the history + +- `beginning-of-line`, move to the beginning of the line + +- `begin-selection`, start selecting text + +- `capitalize-word`, make the current word begin with a capital letter + +- `complete`, guess the remainder of the current token + +- `complete-and-search`, invoke the searchable pager on completion options (for convenience, this also moves backwards in the completion pager) + +- `delete-char`, delete one character to the right of the cursor + +- `downcase-word`, make the current word lowercase + +- `end-of-buffer`, moves to the end of the buffer, i.e. the end of the first line + +- `end-of-history`, move to the end of the history + +- `end-of-line`, move to the end of the line + +- `end-selection`, end selecting text + +- `forward-bigword`, move one whitespace-delimited word to the right + +- `forward-char`, move one character to the right + +- `forward-word`, move one word to the right + +- `history-search-backward`, search the history for the previous match + +- `history-search-forward`, search the history for the next match + +- `kill-bigword`, move the next whitespace-delimited word to the killring + +- `kill-line`, move everything from the cursor to the end of the line to the killring + +- `kill-selection`, move the selected text to the killring + +- `kill-whole-line`, move the line to the killring + +- `kill-word`, move the next word to the killring + +- `pager-toggle-search`, toggles the search field if the completions pager is visible. + +- `suppress-autosuggestion`, remove the current autosuggestion + +- `swap-selection-start-stop`, go to the other end of the highlighted text without changing the selection + +- `transpose-chars`, transpose two characters to the left of the cursor + +- `transpose-words`, transpose two words to the left of the cursor + +- `upcase-word`, make the current word uppercase + +- `yank`, insert the latest entry of the killring into the buffer + +- `yank-pop`, rotate to the previous entry of the killring + + +\subsection bind-example Examples + +\fish +bind \\cd 'exit' +\endfish +Causes `fish` to exit when @key{Control,D} is pressed. + +\fish +bind -k ppage history-search-backward +\endfish +Performs a history search when the @key{Page Up} key is pressed. + +\fish +set -g fish_key_bindings fish_vi_key_bindings +bind -M insert \\cc kill-whole-line force-repaint +\endfish +Turns on Vi key bindings and rebinds @key{Control,C} to clear the input line. + + +\subsection special-case-escape Special Case: The escape Character + +The escape key can be used standalone, for example, to switch from insertion mode to normal mode when using Vi keybindings. Escape may also be used as a "meta" key, to indicate the start of an escape sequence, such as function or arrow keys. Custom bindings can also be defined that begin with an escape character. + +fish waits for a period after receiving the escape character, to determine whether it is standalone or part of an escape sequence. While waiting, additional key presses make the escape key behave as a meta key. If no other key presses come in, it is handled as a standalone escape. The waiting period is set to 300 milliseconds (0.3 seconds) in the default key bindings and 10 milliseconds in the vi key bindings. It can be configured by setting the `fish_escape_delay_ms` variable to a value between 10 and 5000 ms. It is recommended that this be a universal variable that you set once from an interactive session. + +Note: fish 2.2.0 and earlier used a default of 10 milliseconds, and provided no way to configure it. That effectively made it impossible to use escape as a meta key. diff --git a/sphinx_doc_src/cmds/block.rst b/sphinx_doc_src/cmds/block.rst new file mode 100644 index 000000000..9fbbade83 --- /dev/null +++ b/sphinx_doc_src/cmds/block.rst @@ -0,0 +1,46 @@ +\section block block - temporarily block delivery of events + +\subsection block-synopsis Synopsis +\fish{synopsis} +block [OPTIONS...] +\endfish + +\subsection block-description Description + +`block` prevents events triggered by `fish` or the `emit` command from being delivered and acted upon while the block is in place. + +In functions, `block` can be useful while performing work that should not be interrupted by the shell. + +The block can be removed. Any events which triggered while the block was in place will then be delivered. + +Event blocks should not be confused with code blocks, which are created with `begin`, `if`, `while` or `for` + +The following parameters are available: + +- `-l` or `--local` Release the block automatically at the end of the current innermost code block scope + +- `-g` or `--global` Never automatically release the lock + +- `-e` or `--erase` Release global block + + +\subsection block-example Example + +\fish +# Create a function that listens for events +function --on-event foo foo; echo 'foo fired'; end + +# Block the delivery of events +block -g + +emit foo +# No output will be produced + +block -e +# 'foo fired' will now be printed +\endfish + + +\subsection block-notes Notes + +Note that events are only received from the current fish process as there is no way to send events from one fish process to another. diff --git a/sphinx_doc_src/cmds/break.rst b/sphinx_doc_src/cmds/break.rst new file mode 100644 index 000000000..32672c09f --- /dev/null +++ b/sphinx_doc_src/cmds/break.rst @@ -0,0 +1,25 @@ +\section break break - stop the current inner loop + +\subsection break-synopsis Synopsis +\fish{synopsis} +LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] end +\endfish + +\subsection break-description Description + +`break` halts a currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. + +There are no parameters for `break`. + + +\subsection break-example Example +The following code searches all .c files for "smurf", and halts at the first occurrence. + +\fish +for i in *.c + if grep smurf $i + echo Smurfs are present in $i + break + end +end +\endfish diff --git a/sphinx_doc_src/cmds/breakpoint.rst b/sphinx_doc_src/cmds/breakpoint.rst new file mode 100644 index 000000000..8645c18dd --- /dev/null +++ b/sphinx_doc_src/cmds/breakpoint.rst @@ -0,0 +1,14 @@ +\section breakpoint breakpoint - Launch debug mode + +\subsection breakpoint-synopsis Synopsis +\fish{synopsis} +breakpoint +\endfish + +\subsection breakpoint-description Description + +`breakpoint` is used to halt a running script and launch an interactive debugging prompt. + +For more details, see Debugging fish scripts in the `fish` manual. + +There are no parameters for `breakpoint`. diff --git a/sphinx_doc_src/cmds/builtin.rst b/sphinx_doc_src/cmds/builtin.rst new file mode 100644 index 000000000..4c465ef18 --- /dev/null +++ b/sphinx_doc_src/cmds/builtin.rst @@ -0,0 +1,22 @@ +\section builtin builtin - run a builtin command + +\subsection builtin-synopsis Synopsis +\fish{synopsis} +builtin BUILTINNAME [OPTIONS...] +\endfish + +\subsection builtin-description Description + +`builtin` forces the shell to use a builtin command, rather than a function or program. + +The following parameters are available: + +- `-n` or `--names` List the names of all defined builtins + + +\subsection builtin-example Example + +\fish +builtin jobs +# executes the jobs builtin, even if a function named jobs exists +\endfish diff --git a/sphinx_doc_src/cmds/case.rst b/sphinx_doc_src/cmds/case.rst new file mode 100644 index 000000000..065c19e9b --- /dev/null +++ b/sphinx_doc_src/cmds/case.rst @@ -0,0 +1,42 @@ +\section case case - conditionally execute a block of commands + +\subsection case-synopsis Synopsis +\fish{synopsis} +switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end +\endfish + +\subsection case-description Description + +`switch` executes one of several blocks of commands, depending on whether a specified value matches one of several values. `case` is used together with the `switch` statement in order to determine which block should be executed. + +Each `case` command is given one or more parameters. The first `case` command with a parameter that matches the string specified in the switch command will be evaluated. `case` parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames. + +Note that fish does not fall through on case statements. Only the first matching case is executed. + +Note that command substitutions in a case statement will be evaluated even if its body is not taken. All substitutions, including command substitutions, must be performed before the value can be compared against the parameter. + + +\subsection case-example Example + +Say \$animal contains the name of an animal. Then this code would classify it: + +\fish +switch $animal + case cat + echo evil + case wolf dog human moose dolphin whale + echo mammal + case duck goose albatross + echo bird + case shark trout stingray + echo fish + # Note that the next case has a wildcard which is quoted + case '*' + echo I have no idea what a $animal is +end +\endfish + +If the above code was run with `$animal` set to `whale`, the output +would be `mammal`. + +If `$animal` was set to "banana", it would print "I have no idea what a banana is". diff --git a/sphinx_doc_src/cmds/cd.rst b/sphinx_doc_src/cmds/cd.rst new file mode 100644 index 000000000..748f0c322 --- /dev/null +++ b/sphinx_doc_src/cmds/cd.rst @@ -0,0 +1,33 @@ +\section cd cd - change directory + +\subsection cd-synopsis Synopsis +\fish{synopsis} +cd [DIRECTORY] +\endfish + +\subsection cd-description Description +`cd` changes the current working directory. + +If `DIRECTORY` is supplied, it will become the new directory. If no parameter is given, the contents of the `HOME` environment variable will be used. + +If `DIRECTORY` is a relative path, the paths found in the `CDPATH` environment variable array will be tried as prefixes for the specified path. + +Note that the shell will attempt to change directory without requiring `cd` if the name of a directory is provided (starting with `.`, `/` or `~`, or ending with `/`). + +Fish also ships a wrapper function around the builtin `cd` that understands `cd -` as changing to the previous directory. See also `prevd`. This wrapper function maintains a history of the 25 most recently visited directories in the `$dirprev` and `$dirnext` global variables. If you make those universal variables your `cd` history is shared among all fish instances. + +As a special case, `cd .` is equivalent to `cd $PWD`, which is useful in cases where a mountpoint has been recycled or a directory has been removed and recreated. + +\subsection cd-example Examples + +\fish +cd +# changes the working directory to your home directory. + +cd /usr/src/fish-shell +# changes the working directory to /usr/src/fish-shell +\endfish + +\subsection cd-see-also See Also + +See also the `cdh` command for changing to a recently visited directory. diff --git a/sphinx_doc_src/cmds/cdh.rst b/sphinx_doc_src/cmds/cdh.rst new file mode 100644 index 000000000..7d18acd86 --- /dev/null +++ b/sphinx_doc_src/cmds/cdh.rst @@ -0,0 +1,16 @@ +\section cdh cdh - change to a recently visited directory + +\subsection cdh-synopsis Synopsis +\fish{synopsis} +cdh [ directory ] +\endfish + +\subsection cdh-description Description + +`cdh` with no arguments presents a list of recently visited directories. You can then select one of the entries by letter or number. You can also press @key{tab} to use the completion pager to select an item from the list. If you give it a single argument it is equivalent to `cd directory`. + +Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables which this command manipulates. If you make those universal variables your `cd` history is shared among all fish instances. + +\subsection cdh-see-also See Also + +See also the `prevd` and `pushd` commands which also work with the recent `cd` history and are provided for compatibility with other shells. diff --git a/sphinx_doc_src/cmds/command.rst b/sphinx_doc_src/cmds/command.rst new file mode 100644 index 000000000..e4f5c2cf6 --- /dev/null +++ b/sphinx_doc_src/cmds/command.rst @@ -0,0 +1,30 @@ +\section command command - run a program + +\subsection command-synopsis Synopsis +\fish{synopsis} +command [OPTIONS] COMMANDNAME [ARGS...] +\endfish + +\subsection command-description Description + +`command` forces the shell to execute the program `COMMANDNAME` and ignore any functions or builtins with the same name. + +The following options are available: + +- `-a` or `--all` returns all the external commands that are found in `$PATH` in the order they are found. + +- `-q` or `--quiet`, in conjunction with `-s`, silences the output and prints nothing, setting only the exit code. + +- `-s` or `--search` returns the name of the external command that would be executed, or nothing if no file with the specified name could be found in the `$PATH`. + +With the `-s` option, `command` treats every argument as a separate command to look up and sets the exit status to 0 if any of the specified commands were found, or 1 if no commands could be found. Additionally passing a `-q` or `--quiet` option prevents any paths from being printed, like `type -q`, for testing only the exit status. + +For basic compatibility with POSIX `command`, the `-v` flag is recognized as an alias for `-s`. + +\subsection command-example Examples + +`command ls` causes fish to execute the `ls` program, even if an `ls` function exists. + +`command -s ls` returns the path to the `ls` program. + +`command -sq git; and command git log` runs `git log` only if `git` exists. diff --git a/sphinx_doc_src/cmds/commandline.rst b/sphinx_doc_src/cmds/commandline.rst new file mode 100644 index 000000000..d97001709 --- /dev/null +++ b/sphinx_doc_src/cmds/commandline.rst @@ -0,0 +1,82 @@ +\section commandline commandline - set or get the current command line buffer + +\subsection commandline-synopsis Synopsis +\fish{synopsis} +commandline [OPTIONS] [CMD] +\endfish + +\subsection commandline-description Description + +`commandline` can be used to set or get the current contents of the command line buffer. + +With no parameters, `commandline` returns the current value of the command line. + +With `CMD` specified, the command line buffer is erased and replaced with the contents of `CMD`. + +The following options are available: + +- `-C` or `--cursor` set or get the current cursor position, not the contents of the buffer. If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position. + +- `-f` or `--function` inject readline functions into the reader. This option cannot be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual key presses are read. + +The following options change the way `commandline` updates the command line buffer: + +- `-a` or `--append` do not remove the current commandline, append the specified string at the end of it + +- `-i` or `--insert` do not remove the current commandline, insert the specified string at the current cursor position + +- `-r` or `--replace` remove the current commandline and replace it with the specified string (default) + +The following options change what part of the commandline is printed or updated: + +- `-b` or `--current-buffer` select the entire buffer, including any displayed autosuggestion (default) + +- `-j` or `--current-job` select the current job + +- `-p` or `--current-process` select the current process + +- `-s` or `--current-selection` selects the current selection + +- `-t` or `--current-token` select the current token + +The following options change the way `commandline` prints the current commandline buffer: + +- `-c` or `--cut-at-cursor` only print selection up until the current cursor position + +- `-o` or `--tokenize` tokenize the selection and print one string-type token per line + +If `commandline` is called during a call to complete a given string using `complete -C STRING`, `commandline` will consider the specified string to be the current contents of the command line. + +The following options output metadata about the commandline state: + +- `-L` or `--line` print the line that the cursor is on, with the topmost line starting at 1 + +- `-S` or `--search-mode` evaluates to true if the commandline is performing a history search + +- `-P` or `--paging-mode` evaluates to true if the commandline is showing pager contents, such as tab completions + + +\subsection commandline-example Example + +`commandline -j $history[3]` replaces the job under the cursor with the third item from the command line history. + +If the commandline contains +\fish +>_ echo $fl___ounder >&2 | less; and echo $catfish +\endfish + +(with the cursor on the "o" of "flounder") + +Then the following invocations behave like this: +\fish +>_ commandline -t +$flounder +>_ commandline -ct +$fl +>_ commandline -b # or just commandline +echo $flounder >&2 | less; and echo $catfish +>_ commandline -p +echo $flounder >&2 +>_ commandline -j +echo $flounder >&2 | less +\endfish diff --git a/sphinx_doc_src/cmds/complete.rst b/sphinx_doc_src/cmds/complete.rst new file mode 100644 index 000000000..d295d1381 --- /dev/null +++ b/sphinx_doc_src/cmds/complete.rst @@ -0,0 +1,131 @@ +\section complete complete - edit command specific tab-completions + +\subsection complete-synopsis Synopsis +\fish{synopsis} +complete ( -c | --command | -p | --path ) COMMAND + [( -c | --command | -p | --path ) COMMAND]... + [( -e | --erase )] + [( -s | --short-option ) SHORT_OPTION]... + [( -l | --long-option | -o | --old-option ) LONG_OPTION]... + [( -a | --arguments ) OPTION_ARGUMENTS] + [( -k | --keep-order )] + [( -f | --no-files )] + [( -r | --require-parameter )] + [( -x | --exclusive )] + [( -w | --wraps ) WRAPPED_COMMAND]... + [( -n | --condition ) CONDITION] + [( -d | --description ) DESCRIPTION] +complete ( -C[STRING] | --do-complete[=STRING] ) +\endfish + +\subsection complete-description Description + +For an introduction to specifying completions, see Writing your own completions in +the fish manual. + +- `COMMAND` is the name of the command for which to add a completion. + +- `SHORT_OPTION` is a one character option for the command. + +- `LONG_OPTION` is a multi character option for the command. + +- `OPTION_ARGUMENTS` is parameter containing a space-separated list of possible option-arguments, which may contain command substitutions. + +- `DESCRIPTION` is a description of what the option and/or option arguments do. + +- `-c COMMAND` or `--command COMMAND` specifies that `COMMAND` is the name of the command. + +- `-p COMMAND` or `--path COMMAND` specifies that `COMMAND` is the absolute path of the program (optionally containing wildcards). + +- `-e` or `--erase` deletes the specified completion. + +- `-s SHORT_OPTION` or `--short-option=SHORT_OPTION` adds a short option to the completions list. + +- `-l LONG_OPTION` or `--long-option=LONG_OPTION` adds a GNU style long option to the completions list. + +- `-o LONG_OPTION` or `--old-option=LONG_OPTION` adds an old style long option to the completions list (See below for details). + +- `-a OPTION_ARGUMENTS` or `--arguments=OPTION_ARGUMENTS` adds the specified option arguments to the completions list. + +- `-k` or `--keep-order` preserves the order of the `OPTION_ARGUMENTS` specified via `-a` or `--arguments` instead of sorting alphabetically. + +- `-f` or `--no-files` specifies that the options specified by this completion may not be followed by a filename. + +- `-r` or `--require-parameter` specifies that the options specified by this completion always must have an option argument, i.e. may not be followed by another option. + +- `-x` or `--exclusive` implies both `-r` and `-f`. + +- `-w WRAPPED_COMMAND` or `--wraps=WRAPPED_COMMAND` causes the specified command to inherit completions from the wrapped command (See below for details). + +- `-n` or `--condition` specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases. + +- `-CSTRING` or `--do-complete=STRING` makes complete try to find all possible completions for the specified string. + +- `-C` or `--do-complete` with no argument makes complete try to find all possible completions for the current command line buffer. If the shell is not in interactive mode, an error is returned. + +- `-A` and `--authoritative` no longer do anything and are silently ignored. + +- `-u` and `--unauthoritative` no longer do anything and are silently ignored. + +Command specific tab-completions in `fish` are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '`-h`', '`-help`' or '`--help`'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are: + +- Short options, like '`-a`'. Short options are a single character long, are preceded by a single hyphen and may be grouped together (like '`-la`', which is equivalent to '`-l -a`'). Option arguments may be specified in the following parameter ('`-w 32`') or by appending the option with the value ('`-w32`'). + +- Old style long options, like '`-Wall`'. Old style long options can be more than one character long, are preceded by a single hyphen and may not be grouped together. Option arguments are specified in the following parameter ('`-ao null`'). + +- GNU style long options, like '`--colors`'. GNU style long options can be more than one character long, are preceded by two hyphens, and may not be grouped together. Option arguments may be specified in the following parameter ('`--quoting-style shell`') or by appending the option with a '`=`' and the value ('`--quoting-style=shell`'). GNU style long options may be abbreviated so long as the abbreviation is unique ('`--h`') is equivalent to '`--help`' if help is the only long option beginning with an 'h'). + +The options for specifying command name and command path may be used multiple times to define the same completions for multiple commands. + +The options for specifying command switches and wrapped commands may be used multiple times to define multiple completions for the command(s) in a single call. + +Invoking `complete` multiple times for the same command adds the new definitions on top of any existing completions defined for the command. + +When `-a` or `--arguments` is specified in conjunction with long, short, or old style options, the specified arguments are only used as completions when attempting to complete an argument for any of the specified options. If `-a` or `--arguments` is specified without any long, short, or old style options, the specified arguments are used when completing any argument to the command (except when completing an option argument that was specified with `-r` or `--require-parameter`). + +Command substitutions found in `OPTION_ARGUMENTS` are not expected to return a space-separated list of arguments. Instead they must return a newline-separated list of arguments, and each argument may optionally have a tab character followed by the argument description. Any description provided in this way overrides a description given with `-d` or `--description`. + +The `-w` or `--wraps` options causes the specified command to inherit completions from another command. The inheriting command is said to "wrap" the inherited command. The wrapping command may have its own completions in addition to inherited ones. A command may wrap multiple commands, and wrapping is transitive: if A wraps B, and B wraps C, then A automatically inherits all of C's completions. Wrapping can be removed using the `-e` or `--erase` options. Note that wrapping only works for completions specified with `-c` or `--command` and are ignored when specifying completions with `-p` or `--path`. + +When erasing completions, it is possible to either erase all completions for a specific command by specifying `complete -c COMMAND -e`, or by specifying a specific completion option to delete by specifying either a long, short or old style option. + + +\subsection complete-example Example + +The short style option `-o` for the `gcc` command requires that a file follows it. This can be done using writing: + +\fish +complete -c gcc -s o -r +\endfish + +The short style option `-d` for the `grep` command requires that one of the strings '`read`', '`skip`' or '`recurse`' is used. This can be specified writing: + +\fish +complete -c grep -s d -x -a "read skip recurse" +\endfish + +The `su` command takes any username as an argument. Usernames are given as the first colon-separated field in the file /etc/passwd. This can be specified as: + +\fish +complete -x -c su -d "Username" -a "(cat /etc/passwd | cut -d : -f 1)" +\endfish + +The `rpm` command has several different modes. If the `-e` or `--erase` flag has been specified, `rpm` should delete one or more packages, in which case several switches related to deleting packages are valid, like the `nodeps` switch. + +This can be written as: + +\fish +complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d "Don't check dependencies" +\endfish + +where `__fish_contains_opt` is a function that checks the command line buffer for the presence of a specified set of options. + +To implement an alias, use the `-w` or `--wraps` option: + +\fish +complete -c hub -w git +\endfish + +Now hub inherits all of the completions from git. Note this can also be specified in a function declaration. + diff --git a/sphinx_doc_src/cmds/contains.rst b/sphinx_doc_src/cmds/contains.rst new file mode 100644 index 000000000..c65292c09 --- /dev/null +++ b/sphinx_doc_src/cmds/contains.rst @@ -0,0 +1,48 @@ +\section contains contains - test if a word is present in a list + +\subsection contains-synopsis Synopsis +\fish{synopsis} +contains [OPTIONS] KEY [VALUES...] +\endfish + +\subsection contains-description Description + +`contains` tests whether the set `VALUES` contains the string `KEY`. If so, `contains` exits with status 0; if not, it exits with status 1. + +The following options are available: + +- `-i` or `--index` print the word index + +Note that, like GNU tools and most of fish's builtins, `contains` interprets all arguments starting with a `-` as options to contains, until it reaches an argument that is `--` (two dashes). See the examples below. + +\subsection contains-example Example + +If $animals is a list of animals, the following will test if it contains a cat: + +\fish +if contains cat $animals + echo Your animal list is evil! +end +\endfish + +This code will add some directories to $PATH if they aren't yet included: + +\fish +for i in ~/bin /usr/local/bin + if not contains $i $PATH + set PATH $PATH $i + end +end +\endfish + +While this will check if `hasargs` was run with the `-q` option: + +\fish +function hasargs + if contains -- -q $argv + echo '$argv contains a -q option' + end +end +\endfish + +The `--` here stops `contains` from treating `-q` to an option to itself. Instead it treats it as a normal string to check. diff --git a/sphinx_doc_src/cmds/continue.rst b/sphinx_doc_src/cmds/continue.rst new file mode 100644 index 000000000..26346be6a --- /dev/null +++ b/sphinx_doc_src/cmds/continue.rst @@ -0,0 +1,26 @@ +\section continue continue - skip the remainder of the current iteration of the current inner loop + +\subsection continue-synopsis Synopsis +\fish{synopsis} +LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end +\endfish + +\subsection continue-description Description + +`continue` skips the remainder of the current iteration of the current inner loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. + +\subsection continue-example Example + +The following code removes all tmp files that do not contain the word smurf. + +\fish +for i in *.tmp + if grep smurf $i + continue + end + # This "rm" is skipped over if "continue" is executed. + rm $i + # As is this "echo" + echo $i +end +\endfish diff --git a/sphinx_doc_src/cmds/count.rst b/sphinx_doc_src/cmds/count.rst new file mode 100644 index 000000000..bf11a6350 --- /dev/null +++ b/sphinx_doc_src/cmds/count.rst @@ -0,0 +1,25 @@ +\section count count - count the number of elements of an array + +\subsection count-synopsis Synopsis +\fish{synopsis} +count $VARIABLE +\endfish + +\subsection count-description Description + +`count` prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains. + +`count` does not accept any options, not even `-h` or `--help`. + +`count` exits with a non-zero exit status if no arguments were passed to it, and with zero if at least one argument was passed. + + +\subsection count-example Example + +\fish +count $PATH +# Returns the number of directories in the users PATH variable. + +count *.txt +# Returns the number of files in the current working directory ending with the suffix '.txt'. +\endfish \ No newline at end of file diff --git a/sphinx_doc_src/cmds/dirh.rst b/sphinx_doc_src/cmds/dirh.rst new file mode 100644 index 000000000..77e03e185 --- /dev/null +++ b/sphinx_doc_src/cmds/dirh.rst @@ -0,0 +1,14 @@ +\section dirh dirh - print directory history + +\subsection dirh-synopsis Synopsis +\fish{synopsis} +dirh +\endfish + +\subsection dirh-description Description + +`dirh` prints the current directory history. The current position in the history is highlighted using the color defined in the `fish_color_history_current` environment variable. + +`dirh` does not accept any parameters. + +Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables. diff --git a/sphinx_doc_src/cmds/dirs.rst b/sphinx_doc_src/cmds/dirs.rst new file mode 100644 index 000000000..c3da6e84f --- /dev/null +++ b/sphinx_doc_src/cmds/dirs.rst @@ -0,0 +1,15 @@ +\section dirs dirs - print directory stack + +\subsection dirs-synopsis Synopsis +\fish{synopsis} +dirs +dirs -c +\endfish + +\subsection dirs-description Description + +`dirs` prints the current directory stack, as created by the `pushd` command. + +With "-c", it clears the directory stack instead. + +`dirs` does not accept any parameters. diff --git a/sphinx_doc_src/cmds/disown.rst b/sphinx_doc_src/cmds/disown.rst new file mode 100644 index 000000000..45f5c025a --- /dev/null +++ b/sphinx_doc_src/cmds/disown.rst @@ -0,0 +1,24 @@ +\section disown disown - remove a process from the list of jobs + +\subsection disown-synopsis Synopsis +\fish{synopsis} +disown [ PID ... ] +\endfish + +\subsection disown-description Description + +`disown` removes the specified job from the list of jobs. The job itself continues to exist, but fish does not keep track of it any longer. + +Jobs in the list of jobs are sent a hang-up signal when fish terminates, which usually causes the job to terminate; `disown` allows these processes to continue regardless. + +If no process is specified, the most recently-used job is removed (like `bg` and `fg`). If one or more `PID`s are specified, jobs with the specified process IDs are removed from the job list. Invalid jobs are ignored and a warning is printed. + +If a job is stopped, it is sent a signal to continue running, and a warning is printed. It is not possible to use the `bg` builtin to continue a job once it has been disowned. + +`disown` returns 0 if all specified jobs were disowned successfully, and 1 if any problems were encountered. + +\subsection disown-example Example + +`firefox &; disown` will start the Firefox web browser in the background and remove it from the job list, meaning it will not be closed when the fish process is closed. + +`disown (jobs -p)` removes all jobs from the job list without terminating them. diff --git a/sphinx_doc_src/cmds/echo.rst b/sphinx_doc_src/cmds/echo.rst new file mode 100644 index 000000000..69d6df4ef --- /dev/null +++ b/sphinx_doc_src/cmds/echo.rst @@ -0,0 +1,60 @@ +\section echo echo - display a line of text + +\subsection echo-synopsis Synopsis +\fish{synopsis} +echo [OPTIONS] [STRING] +\endfish + +\subsection echo-description Description + +`echo` displays a string of text. + +The following options are available: + +- `-n`, Do not output a newline + +- `-s`, Do not separate arguments with spaces + +- `-E`, Disable interpretation of backslash escapes (default) + +- `-e`, Enable interpretation of backslash escapes + +\subsection echo-escapes Escape Sequences + +If `-e` is used, the following sequences are recognized: + +- `\` backslash + +- `\a` alert (BEL) + +- `\b` backspace + +- `\c` produce no further output + +- `\e` escape + +- `\f` form feed + +- `\n` new line + +- `\r` carriage return + +- `\t` horizontal tab + +- `\v` vertical tab + +- `\0NNN` byte with octal value NNN (1 to 3 digits) + +- `\xHH` byte with hexadecimal value HH (1 to 2 digits) + +\subsection echo-example Example + +\fish +echo 'Hello World' +\endfish +Print hello world to stdout + +\fish +echo -e 'Top\\nBottom' +\endfish +Print Top and Bottom on separate lines, using an escape sequence diff --git a/sphinx_doc_src/cmds/else.rst b/sphinx_doc_src/cmds/else.rst new file mode 100644 index 000000000..76e0c61f3 --- /dev/null +++ b/sphinx_doc_src/cmds/else.rst @@ -0,0 +1,23 @@ +\section else else - execute command if a condition is not met + +\subsection else-synopsis Synopsis +\fish{synopsis} +if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end +\endfish + +\subsection else-description Description + +`if` will execute the command `CONDITION`. If the condition's exit status is 0, the commands `COMMANDS_TRUE` will execute. If it is not 0 and `else` is given, `COMMANDS_FALSE` will be executed. + + +\subsection else-example Example + +The following code tests whether a file `foo.txt` exists as a regular file. + +\fish +if test -f foo.txt + echo foo.txt exists +else + echo foo.txt does not exist +end +\endfish diff --git a/sphinx_doc_src/cmds/emit.rst b/sphinx_doc_src/cmds/emit.rst new file mode 100644 index 000000000..78f8e2467 --- /dev/null +++ b/sphinx_doc_src/cmds/emit.rst @@ -0,0 +1,28 @@ +\section emit emit - Emit a generic event + +\subsection emit-synopsis Synopsis +\fish{synopsis} +emit EVENT_NAME [ARGUMENTS...] +\endfish + +\subsection emit-description Description + +`emit` emits, or fires, an event. Events are delivered to, or caught by, special functions called event handlers. The arguments are passed to the event handlers as function arguments. + + +\subsection emit-example Example + +The following code first defines an event handler for the generic event named 'test_event', and then emits an event of that type. + +\fish +function event_test --on-event test_event + echo event test: $argv +end + +emit test_event something +\endfish + + +\subsection emit-notes Notes + +Note that events are only sent to the current fish process as there is no way to send events from one fish process to another. diff --git a/sphinx_doc_src/cmds/end.rst b/sphinx_doc_src/cmds/end.rst new file mode 100644 index 000000000..2b035930c --- /dev/null +++ b/sphinx_doc_src/cmds/end.rst @@ -0,0 +1,19 @@ +\section end end - end a block of commands. + +\subsection end-synopsis Synopsis +\fish{synopsis} +begin; [COMMANDS...] end +if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end +while CONDITION; COMMANDS...; end +for VARNAME in [VALUES...]; COMMANDS...; end +switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end +\endfish + +\subsection end-description Description + +`end` ends a block of commands. + +For more information, read the +documentation for the block constructs, such as `if`, `for` and `while`. + +The `end` command does not change the current exit status. Instead, the status after it will be the status returned by the most recent command. diff --git a/sphinx_doc_src/cmds/eval.rst b/sphinx_doc_src/cmds/eval.rst new file mode 100644 index 000000000..5e7785077 --- /dev/null +++ b/sphinx_doc_src/cmds/eval.rst @@ -0,0 +1,21 @@ +\section eval eval - evaluate the specified commands + +\subsection eval-synopsis Synopsis +\fish{synopsis} +eval [COMMANDS...] +\endfish + +\subsection eval-description Description +`eval` evaluates the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator. + +If your command does not need access to stdin, consider using `source` instead. + +\subsection eval-example Example + +The following code will call the ls command. Note that `fish` does not support the use of shell variables as direct commands; `eval` can be used to work around this. + +\fish +set cmd ls +eval $cmd +\endfish + diff --git a/sphinx_doc_src/cmds/exec.rst b/sphinx_doc_src/cmds/exec.rst new file mode 100644 index 000000000..f8936101a --- /dev/null +++ b/sphinx_doc_src/cmds/exec.rst @@ -0,0 +1,15 @@ +\section exec exec - execute command in current process + +\subsection exec-synopsis Synopsis +\fish{synopsis} +exec COMMAND [OPTIONS...] +\endfish + +\subsection exec-description Description + +`exec` replaces the currently running shell with a new command. On successful completion, `exec` never returns. `exec` cannot be used inside a pipeline. + + +\subsection exec-example Example + +`exec emacs` starts up the emacs text editor, and exits `fish`. When emacs exits, the session will terminate. diff --git a/sphinx_doc_src/cmds/exit.rst b/sphinx_doc_src/cmds/exit.rst new file mode 100644 index 000000000..b780c4317 --- /dev/null +++ b/sphinx_doc_src/cmds/exit.rst @@ -0,0 +1,12 @@ +\section exit exit - exit the shell + +\subsection exit-synopsis Synopsis +\fish{synopsis} +exit [STATUS] +\endfish + +\subsection exit-description Description + +`exit` causes fish to exit. If `STATUS` is supplied, it will be converted to an integer and used as the exit code. Otherwise, the exit code will be that of the last command executed. + +If exit is called while sourcing a file (using the source builtin) the rest of the file will be skipped, but the shell itself will not exit. diff --git a/sphinx_doc_src/cmds/false.rst b/sphinx_doc_src/cmds/false.rst new file mode 100644 index 000000000..1ce5a4619 --- /dev/null +++ b/sphinx_doc_src/cmds/false.rst @@ -0,0 +1,10 @@ +\section false false - return an unsuccessful result + +\subsection false-synopsis Synopsis +\fish{synopsis} +false +\endfish + +\subsection false-description Description + +`false` sets the exit status to 1. diff --git a/sphinx_doc_src/cmds/fg.rst b/sphinx_doc_src/cmds/fg.rst new file mode 100644 index 000000000..a27a0ad6b --- /dev/null +++ b/sphinx_doc_src/cmds/fg.rst @@ -0,0 +1,15 @@ +\section fg fg - bring job to foreground + +\subsection fg-synopsis Synopsis +\fish{synopsis} +fg [PID] +\endfish + +\subsection fg-description Description + +`fg` brings the specified job to the foreground, resuming it if it is stopped. While a foreground job is executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group ID is put in the foreground. + + +\subsection fg-example Example + +`fg` will put the last job in the foreground. diff --git a/sphinx_doc_src/cmds/fish.rst b/sphinx_doc_src/cmds/fish.rst new file mode 100644 index 000000000..5e22e526d --- /dev/null +++ b/sphinx_doc_src/cmds/fish.rst @@ -0,0 +1,34 @@ +\section fish fish - the friendly interactive shell + +\subsection fish-synopsis Synopsis +\fish{synopsis} +fish [OPTIONS] [-c command] [FILE [ARGUMENTS...]] +\endfish + +\subsection fish-description Description + +`fish` is a command-line shell written mainly with interactive use in mind. The full manual is available in HTML by using the help command from inside fish. + +The following options are available: + +- `-c` or `--command=COMMANDS` evaluate the specified commands instead of reading from the commandline + +- `-C` or `--init-command=COMMANDS` evaluate the specified commands after reading the configuration, before running the command specified by `-c` or reading interactive input + +- `-d` or `--debug-level=DEBUG_LEVEL` specify the verbosity level of fish. A higher number means higher verbosity. The default level is 1. + +- `-i` or `--interactive` specify that fish is to run in interactive mode + +- `-l` or `--login` specify that fish is to run as a login shell + +- `-n` or `--no-execute` do not execute any commands, only perform syntax checking + +- `-p` or `--profile=PROFILE_FILE` when fish exits, output timing information on all executed commands to the specified file + +- `-v` or `--version` display version and exit + +- `-D` or `--debug-stack-frames=DEBUG_LEVEL` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. + +- `-f` or `--features=FEATURES` enables one or more feature flags (separated by a comma). These are how fish stages changes that might break scripts. + +The fish exit status is generally the exit status of the last foreground command. If fish is exiting because of a parse error, the exit status is 127. diff --git a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst new file mode 100644 index 000000000..b56c7e0ac --- /dev/null +++ b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst @@ -0,0 +1,30 @@ +\section fish_breakpoint_prompt fish_breakpoint_prompt - define the appearance of the command line prompt when in the context of a `breakpoint` command + +\subsection fish_breakpoint_prompt-synopsis Synopsis +\fish{synopsis} +function fish_breakpoint_prompt + ... +end +\endfish + +\subsection fish_breakpoint_prompt-description Description + +By defining the `fish_breakpoint_prompt` function, the user can choose a custom prompt when asking for input in response to a `breakpoint` command. The `fish_breakpoint_prompt` function is executed when the prompt is to be shown, and the output is used as a prompt. + +The exit status of commands within `fish_breakpoint_prompt` will not modify the value of $status outside of the `fish_breakpoint_prompt` function. + +`fish` ships with a default version of this function that displays the function name and line number of the current execution context. + + +\subsection fish_breakpoint_prompt-example Example + +A simple prompt that is a simplified version of the default debugging prompt: + +\fish +function fish_breakpoint_prompt -d "Write out the debug prompt" + set -l function (status current-function) + set -l line (status current-line-number) + set -l prompt "$function:$line >" + echo -ns (set_color $fish_color_status) "BP $prompt" (set_color normal) ' ' +end +\endfish diff --git a/sphinx_doc_src/cmds/fish_config.rst b/sphinx_doc_src/cmds/fish_config.rst new file mode 100644 index 000000000..4fa242651 --- /dev/null +++ b/sphinx_doc_src/cmds/fish_config.rst @@ -0,0 +1,18 @@ +\section fish_config fish_config - start the web-based configuration interface + +\subsection fish_config-description Description + +`fish_config` starts the web-based configuration interface. + +The web interface allows you to view your functions, variables and history, and to make changes to your prompt and color configuration. + +`fish_config` starts a local web server and then opens a web browser window; when you have finished, close the browser window and then press the Enter key to terminate the configuration session. + +`fish_config` optionally accepts name of the initial configuration tab. For e.g. `fish_config history` will start configuration interface with history tab. + +If the `BROWSER` environment variable is set, it will be used as the name of the web browser to open instead of the system default. + + +\subsection fish_config-example Example + +`fish_config` opens a new web browser window and allows you to configure certain fish settings. diff --git a/sphinx_doc_src/cmds/fish_indent.rst b/sphinx_doc_src/cmds/fish_indent.rst new file mode 100644 index 000000000..2cc429fb7 --- /dev/null +++ b/sphinx_doc_src/cmds/fish_indent.rst @@ -0,0 +1,28 @@ +\section fish_indent fish_indent - indenter and prettifier + +\subsection fish_indent-synopsis Synopsis +\fish{synopsis} +fish_indent [OPTIONS] +\endfish + +\subsection fish_indent-description Description + +`fish_indent` is used to indent a piece of fish code. `fish_indent` reads commands from standard input and outputs them to standard output or a specified file. + +The following options are available: + +- `-w` or `--write` indents a specified file and immediately writes to that file. + +- `-i` or `--no-indent` do not indent commands; only reformat to one job per line. + +- `-v` or `--version` displays the current fish version and then exits. + +- `--ansi` colorizes the output using ANSI escape sequences, appropriate for the current $TERM, using the colors defined in the environment (such as `$fish_color_command`). + +- `--html` outputs HTML, which supports syntax highlighting if the appropriate CSS is defined. The CSS class names are the same as the variable names, such as `fish_color_command`. + +- `-d` or `--debug-level=DEBUG_LEVEL` enables debug output and specifies a verbosity level (like `fish -d`). Defaults to 0. + +- `-D` or `--debug-stack-frames=DEBUG_LEVEL` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. + +- `--dump-parse-tree` dumps information about the parsed statements to stderr. This is likely to be of interest only to people working on the fish source code. diff --git a/sphinx_doc_src/cmds/fish_key_reader.rst b/sphinx_doc_src/cmds/fish_key_reader.rst new file mode 100644 index 000000000..d1d5db2ab --- /dev/null +++ b/sphinx_doc_src/cmds/fish_key_reader.rst @@ -0,0 +1,35 @@ +\section fish_key_reader fish_key_reader - explore what characters keyboard keys send + +\subsection fish_key_reader-synopsis Synopsis +\fish{synopsis} +fish_key_reader [OPTIONS] +\endfish + +\subsection fish_key_reader-description Description + +`fish_key_reader` is used to study input received from the terminal and can help with key binds. The program is interactive and works on standard input. Individual characters themselves and their hexadecimal values are displayed. + +The tool will write an example `bind` command matching the character sequence captured to stdout. If the character sequence matches a special key name (see `bind --key-names`), both `bind CHARS ...` and `bind -k KEYNAME ...` usage will be shown. Additional details about the characters received, such as the delay between chars, are written to stderr. + +The following options are available: + +- `-c` or `--continuous` begins a session where multiple key sequences can be inspected. By default the program exits after capturing a single key sequence. + +- `-d` or `--debug-level=DEBUG_LEVEL` enables debug output and specifies a verbosity level (like `fish -d`). Defaults to 0. + +- `-D` or `--debug-stack-frames=DEBUG_LEVEL` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. + +- `-h` or `--help` prints usage information. + +- `-v` or `--version` prints fish_key_reader's version and exits. + +\subsection fish_key_reader-usage-notes Usage Notes + +The delay in milliseconds since the previous character was received is included in the diagnostic information written to stderr. This information may be useful to determine the optimal `fish_escape_delay_ms` setting or learn the amount of lag introduced by tools like `ssh`, `mosh` or `tmux`. + +`fish_key_reader` intentionally disables handling of many signals. To terminate `fish_key_reader` in `--continuous` mode do: + +- press `Ctrl-C` twice, or +- press `Ctrl-D` twice, or +- type `exit`, or +- type `quit` diff --git a/sphinx_doc_src/cmds/fish_mode_prompt.rst b/sphinx_doc_src/cmds/fish_mode_prompt.rst new file mode 100644 index 000000000..c397d2c33 --- /dev/null +++ b/sphinx_doc_src/cmds/fish_mode_prompt.rst @@ -0,0 +1,37 @@ +\section fish_mode_prompt fish_mode_prompt - define the appearance of the mode indicator + +\subsection fish_mode_prompt-synopsis Synopsis + +The fish_mode_prompt function will output the mode indicator for use in vi-mode. + +\subsection fish_mode_prompt-description Description + +The default `fish_mode_prompt` function will output indicators about the current Vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. You can also define an empty `fish_mode_prompt` function to remove the Vi mode indicators. The `$fish_bind_mode variable` can be used to determine the current mode. It +will be one of `default`, `insert`, `replace_one`, or `visual`. + +\subsection fish_mode_prompt-example Example + +\fish +function fish_mode_prompt + switch $fish_bind_mode + case default + set_color --bold red + echo 'N' + case insert + set_color --bold green + echo 'I' + case replace_one + set_color --bold green + echo 'R' + case visual + set_color --bold brmagenta + echo 'V' + case '*' + set_color --bold red + echo '?' + end + set_color normal +end +\endfish + +Outputting multiple lines is not supported in `fish_mode_prompt`. diff --git a/sphinx_doc_src/cmds/fish_opt.rst b/sphinx_doc_src/cmds/fish_opt.rst new file mode 100644 index 000000000..24967d24a --- /dev/null +++ b/sphinx_doc_src/cmds/fish_opt.rst @@ -0,0 +1,54 @@ +\section fish_opt fish_opt - create an option spec for the argparse command + +\subsection fish_opt-synopsis Synopsis +\fish{synopsis} +fish_opt [ -h | --help ] +fish_opt ( -s X | --short=X ) [ -l LONG | --long=LONG ] [ --long-only ] \ + [ -o | --optional-val ] [ -r | --required-val ] [ --multiple-vals ] +\endfish + +\subsection fish_opt-description Description + +This command provides a way to produce option specifications suitable for use with the `argparse` command. You can, of course, write the option specs by hand without using this command. But you might prefer to use this for the clarity it provides. + +The following `argparse` options are available: + +- `-s` or `--short` takes a single letter that is used as the short flag in the option being defined. This option is mandatory. + +- `-l` or `--long` takes a string that is used as the long flag in the option being defined. This option is optional and has no default. If no long flag is defined then only the short flag will be allowed when parsing arguments using the option spec. + +- `--long-only` means the option spec being defined will only allow the long flag name to be used. The short flag name must still be defined (i.e., `--short` must be specified) but it cannot be used when parsing args using this option spec. + +- `-o` or `--optional` means the option being defined can take a value but it is optional rather than required. If the option is seen more than once when parsing arguments only the last value seen is saved. This means the resulting flag variable created by `argparse` will zero elements if no value was given with the option else it will have exactly one element. + +- `-r` or `--required` means the option being defined requires a value. If the option is seen more than once when parsing arguments only the last value seen is saved. This means the resulting flag variable created by `argparse` will have exactly one element. + +- `--multiple-vals` means the option being defined requires a value each time it is seen. Each instance is stored. This means the resulting flag variable created by `argparse` will have one element for each instance of this option in the args. + +- `-h` or `--help` displays help about using this command. + +\subsection fish_opt-examples Examples + +Define a single option spec for the boolean help flag: + +\fish +set -l options (fish_opt -s h -l help) +argparse $options -- $argv +\endfish + +Same as above but with a second flag that requires a value: + +\fish +set -l options (fish_opt -s h -l help) +set options $options (fish_opt -s m -l max --required-val) +argparse $options -- $argv +\endfish + +Same as above but with a third flag that can be given multiple times saving the value of each instance seen and only the long flag name (`--token`) can be used: + +\fish +set -l options (fish_opt --short=h --long=help) +set options $options (fish_opt --short=m --long=max --required-val) +set options $options (fish_opt --short=t --long=token --multiple-vals --long-only) +argparse $options -- $argv +\endfish diff --git a/sphinx_doc_src/cmds/fish_prompt.rst b/sphinx_doc_src/cmds/fish_prompt.rst new file mode 100644 index 000000000..1beb5304e --- /dev/null +++ b/sphinx_doc_src/cmds/fish_prompt.rst @@ -0,0 +1,29 @@ +\section fish_prompt fish_prompt - define the appearance of the command line prompt + +\subsection fish_prompt-synopsis Synopsis +\fish{synopsis} +function fish_prompt + ... +end +\endfish + +\subsection fish_prompt-description Description + +By defining the `fish_prompt` function, the user can choose a custom prompt. The `fish_prompt` function is executed when the prompt is to be shown, and the output is used as a prompt. + +The exit status of commands within `fish_prompt` will not modify the value of $status outside of the `fish_prompt` function. + +`fish` ships with a number of example prompts that can be chosen with the `fish_config` command. + + +\subsection fish_prompt-example Example + +A simple prompt: + +\fish +function fish_prompt -d "Write out the prompt" + printf '%s@%s%s%s%s> ' (whoami) (hostname | cut -d . -f 1) \ + (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) +end +\endfish + diff --git a/sphinx_doc_src/cmds/fish_right_prompt.rst b/sphinx_doc_src/cmds/fish_right_prompt.rst new file mode 100644 index 000000000..87de31139 --- /dev/null +++ b/sphinx_doc_src/cmds/fish_right_prompt.rst @@ -0,0 +1,26 @@ +\section fish_right_prompt fish_right_prompt - define the appearance of the right-side command line prompt + +\subsection fish_right_prompt-synopsis Synopsis +\fish{synopsis} +function fish_right_prompt + ... +end +\endfish + +\subsection fish_right_prompt-description Description + +`fish_right_prompt` is similar to `fish_prompt`, except that it appears on the right side of the terminal window. + +Multiple lines are not supported in `fish_right_prompt`. + + +\subsection fish_right_prompt-example Example + +A simple right prompt: + +\fish +function fish_right_prompt -d "Write out the right prompt" + date '+%m/%d/%y' +end +\endfish + diff --git a/sphinx_doc_src/cmds/fish_update_completions.rst b/sphinx_doc_src/cmds/fish_update_completions.rst new file mode 100644 index 000000000..684dac0d8 --- /dev/null +++ b/sphinx_doc_src/cmds/fish_update_completions.rst @@ -0,0 +1,9 @@ +\section fish_update_completions fish_update_completions - Update completions using manual pages + +\subsection fish_update_completions-description Description + +`fish_update_completions` parses manual pages installed on the system, and attempts to create completion files in the `fish` configuration directory. + +This does not overwrite custom completions. + +There are no parameters for `fish_update_completions`. diff --git a/sphinx_doc_src/cmds/fish_vi_mode.rst b/sphinx_doc_src/cmds/fish_vi_mode.rst new file mode 100644 index 000000000..d39697c8f --- /dev/null +++ b/sphinx_doc_src/cmds/fish_vi_mode.rst @@ -0,0 +1,12 @@ +\section fish_vi_mode fish_vi_mode - Enable vi mode + +\subsection fish_vi_mode-synopsis Synopsis +\fish{synopsis} +fish_vi_mode +\endfish + +\subsection fish_vi_mode-description Description + +This function is deprecated. Please call `fish_vi_key_bindings directly` + +`fish_vi_mode` enters a vi-like command editing mode. To always start in vi mode, add `fish_vi_mode` to your `config.fish` file. diff --git a/sphinx_doc_src/cmds/for.rst b/sphinx_doc_src/cmds/for.rst new file mode 100644 index 000000000..508a3ac2d --- /dev/null +++ b/sphinx_doc_src/cmds/for.rst @@ -0,0 +1,36 @@ +\section for for - perform a set of commands multiple times. + +\subsection for-synopsis Synopsis +\fish{synopsis} +for VARNAME in [VALUES...]; COMMANDS...; end +\endfish + +\subsection for-description Description + +`for` is a loop construct. It will perform the commands specified by `COMMANDS` multiple times. On each iteration, the local variable specified by `VARNAME` is assigned a new value from `VALUES`. If `VALUES` is empty, `COMMANDS` will not be executed at all. The `VARNAME` is visible when the loop terminates and will contain the last value assigned to it. If `VARNAME` does not already exist it will be set in the local scope. For our purposes if the `for` block is inside a function there must be a local variable with the same name. If the `for` block is not nested inside a function then global and universal variables of the same name will be used if they exist. + +\subsection for-example Example + +\fish +for i in foo bar baz; echo $i; end + +# would output: +foo +bar +baz +\endfish + +\subsection for-notes Notes + +The `VARNAME` was local to the for block in releases prior to 3.0.0. This means that if you did something like this: + +\fish +for var in a b c + if break_from_loop + break + end +end +echo $var +\endfish + +The last value assigned to `var` when the loop terminated would not be available outside the loop. What `echo $var` would write depended on what it was set to before the loop was run. Likely nothing. diff --git a/sphinx_doc_src/cmds/funced.rst b/sphinx_doc_src/cmds/funced.rst new file mode 100644 index 000000000..b8a7db530 --- /dev/null +++ b/sphinx_doc_src/cmds/funced.rst @@ -0,0 +1,20 @@ +\section funced funced - edit a function interactively + +\subsection funced-synopsis Synopsis +\fish{synopsis} +funced [OPTIONS] NAME +\endfish + +\subsection funced-description Description + +`funced` provides an interface to edit the definition of the function `NAME`. + +If the `$VISUAL` environment variable is set, it will be used as the program to edit the function. If `$VISUAL` is unset but `$EDITOR` is set, that will be used. Otherwise, a built-in editor will be used. Note that to enter a literal newline using the built-in editor you should press @key{Alt,Enter}. Pressing @key{Enter} signals that you are done editing the function. This does not apply to an external editor like emacs or vim. + +If there is no function called `NAME` a new function will be created with the specified name + +- `-e command` or `--editor command` Open the function body inside the text editor given by the command (for example, `-e vi`). The special command `fish` will use the built-in editor (same as specifying `-i`). + +- `-i` or `--interactive` Force opening the function body in the built-in editor even if `$VISUAL` or `$EDITOR` is defined. + +- `-s` or `--save` Automatically save the function after successfully editing it. diff --git a/sphinx_doc_src/cmds/funcsave.rst b/sphinx_doc_src/cmds/funcsave.rst new file mode 100644 index 000000000..32b3f4f31 --- /dev/null +++ b/sphinx_doc_src/cmds/funcsave.rst @@ -0,0 +1,12 @@ +\section funcsave funcsave - save the definition of a function to the user's autoload directory + +\subsection funcsave-synopsis Synopsis +\fish{synopsis} +funcsave FUNCTION_NAME +\endfish + +\subsection funcsave-description Description + +`funcsave` saves the current definition of a function to a file in the fish configuration directory. This function will be automatically loaded by current and future fish sessions. This can be useful if you have interactively created a new function and wish to save it for later use. + +Note that because fish loads functions on-demand, saved functions will not function as event handlers until they are run or sourced otherwise. To activate an event handler for every new shell, add the function to your shell initialization file instead of using `funcsave`. diff --git a/sphinx_doc_src/cmds/function.rst b/sphinx_doc_src/cmds/function.rst new file mode 100644 index 000000000..b6db339e9 --- /dev/null +++ b/sphinx_doc_src/cmds/function.rst @@ -0,0 +1,101 @@ +\section function function - create a function + +\subsection function-synopsis Synopsis +\fish{synopsis} +function NAME [OPTIONS]; BODY; end +\endfish + +\subsection function-description Description + +`function` creates a new function `NAME` with the body `BODY`. + +A function is a list of commands that will be executed when the name of the function is given as a command. + +The following options are available: + +- `-a NAMES` or `--argument-names NAMES` assigns the value of successive command-line arguments to the names given in NAMES. + +- `-d DESCRIPTION` or `--description=DESCRIPTION` is a description of what the function does, suitable as a completion description. + +- `-w WRAPPED_COMMAND` or `--wraps=WRAPPED_COMMAND` causes the function to inherit completions from the given wrapped command. See the documentation for `complete` for more information. + +- `-e` or `--on-event EVENT_NAME` tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt. + +- `-v` or `--on-variable VARIABLE_NAME` tells fish to run this function when the variable VARIABLE_NAME changes value. + +- `-j PGID` or `--on-job-exit PGID` tells fish to run this function when the job with group ID PGID exits. Instead of PGID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution. + +- `-p PID` or `--on-process-exit PID` tells fish to run this function when the fish child process + with process ID PID exits. Instead of a PID, for backward compatibility, + "`%self`" can be specified as an alias for `$fish_pid`, and the function will be run when the + current fish instance exits. + +- `-s` or `--on-signal SIGSPEC` tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP). + +- `-S` or `--no-scope-shadowing` allows the function to access the variables of calling functions. Normally, any variables inside the function that have the same name as variables from the calling function are "shadowed", and their contents is independent of the calling function. + +- `-V` or `--inherit-variable NAME` snapshots the value of the variable `NAME` and defines a local variable with that same name and value when the function is defined. This is similar to a closure in other languages like Python but a bit different. Note the word "snapshot" in the first sentence. If you change the value of the variable after defining the function, even if you do so in the same scope (typically another function) the new value will not be used by the function you just created using this option. See the `function notify` example below for how this might be used. + +If the user enters any additional arguments after the function, they are inserted into the environment variable array `$argv`. If the `--argument-names` option is provided, the arguments are also assigned to names specified in that option. + +By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the emit builtin. Fish generates the following named events: + +- `fish_prompt`, which is emitted whenever a new fish prompt is about to be displayed. + +- `fish_command_not_found`, which is emitted whenever a command lookup failed. + +- `fish_preexec`, which is emitted right before executing an interactive command. The commandline is passed as the first parameter. + + Note: This event will be emitted even if the command is invalid. The commandline parameter includes the entire commandline verbatim, and may potentially include newlines. + +- `fish_postexec`, which is emitted right after executing an interactive command. The commandline is passed as the first parameter. + + Note: This event will be emitted even if the command is invalid. The commandline parameter includes the entire commandline verbatim, and may potentially include newlines. + +- `fish_exit` is emitted right before fish exits. + +\subsection function-example Example + +\fish +function ll + ls -l $argv +end +\endfish + +will run the `ls` command, using the `-l` option, while passing on any additional files and switches to `ls`. + +\fish +function mkdir -d "Create a directory and set CWD" + command mkdir $argv + if test $status = 0 + switch $argv[(count $argv)] + case '-*' + + case '*' + cd $argv[(count $argv)] + return + end + end +end +\endfish + +This will run the `mkdir` command, and if it is successful, change the current working directory to the one just created. + +\fish +function notify + set -l job (jobs -l -g) + or begin; echo "There are no jobs" >&2; return 1; end + + function _notify_job_$job --on-job-exit $job --inherit-variable job + echo -n \a # beep + functions -e _notify_job_$job + end +end +\endfish + +This will beep when the most recent job completes. + + +\subsection function-notes Notes + +Note that events are only received from the current fish process as there is no way to send events from one fish process to another. diff --git a/sphinx_doc_src/cmds/functions.rst b/sphinx_doc_src/cmds/functions.rst new file mode 100644 index 000000000..2b4b067e8 --- /dev/null +++ b/sphinx_doc_src/cmds/functions.rst @@ -0,0 +1,69 @@ +\section functions functions - print or erase functions + +\subsection functions-synopsis Synopsis +\fish{synopsis} +functions [ -a | --all ] [ -n | --names ] +functions [ -D | --details ] [ -v ] FUNCTION +functions -c OLDNAME NEWNAME +functions -d DESCRIPTION FUNCTION +functions [ -e | -q ] FUNCTIONS... +\endfish + +\subsection functions-description Description + +`functions` prints or erases functions. + +The following options are available: + +- `-a` or `--all` lists all functions, even those whose name starts with an underscore. + +- `-c OLDNAME NEWNAME` or `--copy OLDNAME NEWNAME` creates a new function named NEWNAME, using the definition of the OLDNAME function. + +- `-d DESCRIPTION` or `--description=DESCRIPTION` changes the description of this function. + +- `-e` or `--erase` causes the specified functions to be erased. + +- `-D` or `--details` reports the path name where each function is defined or could be autoloaded, `stdin` if the function was defined interactively or on the command line or by reading stdin, and `n/a` if the function isn't available. If the `--verbose` option is also specified then five lines are written: + + -# the pathname as already described, + -# `autoloaded`, `not-autoloaded` or `n/a`, + -# the line number within the file or zero if not applicable, + -# `scope-shadowing` if the function shadows the vars in the calling function (the normal case if it wasn't defined with `--no-scope-shadowing`), else `no-scope-shadowing`, or `n/a` if the function isn't defined, + -# the function description minimally escaped so it is a single line or `n/a` if the function isn't defined. + +You should not assume that only five lines will be written since we may add additional information to the output in the future. + +- `-n` or `--names` lists the names of all defined functions. + +- `-q` or `--query` tests if the specified functions exist. + +- `-v` or `--verbose` will make some output more verbose. + +- `-H` or `--handlers` will show all event handlers. + +- `-t` or `--handlers-type TYPE` will show all event handlers matching the given type + +The default behavior of `functions`, when called with no arguments, is to print the names of all defined functions. Unless the `-a` option is given, no functions starting with underscores are not included in the output. + +If any non-option parameters are given, the definition of the specified functions are printed. + +Automatically loaded functions cannot be removed using `functions -e`. Either remove the definition file or change the $fish_function_path variable to remove autoloaded functions. + +Copying a function using `-c` copies only the body of the function, and does not attach any event notifications from the original function. + +Only one function's description can be changed in a single invocation of `functions -d`. + +The exit status of `functions` is the number of functions specified in the argument list that do not exist, which can be used in concert with the `-q` option. + + +\subsection functions-example Examples +\fish +functions -n +# Displays a list of currently-defined functions + +functions -c foo bar +# Copies the 'foo' function to a new function called 'bar' + +functions -e bar +# Erases the function `bar` +\endfish diff --git a/sphinx_doc_src/cmds/help.rst b/sphinx_doc_src/cmds/help.rst new file mode 100644 index 000000000..9665dba27 --- /dev/null +++ b/sphinx_doc_src/cmds/help.rst @@ -0,0 +1,23 @@ +\section help help - display fish documentation + +\subsection help-synopsis Synopsis +\fish{synopsis} +help [SECTION] +\endfish + +\subsection help-description Description + +`help` displays the fish help documentation. + +If a `SECTION` is specified, the help for that command is shown. + +If the BROWSER environment variable is set, it will be used to display the documentation. Otherwise, fish will search for a suitable browser. + +If you prefer to use a different browser (other than as described above) for fish help, you can set the fish_help_browser variable. This variable may be set as an array, where the first element is the browser command and the rest are browser options. + +Note that most builtin commands display their help in the terminal when given the `--help` option. + + +\subsection help-example Example + +`help fg` shows the documentation for the `fg` builtin. diff --git a/sphinx_doc_src/cmds/history.rst b/sphinx_doc_src/cmds/history.rst new file mode 100644 index 000000000..192bfd191 --- /dev/null +++ b/sphinx_doc_src/cmds/history.rst @@ -0,0 +1,79 @@ +\section history history - Show and manipulate command history + +\subsection history-synopsis Synopsis +\fish{synopsis} +history search [ --show-time ] [ --case-sensitive ] [ --exact | --prefix | --contains ] [ --max=n ] [ --null ] [ -R | --reverse ] [ "search string"... ] +history delete [ --show-time ] [ --case-sensitive ] [ --exact | --prefix | --contains ] "search string"... +history merge +history save +history clear +history ( -h | --help ) +\endfish + +\subsection history-description Description + +`history` is used to search, delete, and otherwise manipulate the history of interactive commands. + +The following operations (sub-commands) are available: + +- `search` returns history items matching the search string. If no search string is provided it returns all history items. This is the default operation if no other operation is specified. You only have to explicitly say `history search` if you wish to search for one of the subcommands. The `--contains` search option will be used if you don't specify a different search option. Entries are ordered newest to oldest unless you use the `--reverse` flag. If stdout is attached to a tty the output will be piped through your pager by the history function. The history builtin simply writes the results to stdout. + +- `delete` deletes history items. Without the `--prefix` or `--contains` options, the exact match of the specified text will be deleted. If you don't specify `--exact` a prompt will be displayed before any items are deleted asking you which entries are to be deleted. You can enter the word "all" to delete all matching entries. You can enter a single ID (the number in square brackets) to delete just that single entry. You can enter more than one ID separated by a space to delete multiple entries. Just press [enter] to not delete anything. Note that the interactive delete behavior is a feature of the history function. The history builtin only supports `--exact --case-sensitive` deletion. + +- `merge` immediately incorporates history changes from other sessions. Ordinarily `fish` ignores history changes from sessions started after the current one. This command applies those changes immediately. + +- `save` immediately writes all changes to the history file. The shell automatically saves the history file; this option is provided for internal use and should not normally need to be used by the user. + +- `clear` clears the history file. A prompt is displayed before the history is erased asking you to confirm you really want to clear all history unless `builtin history` is used. + +The following options are available: + +These flags can appear before or immediately after one of the sub-commands listed above. + +- `-C` or `--case-sensitive` does a case-sensitive search. The default is case-insensitive. Note that prior to fish 2.4.0 the default was case-sensitive. + +- `-c` or `--contains` searches or deletes items in the history that contain the specified text string. This is the default for the `--search` flag. This is not currently supported by the `delete` subcommand. + +- `-e` or `--exact` searches or deletes items in the history that exactly match the specified text string. This is the default for the `delete` subcommand. Note that the match is case-insensitive by default. If you really want an exact match, including letter case, you must use the `-C` or `--case-sensitive` flag. + +- `-p` or `--prefix` searches or deletes items in the history that begin with the specified text string. This is not currently supported by the `--delete` flag. + +- `-t` or `--show-time` prepends each history entry with the date and time the entry was recorded. By default it uses the strftime format `# %c%n`. You can specify another format; e.g., `--show-time="%Y-%m-%d %H:%M:%S "` or `--show-time="%a%I%p"`. The short option, `-t`, doesn't accept a strftime format string; it only uses the default format. Any strftime format is allowed, including `%s` to get the raw UNIX seconds since the epoch. + +- `-z` or `--null` causes history entries written by the search operations to be terminated by a NUL character rather than a newline. This allows the output to be processed by `read -z` to correctly handle multiline history entries. + +- `-` `-n ` or `--max=` limits the matched history items to the first "n" matching entries. This is only valid for `history search`. + +- `-R` or `--reverse` causes the history search results to be ordered oldest to newest. Which is the order used by most shells. The default is newest to oldest. + +- `-h` or `--help` display help for this command. + +\subsection history-examples Example + +\fish +history clear +# Deletes all history items + +history search --contains "foo" +# Outputs a list of all previous commands containing the string "foo". + +history delete --prefix "foo" +# Interactively deletes commands which start with "foo" from the history. +# You can select more than one entry by entering their IDs separated by a space. +\endfish + +\subsection customizing-the-histfile Customizing the name of the history file + +By default interactive commands are logged to `$XDG_DATA_HOME/fish/fish_history` (typically `~/.local/share/fish/fish_history`). + +You can set the `fish_history` variable to another name for the current shell session. The default value (when the variable is unset) is `fish` which corresponds to `$XDG_DATA_HOME/fish/fish_history`. If you set it to e.g. `fun`, the history would be written to `$XDG_DATA_HOME/fish/fun_history`. An empty string means history will not be stored at all. This is similar to the private session features in web browsers. + +You can change `fish_history` at any time (by using `set -x fish_history "session_name"`) and it will take effect right away. If you set it to `"default"`, it will use the default session name (which is `"fish"`). + +Other shells such as bash and zsh use a variable named `HISTFILE` for a similar purpose. Fish uses a different name to avoid conflicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other than `fish` or `default` it will inhibit importing the bash history. That's because the most common use case for this feature is to avoid leaking private or sensitive history when giving a presentation. + +\subsection history-notes Notes + +If you specify both `--prefix` and `--contains` the last flag seen is used. + +Note that for backwards compatibility each subcommand can also be specified as a long option. For example, rather than `history search` you can type `history --search`. Those long options are deprecated and will be removed in a future release. diff --git a/sphinx_doc_src/cmds/if.rst b/sphinx_doc_src/cmds/if.rst new file mode 100644 index 000000000..61ba387c1 --- /dev/null +++ b/sphinx_doc_src/cmds/if.rst @@ -0,0 +1,39 @@ +\section if if - conditionally execute a command + +\subsection if-synopsis Synopsis +\fish{synopsis} +if CONDITION; COMMANDS_TRUE...; +[else if CONDITION2; COMMANDS_TRUE2...;] +[else; COMMANDS_FALSE...;] +end +\endfish + +\subsection if-description Description + +`if` will execute the command `CONDITION`. If the condition's exit status is 0, the commands `COMMANDS_TRUE` will execute. If the exit status is not 0 and `else` is given, `COMMANDS_FALSE` will be executed. + +You can use `and` or `or` in the condition. See the second example below. + +The exit status of the last foreground command to exit can always be accessed using the $status variable. + +\subsection if-example Example + +The following code will print `foo.txt exists` if the file foo.txt exists and is a regular file, otherwise it will print `bar.txt exists` if the file bar.txt exists and is a regular file, otherwise it will print `foo.txt and bar.txt do not exist`. + +\fish +if test -f foo.txt + echo foo.txt exists +else if test -f bar.txt + echo bar.txt exists +else + echo foo.txt and bar.txt do not exist +end +\endfish + +The following code will print "foo.txt exists and is readable" if foo.txt is a regular file and readable +\fish +if test -f foo.txt + and test -r foo.txt + echo "foo.txt exists and is readable" +end +\endfish diff --git a/sphinx_doc_src/cmds/isatty.rst b/sphinx_doc_src/cmds/isatty.rst new file mode 100644 index 000000000..f6ab500e6 --- /dev/null +++ b/sphinx_doc_src/cmds/isatty.rst @@ -0,0 +1,35 @@ +\section isatty isatty - test if a file descriptor is a tty. + +\subsection isatty-synopsis Synopsis +\fish{synopsis} +isatty [FILE DESCRIPTOR] +\endfish + +\subsection isatty-description Description + +`isatty` tests if a file descriptor is a tty. + +`FILE DESCRIPTOR` may be either the number of a file descriptor, or one of the strings `stdin`, `stdout`, or `stderr`. + +If the specified file descriptor is a tty, the exit status of the command is zero. Otherwise, the exit status is non-zero. No messages are printed to standard error. + + +\subsection isatty-examples Examples + +From an interactive shell, the commands below exit with a return value of zero: + +\fish +isatty +isatty stdout +isatty 2 +echo | isatty 1 +\endfish + +And these will exit non-zero: + +\fish +echo | isatty +isatty 9 +isatty stdout > file +isatty 2 2> file +\endfish diff --git a/sphinx_doc_src/cmds/jobs.rst b/sphinx_doc_src/cmds/jobs.rst new file mode 100644 index 000000000..df4fd9f10 --- /dev/null +++ b/sphinx_doc_src/cmds/jobs.rst @@ -0,0 +1,33 @@ +\section jobs jobs - print currently running jobs + +\subsection jobs-synopsis Synopsis +\fish{synopsis} +jobs [OPTIONS] [PID] +\endfish + +\subsection jobs-description Description + +`jobs` prints a list of the currently running jobs and their status. + +jobs accepts the following switches: + +- `-c` or `--command` prints the command name for each process in jobs. + +- `-g` or `--group` only prints the group ID of each job. + +- `-l` or `--last` prints only the last job to be started. + +- `-p` or `--pid` prints the process ID for each process in all jobs. + +- `-q` or `--quiet` prints no output for evaluation of jobs by exit code only. + +On systems that supports this feature, jobs will print the CPU usage of each job since the last command was executed. The CPU usage is expressed as a percentage of full CPU activity. Note that on multiprocessor systems, the total activity may be more than 100\%. + +The exit code of the `jobs` builtin is `0` if there are running background jobs and `1` otherwise. + +\subsection prints no output. + + +\subsection jobs-example Example + +`jobs` outputs a summary of the current jobs. diff --git a/sphinx_doc_src/cmds/math.rst b/sphinx_doc_src/cmds/math.rst new file mode 100644 index 000000000..790933a93 --- /dev/null +++ b/sphinx_doc_src/cmds/math.rst @@ -0,0 +1,104 @@ +\section math math - Perform mathematics calculations + +\subsection math-synopsis Synopsis +\fish{synopsis} +math [-sN | --scale=N] [--] EXPRESSION +\endfish + +\subsection math-description Description + +`math` is used to perform mathematical calculations. It supports all the usual operations such as addition, subtraction, etc. As well as functions like `abs()`, `sqrt()` and `log2()`. + +By default, the output is as a float with trailing zeroes trimmed. To get a fixed representation, the `--scale` option can be used, including `--scale=0` for integer output. + +Keep in mind that parameter expansion takes before expressions are evaluated. This can be very useful in order to perform calculations involving shell variables or the output of command substitutions, but it also means that parenthesis and the asterisk glob character have to be escaped or quoted. + +`math` ignores whitespace between arguments and takes its input as multiple arguments (internally joined with a space), so `math 2 +2` and `math "2 + 2"` work the same. `math 2 2` is an error. + +The following options are available: + +- `-sN` or `--scale=N` sets the scale of the result. `N` must be an integer. A scale of zero causes results to be rounded down to the nearest integer. So `3/2` returns `1` rather than `2` which `1.5` would normally round to. This is for compatibility with `bc` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. + +\subsection return-values Return Values + +If the expression is successfully evaluated and doesn't over/underflow or return NaN the return `status` is zero (success) else one. + +\subsection math-syntax Syntax + +`math` knows some operators, constants, functions and can (obviously) read numbers. + +For numbers, `.` is always the radix character regardless of locale - `2.5`, not `2,5`. Scientific notation (`10e5`) is also available. + +\subsection math-operators Operators + +`math` knows the following operators: + +- `+` for addition and `-` for subtraction. + +- `*` for multiplication, `/` for division. + +- `^` for exponentiation. + +- `%` for modulo. + +- `(` and `)` for grouping. + +They are all used in an infix manner - `5 + 2`, not `+ 5 2`. + +\subsection math-constants Constants + +`math` knows the following constants: + +- `e` - Euler's number. +- `pi` - You know that one. Half of Tau. (Tau is not implemented) + +Use them without a leading `$` - `pi - 3` should be about 0. + +\subsection math-functions Functions + +`math` supports the following functions: + +- `abs` +- `acos` +- `asin` +- `atan` +- `atan2` +- `ceil` +- `cos` +- `cosh` +- `exp` - the base-e exponential function +- `fac` - factorial +- `floor` +- `ln` +- `log` or `log10` - the base-10 logarithm +- `ncr` +- `npr` +- `pow(x,y)` returns x to the y (and can be written as `x ^ y`) +- `round` - rounds to the nearest integer, away from 0 +- `sin` +- `sinh` +- `sqrt` +- `tan` +- `tanh` + +All of the trigonometric functions use radians. + +\subsection math-example Examples + +`math 1+1` outputs 2. + +`math $status - 128` outputs the numerical exit status of the last command minus 128. + +`math 10 / 6` outputs `1.666667`. + +`math -s0 10.0 / 6.0` outputs `1`. + +`math -s3 10 / 6` outputs `1.666`. + +`math "sin(pi)"` outputs `0`. + +\subsection math-notes Compatibility notes + +Fish 1.x and 2.x releases relied on the `bc` command for handling `math` expressions. Starting with fish 3.0.0 fish uses the tinyexpr library and evaluates the expression without the involvement of any external commands. + +You don't need to use `--` before the expression even if it begins with a minus sign which might otherwise be interpreted as an invalid option. If you do insert `--` before the expression it will cause option scanning to stop just like for every other command and it won't be part of the expression. diff --git a/sphinx_doc_src/cmds/nextd.rst b/sphinx_doc_src/cmds/nextd.rst new file mode 100644 index 000000000..61e01f1ef --- /dev/null +++ b/sphinx_doc_src/cmds/nextd.rst @@ -0,0 +1,32 @@ +\section nextd nextd - move forward through directory history + +\subsection nextd-synopsis Synopsis +\fish{synopsis} +nextd [ -l | --list ] [POS] +\endfish + +\subsection nextd-description Description + +`nextd` moves forwards `POS` positions in the history of visited directories; if the end of the history has been hit, a warning is printed. + +If the `-l` or `--list` flag is specified, the current directory history is also displayed. + +Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables which this command manipulates. + +You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. + +\subsection nextd-example Example + +\fish +cd /usr/src +# Working directory is now /usr/src + +cd /usr/src/fish-shell +# Working directory is now /usr/src/fish-shell + +prevd +# Working directory is now /usr/src + +nextd +# Working directory is now /usr/src/fish-shell +\endfish diff --git a/sphinx_doc_src/cmds/not.rst b/sphinx_doc_src/cmds/not.rst new file mode 100644 index 000000000..7848d2dc9 --- /dev/null +++ b/sphinx_doc_src/cmds/not.rst @@ -0,0 +1,23 @@ +\section not not - negate the exit status of a job + +\subsection not-synopsis Synopsis +\fish{synopsis} +not COMMAND [OPTIONS...] +\endfish + +\subsection not-description Description + +`not` negates the exit status of another command. If the exit status is zero, `not` returns 1. Otherwise, `not` returns 0. + + +\subsection not-example Example + +The following code reports an error and exits if no file named spoon can be found. + +\fish +if not test -f spoon + echo There is no spoon + exit 1 +end +\endfish + diff --git a/sphinx_doc_src/cmds/open.rst b/sphinx_doc_src/cmds/open.rst new file mode 100644 index 000000000..7207fc172 --- /dev/null +++ b/sphinx_doc_src/cmds/open.rst @@ -0,0 +1,17 @@ +\section open open - open file in its default application + +\subsection open-synopsis Synopsis +\fish{synopsis} +open FILES... +\endfish + +\subsection open-description Description + +`open` opens a file in its default application, using the appropriate tool for the operating system. On GNU/Linux, this requires the common but optional `xdg-open` utility, from the `xdg-utils` package. + +Note that this function will not be used if a command by this name exists (which is the case on macOS or Haiku). + + +\subsection open-example Example + +`open *.txt` opens all the text files in the current directory using your system's default text editor. diff --git a/sphinx_doc_src/cmds/or.rst b/sphinx_doc_src/cmds/or.rst new file mode 100644 index 000000000..b79e707d6 --- /dev/null +++ b/sphinx_doc_src/cmds/or.rst @@ -0,0 +1,23 @@ +\section or or - conditionally execute a command + +\subsection or-synopsis Synopsis +\fish{synopsis} +COMMAND1; or COMMAND2 +\endfish + +\subsection or-description Description + +`or` is used to execute a command if the previous command was not successful (returned a status of something other than 0). + +`or` statements may be used as part of the condition in an `and` or `while` block. See the documentation +for `if` and `while` for examples. + +`or` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. + +\subsection or-example Example + +The following code runs the `make` command to build a program. If the build succeeds, the program is installed. If either step fails, `make clean` is run, which removes the files created by the build process. + +\fish +make; and make install; or make clean +\endfish diff --git a/sphinx_doc_src/cmds/popd.rst b/sphinx_doc_src/cmds/popd.rst new file mode 100644 index 000000000..93dd4da37 --- /dev/null +++ b/sphinx_doc_src/cmds/popd.rst @@ -0,0 +1,28 @@ +\section popd popd - move through directory stack + +\subsection popd-synopsis Synopsis +\fish{synopsis} +popd +\endfish + +\subsection popd-description Description + +`popd` removes the top directory from the directory stack and changes the working directory to the new top directory. Use `pushd` to add directories to the stack. + +You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. + +\subsection popd-example Example + +\fish +pushd /usr/src +# Working directory is now /usr/src +# Directory stack contains /usr/src + +pushd /usr/src/fish-shell +# Working directory is now /usr/src/fish-shell +# Directory stack contains /usr/src /usr/src/fish-shell + +popd +# Working directory is now /usr/src +# Directory stack contains /usr/src +\endfish diff --git a/sphinx_doc_src/cmds/prevd.rst b/sphinx_doc_src/cmds/prevd.rst new file mode 100644 index 000000000..191d95890 --- /dev/null +++ b/sphinx_doc_src/cmds/prevd.rst @@ -0,0 +1,32 @@ +\section prevd prevd - move backward through directory history + +\subsection prevd-synopsis Synopsis +\fish{synopsis} +prevd [ -l | --list ] [POS] +\endfish + +\subsection prevd-description Description + +`prevd` moves backwards `POS` positions in the history of visited directories; if the beginning of the history has been hit, a warning is printed. + +If the `-l` or `--list` flag is specified, the current history is also displayed. + +Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables which this command manipulates. + +You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. + +\subsection prevd-example Example + +\fish +cd /usr/src +# Working directory is now /usr/src + +cd /usr/src/fish-shell +# Working directory is now /usr/src/fish-shell + +prevd +# Working directory is now /usr/src + +nextd +# Working directory is now /usr/src/fish-shell +\endfish diff --git a/sphinx_doc_src/cmds/printf.rst b/sphinx_doc_src/cmds/printf.rst new file mode 100644 index 000000000..49fb0ad6a --- /dev/null +++ b/sphinx_doc_src/cmds/printf.rst @@ -0,0 +1,70 @@ +\section printf printf - display text according to a format string + +\subsection printf-synopsis Synopsis +\fish{synopsis} +printf format [argument...] +\endfish + +\subsection printf-description Description +printf formats the string FORMAT with ARGUMENT, and displays the result. + +The string FORMAT should contain format specifiers, each of which are replaced with successive arguments according to the specifier. Specifiers are detailed below, and are taken from the C library function `printf(3)`. + +Unlike `echo`, `printf` does not append a new line unless it is specified as part of the string. + +Valid format specifiers are: + +- `%%d`: Argument will be used as decimal integer (signed or unsigned) + +- `%%i`: Argument will be used as a signed integer + +- `%%o`: An octal unsigned integer + +- `%%u`: An unsigned decimal integer + +- `%%x` or `%%X`: An unsigned hexadecimal integer + +- `%%f`, `%%g` or `%%G`: A floating-point number + +- `%%e` or `%%E`: A floating-point number in scientific (XXXeYY) notation + +- `%%s`: A string + +- `%%b`: As a string, interpreting backslash escapes, except that octal escapes are of the form \0 or \0ooo. + +`%%` signifies a literal "%". + +Note that conversion may fail, e.g. "102.234" will not losslessly convert to an integer, causing printf to print an error. + +printf also knows a number of backslash escapes: +- `\"` double quote +- `\\` backslash +- `\a` alert (bell) +- `\b` backspace +- `\c` produce no further output +- `\e` escape +- `\f` form feed +- `\n` new line +- `\r` carriage return +- `\t` horizontal tab +- `\v` vertical tab +- `\ooo` octal number (ooo is 1 to 3 digits) +- `\xhh` hexadecimal number (hhh is 1 to 2 digits) +- `\uhhhh` 16-bit Unicode character (hhhh is 4 digits) +- `\Uhhhhhhhh` 32-bit Unicode character (hhhhhhhh is 8 digits) + +The `format` argument is re-used as many times as necessary to convert all of the given arguments. If a format specifier is not appropriate for the given argument, an error is printed. For example, `printf '%d' "102.234"` produces an error, as "102.234" cannot be formatted as an integer. + +This file has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try `command printf`. + +\subsection printf-example Example + +\fish +printf '%s\\t%s\\n' flounder fish +\endfish +Will print "flounder fish" (separated with a tab character), followed by a newline character. This is useful for writing completions, as fish expects completion scripts to output the option followed by the description, separated with a tab character. + +\fish +printf '%s:%d' "Number of bananas in my pocket" 42 +\endfish +Will print "Number of bananas in my pocket: 42", _without_ a newline. diff --git a/sphinx_doc_src/cmds/prompt_pwd.rst b/sphinx_doc_src/cmds/prompt_pwd.rst new file mode 100644 index 000000000..0eafbf994 --- /dev/null +++ b/sphinx_doc_src/cmds/prompt_pwd.rst @@ -0,0 +1,31 @@ +\section prompt_pwd prompt_pwd - Print pwd suitable for prompt + +\subsection prompt_pwd-synopsis Synopsis +\fish{synopsis} +prompt_pwd +\endfish + +\subsection prompt_pwd-description Description + +prompt_pwd is a function to print the current working directory in a way suitable for prompts. It will replace the home directory with "~" and shorten every path component but the last to a default of one character. + +To change the number of characters per path component, set $fish_prompt_pwd_dir_length to the number of characters. Setting it to 0 or an invalid value will disable shortening entirely. + +\subsection prompt_pwd-example Examples + +\fish{cli-dark} +>_ cd ~/ +>_ echo $PWD +/home/alfa + +>_ prompt_pwd +~ + +>_ cd /tmp/banana/sausage/with/mustard +>_ prompt_pwd +/t/b/s/w/mustard + +>_ set -g fish_prompt_pwd_dir_length 3 +>_ prompt_pwd +/tmp/ban/sau/wit/mustard +\endfish diff --git a/sphinx_doc_src/cmds/psub.rst b/sphinx_doc_src/cmds/psub.rst new file mode 100644 index 000000000..d0c59e0ac --- /dev/null +++ b/sphinx_doc_src/cmds/psub.rst @@ -0,0 +1,28 @@ +\section psub psub - perform process substitution + +\subsection psub-synopsis Synopsis +\fish{synopsis} +COMMAND1 ( COMMAND2 | psub [-F | --fifo] [-f | --file] [-s SUFFIX]) +\endfish + +\subsection psub-description Description + +Some shells (e.g., ksh, bash) feature a syntax that is a mix between command substitution and piping, called process substitution. It is used to send the output of a command into the calling command, much like command substitution, but with the difference that the output is not sent through commandline arguments but through a named pipe, with the filename of the named pipe sent as an argument to the calling program. `psub` combined with a regular command substitution provides the same functionality. + +The following options are available: + +- `-f` or `--file` will cause psub to use a regular file instead of a named pipe to communicate with the calling process. This will cause `psub` to be significantly slower when large amounts of data are involved, but has the advantage that the reading process can seek in the stream. This is the default. + +- `-F` or `--fifo` will cause psub to use a named pipe rather than a file. You should only use this if the command produces no more than 8 KiB of output. The limit on the amount of data a FIFO can buffer varies with the OS but is typically 8 KiB, 16 KiB or 64 KiB. If you use this option and the command on the left of the psub pipeline produces more output a deadlock is likely to occur. + +- `-s` or `--suffix` will append SUFFIX to the filename. + +\subsection psub-example Example + +\fish +diff (sort a.txt | psub) (sort b.txt | psub) +# shows the difference between the sorted versions of files `a.txt` and `b.txt`. + +source-highlight -f esc (cpp main.c | psub -f -s .c) +# highlights `main.c` after preprocessing as a C source. +\endfish diff --git a/sphinx_doc_src/cmds/pushd.rst b/sphinx_doc_src/cmds/pushd.rst new file mode 100644 index 000000000..43d62c6dd --- /dev/null +++ b/sphinx_doc_src/cmds/pushd.rst @@ -0,0 +1,44 @@ +\section pushd pushd - push directory to directory stack + +\subsection pushd-synopsis Synopsis +\fish{synopsis} +pushd [DIRECTORY] +\endfish + +\subsection pushd-description Description + +The `pushd` function adds `DIRECTORY` to the top of the directory stack and makes it the current working directory. `popd` will pop it off and return to the original directory. + +Without arguments, it exchanges the top two directories in the stack. + +`pushd +NUMBER` rotates the stack counter-clockwise i.e. from bottom to top + +`pushd -NUMBER` rotates clockwise i.e. top to bottom. + +See also `dirs` and `dirs -c`. + +You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. + +\subsection pushd-example Example + +\fish +pushd /usr/src +# Working directory is now /usr/src +# Directory stack contains /usr/src + +pushd /usr/src/fish-shell +# Working directory is now /usr/src/fish-shell +# Directory stack contains /usr/src /usr/src/fish-shell + +pushd /tmp/ +# Working directory is now /tmp +# Directory stack contains /tmp /usr/src /usr/src/fish-shell + +pushd +1 +# Working directory is now /usr/src +# Directory stack contains /usr/src /usr/src/fish-shell /tmp + +popd +# Working directory is now /usr/src/fish-shell +# Directory stack contains /usr/src/fish-shell /tmp +\endfish diff --git a/sphinx_doc_src/cmds/pwd.rst b/sphinx_doc_src/cmds/pwd.rst new file mode 100644 index 000000000..b3860498e --- /dev/null +++ b/sphinx_doc_src/cmds/pwd.rst @@ -0,0 +1,16 @@ +\section pwd pwd - output the current working directory + +\subsection pwd-synopsis Synopsis +\fish{synopsis} +pwd +\endfish + +\subsection pwd-description Description + +`pwd` outputs (prints) the current working directory. + +The following options are available: + +- `-L`, Output the logical working directory, without resolving symlinks (default behavior). + +- `-P`, Output the physical working directory, with symlinks resolved. diff --git a/sphinx_doc_src/cmds/random.rst b/sphinx_doc_src/cmds/random.rst new file mode 100644 index 000000000..28f140152 --- /dev/null +++ b/sphinx_doc_src/cmds/random.rst @@ -0,0 +1,44 @@ +\section random random - generate random number + +\subsection random-synopsis Synopsis +\fish{synopsis} +random +random SEED +random START END +random START STEP END +random choice [ITEMS...] +\endfish + +\subsection random-description Description + +`RANDOM` generates a pseudo-random integer from a uniform distribution. The +range (inclusive) is dependent on the arguments passed. +No arguments indicate a range of [0; 32767]. +If one argument is specified, the internal engine will be seeded with the +argument for future invocations of `RANDOM` and no output will be produced. +Two arguments indicate a range of [START; END]. +Three arguments indicate a range of [START; END] with a spacing of STEP +between possible outputs. +`RANDOM choice` will select one random item from the succeeding arguments. + +Note that seeding the engine will NOT give the same result across different +systems. + +You should not consider `RANDOM` cryptographically secure, or even +statistically accurate. + +\subsection random-example Example + +The following code will count down from a random even number between 10 and 20 to 1: + +\fish +for i in (seq (random 10 2 20) -1 1) + echo $i +end +\endfish + +And this will open a random picture from any of the subdirectories: + +\fish +open (random choice **jpg) +\endfish diff --git a/sphinx_doc_src/cmds/read.rst b/sphinx_doc_src/cmds/read.rst new file mode 100644 index 000000000..c898cca59 --- /dev/null +++ b/sphinx_doc_src/cmds/read.rst @@ -0,0 +1,94 @@ +\section read read - read line of input into variables + +\subsection read-synopsis Synopsis +\fish{synopsis} +read [OPTIONS] [VARIABLE ...] +\endfish + +\subsection read-description Description + +`read` reads from standard input and either writes the result back to standard output (for use in command substitution), or stores the result in one or more shell variables. By default, `read` reads a single line and splits it into variables on spaces or tabs. Alternatively, a null character or a maximum number of characters can be used to terminate the input, and other delimiters can be given. Unlike other shells, there is no default variable (such as `REPLY`) for storing the result - instead, it is printed on standard output. + +The following options are available: + +- `-c CMD` or `--command=CMD` sets the initial string in the interactive mode command buffer to `CMD`. + +- `-d DELIMITER` or `--delimiter=DELIMITER` splits on DELIMITER. DELIMITER will be used as an entire string to split on, not a set of characters. + +- `-g` or `--global` makes the variables global. + +- `-s` or `--silent` masks characters written to the terminal, replacing them with asterisks. This is useful for reading things like passwords or other sensitive information. + +- `-l` or `--local` makes the variables local. + +- `-n NCHARS` or `--nchars=NCHARS` makes `read` return after reading NCHARS characters or the end of + the line, whichever comes first. + +- `-p PROMPT_CMD` or `--prompt=PROMPT_CMD` uses the output of the shell command `PROMPT_CMD` as the prompt for the interactive mode. The default prompt command is set_color green; echo read; set_color normal; echo "> ". + +- `-P PROMPT_STR` or `--prompt-str=PROMPT_STR` uses the string as the prompt for the interactive mode. It is equivalent to echo PROMPT_STR and is provided solely to avoid the need to frame the prompt as a command. All special characters in the string are automatically escaped before being passed to the echo command. + +- `-R RIGHT_PROMPT_CMD` or `--right-prompt=RIGHT_PROMPT_CMD` uses the output of the shell command `RIGHT_PROMPT_CMD` as the right prompt for the interactive mode. There is no default right prompt command. + +- `-S` or `--shell` enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode. NOTE: Prior to fish 3.0, the short opt for `--shell` was `-s`, but it has been changed for compatibility with bash's `-s` short opt for `--silent`. + +- `-u` or `--unexport` prevents the variables from being exported to child processes (default behaviour). + +- `-U` or `--universal` causes the specified shell variable to be made universal. + +- `-x` or `--export` exports the variables to child processes. + +- `-a` or `--array` stores the result as an array in a single variable. + +- `-z` or `--null` marks the end of the line with the NUL character, instead of newline. This also + disables interactive mode. + +- `-L` or `--line` reads each line into successive variables, and stops after each variable has been filled. This cannot be combined with the `--delimiter` option. + +Without the `--line` option, `read` reads a single line of input from standard input, breaks it into tokens, and then assigns one token to each variable specified in `VARIABLES`. If there are more tokens than variables, the complete remainder is assigned to the last variable. + +If the `--delimiter` argument is not given, the variable `IFS` is used as a list of characters to split on. Relying on the use of `IFS` is deprecated and this behaviour will be removed in future versions. The default value of `IFS` contains space, tab and newline characters. As a special case, if `IFS` is set to the empty string, each character of the input is considered a separate token. + +With the `--line` option, `read` reads a line of input from standard input into each provided variable, stopping when each variable has been filled. The line is not tokenized. + +If no variable names are provided, `read` enters a special case that simply provides redirection from standard input to standard output, useful for command substitution. For instance, the fish shell command below can be used to read data that should be provided via a command line argument from the console instead of hardcoding it in the command itself, allowing the command to both be reused as-is in various contexts with different input values and preventing possibly sensitive text from being included in the shell history: + +`mysql -uuser -p(read)` + +When running in this mode, `read` does not split the input in any way and text is redirected to standard output without any further processing or manipulation. + +If `-a` or `--array` is provided, only one variable name is allowed and the tokens are stored as an array in this variable. + +See the documentation for `set` for more details on the scoping rules for variables. + +When `read` reaches the end-of-file (EOF) instead of the terminator, the exit status is set to 1. +Otherwise, it is set to 0. + +In order to protect the shell from consuming too many system resources, `read` will only consume a +maximum of 10 MiB (1048576 bytes); if the terminator is not reached before this limit then VARIABLE +is set to empty and the exit status is set to 122. This limit can be altered with the +`fish_read_limit` variable. If set to 0 (zero), the limit is removed. + +\subsection read-history Using another read history file + +The `read` command supported the `-m` and `--mode-name` flags in fish versions prior to 2.7.0 to specify an alternative read history file. Those flags are now deprecated and ignored. Instead, set the `fish_history` variable to specify a history session ID. That will affect both the `read` history file and the fish command history file. You can set it to an empty string to specify that no history should be read or written. This is useful for presentations where you do not want possibly private or sensitive history to be exposed to the audience but do want history relevant to the presentation to be available. + +\subsection read-example Example + +The following code stores the value 'hello' in the shell variable `$foo`. + +\fish +echo hello|read foo + +# This is a neat way to handle command output by-line: +printf '%s\n' line1 line2 line3 line4 | while read -l foo + echo "This is another line: $foo" + end + +# Delimiters given via "-d" are taken as one string +echo a==b==c | read -d == -l a b c +echo $a # a +echo $b # b +echo $c # c + +\endfish diff --git a/sphinx_doc_src/cmds/realpath.rst b/sphinx_doc_src/cmds/realpath.rst new file mode 100644 index 000000000..35e6503a3 --- /dev/null +++ b/sphinx_doc_src/cmds/realpath.rst @@ -0,0 +1,12 @@ +\section realpath realpath - Convert a path to an absolute path without symlinks + +\subsection realpath-synopsis Synopsis +\fish{synopsis} +realpath path +\endfish + +\subsection realpath-description Description + +This is implemented as a function and a builtin. The function will attempt to use an external realpath command if one can be found. Otherwise it falls back to the builtin. The builtin does not support any options. It's meant to be used only by scripts which need to be portable. The builtin implementation behaves like GNU realpath when invoked without any options (which is the most common use case). In general scripts should not invoke the builtin directly. They should just use `realpath`. + +If the path is invalid no translated path will be written to stdout and an error will be reported. diff --git a/sphinx_doc_src/cmds/return.rst b/sphinx_doc_src/cmds/return.rst new file mode 100644 index 000000000..af4ca9aeb --- /dev/null +++ b/sphinx_doc_src/cmds/return.rst @@ -0,0 +1,25 @@ +\section return return - stop the current inner function + +\subsection return-synopsis Synopsis +\fish{synopsis} +function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end +\endfish + +\subsection return-description Description + +`return` halts a currently running function. The exit status is set to `STATUS` if it is given. + +It is usually added inside of a conditional block such as an if statement or a switch statement to conditionally stop the executing function and return to the caller, but it can also be used to specify the exit status of a function. + + +\subsection return-example Example + +The following code is an implementation of the false command as a fish function + +\fish +function false + return 1 +end +\endfish + + diff --git a/sphinx_doc_src/cmds/set.rst b/sphinx_doc_src/cmds/set.rst new file mode 100644 index 000000000..fca3bf170 --- /dev/null +++ b/sphinx_doc_src/cmds/set.rst @@ -0,0 +1,113 @@ +\section set set - display and change shell variables. + +\subsection set-synopsis Synopsis +\fish{synopsis} +set [SCOPE_OPTIONS] +set [OPTIONS] VARIABLE_NAME VALUES... +set [OPTIONS] VARIABLE_NAME[INDICES]... VALUES... +set ( -q | --query ) [SCOPE_OPTIONS] VARIABLE_NAMES... +set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME +set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME[INDICES]... +set ( -S | --show ) [SCOPE_OPTIONS] [VARIABLE_NAME]... +\endfish + +\subsection set-description Description + +`set` manipulates shell variables. + +If set is called with no arguments, the names and values of all shell variables are printed in sorted order. If some of the scope or export flags have been given, only the variables matching the specified scope are printed. + +With both variable names and values provided, `set` assigns the variable `VARIABLE_NAME` the values `VALUES...`. + +The following options control variable scope: + +- `-a` or `--append` causes the values to be appended to the current set of values for the variable. This can be used with `--prepend` to both append and prepend at the same time. This cannot be used when assigning to a variable slice. + +- `-p` or `--prepend` causes the values to be prepended to the current set of values for the variable. This can be used with `--append` to both append and prepend at the same time. This cannot be used when assigning to a variable slice. + +- `-l` or `--local` forces the specified shell variable to be given a scope that is local to the current block, even if a variable with the given name exists and is non-local + +- `-g` or `--global` causes the specified shell variable to be given a global scope. Non-global variables disappear when the block they belong to ends + +- `-U` or `--universal` causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell. + +- `-x` or `--export` causes the specified shell variable to be exported to child processes (making it an "environment variable") + +- `-u` or `--unexport` causes the specified shell variable to NOT be exported to child processes + + +The following options are available: + +- `-e` or `--erase` causes the specified shell variable to be erased + +- `-q` or `--query` test if the specified variable names are defined. Does not output anything, but the builtins exit status is the number of variables specified that were not defined. + +- `-n` or `--names` List only the names of all defined variables, not their value. The names are guaranteed to be sorted. + +- `-S` or `--show` Shows information about the given variables. If no variable names are given then all variables are shown in sorted order. No other flags can be used with this option. The information shown includes whether or not it is set in each of the local, global, and universal scopes. If it is set in one of those scopes whether or not it is exported is reported. The individual elements are also shown along with the length of each element. + +- `-L` or `--long` do not abbreviate long values when printing set variables + + +If a variable is set to more than one value, the variable will be an array with the specified elements. If a variable is set to zero elements, it will become an array with zero elements. + +If the variable name is one or more array elements, such as `PATH[1 3 7]`, only those array elements specified will be changed. If you specify a negative index when expanding or assigning to an array variable, the index will be calculated from the end of the array. For example, the index -1 means the last index of an array. + +The scoping rules when creating or updating a variable are: + +-# Variables may be explicitly set to universal, global or local. Variables with the same name in different scopes will not be changed. + +-# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the previous variable scope is used. + +-# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the `-l` or `--local` flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global. + + +The exporting rules when creating or updating a variable are identical to the scoping rules for variables: + +-# Variables may be explicitly set to either exported or not exported. When an exported variable goes out of scope, it is unexported. + +-# If a variable is not explicitly set to be exported or not exported, but has been previously defined, the previous exporting rule for the variable is kept. + +-# If a variable is not explicitly set to be either exported or unexported and has never before been defined, the variable will not be exported. + + +In query mode, the scope to be examined can be specified. + +In erase mode, if variable indices are specified, only the specified slices of the array variable will be erased. + +`set` requires all options to come before any other arguments. For example, `set flags -l` will have the effect of setting the value of the variable `flags` to '-l', not making the variable local. + +In assignment mode, `set` does not modify the exit status. This allows simultaneous capture of the output and exit status of a subcommand, e.g. `if set output (command)`. In query mode, the exit status is the number of variables that were not found. In erase mode, `set` exits with a zero exit status in case of success, with a non-zero exit status if the commandline was invalid, if the variable was write-protected or if the variable did not exist. + + +\subsection set-examples Examples +\fish +# Prints all global, exported variables. +set -xg + +# Sets the value of the variable $foo to be 'hi'. +set foo hi + +# Appends the value "there" to the variable $foo. +set -a foo there + +# Does the same thing as the previous two commands the way it would be done pre-fish 3.0. +set foo hi +set foo $foo there + +# Removes the variable $smurf +set -e smurf + +# Changes the fourth element of the $PATH array to ~/bin +set PATH[4] ~/bin + +# Outputs the path to Python if `type -p` returns true. +if set python_path (type -p python) + echo "Python is at $python_path" +end +\endfish + +\subsection set-notes Notes + +Fish versions prior to 3.0 supported the syntax `set PATH[1] PATH[4] /bin /sbin`, which worked like +`set PATH[1 4] /bin /sbin`. This syntax was not widely used, and was ambiguous and inconsistent. diff --git a/sphinx_doc_src/cmds/set_color.rst b/sphinx_doc_src/cmds/set_color.rst new file mode 100644 index 000000000..8af576458 --- /dev/null +++ b/sphinx_doc_src/cmds/set_color.rst @@ -0,0 +1,57 @@ +\section set_color set_color - set the terminal color + +\subsection set_color-synopsis Synopsis +\fish{synopsis} +set_color [OPTIONS] VALUE +\endfish + +\subsection set_color-description Description + +`set_color` is used to control the color and styling of text in the terminal. `VALUE` corresponds to a reserved color name such as *red* or a RGB color value given as 3 or 6 hexadecimal digits. The *br*-, as in 'bright', forms are full-brightness variants of the 8 standard-brightness colors on many terminals. *brblack* has higher brightness than *black* - towards gray. A special keyword *normal* resets text formatting to terminal defaults. + +Valid colors include: + + - *black*, *red*, *green*, *yellow*, *blue*, *magenta*, *cyan*, *white* + - *brblack*, *brred*, *brgreen*, *bryellow*, *brblue*, *brmagenta*, *brcyan*, *brwhite* + +An RGB value with three or six hex digits, such as A0FF33 or f2f can be used. `fish` will choose the closest supported color. A three digit value is equivalent to specifying each digit twice; e.g., `set_color 2BC` is the same as `set_color 22BBCC`. Hexadecimal RGB values can be in lower or uppercase. Depending on the capabilities of your terminal (and the level of support `set_color` has for it) the actual color may be approximated by a nearby matching reserved color name or `set_color` may not have an effect on color. A second color may be given as a desired fallback color. e.g. `set_color 124212` *brblue* will instruct set_color to use *brblue* if a terminal is not capable of the exact shade of grey desired. This is very useful when an 8 or 16 color terminal might otherwise not use a color. + +The following options are available: + +- `-b`, `--background` *COLOR* sets the background color. +- `-c`, `--print-colors` prints a list of the 16 named colors. +- `-o`, `--bold` sets bold mode. +- `-d`, `--dim` sets dim mode. +- `-i`, `--italics` sets italics mode. +- `-r`, `--reverse` sets reverse mode. +- `-u`, `--underline` sets underlined mode. + +Using the *normal* keyword will reset foreground, background, and all formatting back to default. + +\subsection set_color-notes Notes + +1. Using the *normal* keyword will reset both background and foreground colors to whatever is the default for the terminal. +2. Setting the background color only affects subsequently written characters. Fish provides no way to set the background color for the entire terminal window. Configuring the window background color (and other attributes such as its opacity) has to be done using whatever mechanisms the terminal provides. +3. Some terminals use the `--bold` escape sequence to switch to a brighter color set rather than increasing the weight of text. +4. `set_color` works by printing sequences of characters to *stdout*. If used in command substitution or a pipe, these characters will also be captured. This may or may not be desirable. Checking the exit code of `isatty stdout` before using `set_color` can be useful to decide not to colorize output in a script. + +\subsection set_color-example Examples + +\fish +set_color red; echo "Roses are red" +set_color blue; echo "Violets are blue" +set_color 62A; echo "Eggplants are dark purple" +set_color normal; echo "Normal is nice" # Resets the background too +\endfish + +\subsection set_color-detection Terminal Capability Detection + +Fish uses a heuristic to decide if a terminal supports the 256-color palette as opposed to the more limited 16 color palette of older terminals. Support can be forced on by setting `fish_term256` to *1*. If `$TERM` contains "256color" (e.g., *xterm-256color*), 256-color support is enabled. If `$TERM` contains *xterm*, 256 color support is enabled (except for MacOS: `$TERM_PROGRAM` and `$TERM_PROGRAM_VERSION` are used to detect Terminal.app from MacOS 10.6; support is disabled here it because it is known that it reports `xterm` and only supports 16 colors. + +If terminfo reports 256 color support for a terminal, support will always be enabled. To debug color palette problems, `tput colors` may be useful to see the number of colors in terminfo for a terminal. Fish launched as `fish -d2` will include diagnostic messages that indicate the color support mode in use. + +Many terminals support 24-bit (i.e., true-color) color escape sequences. This includes modern xterm, Gnome Terminal, Konsole, and iTerm2. Fish attempts to detect such terminals through various means in `config.fish` You can explicitly force that support via `set fish_term24bit 1`. + +The `set_color` command uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Fish will assume that all terminals can use the [ANSI X3.64](https://en.wikipedia.org/wiki/ANSI_escape_code) escape sequences if the terminfo definition indicates a color below 16 is not supported. + +Support for italics, dim, reverse, and other modes is not guaranteed in all terminal emulators. Fish attempts to determine if the terminal supports these modes even if the terminfo database may not be up-to-date. diff --git a/sphinx_doc_src/cmds/source.rst b/sphinx_doc_src/cmds/source.rst new file mode 100644 index 000000000..7b32654ee --- /dev/null +++ b/sphinx_doc_src/cmds/source.rst @@ -0,0 +1,29 @@ +\section source source - evaluate contents of file. + +\subsection source-synopsis Synopsis +\fish{synopsis} +source FILENAME [ARGUMENTS...] +somecommand | source +\endfish + +\subsection source-description Description + +`source` evaluates the commands of the specified file in the current shell. This is different from starting a new process to perform the commands (i.e. `fish < FILENAME`) since the commands will be evaluated by the current shell, which means that changes in shell variables will affect the current shell. If additional arguments are specified after the file name, they will be inserted into the `$argv` variable. The `$argv` variable will not include the name of the sourced file. + +If no file is specified and stdin is not the terminal, or if the file name '`-`' is used, stdin will be read. + +The return status of `source` is the return status of the last job to execute. If something goes wrong while opening or reading the file, `source` exits with a non-zero status. + +`.` (a single period) is an alias for the `source` command. The use of `.` is deprecated in favour of `source`, and `.` will be removed in a future version of fish. + + +\subsection source-example Example + +\fish +source ~/.config/fish/config.fish +# Causes fish to re-read its initialization file. +\endfish + +\subsection Caveats + +In fish versions prior to 2.3.0 the `$argv` variable would have a single element (the name of the sourced file) if no arguments are present. Otherwise it would contain arguments without the name of the sourced file. That behavior was very confusing and unlike other shells such as bash and zsh. diff --git a/sphinx_doc_src/cmds/status.rst b/sphinx_doc_src/cmds/status.rst new file mode 100644 index 000000000..b69996d57 --- /dev/null +++ b/sphinx_doc_src/cmds/status.rst @@ -0,0 +1,67 @@ +\section status status - query fish runtime information + +\subsection status-synopsis Synopsis +\fish{synopsis} +status +status is-login +status is-interactive +status is-block +status is-breakpoint +status is-command-substitution +status is-no-job-control +status is-full-job-control +status is-interactive-job-control +status filename +status fish-path +status function +status line-number +status stack-trace +status job-control CONTROL-TYPE +status features +status test-feature FEATURE +\endfish + +\subsection status-description Description + +With no arguments, `status` displays a summary of the current login and job control status of the shell. + +The following operations (sub-commands) are available: + +- `is-command-sub` returns 0 if fish is currently executing a command substitution. Also `-c` or `--is-command-substitution`. + +- `is-block` returns 0 if fish is currently executing a block of code. Also `-b` or `--is-block`. + +- `is-breakpoint` returns 0 if fish is currently showing a prompt in the context of a `breakpoint` command. See also the `fish_breakpoint_prompt` function. + +- `is-interactive` returns 0 if fish is interactive - that is, connected to a keyboard. Also `-i` or `--is-interactive`. + +- `is-login` returns 0 if fish is a login shell - that is, if fish should perform login tasks such as setting up the PATH. Also `-l` or `--is-login`. + +- `is-full-job-control` returns 0 if full job control is enabled. Also `--is-full-job-control` (no short flag). + +- `is-interactive-job-control` returns 0 if interactive job control is enabled. Also, `--is-interactive-job-control` (no short flag). + +- `is-no-job-control` returns 0 if no job control is enabled. Also `--is-no-job-control` (no short flag). + +- `filename` prints the filename of the currently running script. Also `current-filename`, `-f` or `--current-filename`. + +- `fish-path` prints the absolute path to the currently executing instance of fish. + +- `function` prints the name of the currently called function if able, when missing displays "Not a + function" (or equivalent translated string). Also `current-function`, `-u` or `--current-function`. + +- `line-number` prints the line number of the currently running script. Also `current-line-number`, `-n` or `--current-line-number`. + +- `stack-trace` prints a stack trace of all function calls on the call stack. Also `print-stack-trace`, `-t` or `--print-stack-trace`. + +- `job-control CONTROL-TYPE` sets the job control type, which can be `none`, `full`, or `interactive`. Also `-j CONTROL-TYPE` or `--job-control=CONTROL-TYPE`. + +- `features` lists all available feature flags. + +- `test-feature FEATURE` returns 0 when FEATURE is enabled, 1 if it is disabled, and 2 if it is not recognized. + +\subsection status-notes Notes + +For backwards compatibility each subcommand can also be specified as a long or short option. For example, rather than `status is-login` you can type `status --is-login`. The flag forms are deprecated and may be removed in a future release (but not before fish 3.0). + +You can only specify one subcommand per invocation even if you use the flag form of the subcommand. diff --git a/sphinx_doc_src/cmds/string.rst b/sphinx_doc_src/cmds/string.rst new file mode 100644 index 000000000..52bca9445 --- /dev/null +++ b/sphinx_doc_src/cmds/string.rst @@ -0,0 +1,359 @@ +\section string string - manipulate strings + +\subsection string-synopsis Synopsis +\fish{synopsis} +string escape [(-n | --no-quoted)] [--style=xxx] [STRING...] +string join [(-q | --quiet)] SEP [STRING...] +string join0 [(-q | --quiet)] [STRING...] +string length [(-q | --quiet)] [STRING...] +string lower [(-q | --quiet)] [STRING...] +string match [(-a | --all)] [(-e | --entire)] [(-i | --ignore-case)] [(-r | --regex)] + [(-n | --index)] [(-q | --quiet)] [(-v | --invert)] PATTERN [STRING...] +string repeat [(-n | --count) COUNT] [(-m | --max) MAX] [(-N | --no-newline)] + [(-q | --quiet)] [STRING...] +string replace [(-a | --all)] [(-f | --filter)] [(-i | --ignore-case)] [(-r | --regex)] + [(-q | --quiet)] PATTERN REPLACEMENT [STRING...] +string split [(-m | --max) MAX] [(-n | --no-empty)] [(-q | --quiet)] [(-r | --right)] SEP + [STRING...] +string split0 [(-m | --max) MAX] [(-n | --no-empty)] [(-q | --quiet)] [(-r | --right)] + [STRING...] +string sub [(-s | --start) START] [(-l | --length) LENGTH] [(-q | --quiet)] + [STRING...] +string trim [(-l | --left)] [(-r | --right)] [(-c | --chars CHARS)] + [(-q | --quiet)] [STRING...] +string unescape [--style=xxx] [STRING...] +string upper [(-q | --quiet)] [STRING...] +\endfish + + +\subsection string-description Description + +`string` performs operations on strings. + +STRING arguments are taken from the command line unless standard input is connected to a pipe or a file, in which case they are read from standard input, one STRING per line. It is an error to supply STRING arguments on the command line and on standard input. + +Arguments beginning with `-` are normally interpreted as switches; `--` causes the following arguments not to be treated as switches even if they begin with `-`. Switches and required arguments are recognized only on the command line. + +Most subcommands accept a `-q` or `--quiet` switch, which suppresses the usual output but exits with the documented status. + +The following subcommands are available. + +\subsection string-escape "escape" subcommand + +`string escape` escapes each STRING in one of three ways. The first is `--style=script`. This is the default. It alters the string such that it can be passed back to `eval` to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If `-n` or `--no-quoted` is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise. + +`--style=var` ensures the string can be used as a variable name by hex encoding any non-alphanumeric characters. The string is first converted to UTF-8 before being encoded. + +`--style=url` ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF-8 before being encoded. + +`--style=regex` escapes an input string for literal matching within a regex expression. The string is first converted to UTF-8 before being encoded. + +`string unescape` performs the inverse of the `string escape` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing `string unescape --style=var (string escape --style=var $str)` will return the original string. There is no support for unescaping pcre2. + +\subsection string-join "join" subcommand + +`string join` joins its STRING arguments into a single string separated by SEP, which can be an empty string. Exit status: 0 if at least one join was performed, or 1 otherwise. + +\subsection string-join0 "join0" subcommand + +`string join` joins its STRING arguments into a single string separated by the zero byte (NUL), and adds a trailing NUL. This is most useful in conjunction with tools that accept NUL-delimited input, such as `sort -z`. Exit status: 0 if at least one join was performed, or 1 otherwise. + +\subsection string-length "length" subcommand + +`string length` reports the length of each string argument in characters. Exit status: 0 if at least one non-empty STRING was given, or 1 otherwise. + +\subsection string-lower "lower" subcommand + +`string lower` converts each string argument to lowercase. Exit status: 0 if at least one string was converted to lowercase, else 1. This means that in conjunction with the `-q` flag you can readily test whether a string is already lowercase. + +\subsection string-match "match" subcommand + +`string match` tests each STRING against PATTERN and prints matching substrings. Only the first match for each STRING is reported unless `-a` or `--all` is given, in which case all matches are reported. + +If you specify the `-e` or `--entire` then each matching string is printed including any prefix or suffix not matched by the pattern (equivalent to `grep` without the `-o` flag). You can, obviously, achieve the same result by prepending and appending `*` or `.*` depending on whether or not you have specified the `--regex` flag. The `--entire` flag is simply a way to avoid having to complicate the pattern in that fashion and make the intent of the `string match` clearer. Without `--entire` and `--regex`, a PATTERN will need to match the entire STRING before it will be reported. + +Matching can be made case-insensitive with `--ignore-case` or `-i`. + +If `--index` or `-n` is given, each match is reported as a 1-based start position and a length. By default, PATTERN is interpreted as a glob pattern matched against each entire STRING argument. A glob pattern is only considered a valid match if it matches the entire STRING. + +If `--regex` or `-r` is given, PATTERN is interpreted as a Perl-compatible regular expression, which does not have to match the entire STRING. For a regular expression containing capturing groups, multiple items will be reported for each match, one for the entire match and one for each capturing group. With this, only the matching part of the STRING will be reported, unless `--entire` is given. + +If `--invert` or `-v` is used the selected lines will be only those which do not match the given glob pattern or regular expression. + +Exit status: 0 if at least one match was found, or 1 otherwise. + +\subsection string-repeat "repeat" subcommand + +`string repeat` repeats the STRING `-n` or `--count` times. The `-m` or `--max` option will limit the number of outputted char (excluding the newline). This option can be used by itself or in conjunction with `--count`. If both `--count` and `--max` are present, max char will be outputed unless the final repeated string size is less than max, in that case, the string will repeat until count has been reached. Both `--count` and `--max` will accept a number greater than or equal to zero, in the case of zero, nothing will be outputed. If `-N` or `--no-newline` is given, the output won't contain a newline character at the end. Exit status: 0 if yielded string is not empty, 1 otherwise. + +\subsection string-replace "replace" subcommand + +`string replace` is similar to `string match` but replaces non-overlapping matching substrings with a replacement string and prints the result. By default, PATTERN is treated as a literal substring to be matched. + +If `-r` or `--regex` is given, PATTERN is interpreted as a Perl-compatible regular expression, and REPLACEMENT can contain C-style escape sequences like `\t` as well as references to capturing groups by number or name as `$n` or `${n}`. + +If you specify the `-f` or `--filter` flag then each input string is printed only if a replacement was done. This is useful where you would otherwise use this idiom: `a_cmd | string match pattern | string replace pattern new_pattern`. You can instead just write `a_cmd | string replace --filter pattern new_pattern`. + +Exit status: 0 if at least one replacement was performed, or 1 otherwise. + +\subsection string-split "split" subcommand + +`string split` splits each STRING on the separator SEP, which can be an empty string. If `-m` or `--max` is specified, at most MAX splits are done on each STRING. If `-r` or `--right` is given, splitting is performed right-to-left. This is useful in combination with `-m` or `--max`. With `-n` or `--no-empty`, empty results are excluded from consideration (e.g. `hello\n\nworld` would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise. + +See also `read --delimiter`. + +\subsection string-split0 "split0" subcommand + +`string split0` splits each STRING on the zero byte (NUL). Options are the same as `string split` except that no separator is given. + +`split0` has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as `find -print0` or `sort -z`. See split0 examples below. + +\subsection string-sub "sub" subcommand + +`string sub` prints a substring of each string argument. The start of the substring can be specified with `-s` or `--start` followed by a 1-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with `-l` or `--length`. If the length is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise. + +\subsection string-trim "trim" subcommand + +`string trim` removes leading and trailing whitespace from each STRING. If `-l` or `--left` is given, only leading whitespace is removed. If `-r` or `--right` is given, only trailing whitespace is trimmed. The `-c` or `--chars` switch causes the characters in CHARS to be removed instead of whitespace. Exit status: 0 if at least one character was trimmed, or 1 otherwise. + +\subsection string-upper "upper" subcommand + +`string upper` converts each string argument to uppercase. Exit status: 0 if at least one string was converted to uppercase, else 1. This means that in conjunction with the `-q` flag you can readily test whether a string is already uppercase. + +\subsection regular-expressions Regular Expressions + +Both the `match` and `replace` subcommand support regular expressions when used with the `-r` or `--regex` option. The dialect is that of PCRE2. + +In general, special characters are special by default, so `a+` matches one or more "a"s, while `a\+` matches an "a" and then a "+". `(a+)` matches one or more "a"s in a capturing group (`(?:XXXX)` denotes a non-capturing group). For the replacement parameter of `replace`, `$n` refers to the n-th group of the match. In the match parameter, `\n` (e.g. `\1`) refers back to groups. + +Some features include repetitions: +- `*` refers to 0 or more repetitions of the previous expression +- `+` 1 or more +- `?` 0 or 1. +- `{n}` to exactly n (where n is a number) +- `{n,m}` at least n, no more than m. +- `{n,}` n or more + +Character classes, some of the more important: +- `.` any character except newline +- `\d` a decimal digit and `\D`, not a decimal digit +- `\s` whitespace and `\S`, not whitespace +- `\w` a "word" character and `\W`, a "non-word" character +- `[...]` (where "..." is some characters) is a character set +- `[^...]` is the inverse of the given character set +- `[x-y]` is the range of characters from x-y +- `[[:xxx:]]` is a named character set +- `[[:^xxx:]]` is the inverse of a named character set +- `[[:alnum:]]` : "alphanumeric" +- `[[:alpha:]]` : "alphabetic" +- `[[:ascii:]]` : "0-127" +- `[[:blank:]]` : "space or tab" +- `[[:cntrl:]]` : "control character" +- `[[:digit:]]` : "decimal digit" +- `[[:graph:]]` : "printing, excluding space" +- `[[:lower:]]` : "lower case letter" +- `[[:print:]]` : "printing, including space" +- `[[:punct:]]` : "printing, excluding alphanumeric" +- `[[:space:]]` : "white space" +- `[[:upper:]]` : "upper case letter" +- `[[:word:]]` : "same as \w" +- `[[:xdigit:]]` : "hexadecimal digit" + +Groups: +- `(...)` is a capturing group +- `(?:...)` is a non-capturing group +- `\n` is a backreference (where n is the number of the group, starting with 1) +- `$n` is a reference from the replacement expression to a group in the match expression. + +And some other things: +- `\b` denotes a word boundary, `\B` is not a word boundary. +- `^` is the start of the string or line, `$` the end. +- `|` is "alternation", i.e. the "or". + +\subsection string-example Examples + +\fish{cli-dark} +>_ string length 'hello, world' +12 + +>_ set str foo +>_ string length -q $str; echo $status +0 +# Equivalent to test -n $str +\endfish + +\fish{cli-dark} +>_ string sub --length 2 abcde +ab + +>_ string sub -s 2 -l 2 abcde +bc + +>_ string sub --start=-2 abcde +de +\endfish + +\fish{cli-dark} +>_ string split . example.com +example +com + +>_ string split -r -m1 / /usr/local/bin/fish +/usr/local/bin +fish + +>_ string split '' abc +a +b +c +\endfish + +\fish{cli-dark} +>_ seq 3 | string join ... +1...2...3 +\endfish + +\fish{cli-dark} +>_ string trim ' abc ' +abc + +>_ string trim --right --chars=yz xyzzy zany +x +zan +\endfish + +\fish{cli-dark} +>_ echo \\x07 | string escape +cg +\endfish + +\fish{cli-dark} +>_ string escape --style=var 'a1 b2'\\u6161 +a1_20b2__c_E6_85_A1 +\endfish + +\subsection string-example-match-glob Match Glob Examples + +\fish{cli-dark} +>_ string match '?' a +a + +>_ string match 'a*b' axxb +axxb + +>_ string match -i 'a??B' Axxb +Axxb + +>_ echo 'ok?' | string match '*\\?' +ok? + +# Note that only the second STRING will match here. +>_ string match 'foo' 'foo1' 'foo' 'foo2' +foo + +>_ string match -e 'foo' 'foo1' 'foo' 'foo2' +foo1 +foo +foo2 + + +>_ string match 'foo?' 'foo1' 'foo' 'foo2' +foo1 +foo +foo2 + +\endfish + +\subsection string-example-match-regex Match Regex Examples + +\fish{cli-dark} +>_ string match -r 'cat|dog|fish' 'nice dog' +dog + +>_ string match -r -v "c.*[12]" {cat,dog}(seq 1 4) +dog1 +dog2 +cat3 +dog3 +cat4 +dog4 + +>_ string match -r '(\\d\\d?):(\\d\\d):(\\d\\d)' 2:34:56 +2:34:56 +2 +34 +56 + +>_ string match -r '^(\\w{{2,4}})\\g1$' papa mud murmur +papa +pa +murmur +mur + +>_ string match -r -a -n at ratatat +2 2 +4 2 +6 2 + +>_ string match -r -i '0x[0-9a-f]{{1,8}}' 'int magic = 0xBadC0de;' +0xBadC0de +\endfish + +\subsection string-example-split0 NUL Delimited Examples + +\fish{cli-dark} +>_ # Count files in a directory, without being confused by newlines. +>_ count (find . -print0 | string split0) +42 + +>_ # Sort a list of elements which may contain newlines +>_ set foo beta alpha\\ngamma +>_ set foo (string join0 $foo | sort -z | string split0) +>_ string escape $foo[1] +alpha\\ngamma +\endfish + +\subsection string-example-replace-literal Replace Literal Examples + +\fish{cli-dark} +>_ string replace is was 'blue is my favorite' +blue was my favorite + +>_ string replace 3rd last 1st 2nd 3rd +1st +2nd +last + +>_ string replace -a ' ' _ 'spaces to underscores' +spaces_to_underscores +\endfish + +\subsection string-example-replace-Regex Replace Regex Examples + +\fish{cli-dark} +>_ string replace -r -a '[^\\d.]+' ' ' '0 one two 3.14 four 5x' +0 3.14 5 + +>_ string replace -r '(\\w+)\\s+(\\w+)' '$2 $1 $$' 'left right' +right left $ + +>_ string replace -r '\\s*newline\\s*' '\\n' 'put a newline here' +put a +here +\endfish + +\subsection string-example-repeat Repeat Examples + +\fish{cli-dark} +>_ string repeat -n 2 'foo ' +foo foo + +>_ echo foo | string repeat -n 2 +foofoo + +>_ string repeat -n 2 -m 5 'foo' +foofo + +>_ string repeat -m 5 'foo' +foofo +\endfish diff --git a/sphinx_doc_src/cmds/suspend.rst b/sphinx_doc_src/cmds/suspend.rst new file mode 100644 index 000000000..0fc9485b6 --- /dev/null +++ b/sphinx_doc_src/cmds/suspend.rst @@ -0,0 +1,15 @@ +\section suspend suspend - suspend the current shell + +\subsection suspend-synopsis Synopsis +\fish{synopsis} +suspend [--force] +\endfish + +\subsection suspend-description Description + +`suspend` suspends execution of the current shell by sending it a +SIGTSTP signal, returning to the controlling process. It can be +resumed later by sending it a SIGCONT. In order to prevent suspending +a shell that doesn't have a controlling process, it will not suspend +the shell if it is a login shell. This requirement is bypassed +if the `--force` option is given or the shell is not interactive. \ No newline at end of file diff --git a/sphinx_doc_src/cmds/switch.rst b/sphinx_doc_src/cmds/switch.rst new file mode 100644 index 000000000..9bba2bb0d --- /dev/null +++ b/sphinx_doc_src/cmds/switch.rst @@ -0,0 +1,39 @@ +\section switch switch - conditionally execute a block of commands + +\subsection switch-synopsis Synopsis +\fish{synopsis} +switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end +\endfish + +\subsection switch-description Description + +`switch` performs one of several blocks of commands, depending on whether a specified value equals one of several wildcarded values. `case` is used together with the `switch` statement in order to determine which block should be executed. + +Each `case` command is given one or more parameters. The first `case` command with a parameter that matches the string specified in the switch command will be evaluated. `case` parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames. + +Note that fish does not fall through on case statements. Only the first matching case is executed. + +Note that command substitutions in a case statement will be evaluated even if its body is not taken. All substitutions, including command substitutions, must be performed before the value can be compared against the parameter. + + +\subsection switch-example Example + +If the variable \$animal contains the name of an animal, the following code would attempt to classify it: + +\fish +switch $animal + case cat + echo evil + case wolf dog human moose dolphin whale + echo mammal + case duck goose albatross + echo bird + case shark trout stingray + echo fish + case '*' + echo I have no idea what a $animal is +end +\endfish + +If the above code was run with `$animal` set to `whale`, the output +would be `mammal`. diff --git a/sphinx_doc_src/cmds/test.rst b/sphinx_doc_src/cmds/test.rst new file mode 100644 index 000000000..1f54f1b00 --- /dev/null +++ b/sphinx_doc_src/cmds/test.rst @@ -0,0 +1,166 @@ +\section test test - perform tests on files and text + +\subsection test-synopsis Synopsis +\fish{synopsis} +test [EXPRESSION] +[ [EXPRESSION] ] +\endfish + +\subsection test-description Description + +Tests the expression given and sets the exit status to 0 if true, and 1 if false. An expression is made up of one or more operators and their arguments. + +The first form (`test`) is preferred. For compatibility with other shells, the second form is available: a matching pair of square brackets (`[ [EXPRESSION ] ]`). + +This test is mostly POSIX-compatible. + +When using a variable as an argument for a test operator you should almost always enclose it in double-quotes. There are only two situations it is safe to omit the quote marks. The first is when the argument is a literal string with no whitespace or other characters special to the shell (e.g., semicolon). For example, `test -b /my/file`. The second is using a variable that expands to exactly one element including if that element is the empty string (e.g., `set x ''`). If the variable is not set, set but with no value, or set to more than one value you must enclose it in double-quotes. For example, `test "$x" = "$y"`. Since it is always safe to enclose variables in double-quotes when used as `test` arguments that is the recommended practice. + +\subsection test-files Operators for files and directories + +- `-b FILE` returns true if `FILE` is a block device. + +- `-c FILE` returns true if `FILE` is a character device. + +- `-d FILE` returns true if `FILE` is a directory. + +- `-e FILE` returns true if `FILE` exists. + +- `-f FILE` returns true if `FILE` is a regular file. + +- `-g FILE` returns true if `FILE` has the set-group-ID bit set. + +- `-G FILE` returns true if `FILE` exists and has the same group ID as the current user. + +- `-k FILE` returns true if `FILE` has the sticky bit set. If the OS does not support the concept it returns false. See https://en.wikipedia.org/wiki/Sticky_bit. + +- `-L FILE` returns true if `FILE` is a symbolic link. + +- `-O FILE` returns true if `FILE` exists and is owned by the current user. + +- `-p FILE` returns true if `FILE` is a named pipe. + +- `-r FILE` returns true if `FILE` is marked as readable. + +- `-s FILE` returns true if the size of `FILE` is greater than zero. + +- `-S FILE` returns true if `FILE` is a socket. + +- `-t FD` returns true if the file descriptor `FD` is a terminal (TTY). + +- `-u FILE` returns true if `FILE` has the set-user-ID bit set. + +- `-w FILE` returns true if `FILE` is marked as writable; note that this does not check if the filesystem is read-only. + +- `-x FILE` returns true if `FILE` is marked as executable. + +\subsection test-strings Operators for text strings + +- `STRING1 = STRING2` returns true if the strings `STRING1` and `STRING2` are identical. + +- `STRING1 != STRING2` returns true if the strings `STRING1` and `STRING2` are not identical. + +- `-n STRING` returns true if the length of `STRING` is non-zero. + +- `-z STRING` returns true if the length of `STRING` is zero. + +\subsection test-numbers Operators to compare and examine numbers + +- `NUM1 -eq NUM2` returns true if `NUM1` and `NUM2` are numerically equal. + +- `NUM1 -ne NUM2` returns true if `NUM1` and `NUM2` are not numerically equal. + +- `NUM1 -gt NUM2` returns true if `NUM1` is greater than `NUM2`. + +- `NUM1 -ge NUM2` returns true if `NUM1` is greater than or equal to `NUM2`. + +- `NUM1 -lt NUM2` returns true if `NUM1` is less than `NUM2`. + +- `NUM1 -le NUM2` returns true if `NUM1` is less than or equal to `NUM2`. + +Both integers and floating point numbers are supported. + +\subsection test-combinators Operators to combine expressions + +- `COND1 -a COND2` returns true if both `COND1` and `COND2` are true. + +- `COND1 -o COND2` returns true if either `COND1` or `COND2` are true. + +Expressions can be inverted using the `!` operator: + +- `! EXPRESSION` returns true if `EXPRESSION` is false, and false if `EXPRESSION` is true. + +Expressions can be grouped using parentheses. + +- `( EXPRESSION )` returns the value of `EXPRESSION`. + + Note that parentheses will usually require escaping with `\(` to avoid being interpreted as a command substitution. + + +\subsection test-example Examples + +If the `/tmp` directory exists, copy the `/etc/motd` file to it: + +\fish +if test -d /tmp + cp /etc/motd /tmp/motd +end +\endfish + +If the variable `MANPATH` is defined and not empty, print the contents. (If `MANPATH` is not defined, then it will expand to zero arguments, unless quoted.) + +\fish +if test -n "$MANPATH" + echo $MANPATH +end +\endfish + +Parentheses and the `-o` and `-a` operators can be combined to produce more complicated expressions. In this example, success is printed if there is a `/foo` or `/bar` file as well as a `/baz` or `/bat` file. + +\fish +if test \( -f /foo -o -f /bar \) -a \( -f /baz -o -f /bat \) + echo Success. +end. +\endfish + +Numerical comparisons will simply fail if one of the operands is not a number: + +\fish +if test 42 -eq "The answer to life, the universe and everything" + echo So long and thanks for all the fish # will not be executed +end +\endfish + +A common comparison is with $status: + +\fish +if test $status -eq 0 + echo "Previous command succeeded" +end +\endfish + +The previous test can likewise be inverted: + +\fish +if test ! $status -eq 0 + echo "Previous command failed" +end +\endfish + +which is logically equivalent to the following: + +\fish +if test $status -ne 0 + echo "Previous command failed" +end +\endfish + +\subsection test-standards Standards + +`test` implements a subset of the IEEE Std 1003.1-2008 (POSIX.1) standard. The following exceptions apply: + +- The `<` and `>` operators for comparing strings are not implemented. + +- Because this test is a shell builtin and not a standalone utility, using the -c flag on a special file descriptors like standard input and output may not return the same result when invoked from within a pipe as one would expect when invoking the `test` utility in another shell. + + In cases such as this, one can use `command` `test` to explicitly use the system's standalone `test` rather than this `builtin` `test`. diff --git a/sphinx_doc_src/cmds/trap.rst b/sphinx_doc_src/cmds/trap.rst new file mode 100644 index 000000000..3c8d8a963 --- /dev/null +++ b/sphinx_doc_src/cmds/trap.rst @@ -0,0 +1,37 @@ +\section trap trap - perform an action when the shell receives a signal + +\subsection trap-synopsis Synopsis +\fish{synopsis} +trap [OPTIONS] [[ARG] REASON ... ] +\endfish + +\subsection trap-description Description + +`trap` is a wrapper around the fish event delivery framework. It exists for backwards compatibility with POSIX shells. For other uses, it is recommended to define an event handler. + +The following parameters are available: + +- `ARG` is the command to be executed on signal delivery. + +- `REASON` is the name of the event to trap. For example, a signal like `INT` or `SIGINT`, or the special symbol `EXIT`. + +- `-l` or `--list-signals` prints a list of signal names. + +- `-p` or `--print` prints all defined signal handlers. + +If `ARG` and `REASON` are both specified, `ARG` is the command to be executed when the event specified by `REASON` occurs (e.g., the signal is delivered). + +If `ARG` is absent (and there is a single REASON) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If `ARG` is the null string the signal specified by each `REASON` is ignored by the shell and by the commands it invokes. + +If `ARG` is not present and `-p` has been supplied, then the trap commands associated with each `REASON` are displayed. If no arguments are supplied or if only `-p` is given, `trap` prints the list of commands associated with each signal. + +Signal names are case insensitive and the `SIG` prefix is optional. + +The return status is 1 if any `REASON` is invalid; otherwise trap returns 0. + +\subsection trap-example Example + +\fish +trap "status --print-stack-trace" SIGUSR1 +# Prints a stack trace each time the SIGUSR1 signal is sent to the shell. +\endfish diff --git a/sphinx_doc_src/cmds/true.rst b/sphinx_doc_src/cmds/true.rst new file mode 100644 index 000000000..1418c1ed4 --- /dev/null +++ b/sphinx_doc_src/cmds/true.rst @@ -0,0 +1,10 @@ +\section true true - return a successful result + +\subsection true-synopsis Synopsis +\fish{synopsis} +true +\endfish + +\subsection true-description Description + +`true` sets the exit status to 0. diff --git a/sphinx_doc_src/cmds/type.rst b/sphinx_doc_src/cmds/type.rst new file mode 100644 index 000000000..2d1a56abf --- /dev/null +++ b/sphinx_doc_src/cmds/type.rst @@ -0,0 +1,34 @@ +\section type type - indicate how a command would be interpreted + +\subsection type-synopsis Synopsis +\fish{synopsis} +type [OPTIONS] NAME [NAME ...] +\endfish + +\subsection type-description Description + +With no options, `type` indicates how each `NAME` would be interpreted if used as a command name. + +The following options are available: + +- `-a` or `--all` prints all of possible definitions of the specified names. + +- `-f` or `--no-functions` suppresses function and builtin lookup. + +- `-t` or `--type` prints `function`, `builtin`, or `file` if `NAME` is a shell function, builtin, or disk file, respectively. + +- `-p` or `--path` returns the name of the disk file that would be executed, or nothing if `type -t name` would not return `file`. + +- `-P` or `--force-path` returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the $PATH. + +- `-q` or `--quiet` suppresses all output; this is useful when testing the exit status. + +The `-q`, `-p`, `-t` and `-P` flags (and their long flag aliases) are mutually exclusive. Only one can be specified at a time. + + +\subsection type-example Example + +\fish{cli-dark} +>_ type fg +fg is a builtin +\endfish diff --git a/sphinx_doc_src/cmds/ulimit.rst b/sphinx_doc_src/cmds/ulimit.rst new file mode 100644 index 000000000..86ffe2b6f --- /dev/null +++ b/sphinx_doc_src/cmds/ulimit.rst @@ -0,0 +1,64 @@ +\section ulimit ulimit - set or get resource usage limits + +\subsection ulimit-synopsis Synopsis +\fish{synopsis} +ulimit [OPTIONS] [LIMIT] +\endfish + +\subsection ulimit-description Description + +`ulimit` builtin sets or outputs the resource usage limits of the shell and any processes spawned by it. If a new limit value is omitted, the current value of the limit of the resource is printed; otherwise, the specified limit is set to the new value. + +Use one of the following switches to specify which resource limit to set or report: + +- `-c` or `--core-size`: the maximum size of core files created. By setting this limit to zero, core dumps can be disabled. + +- `-d` or `--data-size`: the maximum size of a process' data segment. + +- `-f` or `--file-size`: the maximum size of files created by the shell. + +- `-l` or `--lock-size`: the maximum size that may be locked into memory. + +- `-m` or `--resident-set-size`: the maximum resident set size. + +- `-n` or `--file-descriptor-count`: the maximum number of open file descriptors (most systems do not allow this value to be set). + +- `-s` or `--stack-size`: the maximum stack size. + +- `-t` or `--cpu-time`: the maximum amount of CPU time in seconds. + +- `-u` or `--process-count`: the maximum number of processes available to a single user. + +- `-v` or `--virtual-memory-size` The maximum amount of virtual memory available to the shell. + +Note that not all these limits are available in all operating systems. + +The value of limit can be a number in the unit specified for the resource or one of the special values `hard`, `soft`, or `unlimited`, which stand for the current hard limit, the current soft limit, and no limit, respectively. + +If limit is given, it is the new value of the specified resource. If no option is given, then `-f` is assumed. Values are in kilobytes, except for `-t`, which is in seconds and `-n` and `-u`, which are unscaled values. The return status is 0 unless an invalid option or argument is supplied, or an error occurs while setting a new limit. + +`ulimit` also accepts the following switches that determine what type of limit to set: + +- `-H` or `--hard` sets hard resource limit + +- `-S` or `--soft` sets soft resource limit + +A hard limit can only be decreased. Once it is set it cannot be increased; a soft limit may be increased up to the value of the hard limit. If neither -H nor -S is specified, both the soft and hard limits are updated when assigning a new limit value, and the soft limit is used when reporting the current value. + +The following additional options are also understood by `ulimit`: + +- `-a` or `--all` prints all current limits + +The `fish` implementation of `ulimit` should behave identically to the implementation in bash, except for these differences: + +- Fish `ulimit` supports GNU-style long options for all switches + +- Fish `ulimit` does not support the `-p` option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe size is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish. + +- Fish `ulimit` does not support getting or setting multiple limits in one command, except reporting all values using the -a switch + + +\subsection ulimit-example Example + +`ulimit -Hs 64` sets the hard stack size limit to 64 kB. + diff --git a/sphinx_doc_src/cmds/umask.rst b/sphinx_doc_src/cmds/umask.rst new file mode 100644 index 000000000..7429d8a9e --- /dev/null +++ b/sphinx_doc_src/cmds/umask.rst @@ -0,0 +1,41 @@ +\section umask umask - set or get the file creation mode mask + +\subsection umask-synopsis Synopsis +\fish{synopsis} +umask [OPTIONS] [MASK] +\endfish + +\subsection umask-description Description + +`umask` displays and manipulates the "umask", or file creation mode mask, which is used to restrict the default access to files. + +The umask may be expressed either as an octal number, which represents the rights that will be removed by default, or symbolically, which represents the only rights that will be granted by default. + +Access rights are explained in the manual page for the `chmod`(1) program. + +With no parameters, the current file creation mode mask is printed as an octal number. + +- `-h` or `--help` prints this message. + +- `-S` or `--symbolic` prints the umask in symbolic form instead of octal form. + +- `-p` or `--as-command` outputs the umask in a form that may be reused as input + +If a numeric mask is specified as a parameter, the current shell's umask will be set to that value, and the rights specified by that mask will be removed from new files and directories by default. + +If a symbolic mask is specified, the desired permission bits, and not the inverse, should be specified. A symbolic mask is a comma separated list of rights. Each right consists of three parts: + +- The first part specifies to whom this set of right applies, and can be one of `u`, `g`, `o` or `a`, where `u` specifies the user who owns the file, `g` specifies the group owner of the file, `o` specific other users rights and `a` specifies all three should be changed. + +- The second part of a right specifies the mode, and can be one of `=`, `+` or `-`, where `=` specifies that the rights should be set to the new value, `+` specifies that the specified right should be added to those previously specified and `-` specifies that the specified rights should be removed from those previously specified. + +- The third part of a right specifies what rights should be changed and can be any combination of `r`, `w` and `x`, representing read, write and execute rights. + +If the first and second parts are skipped, they are assumed to be `a` and `=`, respectively. As an example, `r,u+w` means all users should have read access and the file owner should also have write access. + +Note that symbolic masks currently do not work as intended. + + +\subsection umask-example Example + +`umask 177` or `umask u=rw` sets the file creation mask to read and write for the owner and no permissions at all for any other users. diff --git a/sphinx_doc_src/cmds/vared.rst b/sphinx_doc_src/cmds/vared.rst new file mode 100644 index 000000000..352357872 --- /dev/null +++ b/sphinx_doc_src/cmds/vared.rst @@ -0,0 +1,15 @@ +\section vared vared - interactively edit the value of an environment variable + +\subsection vared-synopsis Synopsis +\fish{synopsis} +vared VARIABLE_NAME +\endfish + +\subsection vared-description Description + +`vared` is used to interactively edit the value of an environment variable. Array variables as a whole can not be edited using `vared`, but individual array elements can. + + +\subsection vared-example Example + +`vared PATH[3]` edits the third element of the PATH array diff --git a/sphinx_doc_src/cmds/wait.rst b/sphinx_doc_src/cmds/wait.rst new file mode 100644 index 000000000..57aa27318 --- /dev/null +++ b/sphinx_doc_src/cmds/wait.rst @@ -0,0 +1,34 @@ +\section wait wait - wait for jobs to complete + +\subsection wait-synopsis Synopsis +\fish{synopsis} +wait [-n | --any] [PID | PROCESS_NAME] ... +\endfish + +\subsection wait-description Description + +`wait` waits for child jobs to complete. + +- If a pid is specified, the command waits for the job that the process with the pid belongs to. +- If a process name is specified, the command waits for the jobs that the matched processes belong to. +- If neither a pid nor a process name is specified, the command waits for all background jobs. +- If the `-n` / `--any` flag is provided, the command returns as soon as the first job completes. If it is not provided, it returns after all jobs complete. + +\subsection wait-example Example + +\fish +sleep 10 & +wait $last_pid +\endfish +spawns `sleep` in the background, and then waits until it finishes. +\fish +for i in (seq 1 5); sleep 10 &; end +wait +\endfish +spawns five jobs in the background, and then waits until all of them finishes. +\fish +for i in (seq 1 5); sleep 10 &; end +hoge & +wait sleep +\endfish +spawns five jobs and `hoge` in the background, and then waits until all `sleep`s finishes, and doesn't wait for `hoge` finishing. diff --git a/sphinx_doc_src/cmds/while.rst b/sphinx_doc_src/cmds/while.rst new file mode 100644 index 000000000..38338792f --- /dev/null +++ b/sphinx_doc_src/cmds/while.rst @@ -0,0 +1,24 @@ +\section while while - perform a command multiple times + +\subsection while-synopsis Synopsis +\fish{synopsis} +while CONDITION; COMMANDS...; end +\endfish + +\subsection while-description Description + +`while` repeatedly executes `CONDITION`, and if the exit status is 0, then executes `COMMANDS`. + +If the exit status of `CONDITION` is non-zero on the first iteration, `COMMANDS` will not be +executed at all, and the exit status of the loop set to the exit status of `CONDITION`. + +The exit status of the loop is 0 otherwise. + +You can use `and` or `or` for complex conditions. Even more complex control can be achieved with `while true` containing a break. + +\subsection while-example Example + +\fish +while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end +# outputs 'file exists' at 10 second intervals as long as the file foo.txt or bar.txt exists. +\endfish diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index 145fbcf8a..4b23d4dd1 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -5,6 +5,13 @@ Introduction This is the documentation for ``fish``, the friendly interactive shell. fish is a user friendly commandline shell intended mostly for interactive use. A shell is a program used to execute other programs. For the latest information on fish, please visit the `fish homepage `_. +.. toctree:: + :glob: + :maxdepth: 1 + + cmds/* + + .. _syntax: Syntax overview From c2138825110da285742af464a434e758c1cf6101 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 16 Dec 2018 17:39:33 -0800 Subject: [PATCH 105/191] Switch command docs from \section to reStructuredText --- sphinx_doc_src/cmds/abbr.rst | 4 +++- sphinx_doc_src/cmds/alias.rst | 4 +++- sphinx_doc_src/cmds/and.rst | 4 +++- sphinx_doc_src/cmds/argparse.rst | 4 +++- sphinx_doc_src/cmds/begin.rst | 4 +++- sphinx_doc_src/cmds/bg.rst | 4 +++- sphinx_doc_src/cmds/bind.rst | 4 +++- sphinx_doc_src/cmds/block.rst | 4 +++- sphinx_doc_src/cmds/break.rst | 4 +++- sphinx_doc_src/cmds/breakpoint.rst | 4 +++- sphinx_doc_src/cmds/builtin.rst | 4 +++- sphinx_doc_src/cmds/case.rst | 4 +++- sphinx_doc_src/cmds/cd.rst | 4 +++- sphinx_doc_src/cmds/cdh.rst | 4 +++- sphinx_doc_src/cmds/command.rst | 4 +++- sphinx_doc_src/cmds/commandline.rst | 4 +++- sphinx_doc_src/cmds/complete.rst | 4 +++- sphinx_doc_src/cmds/contains.rst | 4 +++- sphinx_doc_src/cmds/continue.rst | 4 +++- sphinx_doc_src/cmds/count.rst | 4 +++- sphinx_doc_src/cmds/dirh.rst | 4 +++- sphinx_doc_src/cmds/dirs.rst | 4 +++- sphinx_doc_src/cmds/disown.rst | 4 +++- sphinx_doc_src/cmds/echo.rst | 4 +++- sphinx_doc_src/cmds/else.rst | 4 +++- sphinx_doc_src/cmds/emit.rst | 4 +++- sphinx_doc_src/cmds/end.rst | 4 +++- sphinx_doc_src/cmds/eval.rst | 4 +++- sphinx_doc_src/cmds/exec.rst | 4 +++- sphinx_doc_src/cmds/exit.rst | 4 +++- sphinx_doc_src/cmds/false.rst | 4 +++- sphinx_doc_src/cmds/fg.rst | 4 +++- sphinx_doc_src/cmds/fish.rst | 4 +++- sphinx_doc_src/cmds/fish_breakpoint_prompt.rst | 4 +++- sphinx_doc_src/cmds/fish_config.rst | 4 +++- sphinx_doc_src/cmds/fish_indent.rst | 4 +++- sphinx_doc_src/cmds/fish_key_reader.rst | 4 +++- sphinx_doc_src/cmds/fish_mode_prompt.rst | 4 +++- sphinx_doc_src/cmds/fish_opt.rst | 4 +++- sphinx_doc_src/cmds/fish_prompt.rst | 4 +++- sphinx_doc_src/cmds/fish_right_prompt.rst | 4 +++- sphinx_doc_src/cmds/fish_update_completions.rst | 4 +++- sphinx_doc_src/cmds/fish_vi_mode.rst | 4 +++- sphinx_doc_src/cmds/for.rst | 4 +++- sphinx_doc_src/cmds/funced.rst | 4 +++- sphinx_doc_src/cmds/funcsave.rst | 4 +++- sphinx_doc_src/cmds/function.rst | 4 +++- sphinx_doc_src/cmds/functions.rst | 4 +++- sphinx_doc_src/cmds/help.rst | 4 +++- sphinx_doc_src/cmds/history.rst | 4 +++- sphinx_doc_src/cmds/if.rst | 4 +++- sphinx_doc_src/cmds/isatty.rst | 4 +++- sphinx_doc_src/cmds/jobs.rst | 4 +++- sphinx_doc_src/cmds/math.rst | 4 +++- sphinx_doc_src/cmds/nextd.rst | 4 +++- sphinx_doc_src/cmds/not.rst | 4 +++- sphinx_doc_src/cmds/open.rst | 4 +++- sphinx_doc_src/cmds/or.rst | 4 +++- sphinx_doc_src/cmds/popd.rst | 4 +++- sphinx_doc_src/cmds/prevd.rst | 4 +++- sphinx_doc_src/cmds/printf.rst | 4 +++- sphinx_doc_src/cmds/prompt_pwd.rst | 4 +++- sphinx_doc_src/cmds/psub.rst | 4 +++- sphinx_doc_src/cmds/pushd.rst | 4 +++- sphinx_doc_src/cmds/pwd.rst | 4 +++- sphinx_doc_src/cmds/random.rst | 4 +++- sphinx_doc_src/cmds/read.rst | 4 +++- sphinx_doc_src/cmds/realpath.rst | 4 +++- sphinx_doc_src/cmds/return.rst | 4 +++- sphinx_doc_src/cmds/set.rst | 4 +++- sphinx_doc_src/cmds/set_color.rst | 4 +++- sphinx_doc_src/cmds/source.rst | 4 +++- sphinx_doc_src/cmds/status.rst | 4 +++- sphinx_doc_src/cmds/string.rst | 4 +++- sphinx_doc_src/cmds/suspend.rst | 4 +++- sphinx_doc_src/cmds/switch.rst | 4 +++- sphinx_doc_src/cmds/test.rst | 4 +++- sphinx_doc_src/cmds/trap.rst | 4 +++- sphinx_doc_src/cmds/true.rst | 4 +++- sphinx_doc_src/cmds/type.rst | 4 +++- sphinx_doc_src/cmds/ulimit.rst | 4 +++- sphinx_doc_src/cmds/umask.rst | 4 +++- sphinx_doc_src/cmds/vared.rst | 4 +++- sphinx_doc_src/cmds/wait.rst | 4 +++- sphinx_doc_src/cmds/while.rst | 4 +++- 85 files changed, 255 insertions(+), 85 deletions(-) diff --git a/sphinx_doc_src/cmds/abbr.rst b/sphinx_doc_src/cmds/abbr.rst index 76b0cf5c9..da3d67f3a 100644 --- a/sphinx_doc_src/cmds/abbr.rst +++ b/sphinx_doc_src/cmds/abbr.rst @@ -1,4 +1,6 @@ -\section abbr abbr - manage fish abbreviations +abbr - manage fish abbreviations +========================================== + \subsection abbr-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/alias.rst b/sphinx_doc_src/cmds/alias.rst index 606a05ec7..e7c0ca543 100644 --- a/sphinx_doc_src/cmds/alias.rst +++ b/sphinx_doc_src/cmds/alias.rst @@ -1,4 +1,6 @@ -\section alias alias - create a function +alias - create a function +========================================== + \subsection alias-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/and.rst b/sphinx_doc_src/cmds/and.rst index 3757847de..7abca07dd 100644 --- a/sphinx_doc_src/cmds/and.rst +++ b/sphinx_doc_src/cmds/and.rst @@ -1,4 +1,6 @@ -\section and and - conditionally execute a command +and - conditionally execute a command +========================================== + \subsection and-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/argparse.rst b/sphinx_doc_src/cmds/argparse.rst index 70278198a..d54815d30 100644 --- a/sphinx_doc_src/cmds/argparse.rst +++ b/sphinx_doc_src/cmds/argparse.rst @@ -1,4 +1,6 @@ -\section argparse argparse - parse options passed to a fish script or function +argparse - parse options passed to a fish script or function +========================================== + \subsection argparse-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/begin.rst b/sphinx_doc_src/cmds/begin.rst index dd008bda9..cc63c36c4 100644 --- a/sphinx_doc_src/cmds/begin.rst +++ b/sphinx_doc_src/cmds/begin.rst @@ -1,4 +1,6 @@ -\section begin begin - start a new block of code +begin - start a new block of code +========================================== + \subsection begin-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/bg.rst b/sphinx_doc_src/cmds/bg.rst index 13733f58e..10f40c89c 100644 --- a/sphinx_doc_src/cmds/bg.rst +++ b/sphinx_doc_src/cmds/bg.rst @@ -1,4 +1,6 @@ -\section bg bg - send jobs to background +bg - send jobs to background +========================================== + \subsection bg-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/bind.rst b/sphinx_doc_src/cmds/bind.rst index d778cd31e..db064b71a 100644 --- a/sphinx_doc_src/cmds/bind.rst +++ b/sphinx_doc_src/cmds/bind.rst @@ -1,4 +1,6 @@ -\section bind bind - handle fish key bindings +bind - handle fish key bindings +========================================== + \subsection bind-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/block.rst b/sphinx_doc_src/cmds/block.rst index 9fbbade83..5fe5dd3c9 100644 --- a/sphinx_doc_src/cmds/block.rst +++ b/sphinx_doc_src/cmds/block.rst @@ -1,4 +1,6 @@ -\section block block - temporarily block delivery of events +block - temporarily block delivery of events +========================================== + \subsection block-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/break.rst b/sphinx_doc_src/cmds/break.rst index 32672c09f..0b609955c 100644 --- a/sphinx_doc_src/cmds/break.rst +++ b/sphinx_doc_src/cmds/break.rst @@ -1,4 +1,6 @@ -\section break break - stop the current inner loop +break - stop the current inner loop +========================================== + \subsection break-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/breakpoint.rst b/sphinx_doc_src/cmds/breakpoint.rst index 8645c18dd..f0efffd85 100644 --- a/sphinx_doc_src/cmds/breakpoint.rst +++ b/sphinx_doc_src/cmds/breakpoint.rst @@ -1,4 +1,6 @@ -\section breakpoint breakpoint - Launch debug mode +breakpoint - Launch debug mode +========================================== + \subsection breakpoint-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/builtin.rst b/sphinx_doc_src/cmds/builtin.rst index 4c465ef18..90c512cec 100644 --- a/sphinx_doc_src/cmds/builtin.rst +++ b/sphinx_doc_src/cmds/builtin.rst @@ -1,4 +1,6 @@ -\section builtin builtin - run a builtin command +builtin - run a builtin command +========================================== + \subsection builtin-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/case.rst b/sphinx_doc_src/cmds/case.rst index 065c19e9b..8cfee4a76 100644 --- a/sphinx_doc_src/cmds/case.rst +++ b/sphinx_doc_src/cmds/case.rst @@ -1,4 +1,6 @@ -\section case case - conditionally execute a block of commands +case - conditionally execute a block of commands +========================================== + \subsection case-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/cd.rst b/sphinx_doc_src/cmds/cd.rst index 748f0c322..786f3c68b 100644 --- a/sphinx_doc_src/cmds/cd.rst +++ b/sphinx_doc_src/cmds/cd.rst @@ -1,4 +1,6 @@ -\section cd cd - change directory +cd - change directory +========================================== + \subsection cd-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/cdh.rst b/sphinx_doc_src/cmds/cdh.rst index 7d18acd86..295ab4ea3 100644 --- a/sphinx_doc_src/cmds/cdh.rst +++ b/sphinx_doc_src/cmds/cdh.rst @@ -1,4 +1,6 @@ -\section cdh cdh - change to a recently visited directory +cdh - change to a recently visited directory +========================================== + \subsection cdh-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/command.rst b/sphinx_doc_src/cmds/command.rst index e4f5c2cf6..0eafa8223 100644 --- a/sphinx_doc_src/cmds/command.rst +++ b/sphinx_doc_src/cmds/command.rst @@ -1,4 +1,6 @@ -\section command command - run a program +command - run a program +========================================== + \subsection command-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/commandline.rst b/sphinx_doc_src/cmds/commandline.rst index d97001709..ea2dad4f9 100644 --- a/sphinx_doc_src/cmds/commandline.rst +++ b/sphinx_doc_src/cmds/commandline.rst @@ -1,4 +1,6 @@ -\section commandline commandline - set or get the current command line buffer +commandline - set or get the current command line buffer +========================================== + \subsection commandline-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/complete.rst b/sphinx_doc_src/cmds/complete.rst index d295d1381..1e9d42316 100644 --- a/sphinx_doc_src/cmds/complete.rst +++ b/sphinx_doc_src/cmds/complete.rst @@ -1,4 +1,6 @@ -\section complete complete - edit command specific tab-completions +complete - edit command specific tab-completions +========================================== + \subsection complete-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/contains.rst b/sphinx_doc_src/cmds/contains.rst index c65292c09..cc3d8b1c3 100644 --- a/sphinx_doc_src/cmds/contains.rst +++ b/sphinx_doc_src/cmds/contains.rst @@ -1,4 +1,6 @@ -\section contains contains - test if a word is present in a list +contains - test if a word is present in a list +========================================== + \subsection contains-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/continue.rst b/sphinx_doc_src/cmds/continue.rst index 26346be6a..11c34bd10 100644 --- a/sphinx_doc_src/cmds/continue.rst +++ b/sphinx_doc_src/cmds/continue.rst @@ -1,4 +1,6 @@ -\section continue continue - skip the remainder of the current iteration of the current inner loop +continue - skip the remainder of the current iteration of the current inner loop +========================================== + \subsection continue-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/count.rst b/sphinx_doc_src/cmds/count.rst index bf11a6350..0b5659644 100644 --- a/sphinx_doc_src/cmds/count.rst +++ b/sphinx_doc_src/cmds/count.rst @@ -1,4 +1,6 @@ -\section count count - count the number of elements of an array +count - count the number of elements of an array +========================================== + \subsection count-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/dirh.rst b/sphinx_doc_src/cmds/dirh.rst index 77e03e185..bf94537ba 100644 --- a/sphinx_doc_src/cmds/dirh.rst +++ b/sphinx_doc_src/cmds/dirh.rst @@ -1,4 +1,6 @@ -\section dirh dirh - print directory history +dirh - print directory history +========================================== + \subsection dirh-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/dirs.rst b/sphinx_doc_src/cmds/dirs.rst index c3da6e84f..576d7de63 100644 --- a/sphinx_doc_src/cmds/dirs.rst +++ b/sphinx_doc_src/cmds/dirs.rst @@ -1,4 +1,6 @@ -\section dirs dirs - print directory stack +dirs - print directory stack +========================================== + \subsection dirs-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/disown.rst b/sphinx_doc_src/cmds/disown.rst index 45f5c025a..5047db5e5 100644 --- a/sphinx_doc_src/cmds/disown.rst +++ b/sphinx_doc_src/cmds/disown.rst @@ -1,4 +1,6 @@ -\section disown disown - remove a process from the list of jobs +disown - remove a process from the list of jobs +========================================== + \subsection disown-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/echo.rst b/sphinx_doc_src/cmds/echo.rst index 69d6df4ef..e01e9a63c 100644 --- a/sphinx_doc_src/cmds/echo.rst +++ b/sphinx_doc_src/cmds/echo.rst @@ -1,4 +1,6 @@ -\section echo echo - display a line of text +echo - display a line of text +========================================== + \subsection echo-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/else.rst b/sphinx_doc_src/cmds/else.rst index 76e0c61f3..d622d5750 100644 --- a/sphinx_doc_src/cmds/else.rst +++ b/sphinx_doc_src/cmds/else.rst @@ -1,4 +1,6 @@ -\section else else - execute command if a condition is not met +else - execute command if a condition is not met +========================================== + \subsection else-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/emit.rst b/sphinx_doc_src/cmds/emit.rst index 78f8e2467..58bbde1fa 100644 --- a/sphinx_doc_src/cmds/emit.rst +++ b/sphinx_doc_src/cmds/emit.rst @@ -1,4 +1,6 @@ -\section emit emit - Emit a generic event +emit - Emit a generic event +========================================== + \subsection emit-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/end.rst b/sphinx_doc_src/cmds/end.rst index 2b035930c..24eba81a6 100644 --- a/sphinx_doc_src/cmds/end.rst +++ b/sphinx_doc_src/cmds/end.rst @@ -1,4 +1,6 @@ -\section end end - end a block of commands. +end - end a block of commands. +========================================== + \subsection end-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/eval.rst b/sphinx_doc_src/cmds/eval.rst index 5e7785077..a5dd592b1 100644 --- a/sphinx_doc_src/cmds/eval.rst +++ b/sphinx_doc_src/cmds/eval.rst @@ -1,4 +1,6 @@ -\section eval eval - evaluate the specified commands +eval - evaluate the specified commands +========================================== + \subsection eval-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/exec.rst b/sphinx_doc_src/cmds/exec.rst index f8936101a..9a2f228f6 100644 --- a/sphinx_doc_src/cmds/exec.rst +++ b/sphinx_doc_src/cmds/exec.rst @@ -1,4 +1,6 @@ -\section exec exec - execute command in current process +exec - execute command in current process +========================================== + \subsection exec-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/exit.rst b/sphinx_doc_src/cmds/exit.rst index b780c4317..7baead27c 100644 --- a/sphinx_doc_src/cmds/exit.rst +++ b/sphinx_doc_src/cmds/exit.rst @@ -1,4 +1,6 @@ -\section exit exit - exit the shell +exit - exit the shell +========================================== + \subsection exit-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/false.rst b/sphinx_doc_src/cmds/false.rst index 1ce5a4619..cdf9b60d9 100644 --- a/sphinx_doc_src/cmds/false.rst +++ b/sphinx_doc_src/cmds/false.rst @@ -1,4 +1,6 @@ -\section false false - return an unsuccessful result +false - return an unsuccessful result +========================================== + \subsection false-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fg.rst b/sphinx_doc_src/cmds/fg.rst index a27a0ad6b..518a2a5d8 100644 --- a/sphinx_doc_src/cmds/fg.rst +++ b/sphinx_doc_src/cmds/fg.rst @@ -1,4 +1,6 @@ -\section fg fg - bring job to foreground +fg - bring job to foreground +========================================== + \subsection fg-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fish.rst b/sphinx_doc_src/cmds/fish.rst index 5e22e526d..152c310ce 100644 --- a/sphinx_doc_src/cmds/fish.rst +++ b/sphinx_doc_src/cmds/fish.rst @@ -1,4 +1,6 @@ -\section fish fish - the friendly interactive shell +fish - the friendly interactive shell +========================================== + \subsection fish-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst index b56c7e0ac..4a6b45ce5 100644 --- a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst +++ b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst @@ -1,4 +1,6 @@ -\section fish_breakpoint_prompt fish_breakpoint_prompt - define the appearance of the command line prompt when in the context of a `breakpoint` command +fish_breakpoint_prompt - define the appearance of the command line prompt when in the context of a `breakpoint` command +========================================== + \subsection fish_breakpoint_prompt-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fish_config.rst b/sphinx_doc_src/cmds/fish_config.rst index 4fa242651..e4098ddbd 100644 --- a/sphinx_doc_src/cmds/fish_config.rst +++ b/sphinx_doc_src/cmds/fish_config.rst @@ -1,4 +1,6 @@ -\section fish_config fish_config - start the web-based configuration interface +fish_config - start the web-based configuration interface +========================================== + \subsection fish_config-description Description diff --git a/sphinx_doc_src/cmds/fish_indent.rst b/sphinx_doc_src/cmds/fish_indent.rst index 2cc429fb7..65eff46d8 100644 --- a/sphinx_doc_src/cmds/fish_indent.rst +++ b/sphinx_doc_src/cmds/fish_indent.rst @@ -1,4 +1,6 @@ -\section fish_indent fish_indent - indenter and prettifier +fish_indent - indenter and prettifier +========================================== + \subsection fish_indent-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fish_key_reader.rst b/sphinx_doc_src/cmds/fish_key_reader.rst index d1d5db2ab..bba1fe1d1 100644 --- a/sphinx_doc_src/cmds/fish_key_reader.rst +++ b/sphinx_doc_src/cmds/fish_key_reader.rst @@ -1,4 +1,6 @@ -\section fish_key_reader fish_key_reader - explore what characters keyboard keys send +fish_key_reader - explore what characters keyboard keys send +========================================== + \subsection fish_key_reader-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fish_mode_prompt.rst b/sphinx_doc_src/cmds/fish_mode_prompt.rst index c397d2c33..9c9f15a82 100644 --- a/sphinx_doc_src/cmds/fish_mode_prompt.rst +++ b/sphinx_doc_src/cmds/fish_mode_prompt.rst @@ -1,4 +1,6 @@ -\section fish_mode_prompt fish_mode_prompt - define the appearance of the mode indicator +fish_mode_prompt - define the appearance of the mode indicator +========================================== + \subsection fish_mode_prompt-synopsis Synopsis diff --git a/sphinx_doc_src/cmds/fish_opt.rst b/sphinx_doc_src/cmds/fish_opt.rst index 24967d24a..c6a81415d 100644 --- a/sphinx_doc_src/cmds/fish_opt.rst +++ b/sphinx_doc_src/cmds/fish_opt.rst @@ -1,4 +1,6 @@ -\section fish_opt fish_opt - create an option spec for the argparse command +fish_opt - create an option spec for the argparse command +========================================== + \subsection fish_opt-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fish_prompt.rst b/sphinx_doc_src/cmds/fish_prompt.rst index 1beb5304e..0ee3ba550 100644 --- a/sphinx_doc_src/cmds/fish_prompt.rst +++ b/sphinx_doc_src/cmds/fish_prompt.rst @@ -1,4 +1,6 @@ -\section fish_prompt fish_prompt - define the appearance of the command line prompt +fish_prompt - define the appearance of the command line prompt +========================================== + \subsection fish_prompt-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fish_right_prompt.rst b/sphinx_doc_src/cmds/fish_right_prompt.rst index 87de31139..a4fffa2af 100644 --- a/sphinx_doc_src/cmds/fish_right_prompt.rst +++ b/sphinx_doc_src/cmds/fish_right_prompt.rst @@ -1,4 +1,6 @@ -\section fish_right_prompt fish_right_prompt - define the appearance of the right-side command line prompt +fish_right_prompt - define the appearance of the right-side command line prompt +========================================== + \subsection fish_right_prompt-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/fish_update_completions.rst b/sphinx_doc_src/cmds/fish_update_completions.rst index 684dac0d8..12491c36d 100644 --- a/sphinx_doc_src/cmds/fish_update_completions.rst +++ b/sphinx_doc_src/cmds/fish_update_completions.rst @@ -1,4 +1,6 @@ -\section fish_update_completions fish_update_completions - Update completions using manual pages +fish_update_completions - Update completions using manual pages +========================================== + \subsection fish_update_completions-description Description diff --git a/sphinx_doc_src/cmds/fish_vi_mode.rst b/sphinx_doc_src/cmds/fish_vi_mode.rst index d39697c8f..bed5657f3 100644 --- a/sphinx_doc_src/cmds/fish_vi_mode.rst +++ b/sphinx_doc_src/cmds/fish_vi_mode.rst @@ -1,4 +1,6 @@ -\section fish_vi_mode fish_vi_mode - Enable vi mode +fish_vi_mode - Enable vi mode +========================================== + \subsection fish_vi_mode-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/for.rst b/sphinx_doc_src/cmds/for.rst index 508a3ac2d..4c30846cd 100644 --- a/sphinx_doc_src/cmds/for.rst +++ b/sphinx_doc_src/cmds/for.rst @@ -1,4 +1,6 @@ -\section for for - perform a set of commands multiple times. +for - perform a set of commands multiple times. +========================================== + \subsection for-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/funced.rst b/sphinx_doc_src/cmds/funced.rst index b8a7db530..38709da6f 100644 --- a/sphinx_doc_src/cmds/funced.rst +++ b/sphinx_doc_src/cmds/funced.rst @@ -1,4 +1,6 @@ -\section funced funced - edit a function interactively +funced - edit a function interactively +========================================== + \subsection funced-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/funcsave.rst b/sphinx_doc_src/cmds/funcsave.rst index 32b3f4f31..bd29e62f5 100644 --- a/sphinx_doc_src/cmds/funcsave.rst +++ b/sphinx_doc_src/cmds/funcsave.rst @@ -1,4 +1,6 @@ -\section funcsave funcsave - save the definition of a function to the user's autoload directory +funcsave - save the definition of a function to the user's autoload directory +========================================== + \subsection funcsave-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/function.rst b/sphinx_doc_src/cmds/function.rst index b6db339e9..e892361c7 100644 --- a/sphinx_doc_src/cmds/function.rst +++ b/sphinx_doc_src/cmds/function.rst @@ -1,4 +1,6 @@ -\section function function - create a function +function - create a function +========================================== + \subsection function-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/functions.rst b/sphinx_doc_src/cmds/functions.rst index 2b4b067e8..5321fb3f5 100644 --- a/sphinx_doc_src/cmds/functions.rst +++ b/sphinx_doc_src/cmds/functions.rst @@ -1,4 +1,6 @@ -\section functions functions - print or erase functions +functions - print or erase functions +========================================== + \subsection functions-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/help.rst b/sphinx_doc_src/cmds/help.rst index 9665dba27..a033ed883 100644 --- a/sphinx_doc_src/cmds/help.rst +++ b/sphinx_doc_src/cmds/help.rst @@ -1,4 +1,6 @@ -\section help help - display fish documentation +help - display fish documentation +========================================== + \subsection help-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/history.rst b/sphinx_doc_src/cmds/history.rst index 192bfd191..06a45b031 100644 --- a/sphinx_doc_src/cmds/history.rst +++ b/sphinx_doc_src/cmds/history.rst @@ -1,4 +1,6 @@ -\section history history - Show and manipulate command history +history - Show and manipulate command history +========================================== + \subsection history-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/if.rst b/sphinx_doc_src/cmds/if.rst index 61ba387c1..ded05f8c8 100644 --- a/sphinx_doc_src/cmds/if.rst +++ b/sphinx_doc_src/cmds/if.rst @@ -1,4 +1,6 @@ -\section if if - conditionally execute a command +if - conditionally execute a command +========================================== + \subsection if-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/isatty.rst b/sphinx_doc_src/cmds/isatty.rst index f6ab500e6..192197f63 100644 --- a/sphinx_doc_src/cmds/isatty.rst +++ b/sphinx_doc_src/cmds/isatty.rst @@ -1,4 +1,6 @@ -\section isatty isatty - test if a file descriptor is a tty. +isatty - test if a file descriptor is a tty. +========================================== + \subsection isatty-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/jobs.rst b/sphinx_doc_src/cmds/jobs.rst index df4fd9f10..ae930e1eb 100644 --- a/sphinx_doc_src/cmds/jobs.rst +++ b/sphinx_doc_src/cmds/jobs.rst @@ -1,4 +1,6 @@ -\section jobs jobs - print currently running jobs +jobs - print currently running jobs +========================================== + \subsection jobs-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/math.rst b/sphinx_doc_src/cmds/math.rst index 790933a93..09d239153 100644 --- a/sphinx_doc_src/cmds/math.rst +++ b/sphinx_doc_src/cmds/math.rst @@ -1,4 +1,6 @@ -\section math math - Perform mathematics calculations +math - Perform mathematics calculations +========================================== + \subsection math-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/nextd.rst b/sphinx_doc_src/cmds/nextd.rst index 61e01f1ef..4afb09687 100644 --- a/sphinx_doc_src/cmds/nextd.rst +++ b/sphinx_doc_src/cmds/nextd.rst @@ -1,4 +1,6 @@ -\section nextd nextd - move forward through directory history +nextd - move forward through directory history +========================================== + \subsection nextd-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/not.rst b/sphinx_doc_src/cmds/not.rst index 7848d2dc9..38a5eac83 100644 --- a/sphinx_doc_src/cmds/not.rst +++ b/sphinx_doc_src/cmds/not.rst @@ -1,4 +1,6 @@ -\section not not - negate the exit status of a job +not - negate the exit status of a job +========================================== + \subsection not-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/open.rst b/sphinx_doc_src/cmds/open.rst index 7207fc172..4c63394f4 100644 --- a/sphinx_doc_src/cmds/open.rst +++ b/sphinx_doc_src/cmds/open.rst @@ -1,4 +1,6 @@ -\section open open - open file in its default application +open - open file in its default application +========================================== + \subsection open-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/or.rst b/sphinx_doc_src/cmds/or.rst index b79e707d6..a7dd07967 100644 --- a/sphinx_doc_src/cmds/or.rst +++ b/sphinx_doc_src/cmds/or.rst @@ -1,4 +1,6 @@ -\section or or - conditionally execute a command +or - conditionally execute a command +========================================== + \subsection or-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/popd.rst b/sphinx_doc_src/cmds/popd.rst index 93dd4da37..f542a0acb 100644 --- a/sphinx_doc_src/cmds/popd.rst +++ b/sphinx_doc_src/cmds/popd.rst @@ -1,4 +1,6 @@ -\section popd popd - move through directory stack +popd - move through directory stack +========================================== + \subsection popd-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/prevd.rst b/sphinx_doc_src/cmds/prevd.rst index 191d95890..e94e87c36 100644 --- a/sphinx_doc_src/cmds/prevd.rst +++ b/sphinx_doc_src/cmds/prevd.rst @@ -1,4 +1,6 @@ -\section prevd prevd - move backward through directory history +prevd - move backward through directory history +========================================== + \subsection prevd-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/printf.rst b/sphinx_doc_src/cmds/printf.rst index 49fb0ad6a..e943c92f4 100644 --- a/sphinx_doc_src/cmds/printf.rst +++ b/sphinx_doc_src/cmds/printf.rst @@ -1,4 +1,6 @@ -\section printf printf - display text according to a format string +printf - display text according to a format string +========================================== + \subsection printf-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/prompt_pwd.rst b/sphinx_doc_src/cmds/prompt_pwd.rst index 0eafbf994..f8587af3f 100644 --- a/sphinx_doc_src/cmds/prompt_pwd.rst +++ b/sphinx_doc_src/cmds/prompt_pwd.rst @@ -1,4 +1,6 @@ -\section prompt_pwd prompt_pwd - Print pwd suitable for prompt +prompt_pwd - Print pwd suitable for prompt +========================================== + \subsection prompt_pwd-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/psub.rst b/sphinx_doc_src/cmds/psub.rst index d0c59e0ac..830f2f3ee 100644 --- a/sphinx_doc_src/cmds/psub.rst +++ b/sphinx_doc_src/cmds/psub.rst @@ -1,4 +1,6 @@ -\section psub psub - perform process substitution +psub - perform process substitution +========================================== + \subsection psub-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/pushd.rst b/sphinx_doc_src/cmds/pushd.rst index 43d62c6dd..a07606756 100644 --- a/sphinx_doc_src/cmds/pushd.rst +++ b/sphinx_doc_src/cmds/pushd.rst @@ -1,4 +1,6 @@ -\section pushd pushd - push directory to directory stack +pushd - push directory to directory stack +========================================== + \subsection pushd-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/pwd.rst b/sphinx_doc_src/cmds/pwd.rst index b3860498e..816f2f373 100644 --- a/sphinx_doc_src/cmds/pwd.rst +++ b/sphinx_doc_src/cmds/pwd.rst @@ -1,4 +1,6 @@ -\section pwd pwd - output the current working directory +pwd - output the current working directory +========================================== + \subsection pwd-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/random.rst b/sphinx_doc_src/cmds/random.rst index 28f140152..6f6cc25d5 100644 --- a/sphinx_doc_src/cmds/random.rst +++ b/sphinx_doc_src/cmds/random.rst @@ -1,4 +1,6 @@ -\section random random - generate random number +random - generate random number +========================================== + \subsection random-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/read.rst b/sphinx_doc_src/cmds/read.rst index c898cca59..9a848d28e 100644 --- a/sphinx_doc_src/cmds/read.rst +++ b/sphinx_doc_src/cmds/read.rst @@ -1,4 +1,6 @@ -\section read read - read line of input into variables +read - read line of input into variables +========================================== + \subsection read-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/realpath.rst b/sphinx_doc_src/cmds/realpath.rst index 35e6503a3..9f2bb9bcc 100644 --- a/sphinx_doc_src/cmds/realpath.rst +++ b/sphinx_doc_src/cmds/realpath.rst @@ -1,4 +1,6 @@ -\section realpath realpath - Convert a path to an absolute path without symlinks +realpath - Convert a path to an absolute path without symlinks +========================================== + \subsection realpath-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/return.rst b/sphinx_doc_src/cmds/return.rst index af4ca9aeb..328d397d2 100644 --- a/sphinx_doc_src/cmds/return.rst +++ b/sphinx_doc_src/cmds/return.rst @@ -1,4 +1,6 @@ -\section return return - stop the current inner function +return - stop the current inner function +========================================== + \subsection return-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/set.rst b/sphinx_doc_src/cmds/set.rst index fca3bf170..4a85f539a 100644 --- a/sphinx_doc_src/cmds/set.rst +++ b/sphinx_doc_src/cmds/set.rst @@ -1,4 +1,6 @@ -\section set set - display and change shell variables. +set - display and change shell variables. +========================================== + \subsection set-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/set_color.rst b/sphinx_doc_src/cmds/set_color.rst index 8af576458..a5aede87b 100644 --- a/sphinx_doc_src/cmds/set_color.rst +++ b/sphinx_doc_src/cmds/set_color.rst @@ -1,4 +1,6 @@ -\section set_color set_color - set the terminal color +set_color - set the terminal color +========================================== + \subsection set_color-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/source.rst b/sphinx_doc_src/cmds/source.rst index 7b32654ee..8fc4c8f86 100644 --- a/sphinx_doc_src/cmds/source.rst +++ b/sphinx_doc_src/cmds/source.rst @@ -1,4 +1,6 @@ -\section source source - evaluate contents of file. +source - evaluate contents of file. +========================================== + \subsection source-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/status.rst b/sphinx_doc_src/cmds/status.rst index b69996d57..b3c6de020 100644 --- a/sphinx_doc_src/cmds/status.rst +++ b/sphinx_doc_src/cmds/status.rst @@ -1,4 +1,6 @@ -\section status status - query fish runtime information +status - query fish runtime information +========================================== + \subsection status-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/string.rst b/sphinx_doc_src/cmds/string.rst index 52bca9445..a798de5c5 100644 --- a/sphinx_doc_src/cmds/string.rst +++ b/sphinx_doc_src/cmds/string.rst @@ -1,4 +1,6 @@ -\section string string - manipulate strings +string - manipulate strings +========================================== + \subsection string-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/suspend.rst b/sphinx_doc_src/cmds/suspend.rst index 0fc9485b6..f96e47f9b 100644 --- a/sphinx_doc_src/cmds/suspend.rst +++ b/sphinx_doc_src/cmds/suspend.rst @@ -1,4 +1,6 @@ -\section suspend suspend - suspend the current shell +suspend - suspend the current shell +========================================== + \subsection suspend-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/switch.rst b/sphinx_doc_src/cmds/switch.rst index 9bba2bb0d..7ecf7b60b 100644 --- a/sphinx_doc_src/cmds/switch.rst +++ b/sphinx_doc_src/cmds/switch.rst @@ -1,4 +1,6 @@ -\section switch switch - conditionally execute a block of commands +switch - conditionally execute a block of commands +========================================== + \subsection switch-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/test.rst b/sphinx_doc_src/cmds/test.rst index 1f54f1b00..4ea0f5caf 100644 --- a/sphinx_doc_src/cmds/test.rst +++ b/sphinx_doc_src/cmds/test.rst @@ -1,4 +1,6 @@ -\section test test - perform tests on files and text +test - perform tests on files and text +========================================== + \subsection test-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/trap.rst b/sphinx_doc_src/cmds/trap.rst index 3c8d8a963..7aabf5ed0 100644 --- a/sphinx_doc_src/cmds/trap.rst +++ b/sphinx_doc_src/cmds/trap.rst @@ -1,4 +1,6 @@ -\section trap trap - perform an action when the shell receives a signal +trap - perform an action when the shell receives a signal +========================================== + \subsection trap-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/true.rst b/sphinx_doc_src/cmds/true.rst index 1418c1ed4..00c06561f 100644 --- a/sphinx_doc_src/cmds/true.rst +++ b/sphinx_doc_src/cmds/true.rst @@ -1,4 +1,6 @@ -\section true true - return a successful result +true - return a successful result +========================================== + \subsection true-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/type.rst b/sphinx_doc_src/cmds/type.rst index 2d1a56abf..fa4096243 100644 --- a/sphinx_doc_src/cmds/type.rst +++ b/sphinx_doc_src/cmds/type.rst @@ -1,4 +1,6 @@ -\section type type - indicate how a command would be interpreted +type - indicate how a command would be interpreted +========================================== + \subsection type-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/ulimit.rst b/sphinx_doc_src/cmds/ulimit.rst index 86ffe2b6f..ca822cb6d 100644 --- a/sphinx_doc_src/cmds/ulimit.rst +++ b/sphinx_doc_src/cmds/ulimit.rst @@ -1,4 +1,6 @@ -\section ulimit ulimit - set or get resource usage limits +ulimit - set or get resource usage limits +========================================== + \subsection ulimit-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/umask.rst b/sphinx_doc_src/cmds/umask.rst index 7429d8a9e..23ff022a4 100644 --- a/sphinx_doc_src/cmds/umask.rst +++ b/sphinx_doc_src/cmds/umask.rst @@ -1,4 +1,6 @@ -\section umask umask - set or get the file creation mode mask +umask - set or get the file creation mode mask +========================================== + \subsection umask-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/vared.rst b/sphinx_doc_src/cmds/vared.rst index 352357872..2687c1bf6 100644 --- a/sphinx_doc_src/cmds/vared.rst +++ b/sphinx_doc_src/cmds/vared.rst @@ -1,4 +1,6 @@ -\section vared vared - interactively edit the value of an environment variable +vared - interactively edit the value of an environment variable +========================================== + \subsection vared-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/wait.rst b/sphinx_doc_src/cmds/wait.rst index 57aa27318..9d1565273 100644 --- a/sphinx_doc_src/cmds/wait.rst +++ b/sphinx_doc_src/cmds/wait.rst @@ -1,4 +1,6 @@ -\section wait wait - wait for jobs to complete +wait - wait for jobs to complete +========================================== + \subsection wait-synopsis Synopsis \fish{synopsis} diff --git a/sphinx_doc_src/cmds/while.rst b/sphinx_doc_src/cmds/while.rst index 38338792f..a1511a43f 100644 --- a/sphinx_doc_src/cmds/while.rst +++ b/sphinx_doc_src/cmds/while.rst @@ -1,4 +1,6 @@ -\section while while - perform a command multiple times +while - perform a command multiple times +========================================== + \subsection while-synopsis Synopsis \fish{synopsis} From 256c2dadee7d7e7ca7b3fbf8cd51427b06ccece5 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 17 Dec 2018 17:58:24 -0800 Subject: [PATCH 106/191] Migrate the 'synopsis' sections to .rst format --- sphinx_doc_src/cmds/abbr.rst | 5 ++--- sphinx_doc_src/cmds/alias.rst | 6 +++--- sphinx_doc_src/cmds/and.rst | 6 +++--- sphinx_doc_src/cmds/argparse.rst | 6 +++--- sphinx_doc_src/cmds/begin.rst | 6 +++--- sphinx_doc_src/cmds/bg.rst | 6 +++--- sphinx_doc_src/cmds/bind.rst | 6 +++--- sphinx_doc_src/cmds/block.rst | 6 +++--- sphinx_doc_src/cmds/break.rst | 6 +++--- sphinx_doc_src/cmds/breakpoint.rst | 6 +++--- sphinx_doc_src/cmds/builtin.rst | 6 +++--- sphinx_doc_src/cmds/case.rst | 6 +++--- sphinx_doc_src/cmds/cd.rst | 6 +++--- sphinx_doc_src/cmds/cdh.rst | 7 ++++--- sphinx_doc_src/cmds/command.rst | 6 +++--- sphinx_doc_src/cmds/commandline.rst | 6 +++--- sphinx_doc_src/cmds/complete.rst | 6 +++--- sphinx_doc_src/cmds/contains.rst | 6 +++--- sphinx_doc_src/cmds/continue.rst | 6 +++--- sphinx_doc_src/cmds/count.rst | 6 +++--- sphinx_doc_src/cmds/dirh.rst | 6 +++--- sphinx_doc_src/cmds/dirs.rst | 6 +++--- sphinx_doc_src/cmds/disown.rst | 6 +++--- sphinx_doc_src/cmds/echo.rst | 6 +++--- sphinx_doc_src/cmds/else.rst | 6 +++--- sphinx_doc_src/cmds/emit.rst | 6 +++--- sphinx_doc_src/cmds/end.rst | 6 +++--- sphinx_doc_src/cmds/eval.rst | 6 +++--- sphinx_doc_src/cmds/exec.rst | 6 +++--- sphinx_doc_src/cmds/exit.rst | 6 +++--- sphinx_doc_src/cmds/false.rst | 6 +++--- sphinx_doc_src/cmds/fg.rst | 6 +++--- sphinx_doc_src/cmds/fish.rst | 6 +++--- sphinx_doc_src/cmds/fish_breakpoint_prompt.rst | 6 +++--- sphinx_doc_src/cmds/fish_indent.rst | 6 +++--- sphinx_doc_src/cmds/fish_key_reader.rst | 6 +++--- sphinx_doc_src/cmds/fish_mode_prompt.rst | 1 - sphinx_doc_src/cmds/fish_opt.rst | 6 +++--- sphinx_doc_src/cmds/fish_prompt.rst | 6 +++--- sphinx_doc_src/cmds/fish_right_prompt.rst | 6 +++--- sphinx_doc_src/cmds/fish_vi_mode.rst | 6 +++--- sphinx_doc_src/cmds/for.rst | 6 +++--- sphinx_doc_src/cmds/funced.rst | 6 +++--- sphinx_doc_src/cmds/funcsave.rst | 6 +++--- sphinx_doc_src/cmds/function.rst | 6 +++--- sphinx_doc_src/cmds/functions.rst | 6 +++--- sphinx_doc_src/cmds/help.rst | 6 +++--- sphinx_doc_src/cmds/history.rst | 6 +++--- sphinx_doc_src/cmds/if.rst | 6 +++--- sphinx_doc_src/cmds/isatty.rst | 6 +++--- sphinx_doc_src/cmds/jobs.rst | 6 +++--- sphinx_doc_src/cmds/math.rst | 6 +++--- sphinx_doc_src/cmds/nextd.rst | 6 +++--- sphinx_doc_src/cmds/not.rst | 6 +++--- sphinx_doc_src/cmds/open.rst | 6 +++--- sphinx_doc_src/cmds/or.rst | 6 +++--- sphinx_doc_src/cmds/popd.rst | 6 +++--- sphinx_doc_src/cmds/prevd.rst | 6 +++--- sphinx_doc_src/cmds/printf.rst | 6 +++--- sphinx_doc_src/cmds/prompt_pwd.rst | 6 +++--- sphinx_doc_src/cmds/psub.rst | 6 +++--- sphinx_doc_src/cmds/pushd.rst | 6 +++--- sphinx_doc_src/cmds/pwd.rst | 6 +++--- sphinx_doc_src/cmds/random.rst | 6 +++--- sphinx_doc_src/cmds/read.rst | 6 +++--- sphinx_doc_src/cmds/realpath.rst | 6 +++--- sphinx_doc_src/cmds/return.rst | 6 +++--- sphinx_doc_src/cmds/set.rst | 6 +++--- sphinx_doc_src/cmds/set_color.rst | 6 +++--- sphinx_doc_src/cmds/source.rst | 6 +++--- sphinx_doc_src/cmds/status.rst | 6 +++--- sphinx_doc_src/cmds/string.rst | 6 +++--- sphinx_doc_src/cmds/suspend.rst | 6 +++--- sphinx_doc_src/cmds/switch.rst | 6 +++--- sphinx_doc_src/cmds/test.rst | 6 +++--- sphinx_doc_src/cmds/trap.rst | 6 +++--- sphinx_doc_src/cmds/true.rst | 6 +++--- sphinx_doc_src/cmds/type.rst | 6 +++--- sphinx_doc_src/cmds/ulimit.rst | 6 +++--- sphinx_doc_src/cmds/umask.rst | 6 +++--- sphinx_doc_src/cmds/vared.rst | 6 +++--- sphinx_doc_src/cmds/wait.rst | 6 +++--- sphinx_doc_src/cmds/while.rst | 6 +++--- 83 files changed, 246 insertions(+), 247 deletions(-) diff --git a/sphinx_doc_src/cmds/abbr.rst b/sphinx_doc_src/cmds/abbr.rst index da3d67f3a..5721cb6f1 100644 --- a/sphinx_doc_src/cmds/abbr.rst +++ b/sphinx_doc_src/cmds/abbr.rst @@ -1,15 +1,14 @@ abbr - manage fish abbreviations ========================================== +Synopsis +-------- -\subsection abbr-synopsis Synopsis -\fish{synopsis} abbr --add [SCOPE] WORD EXPANSION abbr --erase word abbr --rename [SCOPE] OLD_WORD NEW_WORD abbr --show abbr --list -\endfish \subsection abbr-description Description diff --git a/sphinx_doc_src/cmds/alias.rst b/sphinx_doc_src/cmds/alias.rst index e7c0ca543..0c5957cae 100644 --- a/sphinx_doc_src/cmds/alias.rst +++ b/sphinx_doc_src/cmds/alias.rst @@ -1,13 +1,13 @@ alias - create a function ========================================== +Synopsis +-------- -\subsection alias-synopsis Synopsis -\fish{synopsis} alias alias [OPTIONS] NAME DEFINITION alias [OPTIONS] NAME=DEFINITION -\endfish + \subsection alias-description Description diff --git a/sphinx_doc_src/cmds/and.rst b/sphinx_doc_src/cmds/and.rst index 7abca07dd..bf2088706 100644 --- a/sphinx_doc_src/cmds/and.rst +++ b/sphinx_doc_src/cmds/and.rst @@ -1,11 +1,11 @@ and - conditionally execute a command ========================================== +Synopsis +-------- -\subsection and-synopsis Synopsis -\fish{synopsis} COMMAND1; and COMMAND2 -\endfish + \subsection and-description Description diff --git a/sphinx_doc_src/cmds/argparse.rst b/sphinx_doc_src/cmds/argparse.rst index d54815d30..881d4df3b 100644 --- a/sphinx_doc_src/cmds/argparse.rst +++ b/sphinx_doc_src/cmds/argparse.rst @@ -1,11 +1,11 @@ argparse - parse options passed to a fish script or function ========================================== +Synopsis +-------- -\subsection argparse-synopsis Synopsis -\fish{synopsis} argparse [OPTIONS] OPTION_SPEC... -- [ARG...] -\endfish + \subsection argparse-description Description diff --git a/sphinx_doc_src/cmds/begin.rst b/sphinx_doc_src/cmds/begin.rst index cc63c36c4..8819a8a63 100644 --- a/sphinx_doc_src/cmds/begin.rst +++ b/sphinx_doc_src/cmds/begin.rst @@ -1,11 +1,11 @@ begin - start a new block of code ========================================== +Synopsis +-------- -\subsection begin-synopsis Synopsis -\fish{synopsis} begin; [COMMANDS...;] end -\endfish + \subsection begin-description Description diff --git a/sphinx_doc_src/cmds/bg.rst b/sphinx_doc_src/cmds/bg.rst index 10f40c89c..5e884c268 100644 --- a/sphinx_doc_src/cmds/bg.rst +++ b/sphinx_doc_src/cmds/bg.rst @@ -1,11 +1,11 @@ bg - send jobs to background ========================================== +Synopsis +-------- -\subsection bg-synopsis Synopsis -\fish{synopsis} bg [PID...] -\endfish + \subsection bg-description Description diff --git a/sphinx_doc_src/cmds/bind.rst b/sphinx_doc_src/cmds/bind.rst index db064b71a..86743a2fe 100644 --- a/sphinx_doc_src/cmds/bind.rst +++ b/sphinx_doc_src/cmds/bind.rst @@ -1,9 +1,9 @@ bind - handle fish key bindings ========================================== +Synopsis +-------- -\subsection bind-synopsis Synopsis -\fish{synopsis} bind [(-M | --mode) MODE] [(-m | --sets-mode) NEW_MODE] [--preset | --user] [(-s | --silent)] [(-k | --key)] SEQUENCE COMMAND [COMMAND...] @@ -14,7 +14,7 @@ bind (-L | --list-modes) bind (-e | --erase) [(-M | --mode) MODE] [--preset] [--user] (-a | --all | [(-k | --key)] SEQUENCE [SEQUENCE...]) -\endfish + \subsection bind-description Description diff --git a/sphinx_doc_src/cmds/block.rst b/sphinx_doc_src/cmds/block.rst index 5fe5dd3c9..24566083f 100644 --- a/sphinx_doc_src/cmds/block.rst +++ b/sphinx_doc_src/cmds/block.rst @@ -1,11 +1,11 @@ block - temporarily block delivery of events ========================================== +Synopsis +-------- -\subsection block-synopsis Synopsis -\fish{synopsis} block [OPTIONS...] -\endfish + \subsection block-description Description diff --git a/sphinx_doc_src/cmds/break.rst b/sphinx_doc_src/cmds/break.rst index 0b609955c..b20305e58 100644 --- a/sphinx_doc_src/cmds/break.rst +++ b/sphinx_doc_src/cmds/break.rst @@ -1,11 +1,11 @@ break - stop the current inner loop ========================================== +Synopsis +-------- -\subsection break-synopsis Synopsis -\fish{synopsis} LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] end -\endfish + \subsection break-description Description diff --git a/sphinx_doc_src/cmds/breakpoint.rst b/sphinx_doc_src/cmds/breakpoint.rst index f0efffd85..4aa2852cc 100644 --- a/sphinx_doc_src/cmds/breakpoint.rst +++ b/sphinx_doc_src/cmds/breakpoint.rst @@ -1,11 +1,11 @@ breakpoint - Launch debug mode ========================================== +Synopsis +-------- -\subsection breakpoint-synopsis Synopsis -\fish{synopsis} breakpoint -\endfish + \subsection breakpoint-description Description diff --git a/sphinx_doc_src/cmds/builtin.rst b/sphinx_doc_src/cmds/builtin.rst index 90c512cec..6df15691d 100644 --- a/sphinx_doc_src/cmds/builtin.rst +++ b/sphinx_doc_src/cmds/builtin.rst @@ -1,11 +1,11 @@ builtin - run a builtin command ========================================== +Synopsis +-------- -\subsection builtin-synopsis Synopsis -\fish{synopsis} builtin BUILTINNAME [OPTIONS...] -\endfish + \subsection builtin-description Description diff --git a/sphinx_doc_src/cmds/case.rst b/sphinx_doc_src/cmds/case.rst index 8cfee4a76..2f06fb0a7 100644 --- a/sphinx_doc_src/cmds/case.rst +++ b/sphinx_doc_src/cmds/case.rst @@ -1,11 +1,11 @@ case - conditionally execute a block of commands ========================================== +Synopsis +-------- -\subsection case-synopsis Synopsis -\fish{synopsis} switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end -\endfish + \subsection case-description Description diff --git a/sphinx_doc_src/cmds/cd.rst b/sphinx_doc_src/cmds/cd.rst index 786f3c68b..2e0590759 100644 --- a/sphinx_doc_src/cmds/cd.rst +++ b/sphinx_doc_src/cmds/cd.rst @@ -1,11 +1,11 @@ cd - change directory ========================================== +Synopsis +-------- -\subsection cd-synopsis Synopsis -\fish{synopsis} cd [DIRECTORY] -\endfish + \subsection cd-description Description `cd` changes the current working directory. diff --git a/sphinx_doc_src/cmds/cdh.rst b/sphinx_doc_src/cmds/cdh.rst index 295ab4ea3..b122bd362 100644 --- a/sphinx_doc_src/cmds/cdh.rst +++ b/sphinx_doc_src/cmds/cdh.rst @@ -2,10 +2,11 @@ cdh - change to a recently visited directory ========================================== -\subsection cdh-synopsis Synopsis -\fish{synopsis} +Synopsis +-------- + cdh [ directory ] -\endfish + \subsection cdh-description Description diff --git a/sphinx_doc_src/cmds/command.rst b/sphinx_doc_src/cmds/command.rst index 0eafa8223..3e832d57c 100644 --- a/sphinx_doc_src/cmds/command.rst +++ b/sphinx_doc_src/cmds/command.rst @@ -1,11 +1,11 @@ command - run a program ========================================== +Synopsis +-------- -\subsection command-synopsis Synopsis -\fish{synopsis} command [OPTIONS] COMMANDNAME [ARGS...] -\endfish + \subsection command-description Description diff --git a/sphinx_doc_src/cmds/commandline.rst b/sphinx_doc_src/cmds/commandline.rst index ea2dad4f9..1241d3df7 100644 --- a/sphinx_doc_src/cmds/commandline.rst +++ b/sphinx_doc_src/cmds/commandline.rst @@ -1,11 +1,11 @@ commandline - set or get the current command line buffer ========================================== +Synopsis +-------- -\subsection commandline-synopsis Synopsis -\fish{synopsis} commandline [OPTIONS] [CMD] -\endfish + \subsection commandline-description Description diff --git a/sphinx_doc_src/cmds/complete.rst b/sphinx_doc_src/cmds/complete.rst index 1e9d42316..3691f7095 100644 --- a/sphinx_doc_src/cmds/complete.rst +++ b/sphinx_doc_src/cmds/complete.rst @@ -1,9 +1,9 @@ complete - edit command specific tab-completions ========================================== +Synopsis +-------- -\subsection complete-synopsis Synopsis -\fish{synopsis} complete ( -c | --command | -p | --path ) COMMAND [( -c | --command | -p | --path ) COMMAND]... [( -e | --erase )] @@ -18,7 +18,7 @@ complete ( -c | --command | -p | --path ) COMMAND [( -n | --condition ) CONDITION] [( -d | --description ) DESCRIPTION] complete ( -C[STRING] | --do-complete[=STRING] ) -\endfish + \subsection complete-description Description diff --git a/sphinx_doc_src/cmds/contains.rst b/sphinx_doc_src/cmds/contains.rst index cc3d8b1c3..8f69ba214 100644 --- a/sphinx_doc_src/cmds/contains.rst +++ b/sphinx_doc_src/cmds/contains.rst @@ -1,11 +1,11 @@ contains - test if a word is present in a list ========================================== +Synopsis +-------- -\subsection contains-synopsis Synopsis -\fish{synopsis} contains [OPTIONS] KEY [VALUES...] -\endfish + \subsection contains-description Description diff --git a/sphinx_doc_src/cmds/continue.rst b/sphinx_doc_src/cmds/continue.rst index 11c34bd10..1d7b7fd03 100644 --- a/sphinx_doc_src/cmds/continue.rst +++ b/sphinx_doc_src/cmds/continue.rst @@ -1,11 +1,11 @@ continue - skip the remainder of the current iteration of the current inner loop ========================================== +Synopsis +-------- -\subsection continue-synopsis Synopsis -\fish{synopsis} LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end -\endfish + \subsection continue-description Description diff --git a/sphinx_doc_src/cmds/count.rst b/sphinx_doc_src/cmds/count.rst index 0b5659644..c84e7fe42 100644 --- a/sphinx_doc_src/cmds/count.rst +++ b/sphinx_doc_src/cmds/count.rst @@ -1,11 +1,11 @@ count - count the number of elements of an array ========================================== +Synopsis +-------- -\subsection count-synopsis Synopsis -\fish{synopsis} count $VARIABLE -\endfish + \subsection count-description Description diff --git a/sphinx_doc_src/cmds/dirh.rst b/sphinx_doc_src/cmds/dirh.rst index bf94537ba..451d44c17 100644 --- a/sphinx_doc_src/cmds/dirh.rst +++ b/sphinx_doc_src/cmds/dirh.rst @@ -1,11 +1,11 @@ dirh - print directory history ========================================== +Synopsis +-------- -\subsection dirh-synopsis Synopsis -\fish{synopsis} dirh -\endfish + \subsection dirh-description Description diff --git a/sphinx_doc_src/cmds/dirs.rst b/sphinx_doc_src/cmds/dirs.rst index 576d7de63..cd07b0f7a 100644 --- a/sphinx_doc_src/cmds/dirs.rst +++ b/sphinx_doc_src/cmds/dirs.rst @@ -1,12 +1,12 @@ dirs - print directory stack ========================================== +Synopsis +-------- -\subsection dirs-synopsis Synopsis -\fish{synopsis} dirs dirs -c -\endfish + \subsection dirs-description Description diff --git a/sphinx_doc_src/cmds/disown.rst b/sphinx_doc_src/cmds/disown.rst index 5047db5e5..c61ca0c03 100644 --- a/sphinx_doc_src/cmds/disown.rst +++ b/sphinx_doc_src/cmds/disown.rst @@ -1,11 +1,11 @@ disown - remove a process from the list of jobs ========================================== +Synopsis +-------- -\subsection disown-synopsis Synopsis -\fish{synopsis} disown [ PID ... ] -\endfish + \subsection disown-description Description diff --git a/sphinx_doc_src/cmds/echo.rst b/sphinx_doc_src/cmds/echo.rst index e01e9a63c..b38dbcbcf 100644 --- a/sphinx_doc_src/cmds/echo.rst +++ b/sphinx_doc_src/cmds/echo.rst @@ -1,11 +1,11 @@ echo - display a line of text ========================================== +Synopsis +-------- -\subsection echo-synopsis Synopsis -\fish{synopsis} echo [OPTIONS] [STRING] -\endfish + \subsection echo-description Description diff --git a/sphinx_doc_src/cmds/else.rst b/sphinx_doc_src/cmds/else.rst index d622d5750..42a4ac8c8 100644 --- a/sphinx_doc_src/cmds/else.rst +++ b/sphinx_doc_src/cmds/else.rst @@ -1,11 +1,11 @@ else - execute command if a condition is not met ========================================== +Synopsis +-------- -\subsection else-synopsis Synopsis -\fish{synopsis} if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end -\endfish + \subsection else-description Description diff --git a/sphinx_doc_src/cmds/emit.rst b/sphinx_doc_src/cmds/emit.rst index 58bbde1fa..e66f3c7da 100644 --- a/sphinx_doc_src/cmds/emit.rst +++ b/sphinx_doc_src/cmds/emit.rst @@ -1,11 +1,11 @@ emit - Emit a generic event ========================================== +Synopsis +-------- -\subsection emit-synopsis Synopsis -\fish{synopsis} emit EVENT_NAME [ARGUMENTS...] -\endfish + \subsection emit-description Description diff --git a/sphinx_doc_src/cmds/end.rst b/sphinx_doc_src/cmds/end.rst index 24eba81a6..7ee68ef15 100644 --- a/sphinx_doc_src/cmds/end.rst +++ b/sphinx_doc_src/cmds/end.rst @@ -1,15 +1,15 @@ end - end a block of commands. ========================================== +Synopsis +-------- -\subsection end-synopsis Synopsis -\fish{synopsis} begin; [COMMANDS...] end if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end while CONDITION; COMMANDS...; end for VARNAME in [VALUES...]; COMMANDS...; end switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end -\endfish + \subsection end-description Description diff --git a/sphinx_doc_src/cmds/eval.rst b/sphinx_doc_src/cmds/eval.rst index a5dd592b1..5e1d09aaf 100644 --- a/sphinx_doc_src/cmds/eval.rst +++ b/sphinx_doc_src/cmds/eval.rst @@ -1,11 +1,11 @@ eval - evaluate the specified commands ========================================== +Synopsis +-------- -\subsection eval-synopsis Synopsis -\fish{synopsis} eval [COMMANDS...] -\endfish + \subsection eval-description Description `eval` evaluates the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator. diff --git a/sphinx_doc_src/cmds/exec.rst b/sphinx_doc_src/cmds/exec.rst index 9a2f228f6..7e0509397 100644 --- a/sphinx_doc_src/cmds/exec.rst +++ b/sphinx_doc_src/cmds/exec.rst @@ -1,11 +1,11 @@ exec - execute command in current process ========================================== +Synopsis +-------- -\subsection exec-synopsis Synopsis -\fish{synopsis} exec COMMAND [OPTIONS...] -\endfish + \subsection exec-description Description diff --git a/sphinx_doc_src/cmds/exit.rst b/sphinx_doc_src/cmds/exit.rst index 7baead27c..54467c09c 100644 --- a/sphinx_doc_src/cmds/exit.rst +++ b/sphinx_doc_src/cmds/exit.rst @@ -1,11 +1,11 @@ exit - exit the shell ========================================== +Synopsis +-------- -\subsection exit-synopsis Synopsis -\fish{synopsis} exit [STATUS] -\endfish + \subsection exit-description Description diff --git a/sphinx_doc_src/cmds/false.rst b/sphinx_doc_src/cmds/false.rst index cdf9b60d9..7e64aa757 100644 --- a/sphinx_doc_src/cmds/false.rst +++ b/sphinx_doc_src/cmds/false.rst @@ -1,11 +1,11 @@ false - return an unsuccessful result ========================================== +Synopsis +-------- -\subsection false-synopsis Synopsis -\fish{synopsis} false -\endfish + \subsection false-description Description diff --git a/sphinx_doc_src/cmds/fg.rst b/sphinx_doc_src/cmds/fg.rst index 518a2a5d8..df0263687 100644 --- a/sphinx_doc_src/cmds/fg.rst +++ b/sphinx_doc_src/cmds/fg.rst @@ -1,11 +1,11 @@ fg - bring job to foreground ========================================== +Synopsis +-------- -\subsection fg-synopsis Synopsis -\fish{synopsis} fg [PID] -\endfish + \subsection fg-description Description diff --git a/sphinx_doc_src/cmds/fish.rst b/sphinx_doc_src/cmds/fish.rst index 152c310ce..83183eaa8 100644 --- a/sphinx_doc_src/cmds/fish.rst +++ b/sphinx_doc_src/cmds/fish.rst @@ -1,11 +1,11 @@ fish - the friendly interactive shell ========================================== +Synopsis +-------- -\subsection fish-synopsis Synopsis -\fish{synopsis} fish [OPTIONS] [-c command] [FILE [ARGUMENTS...]] -\endfish + \subsection fish-description Description diff --git a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst index 4a6b45ce5..2bef17f7c 100644 --- a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst +++ b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst @@ -1,13 +1,13 @@ fish_breakpoint_prompt - define the appearance of the command line prompt when in the context of a `breakpoint` command ========================================== +Synopsis +-------- -\subsection fish_breakpoint_prompt-synopsis Synopsis -\fish{synopsis} function fish_breakpoint_prompt ... end -\endfish + \subsection fish_breakpoint_prompt-description Description diff --git a/sphinx_doc_src/cmds/fish_indent.rst b/sphinx_doc_src/cmds/fish_indent.rst index 65eff46d8..7ee66eaaf 100644 --- a/sphinx_doc_src/cmds/fish_indent.rst +++ b/sphinx_doc_src/cmds/fish_indent.rst @@ -1,11 +1,11 @@ fish_indent - indenter and prettifier ========================================== +Synopsis +-------- -\subsection fish_indent-synopsis Synopsis -\fish{synopsis} fish_indent [OPTIONS] -\endfish + \subsection fish_indent-description Description diff --git a/sphinx_doc_src/cmds/fish_key_reader.rst b/sphinx_doc_src/cmds/fish_key_reader.rst index bba1fe1d1..818c4a59e 100644 --- a/sphinx_doc_src/cmds/fish_key_reader.rst +++ b/sphinx_doc_src/cmds/fish_key_reader.rst @@ -1,11 +1,11 @@ fish_key_reader - explore what characters keyboard keys send ========================================== +Synopsis +-------- -\subsection fish_key_reader-synopsis Synopsis -\fish{synopsis} fish_key_reader [OPTIONS] -\endfish + \subsection fish_key_reader-description Description diff --git a/sphinx_doc_src/cmds/fish_mode_prompt.rst b/sphinx_doc_src/cmds/fish_mode_prompt.rst index 9c9f15a82..2e7d7a4f7 100644 --- a/sphinx_doc_src/cmds/fish_mode_prompt.rst +++ b/sphinx_doc_src/cmds/fish_mode_prompt.rst @@ -2,7 +2,6 @@ fish_mode_prompt - define the appearance of the mode indicator ========================================== -\subsection fish_mode_prompt-synopsis Synopsis The fish_mode_prompt function will output the mode indicator for use in vi-mode. diff --git a/sphinx_doc_src/cmds/fish_opt.rst b/sphinx_doc_src/cmds/fish_opt.rst index c6a81415d..a76a42be2 100644 --- a/sphinx_doc_src/cmds/fish_opt.rst +++ b/sphinx_doc_src/cmds/fish_opt.rst @@ -1,13 +1,13 @@ fish_opt - create an option spec for the argparse command ========================================== +Synopsis +-------- -\subsection fish_opt-synopsis Synopsis -\fish{synopsis} fish_opt [ -h | --help ] fish_opt ( -s X | --short=X ) [ -l LONG | --long=LONG ] [ --long-only ] \ [ -o | --optional-val ] [ -r | --required-val ] [ --multiple-vals ] -\endfish + \subsection fish_opt-description Description diff --git a/sphinx_doc_src/cmds/fish_prompt.rst b/sphinx_doc_src/cmds/fish_prompt.rst index 0ee3ba550..6a8c7afde 100644 --- a/sphinx_doc_src/cmds/fish_prompt.rst +++ b/sphinx_doc_src/cmds/fish_prompt.rst @@ -1,13 +1,13 @@ fish_prompt - define the appearance of the command line prompt ========================================== +Synopsis +-------- -\subsection fish_prompt-synopsis Synopsis -\fish{synopsis} function fish_prompt ... end -\endfish + \subsection fish_prompt-description Description diff --git a/sphinx_doc_src/cmds/fish_right_prompt.rst b/sphinx_doc_src/cmds/fish_right_prompt.rst index a4fffa2af..0950691e1 100644 --- a/sphinx_doc_src/cmds/fish_right_prompt.rst +++ b/sphinx_doc_src/cmds/fish_right_prompt.rst @@ -1,13 +1,13 @@ fish_right_prompt - define the appearance of the right-side command line prompt ========================================== +Synopsis +-------- -\subsection fish_right_prompt-synopsis Synopsis -\fish{synopsis} function fish_right_prompt ... end -\endfish + \subsection fish_right_prompt-description Description diff --git a/sphinx_doc_src/cmds/fish_vi_mode.rst b/sphinx_doc_src/cmds/fish_vi_mode.rst index bed5657f3..40e288190 100644 --- a/sphinx_doc_src/cmds/fish_vi_mode.rst +++ b/sphinx_doc_src/cmds/fish_vi_mode.rst @@ -1,11 +1,11 @@ fish_vi_mode - Enable vi mode ========================================== +Synopsis +-------- -\subsection fish_vi_mode-synopsis Synopsis -\fish{synopsis} fish_vi_mode -\endfish + \subsection fish_vi_mode-description Description diff --git a/sphinx_doc_src/cmds/for.rst b/sphinx_doc_src/cmds/for.rst index 4c30846cd..1b7b20ff7 100644 --- a/sphinx_doc_src/cmds/for.rst +++ b/sphinx_doc_src/cmds/for.rst @@ -1,11 +1,11 @@ for - perform a set of commands multiple times. ========================================== +Synopsis +-------- -\subsection for-synopsis Synopsis -\fish{synopsis} for VARNAME in [VALUES...]; COMMANDS...; end -\endfish + \subsection for-description Description diff --git a/sphinx_doc_src/cmds/funced.rst b/sphinx_doc_src/cmds/funced.rst index 38709da6f..e53f4dadc 100644 --- a/sphinx_doc_src/cmds/funced.rst +++ b/sphinx_doc_src/cmds/funced.rst @@ -1,11 +1,11 @@ funced - edit a function interactively ========================================== +Synopsis +-------- -\subsection funced-synopsis Synopsis -\fish{synopsis} funced [OPTIONS] NAME -\endfish + \subsection funced-description Description diff --git a/sphinx_doc_src/cmds/funcsave.rst b/sphinx_doc_src/cmds/funcsave.rst index bd29e62f5..9a5d1405f 100644 --- a/sphinx_doc_src/cmds/funcsave.rst +++ b/sphinx_doc_src/cmds/funcsave.rst @@ -1,11 +1,11 @@ funcsave - save the definition of a function to the user's autoload directory ========================================== +Synopsis +-------- -\subsection funcsave-synopsis Synopsis -\fish{synopsis} funcsave FUNCTION_NAME -\endfish + \subsection funcsave-description Description diff --git a/sphinx_doc_src/cmds/function.rst b/sphinx_doc_src/cmds/function.rst index e892361c7..26defcc29 100644 --- a/sphinx_doc_src/cmds/function.rst +++ b/sphinx_doc_src/cmds/function.rst @@ -1,11 +1,11 @@ function - create a function ========================================== +Synopsis +-------- -\subsection function-synopsis Synopsis -\fish{synopsis} function NAME [OPTIONS]; BODY; end -\endfish + \subsection function-description Description diff --git a/sphinx_doc_src/cmds/functions.rst b/sphinx_doc_src/cmds/functions.rst index 5321fb3f5..3e52cb90f 100644 --- a/sphinx_doc_src/cmds/functions.rst +++ b/sphinx_doc_src/cmds/functions.rst @@ -1,15 +1,15 @@ functions - print or erase functions ========================================== +Synopsis +-------- -\subsection functions-synopsis Synopsis -\fish{synopsis} functions [ -a | --all ] [ -n | --names ] functions [ -D | --details ] [ -v ] FUNCTION functions -c OLDNAME NEWNAME functions -d DESCRIPTION FUNCTION functions [ -e | -q ] FUNCTIONS... -\endfish + \subsection functions-description Description diff --git a/sphinx_doc_src/cmds/help.rst b/sphinx_doc_src/cmds/help.rst index a033ed883..98ea11693 100644 --- a/sphinx_doc_src/cmds/help.rst +++ b/sphinx_doc_src/cmds/help.rst @@ -1,11 +1,11 @@ help - display fish documentation ========================================== +Synopsis +-------- -\subsection help-synopsis Synopsis -\fish{synopsis} help [SECTION] -\endfish + \subsection help-description Description diff --git a/sphinx_doc_src/cmds/history.rst b/sphinx_doc_src/cmds/history.rst index 06a45b031..739039393 100644 --- a/sphinx_doc_src/cmds/history.rst +++ b/sphinx_doc_src/cmds/history.rst @@ -1,16 +1,16 @@ history - Show and manipulate command history ========================================== +Synopsis +-------- -\subsection history-synopsis Synopsis -\fish{synopsis} history search [ --show-time ] [ --case-sensitive ] [ --exact | --prefix | --contains ] [ --max=n ] [ --null ] [ -R | --reverse ] [ "search string"... ] history delete [ --show-time ] [ --case-sensitive ] [ --exact | --prefix | --contains ] "search string"... history merge history save history clear history ( -h | --help ) -\endfish + \subsection history-description Description diff --git a/sphinx_doc_src/cmds/if.rst b/sphinx_doc_src/cmds/if.rst index ded05f8c8..d684e53f4 100644 --- a/sphinx_doc_src/cmds/if.rst +++ b/sphinx_doc_src/cmds/if.rst @@ -1,14 +1,14 @@ if - conditionally execute a command ========================================== +Synopsis +-------- -\subsection if-synopsis Synopsis -\fish{synopsis} if CONDITION; COMMANDS_TRUE...; [else if CONDITION2; COMMANDS_TRUE2...;] [else; COMMANDS_FALSE...;] end -\endfish + \subsection if-description Description diff --git a/sphinx_doc_src/cmds/isatty.rst b/sphinx_doc_src/cmds/isatty.rst index 192197f63..bf73f06c1 100644 --- a/sphinx_doc_src/cmds/isatty.rst +++ b/sphinx_doc_src/cmds/isatty.rst @@ -1,11 +1,11 @@ isatty - test if a file descriptor is a tty. ========================================== +Synopsis +-------- -\subsection isatty-synopsis Synopsis -\fish{synopsis} isatty [FILE DESCRIPTOR] -\endfish + \subsection isatty-description Description diff --git a/sphinx_doc_src/cmds/jobs.rst b/sphinx_doc_src/cmds/jobs.rst index ae930e1eb..2d17d9f92 100644 --- a/sphinx_doc_src/cmds/jobs.rst +++ b/sphinx_doc_src/cmds/jobs.rst @@ -1,11 +1,11 @@ jobs - print currently running jobs ========================================== +Synopsis +-------- -\subsection jobs-synopsis Synopsis -\fish{synopsis} jobs [OPTIONS] [PID] -\endfish + \subsection jobs-description Description diff --git a/sphinx_doc_src/cmds/math.rst b/sphinx_doc_src/cmds/math.rst index 09d239153..b263746ae 100644 --- a/sphinx_doc_src/cmds/math.rst +++ b/sphinx_doc_src/cmds/math.rst @@ -1,11 +1,11 @@ math - Perform mathematics calculations ========================================== +Synopsis +-------- -\subsection math-synopsis Synopsis -\fish{synopsis} math [-sN | --scale=N] [--] EXPRESSION -\endfish + \subsection math-description Description diff --git a/sphinx_doc_src/cmds/nextd.rst b/sphinx_doc_src/cmds/nextd.rst index 4afb09687..8ce5ce915 100644 --- a/sphinx_doc_src/cmds/nextd.rst +++ b/sphinx_doc_src/cmds/nextd.rst @@ -1,11 +1,11 @@ nextd - move forward through directory history ========================================== +Synopsis +-------- -\subsection nextd-synopsis Synopsis -\fish{synopsis} nextd [ -l | --list ] [POS] -\endfish + \subsection nextd-description Description diff --git a/sphinx_doc_src/cmds/not.rst b/sphinx_doc_src/cmds/not.rst index 38a5eac83..7c572a251 100644 --- a/sphinx_doc_src/cmds/not.rst +++ b/sphinx_doc_src/cmds/not.rst @@ -1,11 +1,11 @@ not - negate the exit status of a job ========================================== +Synopsis +-------- -\subsection not-synopsis Synopsis -\fish{synopsis} not COMMAND [OPTIONS...] -\endfish + \subsection not-description Description diff --git a/sphinx_doc_src/cmds/open.rst b/sphinx_doc_src/cmds/open.rst index 4c63394f4..891d0589e 100644 --- a/sphinx_doc_src/cmds/open.rst +++ b/sphinx_doc_src/cmds/open.rst @@ -1,11 +1,11 @@ open - open file in its default application ========================================== +Synopsis +-------- -\subsection open-synopsis Synopsis -\fish{synopsis} open FILES... -\endfish + \subsection open-description Description diff --git a/sphinx_doc_src/cmds/or.rst b/sphinx_doc_src/cmds/or.rst index a7dd07967..1d507668c 100644 --- a/sphinx_doc_src/cmds/or.rst +++ b/sphinx_doc_src/cmds/or.rst @@ -1,11 +1,11 @@ or - conditionally execute a command ========================================== +Synopsis +-------- -\subsection or-synopsis Synopsis -\fish{synopsis} COMMAND1; or COMMAND2 -\endfish + \subsection or-description Description diff --git a/sphinx_doc_src/cmds/popd.rst b/sphinx_doc_src/cmds/popd.rst index f542a0acb..bd3ab1be6 100644 --- a/sphinx_doc_src/cmds/popd.rst +++ b/sphinx_doc_src/cmds/popd.rst @@ -1,11 +1,11 @@ popd - move through directory stack ========================================== +Synopsis +-------- -\subsection popd-synopsis Synopsis -\fish{synopsis} popd -\endfish + \subsection popd-description Description diff --git a/sphinx_doc_src/cmds/prevd.rst b/sphinx_doc_src/cmds/prevd.rst index e94e87c36..224f994ab 100644 --- a/sphinx_doc_src/cmds/prevd.rst +++ b/sphinx_doc_src/cmds/prevd.rst @@ -1,11 +1,11 @@ prevd - move backward through directory history ========================================== +Synopsis +-------- -\subsection prevd-synopsis Synopsis -\fish{synopsis} prevd [ -l | --list ] [POS] -\endfish + \subsection prevd-description Description diff --git a/sphinx_doc_src/cmds/printf.rst b/sphinx_doc_src/cmds/printf.rst index e943c92f4..ab8aaa95d 100644 --- a/sphinx_doc_src/cmds/printf.rst +++ b/sphinx_doc_src/cmds/printf.rst @@ -1,11 +1,11 @@ printf - display text according to a format string ========================================== +Synopsis +-------- -\subsection printf-synopsis Synopsis -\fish{synopsis} printf format [argument...] -\endfish + \subsection printf-description Description printf formats the string FORMAT with ARGUMENT, and displays the result. diff --git a/sphinx_doc_src/cmds/prompt_pwd.rst b/sphinx_doc_src/cmds/prompt_pwd.rst index f8587af3f..951daa7e5 100644 --- a/sphinx_doc_src/cmds/prompt_pwd.rst +++ b/sphinx_doc_src/cmds/prompt_pwd.rst @@ -1,11 +1,11 @@ prompt_pwd - Print pwd suitable for prompt ========================================== +Synopsis +-------- -\subsection prompt_pwd-synopsis Synopsis -\fish{synopsis} prompt_pwd -\endfish + \subsection prompt_pwd-description Description diff --git a/sphinx_doc_src/cmds/psub.rst b/sphinx_doc_src/cmds/psub.rst index 830f2f3ee..75060590f 100644 --- a/sphinx_doc_src/cmds/psub.rst +++ b/sphinx_doc_src/cmds/psub.rst @@ -1,11 +1,11 @@ psub - perform process substitution ========================================== +Synopsis +-------- -\subsection psub-synopsis Synopsis -\fish{synopsis} COMMAND1 ( COMMAND2 | psub [-F | --fifo] [-f | --file] [-s SUFFIX]) -\endfish + \subsection psub-description Description diff --git a/sphinx_doc_src/cmds/pushd.rst b/sphinx_doc_src/cmds/pushd.rst index a07606756..3d4a5a694 100644 --- a/sphinx_doc_src/cmds/pushd.rst +++ b/sphinx_doc_src/cmds/pushd.rst @@ -1,11 +1,11 @@ pushd - push directory to directory stack ========================================== +Synopsis +-------- -\subsection pushd-synopsis Synopsis -\fish{synopsis} pushd [DIRECTORY] -\endfish + \subsection pushd-description Description diff --git a/sphinx_doc_src/cmds/pwd.rst b/sphinx_doc_src/cmds/pwd.rst index 816f2f373..da99d575b 100644 --- a/sphinx_doc_src/cmds/pwd.rst +++ b/sphinx_doc_src/cmds/pwd.rst @@ -1,11 +1,11 @@ pwd - output the current working directory ========================================== +Synopsis +-------- -\subsection pwd-synopsis Synopsis -\fish{synopsis} pwd -\endfish + \subsection pwd-description Description diff --git a/sphinx_doc_src/cmds/random.rst b/sphinx_doc_src/cmds/random.rst index 6f6cc25d5..18df8b676 100644 --- a/sphinx_doc_src/cmds/random.rst +++ b/sphinx_doc_src/cmds/random.rst @@ -1,15 +1,15 @@ random - generate random number ========================================== +Synopsis +-------- -\subsection random-synopsis Synopsis -\fish{synopsis} random random SEED random START END random START STEP END random choice [ITEMS...] -\endfish + \subsection random-description Description diff --git a/sphinx_doc_src/cmds/read.rst b/sphinx_doc_src/cmds/read.rst index 9a848d28e..d16c7223e 100644 --- a/sphinx_doc_src/cmds/read.rst +++ b/sphinx_doc_src/cmds/read.rst @@ -1,11 +1,11 @@ read - read line of input into variables ========================================== +Synopsis +-------- -\subsection read-synopsis Synopsis -\fish{synopsis} read [OPTIONS] [VARIABLE ...] -\endfish + \subsection read-description Description diff --git a/sphinx_doc_src/cmds/realpath.rst b/sphinx_doc_src/cmds/realpath.rst index 9f2bb9bcc..a34c42198 100644 --- a/sphinx_doc_src/cmds/realpath.rst +++ b/sphinx_doc_src/cmds/realpath.rst @@ -1,11 +1,11 @@ realpath - Convert a path to an absolute path without symlinks ========================================== +Synopsis +-------- -\subsection realpath-synopsis Synopsis -\fish{synopsis} realpath path -\endfish + \subsection realpath-description Description diff --git a/sphinx_doc_src/cmds/return.rst b/sphinx_doc_src/cmds/return.rst index 328d397d2..c7b5ab432 100644 --- a/sphinx_doc_src/cmds/return.rst +++ b/sphinx_doc_src/cmds/return.rst @@ -1,11 +1,11 @@ return - stop the current inner function ========================================== +Synopsis +-------- -\subsection return-synopsis Synopsis -\fish{synopsis} function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end -\endfish + \subsection return-description Description diff --git a/sphinx_doc_src/cmds/set.rst b/sphinx_doc_src/cmds/set.rst index 4a85f539a..ee0807a3e 100644 --- a/sphinx_doc_src/cmds/set.rst +++ b/sphinx_doc_src/cmds/set.rst @@ -1,9 +1,9 @@ set - display and change shell variables. ========================================== +Synopsis +-------- -\subsection set-synopsis Synopsis -\fish{synopsis} set [SCOPE_OPTIONS] set [OPTIONS] VARIABLE_NAME VALUES... set [OPTIONS] VARIABLE_NAME[INDICES]... VALUES... @@ -11,7 +11,7 @@ set ( -q | --query ) [SCOPE_OPTIONS] VARIABLE_NAMES... set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME[INDICES]... set ( -S | --show ) [SCOPE_OPTIONS] [VARIABLE_NAME]... -\endfish + \subsection set-description Description diff --git a/sphinx_doc_src/cmds/set_color.rst b/sphinx_doc_src/cmds/set_color.rst index a5aede87b..84eb1d5b2 100644 --- a/sphinx_doc_src/cmds/set_color.rst +++ b/sphinx_doc_src/cmds/set_color.rst @@ -1,11 +1,11 @@ set_color - set the terminal color ========================================== +Synopsis +-------- -\subsection set_color-synopsis Synopsis -\fish{synopsis} set_color [OPTIONS] VALUE -\endfish + \subsection set_color-description Description diff --git a/sphinx_doc_src/cmds/source.rst b/sphinx_doc_src/cmds/source.rst index 8fc4c8f86..e23fbda25 100644 --- a/sphinx_doc_src/cmds/source.rst +++ b/sphinx_doc_src/cmds/source.rst @@ -1,12 +1,12 @@ source - evaluate contents of file. ========================================== +Synopsis +-------- -\subsection source-synopsis Synopsis -\fish{synopsis} source FILENAME [ARGUMENTS...] somecommand | source -\endfish + \subsection source-description Description diff --git a/sphinx_doc_src/cmds/status.rst b/sphinx_doc_src/cmds/status.rst index b3c6de020..8832855d1 100644 --- a/sphinx_doc_src/cmds/status.rst +++ b/sphinx_doc_src/cmds/status.rst @@ -1,9 +1,9 @@ status - query fish runtime information ========================================== +Synopsis +-------- -\subsection status-synopsis Synopsis -\fish{synopsis} status status is-login status is-interactive @@ -21,7 +21,7 @@ status stack-trace status job-control CONTROL-TYPE status features status test-feature FEATURE -\endfish + \subsection status-description Description diff --git a/sphinx_doc_src/cmds/string.rst b/sphinx_doc_src/cmds/string.rst index a798de5c5..e54784332 100644 --- a/sphinx_doc_src/cmds/string.rst +++ b/sphinx_doc_src/cmds/string.rst @@ -1,9 +1,9 @@ string - manipulate strings ========================================== +Synopsis +-------- -\subsection string-synopsis Synopsis -\fish{synopsis} string escape [(-n | --no-quoted)] [--style=xxx] [STRING...] string join [(-q | --quiet)] SEP [STRING...] string join0 [(-q | --quiet)] [STRING...] @@ -25,7 +25,7 @@ string trim [(-l | --left)] [(-r | --right)] [(-c | --chars CHARS)] [(-q | --quiet)] [STRING...] string unescape [--style=xxx] [STRING...] string upper [(-q | --quiet)] [STRING...] -\endfish + \subsection string-description Description diff --git a/sphinx_doc_src/cmds/suspend.rst b/sphinx_doc_src/cmds/suspend.rst index f96e47f9b..ef5932f3e 100644 --- a/sphinx_doc_src/cmds/suspend.rst +++ b/sphinx_doc_src/cmds/suspend.rst @@ -1,11 +1,11 @@ suspend - suspend the current shell ========================================== +Synopsis +-------- -\subsection suspend-synopsis Synopsis -\fish{synopsis} suspend [--force] -\endfish + \subsection suspend-description Description diff --git a/sphinx_doc_src/cmds/switch.rst b/sphinx_doc_src/cmds/switch.rst index 7ecf7b60b..7f16550ee 100644 --- a/sphinx_doc_src/cmds/switch.rst +++ b/sphinx_doc_src/cmds/switch.rst @@ -1,11 +1,11 @@ switch - conditionally execute a block of commands ========================================== +Synopsis +-------- -\subsection switch-synopsis Synopsis -\fish{synopsis} switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end -\endfish + \subsection switch-description Description diff --git a/sphinx_doc_src/cmds/test.rst b/sphinx_doc_src/cmds/test.rst index 4ea0f5caf..dbe8d07d4 100644 --- a/sphinx_doc_src/cmds/test.rst +++ b/sphinx_doc_src/cmds/test.rst @@ -1,12 +1,12 @@ test - perform tests on files and text ========================================== +Synopsis +-------- -\subsection test-synopsis Synopsis -\fish{synopsis} test [EXPRESSION] [ [EXPRESSION] ] -\endfish + \subsection test-description Description diff --git a/sphinx_doc_src/cmds/trap.rst b/sphinx_doc_src/cmds/trap.rst index 7aabf5ed0..a1e12bcbd 100644 --- a/sphinx_doc_src/cmds/trap.rst +++ b/sphinx_doc_src/cmds/trap.rst @@ -1,11 +1,11 @@ trap - perform an action when the shell receives a signal ========================================== +Synopsis +-------- -\subsection trap-synopsis Synopsis -\fish{synopsis} trap [OPTIONS] [[ARG] REASON ... ] -\endfish + \subsection trap-description Description diff --git a/sphinx_doc_src/cmds/true.rst b/sphinx_doc_src/cmds/true.rst index 00c06561f..2e986de4c 100644 --- a/sphinx_doc_src/cmds/true.rst +++ b/sphinx_doc_src/cmds/true.rst @@ -1,11 +1,11 @@ true - return a successful result ========================================== +Synopsis +-------- -\subsection true-synopsis Synopsis -\fish{synopsis} true -\endfish + \subsection true-description Description diff --git a/sphinx_doc_src/cmds/type.rst b/sphinx_doc_src/cmds/type.rst index fa4096243..26df7876a 100644 --- a/sphinx_doc_src/cmds/type.rst +++ b/sphinx_doc_src/cmds/type.rst @@ -1,11 +1,11 @@ type - indicate how a command would be interpreted ========================================== +Synopsis +-------- -\subsection type-synopsis Synopsis -\fish{synopsis} type [OPTIONS] NAME [NAME ...] -\endfish + \subsection type-description Description diff --git a/sphinx_doc_src/cmds/ulimit.rst b/sphinx_doc_src/cmds/ulimit.rst index ca822cb6d..7b6b60317 100644 --- a/sphinx_doc_src/cmds/ulimit.rst +++ b/sphinx_doc_src/cmds/ulimit.rst @@ -1,11 +1,11 @@ ulimit - set or get resource usage limits ========================================== +Synopsis +-------- -\subsection ulimit-synopsis Synopsis -\fish{synopsis} ulimit [OPTIONS] [LIMIT] -\endfish + \subsection ulimit-description Description diff --git a/sphinx_doc_src/cmds/umask.rst b/sphinx_doc_src/cmds/umask.rst index 23ff022a4..f884fb69f 100644 --- a/sphinx_doc_src/cmds/umask.rst +++ b/sphinx_doc_src/cmds/umask.rst @@ -1,11 +1,11 @@ umask - set or get the file creation mode mask ========================================== +Synopsis +-------- -\subsection umask-synopsis Synopsis -\fish{synopsis} umask [OPTIONS] [MASK] -\endfish + \subsection umask-description Description diff --git a/sphinx_doc_src/cmds/vared.rst b/sphinx_doc_src/cmds/vared.rst index 2687c1bf6..d37e1af0f 100644 --- a/sphinx_doc_src/cmds/vared.rst +++ b/sphinx_doc_src/cmds/vared.rst @@ -1,11 +1,11 @@ vared - interactively edit the value of an environment variable ========================================== +Synopsis +-------- -\subsection vared-synopsis Synopsis -\fish{synopsis} vared VARIABLE_NAME -\endfish + \subsection vared-description Description diff --git a/sphinx_doc_src/cmds/wait.rst b/sphinx_doc_src/cmds/wait.rst index 9d1565273..08ae375e7 100644 --- a/sphinx_doc_src/cmds/wait.rst +++ b/sphinx_doc_src/cmds/wait.rst @@ -1,11 +1,11 @@ wait - wait for jobs to complete ========================================== +Synopsis +-------- -\subsection wait-synopsis Synopsis -\fish{synopsis} wait [-n | --any] [PID | PROCESS_NAME] ... -\endfish + \subsection wait-description Description diff --git a/sphinx_doc_src/cmds/while.rst b/sphinx_doc_src/cmds/while.rst index a1511a43f..20cf3281b 100644 --- a/sphinx_doc_src/cmds/while.rst +++ b/sphinx_doc_src/cmds/while.rst @@ -1,11 +1,11 @@ while - perform a command multiple times ========================================== +Synopsis +-------- -\subsection while-synopsis Synopsis -\fish{synopsis} while CONDITION; COMMANDS...; end -\endfish + \subsection while-description Description From c33d1a217c14ac4ef1288accc0451b0b6b14c0db Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 18 Dec 2018 18:44:30 -0800 Subject: [PATCH 107/191] Convert \\subsection sections into rst format --- sphinx_doc_src/cmds/abbr.rst | 12 ++-- sphinx_doc_src/cmds/alias.rst | 6 +- sphinx_doc_src/cmds/and.rst | 6 +- sphinx_doc_src/cmds/argparse.rst | 21 ++++--- sphinx_doc_src/cmds/begin.rst | 6 +- sphinx_doc_src/cmds/bg.rst | 6 +- sphinx_doc_src/cmds/bind.rst | 12 ++-- sphinx_doc_src/cmds/block.rst | 9 ++- sphinx_doc_src/cmds/break.rst | 6 +- sphinx_doc_src/cmds/breakpoint.rst | 3 +- sphinx_doc_src/cmds/builtin.rst | 6 +- sphinx_doc_src/cmds/case.rst | 6 +- sphinx_doc_src/cmds/cd.rst | 9 ++- sphinx_doc_src/cmds/cdh.rst | 6 +- sphinx_doc_src/cmds/command.rst | 6 +- sphinx_doc_src/cmds/commandline.rst | 6 +- sphinx_doc_src/cmds/complete.rst | 6 +- sphinx_doc_src/cmds/contains.rst | 6 +- sphinx_doc_src/cmds/continue.rst | 6 +- sphinx_doc_src/cmds/count.rst | 6 +- sphinx_doc_src/cmds/dirh.rst | 3 +- sphinx_doc_src/cmds/dirs.rst | 3 +- sphinx_doc_src/cmds/disown.rst | 6 +- sphinx_doc_src/cmds/echo.rst | 9 ++- sphinx_doc_src/cmds/else.rst | 6 +- sphinx_doc_src/cmds/emit.rst | 9 ++- sphinx_doc_src/cmds/end.rst | 3 +- sphinx_doc_src/cmds/eval.rst | 6 +- sphinx_doc_src/cmds/exec.rst | 6 +- sphinx_doc_src/cmds/exit.rst | 3 +- sphinx_doc_src/cmds/false.rst | 3 +- sphinx_doc_src/cmds/fg.rst | 6 +- sphinx_doc_src/cmds/fish.rst | 3 +- .../cmds/fish_breakpoint_prompt.rst | 6 +- sphinx_doc_src/cmds/fish_config.rst | 6 +- sphinx_doc_src/cmds/fish_indent.rst | 3 +- sphinx_doc_src/cmds/fish_key_reader.rst | 6 +- sphinx_doc_src/cmds/fish_mode_prompt.rst | 6 +- sphinx_doc_src/cmds/fish_opt.rst | 6 +- sphinx_doc_src/cmds/fish_prompt.rst | 6 +- sphinx_doc_src/cmds/fish_right_prompt.rst | 6 +- .../cmds/fish_update_completions.rst | 3 +- sphinx_doc_src/cmds/fish_vi_mode.rst | 3 +- sphinx_doc_src/cmds/for.rst | 9 ++- sphinx_doc_src/cmds/funced.rst | 3 +- sphinx_doc_src/cmds/funcsave.rst | 3 +- sphinx_doc_src/cmds/function.rst | 9 ++- sphinx_doc_src/cmds/functions.rst | 6 +- sphinx_doc_src/cmds/help.rst | 6 +- sphinx_doc_src/cmds/history.rst | 12 ++-- sphinx_doc_src/cmds/if.rst | 6 +- sphinx_doc_src/cmds/isatty.rst | 6 +- sphinx_doc_src/cmds/jobs.rst | 9 ++- sphinx_doc_src/cmds/math.rst | 24 +++++--- sphinx_doc_src/cmds/nextd.rst | 6 +- sphinx_doc_src/cmds/not.rst | 6 +- sphinx_doc_src/cmds/open.rst | 6 +- sphinx_doc_src/cmds/or.rst | 6 +- sphinx_doc_src/cmds/popd.rst | 6 +- sphinx_doc_src/cmds/prevd.rst | 6 +- sphinx_doc_src/cmds/printf.rst | 6 +- sphinx_doc_src/cmds/prompt_pwd.rst | 6 +- sphinx_doc_src/cmds/psub.rst | 6 +- sphinx_doc_src/cmds/pushd.rst | 6 +- sphinx_doc_src/cmds/pwd.rst | 3 +- sphinx_doc_src/cmds/random.rst | 6 +- sphinx_doc_src/cmds/read.rst | 9 ++- sphinx_doc_src/cmds/realpath.rst | 3 +- sphinx_doc_src/cmds/return.rst | 6 +- sphinx_doc_src/cmds/set.rst | 9 ++- sphinx_doc_src/cmds/set_color.rst | 12 ++-- sphinx_doc_src/cmds/source.rst | 6 +- sphinx_doc_src/cmds/status.rst | 6 +- sphinx_doc_src/cmds/string.rst | 57 ++++++++++++------- sphinx_doc_src/cmds/suspend.rst | 3 +- sphinx_doc_src/cmds/switch.rst | 6 +- sphinx_doc_src/cmds/test.rst | 21 ++++--- sphinx_doc_src/cmds/trap.rst | 6 +- sphinx_doc_src/cmds/true.rst | 3 +- sphinx_doc_src/cmds/type.rst | 6 +- sphinx_doc_src/cmds/ulimit.rst | 6 +- sphinx_doc_src/cmds/umask.rst | 6 +- sphinx_doc_src/cmds/vared.rst | 6 +- sphinx_doc_src/cmds/wait.rst | 6 +- sphinx_doc_src/cmds/while.rst | 6 +- 85 files changed, 408 insertions(+), 204 deletions(-) diff --git a/sphinx_doc_src/cmds/abbr.rst b/sphinx_doc_src/cmds/abbr.rst index 5721cb6f1..91174d6a5 100644 --- a/sphinx_doc_src/cmds/abbr.rst +++ b/sphinx_doc_src/cmds/abbr.rst @@ -10,13 +10,15 @@ abbr --rename [SCOPE] OLD_WORD NEW_WORD abbr --show abbr --list -\subsection abbr-description Description +Description +------------ `abbr` manages abbreviations - user-defined words that are replaced with longer phrases after they are entered. For example, a frequently-run command like `git checkout` can be abbreviated to `gco`. After entering `gco` and pressing @key{Space} or @key{Enter}, the full text `git checkout` will appear in the command line. -\subsection abbr-options Options +Options +------------ The following options are available: @@ -37,7 +39,8 @@ In addition, when adding abbreviations: See the "Internals" section for more on them. -\subsection abbr-example Examples +Examples +------------ \fish abbr -a -g gco git checkout @@ -64,7 +67,8 @@ ssh another_host abbr -s | source \endfish Import the abbreviations defined on another_host over SSH. -\subsection abbr-internals Internals +Internals +------------ Each abbreviation is stored in its own global or universal variable. The name consists of the prefix `_fish_abbr_` followed by the WORD after being transformed by `string escape style=var`. The WORD cannot contain a space but all other characters are legal. Defining an abbreviation with global scope is slightly faster than universal scope (which is the default). But in general you'll only want to use the global scope when defining abbreviations in a startup script like `~/.config/fish/config.fish` like this: diff --git a/sphinx_doc_src/cmds/alias.rst b/sphinx_doc_src/cmds/alias.rst index 0c5957cae..23a424d14 100644 --- a/sphinx_doc_src/cmds/alias.rst +++ b/sphinx_doc_src/cmds/alias.rst @@ -9,7 +9,8 @@ alias [OPTIONS] NAME DEFINITION alias [OPTIONS] NAME=DEFINITION -\subsection alias-description Description +Description +------------ `alias` is a simple wrapper for the `function` builtin, which creates a function wrapping a command. It has similar syntax to POSIX shell `alias`. For other uses, it is recommended to define a function. @@ -26,7 +27,8 @@ The following options are available: - `-s` or `--save` Automatically save the function created by the alias into your fish configuration directory using funcsave. -\subsection alias-example Example +Example +------------ The following code will create `rmi`, which runs `rm` with additional arguments on every invocation. diff --git a/sphinx_doc_src/cmds/and.rst b/sphinx_doc_src/cmds/and.rst index bf2088706..7a11b6b88 100644 --- a/sphinx_doc_src/cmds/and.rst +++ b/sphinx_doc_src/cmds/and.rst @@ -7,7 +7,8 @@ Synopsis COMMAND1; and COMMAND2 -\subsection and-description Description +Description +------------ `and` is used to execute a command if the previous command was successful (returned a status of 0). @@ -15,7 +16,8 @@ COMMAND1; and COMMAND2 `and` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. -\subsection and-example Example +Example +------------ The following code runs the `make` command to build a program. If the build succeeds, `make`'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and `make clean` is run, which removes the files created by the build process. diff --git a/sphinx_doc_src/cmds/argparse.rst b/sphinx_doc_src/cmds/argparse.rst index 881d4df3b..999cf6ce7 100644 --- a/sphinx_doc_src/cmds/argparse.rst +++ b/sphinx_doc_src/cmds/argparse.rst @@ -7,7 +7,8 @@ Synopsis argparse [OPTIONS] OPTION_SPEC... -- [ARG...] -\subsection argparse-description Description +Description +------------ This command makes it easy for fish scripts and functions to handle arguments in a manner 100% identical to how fish builtin commands handle their arguments. You pass a sequence of arguments that define the options recognized, followed by a literal `--`, then the arguments to be parsed (which might also include a literal `--`). More on this in the usage section below. @@ -17,7 +18,8 @@ Each option that is seen in the ARG list will result in a var name of the form ` For example `_flag_h` and `_flag_help` if `-h` or `--help` is seen. The var will be set with local scope (i.e., as if the script had done `set -l _flag_X`). If the flag is a boolean (that is, does not have an associated value) the values are the short and long flags seen. If the option is not a boolean flag the values will be zero or more values corresponding to the values collected when the ARG list is processed. If the flag was not seen the flag var will not be set. -\subsection argparse-options Options +Options +------------ The following `argparse` options are available. They must appear before all OPTION_SPECs: @@ -33,7 +35,8 @@ The following `argparse` options are available. They must appear before all OPTI - `-h` or `--help` displays help about using this command. -\subsection argparse-usage Usage +Usage +------------ Using this command involves passing two sets of arguments separated by `--`. The first set consists of one or more option specifications (`OPTION_SPEC` above) and options that modify the behavior of `argparse`. These must be listed before the `--` argument. The second set are the arguments to be parsed in accordance with the option specifications. They occur after the `--` argument and can be empty. More about this below but here is a simple example that might be used in a function named `my_function`: @@ -60,7 +63,8 @@ argparse 'h/help' 'n/name' $argv The first `--` seen is what allows the `argparse` command to reliably separate the option specifications from the command arguments. -\subsection argparse-option-specs Option Specifications +Option Specifications +------------ Each option specification is a string composed of @@ -84,7 +88,8 @@ See the `fish_opt` command for a friendlier but more ver In the following examples if a flag is not seen when parsing the arguments then the corresponding _flag_X var(s) will not be set. -\subsection argparse-validation Flag Value Validation +Flag Value Validation +------------ It is common to want to validate the the value provided for an option satisfies some criteria. For example, that it is a valid integer within a specific range. You can always do this after `argparse` returns but you can also request that `argparse` perform the validation by executing arbitrary fish script. To do so simply append an `!` (exclamation-mark) then the fish script to be run. When that code is executed three vars will be defined: @@ -100,7 +105,8 @@ The script should write any error messages to stdout, not stderr. It should retu Fish ships with a `_validate_int` function that accepts a `--min` and `--max` flag. Let's say your command accepts a `-m` or `--max` flag and the minimum allowable value is zero and the maximum is 5. You would define the option like this: `m/max=!_validate_int --min 0 --max 5`. The default if you just call `_validate_int` without those flags is to simply check that the value is a valid integer with no limits on the min or max value allowed. -\subsection argparse-optspec-examples Example OPTION_SPECs +Example OPTION_SPECs +------------ Some OPTION_SPEC examples: @@ -128,6 +134,7 @@ After parsing the arguments the `argv` var is set with local scope to any values If an error occurs during argparse processing it will exit with a non-zero status and print error messages to stderr. -\subsection argparse-notes Notes +Notes +------------ Prior to the addition of this builtin command in the 2.7.0 release there were two main ways to parse the arguments passed to a fish script or function. One way was to use the OS provided `getopt` command. The problem with that is that the GNU and BSD implementations are not compatible. Which makes using that external command difficult other than in trivial situations. The other way is to iterate over `$argv` and use the fish `switch` statement to decide how to handle the argument. That, however, involves a huge amount of boilerplate code. It is also borderline impossible to implement the same behavior as builtin commands. diff --git a/sphinx_doc_src/cmds/begin.rst b/sphinx_doc_src/cmds/begin.rst index 8819a8a63..f53e26585 100644 --- a/sphinx_doc_src/cmds/begin.rst +++ b/sphinx_doc_src/cmds/begin.rst @@ -7,7 +7,8 @@ Synopsis begin; [COMMANDS...;] end -\subsection begin-description Description +Description +------------ `begin` is used to create a new block of code. @@ -18,7 +19,8 @@ The block is unconditionally executed. `begin; ...; end` is equivalent to `if tr `begin` does not change the current exit status itself. After the block has completed, `$status` will be set to the status returned by the most recent command. -\subsection begin-example Example +Example +------------ The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends. diff --git a/sphinx_doc_src/cmds/bg.rst b/sphinx_doc_src/cmds/bg.rst index 5e884c268..866dbaa4c 100644 --- a/sphinx_doc_src/cmds/bg.rst +++ b/sphinx_doc_src/cmds/bg.rst @@ -7,7 +7,8 @@ Synopsis bg [PID...] -\subsection bg-description Description +Description +------------ `bg` sends jobs to the background, resuming them if they are stopped. @@ -18,7 +19,8 @@ When at least one of the arguments isn't a valid job specifier (i.e. PID), When all arguments are valid job specifiers, bg will background all matching jobs that exist. -\subsection bg-example Example +Example +------------ `bg 123 456 789` will background 123, 456 and 789. diff --git a/sphinx_doc_src/cmds/bind.rst b/sphinx_doc_src/cmds/bind.rst index 86743a2fe..9a5faebf8 100644 --- a/sphinx_doc_src/cmds/bind.rst +++ b/sphinx_doc_src/cmds/bind.rst @@ -16,7 +16,8 @@ bind (-e | --erase) [(-M | --mode) MODE] (-a | --all | [(-k | --key)] SEQUENCE [SEQUENCE...]) -\subsection bind-description Description +Description +------------ `bind` adds a binding for the specified key sequence to the specified command. @@ -60,7 +61,8 @@ The following parameters are available: - `--preset` and `--user` specify if bind should operate on user or preset bindings. User bindings take precedence over preset bindings when fish looks up mappings. By default, all `bind` invocations work on the "user" level except for listing, which will show both levels. All invocations except for inserting new bindings can operate on both levels at the same time. `--preset` should only be used in full binding sets (like when working on `fish_vi_key_bindings`). -\subsection bind-functions Special input functions +Special input functions +------------ The following special input functions are available: - `accept-autosuggestion`, accept the current autosuggestion completely @@ -144,7 +146,8 @@ The following special input functions are available: - `yank-pop`, rotate to the previous entry of the killring -\subsection bind-example Examples +Examples +------------ \fish bind \\cd 'exit' @@ -163,7 +166,8 @@ bind -M insert \\cc kill-whole-line force-repaint Turns on Vi key bindings and rebinds @key{Control,C} to clear the input line. -\subsection special-case-escape Special Case: The escape Character +Special Case: The escape Character +------------ The escape key can be used standalone, for example, to switch from insertion mode to normal mode when using Vi keybindings. Escape may also be used as a "meta" key, to indicate the start of an escape sequence, such as function or arrow keys. Custom bindings can also be defined that begin with an escape character. diff --git a/sphinx_doc_src/cmds/block.rst b/sphinx_doc_src/cmds/block.rst index 24566083f..4244c5795 100644 --- a/sphinx_doc_src/cmds/block.rst +++ b/sphinx_doc_src/cmds/block.rst @@ -7,7 +7,8 @@ Synopsis block [OPTIONS...] -\subsection block-description Description +Description +------------ `block` prevents events triggered by `fish` or the `emit` command from being delivered and acted upon while the block is in place. @@ -26,7 +27,8 @@ The following parameters are available: - `-e` or `--erase` Release global block -\subsection block-example Example +Example +------------ \fish # Create a function that listens for events @@ -43,6 +45,7 @@ block -e \endfish -\subsection block-notes Notes +Notes +------------ Note that events are only received from the current fish process as there is no way to send events from one fish process to another. diff --git a/sphinx_doc_src/cmds/break.rst b/sphinx_doc_src/cmds/break.rst index b20305e58..ebbac6608 100644 --- a/sphinx_doc_src/cmds/break.rst +++ b/sphinx_doc_src/cmds/break.rst @@ -7,14 +7,16 @@ Synopsis LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] end -\subsection break-description Description +Description +------------ `break` halts a currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. There are no parameters for `break`. -\subsection break-example Example +Example +------------ The following code searches all .c files for "smurf", and halts at the first occurrence. \fish diff --git a/sphinx_doc_src/cmds/breakpoint.rst b/sphinx_doc_src/cmds/breakpoint.rst index 4aa2852cc..81d951ce0 100644 --- a/sphinx_doc_src/cmds/breakpoint.rst +++ b/sphinx_doc_src/cmds/breakpoint.rst @@ -7,7 +7,8 @@ Synopsis breakpoint -\subsection breakpoint-description Description +Description +------------ `breakpoint` is used to halt a running script and launch an interactive debugging prompt. diff --git a/sphinx_doc_src/cmds/builtin.rst b/sphinx_doc_src/cmds/builtin.rst index 6df15691d..6afb4c6ab 100644 --- a/sphinx_doc_src/cmds/builtin.rst +++ b/sphinx_doc_src/cmds/builtin.rst @@ -7,7 +7,8 @@ Synopsis builtin BUILTINNAME [OPTIONS...] -\subsection builtin-description Description +Description +------------ `builtin` forces the shell to use a builtin command, rather than a function or program. @@ -16,7 +17,8 @@ The following parameters are available: - `-n` or `--names` List the names of all defined builtins -\subsection builtin-example Example +Example +------------ \fish builtin jobs diff --git a/sphinx_doc_src/cmds/case.rst b/sphinx_doc_src/cmds/case.rst index 2f06fb0a7..faf21d401 100644 --- a/sphinx_doc_src/cmds/case.rst +++ b/sphinx_doc_src/cmds/case.rst @@ -7,7 +7,8 @@ Synopsis switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end -\subsection case-description Description +Description +------------ `switch` executes one of several blocks of commands, depending on whether a specified value matches one of several values. `case` is used together with the `switch` statement in order to determine which block should be executed. @@ -18,7 +19,8 @@ Note that fish does not fall through on case statements. Only the first matching Note that command substitutions in a case statement will be evaluated even if its body is not taken. All substitutions, including command substitutions, must be performed before the value can be compared against the parameter. -\subsection case-example Example +Example +------------ Say \$animal contains the name of an animal. Then this code would classify it: diff --git a/sphinx_doc_src/cmds/cd.rst b/sphinx_doc_src/cmds/cd.rst index 2e0590759..96d7283bd 100644 --- a/sphinx_doc_src/cmds/cd.rst +++ b/sphinx_doc_src/cmds/cd.rst @@ -7,7 +7,8 @@ Synopsis cd [DIRECTORY] -\subsection cd-description Description +Description +------------ `cd` changes the current working directory. If `DIRECTORY` is supplied, it will become the new directory. If no parameter is given, the contents of the `HOME` environment variable will be used. @@ -20,7 +21,8 @@ Fish also ships a wrapper function around the builtin `cd` that understands `cd As a special case, `cd .` is equivalent to `cd $PWD`, which is useful in cases where a mountpoint has been recycled or a directory has been removed and recreated. -\subsection cd-example Examples +Examples +------------ \fish cd @@ -30,6 +32,7 @@ cd /usr/src/fish-shell # changes the working directory to /usr/src/fish-shell \endfish -\subsection cd-see-also See Also +See Also +------------ See also the `cdh` command for changing to a recently visited directory. diff --git a/sphinx_doc_src/cmds/cdh.rst b/sphinx_doc_src/cmds/cdh.rst index b122bd362..8ef8bb8b8 100644 --- a/sphinx_doc_src/cmds/cdh.rst +++ b/sphinx_doc_src/cmds/cdh.rst @@ -8,12 +8,14 @@ Synopsis cdh [ directory ] -\subsection cdh-description Description +Description +------------ `cdh` with no arguments presents a list of recently visited directories. You can then select one of the entries by letter or number. You can also press @key{tab} to use the completion pager to select an item from the list. If you give it a single argument it is equivalent to `cd directory`. Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables which this command manipulates. If you make those universal variables your `cd` history is shared among all fish instances. -\subsection cdh-see-also See Also +See Also +------------ See also the `prevd` and `pushd` commands which also work with the recent `cd` history and are provided for compatibility with other shells. diff --git a/sphinx_doc_src/cmds/command.rst b/sphinx_doc_src/cmds/command.rst index 3e832d57c..c77b653b3 100644 --- a/sphinx_doc_src/cmds/command.rst +++ b/sphinx_doc_src/cmds/command.rst @@ -7,7 +7,8 @@ Synopsis command [OPTIONS] COMMANDNAME [ARGS...] -\subsection command-description Description +Description +------------ `command` forces the shell to execute the program `COMMANDNAME` and ignore any functions or builtins with the same name. @@ -23,7 +24,8 @@ With the `-s` option, `command` treats every argument as a separate command to l For basic compatibility with POSIX `command`, the `-v` flag is recognized as an alias for `-s`. -\subsection command-example Examples +Examples +------------ `command ls` causes fish to execute the `ls` program, even if an `ls` function exists. diff --git a/sphinx_doc_src/cmds/commandline.rst b/sphinx_doc_src/cmds/commandline.rst index 1241d3df7..dd02668d5 100644 --- a/sphinx_doc_src/cmds/commandline.rst +++ b/sphinx_doc_src/cmds/commandline.rst @@ -7,7 +7,8 @@ Synopsis commandline [OPTIONS] [CMD] -\subsection commandline-description Description +Description +------------ `commandline` can be used to set or get the current contents of the command line buffer. @@ -58,7 +59,8 @@ The following options output metadata about the commandline state: - `-P` or `--paging-mode` evaluates to true if the commandline is showing pager contents, such as tab completions -\subsection commandline-example Example +Example +------------ `commandline -j $history[3]` replaces the job under the cursor with the third item from the command line history. diff --git a/sphinx_doc_src/cmds/complete.rst b/sphinx_doc_src/cmds/complete.rst index 3691f7095..12d5a9ec1 100644 --- a/sphinx_doc_src/cmds/complete.rst +++ b/sphinx_doc_src/cmds/complete.rst @@ -20,7 +20,8 @@ complete ( -c | --command | -p | --path ) COMMAND complete ( -C[STRING] | --do-complete[=STRING] ) -\subsection complete-description Description +Description +------------ For an introduction to specifying completions, see Writing your own completions in @@ -93,7 +94,8 @@ The `-w` or `--wraps` options causes the specified command to inherit completion When erasing completions, it is possible to either erase all completions for a specific command by specifying `complete -c COMMAND -e`, or by specifying a specific completion option to delete by specifying either a long, short or old style option. -\subsection complete-example Example +Example +------------ The short style option `-o` for the `gcc` command requires that a file follows it. This can be done using writing: diff --git a/sphinx_doc_src/cmds/contains.rst b/sphinx_doc_src/cmds/contains.rst index 8f69ba214..25b0bd84d 100644 --- a/sphinx_doc_src/cmds/contains.rst +++ b/sphinx_doc_src/cmds/contains.rst @@ -7,7 +7,8 @@ Synopsis contains [OPTIONS] KEY [VALUES...] -\subsection contains-description Description +Description +------------ `contains` tests whether the set `VALUES` contains the string `KEY`. If so, `contains` exits with status 0; if not, it exits with status 1. @@ -17,7 +18,8 @@ The following options are available: Note that, like GNU tools and most of fish's builtins, `contains` interprets all arguments starting with a `-` as options to contains, until it reaches an argument that is `--` (two dashes). See the examples below. -\subsection contains-example Example +Example +------------ If $animals is a list of animals, the following will test if it contains a cat: diff --git a/sphinx_doc_src/cmds/continue.rst b/sphinx_doc_src/cmds/continue.rst index 1d7b7fd03..2f131f5e8 100644 --- a/sphinx_doc_src/cmds/continue.rst +++ b/sphinx_doc_src/cmds/continue.rst @@ -7,11 +7,13 @@ Synopsis LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end -\subsection continue-description Description +Description +------------ `continue` skips the remainder of the current iteration of the current inner loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. -\subsection continue-example Example +Example +------------ The following code removes all tmp files that do not contain the word smurf. diff --git a/sphinx_doc_src/cmds/count.rst b/sphinx_doc_src/cmds/count.rst index c84e7fe42..afe51ddc4 100644 --- a/sphinx_doc_src/cmds/count.rst +++ b/sphinx_doc_src/cmds/count.rst @@ -7,7 +7,8 @@ Synopsis count $VARIABLE -\subsection count-description Description +Description +------------ `count` prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains. @@ -16,7 +17,8 @@ count $VARIABLE `count` exits with a non-zero exit status if no arguments were passed to it, and with zero if at least one argument was passed. -\subsection count-example Example +Example +------------ \fish count $PATH diff --git a/sphinx_doc_src/cmds/dirh.rst b/sphinx_doc_src/cmds/dirh.rst index 451d44c17..61c0342c5 100644 --- a/sphinx_doc_src/cmds/dirh.rst +++ b/sphinx_doc_src/cmds/dirh.rst @@ -7,7 +7,8 @@ Synopsis dirh -\subsection dirh-description Description +Description +------------ `dirh` prints the current directory history. The current position in the history is highlighted using the color defined in the `fish_color_history_current` environment variable. diff --git a/sphinx_doc_src/cmds/dirs.rst b/sphinx_doc_src/cmds/dirs.rst index cd07b0f7a..fba514c59 100644 --- a/sphinx_doc_src/cmds/dirs.rst +++ b/sphinx_doc_src/cmds/dirs.rst @@ -8,7 +8,8 @@ dirs dirs -c -\subsection dirs-description Description +Description +------------ `dirs` prints the current directory stack, as created by the `pushd` command. diff --git a/sphinx_doc_src/cmds/disown.rst b/sphinx_doc_src/cmds/disown.rst index c61ca0c03..07bd5a9da 100644 --- a/sphinx_doc_src/cmds/disown.rst +++ b/sphinx_doc_src/cmds/disown.rst @@ -7,7 +7,8 @@ Synopsis disown [ PID ... ] -\subsection disown-description Description +Description +------------ `disown` removes the specified job from the list of jobs. The job itself continues to exist, but fish does not keep track of it any longer. @@ -19,7 +20,8 @@ If a job is stopped, it is sent a signal to continue running, and a warning is p `disown` returns 0 if all specified jobs were disowned successfully, and 1 if any problems were encountered. -\subsection disown-example Example +Example +------------ `firefox &; disown` will start the Firefox web browser in the background and remove it from the job list, meaning it will not be closed when the fish process is closed. diff --git a/sphinx_doc_src/cmds/echo.rst b/sphinx_doc_src/cmds/echo.rst index b38dbcbcf..d29facf00 100644 --- a/sphinx_doc_src/cmds/echo.rst +++ b/sphinx_doc_src/cmds/echo.rst @@ -7,7 +7,8 @@ Synopsis echo [OPTIONS] [STRING] -\subsection echo-description Description +Description +------------ `echo` displays a string of text. @@ -21,7 +22,8 @@ The following options are available: - `-e`, Enable interpretation of backslash escapes -\subsection echo-escapes Escape Sequences +Escape Sequences +------------ If `-e` is used, the following sequences are recognized: @@ -49,7 +51,8 @@ If `-e` is used, the following sequences are recognized: - `\xHH` byte with hexadecimal value HH (1 to 2 digits) -\subsection echo-example Example +Example +------------ \fish echo 'Hello World' diff --git a/sphinx_doc_src/cmds/else.rst b/sphinx_doc_src/cmds/else.rst index 42a4ac8c8..c6c583deb 100644 --- a/sphinx_doc_src/cmds/else.rst +++ b/sphinx_doc_src/cmds/else.rst @@ -7,12 +7,14 @@ Synopsis if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end -\subsection else-description Description +Description +------------ `if` will execute the command `CONDITION`. If the condition's exit status is 0, the commands `COMMANDS_TRUE` will execute. If it is not 0 and `else` is given, `COMMANDS_FALSE` will be executed. -\subsection else-example Example +Example +------------ The following code tests whether a file `foo.txt` exists as a regular file. diff --git a/sphinx_doc_src/cmds/emit.rst b/sphinx_doc_src/cmds/emit.rst index e66f3c7da..b6c25bdfc 100644 --- a/sphinx_doc_src/cmds/emit.rst +++ b/sphinx_doc_src/cmds/emit.rst @@ -7,12 +7,14 @@ Synopsis emit EVENT_NAME [ARGUMENTS...] -\subsection emit-description Description +Description +------------ `emit` emits, or fires, an event. Events are delivered to, or caught by, special functions called event handlers. The arguments are passed to the event handlers as function arguments. -\subsection emit-example Example +Example +------------ The following code first defines an event handler for the generic event named 'test_event', and then emits an event of that type. @@ -25,6 +27,7 @@ emit test_event something \endfish -\subsection emit-notes Notes +Notes +------------ Note that events are only sent to the current fish process as there is no way to send events from one fish process to another. diff --git a/sphinx_doc_src/cmds/end.rst b/sphinx_doc_src/cmds/end.rst index 7ee68ef15..bae471a2f 100644 --- a/sphinx_doc_src/cmds/end.rst +++ b/sphinx_doc_src/cmds/end.rst @@ -11,7 +11,8 @@ for VARNAME in [VALUES...]; COMMANDS...; end switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end -\subsection end-description Description +Description +------------ `end` ends a block of commands. diff --git a/sphinx_doc_src/cmds/eval.rst b/sphinx_doc_src/cmds/eval.rst index 5e1d09aaf..9b75e5406 100644 --- a/sphinx_doc_src/cmds/eval.rst +++ b/sphinx_doc_src/cmds/eval.rst @@ -7,12 +7,14 @@ Synopsis eval [COMMANDS...] -\subsection eval-description Description +Description +------------ `eval` evaluates the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator. If your command does not need access to stdin, consider using `source` instead. -\subsection eval-example Example +Example +------------ The following code will call the ls command. Note that `fish` does not support the use of shell variables as direct commands; `eval` can be used to work around this. diff --git a/sphinx_doc_src/cmds/exec.rst b/sphinx_doc_src/cmds/exec.rst index 7e0509397..4c1637bce 100644 --- a/sphinx_doc_src/cmds/exec.rst +++ b/sphinx_doc_src/cmds/exec.rst @@ -7,11 +7,13 @@ Synopsis exec COMMAND [OPTIONS...] -\subsection exec-description Description +Description +------------ `exec` replaces the currently running shell with a new command. On successful completion, `exec` never returns. `exec` cannot be used inside a pipeline. -\subsection exec-example Example +Example +------------ `exec emacs` starts up the emacs text editor, and exits `fish`. When emacs exits, the session will terminate. diff --git a/sphinx_doc_src/cmds/exit.rst b/sphinx_doc_src/cmds/exit.rst index 54467c09c..497e69292 100644 --- a/sphinx_doc_src/cmds/exit.rst +++ b/sphinx_doc_src/cmds/exit.rst @@ -7,7 +7,8 @@ Synopsis exit [STATUS] -\subsection exit-description Description +Description +------------ `exit` causes fish to exit. If `STATUS` is supplied, it will be converted to an integer and used as the exit code. Otherwise, the exit code will be that of the last command executed. diff --git a/sphinx_doc_src/cmds/false.rst b/sphinx_doc_src/cmds/false.rst index 7e64aa757..31645d0fc 100644 --- a/sphinx_doc_src/cmds/false.rst +++ b/sphinx_doc_src/cmds/false.rst @@ -7,6 +7,7 @@ Synopsis false -\subsection false-description Description +Description +------------ `false` sets the exit status to 1. diff --git a/sphinx_doc_src/cmds/fg.rst b/sphinx_doc_src/cmds/fg.rst index df0263687..8ed9731ab 100644 --- a/sphinx_doc_src/cmds/fg.rst +++ b/sphinx_doc_src/cmds/fg.rst @@ -7,11 +7,13 @@ Synopsis fg [PID] -\subsection fg-description Description +Description +------------ `fg` brings the specified job to the foreground, resuming it if it is stopped. While a foreground job is executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group ID is put in the foreground. -\subsection fg-example Example +Example +------------ `fg` will put the last job in the foreground. diff --git a/sphinx_doc_src/cmds/fish.rst b/sphinx_doc_src/cmds/fish.rst index 83183eaa8..f3a36b941 100644 --- a/sphinx_doc_src/cmds/fish.rst +++ b/sphinx_doc_src/cmds/fish.rst @@ -7,7 +7,8 @@ Synopsis fish [OPTIONS] [-c command] [FILE [ARGUMENTS...]] -\subsection fish-description Description +Description +------------ `fish` is a command-line shell written mainly with interactive use in mind. The full manual is available in HTML by using the help command from inside fish. diff --git a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst index 2bef17f7c..47a411e98 100644 --- a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst +++ b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst @@ -9,7 +9,8 @@ function fish_breakpoint_prompt end -\subsection fish_breakpoint_prompt-description Description +Description +------------ By defining the `fish_breakpoint_prompt` function, the user can choose a custom prompt when asking for input in response to a `breakpoint` command. The `fish_breakpoint_prompt` function is executed when the prompt is to be shown, and the output is used as a prompt. @@ -18,7 +19,8 @@ The exit status of commands within `fish_breakpoint_prompt` will not modify the `fish` ships with a default version of this function that displays the function name and line number of the current execution context. -\subsection fish_breakpoint_prompt-example Example +Example +------------ A simple prompt that is a simplified version of the default debugging prompt: diff --git a/sphinx_doc_src/cmds/fish_config.rst b/sphinx_doc_src/cmds/fish_config.rst index e4098ddbd..2bc16e4b7 100644 --- a/sphinx_doc_src/cmds/fish_config.rst +++ b/sphinx_doc_src/cmds/fish_config.rst @@ -2,7 +2,8 @@ fish_config - start the web-based configuration interface ========================================== -\subsection fish_config-description Description +Description +------------ `fish_config` starts the web-based configuration interface. @@ -15,6 +16,7 @@ The web interface allows you to view your functions, variables and history, and If the `BROWSER` environment variable is set, it will be used as the name of the web browser to open instead of the system default. -\subsection fish_config-example Example +Example +------------ `fish_config` opens a new web browser window and allows you to configure certain fish settings. diff --git a/sphinx_doc_src/cmds/fish_indent.rst b/sphinx_doc_src/cmds/fish_indent.rst index 7ee66eaaf..8c7f0a74b 100644 --- a/sphinx_doc_src/cmds/fish_indent.rst +++ b/sphinx_doc_src/cmds/fish_indent.rst @@ -7,7 +7,8 @@ Synopsis fish_indent [OPTIONS] -\subsection fish_indent-description Description +Description +------------ `fish_indent` is used to indent a piece of fish code. `fish_indent` reads commands from standard input and outputs them to standard output or a specified file. diff --git a/sphinx_doc_src/cmds/fish_key_reader.rst b/sphinx_doc_src/cmds/fish_key_reader.rst index 818c4a59e..03199c37d 100644 --- a/sphinx_doc_src/cmds/fish_key_reader.rst +++ b/sphinx_doc_src/cmds/fish_key_reader.rst @@ -7,7 +7,8 @@ Synopsis fish_key_reader [OPTIONS] -\subsection fish_key_reader-description Description +Description +------------ `fish_key_reader` is used to study input received from the terminal and can help with key binds. The program is interactive and works on standard input. Individual characters themselves and their hexadecimal values are displayed. @@ -25,7 +26,8 @@ The following options are available: - `-v` or `--version` prints fish_key_reader's version and exits. -\subsection fish_key_reader-usage-notes Usage Notes +Usage Notes +------------ The delay in milliseconds since the previous character was received is included in the diagnostic information written to stderr. This information may be useful to determine the optimal `fish_escape_delay_ms` setting or learn the amount of lag introduced by tools like `ssh`, `mosh` or `tmux`. diff --git a/sphinx_doc_src/cmds/fish_mode_prompt.rst b/sphinx_doc_src/cmds/fish_mode_prompt.rst index 2e7d7a4f7..cbaeb2817 100644 --- a/sphinx_doc_src/cmds/fish_mode_prompt.rst +++ b/sphinx_doc_src/cmds/fish_mode_prompt.rst @@ -5,12 +5,14 @@ fish_mode_prompt - define the appearance of the mode indicator The fish_mode_prompt function will output the mode indicator for use in vi-mode. -\subsection fish_mode_prompt-description Description +Description +------------ The default `fish_mode_prompt` function will output indicators about the current Vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. You can also define an empty `fish_mode_prompt` function to remove the Vi mode indicators. The `$fish_bind_mode variable` can be used to determine the current mode. It will be one of `default`, `insert`, `replace_one`, or `visual`. -\subsection fish_mode_prompt-example Example +Example +------------ \fish function fish_mode_prompt diff --git a/sphinx_doc_src/cmds/fish_opt.rst b/sphinx_doc_src/cmds/fish_opt.rst index a76a42be2..e92b0c8ad 100644 --- a/sphinx_doc_src/cmds/fish_opt.rst +++ b/sphinx_doc_src/cmds/fish_opt.rst @@ -9,7 +9,8 @@ fish_opt ( -s X | --short=X ) [ -l LONG | --long=LONG ] [ --long-only ] \ [ -o | --optional-val ] [ -r | --required-val ] [ --multiple-vals ] -\subsection fish_opt-description Description +Description +------------ This command provides a way to produce option specifications suitable for use with the `argparse` command. You can, of course, write the option specs by hand without using this command. But you might prefer to use this for the clarity it provides. @@ -29,7 +30,8 @@ The following `argparse` options are available: - `-h` or `--help` displays help about using this command. -\subsection fish_opt-examples Examples +Examples +------------ Define a single option spec for the boolean help flag: diff --git a/sphinx_doc_src/cmds/fish_prompt.rst b/sphinx_doc_src/cmds/fish_prompt.rst index 6a8c7afde..285d87140 100644 --- a/sphinx_doc_src/cmds/fish_prompt.rst +++ b/sphinx_doc_src/cmds/fish_prompt.rst @@ -9,7 +9,8 @@ function fish_prompt end -\subsection fish_prompt-description Description +Description +------------ By defining the `fish_prompt` function, the user can choose a custom prompt. The `fish_prompt` function is executed when the prompt is to be shown, and the output is used as a prompt. @@ -18,7 +19,8 @@ The exit status of commands within `fish_prompt` will not modify the value of `and` or `or` in the condition. The exit status of the last foreground command to exit can always be accessed using the $status variable. -\subsection if-example Example +Example +------------ The following code will print `foo.txt exists` if the file foo.txt exists and is a regular file, otherwise it will print `bar.txt exists` if the file bar.txt exists and is a regular file, otherwise it will print `foo.txt and bar.txt do not exist`. diff --git a/sphinx_doc_src/cmds/isatty.rst b/sphinx_doc_src/cmds/isatty.rst index bf73f06c1..b421bc725 100644 --- a/sphinx_doc_src/cmds/isatty.rst +++ b/sphinx_doc_src/cmds/isatty.rst @@ -7,7 +7,8 @@ Synopsis isatty [FILE DESCRIPTOR] -\subsection isatty-description Description +Description +------------ `isatty` tests if a file descriptor is a tty. @@ -16,7 +17,8 @@ isatty [FILE DESCRIPTOR] If the specified file descriptor is a tty, the exit status of the command is zero. Otherwise, the exit status is non-zero. No messages are printed to standard error. -\subsection isatty-examples Examples +Examples +------------ From an interactive shell, the commands below exit with a return value of zero: diff --git a/sphinx_doc_src/cmds/jobs.rst b/sphinx_doc_src/cmds/jobs.rst index 2d17d9f92..0c0cd70f3 100644 --- a/sphinx_doc_src/cmds/jobs.rst +++ b/sphinx_doc_src/cmds/jobs.rst @@ -7,7 +7,8 @@ Synopsis jobs [OPTIONS] [PID] -\subsection jobs-description Description +Description +------------ `jobs` prints a list of the currently running jobs and their status. @@ -27,9 +28,11 @@ On systems that supports this feature, jobs will print the CPU usage of each job The exit code of the `jobs` builtin is `0` if there are running background jobs and `1` otherwise. -\subsection prints no output. +no output. +------------ -\subsection jobs-example Example +Example +------------ `jobs` outputs a summary of the current jobs. diff --git a/sphinx_doc_src/cmds/math.rst b/sphinx_doc_src/cmds/math.rst index b263746ae..86183cf8e 100644 --- a/sphinx_doc_src/cmds/math.rst +++ b/sphinx_doc_src/cmds/math.rst @@ -7,7 +7,8 @@ Synopsis math [-sN | --scale=N] [--] EXPRESSION -\subsection math-description Description +Description +------------ `math` is used to perform mathematical calculations. It supports all the usual operations such as addition, subtraction, etc. As well as functions like `abs()`, `sqrt()` and `log2()`. @@ -21,17 +22,20 @@ The following options are available: - `-sN` or `--scale=N` sets the scale of the result. `N` must be an integer. A scale of zero causes results to be rounded down to the nearest integer. So `3/2` returns `1` rather than `2` which `1.5` would normally round to. This is for compatibility with `bc` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. -\subsection return-values Return Values +Return Values +------------ If the expression is successfully evaluated and doesn't over/underflow or return NaN the return `status` is zero (success) else one. -\subsection math-syntax Syntax +Syntax +------------ `math` knows some operators, constants, functions and can (obviously) read numbers. For numbers, `.` is always the radix character regardless of locale - `2.5`, not `2,5`. Scientific notation (`10e5`) is also available. -\subsection math-operators Operators +Operators +------------ `math` knows the following operators: @@ -47,7 +51,8 @@ For numbers, `.` is always the radix character regardless of locale - `2.5`, not They are all used in an infix manner - `5 + 2`, not `+ 5 2`. -\subsection math-constants Constants +Constants +------------ `math` knows the following constants: @@ -56,7 +61,8 @@ They are all used in an infix manner - `5 + 2`, not `+ 5 2`. Use them without a leading `$` - `pi - 3` should be about 0. -\subsection math-functions Functions +Functions +------------ `math` supports the following functions: @@ -85,7 +91,8 @@ Use them without a leading `$` - `pi - 3` should be about 0. All of the trigonometric functions use radians. -\subsection math-example Examples +Examples +------------ `math 1+1` outputs 2. @@ -99,7 +106,8 @@ All of the trigonometric functions use radians. `math "sin(pi)"` outputs `0`. -\subsection math-notes Compatibility notes +Compatibility notes +------------ Fish 1.x and 2.x releases relied on the `bc` command for handling `math` expressions. Starting with fish 3.0.0 fish uses the tinyexpr library and evaluates the expression without the involvement of any external commands. diff --git a/sphinx_doc_src/cmds/nextd.rst b/sphinx_doc_src/cmds/nextd.rst index 8ce5ce915..15f66726c 100644 --- a/sphinx_doc_src/cmds/nextd.rst +++ b/sphinx_doc_src/cmds/nextd.rst @@ -7,7 +7,8 @@ Synopsis nextd [ -l | --list ] [POS] -\subsection nextd-description Description +Description +------------ `nextd` moves forwards `POS` positions in the history of visited directories; if the end of the history has been hit, a warning is printed. @@ -17,7 +18,8 @@ Note that the `cd` command limits directory history to the 25 most recently visi You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. -\subsection nextd-example Example +Example +------------ \fish cd /usr/src diff --git a/sphinx_doc_src/cmds/not.rst b/sphinx_doc_src/cmds/not.rst index 7c572a251..73def4b37 100644 --- a/sphinx_doc_src/cmds/not.rst +++ b/sphinx_doc_src/cmds/not.rst @@ -7,12 +7,14 @@ Synopsis not COMMAND [OPTIONS...] -\subsection not-description Description +Description +------------ `not` negates the exit status of another command. If the exit status is zero, `not` returns 1. Otherwise, `not` returns 0. -\subsection not-example Example +Example +------------ The following code reports an error and exits if no file named spoon can be found. diff --git a/sphinx_doc_src/cmds/open.rst b/sphinx_doc_src/cmds/open.rst index 891d0589e..d093dc955 100644 --- a/sphinx_doc_src/cmds/open.rst +++ b/sphinx_doc_src/cmds/open.rst @@ -7,13 +7,15 @@ Synopsis open FILES... -\subsection open-description Description +Description +------------ `open` opens a file in its default application, using the appropriate tool for the operating system. On GNU/Linux, this requires the common but optional `xdg-open` utility, from the `xdg-utils` package. Note that this function will not be used if a command by this name exists (which is the case on macOS or Haiku). -\subsection open-example Example +Example +------------ `open *.txt` opens all the text files in the current directory using your system's default text editor. diff --git a/sphinx_doc_src/cmds/or.rst b/sphinx_doc_src/cmds/or.rst index 1d507668c..83c8dfe93 100644 --- a/sphinx_doc_src/cmds/or.rst +++ b/sphinx_doc_src/cmds/or.rst @@ -7,7 +7,8 @@ Synopsis COMMAND1; or COMMAND2 -\subsection or-description Description +Description +------------ `or` is used to execute a command if the previous command was not successful (returned a status of something other than 0). @@ -16,7 +17,8 @@ for `if` and `while` for examples. `or` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. -\subsection or-example Example +Example +------------ The following code runs the `make` command to build a program. If the build succeeds, the program is installed. If either step fails, `make clean` is run, which removes the files created by the build process. diff --git a/sphinx_doc_src/cmds/popd.rst b/sphinx_doc_src/cmds/popd.rst index bd3ab1be6..2ebdb2874 100644 --- a/sphinx_doc_src/cmds/popd.rst +++ b/sphinx_doc_src/cmds/popd.rst @@ -7,13 +7,15 @@ Synopsis popd -\subsection popd-description Description +Description +------------ `popd` removes the top directory from the directory stack and changes the working directory to the new top directory. Use `pushd` to add directories to the stack. You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. -\subsection popd-example Example +Example +------------ \fish pushd /usr/src diff --git a/sphinx_doc_src/cmds/prevd.rst b/sphinx_doc_src/cmds/prevd.rst index 224f994ab..50486a7dd 100644 --- a/sphinx_doc_src/cmds/prevd.rst +++ b/sphinx_doc_src/cmds/prevd.rst @@ -7,7 +7,8 @@ Synopsis prevd [ -l | --list ] [POS] -\subsection prevd-description Description +Description +------------ `prevd` moves backwards `POS` positions in the history of visited directories; if the beginning of the history has been hit, a warning is printed. @@ -17,7 +18,8 @@ Note that the `cd` command limits directory history to the 25 most recently visi You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. -\subsection prevd-example Example +Example +------------ \fish cd /usr/src diff --git a/sphinx_doc_src/cmds/printf.rst b/sphinx_doc_src/cmds/printf.rst index ab8aaa95d..dd27e690b 100644 --- a/sphinx_doc_src/cmds/printf.rst +++ b/sphinx_doc_src/cmds/printf.rst @@ -7,7 +7,8 @@ Synopsis printf format [argument...] -\subsection printf-description Description +Description +------------ printf formats the string FORMAT with ARGUMENT, and displays the result. The string FORMAT should contain format specifiers, each of which are replaced with successive arguments according to the specifier. Specifiers are detailed below, and are taken from the C library function `printf(3)`. @@ -59,7 +60,8 @@ The `format` argument is re-used as many times as necessary to convert all of th This file has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try `command printf`. -\subsection printf-example Example +Example +------------ \fish printf '%s\\t%s\\n' flounder fish diff --git a/sphinx_doc_src/cmds/prompt_pwd.rst b/sphinx_doc_src/cmds/prompt_pwd.rst index 951daa7e5..58286b1cc 100644 --- a/sphinx_doc_src/cmds/prompt_pwd.rst +++ b/sphinx_doc_src/cmds/prompt_pwd.rst @@ -7,13 +7,15 @@ Synopsis prompt_pwd -\subsection prompt_pwd-description Description +Description +------------ prompt_pwd is a function to print the current working directory in a way suitable for prompts. It will replace the home directory with "~" and shorten every path component but the last to a default of one character. To change the number of characters per path component, set $fish_prompt_pwd_dir_length to the number of characters. Setting it to 0 or an invalid value will disable shortening entirely. -\subsection prompt_pwd-example Examples +Examples +------------ \fish{cli-dark} >_ cd ~/ diff --git a/sphinx_doc_src/cmds/psub.rst b/sphinx_doc_src/cmds/psub.rst index 75060590f..d63689aea 100644 --- a/sphinx_doc_src/cmds/psub.rst +++ b/sphinx_doc_src/cmds/psub.rst @@ -7,7 +7,8 @@ Synopsis COMMAND1 ( COMMAND2 | psub [-F | --fifo] [-f | --file] [-s SUFFIX]) -\subsection psub-description Description +Description +------------ Some shells (e.g., ksh, bash) feature a syntax that is a mix between command substitution and piping, called process substitution. It is used to send the output of a command into the calling command, much like command substitution, but with the difference that the output is not sent through commandline arguments but through a named pipe, with the filename of the named pipe sent as an argument to the calling program. `psub` combined with a regular command substitution provides the same functionality. @@ -19,7 +20,8 @@ The following options are available: - `-s` or `--suffix` will append SUFFIX to the filename. -\subsection psub-example Example +Example +------------ \fish diff (sort a.txt | psub) (sort b.txt | psub) diff --git a/sphinx_doc_src/cmds/pushd.rst b/sphinx_doc_src/cmds/pushd.rst index 3d4a5a694..238765c65 100644 --- a/sphinx_doc_src/cmds/pushd.rst +++ b/sphinx_doc_src/cmds/pushd.rst @@ -7,7 +7,8 @@ Synopsis pushd [DIRECTORY] -\subsection pushd-description Description +Description +------------ The `pushd` function adds `DIRECTORY` to the top of the directory stack and makes it the current working directory. `popd` will pop it off and return to the original directory. @@ -21,7 +22,8 @@ See also `dirs` and `dirs -c`. You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. -\subsection pushd-example Example +Example +------------ \fish pushd /usr/src diff --git a/sphinx_doc_src/cmds/pwd.rst b/sphinx_doc_src/cmds/pwd.rst index da99d575b..4111c0685 100644 --- a/sphinx_doc_src/cmds/pwd.rst +++ b/sphinx_doc_src/cmds/pwd.rst @@ -7,7 +7,8 @@ Synopsis pwd -\subsection pwd-description Description +Description +------------ `pwd` outputs (prints) the current working directory. diff --git a/sphinx_doc_src/cmds/random.rst b/sphinx_doc_src/cmds/random.rst index 18df8b676..c073d23c9 100644 --- a/sphinx_doc_src/cmds/random.rst +++ b/sphinx_doc_src/cmds/random.rst @@ -11,7 +11,8 @@ random START STEP END random choice [ITEMS...] -\subsection random-description Description +Description +------------ `RANDOM` generates a pseudo-random integer from a uniform distribution. The range (inclusive) is dependent on the arguments passed. @@ -29,7 +30,8 @@ systems. You should not consider `RANDOM` cryptographically secure, or even statistically accurate. -\subsection random-example Example +Example +------------ The following code will count down from a random even number between 10 and 20 to 1: diff --git a/sphinx_doc_src/cmds/read.rst b/sphinx_doc_src/cmds/read.rst index d16c7223e..d7f69974c 100644 --- a/sphinx_doc_src/cmds/read.rst +++ b/sphinx_doc_src/cmds/read.rst @@ -7,7 +7,8 @@ Synopsis read [OPTIONS] [VARIABLE ...] -\subsection read-description Description +Description +------------ `read` reads from standard input and either writes the result back to standard output (for use in command substitution), or stores the result in one or more shell variables. By default, `read` reads a single line and splits it into variables on spaces or tabs. Alternatively, a null character or a maximum number of characters can be used to terminate the input, and other delimiters can be given. Unlike other shells, there is no default variable (such as `REPLY`) for storing the result - instead, it is printed on standard output. @@ -71,11 +72,13 @@ maximum of 10 MiB (1048576 bytes); if the terminator is not reached before this is set to empty and the exit status is set to 122. This limit can be altered with the `fish_read_limit` variable. If set to 0 (zero), the limit is removed. -\subsection read-history Using another read history file +Using another read history file +------------ The `read` command supported the `-m` and `--mode-name` flags in fish versions prior to 2.7.0 to specify an alternative read history file. Those flags are now deprecated and ignored. Instead, set the `fish_history` variable to specify a history session ID. That will affect both the `read` history file and the fish command history file. You can set it to an empty string to specify that no history should be read or written. This is useful for presentations where you do not want possibly private or sensitive history to be exposed to the audience but do want history relevant to the presentation to be available. -\subsection read-example Example +Example +------------ The following code stores the value 'hello' in the shell variable `$foo`. diff --git a/sphinx_doc_src/cmds/realpath.rst b/sphinx_doc_src/cmds/realpath.rst index a34c42198..e3a5bce09 100644 --- a/sphinx_doc_src/cmds/realpath.rst +++ b/sphinx_doc_src/cmds/realpath.rst @@ -7,7 +7,8 @@ Synopsis realpath path -\subsection realpath-description Description +Description +------------ This is implemented as a function and a builtin. The function will attempt to use an external realpath command if one can be found. Otherwise it falls back to the builtin. The builtin does not support any options. It's meant to be used only by scripts which need to be portable. The builtin implementation behaves like GNU realpath when invoked without any options (which is the most common use case). In general scripts should not invoke the builtin directly. They should just use `realpath`. diff --git a/sphinx_doc_src/cmds/return.rst b/sphinx_doc_src/cmds/return.rst index c7b5ab432..f3141bce9 100644 --- a/sphinx_doc_src/cmds/return.rst +++ b/sphinx_doc_src/cmds/return.rst @@ -7,14 +7,16 @@ Synopsis function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end -\subsection return-description Description +Description +------------ `return` halts a currently running function. The exit status is set to `STATUS` if it is given. It is usually added inside of a conditional block such as an if statement or a switch statement to conditionally stop the executing function and return to the caller, but it can also be used to specify the exit status of a function. -\subsection return-example Example +Example +------------ The following code is an implementation of the false command as a fish function diff --git a/sphinx_doc_src/cmds/set.rst b/sphinx_doc_src/cmds/set.rst index ee0807a3e..1d2159d55 100644 --- a/sphinx_doc_src/cmds/set.rst +++ b/sphinx_doc_src/cmds/set.rst @@ -13,7 +13,8 @@ set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME[INDICES]... set ( -S | --show ) [SCOPE_OPTIONS] [VARIABLE_NAME]... -\subsection set-description Description +Description +------------ `set` manipulates shell variables. @@ -82,7 +83,8 @@ In erase mode, if variable indices are specified, only the specified slices of t In assignment mode, `set` does not modify the exit status. This allows simultaneous capture of the output and exit status of a subcommand, e.g. `if set output (command)`. In query mode, the exit status is the number of variables that were not found. In erase mode, `set` exits with a zero exit status in case of success, with a non-zero exit status if the commandline was invalid, if the variable was write-protected or if the variable did not exist. -\subsection set-examples Examples +Examples +------------ \fish # Prints all global, exported variables. set -xg @@ -109,7 +111,8 @@ if set python_path (type -p python) end \endfish -\subsection set-notes Notes +Notes +------------ Fish versions prior to 3.0 supported the syntax `set PATH[1] PATH[4] /bin /sbin`, which worked like `set PATH[1 4] /bin /sbin`. This syntax was not widely used, and was ambiguous and inconsistent. diff --git a/sphinx_doc_src/cmds/set_color.rst b/sphinx_doc_src/cmds/set_color.rst index 84eb1d5b2..bae06ddfe 100644 --- a/sphinx_doc_src/cmds/set_color.rst +++ b/sphinx_doc_src/cmds/set_color.rst @@ -7,7 +7,8 @@ Synopsis set_color [OPTIONS] VALUE -\subsection set_color-description Description +Description +------------ `set_color` is used to control the color and styling of text in the terminal. `VALUE` corresponds to a reserved color name such as *red* or a RGB color value given as 3 or 6 hexadecimal digits. The *br*-, as in 'bright', forms are full-brightness variants of the 8 standard-brightness colors on many terminals. *brblack* has higher brightness than *black* - towards gray. A special keyword *normal* resets text formatting to terminal defaults. @@ -30,14 +31,16 @@ The following options are available: Using the *normal* keyword will reset foreground, background, and all formatting back to default. -\subsection set_color-notes Notes +Notes +------------ 1. Using the *normal* keyword will reset both background and foreground colors to whatever is the default for the terminal. 2. Setting the background color only affects subsequently written characters. Fish provides no way to set the background color for the entire terminal window. Configuring the window background color (and other attributes such as its opacity) has to be done using whatever mechanisms the terminal provides. 3. Some terminals use the `--bold` escape sequence to switch to a brighter color set rather than increasing the weight of text. 4. `set_color` works by printing sequences of characters to *stdout*. If used in command substitution or a pipe, these characters will also be captured. This may or may not be desirable. Checking the exit code of `isatty stdout` before using `set_color` can be useful to decide not to colorize output in a script. -\subsection set_color-example Examples +Examples +------------ \fish set_color red; echo "Roses are red" @@ -46,7 +49,8 @@ set_color 62A; echo "Eggplants are dark purple" set_color normal; echo "Normal is nice" # Resets the background too \endfish -\subsection set_color-detection Terminal Capability Detection +Terminal Capability Detection +------------ Fish uses a heuristic to decide if a terminal supports the 256-color palette as opposed to the more limited 16 color palette of older terminals. Support can be forced on by setting `fish_term256` to *1*. If `$TERM` contains "256color" (e.g., *xterm-256color*), 256-color support is enabled. If `$TERM` contains *xterm*, 256 color support is enabled (except for MacOS: `$TERM_PROGRAM` and `$TERM_PROGRAM_VERSION` are used to detect Terminal.app from MacOS 10.6; support is disabled here it because it is known that it reports `xterm` and only supports 16 colors. diff --git a/sphinx_doc_src/cmds/source.rst b/sphinx_doc_src/cmds/source.rst index e23fbda25..6d72bf2fb 100644 --- a/sphinx_doc_src/cmds/source.rst +++ b/sphinx_doc_src/cmds/source.rst @@ -8,7 +8,8 @@ source FILENAME [ARGUMENTS...] somecommand | source -\subsection source-description Description +Description +------------ `source` evaluates the commands of the specified file in the current shell. This is different from starting a new process to perform the commands (i.e. `fish < FILENAME`) since the commands will be evaluated by the current shell, which means that changes in shell variables will affect the current shell. If additional arguments are specified after the file name, they will be inserted into the `$argv` variable. The `$argv` variable will not include the name of the sourced file. @@ -19,7 +20,8 @@ The return status of `source` is the return status of the last job to execute. I `.` (a single period) is an alias for the `source` command. The use of `.` is deprecated in favour of `source`, and `.` will be removed in a future version of fish. -\subsection source-example Example +Example +------------ \fish source ~/.config/fish/config.fish diff --git a/sphinx_doc_src/cmds/status.rst b/sphinx_doc_src/cmds/status.rst index 8832855d1..aa1422f9f 100644 --- a/sphinx_doc_src/cmds/status.rst +++ b/sphinx_doc_src/cmds/status.rst @@ -23,7 +23,8 @@ status features status test-feature FEATURE -\subsection status-description Description +Description +------------ With no arguments, `status` displays a summary of the current login and job control status of the shell. @@ -62,7 +63,8 @@ The following operations (sub-commands) are available: - `test-feature FEATURE` returns 0 when FEATURE is enabled, 1 if it is disabled, and 2 if it is not recognized. -\subsection status-notes Notes +Notes +------------ For backwards compatibility each subcommand can also be specified as a long or short option. For example, rather than `status is-login` you can type `status --is-login`. The flag forms are deprecated and may be removed in a future release (but not before fish 3.0). diff --git a/sphinx_doc_src/cmds/string.rst b/sphinx_doc_src/cmds/string.rst index e54784332..2149dc4d4 100644 --- a/sphinx_doc_src/cmds/string.rst +++ b/sphinx_doc_src/cmds/string.rst @@ -28,7 +28,8 @@ string upper [(-q | --quiet)] [STRING...] -\subsection string-description Description +Description +------------ `string` performs operations on strings. @@ -40,7 +41,8 @@ Most subcommands accept a `-q` or `--quiet` switch, which suppresses the usual o The following subcommands are available. -\subsection string-escape "escape" subcommand +"escape" subcommand +------------ `string escape` escapes each STRING in one of three ways. The first is `--style=script`. This is the default. It alters the string such that it can be passed back to `eval` to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If `-n` or `--no-quoted` is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise. @@ -52,7 +54,8 @@ The following subcommands are available. `string unescape` performs the inverse of the `string escape` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing `string unescape --style=var (string escape --style=var $str)` will return the original string. There is no support for unescaping pcre2. -\subsection string-join "join" subcommand +"join" subcommand +------------ `string join` joins its STRING arguments into a single string separated by SEP, which can be an empty string. Exit status: 0 if at least one join was performed, or 1 otherwise. @@ -60,15 +63,18 @@ The following subcommands are available. `string join` joins its STRING arguments into a single string separated by the zero byte (NUL), and adds a trailing NUL. This is most useful in conjunction with tools that accept NUL-delimited input, such as `sort -z`. Exit status: 0 if at least one join was performed, or 1 otherwise. -\subsection string-length "length" subcommand +"length" subcommand +------------ `string length` reports the length of each string argument in characters. Exit status: 0 if at least one non-empty STRING was given, or 1 otherwise. -\subsection string-lower "lower" subcommand +"lower" subcommand +------------ `string lower` converts each string argument to lowercase. Exit status: 0 if at least one string was converted to lowercase, else 1. This means that in conjunction with the `-q` flag you can readily test whether a string is already lowercase. -\subsection string-match "match" subcommand +"match" subcommand +------------ `string match` tests each STRING against PATTERN and prints matching substrings. Only the first match for each STRING is reported unless `-a` or `--all` is given, in which case all matches are reported. @@ -84,11 +90,13 @@ If `--invert` or `-v` is used the selected lines will be only those which do not Exit status: 0 if at least one match was found, or 1 otherwise. -\subsection string-repeat "repeat" subcommand +"repeat" subcommand +------------ `string repeat` repeats the STRING `-n` or `--count` times. The `-m` or `--max` option will limit the number of outputted char (excluding the newline). This option can be used by itself or in conjunction with `--count`. If both `--count` and `--max` are present, max char will be outputed unless the final repeated string size is less than max, in that case, the string will repeat until count has been reached. Both `--count` and `--max` will accept a number greater than or equal to zero, in the case of zero, nothing will be outputed. If `-N` or `--no-newline` is given, the output won't contain a newline character at the end. Exit status: 0 if yielded string is not empty, 1 otherwise. -\subsection string-replace "replace" subcommand +"replace" subcommand +------------ `string replace` is similar to `string match` but replaces non-overlapping matching substrings with a replacement string and prints the result. By default, PATTERN is treated as a literal substring to be matched. @@ -98,7 +106,8 @@ If you specify the `-f` or `--filter` flag then each input string is printed onl Exit status: 0 if at least one replacement was performed, or 1 otherwise. -\subsection string-split "split" subcommand +"split" subcommand +------------ `string split` splits each STRING on the separator SEP, which can be an empty string. If `-m` or `--max` is specified, at most MAX splits are done on each STRING. If `-r` or `--right` is given, splitting is performed right-to-left. This is useful in combination with `-m` or `--max`. With `-n` or `--no-empty`, empty results are excluded from consideration (e.g. `hello\n\nworld` would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise. @@ -110,19 +119,23 @@ See also `read --delimiter`. `split0` has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as `find -print0` or `sort -z`. See split0 examples below. -\subsection string-sub "sub" subcommand +"sub" subcommand +------------ `string sub` prints a substring of each string argument. The start of the substring can be specified with `-s` or `--start` followed by a 1-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with `-l` or `--length`. If the length is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise. -\subsection string-trim "trim" subcommand +"trim" subcommand +------------ `string trim` removes leading and trailing whitespace from each STRING. If `-l` or `--left` is given, only leading whitespace is removed. If `-r` or `--right` is given, only trailing whitespace is trimmed. The `-c` or `--chars` switch causes the characters in CHARS to be removed instead of whitespace. Exit status: 0 if at least one character was trimmed, or 1 otherwise. -\subsection string-upper "upper" subcommand +"upper" subcommand +------------ `string upper` converts each string argument to uppercase. Exit status: 0 if at least one string was converted to uppercase, else 1. This means that in conjunction with the `-q` flag you can readily test whether a string is already uppercase. -\subsection regular-expressions Regular Expressions +Regular Expressions +------------ Both the `match` and `replace` subcommand support regular expressions when used with the `-r` or `--regex` option. The dialect is that of PCRE2. @@ -172,7 +185,8 @@ And some other things: - `^` is the start of the string or line, `$` the end. - `|` is "alternation", i.e. the "or". -\subsection string-example Examples +Examples +------------ \fish{cli-dark} >_ string length 'hello, world' @@ -234,7 +248,8 @@ And some other things: a1_20b2__c_E6_85_A1 \endfish -\subsection string-example-match-glob Match Glob Examples +Match Glob Examples +------------ \fish{cli-dark} >_ string match '?' a @@ -266,7 +281,8 @@ foo2 \endfish -\subsection string-example-match-regex Match Regex Examples +Match Regex Examples +------------ \fish{cli-dark} >_ string match -r 'cat|dog|fish' 'nice dog' @@ -315,7 +331,8 @@ foo2 alpha\\ngamma \endfish -\subsection string-example-replace-literal Replace Literal Examples +Replace Literal Examples +------------ \fish{cli-dark} >_ string replace is was 'blue is my favorite' @@ -330,7 +347,8 @@ foo2 spaces_to_underscores \endfish -\subsection string-example-replace-Regex Replace Regex Examples +Replace Regex Examples +------------ \fish{cli-dark} >_ string replace -r -a '[^\\d.]+' ' ' '0 one two 3.14 four 5x' @@ -344,7 +362,8 @@ foo2 here \endfish -\subsection string-example-repeat Repeat Examples +Repeat Examples +------------ \fish{cli-dark} >_ string repeat -n 2 'foo ' diff --git a/sphinx_doc_src/cmds/suspend.rst b/sphinx_doc_src/cmds/suspend.rst index ef5932f3e..e0b3036b2 100644 --- a/sphinx_doc_src/cmds/suspend.rst +++ b/sphinx_doc_src/cmds/suspend.rst @@ -7,7 +7,8 @@ Synopsis suspend [--force] -\subsection suspend-description Description +Description +------------ `suspend` suspends execution of the current shell by sending it a SIGTSTP signal, returning to the controlling process. It can be diff --git a/sphinx_doc_src/cmds/switch.rst b/sphinx_doc_src/cmds/switch.rst index 7f16550ee..821db0456 100644 --- a/sphinx_doc_src/cmds/switch.rst +++ b/sphinx_doc_src/cmds/switch.rst @@ -7,7 +7,8 @@ Synopsis switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end -\subsection switch-description Description +Description +------------ `switch` performs one of several blocks of commands, depending on whether a specified value equals one of several wildcarded values. `case` is used together with the `switch` statement in order to determine which block should be executed. @@ -18,7 +19,8 @@ Note that fish does not fall through on case statements. Only the first matching Note that command substitutions in a case statement will be evaluated even if its body is not taken. All substitutions, including command substitutions, must be performed before the value can be compared against the parameter. -\subsection switch-example Example +Example +------------ If the variable \$animal contains the name of an animal, the following code would attempt to classify it: diff --git a/sphinx_doc_src/cmds/test.rst b/sphinx_doc_src/cmds/test.rst index dbe8d07d4..b5e308e3f 100644 --- a/sphinx_doc_src/cmds/test.rst +++ b/sphinx_doc_src/cmds/test.rst @@ -8,7 +8,8 @@ test [EXPRESSION] [ [EXPRESSION] ] -\subsection test-description Description +Description +------------ Tests the expression given and sets the exit status to 0 if true, and 1 if false. An expression is made up of one or more operators and their arguments. @@ -18,7 +19,8 @@ This test is mostly POSIX-compatible. When using a variable as an argument for a test operator you should almost always enclose it in double-quotes. There are only two situations it is safe to omit the quote marks. The first is when the argument is a literal string with no whitespace or other characters special to the shell (e.g., semicolon). For example, `test -b /my/file`. The second is using a variable that expands to exactly one element including if that element is the empty string (e.g., `set x ''`). If the variable is not set, set but with no value, or set to more than one value you must enclose it in double-quotes. For example, `test "$x" = "$y"`. Since it is always safe to enclose variables in double-quotes when used as `test` arguments that is the recommended practice. -\subsection test-files Operators for files and directories +Operators for files and directories +------------ - `-b FILE` returns true if `FILE` is a block device. @@ -56,7 +58,8 @@ When using a variable as an argument for a test operator you should almost alway - `-x FILE` returns true if `FILE` is marked as executable. -\subsection test-strings Operators for text strings +Operators for text strings +------------ - `STRING1 = STRING2` returns true if the strings `STRING1` and `STRING2` are identical. @@ -66,7 +69,8 @@ When using a variable as an argument for a test operator you should almost alway - `-z STRING` returns true if the length of `STRING` is zero. -\subsection test-numbers Operators to compare and examine numbers +Operators to compare and examine numbers +------------ - `NUM1 -eq NUM2` returns true if `NUM1` and `NUM2` are numerically equal. @@ -82,7 +86,8 @@ When using a variable as an argument for a test operator you should almost alway Both integers and floating point numbers are supported. -\subsection test-combinators Operators to combine expressions +Operators to combine expressions +------------ - `COND1 -a COND2` returns true if both `COND1` and `COND2` are true. @@ -99,7 +104,8 @@ Expressions can be grouped using parentheses. Note that parentheses will usually require escaping with `\(` to avoid being interpreted as a command substitution. -\subsection test-example Examples +Examples +------------ If the `/tmp` directory exists, copy the `/etc/motd` file to it: @@ -157,7 +163,8 @@ if test $status -ne 0 end \endfish -\subsection test-standards Standards +Standards +------------ `test` implements a subset of the IEEE Std 1003.1-2008 (POSIX.1) standard. The following exceptions apply: diff --git a/sphinx_doc_src/cmds/trap.rst b/sphinx_doc_src/cmds/trap.rst index a1e12bcbd..b02aa10fb 100644 --- a/sphinx_doc_src/cmds/trap.rst +++ b/sphinx_doc_src/cmds/trap.rst @@ -7,7 +7,8 @@ Synopsis trap [OPTIONS] [[ARG] REASON ... ] -\subsection trap-description Description +Description +------------ `trap` is a wrapper around the fish event delivery framework. It exists for backwards compatibility with POSIX shells. For other uses, it is recommended to define an event handler. @@ -31,7 +32,8 @@ Signal names are case insensitive and the `SIG` prefix is optional. The return status is 1 if any `REASON` is invalid; otherwise trap returns 0. -\subsection trap-example Example +Example +------------ \fish trap "status --print-stack-trace" SIGUSR1 diff --git a/sphinx_doc_src/cmds/true.rst b/sphinx_doc_src/cmds/true.rst index 2e986de4c..5b30b362f 100644 --- a/sphinx_doc_src/cmds/true.rst +++ b/sphinx_doc_src/cmds/true.rst @@ -7,6 +7,7 @@ Synopsis true -\subsection true-description Description +Description +------------ `true` sets the exit status to 0. diff --git a/sphinx_doc_src/cmds/type.rst b/sphinx_doc_src/cmds/type.rst index 26df7876a..6c4a6a6bd 100644 --- a/sphinx_doc_src/cmds/type.rst +++ b/sphinx_doc_src/cmds/type.rst @@ -7,7 +7,8 @@ Synopsis type [OPTIONS] NAME [NAME ...] -\subsection type-description Description +Description +------------ With no options, `type` indicates how each `NAME` would be interpreted if used as a command name. @@ -28,7 +29,8 @@ The following options are available: The `-q`, `-p`, `-t` and `-P` flags (and their long flag aliases) are mutually exclusive. Only one can be specified at a time. -\subsection type-example Example +Example +------------ \fish{cli-dark} >_ type fg diff --git a/sphinx_doc_src/cmds/ulimit.rst b/sphinx_doc_src/cmds/ulimit.rst index 7b6b60317..86e679546 100644 --- a/sphinx_doc_src/cmds/ulimit.rst +++ b/sphinx_doc_src/cmds/ulimit.rst @@ -7,7 +7,8 @@ Synopsis ulimit [OPTIONS] [LIMIT] -\subsection ulimit-description Description +Description +------------ `ulimit` builtin sets or outputs the resource usage limits of the shell and any processes spawned by it. If a new limit value is omitted, the current value of the limit of the resource is printed; otherwise, the specified limit is set to the new value. @@ -60,7 +61,8 @@ The `fish` implementation of `ulimit` should behave identically to the implement - Fish `ulimit` does not support getting or setting multiple limits in one command, except reporting all values using the -a switch -\subsection ulimit-example Example +Example +------------ `ulimit -Hs 64` sets the hard stack size limit to 64 kB. diff --git a/sphinx_doc_src/cmds/umask.rst b/sphinx_doc_src/cmds/umask.rst index f884fb69f..a615961b1 100644 --- a/sphinx_doc_src/cmds/umask.rst +++ b/sphinx_doc_src/cmds/umask.rst @@ -7,7 +7,8 @@ Synopsis umask [OPTIONS] [MASK] -\subsection umask-description Description +Description +------------ `umask` displays and manipulates the "umask", or file creation mode mask, which is used to restrict the default access to files. @@ -38,6 +39,7 @@ If the first and second parts are skipped, they are assumed to be `a` and `=`, r Note that symbolic masks currently do not work as intended. -\subsection umask-example Example +Example +------------ `umask 177` or `umask u=rw` sets the file creation mask to read and write for the owner and no permissions at all for any other users. diff --git a/sphinx_doc_src/cmds/vared.rst b/sphinx_doc_src/cmds/vared.rst index d37e1af0f..c8f43db08 100644 --- a/sphinx_doc_src/cmds/vared.rst +++ b/sphinx_doc_src/cmds/vared.rst @@ -7,11 +7,13 @@ Synopsis vared VARIABLE_NAME -\subsection vared-description Description +Description +------------ `vared` is used to interactively edit the value of an environment variable. Array variables as a whole can not be edited using `vared`, but individual array elements can. -\subsection vared-example Example +Example +------------ `vared PATH[3]` edits the third element of the PATH array diff --git a/sphinx_doc_src/cmds/wait.rst b/sphinx_doc_src/cmds/wait.rst index 08ae375e7..c40d45b44 100644 --- a/sphinx_doc_src/cmds/wait.rst +++ b/sphinx_doc_src/cmds/wait.rst @@ -7,7 +7,8 @@ Synopsis wait [-n | --any] [PID | PROCESS_NAME] ... -\subsection wait-description Description +Description +------------ `wait` waits for child jobs to complete. @@ -16,7 +17,8 @@ wait [-n | --any] [PID | PROCESS_NAME] ... - If neither a pid nor a process name is specified, the command waits for all background jobs. - If the `-n` / `--any` flag is provided, the command returns as soon as the first job completes. If it is not provided, it returns after all jobs complete. -\subsection wait-example Example +Example +------------ \fish sleep 10 & diff --git a/sphinx_doc_src/cmds/while.rst b/sphinx_doc_src/cmds/while.rst index 20cf3281b..ba8e7fd2b 100644 --- a/sphinx_doc_src/cmds/while.rst +++ b/sphinx_doc_src/cmds/while.rst @@ -7,7 +7,8 @@ Synopsis while CONDITION; COMMANDS...; end -\subsection while-description Description +Description +------------ `while` repeatedly executes `CONDITION`, and if the exit status is 0, then executes `COMMANDS`. @@ -18,7 +19,8 @@ The exit status of the loop is 0 otherwise. You can use `and` or `or` for complex conditions. Even more complex control can be achieved with `while true` containing a break. -\subsection while-example Example +Example +------------ \fish while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end From 2a002a4ba14f06d06b6cd1546ce1bfc5ce288fef Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 18 Dec 2018 19:14:04 -0800 Subject: [PATCH 108/191] Switch \fish sections to rst format --- sphinx_doc_src/cmds/abbr.rst | 64 ++-- sphinx_doc_src/cmds/alias.rst | 21 +- sphinx_doc_src/cmds/and.rst | 9 +- sphinx_doc_src/cmds/argparse.rst | 33 +- sphinx_doc_src/cmds/begin.rst | 42 ++- sphinx_doc_src/cmds/bind.rst | 29 +- sphinx_doc_src/cmds/block.rst | 23 +- sphinx_doc_src/cmds/break.rst | 17 +- sphinx_doc_src/cmds/builtin.rst | 11 +- sphinx_doc_src/cmds/case.rst | 33 +- sphinx_doc_src/cmds/cd.rst | 15 +- sphinx_doc_src/cmds/commandline.rst | 36 +- sphinx_doc_src/cmds/complete.rst | 45 ++- sphinx_doc_src/cmds/contains.rst | 43 ++- sphinx_doc_src/cmds/continue.rst | 23 +- sphinx_doc_src/cmds/count.rst | 15 +- sphinx_doc_src/cmds/echo.rst | 18 +- sphinx_doc_src/cmds/else.rst | 17 +- sphinx_doc_src/cmds/emit.rst | 15 +- sphinx_doc_src/cmds/eval.rst | 11 +- .../cmds/fish_breakpoint_prompt.rst | 19 +- sphinx_doc_src/cmds/fish_mode_prompt.rst | 47 +-- sphinx_doc_src/cmds/fish_opt.rst | 39 ++- sphinx_doc_src/cmds/fish_prompt.rst | 15 +- sphinx_doc_src/cmds/fish_right_prompt.rst | 13 +- sphinx_doc_src/cmds/for.rst | 34 +- sphinx_doc_src/cmds/function.rst | 59 ++-- sphinx_doc_src/cmds/functions.rst | 19 +- sphinx_doc_src/cmds/history.rst | 21 +- sphinx_doc_src/cmds/if.rst | 36 +- sphinx_doc_src/cmds/isatty.rst | 30 +- sphinx_doc_src/cmds/nextd.rst | 23 +- sphinx_doc_src/cmds/not.rst | 15 +- sphinx_doc_src/cmds/or.rst | 9 +- sphinx_doc_src/cmds/popd.rst | 25 +- sphinx_doc_src/cmds/prevd.rst | 23 +- sphinx_doc_src/cmds/printf.rst | 18 +- sphinx_doc_src/cmds/prompt_pwd.rst | 29 +- sphinx_doc_src/cmds/psub.rst | 15 +- sphinx_doc_src/cmds/pushd.rst | 37 +- sphinx_doc_src/cmds/random.rst | 22 +- sphinx_doc_src/cmds/read.rst | 27 +- sphinx_doc_src/cmds/return.rst | 13 +- sphinx_doc_src/cmds/set.rst | 45 +-- sphinx_doc_src/cmds/set_color.rst | 15 +- sphinx_doc_src/cmds/source.rst | 11 +- sphinx_doc_src/cmds/string.rst | 317 ++++++++++-------- sphinx_doc_src/cmds/switch.rst | 31 +- sphinx_doc_src/cmds/test.rst | 91 +++-- sphinx_doc_src/cmds/trap.rst | 11 +- sphinx_doc_src/cmds/type.rst | 11 +- sphinx_doc_src/cmds/wait.rst | 35 +- sphinx_doc_src/cmds/while.rst | 11 +- 53 files changed, 993 insertions(+), 693 deletions(-) diff --git a/sphinx_doc_src/cmds/abbr.rst b/sphinx_doc_src/cmds/abbr.rst index 91174d6a5..79705df0b 100644 --- a/sphinx_doc_src/cmds/abbr.rst +++ b/sphinx_doc_src/cmds/abbr.rst @@ -42,29 +42,44 @@ See the "Internals" section for more on them. Examples ------------ -\fish -abbr -a -g gco git checkout -\endfish + + +:: + + abbr -a -g gco git checkout + Add a new abbreviation where `gco` will be replaced with `git checkout` global to the current shell. This abbreviation will not be automatically visible to other shells unless the same command is run in those shells (such as when executing the commands in config.fish). -\fish -abbr -a -U l less -\endfish + + +:: + + abbr -a -U l less + Add a new abbreviation where `l` will be replaced with `less` universal so all shells. Note that you omit the `-U` since it is the default. -\fish -abbr -r gco gch -\endfish + + +:: + + abbr -r gco gch + Renames an existing abbreviation from `gco` to `gch`. -\fish -abbr -e gco -\endfish + + +:: + + abbr -e gco + Erase the `gco` abbreviation. -\fish -ssh another_host abbr -s | source -\endfish + + +:: + + ssh another_host abbr -s | source + Import the abbreviations defined on another_host over SSH. Internals @@ -73,13 +88,16 @@ Each abbreviation is stored in its own global or universal variable. The name co Defining an abbreviation with global scope is slightly faster than universal scope (which is the default). But in general you'll only want to use the global scope when defining abbreviations in a startup script like `~/.config/fish/config.fish` like this: -\fish -if status --is-interactive - abbr --add --global first 'echo my first abbreviation' - abbr --add --global second 'echo my second abbreviation' - abbr --add --global gco git checkout - # etcetera -end -\endfish + + +:: + + if status --is-interactive + abbr --add --global first 'echo my first abbreviation' + abbr --add --global second 'echo my second abbreviation' + abbr --add --global gco git checkout + # etcetera + end + You can create abbreviations interactively and they will be visible to other fish sessions if you use the `-U` or `--universal` flag or don't explicitly specify the scope and the abbreviation isn't already defined with global scope. If you want it to be visible only to the current shell use the `-g` or `--global` flag. diff --git a/sphinx_doc_src/cmds/alias.rst b/sphinx_doc_src/cmds/alias.rst index 23a424d14..73ff79784 100644 --- a/sphinx_doc_src/cmds/alias.rst +++ b/sphinx_doc_src/cmds/alias.rst @@ -32,14 +32,17 @@ Example The following code will create `rmi`, which runs `rm` with additional arguments on every invocation. -\fish -alias rmi="rm -i" -# This is equivalent to entering the following function: -function rmi --wraps rm --description 'alias rmi=rm -i' - rm -i $argv -end -# This needs to have the spaces escaped or "Chrome.app..." will be seen as an argument to "/Applications/Google": -alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome banana' -\endfish +:: + + alias rmi="rm -i" + + # This is equivalent to entering the following function: + function rmi --wraps rm --description 'alias rmi=rm -i' + rm -i $argv + end + + # This needs to have the spaces escaped or "Chrome.app..." will be seen as an argument to "/Applications/Google": + alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome banana' + diff --git a/sphinx_doc_src/cmds/and.rst b/sphinx_doc_src/cmds/and.rst index 7a11b6b88..fa28dd694 100644 --- a/sphinx_doc_src/cmds/and.rst +++ b/sphinx_doc_src/cmds/and.rst @@ -21,7 +21,10 @@ Example The following code runs the `make` command to build a program. If the build succeeds, `make`'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and `make clean` is run, which removes the files created by the build process. -\fish -make; and make install; or make clean -\endfish + + +:: + + make; and make install; or make clean + diff --git a/sphinx_doc_src/cmds/argparse.rst b/sphinx_doc_src/cmds/argparse.rst index 999cf6ce7..341727e37 100644 --- a/sphinx_doc_src/cmds/argparse.rst +++ b/sphinx_doc_src/cmds/argparse.rst @@ -40,26 +40,35 @@ Usage Using this command involves passing two sets of arguments separated by `--`. The first set consists of one or more option specifications (`OPTION_SPEC` above) and options that modify the behavior of `argparse`. These must be listed before the `--` argument. The second set are the arguments to be parsed in accordance with the option specifications. They occur after the `--` argument and can be empty. More about this below but here is a simple example that might be used in a function named `my_function`: -\fish -argparse --name=my_function 'h/help' 'n/name=' -- $argv -or return -\endfish + + +:: + + argparse --name=my_function 'h/help' 'n/name=' -- $argv + or return + If `$argv` is empty then there is nothing to parse and `argparse` returns zero to indicate success. If `$argv` is not empty then it is checked for flags `-h`, `--help`, `-n` and `--name`. If they are found they are removed from the arguments and local variables (more on this below) are set so the script can determine which options were seen. Assuming `$argv` doesn't have any errors, such as a missing mandatory value for an option, then `argparse` exits with status zero. Otherwise it writes appropriate error messages to stderr and exits with a status of one. The `--` argument is required. You do not have to include any arguments after the `--` but you must include the `--`. For example, this is acceptable: -\fish -set -l argv -argparse 'h/help' 'n/name' -- $argv -\endfish + + +:: + + set -l argv + argparse 'h/help' 'n/name' -- $argv + But this is not: -\fish -set -l argv -argparse 'h/help' 'n/name' $argv -\endfish + + +:: + + set -l argv + argparse 'h/help' 'n/name' $argv + The first `--` seen is what allows the `argparse` command to reliably separate the option specifications from the command arguments. diff --git a/sphinx_doc_src/cmds/begin.rst b/sphinx_doc_src/cmds/begin.rst index f53e26585..2d24381b9 100644 --- a/sphinx_doc_src/cmds/begin.rst +++ b/sphinx_doc_src/cmds/begin.rst @@ -24,27 +24,33 @@ Example The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends. -\fish -begin - set -l PIRATE Yarrr - ... -end -echo $PIRATE -# This will not output anything, since the PIRATE variable -# went out of scope at the end of the block -\endfish +:: + + begin + set -l PIRATE Yarrr + + ... + end + + echo $PIRATE + # This will not output anything, since the PIRATE variable + # went out of scope at the end of the block + In the following code, all output is redirected to the file out.html. -\fish -begin - echo $xml_header - echo $html_header - if test -e $file + + +:: + + begin + echo $xml_header + echo $html_header + if test -e $file + ... + end ... - end - ... -end > out.html -\endfish + end > out.html + diff --git a/sphinx_doc_src/cmds/bind.rst b/sphinx_doc_src/cmds/bind.rst index 9a5faebf8..cf2feebe7 100644 --- a/sphinx_doc_src/cmds/bind.rst +++ b/sphinx_doc_src/cmds/bind.rst @@ -149,20 +149,29 @@ The following special input functions are available: Examples ------------ -\fish -bind \\cd 'exit' -\endfish + + +:: + + bind \\cd 'exit' + Causes `fish` to exit when @key{Control,D} is pressed. -\fish -bind -k ppage history-search-backward -\endfish + + +:: + + bind -k ppage history-search-backward + Performs a history search when the @key{Page Up} key is pressed. -\fish -set -g fish_key_bindings fish_vi_key_bindings -bind -M insert \\cc kill-whole-line force-repaint -\endfish + + +:: + + set -g fish_key_bindings fish_vi_key_bindings + bind -M insert \\cc kill-whole-line force-repaint + Turns on Vi key bindings and rebinds @key{Control,C} to clear the input line. diff --git a/sphinx_doc_src/cmds/block.rst b/sphinx_doc_src/cmds/block.rst index 4244c5795..35efdd625 100644 --- a/sphinx_doc_src/cmds/block.rst +++ b/sphinx_doc_src/cmds/block.rst @@ -30,19 +30,22 @@ The following parameters are available: Example ------------ -\fish -# Create a function that listens for events -function --on-event foo foo; echo 'foo fired'; end -# Block the delivery of events -block -g -emit foo -# No output will be produced +:: + + # Create a function that listens for events + function --on-event foo foo; echo 'foo fired'; end + + # Block the delivery of events + block -g + + emit foo + # No output will be produced + + block -e + # 'foo fired' will now be printed -block -e -# 'foo fired' will now be printed -\endfish Notes diff --git a/sphinx_doc_src/cmds/break.rst b/sphinx_doc_src/cmds/break.rst index ebbac6608..6ee7f9573 100644 --- a/sphinx_doc_src/cmds/break.rst +++ b/sphinx_doc_src/cmds/break.rst @@ -19,11 +19,14 @@ Example ------------ The following code searches all .c files for "smurf", and halts at the first occurrence. -\fish -for i in *.c - if grep smurf $i - echo Smurfs are present in $i - break + + +:: + + for i in *.c + if grep smurf $i + echo Smurfs are present in $i + break + end end -end -\endfish + diff --git a/sphinx_doc_src/cmds/builtin.rst b/sphinx_doc_src/cmds/builtin.rst index 6afb4c6ab..71de7ed19 100644 --- a/sphinx_doc_src/cmds/builtin.rst +++ b/sphinx_doc_src/cmds/builtin.rst @@ -20,7 +20,10 @@ The following parameters are available: Example ------------ -\fish -builtin jobs -# executes the jobs builtin, even if a function named jobs exists -\endfish + + +:: + + builtin jobs + # executes the jobs builtin, even if a function named jobs exists + diff --git a/sphinx_doc_src/cmds/case.rst b/sphinx_doc_src/cmds/case.rst index faf21d401..bc0fe08dd 100644 --- a/sphinx_doc_src/cmds/case.rst +++ b/sphinx_doc_src/cmds/case.rst @@ -24,21 +24,24 @@ Example Say \$animal contains the name of an animal. Then this code would classify it: -\fish -switch $animal - case cat - echo evil - case wolf dog human moose dolphin whale - echo mammal - case duck goose albatross - echo bird - case shark trout stingray - echo fish - # Note that the next case has a wildcard which is quoted - case '*' - echo I have no idea what a $animal is -end -\endfish + + +:: + + switch $animal + case cat + echo evil + case wolf dog human moose dolphin whale + echo mammal + case duck goose albatross + echo bird + case shark trout stingray + echo fish + # Note that the next case has a wildcard which is quoted + case '*' + echo I have no idea what a $animal is + end + If the above code was run with `$animal` set to `whale`, the output would be `mammal`. diff --git a/sphinx_doc_src/cmds/cd.rst b/sphinx_doc_src/cmds/cd.rst index 96d7283bd..1e8b45191 100644 --- a/sphinx_doc_src/cmds/cd.rst +++ b/sphinx_doc_src/cmds/cd.rst @@ -24,13 +24,16 @@ As a special case, `cd .` is equivalent to `cd $PWD`, which is useful in cases w Examples ------------ -\fish -cd -# changes the working directory to your home directory. -cd /usr/src/fish-shell -# changes the working directory to /usr/src/fish-shell -\endfish + +:: + + cd + # changes the working directory to your home directory. + + cd /usr/src/fish-shell + # changes the working directory to /usr/src/fish-shell + See Also ------------ diff --git a/sphinx_doc_src/cmds/commandline.rst b/sphinx_doc_src/cmds/commandline.rst index dd02668d5..6026171db 100644 --- a/sphinx_doc_src/cmds/commandline.rst +++ b/sphinx_doc_src/cmds/commandline.rst @@ -65,22 +65,28 @@ Example `commandline -j $history[3]` replaces the job under the cursor with the third item from the command line history. If the commandline contains -\fish ->_ echo $fl___ounder >&2 | less; and echo $catfish -\endfish + + +:: + + >_ echo $fl___ounder >&2 | less; and echo $catfish + (with the cursor on the "o" of "flounder") Then the following invocations behave like this: -\fish ->_ commandline -t -$flounder ->_ commandline -ct -$fl ->_ commandline -b # or just commandline -echo $flounder >&2 | less; and echo $catfish ->_ commandline -p -echo $flounder >&2 ->_ commandline -j -echo $flounder >&2 | less -\endfish + + +:: + + >_ commandline -t + $flounder + >_ commandline -ct + $fl + >_ commandline -b # or just commandline + echo $flounder >&2 | less; and echo $catfish + >_ commandline -p + echo $flounder >&2 + >_ commandline -j + echo $flounder >&2 | less + diff --git a/sphinx_doc_src/cmds/complete.rst b/sphinx_doc_src/cmds/complete.rst index 12d5a9ec1..a6884a9ae 100644 --- a/sphinx_doc_src/cmds/complete.rst +++ b/sphinx_doc_src/cmds/complete.rst @@ -99,37 +99,52 @@ Example The short style option `-o` for the `gcc` command requires that a file follows it. This can be done using writing: -\fish -complete -c gcc -s o -r -\endfish + + +:: + + complete -c gcc -s o -r + The short style option `-d` for the `grep` command requires that one of the strings '`read`', '`skip`' or '`recurse`' is used. This can be specified writing: -\fish -complete -c grep -s d -x -a "read skip recurse" -\endfish + + +:: + + complete -c grep -s d -x -a "read skip recurse" + The `su` command takes any username as an argument. Usernames are given as the first colon-separated field in the file /etc/passwd. This can be specified as: -\fish -complete -x -c su -d "Username" -a "(cat /etc/passwd | cut -d : -f 1)" -\endfish + + +:: + + complete -x -c su -d "Username" -a "(cat /etc/passwd | cut -d : -f 1)" + The `rpm` command has several different modes. If the `-e` or `--erase` flag has been specified, `rpm` should delete one or more packages, in which case several switches related to deleting packages are valid, like the `nodeps` switch. This can be written as: -\fish -complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d "Don't check dependencies" -\endfish + + +:: + + complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d "Don't check dependencies" + where `__fish_contains_opt` is a function that checks the command line buffer for the presence of a specified set of options. To implement an alias, use the `-w` or `--wraps` option: -\fish -complete -c hub -w git -\endfish + + +:: + + complete -c hub -w git + Now hub inherits all of the completions from git. Note this can also be specified in a function declaration. diff --git a/sphinx_doc_src/cmds/contains.rst b/sphinx_doc_src/cmds/contains.rst index 25b0bd84d..05316bef4 100644 --- a/sphinx_doc_src/cmds/contains.rst +++ b/sphinx_doc_src/cmds/contains.rst @@ -23,30 +23,39 @@ Example If $animals is a list of animals, the following will test if it contains a cat: -\fish -if contains cat $animals - echo Your animal list is evil! -end -\endfish + + +:: + + if contains cat $animals + echo Your animal list is evil! + end + This code will add some directories to $PATH if they aren't yet included: -\fish -for i in ~/bin /usr/local/bin - if not contains $i $PATH - set PATH $PATH $i + + +:: + + for i in ~/bin /usr/local/bin + if not contains $i $PATH + set PATH $PATH $i + end end -end -\endfish + While this will check if `hasargs` was run with the `-q` option: -\fish -function hasargs - if contains -- -q $argv - echo '$argv contains a -q option' + + +:: + + function hasargs + if contains -- -q $argv + echo '$argv contains a -q option' + end end -end -\endfish + The `--` here stops `contains` from treating `-q` to an option to itself. Instead it treats it as a normal string to check. diff --git a/sphinx_doc_src/cmds/continue.rst b/sphinx_doc_src/cmds/continue.rst index 2f131f5e8..95a4a3ec5 100644 --- a/sphinx_doc_src/cmds/continue.rst +++ b/sphinx_doc_src/cmds/continue.rst @@ -17,14 +17,17 @@ Example The following code removes all tmp files that do not contain the word smurf. -\fish -for i in *.tmp - if grep smurf $i - continue + + +:: + + for i in *.tmp + if grep smurf $i + continue + end + # This "rm" is skipped over if "continue" is executed. + rm $i + # As is this "echo" + echo $i end - # This "rm" is skipped over if "continue" is executed. - rm $i - # As is this "echo" - echo $i -end -\endfish + diff --git a/sphinx_doc_src/cmds/count.rst b/sphinx_doc_src/cmds/count.rst index afe51ddc4..3047b9338 100644 --- a/sphinx_doc_src/cmds/count.rst +++ b/sphinx_doc_src/cmds/count.rst @@ -20,10 +20,13 @@ Description Example ------------ -\fish -count $PATH -# Returns the number of directories in the users PATH variable. -count *.txt -# Returns the number of files in the current working directory ending with the suffix '.txt'. -\endfish \ No newline at end of file + +:: + + count $PATH + # Returns the number of directories in the users PATH variable. + + count *.txt + # Returns the number of files in the current working directory ending with the suffix '.txt'. + diff --git a/sphinx_doc_src/cmds/echo.rst b/sphinx_doc_src/cmds/echo.rst index d29facf00..523848fe9 100644 --- a/sphinx_doc_src/cmds/echo.rst +++ b/sphinx_doc_src/cmds/echo.rst @@ -54,12 +54,18 @@ If `-e` is used, the following sequences are recognized: Example ------------ -\fish -echo 'Hello World' -\endfish + + +:: + + echo 'Hello World' + Print hello world to stdout -\fish -echo -e 'Top\\nBottom' -\endfish + + +:: + + echo -e 'Top\\nBottom' + Print Top and Bottom on separate lines, using an escape sequence diff --git a/sphinx_doc_src/cmds/else.rst b/sphinx_doc_src/cmds/else.rst index c6c583deb..6760295a7 100644 --- a/sphinx_doc_src/cmds/else.rst +++ b/sphinx_doc_src/cmds/else.rst @@ -18,10 +18,13 @@ Example The following code tests whether a file `foo.txt` exists as a regular file. -\fish -if test -f foo.txt - echo foo.txt exists -else - echo foo.txt does not exist -end -\endfish + + +:: + + if test -f foo.txt + echo foo.txt exists + else + echo foo.txt does not exist + end + diff --git a/sphinx_doc_src/cmds/emit.rst b/sphinx_doc_src/cmds/emit.rst index b6c25bdfc..794049117 100644 --- a/sphinx_doc_src/cmds/emit.rst +++ b/sphinx_doc_src/cmds/emit.rst @@ -18,13 +18,16 @@ Example The following code first defines an event handler for the generic event named 'test_event', and then emits an event of that type. -\fish -function event_test --on-event test_event - echo event test: $argv -end -emit test_event something -\endfish + +:: + + function event_test --on-event test_event + echo event test: $argv + end + + emit test_event something + Notes diff --git a/sphinx_doc_src/cmds/eval.rst b/sphinx_doc_src/cmds/eval.rst index 9b75e5406..9611dd36a 100644 --- a/sphinx_doc_src/cmds/eval.rst +++ b/sphinx_doc_src/cmds/eval.rst @@ -18,8 +18,11 @@ Example The following code will call the ls command. Note that `fish` does not support the use of shell variables as direct commands; `eval` can be used to work around this. -\fish -set cmd ls -eval $cmd -\endfish + + +:: + + set cmd ls + eval $cmd + diff --git a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst index 47a411e98..b8f6730ca 100644 --- a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst +++ b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst @@ -24,11 +24,14 @@ Example A simple prompt that is a simplified version of the default debugging prompt: -\fish -function fish_breakpoint_prompt -d "Write out the debug prompt" - set -l function (status current-function) - set -l line (status current-line-number) - set -l prompt "$function:$line >" - echo -ns (set_color $fish_color_status) "BP $prompt" (set_color normal) ' ' -end -\endfish + + +:: + + function fish_breakpoint_prompt -d "Write out the debug prompt" + set -l function (status current-function) + set -l line (status current-line-number) + set -l prompt "$function:$line >" + echo -ns (set_color $fish_color_status) "BP $prompt" (set_color normal) ' ' + end + diff --git a/sphinx_doc_src/cmds/fish_mode_prompt.rst b/sphinx_doc_src/cmds/fish_mode_prompt.rst index cbaeb2817..6eaa9a022 100644 --- a/sphinx_doc_src/cmds/fish_mode_prompt.rst +++ b/sphinx_doc_src/cmds/fish_mode_prompt.rst @@ -14,27 +14,30 @@ will be one of `default`, `insert`, `replace_one`, or `visual`. Example ------------ -\fish -function fish_mode_prompt - switch $fish_bind_mode - case default - set_color --bold red - echo 'N' - case insert - set_color --bold green - echo 'I' - case replace_one - set_color --bold green - echo 'R' - case visual - set_color --bold brmagenta - echo 'V' - case '*' - set_color --bold red - echo '?' - end - set_color normal -end -\endfish + + +:: + + function fish_mode_prompt + switch $fish_bind_mode + case default + set_color --bold red + echo 'N' + case insert + set_color --bold green + echo 'I' + case replace_one + set_color --bold green + echo 'R' + case visual + set_color --bold brmagenta + echo 'V' + case '*' + set_color --bold red + echo '?' + end + set_color normal + end + Outputting multiple lines is not supported in `fish_mode_prompt`. diff --git a/sphinx_doc_src/cmds/fish_opt.rst b/sphinx_doc_src/cmds/fish_opt.rst index e92b0c8ad..8faf08120 100644 --- a/sphinx_doc_src/cmds/fish_opt.rst +++ b/sphinx_doc_src/cmds/fish_opt.rst @@ -35,24 +35,33 @@ Examples Define a single option spec for the boolean help flag: -\fish -set -l options (fish_opt -s h -l help) -argparse $options -- $argv -\endfish + + +:: + + set -l options (fish_opt -s h -l help) + argparse $options -- $argv + Same as above but with a second flag that requires a value: -\fish -set -l options (fish_opt -s h -l help) -set options $options (fish_opt -s m -l max --required-val) -argparse $options -- $argv -\endfish + + +:: + + set -l options (fish_opt -s h -l help) + set options $options (fish_opt -s m -l max --required-val) + argparse $options -- $argv + Same as above but with a third flag that can be given multiple times saving the value of each instance seen and only the long flag name (`--token`) can be used: -\fish -set -l options (fish_opt --short=h --long=help) -set options $options (fish_opt --short=m --long=max --required-val) -set options $options (fish_opt --short=t --long=token --multiple-vals --long-only) -argparse $options -- $argv -\endfish + + +:: + + set -l options (fish_opt --short=h --long=help) + set options $options (fish_opt --short=m --long=max --required-val) + set options $options (fish_opt --short=t --long=token --multiple-vals --long-only) + argparse $options -- $argv + diff --git a/sphinx_doc_src/cmds/fish_prompt.rst b/sphinx_doc_src/cmds/fish_prompt.rst index 285d87140..add5e7453 100644 --- a/sphinx_doc_src/cmds/fish_prompt.rst +++ b/sphinx_doc_src/cmds/fish_prompt.rst @@ -24,10 +24,13 @@ Example A simple prompt: -\fish -function fish_prompt -d "Write out the prompt" - printf '%s@%s%s%s%s> ' (whoami) (hostname | cut -d . -f 1) \ - (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) -end -\endfish + + +:: + + function fish_prompt -d "Write out the prompt" + printf '%s@%s%s%s%s> ' (whoami) (hostname | cut -d . -f 1) \ + (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) + end + diff --git a/sphinx_doc_src/cmds/fish_right_prompt.rst b/sphinx_doc_src/cmds/fish_right_prompt.rst index c027e6f84..e9069c1fc 100644 --- a/sphinx_doc_src/cmds/fish_right_prompt.rst +++ b/sphinx_doc_src/cmds/fish_right_prompt.rst @@ -22,9 +22,12 @@ Example A simple right prompt: -\fish -function fish_right_prompt -d "Write out the right prompt" - date '+%m/%d/%y' -end -\endfish + + +:: + + function fish_right_prompt -d "Write out the right prompt" + date '+%m/%d/%y' + end + diff --git a/sphinx_doc_src/cmds/for.rst b/sphinx_doc_src/cmds/for.rst index 3dc81e0e1..1b934f04e 100644 --- a/sphinx_doc_src/cmds/for.rst +++ b/sphinx_doc_src/cmds/for.rst @@ -15,27 +15,33 @@ Description Example ------------ -\fish -for i in foo bar baz; echo $i; end -# would output: -foo -bar -baz -\endfish + +:: + + for i in foo bar baz; echo $i; end + + # would output: + foo + bar + baz + Notes ------------ The `VARNAME` was local to the for block in releases prior to 3.0.0. This means that if you did something like this: -\fish -for var in a b c - if break_from_loop - break + + +:: + + for var in a b c + if break_from_loop + break + end end -end -echo $var -\endfish + echo $var + The last value assigned to `var` when the loop terminated would not be available outside the loop. What `echo $var` would write depended on what it was set to before the loop was run. Likely nothing. diff --git a/sphinx_doc_src/cmds/function.rst b/sphinx_doc_src/cmds/function.rst index ee7e8c631..0d740d590 100644 --- a/sphinx_doc_src/cmds/function.rst +++ b/sphinx_doc_src/cmds/function.rst @@ -60,42 +60,51 @@ By using one of the event handler switches, a function can be made to run automa Example ------------ -\fish -function ll - ls -l $argv -end -\endfish + + +:: + + function ll + ls -l $argv + end + will run the `ls` command, using the `-l` option, while passing on any additional files and switches to `ls`. -\fish -function mkdir -d "Create a directory and set CWD" - command mkdir $argv - if test $status = 0 - switch $argv[(count $argv)] - case '-*' - case '*' - cd $argv[(count $argv)] - return + +:: + + function mkdir -d "Create a directory and set CWD" + command mkdir $argv + if test $status = 0 + switch $argv[(count $argv)] + case '-*' + + case '*' + cd $argv[(count $argv)] + return + end end end -end -\endfish + This will run the `mkdir` command, and if it is successful, change the current working directory to the one just created. -\fish -function notify - set -l job (jobs -l -g) - or begin; echo "There are no jobs" >&2; return 1; end - function _notify_job_$job --on-job-exit $job --inherit-variable job - echo -n \a # beep - functions -e _notify_job_$job + +:: + + function notify + set -l job (jobs -l -g) + or begin; echo "There are no jobs" >&2; return 1; end + + function _notify_job_$job --on-job-exit $job --inherit-variable job + echo -n \a # beep + functions -e _notify_job_$job + end end -end -\endfish + This will beep when the most recent job completes. diff --git a/sphinx_doc_src/cmds/functions.rst b/sphinx_doc_src/cmds/functions.rst index c11e623a2..f5820c595 100644 --- a/sphinx_doc_src/cmds/functions.rst +++ b/sphinx_doc_src/cmds/functions.rst @@ -61,13 +61,16 @@ The exit status of `functions` is the number of functions specified in the argum Examples ------------ -\fish -functions -n -# Displays a list of currently-defined functions -functions -c foo bar -# Copies the 'foo' function to a new function called 'bar' -functions -e bar -# Erases the function `bar` -\endfish +:: + + functions -n + # Displays a list of currently-defined functions + + functions -c foo bar + # Copies the 'foo' function to a new function called 'bar' + + functions -e bar + # Erases the function `bar` + diff --git a/sphinx_doc_src/cmds/history.rst b/sphinx_doc_src/cmds/history.rst index aead95569..0b3701b30 100644 --- a/sphinx_doc_src/cmds/history.rst +++ b/sphinx_doc_src/cmds/history.rst @@ -54,17 +54,20 @@ These flags can appear before or immediately after one of the sub-commands liste Example ------------ -\fish -history clear -# Deletes all history items -history search --contains "foo" -# Outputs a list of all previous commands containing the string "foo". -history delete --prefix "foo" -# Interactively deletes commands which start with "foo" from the history. -# You can select more than one entry by entering their IDs separated by a space. -\endfish +:: + + history clear + # Deletes all history items + + history search --contains "foo" + # Outputs a list of all previous commands containing the string "foo". + + history delete --prefix "foo" + # Interactively deletes commands which start with "foo" from the history. + # You can select more than one entry by entering their IDs separated by a space. + Customizing the name of the history file ------------ diff --git a/sphinx_doc_src/cmds/if.rst b/sphinx_doc_src/cmds/if.rst index ca0e3a594..fea89d3b0 100644 --- a/sphinx_doc_src/cmds/if.rst +++ b/sphinx_doc_src/cmds/if.rst @@ -24,20 +24,26 @@ Example The following code will print `foo.txt exists` if the file foo.txt exists and is a regular file, otherwise it will print `bar.txt exists` if the file bar.txt exists and is a regular file, otherwise it will print `foo.txt and bar.txt do not exist`. -\fish -if test -f foo.txt - echo foo.txt exists -else if test -f bar.txt - echo bar.txt exists -else - echo foo.txt and bar.txt do not exist -end -\endfish + + +:: + + if test -f foo.txt + echo foo.txt exists + else if test -f bar.txt + echo bar.txt exists + else + echo foo.txt and bar.txt do not exist + end + The following code will print "foo.txt exists and is readable" if foo.txt is a regular file and readable -\fish -if test -f foo.txt - and test -r foo.txt - echo "foo.txt exists and is readable" -end -\endfish + + +:: + + if test -f foo.txt + and test -r foo.txt + echo "foo.txt exists and is readable" + end + diff --git a/sphinx_doc_src/cmds/isatty.rst b/sphinx_doc_src/cmds/isatty.rst index b421bc725..26d2c9ca0 100644 --- a/sphinx_doc_src/cmds/isatty.rst +++ b/sphinx_doc_src/cmds/isatty.rst @@ -22,18 +22,24 @@ Examples From an interactive shell, the commands below exit with a return value of zero: -\fish -isatty -isatty stdout -isatty 2 -echo | isatty 1 -\endfish + + +:: + + isatty + isatty stdout + isatty 2 + echo | isatty 1 + And these will exit non-zero: -\fish -echo | isatty -isatty 9 -isatty stdout > file -isatty 2 2> file -\endfish + + +:: + + echo | isatty + isatty 9 + isatty stdout > file + isatty 2 2> file + diff --git a/sphinx_doc_src/cmds/nextd.rst b/sphinx_doc_src/cmds/nextd.rst index 15f66726c..fd4ca53c6 100644 --- a/sphinx_doc_src/cmds/nextd.rst +++ b/sphinx_doc_src/cmds/nextd.rst @@ -21,16 +21,19 @@ You may be interested in the `cdh` command which Example ------------ -\fish -cd /usr/src -# Working directory is now /usr/src -cd /usr/src/fish-shell -# Working directory is now /usr/src/fish-shell -prevd -# Working directory is now /usr/src +:: + + cd /usr/src + # Working directory is now /usr/src + + cd /usr/src/fish-shell + # Working directory is now /usr/src/fish-shell + + prevd + # Working directory is now /usr/src + + nextd + # Working directory is now /usr/src/fish-shell -nextd -# Working directory is now /usr/src/fish-shell -\endfish diff --git a/sphinx_doc_src/cmds/not.rst b/sphinx_doc_src/cmds/not.rst index 73def4b37..de19ae7a4 100644 --- a/sphinx_doc_src/cmds/not.rst +++ b/sphinx_doc_src/cmds/not.rst @@ -18,10 +18,13 @@ Example The following code reports an error and exits if no file named spoon can be found. -\fish -if not test -f spoon - echo There is no spoon - exit 1 -end -\endfish + + +:: + + if not test -f spoon + echo There is no spoon + exit 1 + end + diff --git a/sphinx_doc_src/cmds/or.rst b/sphinx_doc_src/cmds/or.rst index 83c8dfe93..9f2eab5de 100644 --- a/sphinx_doc_src/cmds/or.rst +++ b/sphinx_doc_src/cmds/or.rst @@ -22,6 +22,9 @@ Example The following code runs the `make` command to build a program. If the build succeeds, the program is installed. If either step fails, `make clean` is run, which removes the files created by the build process. -\fish -make; and make install; or make clean -\endfish + + +:: + + make; and make install; or make clean + diff --git a/sphinx_doc_src/cmds/popd.rst b/sphinx_doc_src/cmds/popd.rst index 2ebdb2874..c55d2d45f 100644 --- a/sphinx_doc_src/cmds/popd.rst +++ b/sphinx_doc_src/cmds/popd.rst @@ -17,16 +17,19 @@ You may be interested in the `cdh` command which Example ------------ -\fish -pushd /usr/src -# Working directory is now /usr/src -# Directory stack contains /usr/src -pushd /usr/src/fish-shell -# Working directory is now /usr/src/fish-shell -# Directory stack contains /usr/src /usr/src/fish-shell -popd -# Working directory is now /usr/src -# Directory stack contains /usr/src -\endfish +:: + + pushd /usr/src + # Working directory is now /usr/src + # Directory stack contains /usr/src + + pushd /usr/src/fish-shell + # Working directory is now /usr/src/fish-shell + # Directory stack contains /usr/src /usr/src/fish-shell + + popd + # Working directory is now /usr/src + # Directory stack contains /usr/src + diff --git a/sphinx_doc_src/cmds/prevd.rst b/sphinx_doc_src/cmds/prevd.rst index 50486a7dd..b73d6eab5 100644 --- a/sphinx_doc_src/cmds/prevd.rst +++ b/sphinx_doc_src/cmds/prevd.rst @@ -21,16 +21,19 @@ You may be interested in the `cdh` command which Example ------------ -\fish -cd /usr/src -# Working directory is now /usr/src -cd /usr/src/fish-shell -# Working directory is now /usr/src/fish-shell -prevd -# Working directory is now /usr/src +:: + + cd /usr/src + # Working directory is now /usr/src + + cd /usr/src/fish-shell + # Working directory is now /usr/src/fish-shell + + prevd + # Working directory is now /usr/src + + nextd + # Working directory is now /usr/src/fish-shell -nextd -# Working directory is now /usr/src/fish-shell -\endfish diff --git a/sphinx_doc_src/cmds/printf.rst b/sphinx_doc_src/cmds/printf.rst index dd27e690b..cc3a528b5 100644 --- a/sphinx_doc_src/cmds/printf.rst +++ b/sphinx_doc_src/cmds/printf.rst @@ -63,12 +63,18 @@ This file has been imported from the printf in GNU Coreutils version 6.9. If you Example ------------ -\fish -printf '%s\\t%s\\n' flounder fish -\endfish + + +:: + + printf '%s\\t%s\\n' flounder fish + Will print "flounder fish" (separated with a tab character), followed by a newline character. This is useful for writing completions, as fish expects completion scripts to output the option followed by the description, separated with a tab character. -\fish -printf '%s:%d' "Number of bananas in my pocket" 42 -\endfish + + +:: + + printf '%s:%d' "Number of bananas in my pocket" 42 + Will print "Number of bananas in my pocket: 42", _without_ a newline. diff --git a/sphinx_doc_src/cmds/prompt_pwd.rst b/sphinx_doc_src/cmds/prompt_pwd.rst index 58286b1cc..3d914d0cc 100644 --- a/sphinx_doc_src/cmds/prompt_pwd.rst +++ b/sphinx_doc_src/cmds/prompt_pwd.rst @@ -17,19 +17,22 @@ To change the number of characters per path component, set $fish_prompt_pwd_dir_ Examples ------------ -\fish{cli-dark} ->_ cd ~/ ->_ echo $PWD -/home/alfa ->_ prompt_pwd -~ ->_ cd /tmp/banana/sausage/with/mustard ->_ prompt_pwd -/t/b/s/w/mustard +:: + + >_ cd ~/ + >_ echo $PWD + /home/alfa + + >_ prompt_pwd + ~ + + >_ cd /tmp/banana/sausage/with/mustard + >_ prompt_pwd + /t/b/s/w/mustard + + >_ set -g fish_prompt_pwd_dir_length 3 + >_ prompt_pwd + /tmp/ban/sau/wit/mustard ->_ set -g fish_prompt_pwd_dir_length 3 ->_ prompt_pwd -/tmp/ban/sau/wit/mustard -\endfish diff --git a/sphinx_doc_src/cmds/psub.rst b/sphinx_doc_src/cmds/psub.rst index d63689aea..5e3e4a984 100644 --- a/sphinx_doc_src/cmds/psub.rst +++ b/sphinx_doc_src/cmds/psub.rst @@ -23,10 +23,13 @@ The following options are available: Example ------------ -\fish -diff (sort a.txt | psub) (sort b.txt | psub) -# shows the difference between the sorted versions of files `a.txt` and `b.txt`. -source-highlight -f esc (cpp main.c | psub -f -s .c) -# highlights `main.c` after preprocessing as a C source. -\endfish + +:: + + diff (sort a.txt | psub) (sort b.txt | psub) + # shows the difference between the sorted versions of files `a.txt` and `b.txt`. + + source-highlight -f esc (cpp main.c | psub -f -s .c) + # highlights `main.c` after preprocessing as a C source. + diff --git a/sphinx_doc_src/cmds/pushd.rst b/sphinx_doc_src/cmds/pushd.rst index 238765c65..ef96186a1 100644 --- a/sphinx_doc_src/cmds/pushd.rst +++ b/sphinx_doc_src/cmds/pushd.rst @@ -25,24 +25,27 @@ You may be interested in the `cdh` command which Example ------------ -\fish -pushd /usr/src -# Working directory is now /usr/src -# Directory stack contains /usr/src -pushd /usr/src/fish-shell -# Working directory is now /usr/src/fish-shell -# Directory stack contains /usr/src /usr/src/fish-shell -pushd /tmp/ -# Working directory is now /tmp -# Directory stack contains /tmp /usr/src /usr/src/fish-shell +:: -pushd +1 -# Working directory is now /usr/src -# Directory stack contains /usr/src /usr/src/fish-shell /tmp + pushd /usr/src + # Working directory is now /usr/src + # Directory stack contains /usr/src + + pushd /usr/src/fish-shell + # Working directory is now /usr/src/fish-shell + # Directory stack contains /usr/src /usr/src/fish-shell + + pushd /tmp/ + # Working directory is now /tmp + # Directory stack contains /tmp /usr/src /usr/src/fish-shell + + pushd +1 + # Working directory is now /usr/src + # Directory stack contains /usr/src /usr/src/fish-shell /tmp + + popd + # Working directory is now /usr/src/fish-shell + # Directory stack contains /usr/src/fish-shell /tmp -popd -# Working directory is now /usr/src/fish-shell -# Directory stack contains /usr/src/fish-shell /tmp -\endfish diff --git a/sphinx_doc_src/cmds/random.rst b/sphinx_doc_src/cmds/random.rst index c073d23c9..0dde95e6a 100644 --- a/sphinx_doc_src/cmds/random.rst +++ b/sphinx_doc_src/cmds/random.rst @@ -35,14 +35,20 @@ Example The following code will count down from a random even number between 10 and 20 to 1: -\fish -for i in (seq (random 10 2 20) -1 1) - echo $i -end -\endfish + + +:: + + for i in (seq (random 10 2 20) -1 1) + echo $i + end + And this will open a random picture from any of the subdirectories: -\fish -open (random choice **jpg) -\endfish + + +:: + + open (random choice **jpg) + diff --git a/sphinx_doc_src/cmds/read.rst b/sphinx_doc_src/cmds/read.rst index d7f69974c..69e2ef91b 100644 --- a/sphinx_doc_src/cmds/read.rst +++ b/sphinx_doc_src/cmds/read.rst @@ -82,18 +82,21 @@ Example The following code stores the value 'hello' in the shell variable `$foo`. -\fish -echo hello|read foo -# This is a neat way to handle command output by-line: -printf '%s\n' line1 line2 line3 line4 | while read -l foo - echo "This is another line: $foo" - end -# Delimiters given via "-d" are taken as one string -echo a==b==c | read -d == -l a b c -echo $a # a -echo $b # b -echo $c # c +:: + + echo hello|read foo + + # This is a neat way to handle command output by-line: + printf '%s\n' line1 line2 line3 line4 | while read -l foo + echo "This is another line: $foo" + end + + # Delimiters given via "-d" are taken as one string + echo a==b==c | read -d == -l a b c + echo $a # a + echo $b # b + echo $c # c + -\endfish diff --git a/sphinx_doc_src/cmds/return.rst b/sphinx_doc_src/cmds/return.rst index f3141bce9..38c8c82db 100644 --- a/sphinx_doc_src/cmds/return.rst +++ b/sphinx_doc_src/cmds/return.rst @@ -20,10 +20,13 @@ Example The following code is an implementation of the false command as a fish function -\fish -function false - return 1 -end -\endfish + + +:: + + function false + return 1 + end + diff --git a/sphinx_doc_src/cmds/set.rst b/sphinx_doc_src/cmds/set.rst index 1d2159d55..f5a7f4742 100644 --- a/sphinx_doc_src/cmds/set.rst +++ b/sphinx_doc_src/cmds/set.rst @@ -85,31 +85,34 @@ In assignment mode, `set` does not modify the exit status. This allows simultane Examples ------------ -\fish -# Prints all global, exported variables. -set -xg -# Sets the value of the variable $foo to be 'hi'. -set foo hi -# Appends the value "there" to the variable $foo. -set -a foo there +:: -# Does the same thing as the previous two commands the way it would be done pre-fish 3.0. -set foo hi -set foo $foo there + # Prints all global, exported variables. + set -xg + + # Sets the value of the variable $foo to be 'hi'. + set foo hi + + # Appends the value "there" to the variable $foo. + set -a foo there + + # Does the same thing as the previous two commands the way it would be done pre-fish 3.0. + set foo hi + set foo $foo there + + # Removes the variable $smurf + set -e smurf + + # Changes the fourth element of the $PATH array to ~/bin + set PATH[4] ~/bin + + # Outputs the path to Python if `type -p` returns true. + if set python_path (type -p python) + echo "Python is at $python_path" + end -# Removes the variable $smurf -set -e smurf - -# Changes the fourth element of the $PATH array to ~/bin -set PATH[4] ~/bin - -# Outputs the path to Python if `type -p` returns true. -if set python_path (type -p python) - echo "Python is at $python_path" -end -\endfish Notes ------------ diff --git a/sphinx_doc_src/cmds/set_color.rst b/sphinx_doc_src/cmds/set_color.rst index bae06ddfe..7a330bc51 100644 --- a/sphinx_doc_src/cmds/set_color.rst +++ b/sphinx_doc_src/cmds/set_color.rst @@ -42,12 +42,15 @@ Notes Examples ------------ -\fish -set_color red; echo "Roses are red" -set_color blue; echo "Violets are blue" -set_color 62A; echo "Eggplants are dark purple" -set_color normal; echo "Normal is nice" # Resets the background too -\endfish + + +:: + + set_color red; echo "Roses are red" + set_color blue; echo "Violets are blue" + set_color 62A; echo "Eggplants are dark purple" + set_color normal; echo "Normal is nice" # Resets the background too + Terminal Capability Detection ------------ diff --git a/sphinx_doc_src/cmds/source.rst b/sphinx_doc_src/cmds/source.rst index 6d72bf2fb..a560608d7 100644 --- a/sphinx_doc_src/cmds/source.rst +++ b/sphinx_doc_src/cmds/source.rst @@ -23,10 +23,13 @@ The return status of `source` is the return status of the last job to execute. I Example ------------ -\fish -source ~/.config/fish/config.fish -# Causes fish to re-read its initialization file. -\endfish + + +:: + + source ~/.config/fish/config.fish + # Causes fish to re-read its initialization file. + \subsection Caveats diff --git a/sphinx_doc_src/cmds/string.rst b/sphinx_doc_src/cmds/string.rst index 2149dc4d4..7a71f275f 100644 --- a/sphinx_doc_src/cmds/string.rst +++ b/sphinx_doc_src/cmds/string.rst @@ -188,193 +188,232 @@ And some other things: Examples ------------ -\fish{cli-dark} ->_ string length 'hello, world' -12 ->_ set str foo ->_ string length -q $str; echo $status -0 -# Equivalent to test -n $str -\endfish -\fish{cli-dark} ->_ string sub --length 2 abcde -ab +:: ->_ string sub -s 2 -l 2 abcde -bc + >_ string length 'hello, world' + 12 + + >_ set str foo + >_ string length -q $str; echo $status + 0 + # Equivalent to test -n $str ->_ string sub --start=-2 abcde -de -\endfish -\fish{cli-dark} ->_ string split . example.com -example -com ->_ string split -r -m1 / /usr/local/bin/fish -/usr/local/bin -fish ->_ string split '' abc -a -b -c -\endfish +:: -\fish{cli-dark} ->_ seq 3 | string join ... -1...2...3 -\endfish + >_ string sub --length 2 abcde + ab + + >_ string sub -s 2 -l 2 abcde + bc + + >_ string sub --start=-2 abcde + de -\fish{cli-dark} ->_ string trim ' abc ' -abc ->_ string trim --right --chars=yz xyzzy zany -x -zan -\endfish -\fish{cli-dark} ->_ echo \\x07 | string escape -cg -\endfish -\fish{cli-dark} ->_ string escape --style=var 'a1 b2'\\u6161 -a1_20b2__c_E6_85_A1 -\endfish +:: + + >_ string split . example.com + example + com + + >_ string split -r -m1 / /usr/local/bin/fish + /usr/local/bin + fish + + >_ string split '' abc + a + b + c + + + + +:: + + >_ seq 3 | string join ... + 1...2...3 + + + + +:: + + >_ string trim ' abc ' + abc + + >_ string trim --right --chars=yz xyzzy zany + x + zan + + + + +:: + + >_ echo \\x07 | string escape + cg + + + + +:: + + >_ string escape --style=var 'a1 b2'\\u6161 + a1_20b2__c_E6_85_A1 + Match Glob Examples ------------ -\fish{cli-dark} ->_ string match '?' a -a ->_ string match 'a*b' axxb -axxb ->_ string match -i 'a??B' Axxb -Axxb +:: ->_ echo 'ok?' | string match '*\\?' -ok? + >_ string match '?' a + a + + >_ string match 'a*b' axxb + axxb + + >_ string match -i 'a??B' Axxb + Axxb + + >_ echo 'ok?' | string match '*\\?' + ok? + + # Note that only the second STRING will match here. + >_ string match 'foo' 'foo1' 'foo' 'foo2' + foo + + >_ string match -e 'foo' 'foo1' 'foo' 'foo2' + foo1 + foo + foo2 + + + >_ string match 'foo?' 'foo1' 'foo' 'foo2' + foo1 + foo + foo2 + -# Note that only the second STRING will match here. ->_ string match 'foo' 'foo1' 'foo' 'foo2' -foo - ->_ string match -e 'foo' 'foo1' 'foo' 'foo2' -foo1 -foo -foo2 - - ->_ string match 'foo?' 'foo1' 'foo' 'foo2' -foo1 -foo -foo2 - -\endfish Match Regex Examples ------------ -\fish{cli-dark} ->_ string match -r 'cat|dog|fish' 'nice dog' -dog ->_ string match -r -v "c.*[12]" {cat,dog}(seq 1 4) -dog1 -dog2 -cat3 -dog3 -cat4 -dog4 ->_ string match -r '(\\d\\d?):(\\d\\d):(\\d\\d)' 2:34:56 -2:34:56 -2 -34 -56 +:: ->_ string match -r '^(\\w{{2,4}})\\g1$' papa mud murmur -papa -pa -murmur -mur + >_ string match -r 'cat|dog|fish' 'nice dog' + dog + + >_ string match -r -v "c.*[12]" {cat,dog}(seq 1 4) + dog1 + dog2 + cat3 + dog3 + cat4 + dog4 + + >_ string match -r '(\\d\\d?):(\\d\\d):(\\d\\d)' 2:34:56 + 2:34:56 + 2 + 34 + 56 + + >_ string match -r '^(\\w{{2,4}})\\g1$' papa mud murmur + papa + pa + murmur + mur + + >_ string match -r -a -n at ratatat + 2 2 + 4 2 + 6 2 + + >_ string match -r -i '0x[0-9a-f]{{1,8}}' 'int magic = 0xBadC0de;' + 0xBadC0de ->_ string match -r -a -n at ratatat -2 2 -4 2 -6 2 - ->_ string match -r -i '0x[0-9a-f]{{1,8}}' 'int magic = 0xBadC0de;' -0xBadC0de -\endfish \subsection string-example-split0 NUL Delimited Examples -\fish{cli-dark} ->_ # Count files in a directory, without being confused by newlines. ->_ count (find . -print0 | string split0) -42 ->_ # Sort a list of elements which may contain newlines ->_ set foo beta alpha\\ngamma ->_ set foo (string join0 $foo | sort -z | string split0) ->_ string escape $foo[1] -alpha\\ngamma -\endfish + +:: + + >_ # Count files in a directory, without being confused by newlines. + >_ count (find . -print0 | string split0) + 42 + + >_ # Sort a list of elements which may contain newlines + >_ set foo beta alpha\\ngamma + >_ set foo (string join0 $foo | sort -z | string split0) + >_ string escape $foo[1] + alpha\\ngamma + Replace Literal Examples ------------ -\fish{cli-dark} ->_ string replace is was 'blue is my favorite' -blue was my favorite ->_ string replace 3rd last 1st 2nd 3rd -1st -2nd -last ->_ string replace -a ' ' _ 'spaces to underscores' -spaces_to_underscores -\endfish +:: + + >_ string replace is was 'blue is my favorite' + blue was my favorite + + >_ string replace 3rd last 1st 2nd 3rd + 1st + 2nd + last + + >_ string replace -a ' ' _ 'spaces to underscores' + spaces_to_underscores + Replace Regex Examples ------------ -\fish{cli-dark} ->_ string replace -r -a '[^\\d.]+' ' ' '0 one two 3.14 four 5x' -0 3.14 5 ->_ string replace -r '(\\w+)\\s+(\\w+)' '$2 $1 $$' 'left right' -right left $ ->_ string replace -r '\\s*newline\\s*' '\\n' 'put a newline here' -put a -here -\endfish +:: + + >_ string replace -r -a '[^\\d.]+' ' ' '0 one two 3.14 four 5x' + 0 3.14 5 + + >_ string replace -r '(\\w+)\\s+(\\w+)' '$2 $1 $$' 'left right' + right left $ + + >_ string replace -r '\\s*newline\\s*' '\\n' 'put a newline here' + put a + here + Repeat Examples ------------ -\fish{cli-dark} ->_ string repeat -n 2 'foo ' -foo foo ->_ echo foo | string repeat -n 2 -foofoo ->_ string repeat -n 2 -m 5 'foo' -foofo +:: + + >_ string repeat -n 2 'foo ' + foo foo + + >_ echo foo | string repeat -n 2 + foofoo + + >_ string repeat -n 2 -m 5 'foo' + foofo + + >_ string repeat -m 5 'foo' + foofo ->_ string repeat -m 5 'foo' -foofo -\endfish diff --git a/sphinx_doc_src/cmds/switch.rst b/sphinx_doc_src/cmds/switch.rst index 821db0456..531240767 100644 --- a/sphinx_doc_src/cmds/switch.rst +++ b/sphinx_doc_src/cmds/switch.rst @@ -24,20 +24,23 @@ Example If the variable \$animal contains the name of an animal, the following code would attempt to classify it: -\fish -switch $animal - case cat - echo evil - case wolf dog human moose dolphin whale - echo mammal - case duck goose albatross - echo bird - case shark trout stingray - echo fish - case '*' - echo I have no idea what a $animal is -end -\endfish + + +:: + + switch $animal + case cat + echo evil + case wolf dog human moose dolphin whale + echo mammal + case duck goose albatross + echo bird + case shark trout stingray + echo fish + case '*' + echo I have no idea what a $animal is + end + If the above code was run with `$animal` set to `whale`, the output would be `mammal`. diff --git a/sphinx_doc_src/cmds/test.rst b/sphinx_doc_src/cmds/test.rst index b5e308e3f..dae2b6642 100644 --- a/sphinx_doc_src/cmds/test.rst +++ b/sphinx_doc_src/cmds/test.rst @@ -109,59 +109,80 @@ Examples If the `/tmp` directory exists, copy the `/etc/motd` file to it: -\fish -if test -d /tmp - cp /etc/motd /tmp/motd -end -\endfish + + +:: + + if test -d /tmp + cp /etc/motd /tmp/motd + end + If the variable `MANPATH` is defined and not empty, print the contents. (If `MANPATH` is not defined, then it will expand to zero arguments, unless quoted.) -\fish -if test -n "$MANPATH" - echo $MANPATH -end -\endfish + + +:: + + if test -n "$MANPATH" + echo $MANPATH + end + Parentheses and the `-o` and `-a` operators can be combined to produce more complicated expressions. In this example, success is printed if there is a `/foo` or `/bar` file as well as a `/baz` or `/bat` file. -\fish -if test \( -f /foo -o -f /bar \) -a \( -f /baz -o -f /bat \) - echo Success. -end. -\endfish + + +:: + + if test \( -f /foo -o -f /bar \) -a \( -f /baz -o -f /bat \) + echo Success. + end. + Numerical comparisons will simply fail if one of the operands is not a number: -\fish -if test 42 -eq "The answer to life, the universe and everything" - echo So long and thanks for all the fish # will not be executed -end -\endfish + + +:: + + if test 42 -eq "The answer to life, the universe and everything" + echo So long and thanks for all the fish # will not be executed + end + A common comparison is with $status: -\fish -if test $status -eq 0 - echo "Previous command succeeded" -end -\endfish + + +:: + + if test $status -eq 0 + echo "Previous command succeeded" + end + The previous test can likewise be inverted: -\fish -if test ! $status -eq 0 - echo "Previous command failed" -end -\endfish + + +:: + + if test ! $status -eq 0 + echo "Previous command failed" + end + which is logically equivalent to the following: -\fish -if test $status -ne 0 - echo "Previous command failed" -end -\endfish + + +:: + + if test $status -ne 0 + echo "Previous command failed" + end + Standards ------------ diff --git a/sphinx_doc_src/cmds/trap.rst b/sphinx_doc_src/cmds/trap.rst index b02aa10fb..870c8bedb 100644 --- a/sphinx_doc_src/cmds/trap.rst +++ b/sphinx_doc_src/cmds/trap.rst @@ -35,7 +35,10 @@ The return status is 1 if any `REASON` is invalid; otherwise trap returns 0. Example ------------ -\fish -trap "status --print-stack-trace" SIGUSR1 -# Prints a stack trace each time the SIGUSR1 signal is sent to the shell. -\endfish + + +:: + + trap "status --print-stack-trace" SIGUSR1 + # Prints a stack trace each time the SIGUSR1 signal is sent to the shell. + diff --git a/sphinx_doc_src/cmds/type.rst b/sphinx_doc_src/cmds/type.rst index 6c4a6a6bd..4426a0981 100644 --- a/sphinx_doc_src/cmds/type.rst +++ b/sphinx_doc_src/cmds/type.rst @@ -32,7 +32,10 @@ The `-q`, `-p`, `-t` and `-P` flags (and their long flag aliases) are mutually e Example ------------ -\fish{cli-dark} ->_ type fg -fg is a builtin -\endfish + + +:: + + >_ type fg + fg is a builtin + diff --git a/sphinx_doc_src/cmds/wait.rst b/sphinx_doc_src/cmds/wait.rst index c40d45b44..904ae557e 100644 --- a/sphinx_doc_src/cmds/wait.rst +++ b/sphinx_doc_src/cmds/wait.rst @@ -20,19 +20,28 @@ Description Example ------------ -\fish -sleep 10 & -wait $last_pid -\endfish + + +:: + + sleep 10 & + wait $last_pid + spawns `sleep` in the background, and then waits until it finishes. -\fish -for i in (seq 1 5); sleep 10 &; end -wait -\endfish + + +:: + + for i in (seq 1 5); sleep 10 &; end + wait + spawns five jobs in the background, and then waits until all of them finishes. -\fish -for i in (seq 1 5); sleep 10 &; end -hoge & -wait sleep -\endfish + + +:: + + for i in (seq 1 5); sleep 10 &; end + hoge & + wait sleep + spawns five jobs and `hoge` in the background, and then waits until all `sleep`s finishes, and doesn't wait for `hoge` finishing. diff --git a/sphinx_doc_src/cmds/while.rst b/sphinx_doc_src/cmds/while.rst index ba8e7fd2b..af1429afe 100644 --- a/sphinx_doc_src/cmds/while.rst +++ b/sphinx_doc_src/cmds/while.rst @@ -22,7 +22,10 @@ You can use `and` or `or` for complex condi Example ------------ -\fish -while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end -# outputs 'file exists' at 10 second intervals as long as the file foo.txt or bar.txt exists. -\endfish + + +:: + + while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end + # outputs 'file exists' at 10 second intervals as long as the file foo.txt or bar.txt exists. + From 0e936198db25cae9e0b43057ead0d6949ec7750c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 19 Dec 2018 12:02:45 -0800 Subject: [PATCH 109/191] Switch backticks to double backticks for rst compatibility --- sphinx_doc_src/cmds/abbr.rst | 32 ++--- sphinx_doc_src/cmds/alias.rst | 16 +-- sphinx_doc_src/cmds/and.rst | 8 +- sphinx_doc_src/cmds/argparse.rst | 80 +++++------ sphinx_doc_src/cmds/begin.rst | 8 +- sphinx_doc_src/cmds/bg.rst | 8 +- sphinx_doc_src/cmds/bind.rst | 124 ++++++++-------- sphinx_doc_src/cmds/block.rst | 12 +- sphinx_doc_src/cmds/break.rst | 4 +- sphinx_doc_src/cmds/breakpoint.rst | 6 +- sphinx_doc_src/cmds/builtin.rst | 4 +- sphinx_doc_src/cmds/case.rst | 10 +- sphinx_doc_src/cmds/cd.rst | 14 +- sphinx_doc_src/cmds/cdh.rst | 6 +- sphinx_doc_src/cmds/command.rst | 18 +-- sphinx_doc_src/cmds/commandline.rst | 44 +++--- sphinx_doc_src/cmds/complete.rst | 74 +++++----- sphinx_doc_src/cmds/contains.rst | 10 +- sphinx_doc_src/cmds/continue.rst | 2 +- sphinx_doc_src/cmds/count.rst | 6 +- sphinx_doc_src/cmds/dirh.rst | 6 +- sphinx_doc_src/cmds/dirs.rst | 4 +- sphinx_doc_src/cmds/disown.rst | 14 +- sphinx_doc_src/cmds/echo.rst | 36 ++--- sphinx_doc_src/cmds/else.rst | 4 +- sphinx_doc_src/cmds/emit.rst | 2 +- sphinx_doc_src/cmds/end.rst | 6 +- sphinx_doc_src/cmds/eval.rst | 6 +- sphinx_doc_src/cmds/exec.rst | 4 +- sphinx_doc_src/cmds/exit.rst | 2 +- sphinx_doc_src/cmds/false.rst | 2 +- sphinx_doc_src/cmds/fg.rst | 4 +- sphinx_doc_src/cmds/fish.rst | 22 +-- .../cmds/fish_breakpoint_prompt.rst | 8 +- sphinx_doc_src/cmds/fish_config.rst | 10 +- sphinx_doc_src/cmds/fish_indent.rst | 18 +-- sphinx_doc_src/cmds/fish_key_reader.rst | 26 ++-- sphinx_doc_src/cmds/fish_mode_prompt.rst | 6 +- sphinx_doc_src/cmds/fish_opt.rst | 20 +-- sphinx_doc_src/cmds/fish_prompt.rst | 6 +- sphinx_doc_src/cmds/fish_right_prompt.rst | 4 +- .../cmds/fish_update_completions.rst | 4 +- sphinx_doc_src/cmds/fish_vi_mode.rst | 4 +- sphinx_doc_src/cmds/for.rst | 6 +- sphinx_doc_src/cmds/funced.rst | 12 +- sphinx_doc_src/cmds/funcsave.rst | 4 +- sphinx_doc_src/cmds/function.rst | 40 +++--- sphinx_doc_src/cmds/functions.rst | 40 +++--- sphinx_doc_src/cmds/help.rst | 8 +- sphinx_doc_src/cmds/history.rst | 42 +++--- sphinx_doc_src/cmds/if.rst | 6 +- sphinx_doc_src/cmds/isatty.rst | 4 +- sphinx_doc_src/cmds/jobs.rst | 16 +-- sphinx_doc_src/cmds/math.rst | 98 ++++++------- sphinx_doc_src/cmds/nextd.rst | 8 +- sphinx_doc_src/cmds/not.rst | 2 +- sphinx_doc_src/cmds/open.rst | 4 +- sphinx_doc_src/cmds/or.rst | 10 +- sphinx_doc_src/cmds/popd.rst | 4 +- sphinx_doc_src/cmds/prevd.rst | 8 +- sphinx_doc_src/cmds/printf.rst | 58 ++++---- sphinx_doc_src/cmds/psub.rst | 12 +- sphinx_doc_src/cmds/pushd.rst | 10 +- sphinx_doc_src/cmds/pwd.rst | 6 +- sphinx_doc_src/cmds/random.rst | 8 +- sphinx_doc_src/cmds/read.rst | 60 ++++---- sphinx_doc_src/cmds/realpath.rst | 2 +- sphinx_doc_src/cmds/return.rst | 2 +- sphinx_doc_src/cmds/set.rst | 42 +++--- sphinx_doc_src/cmds/set_color.rst | 30 ++-- sphinx_doc_src/cmds/source.rst | 10 +- sphinx_doc_src/cmds/status.rst | 38 ++--- sphinx_doc_src/cmds/string.rst | 134 +++++++++--------- sphinx_doc_src/cmds/suspend.rst | 4 +- sphinx_doc_src/cmds/switch.rst | 8 +- sphinx_doc_src/cmds/test.rst | 86 +++++------ sphinx_doc_src/cmds/trap.rst | 20 +-- sphinx_doc_src/cmds/true.rst | 2 +- sphinx_doc_src/cmds/type.rst | 16 +-- sphinx_doc_src/cmds/ulimit.rst | 46 +++--- sphinx_doc_src/cmds/umask.rst | 20 +-- sphinx_doc_src/cmds/vared.rst | 4 +- sphinx_doc_src/cmds/wait.rst | 8 +- sphinx_doc_src/cmds/while.rst | 8 +- 84 files changed, 825 insertions(+), 825 deletions(-) diff --git a/sphinx_doc_src/cmds/abbr.rst b/sphinx_doc_src/cmds/abbr.rst index 79705df0b..7aff46d13 100644 --- a/sphinx_doc_src/cmds/abbr.rst +++ b/sphinx_doc_src/cmds/abbr.rst @@ -13,29 +13,29 @@ abbr --list Description ------------ -`abbr` manages abbreviations - user-defined words that are replaced with longer phrases after they are entered. +``abbr`` manages abbreviations - user-defined words that are replaced with longer phrases after they are entered. -For example, a frequently-run command like `git checkout` can be abbreviated to `gco`. After entering `gco` and pressing @key{Space} or @key{Enter}, the full text `git checkout` will appear in the command line. +For example, a frequently-run command like ``git checkout`` can be abbreviated to ``gco``. After entering ``gco`` and pressing @key{Space} or @key{Enter}, the full text ``git checkout`` will appear in the command line. Options ------------ The following options are available: -- `-a WORD EXPANSION` or `--add WORD EXPANSION` Adds a new abbreviation, causing WORD to be expanded to PHRASE. +- ``-a WORD EXPANSION`` or ``--add WORD EXPANSION`` Adds a new abbreviation, causing WORD to be expanded to PHRASE. -- `-r OLD_WORD NEW_WORD` or `--rename OLD_WORD NEW_WORD` Renames an abbreviation, from OLD_WORD to NEW_WORD. +- ``-r OLD_WORD NEW_WORD`` or ``--rename OLD_WORD NEW_WORD`` Renames an abbreviation, from OLD_WORD to NEW_WORD. -- `-s` or `--show` Show all abbreviations in a manner suitable for export and import. +- ``-s`` or ``--show`` Show all abbreviations in a manner suitable for export and import. -- `-l` or `--list` Lists all abbreviated words. +- ``-l`` or ``--list`` Lists all abbreviated words. -- `-e WORD` or `--erase WORD` Erase the abbreviation WORD. +- ``-e WORD`` or ``--erase WORD`` Erase the abbreviation WORD. In addition, when adding abbreviations: -- `-g` or `--global` to use a global variable. -- `-U` or `--universal` to use a universal variable (default). +- ``-g`` or ``--global`` to use a global variable. +- ``-U`` or ``--universal`` to use a universal variable (default). See the "Internals" section for more on them. @@ -48,7 +48,7 @@ Examples abbr -a -g gco git checkout -Add a new abbreviation where `gco` will be replaced with `git checkout` global to the current shell. This abbreviation will not be automatically visible to other shells unless the same command is run in those shells (such as when executing the commands in config.fish). +Add a new abbreviation where ``gco`` will be replaced with ``git checkout`` global to the current shell. This abbreviation will not be automatically visible to other shells unless the same command is run in those shells (such as when executing the commands in config.fish). @@ -56,7 +56,7 @@ Add a new abbreviation where `gco` will be replaced with `git checkout` global t abbr -a -U l less -Add a new abbreviation where `l` will be replaced with `less` universal so all shells. Note that you omit the `-U` since it is the default. +Add a new abbreviation where ``l`` will be replaced with ``less`` universal so all shells. Note that you omit the ``-U`` since it is the default. @@ -64,7 +64,7 @@ Add a new abbreviation where `l` will be replaced with `less` universal so all s abbr -r gco gch -Renames an existing abbreviation from `gco` to `gch`. +Renames an existing abbreviation from ``gco`` to ``gch``. @@ -72,7 +72,7 @@ Renames an existing abbreviation from `gco` to `gch`. abbr -e gco -Erase the `gco` abbreviation. +Erase the ``gco`` abbreviation. @@ -84,9 +84,9 @@ Import the abbreviations defined on another_host over SSH. Internals ------------ -Each abbreviation is stored in its own global or universal variable. The name consists of the prefix `_fish_abbr_` followed by the WORD after being transformed by `string escape style=var`. The WORD cannot contain a space but all other characters are legal. +Each abbreviation is stored in its own global or universal variable. The name consists of the prefix ``_fish_abbr_`` followed by the WORD after being transformed by ``string escape style=var``. The WORD cannot contain a space but all other characters are legal. -Defining an abbreviation with global scope is slightly faster than universal scope (which is the default). But in general you'll only want to use the global scope when defining abbreviations in a startup script like `~/.config/fish/config.fish` like this: +Defining an abbreviation with global scope is slightly faster than universal scope (which is the default). But in general you'll only want to use the global scope when defining abbreviations in a startup script like ``~/.config/fish/config.fish`` like this: @@ -100,4 +100,4 @@ Defining an abbreviation with global scope is slightly faster than universal sco end -You can create abbreviations interactively and they will be visible to other fish sessions if you use the `-U` or `--universal` flag or don't explicitly specify the scope and the abbreviation isn't already defined with global scope. If you want it to be visible only to the current shell use the `-g` or `--global` flag. +You can create abbreviations interactively and they will be visible to other fish sessions if you use the ``-U`` or ``--universal`` flag or don't explicitly specify the scope and the abbreviation isn't already defined with global scope. If you want it to be visible only to the current shell use the ``-g`` or ``--global`` flag. diff --git a/sphinx_doc_src/cmds/alias.rst b/sphinx_doc_src/cmds/alias.rst index 73ff79784..39cad912f 100644 --- a/sphinx_doc_src/cmds/alias.rst +++ b/sphinx_doc_src/cmds/alias.rst @@ -12,25 +12,25 @@ alias [OPTIONS] NAME=DEFINITION Description ------------ -`alias` is a simple wrapper for the `function` builtin, which creates a function wrapping a command. It has similar syntax to POSIX shell `alias`. For other uses, it is recommended to define a function. +``alias`` is a simple wrapper for the ``function`` builtin, which creates a function wrapping a command. It has similar syntax to POSIX shell ``alias``. For other uses, it is recommended to define a function. -`fish` marks functions that have been created by `alias` by including the command used to create them in the function description. You can list `alias`-created functions by running `alias` without arguments. They must be erased using `functions -e`. +``fish`` marks functions that have been created by ``alias`` by including the command used to create them in the function description. You can list ``alias``-created functions by running ``alias`` without arguments. They must be erased using ``functions -e``. -- `NAME` is the name of the alias -- `DEFINITION` is the actual command to execute. The string `$argv` will be appended. +- ``NAME`` is the name of the alias +- ``DEFINITION`` is the actual command to execute. The string ``$argv`` will be appended. -You cannot create an alias to a function with the same name. Note that spaces need to be escaped in the call to `alias` just like at the command line, _even inside quoted parts_. +You cannot create an alias to a function with the same name. Note that spaces need to be escaped in the call to ``alias`` just like at the command line, _even inside quoted parts_. The following options are available: -- `-h` or `--help` displays help about using this command. +- ``-h`` or ``--help`` displays help about using this command. -- `-s` or `--save` Automatically save the function created by the alias into your fish configuration directory using funcsave. +- ``-s`` or ``--save`` Automatically save the function created by the alias into your fish configuration directory using funcsave. Example ------------ -The following code will create `rmi`, which runs `rm` with additional arguments on every invocation. +The following code will create ``rmi``, which runs ``rm`` with additional arguments on every invocation. diff --git a/sphinx_doc_src/cmds/and.rst b/sphinx_doc_src/cmds/and.rst index fa28dd694..79ae303e1 100644 --- a/sphinx_doc_src/cmds/and.rst +++ b/sphinx_doc_src/cmds/and.rst @@ -10,16 +10,16 @@ COMMAND1; and COMMAND2 Description ------------ -`and` is used to execute a command if the previous command was successful (returned a status of 0). +``and`` is used to execute a command if the previous command was successful (returned a status of 0). -`and` statements may be used as part of the condition in an `if` or `while` block. See the documentation for `if` and `while` for examples. +``and`` statements may be used as part of the condition in an ``if`` or ``while`` block. See the documentation for ``if`` and ``while`` for examples. -`and` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. +``and`` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. Example ------------ -The following code runs the `make` command to build a program. If the build succeeds, `make`'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and `make clean` is run, which removes the files created by the build process. +The following code runs the ``make`` command to build a program. If the build succeeds, ``make``'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and ``make clean`` is run, which removes the files created by the build process. diff --git a/sphinx_doc_src/cmds/argparse.rst b/sphinx_doc_src/cmds/argparse.rst index 341727e37..3628a0a0e 100644 --- a/sphinx_doc_src/cmds/argparse.rst +++ b/sphinx_doc_src/cmds/argparse.rst @@ -10,35 +10,35 @@ argparse [OPTIONS] OPTION_SPEC... -- [ARG...] Description ------------ -This command makes it easy for fish scripts and functions to handle arguments in a manner 100% identical to how fish builtin commands handle their arguments. You pass a sequence of arguments that define the options recognized, followed by a literal `--`, then the arguments to be parsed (which might also include a literal `--`). More on this in the usage section below. +This command makes it easy for fish scripts and functions to handle arguments in a manner 100% identical to how fish builtin commands handle their arguments. You pass a sequence of arguments that define the options recognized, followed by a literal ``--``, then the arguments to be parsed (which might also include a literal ``--``). More on this in the usage section below. -Each OPTION_SPEC can be written in the domain specific language described below or created using the companion `fish_opt` command. All OPTION_SPECs must appear after any argparse flags and before the `--` that separates them from the arguments to be parsed. +Each OPTION_SPEC can be written in the domain specific language described below or created using the companion ``fish_opt`` command. All OPTION_SPECs must appear after any argparse flags and before the ``--`` that separates them from the arguments to be parsed. -Each option that is seen in the ARG list will result in a var name of the form `_flag_X`, where `X` is the short flag letter and the long flag name. The OPTION_SPEC always requires a short flag even if it can't be used. So there will always be `_flag_X` var set using the short flag letter if the corresponding short or long flag is seen. The long flag name var (e.g., `_flag_help`) will only be defined, obviously, if the OPTION_SPEC includes a long flag name. +Each option that is seen in the ARG list will result in a var name of the form ``_flag_X``, where ``X`` is the short flag letter and the long flag name. The OPTION_SPEC always requires a short flag even if it can't be used. So there will always be ``_flag_X`` var set using the short flag letter if the corresponding short or long flag is seen. The long flag name var (e.g., ``_flag_help``) will only be defined, obviously, if the OPTION_SPEC includes a long flag name. -For example `_flag_h` and `_flag_help` if `-h` or `--help` is seen. The var will be set with local scope (i.e., as if the script had done `set -l _flag_X`). If the flag is a boolean (that is, does not have an associated value) the values are the short and long flags seen. If the option is not a boolean flag the values will be zero or more values corresponding to the values collected when the ARG list is processed. If the flag was not seen the flag var will not be set. +For example ``_flag_h`` and ``_flag_help`` if ``-h`` or ``--help`` is seen. The var will be set with local scope (i.e., as if the script had done ``set -l _flag_X``). If the flag is a boolean (that is, does not have an associated value) the values are the short and long flags seen. If the option is not a boolean flag the values will be zero or more values corresponding to the values collected when the ARG list is processed. If the flag was not seen the flag var will not be set. Options ------------ -The following `argparse` options are available. They must appear before all OPTION_SPECs: +The following ``argparse`` options are available. They must appear before all OPTION_SPECs: -- `-n` or `--name` is the command name to insert into any error messages. If you don't provide this value `argparse` will be used. +- ``-n`` or ``--name`` is the command name to insert into any error messages. If you don't provide this value ``argparse`` will be used. -- `-x` or `--exclusive` should be followed by a comma separated list of short of long options that are mutually exclusive. You can use this option more than once to define multiple sets of mutually exclusive options. +- ``-x`` or ``--exclusive`` should be followed by a comma separated list of short of long options that are mutually exclusive. You can use this option more than once to define multiple sets of mutually exclusive options. -- `-N` or `--min-args` is followed by an integer that defines the minimum number of acceptable non-option arguments. The default is zero. +- ``-N`` or ``--min-args`` is followed by an integer that defines the minimum number of acceptable non-option arguments. The default is zero. -- `-X` or `--max-args` is followed by an integer that defines the maximum number of acceptable non-option arguments. The default is infinity. +- ``-X`` or ``--max-args`` is followed by an integer that defines the maximum number of acceptable non-option arguments. The default is infinity. -- `-s` or `--stop-nonopt` causes scanning the arguments to stop as soon as the first non-option argument is seen. Using this arg is equivalent to calling the C function `getopt_long()` with the short options starting with a `+` symbol. This is sometimes known as "POSIXLY CORRECT". If this flag is not used then arguments are reordered (i.e., permuted) so that all non-option arguments are moved after option arguments. This mode has several uses but the main one is to implement a command that has subcommands. +- ``-s`` or ``--stop-nonopt`` causes scanning the arguments to stop as soon as the first non-option argument is seen. Using this arg is equivalent to calling the C function ``getopt_long()`` with the short options starting with a ``+`` symbol. This is sometimes known as "POSIXLY CORRECT". If this flag is not used then arguments are reordered (i.e., permuted) so that all non-option arguments are moved after option arguments. This mode has several uses but the main one is to implement a command that has subcommands. -- `-h` or `--help` displays help about using this command. +- ``-h`` or ``--help`` displays help about using this command. Usage ------------ -Using this command involves passing two sets of arguments separated by `--`. The first set consists of one or more option specifications (`OPTION_SPEC` above) and options that modify the behavior of `argparse`. These must be listed before the `--` argument. The second set are the arguments to be parsed in accordance with the option specifications. They occur after the `--` argument and can be empty. More about this below but here is a simple example that might be used in a function named `my_function`: +Using this command involves passing two sets of arguments separated by ``--``. The first set consists of one or more option specifications (``OPTION_SPEC`` above) and options that modify the behavior of ``argparse``. These must be listed before the ``--`` argument. The second set are the arguments to be parsed in accordance with the option specifications. They occur after the ``--`` argument and can be empty. More about this below but here is a simple example that might be used in a function named ``my_function``: @@ -48,9 +48,9 @@ Using this command involves passing two sets of arguments separated by `--`. The or return -If `$argv` is empty then there is nothing to parse and `argparse` returns zero to indicate success. If `$argv` is not empty then it is checked for flags `-h`, `--help`, `-n` and `--name`. If they are found they are removed from the arguments and local variables (more on this below) are set so the script can determine which options were seen. Assuming `$argv` doesn't have any errors, such as a missing mandatory value for an option, then `argparse` exits with status zero. Otherwise it writes appropriate error messages to stderr and exits with a status of one. +If ``$argv`` is empty then there is nothing to parse and ``argparse`` returns zero to indicate success. If ``$argv`` is not empty then it is checked for flags ``-h``, ``--help``, ``-n`` and ``--name``. If they are found they are removed from the arguments and local variables (more on this below) are set so the script can determine which options were seen. Assuming ``$argv`` doesn't have any errors, such as a missing mandatory value for an option, then ``argparse`` exits with status zero. Otherwise it writes appropriate error messages to stderr and exits with a status of one. -The `--` argument is required. You do not have to include any arguments after the `--` but you must include the `--`. For example, this is acceptable: +The ``--`` argument is required. You do not have to include any arguments after the ``--`` but you must include the ``--``. For example, this is acceptable: @@ -70,80 +70,80 @@ But this is not: argparse 'h/help' 'n/name' $argv -The first `--` seen is what allows the `argparse` command to reliably separate the option specifications from the command arguments. +The first ``--`` seen is what allows the ``argparse`` command to reliably separate the option specifications from the command arguments. Option Specifications ------------ Each option specification is a string composed of -- A short flag letter (which is mandatory). It must be an alphanumeric or "#". The "#" character is special and means that a flag of the form `-123` is valid. The short flag "#" must be followed by "-" (since the short name isn't otherwise valid since `_flag_#` is not a valid var name) and must be followed by a long flag name with no modifiers. +- A short flag letter (which is mandatory). It must be an alphanumeric or "#". The "#" character is special and means that a flag of the form ``-123`` is valid. The short flag "#" must be followed by "-" (since the short name isn't otherwise valid since ``_flag_#`` is not a valid var name) and must be followed by a long flag name with no modifiers. -- A `/` if the short flag can be used by someone invoking your command else `-` if it should not be exposed as a valid short flag. If there is no long flag name these characters should be omitted. You can also specify a '#' to indicate the short and long flag names can be used and the value can be specified as an implicit int; i.e., a flag of the form `-NNN`. +- A ``/`` if the short flag can be used by someone invoking your command else ``-`` if it should not be exposed as a valid short flag. If there is no long flag name these characters should be omitted. You can also specify a '#' to indicate the short and long flag names can be used and the value can be specified as an implicit int; i.e., a flag of the form ``-NNN``. - A long flag name which is optional. If not present then only the short flag letter can be used. - Nothing if the flag is a boolean that takes no argument or is an implicit int flag, else -- `=` if it requires a value and only the last instance of the flag is saved, else +- ``=`` if it requires a value and only the last instance of the flag is saved, else -- `=?` it takes an optional value and only the last instance of the flag is saved, else +- ``=?`` it takes an optional value and only the last instance of the flag is saved, else -- `=+` if it requires a value and each instance of the flag is saved. +- ``=+`` if it requires a value and each instance of the flag is saved. -- Optionally a `!` followed by fish script to validate the value. Typically this will be a function to run. If the return status is zero the value for the flag is valid. If non-zero the value is invalid. Any error messages should be written to stdout (not stderr). See the section on Flag Value Validation for more information. +- Optionally a ``!`` followed by fish script to validate the value. Typically this will be a function to run. If the return status is zero the value for the flag is valid. If non-zero the value is invalid. Any error messages should be written to stdout (not stderr). See the section on Flag Value Validation for more information. -See the `fish_opt` command for a friendlier but more verbose way to create option specifications. +See the ``fish_opt`` command for a friendlier but more verbose way to create option specifications. In the following examples if a flag is not seen when parsing the arguments then the corresponding _flag_X var(s) will not be set. Flag Value Validation ------------ -It is common to want to validate the the value provided for an option satisfies some criteria. For example, that it is a valid integer within a specific range. You can always do this after `argparse` returns but you can also request that `argparse` perform the validation by executing arbitrary fish script. To do so simply append an `!` (exclamation-mark) then the fish script to be run. When that code is executed three vars will be defined: +It is common to want to validate the the value provided for an option satisfies some criteria. For example, that it is a valid integer within a specific range. You can always do this after ``argparse`` returns but you can also request that ``argparse`` perform the validation by executing arbitrary fish script. To do so simply append an ``!`` (exclamation-mark) then the fish script to be run. When that code is executed three vars will be defined: -- `_argparse_cmd` will be set to the value of the value of the `argparse --name` value. +- ``_argparse_cmd`` will be set to the value of the value of the ``argparse --name`` value. -- `_flag_name` will be set to the short or long flag that being processed. +- ``_flag_name`` will be set to the short or long flag that being processed. -- `_flag_value` will be set to the value associated with the flag being processed. +- ``_flag_value`` will be set to the value associated with the flag being processed. -If you do this via a function it should be defined with the `--no-scope-shadowing` flag. Otherwise it won't have access to those variables. +If you do this via a function it should be defined with the ``--no-scope-shadowing`` flag. Otherwise it won't have access to those variables. The script should write any error messages to stdout, not stderr. It should return a status of zero if the flag value is valid otherwise a non-zero status to indicate it is invalid. -Fish ships with a `_validate_int` function that accepts a `--min` and `--max` flag. Let's say your command accepts a `-m` or `--max` flag and the minimum allowable value is zero and the maximum is 5. You would define the option like this: `m/max=!_validate_int --min 0 --max 5`. The default if you just call `_validate_int` without those flags is to simply check that the value is a valid integer with no limits on the min or max value allowed. +Fish ships with a ``_validate_int`` function that accepts a ``--min`` and ``--max`` flag. Let's say your command accepts a ``-m`` or ``--max`` flag and the minimum allowable value is zero and the maximum is 5. You would define the option like this: ``m/max=!_validate_int --min 0 --max 5``. The default if you just call ``_validate_int`` without those flags is to simply check that the value is a valid integer with no limits on the min or max value allowed. Example OPTION_SPECs ------------ Some OPTION_SPEC examples: -- `h/help` means that both `-h` and `--help` are valid. The flag is a boolean and can be used more than once. If either flag is used then `_flag_h` and `_flag_help` will be set to the count of how many times either flag was seen. +- ``h/help`` means that both ``-h`` and ``--help`` are valid. The flag is a boolean and can be used more than once. If either flag is used then ``_flag_h`` and ``_flag_help`` will be set to the count of how many times either flag was seen. -- `h-help` means that only `--help` is valid. The flag is a boolean and can be used more than once. If the long flag is used then `_flag_h` and `_flag_help` will be set to the count of how many times the long flag was seen. +- ``h-help`` means that only ``--help`` is valid. The flag is a boolean and can be used more than once. If the long flag is used then ``_flag_h`` and ``_flag_help`` will be set to the count of how many times the long flag was seen. -- `n/name=` means that both `-n` and `--name` are valid. It requires a value and can be used at most once. If the flag is seen then `_flag_n` and `_flag_name` will be set with the single mandatory value associated with the flag. +- ``n/name=`` means that both ``-n`` and ``--name`` are valid. It requires a value and can be used at most once. If the flag is seen then ``_flag_n`` and ``_flag_name`` will be set with the single mandatory value associated with the flag. -- `n/name=?` means that both `-n` and `--name` are valid. It accepts an optional value and can be used at most once. If the flag is seen then `_flag_n` and `_flag_name` will be set with the value associated with the flag if one was provided else it will be set with no values. +- ``n/name=?`` means that both ``-n`` and ``--name`` are valid. It accepts an optional value and can be used at most once. If the flag is seen then ``_flag_n`` and ``_flag_name`` will be set with the value associated with the flag if one was provided else it will be set with no values. -- `n-name=+` means that only `--name` is valid. It requires a value and can be used more than once. If the flag is seen then `_flag_n` and `_flag_name` will be set with the values associated with each occurrence of the flag. +- ``n-name=+`` means that only ``--name`` is valid. It requires a value and can be used more than once. If the flag is seen then ``_flag_n`` and ``_flag_name`` will be set with the values associated with each occurrence of the flag. -- `x` means that only `-x` is valid. It is a boolean can can be used more than once. If it is seen then `_flag_x` will be set to the count of how many times the flag was seen. +- ``x`` means that only ``-x`` is valid. It is a boolean can can be used more than once. If it is seen then ``_flag_x`` will be set to the count of how many times the flag was seen. -- `x=`, `x=?`, and `x=+` are similar to the n/name examples above but there is no long flag alternative to the short flag `-x`. +- ``x=``, ``x=?``, and ``x=+`` are similar to the n/name examples above but there is no long flag alternative to the short flag ``-x``. -- `x-` is not valid since there is no long flag name and therefore the short flag, `-x`, has to be usable. +- ``x-`` is not valid since there is no long flag name and therefore the short flag, ``-x``, has to be usable. -- `#-max` means that flags matching the regex "^--?\d+$" are valid. When seen they are assigned to the variable `_flag_max`. This allows any valid positive or negative integer to be specified by prefixing it with a single "-". Many commands support this idiom. For example `head -3 /a/file` to emit only the first three lines of /a/file. +- ``#-max`` means that flags matching the regex "^--?\d+$" are valid. When seen they are assigned to the variable ``_flag_max``. This allows any valid positive or negative integer to be specified by prefixing it with a single "-". Many commands support this idiom. For example ``head -3 /a/file`` to emit only the first three lines of /a/file. -- `n#max` means that flags matching the regex "^--?\d+$" are valid. When seen they are assigned to the variables `_flag_n` and `_flag_max`. This allows any valid positive or negative integer to be specified by prefixing it with a single "-". Many commands support this idiom. For example `head -3 /a/file` to emit only the first three lines of /a/file. You can also specify the value using either flag: `-n NNN` or `--max NNN` in this example. +- ``n#max`` means that flags matching the regex "^--?\d+$" are valid. When seen they are assigned to the variables ``_flag_n`` and ``_flag_max``. This allows any valid positive or negative integer to be specified by prefixing it with a single "-". Many commands support this idiom. For example ``head -3 /a/file`` to emit only the first three lines of /a/file. You can also specify the value using either flag: ``-n NNN`` or ``--max NNN`` in this example. -After parsing the arguments the `argv` var is set with local scope to any values not already consumed during flag processing. If there are not unbound values the var is set but `count $argv` will be zero. +After parsing the arguments the ``argv`` var is set with local scope to any values not already consumed during flag processing. If there are not unbound values the var is set but ``count $argv`` will be zero. If an error occurs during argparse processing it will exit with a non-zero status and print error messages to stderr. Notes ------------ -Prior to the addition of this builtin command in the 2.7.0 release there were two main ways to parse the arguments passed to a fish script or function. One way was to use the OS provided `getopt` command. The problem with that is that the GNU and BSD implementations are not compatible. Which makes using that external command difficult other than in trivial situations. The other way is to iterate over `$argv` and use the fish `switch` statement to decide how to handle the argument. That, however, involves a huge amount of boilerplate code. It is also borderline impossible to implement the same behavior as builtin commands. +Prior to the addition of this builtin command in the 2.7.0 release there were two main ways to parse the arguments passed to a fish script or function. One way was to use the OS provided ``getopt`` command. The problem with that is that the GNU and BSD implementations are not compatible. Which makes using that external command difficult other than in trivial situations. The other way is to iterate over ``$argv`` and use the fish ``switch`` statement to decide how to handle the argument. That, however, involves a huge amount of boilerplate code. It is also borderline impossible to implement the same behavior as builtin commands. diff --git a/sphinx_doc_src/cmds/begin.rst b/sphinx_doc_src/cmds/begin.rst index 2d24381b9..a9b626f98 100644 --- a/sphinx_doc_src/cmds/begin.rst +++ b/sphinx_doc_src/cmds/begin.rst @@ -10,13 +10,13 @@ begin; [COMMANDS...;] end Description ------------ -`begin` is used to create a new block of code. +``begin`` is used to create a new block of code. -A block allows the introduction of a new variable scope, redirection of the input or output of a set of commands as a group, or to specify precedence when using the conditional commands like `and`. +A block allows the introduction of a new variable scope, redirection of the input or output of a set of commands as a group, or to specify precedence when using the conditional commands like ``and``. -The block is unconditionally executed. `begin; ...; end` is equivalent to `if true; ...; end`. +The block is unconditionally executed. ``begin; ...; end`` is equivalent to ``if true; ...; end``. -`begin` does not change the current exit status itself. After the block has completed, `$status` will be set to the status returned by the most recent command. +``begin`` does not change the current exit status itself. After the block has completed, ``$status`` will be set to the status returned by the most recent command. Example diff --git a/sphinx_doc_src/cmds/bg.rst b/sphinx_doc_src/cmds/bg.rst index 866dbaa4c..7db38aa7f 100644 --- a/sphinx_doc_src/cmds/bg.rst +++ b/sphinx_doc_src/cmds/bg.rst @@ -10,20 +10,20 @@ bg [PID...] Description ------------ -`bg` sends jobs to the background, resuming them if they are stopped. +``bg`` sends jobs to the background, resuming them if they are stopped. A background job is executed simultaneously with fish, and does not have access to the keyboard. If no job is specified, the last job to be used is put in the background. If PID is specified, the jobs with the specified process group IDs are put in the background. When at least one of the arguments isn't a valid job specifier (i.e. PID), -`bg` will print an error without backgrounding anything. +``bg`` will print an error without backgrounding anything. When all arguments are valid job specifiers, bg will background all matching jobs that exist. Example ------------ -`bg 123 456 789` will background 123, 456 and 789. +``bg 123 456 789`` will background 123, 456 and 789. If only 123 and 789 exist, it will still background them and print an error about 456. -`bg 123 banana` or `bg banana 123` will complain that "banana" is not a valid job specifier. +``bg 123 banana`` or ``bg banana 123`` will complain that "banana" is not a valid job specifier. diff --git a/sphinx_doc_src/cmds/bind.rst b/sphinx_doc_src/cmds/bind.rst index cf2feebe7..dacf10cfd 100644 --- a/sphinx_doc_src/cmds/bind.rst +++ b/sphinx_doc_src/cmds/bind.rst @@ -19,131 +19,131 @@ bind (-e | --erase) [(-M | --mode) MODE] Description ------------ -`bind` adds a binding for the specified key sequence to the specified command. +``bind`` adds a binding for the specified key sequence to the specified command. -SEQUENCE is the character sequence to bind to. These should be written as fish escape sequences. For example, because pressing the Alt key and another character sends that character prefixed with an escape character, Alt-based key bindings can be written using the `\e` escape. For example, @key{Alt,w} can be written as `\ew`. The control character can be written in much the same way using the `\c` escape, for example @key{Control,X} (^X) can be written as `\cx`. Note that Alt-based key bindings are case sensitive and Control-based key bindings are not. This is a constraint of text-based terminals, not `fish`. +SEQUENCE is the character sequence to bind to. These should be written as fish escape sequences. For example, because pressing the Alt key and another character sends that character prefixed with an escape character, Alt-based key bindings can be written using the ``\e`` escape. For example, @key{Alt,w} can be written as ``\ew``. The control character can be written in much the same way using the ``\c`` escape, for example @key{Control,X} (^X) can be written as ``\cx``. Note that Alt-based key bindings are case sensitive and Control-based key bindings are not. This is a constraint of text-based terminals, not ``fish``. -The default key binding can be set by specifying a `SEQUENCE` of the empty string (that is, ```''``` ). It will be used whenever no other binding matches. For most key bindings, it makes sense to use the `self-insert` function (i.e. ```bind '' self-insert```) as the default keybinding. This will insert any keystrokes not specifically bound to into the editor. Non- printable characters are ignored by the editor, so this will not result in control sequences being printable. +The default key binding can be set by specifying a ``SEQUENCE`` of the empty string (that is, ``''`` ). It will be used whenever no other binding matches. For most key bindings, it makes sense to use the ``self-insert`` function (i.e. ``````bind '' self-insert``````) as the default keybinding. This will insert any keystrokes not specifically bound to into the editor. Non- printable characters are ignored by the editor, so this will not result in control sequences being printable. -If the `-k` switch is used, the name of the key (such as 'down', 'up' or 'backspace') is used instead of a sequence. The names used are the same as the corresponding curses variables, but without the 'key_' prefix. (See `terminfo(5)` for more information, or use `bind --key-names` for a list of all available named keys.) If used in conjunction with the `-s` switch, `bind` will silently ignore bindings to named keys that are not found in termcap for the current `$TERMINAL`, otherwise a warning is emitted. +If the ``-k`` switch is used, the name of the key (such as 'down', 'up' or 'backspace') is used instead of a sequence. The names used are the same as the corresponding curses variables, but without the 'key_' prefix. (See ``terminfo(5)`` for more information, or use ``bind --key-names`` for a list of all available named keys.) If used in conjunction with the ``-s`` switch, ``bind`` will silently ignore bindings to named keys that are not found in termcap for the current ``$TERMINAL``, otherwise a warning is emitted. -`COMMAND` can be any fish command, but it can also be one of a set of special input functions. These include functions for moving the cursor, operating on the kill-ring, performing tab completion, etc. Use `bind --function-names` for a complete list of these input functions. +``COMMAND`` can be any fish command, but it can also be one of a set of special input functions. These include functions for moving the cursor, operating on the kill-ring, performing tab completion, etc. Use ``bind --function-names`` for a complete list of these input functions. -When `COMMAND` is a shellscript command, it is a good practice to put the actual code into a function and simply bind to the function name. This way it becomes significantly easier to test the function while editing, and the result is usually more readable as well. +When ``COMMAND`` is a shellscript command, it is a good practice to put the actual code into a function and simply bind to the function name. This way it becomes significantly easier to test the function while editing, and the result is usually more readable as well. -If a script produces output, it should finish by calling `commandline -f repaint` to tell fish that a repaint is in order. +If a script produces output, it should finish by calling ``commandline -f repaint`` to tell fish that a repaint is in order. -When multiple `COMMAND`s are provided, they are all run in the specified order when the key is pressed. Note that special input functions cannot be combined with ordinary shell script commands. The commands must be entirely a sequence of special input functions (from `bind -f`) or all shell script commands (i.e., valid fish script). +When multiple ``COMMAND``s are provided, they are all run in the specified order when the key is pressed. Note that special input functions cannot be combined with ordinary shell script commands. The commands must be entirely a sequence of special input functions (from ``bind -f``) or all shell script commands (i.e., valid fish script). -If no `SEQUENCE` is provided, all bindings (or just the bindings in the specified `MODE`) are printed. If `SEQUENCE` is provided without `COMMAND`, just the binding matching that sequence is printed. +If no ``SEQUENCE`` is provided, all bindings (or just the bindings in the specified ``MODE``) are printed. If ``SEQUENCE`` is provided without ``COMMAND``, just the binding matching that sequence is printed. -To save custom keybindings, put the `bind` statements into config.fish. Alternatively, fish also automatically executes a function called `fish_user_key_bindings` if it exists. +To save custom keybindings, put the ``bind`` statements into config.fish. Alternatively, fish also automatically executes a function called ``fish_user_key_bindings`` if it exists. -Key bindings may use "modes", which mimics Vi's modal input behavior. The default mode is "default", and every bind applies to a single mode. The mode can be viewed/changed with the `$fish_bind_mode` variable. +Key bindings may use "modes", which mimics Vi's modal input behavior. The default mode is "default", and every bind applies to a single mode. The mode can be viewed/changed with the ``$fish_bind_mode`` variable. The following parameters are available: -- `-k` or `--key` Specify a key name, such as 'left' or 'backspace' instead of a character sequence +- ``-k`` or ``--key`` Specify a key name, such as 'left' or 'backspace' instead of a character sequence -- `-K` or `--key-names` Display a list of available key names. Specifying `-a` or `--all` includes keys that don't have a known mapping +- ``-K`` or ``--key-names`` Display a list of available key names. Specifying ``-a`` or ``--all`` includes keys that don't have a known mapping -- `-f` or `--function-names` Display a list of available input functions +- ``-f`` or ``--function-names`` Display a list of available input functions -- `-L` or `--list-modes` Display a list of defined bind modes +- ``-L`` or ``--list-modes`` Display a list of defined bind modes -- `-M MODE` or `--mode MODE` Specify a bind mode that the bind is used in. Defaults to "default" +- ``-M MODE`` or ``--mode MODE`` Specify a bind mode that the bind is used in. Defaults to "default" -- `-m NEW_MODE` or `--sets-mode NEW_MODE` Change the current mode to `NEW_MODE` after this binding is executed +- ``-m NEW_MODE`` or ``--sets-mode NEW_MODE`` Change the current mode to ``NEW_MODE`` after this binding is executed -- `-e` or `--erase` Erase the binding with the given sequence and mode instead of defining a new one. Multiple sequences can be specified with this flag. Specifying `-a` or `--all` with `-M` or `--mode` erases all binds in the given mode regardless of sequence. Specifying `-a` or `--all` without `-M` or `--mode` erases all binds in all modes regardless of sequence. +- ``-e`` or ``--erase`` Erase the binding with the given sequence and mode instead of defining a new one. Multiple sequences can be specified with this flag. Specifying ``-a`` or ``--all`` with ``-M`` or ``--mode`` erases all binds in the given mode regardless of sequence. Specifying ``-a`` or ``--all`` without ``-M`` or ``--mode`` erases all binds in all modes regardless of sequence. -- `-a` or `--all` See `--erase` and `--key-names` +- ``-a`` or ``--all`` See ``--erase`` and ``--key-names`` -- `--preset` and `--user` specify if bind should operate on user or preset bindings. User bindings take precedence over preset bindings when fish looks up mappings. By default, all `bind` invocations work on the "user" level except for listing, which will show both levels. All invocations except for inserting new bindings can operate on both levels at the same time. `--preset` should only be used in full binding sets (like when working on `fish_vi_key_bindings`). +- ``--preset`` and ``--user`` specify if bind should operate on user or preset bindings. User bindings take precedence over preset bindings when fish looks up mappings. By default, all ``bind`` invocations work on the "user" level except for listing, which will show both levels. All invocations except for inserting new bindings can operate on both levels at the same time. ``--preset`` should only be used in full binding sets (like when working on ``fish_vi_key_bindings``). Special input functions ------------ The following special input functions are available: -- `accept-autosuggestion`, accept the current autosuggestion completely +- ``accept-autosuggestion``, accept the current autosuggestion completely -- `backward-char`, moves one character to the left +- ``backward-char``, moves one character to the left -- `backward-bigword`, move one whitespace-delimited word to the left +- ``backward-bigword``, move one whitespace-delimited word to the left -- `backward-delete-char`, deletes one character of input to the left of the cursor +- ``backward-delete-char``, deletes one character of input to the left of the cursor -- `backward-kill-bigword`, move the whitespace-delimited word to the left of the cursor to the killring +- ``backward-kill-bigword``, move the whitespace-delimited word to the left of the cursor to the killring -- `backward-kill-line`, move everything from the beginning of the line to the cursor to the killring +- ``backward-kill-line``, move everything from the beginning of the line to the cursor to the killring -- `backward-kill-path-component`, move one path component to the left of the cursor (everything from the last "/" or whitespace exclusive) to the killring +- ``backward-kill-path-component``, move one path component to the left of the cursor (everything from the last "/" or whitespace exclusive) to the killring -- `backward-kill-word`, move the word to the left of the cursor to the killring +- ``backward-kill-word``, move the word to the left of the cursor to the killring -- `backward-word`, move one word to the left +- ``backward-word``, move one word to the left -- `beginning-of-buffer`, moves to the beginning of the buffer, i.e. the start of the first line +- ``beginning-of-buffer``, moves to the beginning of the buffer, i.e. the start of the first line -- `beginning-of-history`, move to the beginning of the history +- ``beginning-of-history``, move to the beginning of the history -- `beginning-of-line`, move to the beginning of the line +- ``beginning-of-line``, move to the beginning of the line -- `begin-selection`, start selecting text +- ``begin-selection``, start selecting text -- `capitalize-word`, make the current word begin with a capital letter +- ``capitalize-word``, make the current word begin with a capital letter -- `complete`, guess the remainder of the current token +- ``complete``, guess the remainder of the current token -- `complete-and-search`, invoke the searchable pager on completion options (for convenience, this also moves backwards in the completion pager) +- ``complete-and-search``, invoke the searchable pager on completion options (for convenience, this also moves backwards in the completion pager) -- `delete-char`, delete one character to the right of the cursor +- ``delete-char``, delete one character to the right of the cursor -- `downcase-word`, make the current word lowercase +- ``downcase-word``, make the current word lowercase -- `end-of-buffer`, moves to the end of the buffer, i.e. the end of the first line +- ``end-of-buffer``, moves to the end of the buffer, i.e. the end of the first line -- `end-of-history`, move to the end of the history +- ``end-of-history``, move to the end of the history -- `end-of-line`, move to the end of the line +- ``end-of-line``, move to the end of the line -- `end-selection`, end selecting text +- ``end-selection``, end selecting text -- `forward-bigword`, move one whitespace-delimited word to the right +- ``forward-bigword``, move one whitespace-delimited word to the right -- `forward-char`, move one character to the right +- ``forward-char``, move one character to the right -- `forward-word`, move one word to the right +- ``forward-word``, move one word to the right -- `history-search-backward`, search the history for the previous match +- ``history-search-backward``, search the history for the previous match -- `history-search-forward`, search the history for the next match +- ``history-search-forward``, search the history for the next match -- `kill-bigword`, move the next whitespace-delimited word to the killring +- ``kill-bigword``, move the next whitespace-delimited word to the killring -- `kill-line`, move everything from the cursor to the end of the line to the killring +- ``kill-line``, move everything from the cursor to the end of the line to the killring -- `kill-selection`, move the selected text to the killring +- ``kill-selection``, move the selected text to the killring -- `kill-whole-line`, move the line to the killring +- ``kill-whole-line``, move the line to the killring -- `kill-word`, move the next word to the killring +- ``kill-word``, move the next word to the killring -- `pager-toggle-search`, toggles the search field if the completions pager is visible. +- ``pager-toggle-search``, toggles the search field if the completions pager is visible. -- `suppress-autosuggestion`, remove the current autosuggestion +- ``suppress-autosuggestion``, remove the current autosuggestion -- `swap-selection-start-stop`, go to the other end of the highlighted text without changing the selection +- ``swap-selection-start-stop``, go to the other end of the highlighted text without changing the selection -- `transpose-chars`, transpose two characters to the left of the cursor +- ``transpose-chars``, transpose two characters to the left of the cursor -- `transpose-words`, transpose two words to the left of the cursor +- ``transpose-words``, transpose two words to the left of the cursor -- `upcase-word`, make the current word uppercase +- ``upcase-word``, make the current word uppercase -- `yank`, insert the latest entry of the killring into the buffer +- ``yank``, insert the latest entry of the killring into the buffer -- `yank-pop`, rotate to the previous entry of the killring +- ``yank-pop``, rotate to the previous entry of the killring Examples @@ -155,7 +155,7 @@ Examples bind \\cd 'exit' -Causes `fish` to exit when @key{Control,D} is pressed. +Causes ``fish`` to exit when @key{Control,D} is pressed. @@ -180,6 +180,6 @@ Special Case: The escape Character The escape key can be used standalone, for example, to switch from insertion mode to normal mode when using Vi keybindings. Escape may also be used as a "meta" key, to indicate the start of an escape sequence, such as function or arrow keys. Custom bindings can also be defined that begin with an escape character. -fish waits for a period after receiving the escape character, to determine whether it is standalone or part of an escape sequence. While waiting, additional key presses make the escape key behave as a meta key. If no other key presses come in, it is handled as a standalone escape. The waiting period is set to 300 milliseconds (0.3 seconds) in the default key bindings and 10 milliseconds in the vi key bindings. It can be configured by setting the `fish_escape_delay_ms` variable to a value between 10 and 5000 ms. It is recommended that this be a universal variable that you set once from an interactive session. +fish waits for a period after receiving the escape character, to determine whether it is standalone or part of an escape sequence. While waiting, additional key presses make the escape key behave as a meta key. If no other key presses come in, it is handled as a standalone escape. The waiting period is set to 300 milliseconds (0.3 seconds) in the default key bindings and 10 milliseconds in the vi key bindings. It can be configured by setting the ``fish_escape_delay_ms`` variable to a value between 10 and 5000 ms. It is recommended that this be a universal variable that you set once from an interactive session. Note: fish 2.2.0 and earlier used a default of 10 milliseconds, and provided no way to configure it. That effectively made it impossible to use escape as a meta key. diff --git a/sphinx_doc_src/cmds/block.rst b/sphinx_doc_src/cmds/block.rst index 35efdd625..acd7e7c37 100644 --- a/sphinx_doc_src/cmds/block.rst +++ b/sphinx_doc_src/cmds/block.rst @@ -10,21 +10,21 @@ block [OPTIONS...] Description ------------ -`block` prevents events triggered by `fish` or the `emit` command from being delivered and acted upon while the block is in place. +``block`` prevents events triggered by ``fish`` or the ``emit`` command from being delivered and acted upon while the block is in place. -In functions, `block` can be useful while performing work that should not be interrupted by the shell. +In functions, ``block`` can be useful while performing work that should not be interrupted by the shell. The block can be removed. Any events which triggered while the block was in place will then be delivered. -Event blocks should not be confused with code blocks, which are created with `begin`, `if`, `while` or `for` +Event blocks should not be confused with code blocks, which are created with ``begin``, ``if``, ``while`` or ``for`` The following parameters are available: -- `-l` or `--local` Release the block automatically at the end of the current innermost code block scope +- ``-l`` or ``--local`` Release the block automatically at the end of the current innermost code block scope -- `-g` or `--global` Never automatically release the lock +- ``-g`` or ``--global`` Never automatically release the lock -- `-e` or `--erase` Release global block +- ``-e`` or ``--erase`` Release global block Example diff --git a/sphinx_doc_src/cmds/break.rst b/sphinx_doc_src/cmds/break.rst index 6ee7f9573..9251df0b6 100644 --- a/sphinx_doc_src/cmds/break.rst +++ b/sphinx_doc_src/cmds/break.rst @@ -10,9 +10,9 @@ LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] end Description ------------ -`break` halts a currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. +``break`` halts a currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. -There are no parameters for `break`. +There are no parameters for ``break``. Example diff --git a/sphinx_doc_src/cmds/breakpoint.rst b/sphinx_doc_src/cmds/breakpoint.rst index 81d951ce0..4db33f5ee 100644 --- a/sphinx_doc_src/cmds/breakpoint.rst +++ b/sphinx_doc_src/cmds/breakpoint.rst @@ -10,8 +10,8 @@ breakpoint Description ------------ -`breakpoint` is used to halt a running script and launch an interactive debugging prompt. +``breakpoint`` is used to halt a running script and launch an interactive debugging prompt. -For more details, see Debugging fish scripts in the `fish` manual. +For more details, see Debugging fish scripts in the ``fish`` manual. -There are no parameters for `breakpoint`. +There are no parameters for ``breakpoint``. diff --git a/sphinx_doc_src/cmds/builtin.rst b/sphinx_doc_src/cmds/builtin.rst index 71de7ed19..48d413a59 100644 --- a/sphinx_doc_src/cmds/builtin.rst +++ b/sphinx_doc_src/cmds/builtin.rst @@ -10,11 +10,11 @@ builtin BUILTINNAME [OPTIONS...] Description ------------ -`builtin` forces the shell to use a builtin command, rather than a function or program. +``builtin`` forces the shell to use a builtin command, rather than a function or program. The following parameters are available: -- `-n` or `--names` List the names of all defined builtins +- ``-n`` or ``--names`` List the names of all defined builtins Example diff --git a/sphinx_doc_src/cmds/case.rst b/sphinx_doc_src/cmds/case.rst index bc0fe08dd..2ed89819e 100644 --- a/sphinx_doc_src/cmds/case.rst +++ b/sphinx_doc_src/cmds/case.rst @@ -10,9 +10,9 @@ switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end Description ------------ -`switch` executes one of several blocks of commands, depending on whether a specified value matches one of several values. `case` is used together with the `switch` statement in order to determine which block should be executed. +``switch`` executes one of several blocks of commands, depending on whether a specified value matches one of several values. ``case`` is used together with the ``switch`` statement in order to determine which block should be executed. -Each `case` command is given one or more parameters. The first `case` command with a parameter that matches the string specified in the switch command will be evaluated. `case` parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames. +Each ``case`` command is given one or more parameters. The first ``case`` command with a parameter that matches the string specified in the switch command will be evaluated. ``case`` parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames. Note that fish does not fall through on case statements. Only the first matching case is executed. @@ -43,7 +43,7 @@ Say \$animal contains the name of an animal. Then this code would classify it: end -If the above code was run with `$animal` set to `whale`, the output -would be `mammal`. +If the above code was run with ``$animal`` set to ``whale``, the output +would be ``mammal``. -If `$animal` was set to "banana", it would print "I have no idea what a banana is". +If ``$animal`` was set to "banana", it would print "I have no idea what a banana is". diff --git a/sphinx_doc_src/cmds/cd.rst b/sphinx_doc_src/cmds/cd.rst index 1e8b45191..0707d40a3 100644 --- a/sphinx_doc_src/cmds/cd.rst +++ b/sphinx_doc_src/cmds/cd.rst @@ -9,17 +9,17 @@ cd [DIRECTORY] Description ------------ -`cd` changes the current working directory. +``cd`` changes the current working directory. -If `DIRECTORY` is supplied, it will become the new directory. If no parameter is given, the contents of the `HOME` environment variable will be used. +If ``DIRECTORY`` is supplied, it will become the new directory. If no parameter is given, the contents of the ``HOME`` environment variable will be used. -If `DIRECTORY` is a relative path, the paths found in the `CDPATH` environment variable array will be tried as prefixes for the specified path. +If ``DIRECTORY`` is a relative path, the paths found in the ``CDPATH`` environment variable array will be tried as prefixes for the specified path. -Note that the shell will attempt to change directory without requiring `cd` if the name of a directory is provided (starting with `.`, `/` or `~`, or ending with `/`). +Note that the shell will attempt to change directory without requiring ``cd`` if the name of a directory is provided (starting with ``.``, ``/`` or ``~``, or ending with ``/``). -Fish also ships a wrapper function around the builtin `cd` that understands `cd -` as changing to the previous directory. See also `prevd`. This wrapper function maintains a history of the 25 most recently visited directories in the `$dirprev` and `$dirnext` global variables. If you make those universal variables your `cd` history is shared among all fish instances. +Fish also ships a wrapper function around the builtin ``cd`` that understands ``cd -`` as changing to the previous directory. See also ``prevd``. This wrapper function maintains a history of the 25 most recently visited directories in the ``$dirprev`` and ``$dirnext`` global variables. If you make those universal variables your ``cd`` history is shared among all fish instances. -As a special case, `cd .` is equivalent to `cd $PWD`, which is useful in cases where a mountpoint has been recycled or a directory has been removed and recreated. +As a special case, ``cd .`` is equivalent to ``cd $PWD``, which is useful in cases where a mountpoint has been recycled or a directory has been removed and recreated. Examples ------------ @@ -38,4 +38,4 @@ Examples See Also ------------ -See also the `cdh` command for changing to a recently visited directory. +See also the ``cdh`` command for changing to a recently visited directory. diff --git a/sphinx_doc_src/cmds/cdh.rst b/sphinx_doc_src/cmds/cdh.rst index 8ef8bb8b8..60b58fe46 100644 --- a/sphinx_doc_src/cmds/cdh.rst +++ b/sphinx_doc_src/cmds/cdh.rst @@ -11,11 +11,11 @@ cdh [ directory ] Description ------------ -`cdh` with no arguments presents a list of recently visited directories. You can then select one of the entries by letter or number. You can also press @key{tab} to use the completion pager to select an item from the list. If you give it a single argument it is equivalent to `cd directory`. +``cdh`` with no arguments presents a list of recently visited directories. You can then select one of the entries by letter or number. You can also press @key{tab} to use the completion pager to select an item from the list. If you give it a single argument it is equivalent to ``cd directory``. -Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables which this command manipulates. If you make those universal variables your `cd` history is shared among all fish instances. +Note that the ``cd`` command limits directory history to the 25 most recently visited directories. The history is stored in the ``$dirprev`` and ``$dirnext`` variables which this command manipulates. If you make those universal variables your ``cd`` history is shared among all fish instances. See Also ------------ -See also the `prevd` and `pushd` commands which also work with the recent `cd` history and are provided for compatibility with other shells. +See also the ``prevd`` and ``pushd`` commands which also work with the recent ``cd`` history and are provided for compatibility with other shells. diff --git a/sphinx_doc_src/cmds/command.rst b/sphinx_doc_src/cmds/command.rst index c77b653b3..b72f79b34 100644 --- a/sphinx_doc_src/cmds/command.rst +++ b/sphinx_doc_src/cmds/command.rst @@ -10,25 +10,25 @@ command [OPTIONS] COMMANDNAME [ARGS...] Description ------------ -`command` forces the shell to execute the program `COMMANDNAME` and ignore any functions or builtins with the same name. +``command`` forces the shell to execute the program ``COMMANDNAME`` and ignore any functions or builtins with the same name. The following options are available: -- `-a` or `--all` returns all the external commands that are found in `$PATH` in the order they are found. +- ``-a`` or ``--all`` returns all the external commands that are found in ``$PATH`` in the order they are found. -- `-q` or `--quiet`, in conjunction with `-s`, silences the output and prints nothing, setting only the exit code. +- ``-q`` or ``--quiet``, in conjunction with ``-s``, silences the output and prints nothing, setting only the exit code. -- `-s` or `--search` returns the name of the external command that would be executed, or nothing if no file with the specified name could be found in the `$PATH`. +- ``-s`` or ``--search`` returns the name of the external command that would be executed, or nothing if no file with the specified name could be found in the ``$PATH``. -With the `-s` option, `command` treats every argument as a separate command to look up and sets the exit status to 0 if any of the specified commands were found, or 1 if no commands could be found. Additionally passing a `-q` or `--quiet` option prevents any paths from being printed, like `type -q`, for testing only the exit status. +With the ``-s`` option, ``command`` treats every argument as a separate command to look up and sets the exit status to 0 if any of the specified commands were found, or 1 if no commands could be found. Additionally passing a ``-q`` or ``--quiet`` option prevents any paths from being printed, like ``type -q``, for testing only the exit status. -For basic compatibility with POSIX `command`, the `-v` flag is recognized as an alias for `-s`. +For basic compatibility with POSIX ``command``, the ``-v`` flag is recognized as an alias for ``-s``. Examples ------------ -`command ls` causes fish to execute the `ls` program, even if an `ls` function exists. +``command ls`` causes fish to execute the ``ls`` program, even if an ``ls`` function exists. -`command -s ls` returns the path to the `ls` program. +``command -s ls`` returns the path to the ``ls`` program. -`command -sq git; and command git log` runs `git log` only if `git` exists. +``command -sq git; and command git log`` runs ``git log`` only if ``git`` exists. diff --git a/sphinx_doc_src/cmds/commandline.rst b/sphinx_doc_src/cmds/commandline.rst index 6026171db..d13dcac84 100644 --- a/sphinx_doc_src/cmds/commandline.rst +++ b/sphinx_doc_src/cmds/commandline.rst @@ -10,59 +10,59 @@ commandline [OPTIONS] [CMD] Description ------------ -`commandline` can be used to set or get the current contents of the command line buffer. +``commandline`` can be used to set or get the current contents of the command line buffer. -With no parameters, `commandline` returns the current value of the command line. +With no parameters, ``commandline`` returns the current value of the command line. -With `CMD` specified, the command line buffer is erased and replaced with the contents of `CMD`. +With ``CMD`` specified, the command line buffer is erased and replaced with the contents of ``CMD``. The following options are available: -- `-C` or `--cursor` set or get the current cursor position, not the contents of the buffer. If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position. +- ``-C`` or ``--cursor`` set or get the current cursor position, not the contents of the buffer. If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position. -- `-f` or `--function` inject readline functions into the reader. This option cannot be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual key presses are read. +- ``-f`` or ``--function`` inject readline functions into the reader. This option cannot be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual key presses are read. -The following options change the way `commandline` updates the command line buffer: +The following options change the way ``commandline`` updates the command line buffer: -- `-a` or `--append` do not remove the current commandline, append the specified string at the end of it +- ``-a`` or ``--append`` do not remove the current commandline, append the specified string at the end of it -- `-i` or `--insert` do not remove the current commandline, insert the specified string at the current cursor position +- ``-i`` or ``--insert`` do not remove the current commandline, insert the specified string at the current cursor position -- `-r` or `--replace` remove the current commandline and replace it with the specified string (default) +- ``-r`` or ``--replace`` remove the current commandline and replace it with the specified string (default) The following options change what part of the commandline is printed or updated: -- `-b` or `--current-buffer` select the entire buffer, including any displayed autosuggestion (default) +- ``-b`` or ``--current-buffer`` select the entire buffer, including any displayed autosuggestion (default) -- `-j` or `--current-job` select the current job +- ``-j`` or ``--current-job`` select the current job -- `-p` or `--current-process` select the current process +- ``-p`` or ``--current-process`` select the current process -- `-s` or `--current-selection` selects the current selection +- ``-s`` or ``--current-selection`` selects the current selection -- `-t` or `--current-token` select the current token +- ``-t`` or ``--current-token`` select the current token -The following options change the way `commandline` prints the current commandline buffer: +The following options change the way ``commandline`` prints the current commandline buffer: -- `-c` or `--cut-at-cursor` only print selection up until the current cursor position +- ``-c`` or ``--cut-at-cursor`` only print selection up until the current cursor position -- `-o` or `--tokenize` tokenize the selection and print one string-type token per line +- ``-o`` or ``--tokenize`` tokenize the selection and print one string-type token per line -If `commandline` is called during a call to complete a given string using `complete -C STRING`, `commandline` will consider the specified string to be the current contents of the command line. +If ``commandline`` is called during a call to complete a given string using ``complete -C STRING``, ``commandline`` will consider the specified string to be the current contents of the command line. The following options output metadata about the commandline state: -- `-L` or `--line` print the line that the cursor is on, with the topmost line starting at 1 +- ``-L`` or ``--line`` print the line that the cursor is on, with the topmost line starting at 1 -- `-S` or `--search-mode` evaluates to true if the commandline is performing a history search +- ``-S`` or ``--search-mode`` evaluates to true if the commandline is performing a history search -- `-P` or `--paging-mode` evaluates to true if the commandline is showing pager contents, such as tab completions +- ``-P`` or ``--paging-mode`` evaluates to true if the commandline is showing pager contents, such as tab completions Example ------------ -`commandline -j $history[3]` replaces the job under the cursor with the third item from the command line history. +``commandline -j $history[3]`` replaces the job under the cursor with the third item from the command line history. If the commandline contains diff --git a/sphinx_doc_src/cmds/complete.rst b/sphinx_doc_src/cmds/complete.rst index a6884a9ae..6e4cf79e6 100644 --- a/sphinx_doc_src/cmds/complete.rst +++ b/sphinx_doc_src/cmds/complete.rst @@ -27,77 +27,77 @@ For an introduction to specifying completions, see Writing your own completions in the fish manual. -- `COMMAND` is the name of the command for which to add a completion. +- ``COMMAND`` is the name of the command for which to add a completion. -- `SHORT_OPTION` is a one character option for the command. +- ``SHORT_OPTION`` is a one character option for the command. -- `LONG_OPTION` is a multi character option for the command. +- ``LONG_OPTION`` is a multi character option for the command. -- `OPTION_ARGUMENTS` is parameter containing a space-separated list of possible option-arguments, which may contain command substitutions. +- ``OPTION_ARGUMENTS`` is parameter containing a space-separated list of possible option-arguments, which may contain command substitutions. -- `DESCRIPTION` is a description of what the option and/or option arguments do. +- ``DESCRIPTION`` is a description of what the option and/or option arguments do. -- `-c COMMAND` or `--command COMMAND` specifies that `COMMAND` is the name of the command. +- ``-c COMMAND`` or ``--command COMMAND`` specifies that ``COMMAND`` is the name of the command. -- `-p COMMAND` or `--path COMMAND` specifies that `COMMAND` is the absolute path of the program (optionally containing wildcards). +- ``-p COMMAND`` or ``--path COMMAND`` specifies that ``COMMAND`` is the absolute path of the program (optionally containing wildcards). -- `-e` or `--erase` deletes the specified completion. +- ``-e`` or ``--erase`` deletes the specified completion. -- `-s SHORT_OPTION` or `--short-option=SHORT_OPTION` adds a short option to the completions list. +- ``-s SHORT_OPTION`` or ``--short-option=SHORT_OPTION`` adds a short option to the completions list. -- `-l LONG_OPTION` or `--long-option=LONG_OPTION` adds a GNU style long option to the completions list. +- ``-l LONG_OPTION`` or ``--long-option=LONG_OPTION`` adds a GNU style long option to the completions list. -- `-o LONG_OPTION` or `--old-option=LONG_OPTION` adds an old style long option to the completions list (See below for details). +- ``-o LONG_OPTION`` or ``--old-option=LONG_OPTION`` adds an old style long option to the completions list (See below for details). -- `-a OPTION_ARGUMENTS` or `--arguments=OPTION_ARGUMENTS` adds the specified option arguments to the completions list. +- ``-a OPTION_ARGUMENTS`` or ``--arguments=OPTION_ARGUMENTS`` adds the specified option arguments to the completions list. -- `-k` or `--keep-order` preserves the order of the `OPTION_ARGUMENTS` specified via `-a` or `--arguments` instead of sorting alphabetically. +- ``-k`` or ``--keep-order`` preserves the order of the ``OPTION_ARGUMENTS`` specified via ``-a`` or ``--arguments`` instead of sorting alphabetically. -- `-f` or `--no-files` specifies that the options specified by this completion may not be followed by a filename. +- ``-f`` or ``--no-files`` specifies that the options specified by this completion may not be followed by a filename. -- `-r` or `--require-parameter` specifies that the options specified by this completion always must have an option argument, i.e. may not be followed by another option. +- ``-r`` or ``--require-parameter`` specifies that the options specified by this completion always must have an option argument, i.e. may not be followed by another option. -- `-x` or `--exclusive` implies both `-r` and `-f`. +- ``-x`` or ``--exclusive`` implies both ``-r`` and ``-f``. -- `-w WRAPPED_COMMAND` or `--wraps=WRAPPED_COMMAND` causes the specified command to inherit completions from the wrapped command (See below for details). +- ``-w WRAPPED_COMMAND`` or ``--wraps=WRAPPED_COMMAND`` causes the specified command to inherit completions from the wrapped command (See below for details). -- `-n` or `--condition` specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases. +- ``-n`` or ``--condition`` specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases. -- `-CSTRING` or `--do-complete=STRING` makes complete try to find all possible completions for the specified string. +- ``-CSTRING`` or ``--do-complete=STRING`` makes complete try to find all possible completions for the specified string. -- `-C` or `--do-complete` with no argument makes complete try to find all possible completions for the current command line buffer. If the shell is not in interactive mode, an error is returned. +- ``-C`` or ``--do-complete`` with no argument makes complete try to find all possible completions for the current command line buffer. If the shell is not in interactive mode, an error is returned. -- `-A` and `--authoritative` no longer do anything and are silently ignored. +- ``-A`` and ``--authoritative`` no longer do anything and are silently ignored. -- `-u` and `--unauthoritative` no longer do anything and are silently ignored. +- ``-u`` and ``--unauthoritative`` no longer do anything and are silently ignored. -Command specific tab-completions in `fish` are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '`-h`', '`-help`' or '`--help`'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are: +Command specific tab-completions in ``fish`` are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '``-h``', '``-help``' or '``--help``'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are: -- Short options, like '`-a`'. Short options are a single character long, are preceded by a single hyphen and may be grouped together (like '`-la`', which is equivalent to '`-l -a`'). Option arguments may be specified in the following parameter ('`-w 32`') or by appending the option with the value ('`-w32`'). +- Short options, like '``-a``'. Short options are a single character long, are preceded by a single hyphen and may be grouped together (like '``-la``', which is equivalent to '``-l -a``'). Option arguments may be specified in the following parameter ('``-w 32``') or by appending the option with the value ('``-w32``'). -- Old style long options, like '`-Wall`'. Old style long options can be more than one character long, are preceded by a single hyphen and may not be grouped together. Option arguments are specified in the following parameter ('`-ao null`'). +- Old style long options, like '``-Wall``'. Old style long options can be more than one character long, are preceded by a single hyphen and may not be grouped together. Option arguments are specified in the following parameter ('``-ao null``'). -- GNU style long options, like '`--colors`'. GNU style long options can be more than one character long, are preceded by two hyphens, and may not be grouped together. Option arguments may be specified in the following parameter ('`--quoting-style shell`') or by appending the option with a '`=`' and the value ('`--quoting-style=shell`'). GNU style long options may be abbreviated so long as the abbreviation is unique ('`--h`') is equivalent to '`--help`' if help is the only long option beginning with an 'h'). +- GNU style long options, like '``--colors``'. GNU style long options can be more than one character long, are preceded by two hyphens, and may not be grouped together. Option arguments may be specified in the following parameter ('``--quoting-style shell``') or by appending the option with a '``=``' and the value ('``--quoting-style=shell``'). GNU style long options may be abbreviated so long as the abbreviation is unique ('``--h``') is equivalent to '``--help``' if help is the only long option beginning with an 'h'). The options for specifying command name and command path may be used multiple times to define the same completions for multiple commands. The options for specifying command switches and wrapped commands may be used multiple times to define multiple completions for the command(s) in a single call. -Invoking `complete` multiple times for the same command adds the new definitions on top of any existing completions defined for the command. +Invoking ``complete`` multiple times for the same command adds the new definitions on top of any existing completions defined for the command. -When `-a` or `--arguments` is specified in conjunction with long, short, or old style options, the specified arguments are only used as completions when attempting to complete an argument for any of the specified options. If `-a` or `--arguments` is specified without any long, short, or old style options, the specified arguments are used when completing any argument to the command (except when completing an option argument that was specified with `-r` or `--require-parameter`). +When ``-a`` or ``--arguments`` is specified in conjunction with long, short, or old style options, the specified arguments are only used as completions when attempting to complete an argument for any of the specified options. If ``-a`` or ``--arguments`` is specified without any long, short, or old style options, the specified arguments are used when completing any argument to the command (except when completing an option argument that was specified with ``-r`` or ``--require-parameter``). -Command substitutions found in `OPTION_ARGUMENTS` are not expected to return a space-separated list of arguments. Instead they must return a newline-separated list of arguments, and each argument may optionally have a tab character followed by the argument description. Any description provided in this way overrides a description given with `-d` or `--description`. +Command substitutions found in ``OPTION_ARGUMENTS`` are not expected to return a space-separated list of arguments. Instead they must return a newline-separated list of arguments, and each argument may optionally have a tab character followed by the argument description. Any description provided in this way overrides a description given with ``-d`` or ``--description``. -The `-w` or `--wraps` options causes the specified command to inherit completions from another command. The inheriting command is said to "wrap" the inherited command. The wrapping command may have its own completions in addition to inherited ones. A command may wrap multiple commands, and wrapping is transitive: if A wraps B, and B wraps C, then A automatically inherits all of C's completions. Wrapping can be removed using the `-e` or `--erase` options. Note that wrapping only works for completions specified with `-c` or `--command` and are ignored when specifying completions with `-p` or `--path`. +The ``-w`` or ``--wraps`` options causes the specified command to inherit completions from another command. The inheriting command is said to "wrap" the inherited command. The wrapping command may have its own completions in addition to inherited ones. A command may wrap multiple commands, and wrapping is transitive: if A wraps B, and B wraps C, then A automatically inherits all of C's completions. Wrapping can be removed using the ``-e`` or ``--erase`` options. Note that wrapping only works for completions specified with ``-c`` or ``--command`` and are ignored when specifying completions with ``-p`` or ``--path``. -When erasing completions, it is possible to either erase all completions for a specific command by specifying `complete -c COMMAND -e`, or by specifying a specific completion option to delete by specifying either a long, short or old style option. +When erasing completions, it is possible to either erase all completions for a specific command by specifying ``complete -c COMMAND -e``, or by specifying a specific completion option to delete by specifying either a long, short or old style option. Example ------------ -The short style option `-o` for the `gcc` command requires that a file follows it. This can be done using writing: +The short style option ``-o`` for the ``gcc`` command requires that a file follows it. This can be done using writing: @@ -106,7 +106,7 @@ The short style option `-o` for the `gcc` command requires that a file follows i complete -c gcc -s o -r -The short style option `-d` for the `grep` command requires that one of the strings '`read`', '`skip`' or '`recurse`' is used. This can be specified writing: +The short style option ``-d`` for the ``grep`` command requires that one of the strings '``read``', '``skip``' or '``recurse``' is used. This can be specified writing: @@ -115,7 +115,7 @@ The short style option `-d` for the `grep` command requires that one of the stri complete -c grep -s d -x -a "read skip recurse" -The `su` command takes any username as an argument. Usernames are given as the first colon-separated field in the file /etc/passwd. This can be specified as: +The ``su`` command takes any username as an argument. Usernames are given as the first colon-separated field in the file /etc/passwd. This can be specified as: @@ -124,7 +124,7 @@ The `su` command takes any username as an argument. Usernames are given as the f complete -x -c su -d "Username" -a "(cat /etc/passwd | cut -d : -f 1)" -The `rpm` command has several different modes. If the `-e` or `--erase` flag has been specified, `rpm` should delete one or more packages, in which case several switches related to deleting packages are valid, like the `nodeps` switch. +The ``rpm`` command has several different modes. If the ``-e`` or ``--erase`` flag has been specified, ``rpm`` should delete one or more packages, in which case several switches related to deleting packages are valid, like the ``nodeps`` switch. This can be written as: @@ -135,9 +135,9 @@ This can be written as: complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d "Don't check dependencies" -where `__fish_contains_opt` is a function that checks the command line buffer for the presence of a specified set of options. +where ``__fish_contains_opt`` is a function that checks the command line buffer for the presence of a specified set of options. -To implement an alias, use the `-w` or `--wraps` option: +To implement an alias, use the ``-w`` or ``--wraps`` option: diff --git a/sphinx_doc_src/cmds/contains.rst b/sphinx_doc_src/cmds/contains.rst index 05316bef4..e5338c80c 100644 --- a/sphinx_doc_src/cmds/contains.rst +++ b/sphinx_doc_src/cmds/contains.rst @@ -10,13 +10,13 @@ contains [OPTIONS] KEY [VALUES...] Description ------------ -`contains` tests whether the set `VALUES` contains the string `KEY`. If so, `contains` exits with status 0; if not, it exits with status 1. +``contains`` tests whether the set ``VALUES`` contains the string ``KEY``. If so, ``contains`` exits with status 0; if not, it exits with status 1. The following options are available: -- `-i` or `--index` print the word index +- ``-i`` or ``--index`` print the word index -Note that, like GNU tools and most of fish's builtins, `contains` interprets all arguments starting with a `-` as options to contains, until it reaches an argument that is `--` (two dashes). See the examples below. +Note that, like GNU tools and most of fish's builtins, ``contains`` interprets all arguments starting with a ``-`` as options to contains, until it reaches an argument that is ``--`` (two dashes). See the examples below. Example ------------ @@ -45,7 +45,7 @@ This code will add some directories to $PATH if they aren't yet included: end -While this will check if `hasargs` was run with the `-q` option: +While this will check if ``hasargs`` was run with the ``-q`` option: @@ -58,4 +58,4 @@ While this will check if `hasargs` was run with the `-q` option: end -The `--` here stops `contains` from treating `-q` to an option to itself. Instead it treats it as a normal string to check. +The ``--`` here stops ``contains`` from treating ``-q`` to an option to itself. Instead it treats it as a normal string to check. diff --git a/sphinx_doc_src/cmds/continue.rst b/sphinx_doc_src/cmds/continue.rst index 95a4a3ec5..39cddf805 100644 --- a/sphinx_doc_src/cmds/continue.rst +++ b/sphinx_doc_src/cmds/continue.rst @@ -10,7 +10,7 @@ LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end Description ------------ -`continue` skips the remainder of the current iteration of the current inner loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. +``continue`` skips the remainder of the current iteration of the current inner loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. Example ------------ diff --git a/sphinx_doc_src/cmds/count.rst b/sphinx_doc_src/cmds/count.rst index 3047b9338..fe89b2261 100644 --- a/sphinx_doc_src/cmds/count.rst +++ b/sphinx_doc_src/cmds/count.rst @@ -10,11 +10,11 @@ count $VARIABLE Description ------------ -`count` prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains. +``count`` prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains. -`count` does not accept any options, not even `-h` or `--help`. +``count`` does not accept any options, not even ``-h`` or ``--help``. -`count` exits with a non-zero exit status if no arguments were passed to it, and with zero if at least one argument was passed. +``count`` exits with a non-zero exit status if no arguments were passed to it, and with zero if at least one argument was passed. Example diff --git a/sphinx_doc_src/cmds/dirh.rst b/sphinx_doc_src/cmds/dirh.rst index 61c0342c5..847c64df7 100644 --- a/sphinx_doc_src/cmds/dirh.rst +++ b/sphinx_doc_src/cmds/dirh.rst @@ -10,8 +10,8 @@ dirh Description ------------ -`dirh` prints the current directory history. The current position in the history is highlighted using the color defined in the `fish_color_history_current` environment variable. +``dirh`` prints the current directory history. The current position in the history is highlighted using the color defined in the ``fish_color_history_current`` environment variable. -`dirh` does not accept any parameters. +``dirh`` does not accept any parameters. -Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables. +Note that the ``cd`` command limits directory history to the 25 most recently visited directories. The history is stored in the ``$dirprev`` and ``$dirnext`` variables. diff --git a/sphinx_doc_src/cmds/dirs.rst b/sphinx_doc_src/cmds/dirs.rst index fba514c59..6dff26d1a 100644 --- a/sphinx_doc_src/cmds/dirs.rst +++ b/sphinx_doc_src/cmds/dirs.rst @@ -11,8 +11,8 @@ dirs -c Description ------------ -`dirs` prints the current directory stack, as created by the `pushd` command. +``dirs`` prints the current directory stack, as created by the ``pushd`` command. With "-c", it clears the directory stack instead. -`dirs` does not accept any parameters. +``dirs`` does not accept any parameters. diff --git a/sphinx_doc_src/cmds/disown.rst b/sphinx_doc_src/cmds/disown.rst index 07bd5a9da..701c62b3a 100644 --- a/sphinx_doc_src/cmds/disown.rst +++ b/sphinx_doc_src/cmds/disown.rst @@ -10,19 +10,19 @@ disown [ PID ... ] Description ------------ -`disown` removes the specified job from the list of jobs. The job itself continues to exist, but fish does not keep track of it any longer. +``disown`` removes the specified job from the list of jobs. The job itself continues to exist, but fish does not keep track of it any longer. -Jobs in the list of jobs are sent a hang-up signal when fish terminates, which usually causes the job to terminate; `disown` allows these processes to continue regardless. +Jobs in the list of jobs are sent a hang-up signal when fish terminates, which usually causes the job to terminate; ``disown`` allows these processes to continue regardless. -If no process is specified, the most recently-used job is removed (like `bg` and `fg`). If one or more `PID`s are specified, jobs with the specified process IDs are removed from the job list. Invalid jobs are ignored and a warning is printed. +If no process is specified, the most recently-used job is removed (like ``bg`` and ``fg``). If one or more ``PID``s are specified, jobs with the specified process IDs are removed from the job list. Invalid jobs are ignored and a warning is printed. -If a job is stopped, it is sent a signal to continue running, and a warning is printed. It is not possible to use the `bg` builtin to continue a job once it has been disowned. +If a job is stopped, it is sent a signal to continue running, and a warning is printed. It is not possible to use the ``bg`` builtin to continue a job once it has been disowned. -`disown` returns 0 if all specified jobs were disowned successfully, and 1 if any problems were encountered. +``disown`` returns 0 if all specified jobs were disowned successfully, and 1 if any problems were encountered. Example ------------ -`firefox &; disown` will start the Firefox web browser in the background and remove it from the job list, meaning it will not be closed when the fish process is closed. +``firefox &; disown`` will start the Firefox web browser in the background and remove it from the job list, meaning it will not be closed when the fish process is closed. -`disown (jobs -p)` removes all jobs from the job list without terminating them. +``disown (jobs -p)`` removes all jobs from the job list without terminating them. diff --git a/sphinx_doc_src/cmds/echo.rst b/sphinx_doc_src/cmds/echo.rst index 523848fe9..0d366296f 100644 --- a/sphinx_doc_src/cmds/echo.rst +++ b/sphinx_doc_src/cmds/echo.rst @@ -10,46 +10,46 @@ echo [OPTIONS] [STRING] Description ------------ -`echo` displays a string of text. +``echo`` displays a string of text. The following options are available: -- `-n`, Do not output a newline +- ``-n``, Do not output a newline -- `-s`, Do not separate arguments with spaces +- ``-s``, Do not separate arguments with spaces -- `-E`, Disable interpretation of backslash escapes (default) +- ``-E``, Disable interpretation of backslash escapes (default) -- `-e`, Enable interpretation of backslash escapes +- ``-e``, Enable interpretation of backslash escapes Escape Sequences ------------ -If `-e` is used, the following sequences are recognized: +If ``-e`` is used, the following sequences are recognized: -- `\` backslash +- ``\`` backslash -- `\a` alert (BEL) +- ``\a`` alert (BEL) -- `\b` backspace +- ``\b`` backspace -- `\c` produce no further output +- ``\c`` produce no further output -- `\e` escape +- ``\e`` escape -- `\f` form feed +- ``\f`` form feed -- `\n` new line +- ``\n`` new line -- `\r` carriage return +- ``\r`` carriage return -- `\t` horizontal tab +- ``\t`` horizontal tab -- `\v` vertical tab +- ``\v`` vertical tab -- `\0NNN` byte with octal value NNN (1 to 3 digits) +- ``\0NNN`` byte with octal value NNN (1 to 3 digits) -- `\xHH` byte with hexadecimal value HH (1 to 2 digits) +- ``\xHH`` byte with hexadecimal value HH (1 to 2 digits) Example ------------ diff --git a/sphinx_doc_src/cmds/else.rst b/sphinx_doc_src/cmds/else.rst index 6760295a7..8c8f0e1d6 100644 --- a/sphinx_doc_src/cmds/else.rst +++ b/sphinx_doc_src/cmds/else.rst @@ -10,13 +10,13 @@ if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end Description ------------ -`if` will execute the command `CONDITION`. If the condition's exit status is 0, the commands `COMMANDS_TRUE` will execute. If it is not 0 and `else` is given, `COMMANDS_FALSE` will be executed. +``if`` will execute the command ``CONDITION``. If the condition's exit status is 0, the commands ``COMMANDS_TRUE`` will execute. If it is not 0 and ``else`` is given, ``COMMANDS_FALSE`` will be executed. Example ------------ -The following code tests whether a file `foo.txt` exists as a regular file. +The following code tests whether a file ``foo.txt`` exists as a regular file. diff --git a/sphinx_doc_src/cmds/emit.rst b/sphinx_doc_src/cmds/emit.rst index 794049117..a4326eb51 100644 --- a/sphinx_doc_src/cmds/emit.rst +++ b/sphinx_doc_src/cmds/emit.rst @@ -10,7 +10,7 @@ emit EVENT_NAME [ARGUMENTS...] Description ------------ -`emit` emits, or fires, an event. Events are delivered to, or caught by, special functions called event handlers. The arguments are passed to the event handlers as function arguments. +``emit`` emits, or fires, an event. Events are delivered to, or caught by, special functions called event handlers. The arguments are passed to the event handlers as function arguments. Example diff --git a/sphinx_doc_src/cmds/end.rst b/sphinx_doc_src/cmds/end.rst index bae471a2f..3ed4d66b6 100644 --- a/sphinx_doc_src/cmds/end.rst +++ b/sphinx_doc_src/cmds/end.rst @@ -14,9 +14,9 @@ switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end Description ------------ -`end` ends a block of commands. +``end`` ends a block of commands. For more information, read the -documentation for the block constructs, such as `if`, `for` and `while`. +documentation for the block constructs, such as ``if``, ``for`` and ``while``. -The `end` command does not change the current exit status. Instead, the status after it will be the status returned by the most recent command. +The ``end`` command does not change the current exit status. Instead, the status after it will be the status returned by the most recent command. diff --git a/sphinx_doc_src/cmds/eval.rst b/sphinx_doc_src/cmds/eval.rst index 9611dd36a..bd76f9743 100644 --- a/sphinx_doc_src/cmds/eval.rst +++ b/sphinx_doc_src/cmds/eval.rst @@ -9,14 +9,14 @@ eval [COMMANDS...] Description ------------ -`eval` evaluates the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator. +``eval`` evaluates the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator. -If your command does not need access to stdin, consider using `source` instead. +If your command does not need access to stdin, consider using ``source`` instead. Example ------------ -The following code will call the ls command. Note that `fish` does not support the use of shell variables as direct commands; `eval` can be used to work around this. +The following code will call the ls command. Note that ``fish`` does not support the use of shell variables as direct commands; ``eval`` can be used to work around this. diff --git a/sphinx_doc_src/cmds/exec.rst b/sphinx_doc_src/cmds/exec.rst index 4c1637bce..e9b77c6e6 100644 --- a/sphinx_doc_src/cmds/exec.rst +++ b/sphinx_doc_src/cmds/exec.rst @@ -10,10 +10,10 @@ exec COMMAND [OPTIONS...] Description ------------ -`exec` replaces the currently running shell with a new command. On successful completion, `exec` never returns. `exec` cannot be used inside a pipeline. +``exec`` replaces the currently running shell with a new command. On successful completion, ``exec`` never returns. ``exec`` cannot be used inside a pipeline. Example ------------ -`exec emacs` starts up the emacs text editor, and exits `fish`. When emacs exits, the session will terminate. +``exec emacs`` starts up the emacs text editor, and exits ``fish``. When emacs exits, the session will terminate. diff --git a/sphinx_doc_src/cmds/exit.rst b/sphinx_doc_src/cmds/exit.rst index 497e69292..cd793b884 100644 --- a/sphinx_doc_src/cmds/exit.rst +++ b/sphinx_doc_src/cmds/exit.rst @@ -10,6 +10,6 @@ exit [STATUS] Description ------------ -`exit` causes fish to exit. If `STATUS` is supplied, it will be converted to an integer and used as the exit code. Otherwise, the exit code will be that of the last command executed. +``exit`` causes fish to exit. If ``STATUS`` is supplied, it will be converted to an integer and used as the exit code. Otherwise, the exit code will be that of the last command executed. If exit is called while sourcing a file (using the source builtin) the rest of the file will be skipped, but the shell itself will not exit. diff --git a/sphinx_doc_src/cmds/false.rst b/sphinx_doc_src/cmds/false.rst index 31645d0fc..47f526508 100644 --- a/sphinx_doc_src/cmds/false.rst +++ b/sphinx_doc_src/cmds/false.rst @@ -10,4 +10,4 @@ false Description ------------ -`false` sets the exit status to 1. +``false`` sets the exit status to 1. diff --git a/sphinx_doc_src/cmds/fg.rst b/sphinx_doc_src/cmds/fg.rst index 8ed9731ab..a1bb08b9f 100644 --- a/sphinx_doc_src/cmds/fg.rst +++ b/sphinx_doc_src/cmds/fg.rst @@ -10,10 +10,10 @@ fg [PID] Description ------------ -`fg` brings the specified job to the foreground, resuming it if it is stopped. While a foreground job is executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group ID is put in the foreground. +``fg`` brings the specified job to the foreground, resuming it if it is stopped. While a foreground job is executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group ID is put in the foreground. Example ------------ -`fg` will put the last job in the foreground. +``fg`` will put the last job in the foreground. diff --git a/sphinx_doc_src/cmds/fish.rst b/sphinx_doc_src/cmds/fish.rst index f3a36b941..1325818ef 100644 --- a/sphinx_doc_src/cmds/fish.rst +++ b/sphinx_doc_src/cmds/fish.rst @@ -10,28 +10,28 @@ fish [OPTIONS] [-c command] [FILE [ARGUMENTS...]] Description ------------ -`fish` is a command-line shell written mainly with interactive use in mind. The full manual is available in HTML by using the help command from inside fish. +``fish`` is a command-line shell written mainly with interactive use in mind. The full manual is available in HTML by using the help command from inside fish. The following options are available: -- `-c` or `--command=COMMANDS` evaluate the specified commands instead of reading from the commandline +- ``-c`` or ``--command=COMMANDS`` evaluate the specified commands instead of reading from the commandline -- `-C` or `--init-command=COMMANDS` evaluate the specified commands after reading the configuration, before running the command specified by `-c` or reading interactive input +- ``-C`` or ``--init-command=COMMANDS`` evaluate the specified commands after reading the configuration, before running the command specified by ``-c`` or reading interactive input -- `-d` or `--debug-level=DEBUG_LEVEL` specify the verbosity level of fish. A higher number means higher verbosity. The default level is 1. +- ``-d`` or ``--debug-level=DEBUG_LEVEL`` specify the verbosity level of fish. A higher number means higher verbosity. The default level is 1. -- `-i` or `--interactive` specify that fish is to run in interactive mode +- ``-i`` or ``--interactive`` specify that fish is to run in interactive mode -- `-l` or `--login` specify that fish is to run as a login shell +- ``-l`` or ``--login`` specify that fish is to run as a login shell -- `-n` or `--no-execute` do not execute any commands, only perform syntax checking +- ``-n`` or ``--no-execute`` do not execute any commands, only perform syntax checking -- `-p` or `--profile=PROFILE_FILE` when fish exits, output timing information on all executed commands to the specified file +- ``-p`` or ``--profile=PROFILE_FILE`` when fish exits, output timing information on all executed commands to the specified file -- `-v` or `--version` display version and exit +- ``-v`` or ``--version`` display version and exit -- `-D` or `--debug-stack-frames=DEBUG_LEVEL` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. +- ``-D`` or ``--debug-stack-frames=DEBUG_LEVEL`` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. -- `-f` or `--features=FEATURES` enables one or more feature flags (separated by a comma). These are how fish stages changes that might break scripts. +- ``-f`` or ``--features=FEATURES`` enables one or more feature flags (separated by a comma). These are how fish stages changes that might break scripts. The fish exit status is generally the exit status of the last foreground command. If fish is exiting because of a parse error, the exit status is 127. diff --git a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst index b8f6730ca..e8519b279 100644 --- a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst +++ b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst @@ -1,4 +1,4 @@ -fish_breakpoint_prompt - define the appearance of the command line prompt when in the context of a `breakpoint` command +fish_breakpoint_prompt - define the appearance of the command line prompt when in the context of a ``breakpoint`` command ========================================== Synopsis @@ -12,11 +12,11 @@ end Description ------------ -By defining the `fish_breakpoint_prompt` function, the user can choose a custom prompt when asking for input in response to a `breakpoint` command. The `fish_breakpoint_prompt` function is executed when the prompt is to be shown, and the output is used as a prompt. +By defining the ``fish_breakpoint_prompt`` function, the user can choose a custom prompt when asking for input in response to a ``breakpoint`` command. The ``fish_breakpoint_prompt`` function is executed when the prompt is to be shown, and the output is used as a prompt. -The exit status of commands within `fish_breakpoint_prompt` will not modify the value of $status outside of the `fish_breakpoint_prompt` function. +The exit status of commands within ``fish_breakpoint_prompt`` will not modify the value of $status outside of the ``fish_breakpoint_prompt`` function. -`fish` ships with a default version of this function that displays the function name and line number of the current execution context. +``fish`` ships with a default version of this function that displays the function name and line number of the current execution context. Example diff --git a/sphinx_doc_src/cmds/fish_config.rst b/sphinx_doc_src/cmds/fish_config.rst index 2bc16e4b7..c761479bb 100644 --- a/sphinx_doc_src/cmds/fish_config.rst +++ b/sphinx_doc_src/cmds/fish_config.rst @@ -5,18 +5,18 @@ fish_config - start the web-based configuration interface Description ------------ -`fish_config` starts the web-based configuration interface. +``fish_config`` starts the web-based configuration interface. The web interface allows you to view your functions, variables and history, and to make changes to your prompt and color configuration. -`fish_config` starts a local web server and then opens a web browser window; when you have finished, close the browser window and then press the Enter key to terminate the configuration session. +``fish_config`` starts a local web server and then opens a web browser window; when you have finished, close the browser window and then press the Enter key to terminate the configuration session. -`fish_config` optionally accepts name of the initial configuration tab. For e.g. `fish_config history` will start configuration interface with history tab. +``fish_config`` optionally accepts name of the initial configuration tab. For e.g. ``fish_config history`` will start configuration interface with history tab. -If the `BROWSER` environment variable is set, it will be used as the name of the web browser to open instead of the system default. +If the ``BROWSER`` environment variable is set, it will be used as the name of the web browser to open instead of the system default. Example ------------ -`fish_config` opens a new web browser window and allows you to configure certain fish settings. +``fish_config`` opens a new web browser window and allows you to configure certain fish settings. diff --git a/sphinx_doc_src/cmds/fish_indent.rst b/sphinx_doc_src/cmds/fish_indent.rst index 8c7f0a74b..10da3ee1d 100644 --- a/sphinx_doc_src/cmds/fish_indent.rst +++ b/sphinx_doc_src/cmds/fish_indent.rst @@ -10,22 +10,22 @@ fish_indent [OPTIONS] Description ------------ -`fish_indent` is used to indent a piece of fish code. `fish_indent` reads commands from standard input and outputs them to standard output or a specified file. +``fish_indent`` is used to indent a piece of fish code. ``fish_indent`` reads commands from standard input and outputs them to standard output or a specified file. The following options are available: -- `-w` or `--write` indents a specified file and immediately writes to that file. +- ``-w`` or ``--write`` indents a specified file and immediately writes to that file. -- `-i` or `--no-indent` do not indent commands; only reformat to one job per line. +- ``-i`` or ``--no-indent`` do not indent commands; only reformat to one job per line. -- `-v` or `--version` displays the current fish version and then exits. +- ``-v`` or ``--version`` displays the current fish version and then exits. -- `--ansi` colorizes the output using ANSI escape sequences, appropriate for the current $TERM, using the colors defined in the environment (such as `$fish_color_command`). +- ``--ansi`` colorizes the output using ANSI escape sequences, appropriate for the current $TERM, using the colors defined in the environment (such as ``$fish_color_command``). -- `--html` outputs HTML, which supports syntax highlighting if the appropriate CSS is defined. The CSS class names are the same as the variable names, such as `fish_color_command`. +- ``--html`` outputs HTML, which supports syntax highlighting if the appropriate CSS is defined. The CSS class names are the same as the variable names, such as ``fish_color_command``. -- `-d` or `--debug-level=DEBUG_LEVEL` enables debug output and specifies a verbosity level (like `fish -d`). Defaults to 0. +- ``-d`` or ``--debug-level=DEBUG_LEVEL`` enables debug output and specifies a verbosity level (like ``fish -d``). Defaults to 0. -- `-D` or `--debug-stack-frames=DEBUG_LEVEL` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. +- ``-D`` or ``--debug-stack-frames=DEBUG_LEVEL`` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. -- `--dump-parse-tree` dumps information about the parsed statements to stderr. This is likely to be of interest only to people working on the fish source code. +- ``--dump-parse-tree`` dumps information about the parsed statements to stderr. This is likely to be of interest only to people working on the fish source code. diff --git a/sphinx_doc_src/cmds/fish_key_reader.rst b/sphinx_doc_src/cmds/fish_key_reader.rst index 03199c37d..4290ec7b6 100644 --- a/sphinx_doc_src/cmds/fish_key_reader.rst +++ b/sphinx_doc_src/cmds/fish_key_reader.rst @@ -10,30 +10,30 @@ fish_key_reader [OPTIONS] Description ------------ -`fish_key_reader` is used to study input received from the terminal and can help with key binds. The program is interactive and works on standard input. Individual characters themselves and their hexadecimal values are displayed. +``fish_key_reader`` is used to study input received from the terminal and can help with key binds. The program is interactive and works on standard input. Individual characters themselves and their hexadecimal values are displayed. -The tool will write an example `bind` command matching the character sequence captured to stdout. If the character sequence matches a special key name (see `bind --key-names`), both `bind CHARS ...` and `bind -k KEYNAME ...` usage will be shown. Additional details about the characters received, such as the delay between chars, are written to stderr. +The tool will write an example ``bind`` command matching the character sequence captured to stdout. If the character sequence matches a special key name (see ``bind --key-names``), both ``bind CHARS ...`` and ``bind -k KEYNAME ...`` usage will be shown. Additional details about the characters received, such as the delay between chars, are written to stderr. The following options are available: -- `-c` or `--continuous` begins a session where multiple key sequences can be inspected. By default the program exits after capturing a single key sequence. +- ``-c`` or ``--continuous`` begins a session where multiple key sequences can be inspected. By default the program exits after capturing a single key sequence. -- `-d` or `--debug-level=DEBUG_LEVEL` enables debug output and specifies a verbosity level (like `fish -d`). Defaults to 0. +- ``-d`` or ``--debug-level=DEBUG_LEVEL`` enables debug output and specifies a verbosity level (like ``fish -d``). Defaults to 0. -- `-D` or `--debug-stack-frames=DEBUG_LEVEL` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. +- ``-D`` or ``--debug-stack-frames=DEBUG_LEVEL`` specify how many stack frames to display when debug messages are written. The default is zero. A value of 3 or 4 is usually sufficient to gain insight into how a given debug call was reached but you can specify a value up to 128. -- `-h` or `--help` prints usage information. +- ``-h`` or ``--help`` prints usage information. -- `-v` or `--version` prints fish_key_reader's version and exits. +- ``-v`` or ``--version`` prints fish_key_reader's version and exits. Usage Notes ------------ -The delay in milliseconds since the previous character was received is included in the diagnostic information written to stderr. This information may be useful to determine the optimal `fish_escape_delay_ms` setting or learn the amount of lag introduced by tools like `ssh`, `mosh` or `tmux`. +The delay in milliseconds since the previous character was received is included in the diagnostic information written to stderr. This information may be useful to determine the optimal ``fish_escape_delay_ms`` setting or learn the amount of lag introduced by tools like ``ssh``, ``mosh`` or ``tmux``. -`fish_key_reader` intentionally disables handling of many signals. To terminate `fish_key_reader` in `--continuous` mode do: +``fish_key_reader`` intentionally disables handling of many signals. To terminate ``fish_key_reader`` in ``--continuous`` mode do: -- press `Ctrl-C` twice, or -- press `Ctrl-D` twice, or -- type `exit`, or -- type `quit` +- press ``Ctrl-C`` twice, or +- press ``Ctrl-D`` twice, or +- type ``exit``, or +- type ``quit`` diff --git a/sphinx_doc_src/cmds/fish_mode_prompt.rst b/sphinx_doc_src/cmds/fish_mode_prompt.rst index 6eaa9a022..97d84da8f 100644 --- a/sphinx_doc_src/cmds/fish_mode_prompt.rst +++ b/sphinx_doc_src/cmds/fish_mode_prompt.rst @@ -8,8 +8,8 @@ The fish_mode_prompt function will output the mode indicator for use in vi-mode. Description ------------ -The default `fish_mode_prompt` function will output indicators about the current Vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. You can also define an empty `fish_mode_prompt` function to remove the Vi mode indicators. The `$fish_bind_mode variable` can be used to determine the current mode. It -will be one of `default`, `insert`, `replace_one`, or `visual`. +The default ``fish_mode_prompt`` function will output indicators about the current Vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. You can also define an empty ``fish_mode_prompt`` function to remove the Vi mode indicators. The ``$fish_bind_mode variable`` can be used to determine the current mode. It +will be one of ``default``, ``insert``, ``replace_one``, or ``visual``. Example ------------ @@ -40,4 +40,4 @@ Example end -Outputting multiple lines is not supported in `fish_mode_prompt`. +Outputting multiple lines is not supported in ``fish_mode_prompt``. diff --git a/sphinx_doc_src/cmds/fish_opt.rst b/sphinx_doc_src/cmds/fish_opt.rst index 8faf08120..a844fe330 100644 --- a/sphinx_doc_src/cmds/fish_opt.rst +++ b/sphinx_doc_src/cmds/fish_opt.rst @@ -12,23 +12,23 @@ fish_opt ( -s X | --short=X ) [ -l LONG | --long=LONG ] [ --long-only ] \ Description ------------ -This command provides a way to produce option specifications suitable for use with the `argparse` command. You can, of course, write the option specs by hand without using this command. But you might prefer to use this for the clarity it provides. +This command provides a way to produce option specifications suitable for use with the ``argparse`` command. You can, of course, write the option specs by hand without using this command. But you might prefer to use this for the clarity it provides. -The following `argparse` options are available: +The following ``argparse`` options are available: -- `-s` or `--short` takes a single letter that is used as the short flag in the option being defined. This option is mandatory. +- ``-s`` or ``--short`` takes a single letter that is used as the short flag in the option being defined. This option is mandatory. -- `-l` or `--long` takes a string that is used as the long flag in the option being defined. This option is optional and has no default. If no long flag is defined then only the short flag will be allowed when parsing arguments using the option spec. +- ``-l`` or ``--long`` takes a string that is used as the long flag in the option being defined. This option is optional and has no default. If no long flag is defined then only the short flag will be allowed when parsing arguments using the option spec. -- `--long-only` means the option spec being defined will only allow the long flag name to be used. The short flag name must still be defined (i.e., `--short` must be specified) but it cannot be used when parsing args using this option spec. +- ``--long-only`` means the option spec being defined will only allow the long flag name to be used. The short flag name must still be defined (i.e., ``--short`` must be specified) but it cannot be used when parsing args using this option spec. -- `-o` or `--optional` means the option being defined can take a value but it is optional rather than required. If the option is seen more than once when parsing arguments only the last value seen is saved. This means the resulting flag variable created by `argparse` will zero elements if no value was given with the option else it will have exactly one element. +- ``-o`` or ``--optional`` means the option being defined can take a value but it is optional rather than required. If the option is seen more than once when parsing arguments only the last value seen is saved. This means the resulting flag variable created by ``argparse`` will zero elements if no value was given with the option else it will have exactly one element. -- `-r` or `--required` means the option being defined requires a value. If the option is seen more than once when parsing arguments only the last value seen is saved. This means the resulting flag variable created by `argparse` will have exactly one element. +- ``-r`` or ``--required`` means the option being defined requires a value. If the option is seen more than once when parsing arguments only the last value seen is saved. This means the resulting flag variable created by ``argparse`` will have exactly one element. -- `--multiple-vals` means the option being defined requires a value each time it is seen. Each instance is stored. This means the resulting flag variable created by `argparse` will have one element for each instance of this option in the args. +- ``--multiple-vals`` means the option being defined requires a value each time it is seen. Each instance is stored. This means the resulting flag variable created by ``argparse`` will have one element for each instance of this option in the args. -- `-h` or `--help` displays help about using this command. +- ``-h`` or ``--help`` displays help about using this command. Examples ------------ @@ -54,7 +54,7 @@ Same as above but with a second flag that requires a value: argparse $options -- $argv -Same as above but with a third flag that can be given multiple times saving the value of each instance seen and only the long flag name (`--token`) can be used: +Same as above but with a third flag that can be given multiple times saving the value of each instance seen and only the long flag name (``--token``) can be used: diff --git a/sphinx_doc_src/cmds/fish_prompt.rst b/sphinx_doc_src/cmds/fish_prompt.rst index add5e7453..4e03fa28c 100644 --- a/sphinx_doc_src/cmds/fish_prompt.rst +++ b/sphinx_doc_src/cmds/fish_prompt.rst @@ -12,11 +12,11 @@ end Description ------------ -By defining the `fish_prompt` function, the user can choose a custom prompt. The `fish_prompt` function is executed when the prompt is to be shown, and the output is used as a prompt. +By defining the ``fish_prompt`` function, the user can choose a custom prompt. The ``fish_prompt`` function is executed when the prompt is to be shown, and the output is used as a prompt. -The exit status of commands within `fish_prompt` will not modify the value of $status outside of the `fish_prompt` function. +The exit status of commands within ``fish_prompt`` will not modify the value of $status outside of the ``fish_prompt`` function. -`fish` ships with a number of example prompts that can be chosen with the `fish_config` command. +``fish`` ships with a number of example prompts that can be chosen with the ``fish_config`` command. Example diff --git a/sphinx_doc_src/cmds/fish_right_prompt.rst b/sphinx_doc_src/cmds/fish_right_prompt.rst index e9069c1fc..701cb65ad 100644 --- a/sphinx_doc_src/cmds/fish_right_prompt.rst +++ b/sphinx_doc_src/cmds/fish_right_prompt.rst @@ -12,9 +12,9 @@ end Description ------------ -`fish_right_prompt` is similar to `fish_prompt`, except that it appears on the right side of the terminal window. +``fish_right_prompt`` is similar to ``fish_prompt``, except that it appears on the right side of the terminal window. -Multiple lines are not supported in `fish_right_prompt`. +Multiple lines are not supported in ``fish_right_prompt``. Example diff --git a/sphinx_doc_src/cmds/fish_update_completions.rst b/sphinx_doc_src/cmds/fish_update_completions.rst index d11279f5f..a1f5de530 100644 --- a/sphinx_doc_src/cmds/fish_update_completions.rst +++ b/sphinx_doc_src/cmds/fish_update_completions.rst @@ -5,8 +5,8 @@ fish_update_completions - Update completions using manual pages Description ------------ -`fish_update_completions` parses manual pages installed on the system, and attempts to create completion files in the `fish` configuration directory. +``fish_update_completions`` parses manual pages installed on the system, and attempts to create completion files in the ``fish`` configuration directory. This does not overwrite custom completions. -There are no parameters for `fish_update_completions`. +There are no parameters for ``fish_update_completions``. diff --git a/sphinx_doc_src/cmds/fish_vi_mode.rst b/sphinx_doc_src/cmds/fish_vi_mode.rst index fece6cb55..9a8e7ff73 100644 --- a/sphinx_doc_src/cmds/fish_vi_mode.rst +++ b/sphinx_doc_src/cmds/fish_vi_mode.rst @@ -10,6 +10,6 @@ fish_vi_mode Description ------------ -This function is deprecated. Please call `fish_vi_key_bindings directly` +This function is deprecated. Please call ``fish_vi_key_bindings directly`` -`fish_vi_mode` enters a vi-like command editing mode. To always start in vi mode, add `fish_vi_mode` to your `config.fish` file. +``fish_vi_mode`` enters a vi-like command editing mode. To always start in vi mode, add ``fish_vi_mode`` to your ``config.fish`` file. diff --git a/sphinx_doc_src/cmds/for.rst b/sphinx_doc_src/cmds/for.rst index 1b934f04e..e7881b114 100644 --- a/sphinx_doc_src/cmds/for.rst +++ b/sphinx_doc_src/cmds/for.rst @@ -10,7 +10,7 @@ for VARNAME in [VALUES...]; COMMANDS...; end Description ------------ -`for` is a loop construct. It will perform the commands specified by `COMMANDS` multiple times. On each iteration, the local variable specified by `VARNAME` is assigned a new value from `VALUES`. If `VALUES` is empty, `COMMANDS` will not be executed at all. The `VARNAME` is visible when the loop terminates and will contain the last value assigned to it. If `VARNAME` does not already exist it will be set in the local scope. For our purposes if the `for` block is inside a function there must be a local variable with the same name. If the `for` block is not nested inside a function then global and universal variables of the same name will be used if they exist. +``for`` is a loop construct. It will perform the commands specified by ``COMMANDS`` multiple times. On each iteration, the local variable specified by ``VARNAME`` is assigned a new value from ``VALUES``. If ``VALUES`` is empty, ``COMMANDS`` will not be executed at all. The ``VARNAME`` is visible when the loop terminates and will contain the last value assigned to it. If ``VARNAME`` does not already exist it will be set in the local scope. For our purposes if the ``for`` block is inside a function there must be a local variable with the same name. If the ``for`` block is not nested inside a function then global and universal variables of the same name will be used if they exist. Example ------------ @@ -30,7 +30,7 @@ Example Notes ------------ -The `VARNAME` was local to the for block in releases prior to 3.0.0. This means that if you did something like this: +The ``VARNAME`` was local to the for block in releases prior to 3.0.0. This means that if you did something like this: @@ -44,4 +44,4 @@ The `VARNAME` was local to the for block in releases prior to 3.0.0. This means echo $var -The last value assigned to `var` when the loop terminated would not be available outside the loop. What `echo $var` would write depended on what it was set to before the loop was run. Likely nothing. +The last value assigned to ``var`` when the loop terminated would not be available outside the loop. What ``echo $var`` would write depended on what it was set to before the loop was run. Likely nothing. diff --git a/sphinx_doc_src/cmds/funced.rst b/sphinx_doc_src/cmds/funced.rst index 40ad7ce0c..b554dcaad 100644 --- a/sphinx_doc_src/cmds/funced.rst +++ b/sphinx_doc_src/cmds/funced.rst @@ -10,14 +10,14 @@ funced [OPTIONS] NAME Description ------------ -`funced` provides an interface to edit the definition of the function `NAME`. +``funced`` provides an interface to edit the definition of the function ``NAME``. -If the `$VISUAL` environment variable is set, it will be used as the program to edit the function. If `$VISUAL` is unset but `$EDITOR` is set, that will be used. Otherwise, a built-in editor will be used. Note that to enter a literal newline using the built-in editor you should press @key{Alt,Enter}. Pressing @key{Enter} signals that you are done editing the function. This does not apply to an external editor like emacs or vim. +If the ``$VISUAL`` environment variable is set, it will be used as the program to edit the function. If ``$VISUAL`` is unset but ``$EDITOR`` is set, that will be used. Otherwise, a built-in editor will be used. Note that to enter a literal newline using the built-in editor you should press @key{Alt,Enter}. Pressing @key{Enter} signals that you are done editing the function. This does not apply to an external editor like emacs or vim. -If there is no function called `NAME` a new function will be created with the specified name +If there is no function called ``NAME`` a new function will be created with the specified name -- `-e command` or `--editor command` Open the function body inside the text editor given by the command (for example, `-e vi`). The special command `fish` will use the built-in editor (same as specifying `-i`). +- ``-e command`` or ``--editor command`` Open the function body inside the text editor given by the command (for example, ``-e vi``). The special command ``fish`` will use the built-in editor (same as specifying ``-i``). -- `-i` or `--interactive` Force opening the function body in the built-in editor even if `$VISUAL` or `$EDITOR` is defined. +- ``-i`` or ``--interactive`` Force opening the function body in the built-in editor even if ``$VISUAL`` or ``$EDITOR`` is defined. -- `-s` or `--save` Automatically save the function after successfully editing it. +- ``-s`` or ``--save`` Automatically save the function after successfully editing it. diff --git a/sphinx_doc_src/cmds/funcsave.rst b/sphinx_doc_src/cmds/funcsave.rst index 203851b81..53e46d31b 100644 --- a/sphinx_doc_src/cmds/funcsave.rst +++ b/sphinx_doc_src/cmds/funcsave.rst @@ -10,6 +10,6 @@ funcsave FUNCTION_NAME Description ------------ -`funcsave` saves the current definition of a function to a file in the fish configuration directory. This function will be automatically loaded by current and future fish sessions. This can be useful if you have interactively created a new function and wish to save it for later use. +``funcsave`` saves the current definition of a function to a file in the fish configuration directory. This function will be automatically loaded by current and future fish sessions. This can be useful if you have interactively created a new function and wish to save it for later use. -Note that because fish loads functions on-demand, saved functions will not function as event handlers until they are run or sourced otherwise. To activate an event handler for every new shell, add the function to your shell initialization file instead of using `funcsave`. +Note that because fish loads functions on-demand, saved functions will not function as event handlers until they are run or sourced otherwise. To activate an event handler for every new shell, add the function to your shell initialization file instead of using ``funcsave``. diff --git a/sphinx_doc_src/cmds/function.rst b/sphinx_doc_src/cmds/function.rst index 0d740d590..40e158941 100644 --- a/sphinx_doc_src/cmds/function.rst +++ b/sphinx_doc_src/cmds/function.rst @@ -10,52 +10,52 @@ function NAME [OPTIONS]; BODY; end Description ------------ -`function` creates a new function `NAME` with the body `BODY`. +``function`` creates a new function ``NAME`` with the body ``BODY``. A function is a list of commands that will be executed when the name of the function is given as a command. The following options are available: -- `-a NAMES` or `--argument-names NAMES` assigns the value of successive command-line arguments to the names given in NAMES. +- ``-a NAMES`` or ``--argument-names NAMES`` assigns the value of successive command-line arguments to the names given in NAMES. -- `-d DESCRIPTION` or `--description=DESCRIPTION` is a description of what the function does, suitable as a completion description. +- ``-d DESCRIPTION`` or ``--description=DESCRIPTION`` is a description of what the function does, suitable as a completion description. -- `-w WRAPPED_COMMAND` or `--wraps=WRAPPED_COMMAND` causes the function to inherit completions from the given wrapped command. See the documentation for `complete` for more information. +- ``-w WRAPPED_COMMAND`` or ``--wraps=WRAPPED_COMMAND`` causes the function to inherit completions from the given wrapped command. See the documentation for ``complete`` for more information. -- `-e` or `--on-event EVENT_NAME` tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt. +- ``-e`` or ``--on-event EVENT_NAME`` tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt. -- `-v` or `--on-variable VARIABLE_NAME` tells fish to run this function when the variable VARIABLE_NAME changes value. +- ``-v`` or ``--on-variable VARIABLE_NAME`` tells fish to run this function when the variable VARIABLE_NAME changes value. -- `-j PGID` or `--on-job-exit PGID` tells fish to run this function when the job with group ID PGID exits. Instead of PGID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution. +- ``-j PGID`` or ``--on-job-exit PGID`` tells fish to run this function when the job with group ID PGID exits. Instead of PGID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution. -- `-p PID` or `--on-process-exit PID` tells fish to run this function when the fish child process +- ``-p PID`` or ``--on-process-exit PID`` tells fish to run this function when the fish child process with process ID PID exits. Instead of a PID, for backward compatibility, - "`%self`" can be specified as an alias for `$fish_pid`, and the function will be run when the + "``%self``" can be specified as an alias for ``$fish_pid``, and the function will be run when the current fish instance exits. -- `-s` or `--on-signal SIGSPEC` tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP). +- ``-s`` or ``--on-signal SIGSPEC`` tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP). -- `-S` or `--no-scope-shadowing` allows the function to access the variables of calling functions. Normally, any variables inside the function that have the same name as variables from the calling function are "shadowed", and their contents is independent of the calling function. +- ``-S`` or ``--no-scope-shadowing`` allows the function to access the variables of calling functions. Normally, any variables inside the function that have the same name as variables from the calling function are "shadowed", and their contents is independent of the calling function. -- `-V` or `--inherit-variable NAME` snapshots the value of the variable `NAME` and defines a local variable with that same name and value when the function is defined. This is similar to a closure in other languages like Python but a bit different. Note the word "snapshot" in the first sentence. If you change the value of the variable after defining the function, even if you do so in the same scope (typically another function) the new value will not be used by the function you just created using this option. See the `function notify` example below for how this might be used. +- ``-V`` or ``--inherit-variable NAME`` snapshots the value of the variable ``NAME`` and defines a local variable with that same name and value when the function is defined. This is similar to a closure in other languages like Python but a bit different. Note the word "snapshot" in the first sentence. If you change the value of the variable after defining the function, even if you do so in the same scope (typically another function) the new value will not be used by the function you just created using this option. See the ``function notify`` example below for how this might be used. -If the user enters any additional arguments after the function, they are inserted into the environment variable array `$argv`. If the `--argument-names` option is provided, the arguments are also assigned to names specified in that option. +If the user enters any additional arguments after the function, they are inserted into the environment variable array ``$argv``. If the ``--argument-names`` option is provided, the arguments are also assigned to names specified in that option. By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the emit builtin. Fish generates the following named events: -- `fish_prompt`, which is emitted whenever a new fish prompt is about to be displayed. +- ``fish_prompt``, which is emitted whenever a new fish prompt is about to be displayed. -- `fish_command_not_found`, which is emitted whenever a command lookup failed. +- ``fish_command_not_found``, which is emitted whenever a command lookup failed. -- `fish_preexec`, which is emitted right before executing an interactive command. The commandline is passed as the first parameter. +- ``fish_preexec``, which is emitted right before executing an interactive command. The commandline is passed as the first parameter. Note: This event will be emitted even if the command is invalid. The commandline parameter includes the entire commandline verbatim, and may potentially include newlines. -- `fish_postexec`, which is emitted right after executing an interactive command. The commandline is passed as the first parameter. +- ``fish_postexec``, which is emitted right after executing an interactive command. The commandline is passed as the first parameter. Note: This event will be emitted even if the command is invalid. The commandline parameter includes the entire commandline verbatim, and may potentially include newlines. -- `fish_exit` is emitted right before fish exits. +- ``fish_exit`` is emitted right before fish exits. Example ------------ @@ -69,7 +69,7 @@ Example end -will run the `ls` command, using the `-l` option, while passing on any additional files and switches to `ls`. +will run the ``ls`` command, using the ``-l`` option, while passing on any additional files and switches to ``ls``. @@ -89,7 +89,7 @@ will run the `ls` command, using the `-l` option, while passing on any additiona end -This will run the `mkdir` command, and if it is successful, change the current working directory to the one just created. +This will run the ``mkdir`` command, and if it is successful, change the current working directory to the one just created. diff --git a/sphinx_doc_src/cmds/functions.rst b/sphinx_doc_src/cmds/functions.rst index f5820c595..e4675fece 100644 --- a/sphinx_doc_src/cmds/functions.rst +++ b/sphinx_doc_src/cmds/functions.rst @@ -14,49 +14,49 @@ functions [ -e | -q ] FUNCTIONS... Description ------------ -`functions` prints or erases functions. +``functions`` prints or erases functions. The following options are available: -- `-a` or `--all` lists all functions, even those whose name starts with an underscore. +- ``-a`` or ``--all`` lists all functions, even those whose name starts with an underscore. -- `-c OLDNAME NEWNAME` or `--copy OLDNAME NEWNAME` creates a new function named NEWNAME, using the definition of the OLDNAME function. +- ``-c OLDNAME NEWNAME`` or ``--copy OLDNAME NEWNAME`` creates a new function named NEWNAME, using the definition of the OLDNAME function. -- `-d DESCRIPTION` or `--description=DESCRIPTION` changes the description of this function. +- ``-d DESCRIPTION`` or ``--description=DESCRIPTION`` changes the description of this function. -- `-e` or `--erase` causes the specified functions to be erased. +- ``-e`` or ``--erase`` causes the specified functions to be erased. -- `-D` or `--details` reports the path name where each function is defined or could be autoloaded, `stdin` if the function was defined interactively or on the command line or by reading stdin, and `n/a` if the function isn't available. If the `--verbose` option is also specified then five lines are written: +- ``-D`` or ``--details`` reports the path name where each function is defined or could be autoloaded, ``stdin`` if the function was defined interactively or on the command line or by reading stdin, and ``n/a`` if the function isn't available. If the ``--verbose`` option is also specified then five lines are written: -# the pathname as already described, - -# `autoloaded`, `not-autoloaded` or `n/a`, + -# ``autoloaded``, ``not-autoloaded`` or ``n/a``, -# the line number within the file or zero if not applicable, - -# `scope-shadowing` if the function shadows the vars in the calling function (the normal case if it wasn't defined with `--no-scope-shadowing`), else `no-scope-shadowing`, or `n/a` if the function isn't defined, - -# the function description minimally escaped so it is a single line or `n/a` if the function isn't defined. + -# ``scope-shadowing`` if the function shadows the vars in the calling function (the normal case if it wasn't defined with ``--no-scope-shadowing``), else ``no-scope-shadowing``, or ``n/a`` if the function isn't defined, + -# the function description minimally escaped so it is a single line or ``n/a`` if the function isn't defined. You should not assume that only five lines will be written since we may add additional information to the output in the future. -- `-n` or `--names` lists the names of all defined functions. +- ``-n`` or ``--names`` lists the names of all defined functions. -- `-q` or `--query` tests if the specified functions exist. +- ``-q`` or ``--query`` tests if the specified functions exist. -- `-v` or `--verbose` will make some output more verbose. +- ``-v`` or ``--verbose`` will make some output more verbose. -- `-H` or `--handlers` will show all event handlers. +- ``-H`` or ``--handlers`` will show all event handlers. -- `-t` or `--handlers-type TYPE` will show all event handlers matching the given type +- ``-t`` or ``--handlers-type TYPE`` will show all event handlers matching the given type -The default behavior of `functions`, when called with no arguments, is to print the names of all defined functions. Unless the `-a` option is given, no functions starting with underscores are not included in the output. +The default behavior of ``functions``, when called with no arguments, is to print the names of all defined functions. Unless the ``-a`` option is given, no functions starting with underscores are not included in the output. If any non-option parameters are given, the definition of the specified functions are printed. -Automatically loaded functions cannot be removed using `functions -e`. Either remove the definition file or change the $fish_function_path variable to remove autoloaded functions. +Automatically loaded functions cannot be removed using ``functions -e``. Either remove the definition file or change the $fish_function_path variable to remove autoloaded functions. -Copying a function using `-c` copies only the body of the function, and does not attach any event notifications from the original function. +Copying a function using ``-c`` copies only the body of the function, and does not attach any event notifications from the original function. -Only one function's description can be changed in a single invocation of `functions -d`. +Only one function's description can be changed in a single invocation of ``functions -d``. -The exit status of `functions` is the number of functions specified in the argument list that do not exist, which can be used in concert with the `-q` option. +The exit status of ``functions`` is the number of functions specified in the argument list that do not exist, which can be used in concert with the ``-q`` option. Examples @@ -72,5 +72,5 @@ Examples # Copies the 'foo' function to a new function called 'bar' functions -e bar - # Erases the function `bar` + # Erases the function ``bar`` diff --git a/sphinx_doc_src/cmds/help.rst b/sphinx_doc_src/cmds/help.rst index ff42119a5..4ec33f9fd 100644 --- a/sphinx_doc_src/cmds/help.rst +++ b/sphinx_doc_src/cmds/help.rst @@ -10,18 +10,18 @@ help [SECTION] Description ------------ -`help` displays the fish help documentation. +``help`` displays the fish help documentation. -If a `SECTION` is specified, the help for that command is shown. +If a ``SECTION`` is specified, the help for that command is shown. If the BROWSER environment variable is set, it will be used to display the documentation. Otherwise, fish will search for a suitable browser. If you prefer to use a different browser (other than as described above) for fish help, you can set the fish_help_browser variable. This variable may be set as an array, where the first element is the browser command and the rest are browser options. -Note that most builtin commands display their help in the terminal when given the `--help` option. +Note that most builtin commands display their help in the terminal when given the ``--help`` option. Example ------------ -`help fg` shows the documentation for the `fg` builtin. +``help fg`` shows the documentation for the ``fg`` builtin. diff --git a/sphinx_doc_src/cmds/history.rst b/sphinx_doc_src/cmds/history.rst index 0b3701b30..9b36e6f19 100644 --- a/sphinx_doc_src/cmds/history.rst +++ b/sphinx_doc_src/cmds/history.rst @@ -15,41 +15,41 @@ history ( -h | --help ) Description ------------ -`history` is used to search, delete, and otherwise manipulate the history of interactive commands. +``history`` is used to search, delete, and otherwise manipulate the history of interactive commands. The following operations (sub-commands) are available: -- `search` returns history items matching the search string. If no search string is provided it returns all history items. This is the default operation if no other operation is specified. You only have to explicitly say `history search` if you wish to search for one of the subcommands. The `--contains` search option will be used if you don't specify a different search option. Entries are ordered newest to oldest unless you use the `--reverse` flag. If stdout is attached to a tty the output will be piped through your pager by the history function. The history builtin simply writes the results to stdout. +- ``search`` returns history items matching the search string. If no search string is provided it returns all history items. This is the default operation if no other operation is specified. You only have to explicitly say ``history search`` if you wish to search for one of the subcommands. The ``--contains`` search option will be used if you don't specify a different search option. Entries are ordered newest to oldest unless you use the ``--reverse`` flag. If stdout is attached to a tty the output will be piped through your pager by the history function. The history builtin simply writes the results to stdout. -- `delete` deletes history items. Without the `--prefix` or `--contains` options, the exact match of the specified text will be deleted. If you don't specify `--exact` a prompt will be displayed before any items are deleted asking you which entries are to be deleted. You can enter the word "all" to delete all matching entries. You can enter a single ID (the number in square brackets) to delete just that single entry. You can enter more than one ID separated by a space to delete multiple entries. Just press [enter] to not delete anything. Note that the interactive delete behavior is a feature of the history function. The history builtin only supports `--exact --case-sensitive` deletion. +- ``delete`` deletes history items. Without the ``--prefix`` or ``--contains`` options, the exact match of the specified text will be deleted. If you don't specify ``--exact`` a prompt will be displayed before any items are deleted asking you which entries are to be deleted. You can enter the word "all" to delete all matching entries. You can enter a single ID (the number in square brackets) to delete just that single entry. You can enter more than one ID separated by a space to delete multiple entries. Just press [enter] to not delete anything. Note that the interactive delete behavior is a feature of the history function. The history builtin only supports ``--exact --case-sensitive`` deletion. -- `merge` immediately incorporates history changes from other sessions. Ordinarily `fish` ignores history changes from sessions started after the current one. This command applies those changes immediately. +- ``merge`` immediately incorporates history changes from other sessions. Ordinarily ``fish`` ignores history changes from sessions started after the current one. This command applies those changes immediately. -- `save` immediately writes all changes to the history file. The shell automatically saves the history file; this option is provided for internal use and should not normally need to be used by the user. +- ``save`` immediately writes all changes to the history file. The shell automatically saves the history file; this option is provided for internal use and should not normally need to be used by the user. -- `clear` clears the history file. A prompt is displayed before the history is erased asking you to confirm you really want to clear all history unless `builtin history` is used. +- ``clear`` clears the history file. A prompt is displayed before the history is erased asking you to confirm you really want to clear all history unless ``builtin history`` is used. The following options are available: These flags can appear before or immediately after one of the sub-commands listed above. -- `-C` or `--case-sensitive` does a case-sensitive search. The default is case-insensitive. Note that prior to fish 2.4.0 the default was case-sensitive. +- ``-C`` or ``--case-sensitive`` does a case-sensitive search. The default is case-insensitive. Note that prior to fish 2.4.0 the default was case-sensitive. -- `-c` or `--contains` searches or deletes items in the history that contain the specified text string. This is the default for the `--search` flag. This is not currently supported by the `delete` subcommand. +- ``-c`` or ``--contains`` searches or deletes items in the history that contain the specified text string. This is the default for the ``--search`` flag. This is not currently supported by the ``delete`` subcommand. -- `-e` or `--exact` searches or deletes items in the history that exactly match the specified text string. This is the default for the `delete` subcommand. Note that the match is case-insensitive by default. If you really want an exact match, including letter case, you must use the `-C` or `--case-sensitive` flag. +- ``-e`` or ``--exact`` searches or deletes items in the history that exactly match the specified text string. This is the default for the ``delete`` subcommand. Note that the match is case-insensitive by default. If you really want an exact match, including letter case, you must use the ``-C`` or ``--case-sensitive`` flag. -- `-p` or `--prefix` searches or deletes items in the history that begin with the specified text string. This is not currently supported by the `--delete` flag. +- ``-p`` or ``--prefix`` searches or deletes items in the history that begin with the specified text string. This is not currently supported by the ``--delete`` flag. -- `-t` or `--show-time` prepends each history entry with the date and time the entry was recorded. By default it uses the strftime format `# %c%n`. You can specify another format; e.g., `--show-time="%Y-%m-%d %H:%M:%S "` or `--show-time="%a%I%p"`. The short option, `-t`, doesn't accept a strftime format string; it only uses the default format. Any strftime format is allowed, including `%s` to get the raw UNIX seconds since the epoch. +- ``-t`` or ``--show-time`` prepends each history entry with the date and time the entry was recorded. By default it uses the strftime format ``# %c%n``. You can specify another format; e.g., ``--show-time="%Y-%m-%d %H:%M:%S "`` or ``--show-time="%a%I%p"``. The short option, ``-t``, doesn't accept a strftime format string; it only uses the default format. Any strftime format is allowed, including ``%s`` to get the raw UNIX seconds since the epoch. -- `-z` or `--null` causes history entries written by the search operations to be terminated by a NUL character rather than a newline. This allows the output to be processed by `read -z` to correctly handle multiline history entries. +- ``-z`` or ``--null`` causes history entries written by the search operations to be terminated by a NUL character rather than a newline. This allows the output to be processed by ``read -z`` to correctly handle multiline history entries. -- `-` `-n ` or `--max=` limits the matched history items to the first "n" matching entries. This is only valid for `history search`. +- ``-`` ``-n `` or ``--max=`` limits the matched history items to the first "n" matching entries. This is only valid for ``history search``. -- `-R` or `--reverse` causes the history search results to be ordered oldest to newest. Which is the order used by most shells. The default is newest to oldest. +- ``-R`` or ``--reverse`` causes the history search results to be ordered oldest to newest. Which is the order used by most shells. The default is newest to oldest. -- `-h` or `--help` display help for this command. +- ``-h`` or ``--help`` display help for this command. Example ------------ @@ -72,17 +72,17 @@ Example Customizing the name of the history file ------------ -By default interactive commands are logged to `$XDG_DATA_HOME/fish/fish_history` (typically `~/.local/share/fish/fish_history`). +By default interactive commands are logged to ``$XDG_DATA_HOME/fish/fish_history`` (typically ``~/.local/share/fish/fish_history``). -You can set the `fish_history` variable to another name for the current shell session. The default value (when the variable is unset) is `fish` which corresponds to `$XDG_DATA_HOME/fish/fish_history`. If you set it to e.g. `fun`, the history would be written to `$XDG_DATA_HOME/fish/fun_history`. An empty string means history will not be stored at all. This is similar to the private session features in web browsers. +You can set the ``fish_history`` variable to another name for the current shell session. The default value (when the variable is unset) is ``fish`` which corresponds to ``$XDG_DATA_HOME/fish/fish_history``. If you set it to e.g. ``fun``, the history would be written to ``$XDG_DATA_HOME/fish/fun_history``. An empty string means history will not be stored at all. This is similar to the private session features in web browsers. -You can change `fish_history` at any time (by using `set -x fish_history "session_name"`) and it will take effect right away. If you set it to `"default"`, it will use the default session name (which is `"fish"`). +You can change ``fish_history`` at any time (by using ``set -x fish_history "session_name"``) and it will take effect right away. If you set it to ``"default"``, it will use the default session name (which is ``"fish"``). -Other shells such as bash and zsh use a variable named `HISTFILE` for a similar purpose. Fish uses a different name to avoid conflicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other than `fish` or `default` it will inhibit importing the bash history. That's because the most common use case for this feature is to avoid leaking private or sensitive history when giving a presentation. +Other shells such as bash and zsh use a variable named ``HISTFILE`` for a similar purpose. Fish uses a different name to avoid conflicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other than ``fish`` or ``default`` it will inhibit importing the bash history. That's because the most common use case for this feature is to avoid leaking private or sensitive history when giving a presentation. Notes ------------ -If you specify both `--prefix` and `--contains` the last flag seen is used. +If you specify both ``--prefix`` and ``--contains`` the last flag seen is used. -Note that for backwards compatibility each subcommand can also be specified as a long option. For example, rather than `history search` you can type `history --search`. Those long options are deprecated and will be removed in a future release. +Note that for backwards compatibility each subcommand can also be specified as a long option. For example, rather than ``history search`` you can type ``history --search``. Those long options are deprecated and will be removed in a future release. diff --git a/sphinx_doc_src/cmds/if.rst b/sphinx_doc_src/cmds/if.rst index fea89d3b0..3ba43ae9d 100644 --- a/sphinx_doc_src/cmds/if.rst +++ b/sphinx_doc_src/cmds/if.rst @@ -13,16 +13,16 @@ end Description ------------ -`if` will execute the command `CONDITION`. If the condition's exit status is 0, the commands `COMMANDS_TRUE` will execute. If the exit status is not 0 and `else` is given, `COMMANDS_FALSE` will be executed. +``if`` will execute the command ``CONDITION``. If the condition's exit status is 0, the commands ``COMMANDS_TRUE`` will execute. If the exit status is not 0 and ``else`` is given, ``COMMANDS_FALSE`` will be executed. -You can use `and` or `or` in the condition. See the second example below. +You can use ``and`` or ``or`` in the condition. See the second example below. The exit status of the last foreground command to exit can always be accessed using the $status variable. Example ------------ -The following code will print `foo.txt exists` if the file foo.txt exists and is a regular file, otherwise it will print `bar.txt exists` if the file bar.txt exists and is a regular file, otherwise it will print `foo.txt and bar.txt do not exist`. +The following code will print ``foo.txt exists`` if the file foo.txt exists and is a regular file, otherwise it will print ``bar.txt exists`` if the file bar.txt exists and is a regular file, otherwise it will print ``foo.txt and bar.txt do not exist``. diff --git a/sphinx_doc_src/cmds/isatty.rst b/sphinx_doc_src/cmds/isatty.rst index 26d2c9ca0..fc231e314 100644 --- a/sphinx_doc_src/cmds/isatty.rst +++ b/sphinx_doc_src/cmds/isatty.rst @@ -10,9 +10,9 @@ isatty [FILE DESCRIPTOR] Description ------------ -`isatty` tests if a file descriptor is a tty. +``isatty`` tests if a file descriptor is a tty. -`FILE DESCRIPTOR` may be either the number of a file descriptor, or one of the strings `stdin`, `stdout`, or `stderr`. +``FILE DESCRIPTOR`` may be either the number of a file descriptor, or one of the strings ``stdin``, ``stdout``, or ``stderr``. If the specified file descriptor is a tty, the exit status of the command is zero. Otherwise, the exit status is non-zero. No messages are printed to standard error. diff --git a/sphinx_doc_src/cmds/jobs.rst b/sphinx_doc_src/cmds/jobs.rst index 0c0cd70f3..3ba255e8c 100644 --- a/sphinx_doc_src/cmds/jobs.rst +++ b/sphinx_doc_src/cmds/jobs.rst @@ -10,23 +10,23 @@ jobs [OPTIONS] [PID] Description ------------ -`jobs` prints a list of the currently running jobs and their status. +``jobs`` prints a list of the currently running jobs and their status. jobs accepts the following switches: -- `-c` or `--command` prints the command name for each process in jobs. +- ``-c`` or ``--command`` prints the command name for each process in jobs. -- `-g` or `--group` only prints the group ID of each job. +- ``-g`` or ``--group`` only prints the group ID of each job. -- `-l` or `--last` prints only the last job to be started. +- ``-l`` or ``--last`` prints only the last job to be started. -- `-p` or `--pid` prints the process ID for each process in all jobs. +- ``-p`` or ``--pid`` prints the process ID for each process in all jobs. -- `-q` or `--quiet` prints no output for evaluation of jobs by exit code only. +- ``-q`` or ``--quiet`` prints no output for evaluation of jobs by exit code only. On systems that supports this feature, jobs will print the CPU usage of each job since the last command was executed. The CPU usage is expressed as a percentage of full CPU activity. Note that on multiprocessor systems, the total activity may be more than 100\%. -The exit code of the `jobs` builtin is `0` if there are running background jobs and `1` otherwise. +The exit code of the ``jobs`` builtin is ``0`` if there are running background jobs and ``1`` otherwise. no output. ------------ @@ -35,4 +35,4 @@ no output. Example ------------ -`jobs` outputs a summary of the current jobs. +``jobs`` outputs a summary of the current jobs. diff --git a/sphinx_doc_src/cmds/math.rst b/sphinx_doc_src/cmds/math.rst index 86183cf8e..170d86357 100644 --- a/sphinx_doc_src/cmds/math.rst +++ b/sphinx_doc_src/cmds/math.rst @@ -10,105 +10,105 @@ math [-sN | --scale=N] [--] EXPRESSION Description ------------ -`math` is used to perform mathematical calculations. It supports all the usual operations such as addition, subtraction, etc. As well as functions like `abs()`, `sqrt()` and `log2()`. +``math`` is used to perform mathematical calculations. It supports all the usual operations such as addition, subtraction, etc. As well as functions like ``abs()``, ``sqrt()`` and ``log2()``. -By default, the output is as a float with trailing zeroes trimmed. To get a fixed representation, the `--scale` option can be used, including `--scale=0` for integer output. +By default, the output is as a float with trailing zeroes trimmed. To get a fixed representation, the ``--scale`` option can be used, including ``--scale=0`` for integer output. Keep in mind that parameter expansion takes before expressions are evaluated. This can be very useful in order to perform calculations involving shell variables or the output of command substitutions, but it also means that parenthesis and the asterisk glob character have to be escaped or quoted. -`math` ignores whitespace between arguments and takes its input as multiple arguments (internally joined with a space), so `math 2 +2` and `math "2 + 2"` work the same. `math 2 2` is an error. +``math`` ignores whitespace between arguments and takes its input as multiple arguments (internally joined with a space), so ``math 2 +2`` and ``math "2 + 2"`` work the same. ``math 2 2`` is an error. The following options are available: -- `-sN` or `--scale=N` sets the scale of the result. `N` must be an integer. A scale of zero causes results to be rounded down to the nearest integer. So `3/2` returns `1` rather than `2` which `1.5` would normally round to. This is for compatibility with `bc` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. +- ``-sN`` or ``--scale=N`` sets the scale of the result. ``N`` must be an integer. A scale of zero causes results to be rounded down to the nearest integer. So ``3/2`` returns ``1`` rather than ``2`` which ``1.5`` would normally round to. This is for compatibility with ``bc`` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. Return Values ------------ -If the expression is successfully evaluated and doesn't over/underflow or return NaN the return `status` is zero (success) else one. +If the expression is successfully evaluated and doesn't over/underflow or return NaN the return ``status`` is zero (success) else one. Syntax ------------ -`math` knows some operators, constants, functions and can (obviously) read numbers. +``math`` knows some operators, constants, functions and can (obviously) read numbers. -For numbers, `.` is always the radix character regardless of locale - `2.5`, not `2,5`. Scientific notation (`10e5`) is also available. +For numbers, ``.`` is always the radix character regardless of locale - ``2.5``, not ``2,5``. Scientific notation (``10e5``) is also available. Operators ------------ -`math` knows the following operators: +``math`` knows the following operators: -- `+` for addition and `-` for subtraction. +- ``+`` for addition and ``-`` for subtraction. -- `*` for multiplication, `/` for division. +- ``*`` for multiplication, ``/`` for division. -- `^` for exponentiation. +- ``^`` for exponentiation. -- `%` for modulo. +- ``%`` for modulo. -- `(` and `)` for grouping. +- ``(`` and ``)`` for grouping. -They are all used in an infix manner - `5 + 2`, not `+ 5 2`. +They are all used in an infix manner - ``5 + 2``, not ``+ 5 2``. Constants ------------ -`math` knows the following constants: +``math`` knows the following constants: -- `e` - Euler's number. -- `pi` - You know that one. Half of Tau. (Tau is not implemented) +- ``e`` - Euler's number. +- ``pi`` - You know that one. Half of Tau. (Tau is not implemented) -Use them without a leading `$` - `pi - 3` should be about 0. +Use them without a leading ``$`` - ``pi - 3`` should be about 0. Functions ------------ -`math` supports the following functions: +``math`` supports the following functions: -- `abs` -- `acos` -- `asin` -- `atan` -- `atan2` -- `ceil` -- `cos` -- `cosh` -- `exp` - the base-e exponential function -- `fac` - factorial -- `floor` -- `ln` -- `log` or `log10` - the base-10 logarithm -- `ncr` -- `npr` -- `pow(x,y)` returns x to the y (and can be written as `x ^ y`) -- `round` - rounds to the nearest integer, away from 0 -- `sin` -- `sinh` -- `sqrt` -- `tan` -- `tanh` +- ``abs`` +- ``acos`` +- ``asin`` +- ``atan`` +- ``atan2`` +- ``ceil`` +- ``cos`` +- ``cosh`` +- ``exp`` - the base-e exponential function +- ``fac`` - factorial +- ``floor`` +- ``ln`` +- ``log`` or ``log10`` - the base-10 logarithm +- ``ncr`` +- ``npr`` +- ``pow(x,y)`` returns x to the y (and can be written as ``x ^ y``) +- ``round`` - rounds to the nearest integer, away from 0 +- ``sin`` +- ``sinh`` +- ``sqrt`` +- ``tan`` +- ``tanh`` All of the trigonometric functions use radians. Examples ------------ -`math 1+1` outputs 2. +``math 1+1`` outputs 2. -`math $status - 128` outputs the numerical exit status of the last command minus 128. +``math $status - 128`` outputs the numerical exit status of the last command minus 128. -`math 10 / 6` outputs `1.666667`. +``math 10 / 6`` outputs ``1.666667``. -`math -s0 10.0 / 6.0` outputs `1`. +``math -s0 10.0 / 6.0`` outputs ``1``. -`math -s3 10 / 6` outputs `1.666`. +``math -s3 10 / 6`` outputs ``1.666``. -`math "sin(pi)"` outputs `0`. +``math "sin(pi)"`` outputs ``0``. Compatibility notes ------------ -Fish 1.x and 2.x releases relied on the `bc` command for handling `math` expressions. Starting with fish 3.0.0 fish uses the tinyexpr library and evaluates the expression without the involvement of any external commands. +Fish 1.x and 2.x releases relied on the ``bc`` command for handling ``math`` expressions. Starting with fish 3.0.0 fish uses the tinyexpr library and evaluates the expression without the involvement of any external commands. -You don't need to use `--` before the expression even if it begins with a minus sign which might otherwise be interpreted as an invalid option. If you do insert `--` before the expression it will cause option scanning to stop just like for every other command and it won't be part of the expression. +You don't need to use ``--`` before the expression even if it begins with a minus sign which might otherwise be interpreted as an invalid option. If you do insert ``--`` before the expression it will cause option scanning to stop just like for every other command and it won't be part of the expression. diff --git a/sphinx_doc_src/cmds/nextd.rst b/sphinx_doc_src/cmds/nextd.rst index fd4ca53c6..d954b7142 100644 --- a/sphinx_doc_src/cmds/nextd.rst +++ b/sphinx_doc_src/cmds/nextd.rst @@ -10,13 +10,13 @@ nextd [ -l | --list ] [POS] Description ------------ -`nextd` moves forwards `POS` positions in the history of visited directories; if the end of the history has been hit, a warning is printed. +``nextd`` moves forwards ``POS`` positions in the history of visited directories; if the end of the history has been hit, a warning is printed. -If the `-l` or `--list` flag is specified, the current directory history is also displayed. +If the ``-l`` or ``--list`` flag is specified, the current directory history is also displayed. -Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables which this command manipulates. +Note that the ``cd`` command limits directory history to the 25 most recently visited directories. The history is stored in the ``$dirprev`` and ``$dirnext`` variables which this command manipulates. -You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. +You may be interested in the ``cdh`` command which provides a more intuitive way to navigate to recently visited directories. Example ------------ diff --git a/sphinx_doc_src/cmds/not.rst b/sphinx_doc_src/cmds/not.rst index de19ae7a4..50438fc39 100644 --- a/sphinx_doc_src/cmds/not.rst +++ b/sphinx_doc_src/cmds/not.rst @@ -10,7 +10,7 @@ not COMMAND [OPTIONS...] Description ------------ -`not` negates the exit status of another command. If the exit status is zero, `not` returns 1. Otherwise, `not` returns 0. +``not`` negates the exit status of another command. If the exit status is zero, ``not`` returns 1. Otherwise, ``not`` returns 0. Example diff --git a/sphinx_doc_src/cmds/open.rst b/sphinx_doc_src/cmds/open.rst index d093dc955..4b86a0641 100644 --- a/sphinx_doc_src/cmds/open.rst +++ b/sphinx_doc_src/cmds/open.rst @@ -10,7 +10,7 @@ open FILES... Description ------------ -`open` opens a file in its default application, using the appropriate tool for the operating system. On GNU/Linux, this requires the common but optional `xdg-open` utility, from the `xdg-utils` package. +``open`` opens a file in its default application, using the appropriate tool for the operating system. On GNU/Linux, this requires the common but optional ``xdg-open`` utility, from the ``xdg-utils`` package. Note that this function will not be used if a command by this name exists (which is the case on macOS or Haiku). @@ -18,4 +18,4 @@ Note that this function will not be used if a command by this name exists (which Example ------------ -`open *.txt` opens all the text files in the current directory using your system's default text editor. +``open *.txt`` opens all the text files in the current directory using your system's default text editor. diff --git a/sphinx_doc_src/cmds/or.rst b/sphinx_doc_src/cmds/or.rst index 9f2eab5de..7f04d8af0 100644 --- a/sphinx_doc_src/cmds/or.rst +++ b/sphinx_doc_src/cmds/or.rst @@ -10,17 +10,17 @@ COMMAND1; or COMMAND2 Description ------------ -`or` is used to execute a command if the previous command was not successful (returned a status of something other than 0). +``or`` is used to execute a command if the previous command was not successful (returned a status of something other than 0). -`or` statements may be used as part of the condition in an `and` or `while` block. See the documentation -for `if` and `while` for examples. +``or`` statements may be used as part of the condition in an ``and`` or ``while`` block. See the documentation +for ``if`` and ``while`` for examples. -`or` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. +``or`` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. Example ------------ -The following code runs the `make` command to build a program. If the build succeeds, the program is installed. If either step fails, `make clean` is run, which removes the files created by the build process. +The following code runs the ``make`` command to build a program. If the build succeeds, the program is installed. If either step fails, ``make clean`` is run, which removes the files created by the build process. diff --git a/sphinx_doc_src/cmds/popd.rst b/sphinx_doc_src/cmds/popd.rst index c55d2d45f..126d331d2 100644 --- a/sphinx_doc_src/cmds/popd.rst +++ b/sphinx_doc_src/cmds/popd.rst @@ -10,9 +10,9 @@ popd Description ------------ -`popd` removes the top directory from the directory stack and changes the working directory to the new top directory. Use `pushd` to add directories to the stack. +``popd`` removes the top directory from the directory stack and changes the working directory to the new top directory. Use ``pushd`` to add directories to the stack. -You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. +You may be interested in the ``cdh`` command which provides a more intuitive way to navigate to recently visited directories. Example ------------ diff --git a/sphinx_doc_src/cmds/prevd.rst b/sphinx_doc_src/cmds/prevd.rst index b73d6eab5..9087249f7 100644 --- a/sphinx_doc_src/cmds/prevd.rst +++ b/sphinx_doc_src/cmds/prevd.rst @@ -10,13 +10,13 @@ prevd [ -l | --list ] [POS] Description ------------ -`prevd` moves backwards `POS` positions in the history of visited directories; if the beginning of the history has been hit, a warning is printed. +``prevd`` moves backwards ``POS`` positions in the history of visited directories; if the beginning of the history has been hit, a warning is printed. -If the `-l` or `--list` flag is specified, the current history is also displayed. +If the ``-l`` or ``--list`` flag is specified, the current history is also displayed. -Note that the `cd` command limits directory history to the 25 most recently visited directories. The history is stored in the `$dirprev` and `$dirnext` variables which this command manipulates. +Note that the ``cd`` command limits directory history to the 25 most recently visited directories. The history is stored in the ``$dirprev`` and ``$dirnext`` variables which this command manipulates. -You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. +You may be interested in the ``cdh`` command which provides a more intuitive way to navigate to recently visited directories. Example ------------ diff --git a/sphinx_doc_src/cmds/printf.rst b/sphinx_doc_src/cmds/printf.rst index cc3a528b5..d951e16ab 100644 --- a/sphinx_doc_src/cmds/printf.rst +++ b/sphinx_doc_src/cmds/printf.rst @@ -11,54 +11,54 @@ Description ------------ printf formats the string FORMAT with ARGUMENT, and displays the result. -The string FORMAT should contain format specifiers, each of which are replaced with successive arguments according to the specifier. Specifiers are detailed below, and are taken from the C library function `printf(3)`. +The string FORMAT should contain format specifiers, each of which are replaced with successive arguments according to the specifier. Specifiers are detailed below, and are taken from the C library function ``printf(3)``. -Unlike `echo`, `printf` does not append a new line unless it is specified as part of the string. +Unlike ``echo``, ``printf`` does not append a new line unless it is specified as part of the string. Valid format specifiers are: -- `%%d`: Argument will be used as decimal integer (signed or unsigned) +- ``%%d``: Argument will be used as decimal integer (signed or unsigned) -- `%%i`: Argument will be used as a signed integer +- ``%%i``: Argument will be used as a signed integer -- `%%o`: An octal unsigned integer +- ``%%o``: An octal unsigned integer -- `%%u`: An unsigned decimal integer +- ``%%u``: An unsigned decimal integer -- `%%x` or `%%X`: An unsigned hexadecimal integer +- ``%%x`` or ``%%X``: An unsigned hexadecimal integer -- `%%f`, `%%g` or `%%G`: A floating-point number +- ``%%f``, ``%%g`` or ``%%G``: A floating-point number -- `%%e` or `%%E`: A floating-point number in scientific (XXXeYY) notation +- ``%%e`` or ``%%E``: A floating-point number in scientific (XXXeYY) notation -- `%%s`: A string +- ``%%s``: A string -- `%%b`: As a string, interpreting backslash escapes, except that octal escapes are of the form \0 or \0ooo. +- ``%%b``: As a string, interpreting backslash escapes, except that octal escapes are of the form \0 or \0ooo. -`%%` signifies a literal "%". +``%%`` signifies a literal "%". Note that conversion may fail, e.g. "102.234" will not losslessly convert to an integer, causing printf to print an error. printf also knows a number of backslash escapes: -- `\"` double quote -- `\\` backslash -- `\a` alert (bell) -- `\b` backspace -- `\c` produce no further output -- `\e` escape -- `\f` form feed -- `\n` new line -- `\r` carriage return -- `\t` horizontal tab -- `\v` vertical tab -- `\ooo` octal number (ooo is 1 to 3 digits) -- `\xhh` hexadecimal number (hhh is 1 to 2 digits) -- `\uhhhh` 16-bit Unicode character (hhhh is 4 digits) -- `\Uhhhhhhhh` 32-bit Unicode character (hhhhhhhh is 8 digits) +- ``\"`` double quote +- ``\\`` backslash +- ``\a`` alert (bell) +- ``\b`` backspace +- ``\c`` produce no further output +- ``\e`` escape +- ``\f`` form feed +- ``\n`` new line +- ``\r`` carriage return +- ``\t`` horizontal tab +- ``\v`` vertical tab +- ``\ooo`` octal number (ooo is 1 to 3 digits) +- ``\xhh`` hexadecimal number (hhh is 1 to 2 digits) +- ``\uhhhh`` 16-bit Unicode character (hhhh is 4 digits) +- ``\Uhhhhhhhh`` 32-bit Unicode character (hhhhhhhh is 8 digits) -The `format` argument is re-used as many times as necessary to convert all of the given arguments. If a format specifier is not appropriate for the given argument, an error is printed. For example, `printf '%d' "102.234"` produces an error, as "102.234" cannot be formatted as an integer. +The ``format`` argument is re-used as many times as necessary to convert all of the given arguments. If a format specifier is not appropriate for the given argument, an error is printed. For example, ``printf '%d' "102.234"`` produces an error, as "102.234" cannot be formatted as an integer. -This file has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try `command printf`. +This file has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try ``command printf``. Example ------------ diff --git a/sphinx_doc_src/cmds/psub.rst b/sphinx_doc_src/cmds/psub.rst index 5e3e4a984..6229ea2f9 100644 --- a/sphinx_doc_src/cmds/psub.rst +++ b/sphinx_doc_src/cmds/psub.rst @@ -10,15 +10,15 @@ COMMAND1 ( COMMAND2 | psub [-F | --fifo] [-f | --file] [-s SUFFIX]) Description ------------ -Some shells (e.g., ksh, bash) feature a syntax that is a mix between command substitution and piping, called process substitution. It is used to send the output of a command into the calling command, much like command substitution, but with the difference that the output is not sent through commandline arguments but through a named pipe, with the filename of the named pipe sent as an argument to the calling program. `psub` combined with a regular command substitution provides the same functionality. +Some shells (e.g., ksh, bash) feature a syntax that is a mix between command substitution and piping, called process substitution. It is used to send the output of a command into the calling command, much like command substitution, but with the difference that the output is not sent through commandline arguments but through a named pipe, with the filename of the named pipe sent as an argument to the calling program. ``psub`` combined with a regular command substitution provides the same functionality. The following options are available: -- `-f` or `--file` will cause psub to use a regular file instead of a named pipe to communicate with the calling process. This will cause `psub` to be significantly slower when large amounts of data are involved, but has the advantage that the reading process can seek in the stream. This is the default. +- ``-f`` or ``--file`` will cause psub to use a regular file instead of a named pipe to communicate with the calling process. This will cause ``psub`` to be significantly slower when large amounts of data are involved, but has the advantage that the reading process can seek in the stream. This is the default. -- `-F` or `--fifo` will cause psub to use a named pipe rather than a file. You should only use this if the command produces no more than 8 KiB of output. The limit on the amount of data a FIFO can buffer varies with the OS but is typically 8 KiB, 16 KiB or 64 KiB. If you use this option and the command on the left of the psub pipeline produces more output a deadlock is likely to occur. +- ``-F`` or ``--fifo`` will cause psub to use a named pipe rather than a file. You should only use this if the command produces no more than 8 KiB of output. The limit on the amount of data a FIFO can buffer varies with the OS but is typically 8 KiB, 16 KiB or 64 KiB. If you use this option and the command on the left of the psub pipeline produces more output a deadlock is likely to occur. -- `-s` or `--suffix` will append SUFFIX to the filename. +- ``-s`` or ``--suffix`` will append SUFFIX to the filename. Example ------------ @@ -28,8 +28,8 @@ Example :: diff (sort a.txt | psub) (sort b.txt | psub) - # shows the difference between the sorted versions of files `a.txt` and `b.txt`. + # shows the difference between the sorted versions of files ``a.txt`` and ``b.txt``. source-highlight -f esc (cpp main.c | psub -f -s .c) - # highlights `main.c` after preprocessing as a C source. + # highlights ``main.c`` after preprocessing as a C source. diff --git a/sphinx_doc_src/cmds/pushd.rst b/sphinx_doc_src/cmds/pushd.rst index ef96186a1..68cd3b5ae 100644 --- a/sphinx_doc_src/cmds/pushd.rst +++ b/sphinx_doc_src/cmds/pushd.rst @@ -10,17 +10,17 @@ pushd [DIRECTORY] Description ------------ -The `pushd` function adds `DIRECTORY` to the top of the directory stack and makes it the current working directory. `popd` will pop it off and return to the original directory. +The ``pushd`` function adds ``DIRECTORY`` to the top of the directory stack and makes it the current working directory. ``popd`` will pop it off and return to the original directory. Without arguments, it exchanges the top two directories in the stack. -`pushd +NUMBER` rotates the stack counter-clockwise i.e. from bottom to top +``pushd +NUMBER`` rotates the stack counter-clockwise i.e. from bottom to top -`pushd -NUMBER` rotates clockwise i.e. top to bottom. +``pushd -NUMBER`` rotates clockwise i.e. top to bottom. -See also `dirs` and `dirs -c`. +See also ``dirs`` and ``dirs -c``. -You may be interested in the `cdh` command which provides a more intuitive way to navigate to recently visited directories. +You may be interested in the ``cdh`` command which provides a more intuitive way to navigate to recently visited directories. Example ------------ diff --git a/sphinx_doc_src/cmds/pwd.rst b/sphinx_doc_src/cmds/pwd.rst index 4111c0685..9845e1533 100644 --- a/sphinx_doc_src/cmds/pwd.rst +++ b/sphinx_doc_src/cmds/pwd.rst @@ -10,10 +10,10 @@ pwd Description ------------ -`pwd` outputs (prints) the current working directory. +``pwd`` outputs (prints) the current working directory. The following options are available: -- `-L`, Output the logical working directory, without resolving symlinks (default behavior). +- ``-L``, Output the logical working directory, without resolving symlinks (default behavior). -- `-P`, Output the physical working directory, with symlinks resolved. +- ``-P``, Output the physical working directory, with symlinks resolved. diff --git a/sphinx_doc_src/cmds/random.rst b/sphinx_doc_src/cmds/random.rst index 0dde95e6a..43bbc1809 100644 --- a/sphinx_doc_src/cmds/random.rst +++ b/sphinx_doc_src/cmds/random.rst @@ -14,20 +14,20 @@ random choice [ITEMS...] Description ------------ -`RANDOM` generates a pseudo-random integer from a uniform distribution. The +``RANDOM`` generates a pseudo-random integer from a uniform distribution. The range (inclusive) is dependent on the arguments passed. No arguments indicate a range of [0; 32767]. If one argument is specified, the internal engine will be seeded with the -argument for future invocations of `RANDOM` and no output will be produced. +argument for future invocations of ``RANDOM`` and no output will be produced. Two arguments indicate a range of [START; END]. Three arguments indicate a range of [START; END] with a spacing of STEP between possible outputs. -`RANDOM choice` will select one random item from the succeeding arguments. +``RANDOM choice`` will select one random item from the succeeding arguments. Note that seeding the engine will NOT give the same result across different systems. -You should not consider `RANDOM` cryptographically secure, or even +You should not consider ``RANDOM`` cryptographically secure, or even statistically accurate. Example diff --git a/sphinx_doc_src/cmds/read.rst b/sphinx_doc_src/cmds/read.rst index 69e2ef91b..974ad6ab8 100644 --- a/sphinx_doc_src/cmds/read.rst +++ b/sphinx_doc_src/cmds/read.rst @@ -10,77 +10,77 @@ read [OPTIONS] [VARIABLE ...] Description ------------ -`read` reads from standard input and either writes the result back to standard output (for use in command substitution), or stores the result in one or more shell variables. By default, `read` reads a single line and splits it into variables on spaces or tabs. Alternatively, a null character or a maximum number of characters can be used to terminate the input, and other delimiters can be given. Unlike other shells, there is no default variable (such as `REPLY`) for storing the result - instead, it is printed on standard output. +``read`` reads from standard input and either writes the result back to standard output (for use in command substitution), or stores the result in one or more shell variables. By default, ``read`` reads a single line and splits it into variables on spaces or tabs. Alternatively, a null character or a maximum number of characters can be used to terminate the input, and other delimiters can be given. Unlike other shells, there is no default variable (such as ``REPLY``) for storing the result - instead, it is printed on standard output. The following options are available: -- `-c CMD` or `--command=CMD` sets the initial string in the interactive mode command buffer to `CMD`. +- ``-c CMD`` or ``--command=CMD`` sets the initial string in the interactive mode command buffer to ``CMD``. -- `-d DELIMITER` or `--delimiter=DELIMITER` splits on DELIMITER. DELIMITER will be used as an entire string to split on, not a set of characters. +- ``-d DELIMITER`` or ``--delimiter=DELIMITER`` splits on DELIMITER. DELIMITER will be used as an entire string to split on, not a set of characters. -- `-g` or `--global` makes the variables global. +- ``-g`` or ``--global`` makes the variables global. -- `-s` or `--silent` masks characters written to the terminal, replacing them with asterisks. This is useful for reading things like passwords or other sensitive information. +- ``-s`` or ``--silent`` masks characters written to the terminal, replacing them with asterisks. This is useful for reading things like passwords or other sensitive information. -- `-l` or `--local` makes the variables local. +- ``-l`` or ``--local`` makes the variables local. -- `-n NCHARS` or `--nchars=NCHARS` makes `read` return after reading NCHARS characters or the end of +- ``-n NCHARS`` or ``--nchars=NCHARS`` makes ``read`` return after reading NCHARS characters or the end of the line, whichever comes first. -- `-p PROMPT_CMD` or `--prompt=PROMPT_CMD` uses the output of the shell command `PROMPT_CMD` as the prompt for the interactive mode. The default prompt command is set_color green; echo read; set_color normal; echo "> ". +- ``-p PROMPT_CMD`` or ``--prompt=PROMPT_CMD`` uses the output of the shell command ``PROMPT_CMD`` as the prompt for the interactive mode. The default prompt command is set_color green; echo read; set_color normal; echo "> ". -- `-P PROMPT_STR` or `--prompt-str=PROMPT_STR` uses the string as the prompt for the interactive mode. It is equivalent to echo PROMPT_STR and is provided solely to avoid the need to frame the prompt as a command. All special characters in the string are automatically escaped before being passed to the echo command. +- ``-P PROMPT_STR`` or ``--prompt-str=PROMPT_STR`` uses the string as the prompt for the interactive mode. It is equivalent to echo PROMPT_STR and is provided solely to avoid the need to frame the prompt as a command. All special characters in the string are automatically escaped before being passed to the echo command. -- `-R RIGHT_PROMPT_CMD` or `--right-prompt=RIGHT_PROMPT_CMD` uses the output of the shell command `RIGHT_PROMPT_CMD` as the right prompt for the interactive mode. There is no default right prompt command. +- ``-R RIGHT_PROMPT_CMD`` or ``--right-prompt=RIGHT_PROMPT_CMD`` uses the output of the shell command ``RIGHT_PROMPT_CMD`` as the right prompt for the interactive mode. There is no default right prompt command. -- `-S` or `--shell` enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode. NOTE: Prior to fish 3.0, the short opt for `--shell` was `-s`, but it has been changed for compatibility with bash's `-s` short opt for `--silent`. +- ``-S`` or ``--shell`` enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode. NOTE: Prior to fish 3.0, the short opt for ``--shell`` was ``-s``, but it has been changed for compatibility with bash's ``-s`` short opt for ``--silent``. -- `-u` or `--unexport` prevents the variables from being exported to child processes (default behaviour). +- ``-u`` or ``--unexport`` prevents the variables from being exported to child processes (default behaviour). -- `-U` or `--universal` causes the specified shell variable to be made universal. +- ``-U`` or ``--universal`` causes the specified shell variable to be made universal. -- `-x` or `--export` exports the variables to child processes. +- ``-x`` or ``--export`` exports the variables to child processes. -- `-a` or `--array` stores the result as an array in a single variable. +- ``-a`` or ``--array`` stores the result as an array in a single variable. -- `-z` or `--null` marks the end of the line with the NUL character, instead of newline. This also +- ``-z`` or ``--null`` marks the end of the line with the NUL character, instead of newline. This also disables interactive mode. -- `-L` or `--line` reads each line into successive variables, and stops after each variable has been filled. This cannot be combined with the `--delimiter` option. +- ``-L`` or ``--line`` reads each line into successive variables, and stops after each variable has been filled. This cannot be combined with the ``--delimiter`` option. -Without the `--line` option, `read` reads a single line of input from standard input, breaks it into tokens, and then assigns one token to each variable specified in `VARIABLES`. If there are more tokens than variables, the complete remainder is assigned to the last variable. +Without the ``--line`` option, ``read`` reads a single line of input from standard input, breaks it into tokens, and then assigns one token to each variable specified in ``VARIABLES``. If there are more tokens than variables, the complete remainder is assigned to the last variable. -If the `--delimiter` argument is not given, the variable `IFS` is used as a list of characters to split on. Relying on the use of `IFS` is deprecated and this behaviour will be removed in future versions. The default value of `IFS` contains space, tab and newline characters. As a special case, if `IFS` is set to the empty string, each character of the input is considered a separate token. +If the ``--delimiter`` argument is not given, the variable ``IFS`` is used as a list of characters to split on. Relying on the use of ``IFS`` is deprecated and this behaviour will be removed in future versions. The default value of ``IFS`` contains space, tab and newline characters. As a special case, if ``IFS`` is set to the empty string, each character of the input is considered a separate token. -With the `--line` option, `read` reads a line of input from standard input into each provided variable, stopping when each variable has been filled. The line is not tokenized. +With the ``--line`` option, ``read`` reads a line of input from standard input into each provided variable, stopping when each variable has been filled. The line is not tokenized. -If no variable names are provided, `read` enters a special case that simply provides redirection from standard input to standard output, useful for command substitution. For instance, the fish shell command below can be used to read data that should be provided via a command line argument from the console instead of hardcoding it in the command itself, allowing the command to both be reused as-is in various contexts with different input values and preventing possibly sensitive text from being included in the shell history: +If no variable names are provided, ``read`` enters a special case that simply provides redirection from standard input to standard output, useful for command substitution. For instance, the fish shell command below can be used to read data that should be provided via a command line argument from the console instead of hardcoding it in the command itself, allowing the command to both be reused as-is in various contexts with different input values and preventing possibly sensitive text from being included in the shell history: -`mysql -uuser -p(read)` +``mysql -uuser -p(read)`` -When running in this mode, `read` does not split the input in any way and text is redirected to standard output without any further processing or manipulation. +When running in this mode, ``read`` does not split the input in any way and text is redirected to standard output without any further processing or manipulation. -If `-a` or `--array` is provided, only one variable name is allowed and the tokens are stored as an array in this variable. +If ``-a`` or ``--array`` is provided, only one variable name is allowed and the tokens are stored as an array in this variable. -See the documentation for `set` for more details on the scoping rules for variables. +See the documentation for ``set`` for more details on the scoping rules for variables. -When `read` reaches the end-of-file (EOF) instead of the terminator, the exit status is set to 1. +When ``read`` reaches the end-of-file (EOF) instead of the terminator, the exit status is set to 1. Otherwise, it is set to 0. -In order to protect the shell from consuming too many system resources, `read` will only consume a +In order to protect the shell from consuming too many system resources, ``read`` will only consume a maximum of 10 MiB (1048576 bytes); if the terminator is not reached before this limit then VARIABLE is set to empty and the exit status is set to 122. This limit can be altered with the -`fish_read_limit` variable. If set to 0 (zero), the limit is removed. +``fish_read_limit`` variable. If set to 0 (zero), the limit is removed. Using another read history file ------------ -The `read` command supported the `-m` and `--mode-name` flags in fish versions prior to 2.7.0 to specify an alternative read history file. Those flags are now deprecated and ignored. Instead, set the `fish_history` variable to specify a history session ID. That will affect both the `read` history file and the fish command history file. You can set it to an empty string to specify that no history should be read or written. This is useful for presentations where you do not want possibly private or sensitive history to be exposed to the audience but do want history relevant to the presentation to be available. +The ``read`` command supported the ``-m`` and ``--mode-name`` flags in fish versions prior to 2.7.0 to specify an alternative read history file. Those flags are now deprecated and ignored. Instead, set the ``fish_history`` variable to specify a history session ID. That will affect both the ``read`` history file and the fish command history file. You can set it to an empty string to specify that no history should be read or written. This is useful for presentations where you do not want possibly private or sensitive history to be exposed to the audience but do want history relevant to the presentation to be available. Example ------------ -The following code stores the value 'hello' in the shell variable `$foo`. +The following code stores the value 'hello' in the shell variable ``$foo``. diff --git a/sphinx_doc_src/cmds/realpath.rst b/sphinx_doc_src/cmds/realpath.rst index e3a5bce09..4b6700c66 100644 --- a/sphinx_doc_src/cmds/realpath.rst +++ b/sphinx_doc_src/cmds/realpath.rst @@ -10,6 +10,6 @@ realpath path Description ------------ -This is implemented as a function and a builtin. The function will attempt to use an external realpath command if one can be found. Otherwise it falls back to the builtin. The builtin does not support any options. It's meant to be used only by scripts which need to be portable. The builtin implementation behaves like GNU realpath when invoked without any options (which is the most common use case). In general scripts should not invoke the builtin directly. They should just use `realpath`. +This is implemented as a function and a builtin. The function will attempt to use an external realpath command if one can be found. Otherwise it falls back to the builtin. The builtin does not support any options. It's meant to be used only by scripts which need to be portable. The builtin implementation behaves like GNU realpath when invoked without any options (which is the most common use case). In general scripts should not invoke the builtin directly. They should just use ``realpath``. If the path is invalid no translated path will be written to stdout and an error will be reported. diff --git a/sphinx_doc_src/cmds/return.rst b/sphinx_doc_src/cmds/return.rst index 38c8c82db..edf51aa9a 100644 --- a/sphinx_doc_src/cmds/return.rst +++ b/sphinx_doc_src/cmds/return.rst @@ -10,7 +10,7 @@ function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end Description ------------ -`return` halts a currently running function. The exit status is set to `STATUS` if it is given. +``return`` halts a currently running function. The exit status is set to ``STATUS`` if it is given. It is usually added inside of a conditional block such as an if statement or a switch statement to conditionally stop the executing function and return to the caller, but it can also be used to specify the exit status of a function. diff --git a/sphinx_doc_src/cmds/set.rst b/sphinx_doc_src/cmds/set.rst index f5a7f4742..badd96a79 100644 --- a/sphinx_doc_src/cmds/set.rst +++ b/sphinx_doc_src/cmds/set.rst @@ -16,45 +16,45 @@ set ( -S | --show ) [SCOPE_OPTIONS] [VARIABLE_NAME]... Description ------------ -`set` manipulates shell variables. +``set`` manipulates shell variables. If set is called with no arguments, the names and values of all shell variables are printed in sorted order. If some of the scope or export flags have been given, only the variables matching the specified scope are printed. -With both variable names and values provided, `set` assigns the variable `VARIABLE_NAME` the values `VALUES...`. +With both variable names and values provided, ``set`` assigns the variable ``VARIABLE_NAME`` the values ``VALUES...``. The following options control variable scope: -- `-a` or `--append` causes the values to be appended to the current set of values for the variable. This can be used with `--prepend` to both append and prepend at the same time. This cannot be used when assigning to a variable slice. +- ``-a`` or ``--append`` causes the values to be appended to the current set of values for the variable. This can be used with ``--prepend`` to both append and prepend at the same time. This cannot be used when assigning to a variable slice. -- `-p` or `--prepend` causes the values to be prepended to the current set of values for the variable. This can be used with `--append` to both append and prepend at the same time. This cannot be used when assigning to a variable slice. +- ``-p`` or ``--prepend`` causes the values to be prepended to the current set of values for the variable. This can be used with ``--append`` to both append and prepend at the same time. This cannot be used when assigning to a variable slice. -- `-l` or `--local` forces the specified shell variable to be given a scope that is local to the current block, even if a variable with the given name exists and is non-local +- ``-l`` or ``--local`` forces the specified shell variable to be given a scope that is local to the current block, even if a variable with the given name exists and is non-local -- `-g` or `--global` causes the specified shell variable to be given a global scope. Non-global variables disappear when the block they belong to ends +- ``-g`` or ``--global`` causes the specified shell variable to be given a global scope. Non-global variables disappear when the block they belong to ends -- `-U` or `--universal` causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell. +- ``-U`` or ``--universal`` causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell. -- `-x` or `--export` causes the specified shell variable to be exported to child processes (making it an "environment variable") +- ``-x`` or ``--export`` causes the specified shell variable to be exported to child processes (making it an "environment variable") -- `-u` or `--unexport` causes the specified shell variable to NOT be exported to child processes +- ``-u`` or ``--unexport`` causes the specified shell variable to NOT be exported to child processes The following options are available: -- `-e` or `--erase` causes the specified shell variable to be erased +- ``-e`` or ``--erase`` causes the specified shell variable to be erased -- `-q` or `--query` test if the specified variable names are defined. Does not output anything, but the builtins exit status is the number of variables specified that were not defined. +- ``-q`` or ``--query`` test if the specified variable names are defined. Does not output anything, but the builtins exit status is the number of variables specified that were not defined. -- `-n` or `--names` List only the names of all defined variables, not their value. The names are guaranteed to be sorted. +- ``-n`` or ``--names`` List only the names of all defined variables, not their value. The names are guaranteed to be sorted. -- `-S` or `--show` Shows information about the given variables. If no variable names are given then all variables are shown in sorted order. No other flags can be used with this option. The information shown includes whether or not it is set in each of the local, global, and universal scopes. If it is set in one of those scopes whether or not it is exported is reported. The individual elements are also shown along with the length of each element. +- ``-S`` or ``--show`` Shows information about the given variables. If no variable names are given then all variables are shown in sorted order. No other flags can be used with this option. The information shown includes whether or not it is set in each of the local, global, and universal scopes. If it is set in one of those scopes whether or not it is exported is reported. The individual elements are also shown along with the length of each element. -- `-L` or `--long` do not abbreviate long values when printing set variables +- ``-L`` or ``--long`` do not abbreviate long values when printing set variables If a variable is set to more than one value, the variable will be an array with the specified elements. If a variable is set to zero elements, it will become an array with zero elements. -If the variable name is one or more array elements, such as `PATH[1 3 7]`, only those array elements specified will be changed. If you specify a negative index when expanding or assigning to an array variable, the index will be calculated from the end of the array. For example, the index -1 means the last index of an array. +If the variable name is one or more array elements, such as ``PATH[1 3 7]``, only those array elements specified will be changed. If you specify a negative index when expanding or assigning to an array variable, the index will be calculated from the end of the array. For example, the index -1 means the last index of an array. The scoping rules when creating or updating a variable are: @@ -62,7 +62,7 @@ The scoping rules when creating or updating a variable are: -# If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the previous variable scope is used. --# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the `-l` or `--local` flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global. +-# If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the ``-l`` or ``--local`` flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global. The exporting rules when creating or updating a variable are identical to the scoping rules for variables: @@ -78,9 +78,9 @@ In query mode, the scope to be examined can be specified. In erase mode, if variable indices are specified, only the specified slices of the array variable will be erased. -`set` requires all options to come before any other arguments. For example, `set flags -l` will have the effect of setting the value of the variable `flags` to '-l', not making the variable local. +``set`` requires all options to come before any other arguments. For example, ``set flags -l`` will have the effect of setting the value of the variable ``flags`` to '-l', not making the variable local. -In assignment mode, `set` does not modify the exit status. This allows simultaneous capture of the output and exit status of a subcommand, e.g. `if set output (command)`. In query mode, the exit status is the number of variables that were not found. In erase mode, `set` exits with a zero exit status in case of success, with a non-zero exit status if the commandline was invalid, if the variable was write-protected or if the variable did not exist. +In assignment mode, ``set`` does not modify the exit status. This allows simultaneous capture of the output and exit status of a subcommand, e.g. ``if set output (command)``. In query mode, the exit status is the number of variables that were not found. In erase mode, ``set`` exits with a zero exit status in case of success, with a non-zero exit status if the commandline was invalid, if the variable was write-protected or if the variable did not exist. Examples @@ -108,7 +108,7 @@ Examples # Changes the fourth element of the $PATH array to ~/bin set PATH[4] ~/bin - # Outputs the path to Python if `type -p` returns true. + # Outputs the path to Python if ``type -p`` returns true. if set python_path (type -p python) echo "Python is at $python_path" end @@ -117,5 +117,5 @@ Examples Notes ------------ -Fish versions prior to 3.0 supported the syntax `set PATH[1] PATH[4] /bin /sbin`, which worked like -`set PATH[1 4] /bin /sbin`. This syntax was not widely used, and was ambiguous and inconsistent. +Fish versions prior to 3.0 supported the syntax ``set PATH[1] PATH[4] /bin /sbin``, which worked like +``set PATH[1 4] /bin /sbin``. This syntax was not widely used, and was ambiguous and inconsistent. diff --git a/sphinx_doc_src/cmds/set_color.rst b/sphinx_doc_src/cmds/set_color.rst index 7a330bc51..77aa432a0 100644 --- a/sphinx_doc_src/cmds/set_color.rst +++ b/sphinx_doc_src/cmds/set_color.rst @@ -10,24 +10,24 @@ set_color [OPTIONS] VALUE Description ------------ -`set_color` is used to control the color and styling of text in the terminal. `VALUE` corresponds to a reserved color name such as *red* or a RGB color value given as 3 or 6 hexadecimal digits. The *br*-, as in 'bright', forms are full-brightness variants of the 8 standard-brightness colors on many terminals. *brblack* has higher brightness than *black* - towards gray. A special keyword *normal* resets text formatting to terminal defaults. +``set_color`` is used to control the color and styling of text in the terminal. ``VALUE`` corresponds to a reserved color name such as *red* or a RGB color value given as 3 or 6 hexadecimal digits. The *br*-, as in 'bright', forms are full-brightness variants of the 8 standard-brightness colors on many terminals. *brblack* has higher brightness than *black* - towards gray. A special keyword *normal* resets text formatting to terminal defaults. Valid colors include: - *black*, *red*, *green*, *yellow*, *blue*, *magenta*, *cyan*, *white* - *brblack*, *brred*, *brgreen*, *bryellow*, *brblue*, *brmagenta*, *brcyan*, *brwhite* -An RGB value with three or six hex digits, such as A0FF33 or f2f can be used. `fish` will choose the closest supported color. A three digit value is equivalent to specifying each digit twice; e.g., `set_color 2BC` is the same as `set_color 22BBCC`. Hexadecimal RGB values can be in lower or uppercase. Depending on the capabilities of your terminal (and the level of support `set_color` has for it) the actual color may be approximated by a nearby matching reserved color name or `set_color` may not have an effect on color. A second color may be given as a desired fallback color. e.g. `set_color 124212` *brblue* will instruct set_color to use *brblue* if a terminal is not capable of the exact shade of grey desired. This is very useful when an 8 or 16 color terminal might otherwise not use a color. +An RGB value with three or six hex digits, such as A0FF33 or f2f can be used. ``fish`` will choose the closest supported color. A three digit value is equivalent to specifying each digit twice; e.g., ``set_color 2BC`` is the same as ``set_color 22BBCC``. Hexadecimal RGB values can be in lower or uppercase. Depending on the capabilities of your terminal (and the level of support ``set_color`` has for it) the actual color may be approximated by a nearby matching reserved color name or ``set_color`` may not have an effect on color. A second color may be given as a desired fallback color. e.g. ``set_color 124212`` *brblue* will instruct set_color to use *brblue* if a terminal is not capable of the exact shade of grey desired. This is very useful when an 8 or 16 color terminal might otherwise not use a color. The following options are available: -- `-b`, `--background` *COLOR* sets the background color. -- `-c`, `--print-colors` prints a list of the 16 named colors. -- `-o`, `--bold` sets bold mode. -- `-d`, `--dim` sets dim mode. -- `-i`, `--italics` sets italics mode. -- `-r`, `--reverse` sets reverse mode. -- `-u`, `--underline` sets underlined mode. +- ``-b``, ``--background`` *COLOR* sets the background color. +- ``-c``, ``--print-colors`` prints a list of the 16 named colors. +- ``-o``, ``--bold`` sets bold mode. +- ``-d``, ``--dim`` sets dim mode. +- ``-i``, ``--italics`` sets italics mode. +- ``-r``, ``--reverse`` sets reverse mode. +- ``-u``, ``--underline`` sets underlined mode. Using the *normal* keyword will reset foreground, background, and all formatting back to default. @@ -36,8 +36,8 @@ Notes 1. Using the *normal* keyword will reset both background and foreground colors to whatever is the default for the terminal. 2. Setting the background color only affects subsequently written characters. Fish provides no way to set the background color for the entire terminal window. Configuring the window background color (and other attributes such as its opacity) has to be done using whatever mechanisms the terminal provides. -3. Some terminals use the `--bold` escape sequence to switch to a brighter color set rather than increasing the weight of text. -4. `set_color` works by printing sequences of characters to *stdout*. If used in command substitution or a pipe, these characters will also be captured. This may or may not be desirable. Checking the exit code of `isatty stdout` before using `set_color` can be useful to decide not to colorize output in a script. +3. Some terminals use the ``--bold`` escape sequence to switch to a brighter color set rather than increasing the weight of text. +4. ``set_color`` works by printing sequences of characters to *stdout*. If used in command substitution or a pipe, these characters will also be captured. This may or may not be desirable. Checking the exit code of ``isatty stdout`` before using ``set_color`` can be useful to decide not to colorize output in a script. Examples ------------ @@ -55,12 +55,12 @@ Examples Terminal Capability Detection ------------ -Fish uses a heuristic to decide if a terminal supports the 256-color palette as opposed to the more limited 16 color palette of older terminals. Support can be forced on by setting `fish_term256` to *1*. If `$TERM` contains "256color" (e.g., *xterm-256color*), 256-color support is enabled. If `$TERM` contains *xterm*, 256 color support is enabled (except for MacOS: `$TERM_PROGRAM` and `$TERM_PROGRAM_VERSION` are used to detect Terminal.app from MacOS 10.6; support is disabled here it because it is known that it reports `xterm` and only supports 16 colors. +Fish uses a heuristic to decide if a terminal supports the 256-color palette as opposed to the more limited 16 color palette of older terminals. Support can be forced on by setting ``fish_term256`` to *1*. If ``$TERM`` contains "256color" (e.g., *xterm-256color*), 256-color support is enabled. If ``$TERM`` contains *xterm*, 256 color support is enabled (except for MacOS: ``$TERM_PROGRAM`` and ``$TERM_PROGRAM_VERSION`` are used to detect Terminal.app from MacOS 10.6; support is disabled here it because it is known that it reports ``xterm`` and only supports 16 colors. -If terminfo reports 256 color support for a terminal, support will always be enabled. To debug color palette problems, `tput colors` may be useful to see the number of colors in terminfo for a terminal. Fish launched as `fish -d2` will include diagnostic messages that indicate the color support mode in use. +If terminfo reports 256 color support for a terminal, support will always be enabled. To debug color palette problems, ``tput colors`` may be useful to see the number of colors in terminfo for a terminal. Fish launched as ``fish -d2`` will include diagnostic messages that indicate the color support mode in use. -Many terminals support 24-bit (i.e., true-color) color escape sequences. This includes modern xterm, Gnome Terminal, Konsole, and iTerm2. Fish attempts to detect such terminals through various means in `config.fish` You can explicitly force that support via `set fish_term24bit 1`. +Many terminals support 24-bit (i.e., true-color) color escape sequences. This includes modern xterm, Gnome Terminal, Konsole, and iTerm2. Fish attempts to detect such terminals through various means in ``config.fish`` You can explicitly force that support via ``set fish_term24bit 1``. -The `set_color` command uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Fish will assume that all terminals can use the [ANSI X3.64](https://en.wikipedia.org/wiki/ANSI_escape_code) escape sequences if the terminfo definition indicates a color below 16 is not supported. +The ``set_color`` command uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Fish will assume that all terminals can use the [ANSI X3.64](https://en.wikipedia.org/wiki/ANSI_escape_code) escape sequences if the terminfo definition indicates a color below 16 is not supported. Support for italics, dim, reverse, and other modes is not guaranteed in all terminal emulators. Fish attempts to determine if the terminal supports these modes even if the terminfo database may not be up-to-date. diff --git a/sphinx_doc_src/cmds/source.rst b/sphinx_doc_src/cmds/source.rst index a560608d7..8c1d2f710 100644 --- a/sphinx_doc_src/cmds/source.rst +++ b/sphinx_doc_src/cmds/source.rst @@ -11,13 +11,13 @@ somecommand | source Description ------------ -`source` evaluates the commands of the specified file in the current shell. This is different from starting a new process to perform the commands (i.e. `fish < FILENAME`) since the commands will be evaluated by the current shell, which means that changes in shell variables will affect the current shell. If additional arguments are specified after the file name, they will be inserted into the `$argv` variable. The `$argv` variable will not include the name of the sourced file. +``source`` evaluates the commands of the specified file in the current shell. This is different from starting a new process to perform the commands (i.e. ``fish < FILENAME``) since the commands will be evaluated by the current shell, which means that changes in shell variables will affect the current shell. If additional arguments are specified after the file name, they will be inserted into the ``$argv`` variable. The ``$argv`` variable will not include the name of the sourced file. -If no file is specified and stdin is not the terminal, or if the file name '`-`' is used, stdin will be read. +If no file is specified and stdin is not the terminal, or if the file name '``-``' is used, stdin will be read. -The return status of `source` is the return status of the last job to execute. If something goes wrong while opening or reading the file, `source` exits with a non-zero status. +The return status of ``source`` is the return status of the last job to execute. If something goes wrong while opening or reading the file, ``source`` exits with a non-zero status. -`.` (a single period) is an alias for the `source` command. The use of `.` is deprecated in favour of `source`, and `.` will be removed in a future version of fish. +``.`` (a single period) is an alias for the ``source`` command. The use of ``.`` is deprecated in favour of ``source``, and ``.`` will be removed in a future version of fish. Example @@ -33,4 +33,4 @@ Example \subsection Caveats -In fish versions prior to 2.3.0 the `$argv` variable would have a single element (the name of the sourced file) if no arguments are present. Otherwise it would contain arguments without the name of the sourced file. That behavior was very confusing and unlike other shells such as bash and zsh. +In fish versions prior to 2.3.0 the ``$argv`` variable would have a single element (the name of the sourced file) if no arguments are present. Otherwise it would contain arguments without the name of the sourced file. That behavior was very confusing and unlike other shells such as bash and zsh. diff --git a/sphinx_doc_src/cmds/status.rst b/sphinx_doc_src/cmds/status.rst index aa1422f9f..40503f60b 100644 --- a/sphinx_doc_src/cmds/status.rst +++ b/sphinx_doc_src/cmds/status.rst @@ -26,46 +26,46 @@ status test-feature FEATURE Description ------------ -With no arguments, `status` displays a summary of the current login and job control status of the shell. +With no arguments, ``status`` displays a summary of the current login and job control status of the shell. The following operations (sub-commands) are available: -- `is-command-sub` returns 0 if fish is currently executing a command substitution. Also `-c` or `--is-command-substitution`. +- ``is-command-sub`` returns 0 if fish is currently executing a command substitution. Also ``-c`` or ``--is-command-substitution``. -- `is-block` returns 0 if fish is currently executing a block of code. Also `-b` or `--is-block`. +- ``is-block`` returns 0 if fish is currently executing a block of code. Also ``-b`` or ``--is-block``. -- `is-breakpoint` returns 0 if fish is currently showing a prompt in the context of a `breakpoint` command. See also the `fish_breakpoint_prompt` function. +- ``is-breakpoint`` returns 0 if fish is currently showing a prompt in the context of a ``breakpoint`` command. See also the ``fish_breakpoint_prompt`` function. -- `is-interactive` returns 0 if fish is interactive - that is, connected to a keyboard. Also `-i` or `--is-interactive`. +- ``is-interactive`` returns 0 if fish is interactive - that is, connected to a keyboard. Also ``-i`` or ``--is-interactive``. -- `is-login` returns 0 if fish is a login shell - that is, if fish should perform login tasks such as setting up the PATH. Also `-l` or `--is-login`. +- ``is-login`` returns 0 if fish is a login shell - that is, if fish should perform login tasks such as setting up the PATH. Also ``-l`` or ``--is-login``. -- `is-full-job-control` returns 0 if full job control is enabled. Also `--is-full-job-control` (no short flag). +- ``is-full-job-control`` returns 0 if full job control is enabled. Also ``--is-full-job-control`` (no short flag). -- `is-interactive-job-control` returns 0 if interactive job control is enabled. Also, `--is-interactive-job-control` (no short flag). +- ``is-interactive-job-control`` returns 0 if interactive job control is enabled. Also, ``--is-interactive-job-control`` (no short flag). -- `is-no-job-control` returns 0 if no job control is enabled. Also `--is-no-job-control` (no short flag). +- ``is-no-job-control`` returns 0 if no job control is enabled. Also ``--is-no-job-control`` (no short flag). -- `filename` prints the filename of the currently running script. Also `current-filename`, `-f` or `--current-filename`. +- ``filename`` prints the filename of the currently running script. Also ``current-filename``, ``-f`` or ``--current-filename``. -- `fish-path` prints the absolute path to the currently executing instance of fish. +- ``fish-path`` prints the absolute path to the currently executing instance of fish. -- `function` prints the name of the currently called function if able, when missing displays "Not a - function" (or equivalent translated string). Also `current-function`, `-u` or `--current-function`. +- ``function`` prints the name of the currently called function if able, when missing displays "Not a + function" (or equivalent translated string). Also ``current-function``, ``-u`` or ``--current-function``. -- `line-number` prints the line number of the currently running script. Also `current-line-number`, `-n` or `--current-line-number`. +- ``line-number`` prints the line number of the currently running script. Also ``current-line-number``, ``-n`` or ``--current-line-number``. -- `stack-trace` prints a stack trace of all function calls on the call stack. Also `print-stack-trace`, `-t` or `--print-stack-trace`. +- ``stack-trace`` prints a stack trace of all function calls on the call stack. Also ``print-stack-trace``, ``-t`` or ``--print-stack-trace``. -- `job-control CONTROL-TYPE` sets the job control type, which can be `none`, `full`, or `interactive`. Also `-j CONTROL-TYPE` or `--job-control=CONTROL-TYPE`. +- ``job-control CONTROL-TYPE`` sets the job control type, which can be ``none``, ``full``, or ``interactive``. Also ``-j CONTROL-TYPE`` or ``--job-control=CONTROL-TYPE``. -- `features` lists all available feature flags. +- ``features`` lists all available feature flags. -- `test-feature FEATURE` returns 0 when FEATURE is enabled, 1 if it is disabled, and 2 if it is not recognized. +- ``test-feature FEATURE`` returns 0 when FEATURE is enabled, 1 if it is disabled, and 2 if it is not recognized. Notes ------------ -For backwards compatibility each subcommand can also be specified as a long or short option. For example, rather than `status is-login` you can type `status --is-login`. The flag forms are deprecated and may be removed in a future release (but not before fish 3.0). +For backwards compatibility each subcommand can also be specified as a long or short option. For example, rather than ``status is-login`` you can type ``status --is-login``. The flag forms are deprecated and may be removed in a future release (but not before fish 3.0). You can only specify one subcommand per invocation even if you use the flag form of the subcommand. diff --git a/sphinx_doc_src/cmds/string.rst b/sphinx_doc_src/cmds/string.rst index 7a71f275f..bbfca183e 100644 --- a/sphinx_doc_src/cmds/string.rst +++ b/sphinx_doc_src/cmds/string.rst @@ -31,159 +31,159 @@ string upper [(-q | --quiet)] [STRING...] Description ------------ -`string` performs operations on strings. +``string`` performs operations on strings. STRING arguments are taken from the command line unless standard input is connected to a pipe or a file, in which case they are read from standard input, one STRING per line. It is an error to supply STRING arguments on the command line and on standard input. -Arguments beginning with `-` are normally interpreted as switches; `--` causes the following arguments not to be treated as switches even if they begin with `-`. Switches and required arguments are recognized only on the command line. +Arguments beginning with ``-`` are normally interpreted as switches; ``--`` causes the following arguments not to be treated as switches even if they begin with ``-``. Switches and required arguments are recognized only on the command line. -Most subcommands accept a `-q` or `--quiet` switch, which suppresses the usual output but exits with the documented status. +Most subcommands accept a ``-q`` or ``--quiet`` switch, which suppresses the usual output but exits with the documented status. The following subcommands are available. "escape" subcommand ------------ -`string escape` escapes each STRING in one of three ways. The first is `--style=script`. This is the default. It alters the string such that it can be passed back to `eval` to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If `-n` or `--no-quoted` is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise. +``string escape`` escapes each STRING in one of three ways. The first is ``--style=script``. This is the default. It alters the string such that it can be passed back to ``eval`` to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If ``-n`` or ``--no-quoted`` is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise. -`--style=var` ensures the string can be used as a variable name by hex encoding any non-alphanumeric characters. The string is first converted to UTF-8 before being encoded. +``--style=var`` ensures the string can be used as a variable name by hex encoding any non-alphanumeric characters. The string is first converted to UTF-8 before being encoded. -`--style=url` ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF-8 before being encoded. +``--style=url`` ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF-8 before being encoded. -`--style=regex` escapes an input string for literal matching within a regex expression. The string is first converted to UTF-8 before being encoded. +``--style=regex`` escapes an input string for literal matching within a regex expression. The string is first converted to UTF-8 before being encoded. -`string unescape` performs the inverse of the `string escape` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing `string unescape --style=var (string escape --style=var $str)` will return the original string. There is no support for unescaping pcre2. +``string unescape`` performs the inverse of the ``string escape`` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing ``string unescape --style=var (string escape --style=var $str)`` will return the original string. There is no support for unescaping pcre2. "join" subcommand ------------ -`string join` joins its STRING arguments into a single string separated by SEP, which can be an empty string. Exit status: 0 if at least one join was performed, or 1 otherwise. +``string join`` joins its STRING arguments into a single string separated by SEP, which can be an empty string. Exit status: 0 if at least one join was performed, or 1 otherwise. \subsection string-join0 "join0" subcommand -`string join` joins its STRING arguments into a single string separated by the zero byte (NUL), and adds a trailing NUL. This is most useful in conjunction with tools that accept NUL-delimited input, such as `sort -z`. Exit status: 0 if at least one join was performed, or 1 otherwise. +``string join`` joins its STRING arguments into a single string separated by the zero byte (NUL), and adds a trailing NUL. This is most useful in conjunction with tools that accept NUL-delimited input, such as ``sort -z``. Exit status: 0 if at least one join was performed, or 1 otherwise. "length" subcommand ------------ -`string length` reports the length of each string argument in characters. Exit status: 0 if at least one non-empty STRING was given, or 1 otherwise. +``string length`` reports the length of each string argument in characters. Exit status: 0 if at least one non-empty STRING was given, or 1 otherwise. "lower" subcommand ------------ -`string lower` converts each string argument to lowercase. Exit status: 0 if at least one string was converted to lowercase, else 1. This means that in conjunction with the `-q` flag you can readily test whether a string is already lowercase. +``string lower`` converts each string argument to lowercase. Exit status: 0 if at least one string was converted to lowercase, else 1. This means that in conjunction with the ``-q`` flag you can readily test whether a string is already lowercase. "match" subcommand ------------ -`string match` tests each STRING against PATTERN and prints matching substrings. Only the first match for each STRING is reported unless `-a` or `--all` is given, in which case all matches are reported. +``string match`` tests each STRING against PATTERN and prints matching substrings. Only the first match for each STRING is reported unless ``-a`` or ``--all`` is given, in which case all matches are reported. -If you specify the `-e` or `--entire` then each matching string is printed including any prefix or suffix not matched by the pattern (equivalent to `grep` without the `-o` flag). You can, obviously, achieve the same result by prepending and appending `*` or `.*` depending on whether or not you have specified the `--regex` flag. The `--entire` flag is simply a way to avoid having to complicate the pattern in that fashion and make the intent of the `string match` clearer. Without `--entire` and `--regex`, a PATTERN will need to match the entire STRING before it will be reported. +If you specify the ``-e`` or ``--entire`` then each matching string is printed including any prefix or suffix not matched by the pattern (equivalent to ``grep`` without the ``-o`` flag). You can, obviously, achieve the same result by prepending and appending ``*`` or ``.*`` depending on whether or not you have specified the ``--regex`` flag. The ``--entire`` flag is simply a way to avoid having to complicate the pattern in that fashion and make the intent of the ``string match`` clearer. Without ``--entire`` and ``--regex``, a PATTERN will need to match the entire STRING before it will be reported. -Matching can be made case-insensitive with `--ignore-case` or `-i`. +Matching can be made case-insensitive with ``--ignore-case`` or ``-i``. -If `--index` or `-n` is given, each match is reported as a 1-based start position and a length. By default, PATTERN is interpreted as a glob pattern matched against each entire STRING argument. A glob pattern is only considered a valid match if it matches the entire STRING. +If ``--index`` or ``-n`` is given, each match is reported as a 1-based start position and a length. By default, PATTERN is interpreted as a glob pattern matched against each entire STRING argument. A glob pattern is only considered a valid match if it matches the entire STRING. -If `--regex` or `-r` is given, PATTERN is interpreted as a Perl-compatible regular expression, which does not have to match the entire STRING. For a regular expression containing capturing groups, multiple items will be reported for each match, one for the entire match and one for each capturing group. With this, only the matching part of the STRING will be reported, unless `--entire` is given. +If ``--regex`` or ``-r`` is given, PATTERN is interpreted as a Perl-compatible regular expression, which does not have to match the entire STRING. For a regular expression containing capturing groups, multiple items will be reported for each match, one for the entire match and one for each capturing group. With this, only the matching part of the STRING will be reported, unless ``--entire`` is given. -If `--invert` or `-v` is used the selected lines will be only those which do not match the given glob pattern or regular expression. +If ``--invert`` or ``-v`` is used the selected lines will be only those which do not match the given glob pattern or regular expression. Exit status: 0 if at least one match was found, or 1 otherwise. "repeat" subcommand ------------ -`string repeat` repeats the STRING `-n` or `--count` times. The `-m` or `--max` option will limit the number of outputted char (excluding the newline). This option can be used by itself or in conjunction with `--count`. If both `--count` and `--max` are present, max char will be outputed unless the final repeated string size is less than max, in that case, the string will repeat until count has been reached. Both `--count` and `--max` will accept a number greater than or equal to zero, in the case of zero, nothing will be outputed. If `-N` or `--no-newline` is given, the output won't contain a newline character at the end. Exit status: 0 if yielded string is not empty, 1 otherwise. +``string repeat`` repeats the STRING ``-n`` or ``--count`` times. The ``-m`` or ``--max`` option will limit the number of outputted char (excluding the newline). This option can be used by itself or in conjunction with ``--count``. If both ``--count`` and ``--max`` are present, max char will be outputed unless the final repeated string size is less than max, in that case, the string will repeat until count has been reached. Both ``--count`` and ``--max`` will accept a number greater than or equal to zero, in the case of zero, nothing will be outputed. If ``-N`` or ``--no-newline`` is given, the output won't contain a newline character at the end. Exit status: 0 if yielded string is not empty, 1 otherwise. "replace" subcommand ------------ -`string replace` is similar to `string match` but replaces non-overlapping matching substrings with a replacement string and prints the result. By default, PATTERN is treated as a literal substring to be matched. +``string replace`` is similar to ``string match`` but replaces non-overlapping matching substrings with a replacement string and prints the result. By default, PATTERN is treated as a literal substring to be matched. -If `-r` or `--regex` is given, PATTERN is interpreted as a Perl-compatible regular expression, and REPLACEMENT can contain C-style escape sequences like `\t` as well as references to capturing groups by number or name as `$n` or `${n}`. +If ``-r`` or ``--regex`` is given, PATTERN is interpreted as a Perl-compatible regular expression, and REPLACEMENT can contain C-style escape sequences like ``\t`` as well as references to capturing groups by number or name as ``$n`` or ``${n}``. -If you specify the `-f` or `--filter` flag then each input string is printed only if a replacement was done. This is useful where you would otherwise use this idiom: `a_cmd | string match pattern | string replace pattern new_pattern`. You can instead just write `a_cmd | string replace --filter pattern new_pattern`. +If you specify the ``-f`` or ``--filter`` flag then each input string is printed only if a replacement was done. This is useful where you would otherwise use this idiom: ``a_cmd | string match pattern | string replace pattern new_pattern``. You can instead just write ``a_cmd | string replace --filter pattern new_pattern``. Exit status: 0 if at least one replacement was performed, or 1 otherwise. "split" subcommand ------------ -`string split` splits each STRING on the separator SEP, which can be an empty string. If `-m` or `--max` is specified, at most MAX splits are done on each STRING. If `-r` or `--right` is given, splitting is performed right-to-left. This is useful in combination with `-m` or `--max`. With `-n` or `--no-empty`, empty results are excluded from consideration (e.g. `hello\n\nworld` would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise. +``string split`` splits each STRING on the separator SEP, which can be an empty string. If ``-m`` or ``--max`` is specified, at most MAX splits are done on each STRING. If ``-r`` or ``--right`` is given, splitting is performed right-to-left. This is useful in combination with ``-m`` or ``--max``. With ``-n`` or ``--no-empty``, empty results are excluded from consideration (e.g. ``hello\n\nworld`` would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise. -See also `read --delimiter`. +See also ``read --delimiter``. \subsection string-split0 "split0" subcommand -`string split0` splits each STRING on the zero byte (NUL). Options are the same as `string split` except that no separator is given. +``string split0`` splits each STRING on the zero byte (NUL). Options are the same as ``string split`` except that no separator is given. -`split0` has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as `find -print0` or `sort -z`. See split0 examples below. +``split0`` has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as ``find -print0`` or ``sort -z``. See split0 examples below. "sub" subcommand ------------ -`string sub` prints a substring of each string argument. The start of the substring can be specified with `-s` or `--start` followed by a 1-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with `-l` or `--length`. If the length is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise. +``string sub`` prints a substring of each string argument. The start of the substring can be specified with ``-s`` or ``--start`` followed by a 1-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with ``-l`` or ``--length``. If the length is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise. "trim" subcommand ------------ -`string trim` removes leading and trailing whitespace from each STRING. If `-l` or `--left` is given, only leading whitespace is removed. If `-r` or `--right` is given, only trailing whitespace is trimmed. The `-c` or `--chars` switch causes the characters in CHARS to be removed instead of whitespace. Exit status: 0 if at least one character was trimmed, or 1 otherwise. +``string trim`` removes leading and trailing whitespace from each STRING. If ``-l`` or ``--left`` is given, only leading whitespace is removed. If ``-r`` or ``--right`` is given, only trailing whitespace is trimmed. The ``-c`` or ``--chars`` switch causes the characters in CHARS to be removed instead of whitespace. Exit status: 0 if at least one character was trimmed, or 1 otherwise. "upper" subcommand ------------ -`string upper` converts each string argument to uppercase. Exit status: 0 if at least one string was converted to uppercase, else 1. This means that in conjunction with the `-q` flag you can readily test whether a string is already uppercase. +``string upper`` converts each string argument to uppercase. Exit status: 0 if at least one string was converted to uppercase, else 1. This means that in conjunction with the ``-q`` flag you can readily test whether a string is already uppercase. Regular Expressions ------------ -Both the `match` and `replace` subcommand support regular expressions when used with the `-r` or `--regex` option. The dialect is that of PCRE2. +Both the ``match`` and ``replace`` subcommand support regular expressions when used with the ``-r`` or ``--regex`` option. The dialect is that of PCRE2. -In general, special characters are special by default, so `a+` matches one or more "a"s, while `a\+` matches an "a" and then a "+". `(a+)` matches one or more "a"s in a capturing group (`(?:XXXX)` denotes a non-capturing group). For the replacement parameter of `replace`, `$n` refers to the n-th group of the match. In the match parameter, `\n` (e.g. `\1`) refers back to groups. +In general, special characters are special by default, so ``a+`` matches one or more "a"s, while ``a\+`` matches an "a" and then a "+". ``(a+)`` matches one or more "a"s in a capturing group (``(?:XXXX)`` denotes a non-capturing group). For the replacement parameter of ``replace``, ``$n`` refers to the n-th group of the match. In the match parameter, ``\n`` (e.g. ``\1``) refers back to groups. Some features include repetitions: -- `*` refers to 0 or more repetitions of the previous expression -- `+` 1 or more -- `?` 0 or 1. -- `{n}` to exactly n (where n is a number) -- `{n,m}` at least n, no more than m. -- `{n,}` n or more +- ``*`` refers to 0 or more repetitions of the previous expression +- ``+`` 1 or more +- ``?`` 0 or 1. +- ``{n}`` to exactly n (where n is a number) +- ``{n,m}`` at least n, no more than m. +- ``{n,}`` n or more Character classes, some of the more important: -- `.` any character except newline -- `\d` a decimal digit and `\D`, not a decimal digit -- `\s` whitespace and `\S`, not whitespace -- `\w` a "word" character and `\W`, a "non-word" character -- `[...]` (where "..." is some characters) is a character set -- `[^...]` is the inverse of the given character set -- `[x-y]` is the range of characters from x-y -- `[[:xxx:]]` is a named character set -- `[[:^xxx:]]` is the inverse of a named character set -- `[[:alnum:]]` : "alphanumeric" -- `[[:alpha:]]` : "alphabetic" -- `[[:ascii:]]` : "0-127" -- `[[:blank:]]` : "space or tab" -- `[[:cntrl:]]` : "control character" -- `[[:digit:]]` : "decimal digit" -- `[[:graph:]]` : "printing, excluding space" -- `[[:lower:]]` : "lower case letter" -- `[[:print:]]` : "printing, including space" -- `[[:punct:]]` : "printing, excluding alphanumeric" -- `[[:space:]]` : "white space" -- `[[:upper:]]` : "upper case letter" -- `[[:word:]]` : "same as \w" -- `[[:xdigit:]]` : "hexadecimal digit" +- ``.`` any character except newline +- ``\d`` a decimal digit and ``\D``, not a decimal digit +- ``\s`` whitespace and ``\S``, not whitespace +- ``\w`` a "word" character and ``\W``, a "non-word" character +- ``[...]`` (where "..." is some characters) is a character set +- ``[^...]`` is the inverse of the given character set +- ``[x-y]`` is the range of characters from x-y +- ``[[:xxx:]]`` is a named character set +- ``[[:^xxx:]]`` is the inverse of a named character set +- ``[[:alnum:]]`` : "alphanumeric" +- ``[[:alpha:]]`` : "alphabetic" +- ``[[:ascii:]]`` : "0-127" +- ``[[:blank:]]`` : "space or tab" +- ``[[:cntrl:]]`` : "control character" +- ``[[:digit:]]`` : "decimal digit" +- ``[[:graph:]]`` : "printing, excluding space" +- ``[[:lower:]]`` : "lower case letter" +- ``[[:print:]]`` : "printing, including space" +- ``[[:punct:]]`` : "printing, excluding alphanumeric" +- ``[[:space:]]`` : "white space" +- ``[[:upper:]]`` : "upper case letter" +- ``[[:word:]]`` : "same as \w" +- ``[[:xdigit:]]`` : "hexadecimal digit" Groups: -- `(...)` is a capturing group -- `(?:...)` is a non-capturing group -- `\n` is a backreference (where n is the number of the group, starting with 1) -- `$n` is a reference from the replacement expression to a group in the match expression. +- ``(...)`` is a capturing group +- ``(?:...)`` is a non-capturing group +- ``\n`` is a backreference (where n is the number of the group, starting with 1) +- ``$n`` is a reference from the replacement expression to a group in the match expression. And some other things: -- `\b` denotes a word boundary, `\B` is not a word boundary. -- `^` is the start of the string or line, `$` the end. -- `|` is "alternation", i.e. the "or". +- ``\b`` denotes a word boundary, ``\B`` is not a word boundary. +- ``^`` is the start of the string or line, ``$`` the end. +- ``|`` is "alternation", i.e. the "or". Examples ------------ diff --git a/sphinx_doc_src/cmds/suspend.rst b/sphinx_doc_src/cmds/suspend.rst index e0b3036b2..21559783a 100644 --- a/sphinx_doc_src/cmds/suspend.rst +++ b/sphinx_doc_src/cmds/suspend.rst @@ -10,9 +10,9 @@ suspend [--force] Description ------------ -`suspend` suspends execution of the current shell by sending it a +``suspend`` suspends execution of the current shell by sending it a SIGTSTP signal, returning to the controlling process. It can be resumed later by sending it a SIGCONT. In order to prevent suspending a shell that doesn't have a controlling process, it will not suspend the shell if it is a login shell. This requirement is bypassed -if the `--force` option is given or the shell is not interactive. \ No newline at end of file +if the ``--force`` option is given or the shell is not interactive. \ No newline at end of file diff --git a/sphinx_doc_src/cmds/switch.rst b/sphinx_doc_src/cmds/switch.rst index 531240767..92779c03c 100644 --- a/sphinx_doc_src/cmds/switch.rst +++ b/sphinx_doc_src/cmds/switch.rst @@ -10,9 +10,9 @@ switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end Description ------------ -`switch` performs one of several blocks of commands, depending on whether a specified value equals one of several wildcarded values. `case` is used together with the `switch` statement in order to determine which block should be executed. +``switch`` performs one of several blocks of commands, depending on whether a specified value equals one of several wildcarded values. ``case`` is used together with the ``switch`` statement in order to determine which block should be executed. -Each `case` command is given one or more parameters. The first `case` command with a parameter that matches the string specified in the switch command will be evaluated. `case` parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames. +Each ``case`` command is given one or more parameters. The first ``case`` command with a parameter that matches the string specified in the switch command will be evaluated. ``case`` parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames. Note that fish does not fall through on case statements. Only the first matching case is executed. @@ -42,5 +42,5 @@ If the variable \$animal contains the name of an animal, the following code woul end -If the above code was run with `$animal` set to `whale`, the output -would be `mammal`. +If the above code was run with ``$animal`` set to ``whale``, the output +would be ``mammal``. diff --git a/sphinx_doc_src/cmds/test.rst b/sphinx_doc_src/cmds/test.rst index dae2b6642..b807fb8c5 100644 --- a/sphinx_doc_src/cmds/test.rst +++ b/sphinx_doc_src/cmds/test.rst @@ -13,101 +13,101 @@ Description Tests the expression given and sets the exit status to 0 if true, and 1 if false. An expression is made up of one or more operators and their arguments. -The first form (`test`) is preferred. For compatibility with other shells, the second form is available: a matching pair of square brackets (`[ [EXPRESSION ] ]`). +The first form (``test``) is preferred. For compatibility with other shells, the second form is available: a matching pair of square brackets (``[ [EXPRESSION ] ]``). This test is mostly POSIX-compatible. -When using a variable as an argument for a test operator you should almost always enclose it in double-quotes. There are only two situations it is safe to omit the quote marks. The first is when the argument is a literal string with no whitespace or other characters special to the shell (e.g., semicolon). For example, `test -b /my/file`. The second is using a variable that expands to exactly one element including if that element is the empty string (e.g., `set x ''`). If the variable is not set, set but with no value, or set to more than one value you must enclose it in double-quotes. For example, `test "$x" = "$y"`. Since it is always safe to enclose variables in double-quotes when used as `test` arguments that is the recommended practice. +When using a variable as an argument for a test operator you should almost always enclose it in double-quotes. There are only two situations it is safe to omit the quote marks. The first is when the argument is a literal string with no whitespace or other characters special to the shell (e.g., semicolon). For example, ``test -b /my/file``. The second is using a variable that expands to exactly one element including if that element is the empty string (e.g., ``set x ''``). If the variable is not set, set but with no value, or set to more than one value you must enclose it in double-quotes. For example, ``test "$x" = "$y"``. Since it is always safe to enclose variables in double-quotes when used as ``test`` arguments that is the recommended practice. Operators for files and directories ------------ -- `-b FILE` returns true if `FILE` is a block device. +- ``-b FILE`` returns true if ``FILE`` is a block device. -- `-c FILE` returns true if `FILE` is a character device. +- ``-c FILE`` returns true if ``FILE`` is a character device. -- `-d FILE` returns true if `FILE` is a directory. +- ``-d FILE`` returns true if ``FILE`` is a directory. -- `-e FILE` returns true if `FILE` exists. +- ``-e FILE`` returns true if ``FILE`` exists. -- `-f FILE` returns true if `FILE` is a regular file. +- ``-f FILE`` returns true if ``FILE`` is a regular file. -- `-g FILE` returns true if `FILE` has the set-group-ID bit set. +- ``-g FILE`` returns true if ``FILE`` has the set-group-ID bit set. -- `-G FILE` returns true if `FILE` exists and has the same group ID as the current user. +- ``-G FILE`` returns true if ``FILE`` exists and has the same group ID as the current user. -- `-k FILE` returns true if `FILE` has the sticky bit set. If the OS does not support the concept it returns false. See https://en.wikipedia.org/wiki/Sticky_bit. +- ``-k FILE`` returns true if ``FILE`` has the sticky bit set. If the OS does not support the concept it returns false. See https://en.wikipedia.org/wiki/Sticky_bit. -- `-L FILE` returns true if `FILE` is a symbolic link. +- ``-L FILE`` returns true if ``FILE`` is a symbolic link. -- `-O FILE` returns true if `FILE` exists and is owned by the current user. +- ``-O FILE`` returns true if ``FILE`` exists and is owned by the current user. -- `-p FILE` returns true if `FILE` is a named pipe. +- ``-p FILE`` returns true if ``FILE`` is a named pipe. -- `-r FILE` returns true if `FILE` is marked as readable. +- ``-r FILE`` returns true if ``FILE`` is marked as readable. -- `-s FILE` returns true if the size of `FILE` is greater than zero. +- ``-s FILE`` returns true if the size of ``FILE`` is greater than zero. -- `-S FILE` returns true if `FILE` is a socket. +- ``-S FILE`` returns true if ``FILE`` is a socket. -- `-t FD` returns true if the file descriptor `FD` is a terminal (TTY). +- ``-t FD`` returns true if the file descriptor ``FD`` is a terminal (TTY). -- `-u FILE` returns true if `FILE` has the set-user-ID bit set. +- ``-u FILE`` returns true if ``FILE`` has the set-user-ID bit set. -- `-w FILE` returns true if `FILE` is marked as writable; note that this does not check if the filesystem is read-only. +- ``-w FILE`` returns true if ``FILE`` is marked as writable; note that this does not check if the filesystem is read-only. -- `-x FILE` returns true if `FILE` is marked as executable. +- ``-x FILE`` returns true if ``FILE`` is marked as executable. Operators for text strings ------------ -- `STRING1 = STRING2` returns true if the strings `STRING1` and `STRING2` are identical. +- ``STRING1 = STRING2`` returns true if the strings ``STRING1`` and ``STRING2`` are identical. -- `STRING1 != STRING2` returns true if the strings `STRING1` and `STRING2` are not identical. +- ``STRING1 != STRING2`` returns true if the strings ``STRING1`` and ``STRING2`` are not identical. -- `-n STRING` returns true if the length of `STRING` is non-zero. +- ``-n STRING`` returns true if the length of ``STRING`` is non-zero. -- `-z STRING` returns true if the length of `STRING` is zero. +- ``-z STRING`` returns true if the length of ``STRING`` is zero. Operators to compare and examine numbers ------------ -- `NUM1 -eq NUM2` returns true if `NUM1` and `NUM2` are numerically equal. +- ``NUM1 -eq NUM2`` returns true if ``NUM1`` and ``NUM2`` are numerically equal. -- `NUM1 -ne NUM2` returns true if `NUM1` and `NUM2` are not numerically equal. +- ``NUM1 -ne NUM2`` returns true if ``NUM1`` and ``NUM2`` are not numerically equal. -- `NUM1 -gt NUM2` returns true if `NUM1` is greater than `NUM2`. +- ``NUM1 -gt NUM2`` returns true if ``NUM1`` is greater than ``NUM2``. -- `NUM1 -ge NUM2` returns true if `NUM1` is greater than or equal to `NUM2`. +- ``NUM1 -ge NUM2`` returns true if ``NUM1`` is greater than or equal to ``NUM2``. -- `NUM1 -lt NUM2` returns true if `NUM1` is less than `NUM2`. +- ``NUM1 -lt NUM2`` returns true if ``NUM1`` is less than ``NUM2``. -- `NUM1 -le NUM2` returns true if `NUM1` is less than or equal to `NUM2`. +- ``NUM1 -le NUM2`` returns true if ``NUM1`` is less than or equal to ``NUM2``. Both integers and floating point numbers are supported. Operators to combine expressions ------------ -- `COND1 -a COND2` returns true if both `COND1` and `COND2` are true. +- ``COND1 -a COND2`` returns true if both ``COND1`` and ``COND2`` are true. -- `COND1 -o COND2` returns true if either `COND1` or `COND2` are true. +- ``COND1 -o COND2`` returns true if either ``COND1`` or ``COND2`` are true. -Expressions can be inverted using the `!` operator: +Expressions can be inverted using the ``!`` operator: -- `! EXPRESSION` returns true if `EXPRESSION` is false, and false if `EXPRESSION` is true. +- ``! EXPRESSION`` returns true if ``EXPRESSION`` is false, and false if ``EXPRESSION`` is true. Expressions can be grouped using parentheses. -- `( EXPRESSION )` returns the value of `EXPRESSION`. +- ``( EXPRESSION )`` returns the value of ``EXPRESSION``. - Note that parentheses will usually require escaping with `\(` to avoid being interpreted as a command substitution. + Note that parentheses will usually require escaping with ``\(`` to avoid being interpreted as a command substitution. Examples ------------ -If the `/tmp` directory exists, copy the `/etc/motd` file to it: +If the ``/tmp`` directory exists, copy the ``/etc/motd`` file to it: @@ -118,7 +118,7 @@ If the `/tmp` directory exists, copy the `/etc/motd` file to it: end -If the variable `MANPATH` is defined and not empty, print the contents. (If `MANPATH` is not defined, then it will expand to zero arguments, unless quoted.) +If the variable ``MANPATH`` is defined and not empty, print the contents. (If ``MANPATH`` is not defined, then it will expand to zero arguments, unless quoted.) @@ -129,7 +129,7 @@ If the variable `MANPATH` is defined and not empty, print the contents. (If `MAN end -Parentheses and the `-o` and `-a` operators can be combined to produce more complicated expressions. In this example, success is printed if there is a `/foo` or `/bar` file as well as a `/baz` or `/bat` file. +Parentheses and the ``-o`` and ``-a`` operators can be combined to produce more complicated expressions. In this example, success is printed if there is a ``/foo`` or ``/bar`` file as well as a ``/baz`` or ``/bat`` file. @@ -187,10 +187,10 @@ which is logically equivalent to the following: Standards ------------ -`test` implements a subset of the IEEE Std 1003.1-2008 (POSIX.1) standard. The following exceptions apply: +``test`` implements a subset of the IEEE Std 1003.1-2008 (POSIX.1) standard. The following exceptions apply: -- The `<` and `>` operators for comparing strings are not implemented. +- The ``<`` and ``>`` operators for comparing strings are not implemented. -- Because this test is a shell builtin and not a standalone utility, using the -c flag on a special file descriptors like standard input and output may not return the same result when invoked from within a pipe as one would expect when invoking the `test` utility in another shell. +- Because this test is a shell builtin and not a standalone utility, using the -c flag on a special file descriptors like standard input and output may not return the same result when invoked from within a pipe as one would expect when invoking the ``test`` utility in another shell. - In cases such as this, one can use `command` `test` to explicitly use the system's standalone `test` rather than this `builtin` `test`. + In cases such as this, one can use ``command`` ``test`` to explicitly use the system's standalone ``test`` rather than this ``builtin`` ``test``. diff --git a/sphinx_doc_src/cmds/trap.rst b/sphinx_doc_src/cmds/trap.rst index 870c8bedb..76279ba8f 100644 --- a/sphinx_doc_src/cmds/trap.rst +++ b/sphinx_doc_src/cmds/trap.rst @@ -10,27 +10,27 @@ trap [OPTIONS] [[ARG] REASON ... ] Description ------------ -`trap` is a wrapper around the fish event delivery framework. It exists for backwards compatibility with POSIX shells. For other uses, it is recommended to define an event handler. +``trap`` is a wrapper around the fish event delivery framework. It exists for backwards compatibility with POSIX shells. For other uses, it is recommended to define an event handler. The following parameters are available: -- `ARG` is the command to be executed on signal delivery. +- ``ARG`` is the command to be executed on signal delivery. -- `REASON` is the name of the event to trap. For example, a signal like `INT` or `SIGINT`, or the special symbol `EXIT`. +- ``REASON`` is the name of the event to trap. For example, a signal like ``INT`` or ``SIGINT``, or the special symbol ``EXIT``. -- `-l` or `--list-signals` prints a list of signal names. +- ``-l`` or ``--list-signals`` prints a list of signal names. -- `-p` or `--print` prints all defined signal handlers. +- ``-p`` or ``--print`` prints all defined signal handlers. -If `ARG` and `REASON` are both specified, `ARG` is the command to be executed when the event specified by `REASON` occurs (e.g., the signal is delivered). +If ``ARG`` and ``REASON`` are both specified, ``ARG`` is the command to be executed when the event specified by ``REASON`` occurs (e.g., the signal is delivered). -If `ARG` is absent (and there is a single REASON) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If `ARG` is the null string the signal specified by each `REASON` is ignored by the shell and by the commands it invokes. +If ``ARG`` is absent (and there is a single REASON) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If ``ARG`` is the null string the signal specified by each ``REASON`` is ignored by the shell and by the commands it invokes. -If `ARG` is not present and `-p` has been supplied, then the trap commands associated with each `REASON` are displayed. If no arguments are supplied or if only `-p` is given, `trap` prints the list of commands associated with each signal. +If ``ARG`` is not present and ``-p`` has been supplied, then the trap commands associated with each ``REASON`` are displayed. If no arguments are supplied or if only ``-p`` is given, ``trap`` prints the list of commands associated with each signal. -Signal names are case insensitive and the `SIG` prefix is optional. +Signal names are case insensitive and the ``SIG`` prefix is optional. -The return status is 1 if any `REASON` is invalid; otherwise trap returns 0. +The return status is 1 if any ``REASON`` is invalid; otherwise trap returns 0. Example ------------ diff --git a/sphinx_doc_src/cmds/true.rst b/sphinx_doc_src/cmds/true.rst index 5b30b362f..98ce568a4 100644 --- a/sphinx_doc_src/cmds/true.rst +++ b/sphinx_doc_src/cmds/true.rst @@ -10,4 +10,4 @@ true Description ------------ -`true` sets the exit status to 0. +``true`` sets the exit status to 0. diff --git a/sphinx_doc_src/cmds/type.rst b/sphinx_doc_src/cmds/type.rst index 4426a0981..c1fdfeb07 100644 --- a/sphinx_doc_src/cmds/type.rst +++ b/sphinx_doc_src/cmds/type.rst @@ -10,23 +10,23 @@ type [OPTIONS] NAME [NAME ...] Description ------------ -With no options, `type` indicates how each `NAME` would be interpreted if used as a command name. +With no options, ``type`` indicates how each ``NAME`` would be interpreted if used as a command name. The following options are available: -- `-a` or `--all` prints all of possible definitions of the specified names. +- ``-a`` or ``--all`` prints all of possible definitions of the specified names. -- `-f` or `--no-functions` suppresses function and builtin lookup. +- ``-f`` or ``--no-functions`` suppresses function and builtin lookup. -- `-t` or `--type` prints `function`, `builtin`, or `file` if `NAME` is a shell function, builtin, or disk file, respectively. +- ``-t`` or ``--type`` prints ``function``, ``builtin``, or ``file`` if ``NAME`` is a shell function, builtin, or disk file, respectively. -- `-p` or `--path` returns the name of the disk file that would be executed, or nothing if `type -t name` would not return `file`. +- ``-p`` or ``--path`` returns the name of the disk file that would be executed, or nothing if ``type -t name`` would not return ``file``. -- `-P` or `--force-path` returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the $PATH. +- ``-P`` or ``--force-path`` returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the $PATH. -- `-q` or `--quiet` suppresses all output; this is useful when testing the exit status. +- ``-q`` or ``--quiet`` suppresses all output; this is useful when testing the exit status. -The `-q`, `-p`, `-t` and `-P` flags (and their long flag aliases) are mutually exclusive. Only one can be specified at a time. +The ``-q``, ``-p``, ``-t`` and ``-P`` flags (and their long flag aliases) are mutually exclusive. Only one can be specified at a time. Example diff --git a/sphinx_doc_src/cmds/ulimit.rst b/sphinx_doc_src/cmds/ulimit.rst index 86e679546..032333aa0 100644 --- a/sphinx_doc_src/cmds/ulimit.rst +++ b/sphinx_doc_src/cmds/ulimit.rst @@ -10,59 +10,59 @@ ulimit [OPTIONS] [LIMIT] Description ------------ -`ulimit` builtin sets or outputs the resource usage limits of the shell and any processes spawned by it. If a new limit value is omitted, the current value of the limit of the resource is printed; otherwise, the specified limit is set to the new value. +``ulimit`` builtin sets or outputs the resource usage limits of the shell and any processes spawned by it. If a new limit value is omitted, the current value of the limit of the resource is printed; otherwise, the specified limit is set to the new value. Use one of the following switches to specify which resource limit to set or report: -- `-c` or `--core-size`: the maximum size of core files created. By setting this limit to zero, core dumps can be disabled. +- ``-c`` or ``--core-size``: the maximum size of core files created. By setting this limit to zero, core dumps can be disabled. -- `-d` or `--data-size`: the maximum size of a process' data segment. +- ``-d`` or ``--data-size``: the maximum size of a process' data segment. -- `-f` or `--file-size`: the maximum size of files created by the shell. +- ``-f`` or ``--file-size``: the maximum size of files created by the shell. -- `-l` or `--lock-size`: the maximum size that may be locked into memory. +- ``-l`` or ``--lock-size``: the maximum size that may be locked into memory. -- `-m` or `--resident-set-size`: the maximum resident set size. +- ``-m`` or ``--resident-set-size``: the maximum resident set size. -- `-n` or `--file-descriptor-count`: the maximum number of open file descriptors (most systems do not allow this value to be set). +- ``-n`` or ``--file-descriptor-count``: the maximum number of open file descriptors (most systems do not allow this value to be set). -- `-s` or `--stack-size`: the maximum stack size. +- ``-s`` or ``--stack-size``: the maximum stack size. -- `-t` or `--cpu-time`: the maximum amount of CPU time in seconds. +- ``-t`` or ``--cpu-time``: the maximum amount of CPU time in seconds. -- `-u` or `--process-count`: the maximum number of processes available to a single user. +- ``-u`` or ``--process-count``: the maximum number of processes available to a single user. -- `-v` or `--virtual-memory-size` The maximum amount of virtual memory available to the shell. +- ``-v`` or ``--virtual-memory-size`` The maximum amount of virtual memory available to the shell. Note that not all these limits are available in all operating systems. -The value of limit can be a number in the unit specified for the resource or one of the special values `hard`, `soft`, or `unlimited`, which stand for the current hard limit, the current soft limit, and no limit, respectively. +The value of limit can be a number in the unit specified for the resource or one of the special values ``hard``, ``soft``, or ``unlimited``, which stand for the current hard limit, the current soft limit, and no limit, respectively. -If limit is given, it is the new value of the specified resource. If no option is given, then `-f` is assumed. Values are in kilobytes, except for `-t`, which is in seconds and `-n` and `-u`, which are unscaled values. The return status is 0 unless an invalid option or argument is supplied, or an error occurs while setting a new limit. +If limit is given, it is the new value of the specified resource. If no option is given, then ``-f`` is assumed. Values are in kilobytes, except for ``-t``, which is in seconds and ``-n`` and ``-u``, which are unscaled values. The return status is 0 unless an invalid option or argument is supplied, or an error occurs while setting a new limit. -`ulimit` also accepts the following switches that determine what type of limit to set: +``ulimit`` also accepts the following switches that determine what type of limit to set: -- `-H` or `--hard` sets hard resource limit +- ``-H`` or ``--hard`` sets hard resource limit -- `-S` or `--soft` sets soft resource limit +- ``-S`` or ``--soft`` sets soft resource limit A hard limit can only be decreased. Once it is set it cannot be increased; a soft limit may be increased up to the value of the hard limit. If neither -H nor -S is specified, both the soft and hard limits are updated when assigning a new limit value, and the soft limit is used when reporting the current value. -The following additional options are also understood by `ulimit`: +The following additional options are also understood by ``ulimit``: -- `-a` or `--all` prints all current limits +- ``-a`` or ``--all`` prints all current limits -The `fish` implementation of `ulimit` should behave identically to the implementation in bash, except for these differences: +The ``fish`` implementation of ``ulimit`` should behave identically to the implementation in bash, except for these differences: -- Fish `ulimit` supports GNU-style long options for all switches +- Fish ``ulimit`` supports GNU-style long options for all switches -- Fish `ulimit` does not support the `-p` option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe size is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish. +- Fish ``ulimit`` does not support the ``-p`` option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe size is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish. -- Fish `ulimit` does not support getting or setting multiple limits in one command, except reporting all values using the -a switch +- Fish ``ulimit`` does not support getting or setting multiple limits in one command, except reporting all values using the -a switch Example ------------ -`ulimit -Hs 64` sets the hard stack size limit to 64 kB. +``ulimit -Hs 64`` sets the hard stack size limit to 64 kB. diff --git a/sphinx_doc_src/cmds/umask.rst b/sphinx_doc_src/cmds/umask.rst index a615961b1..f67e710dc 100644 --- a/sphinx_doc_src/cmds/umask.rst +++ b/sphinx_doc_src/cmds/umask.rst @@ -10,31 +10,31 @@ umask [OPTIONS] [MASK] Description ------------ -`umask` displays and manipulates the "umask", or file creation mode mask, which is used to restrict the default access to files. +``umask`` displays and manipulates the "umask", or file creation mode mask, which is used to restrict the default access to files. The umask may be expressed either as an octal number, which represents the rights that will be removed by default, or symbolically, which represents the only rights that will be granted by default. -Access rights are explained in the manual page for the `chmod`(1) program. +Access rights are explained in the manual page for the ``chmod``(1) program. With no parameters, the current file creation mode mask is printed as an octal number. -- `-h` or `--help` prints this message. +- ``-h`` or ``--help`` prints this message. -- `-S` or `--symbolic` prints the umask in symbolic form instead of octal form. +- ``-S`` or ``--symbolic`` prints the umask in symbolic form instead of octal form. -- `-p` or `--as-command` outputs the umask in a form that may be reused as input +- ``-p`` or ``--as-command`` outputs the umask in a form that may be reused as input If a numeric mask is specified as a parameter, the current shell's umask will be set to that value, and the rights specified by that mask will be removed from new files and directories by default. If a symbolic mask is specified, the desired permission bits, and not the inverse, should be specified. A symbolic mask is a comma separated list of rights. Each right consists of three parts: -- The first part specifies to whom this set of right applies, and can be one of `u`, `g`, `o` or `a`, where `u` specifies the user who owns the file, `g` specifies the group owner of the file, `o` specific other users rights and `a` specifies all three should be changed. +- The first part specifies to whom this set of right applies, and can be one of ``u``, ``g``, ``o`` or ``a``, where ``u`` specifies the user who owns the file, ``g`` specifies the group owner of the file, ``o`` specific other users rights and ``a`` specifies all three should be changed. -- The second part of a right specifies the mode, and can be one of `=`, `+` or `-`, where `=` specifies that the rights should be set to the new value, `+` specifies that the specified right should be added to those previously specified and `-` specifies that the specified rights should be removed from those previously specified. +- The second part of a right specifies the mode, and can be one of ``=``, ``+`` or ``-``, where ``=`` specifies that the rights should be set to the new value, ``+`` specifies that the specified right should be added to those previously specified and ``-`` specifies that the specified rights should be removed from those previously specified. -- The third part of a right specifies what rights should be changed and can be any combination of `r`, `w` and `x`, representing read, write and execute rights. +- The third part of a right specifies what rights should be changed and can be any combination of ``r``, ``w`` and ``x``, representing read, write and execute rights. -If the first and second parts are skipped, they are assumed to be `a` and `=`, respectively. As an example, `r,u+w` means all users should have read access and the file owner should also have write access. +If the first and second parts are skipped, they are assumed to be ``a`` and ``=``, respectively. As an example, ``r,u+w`` means all users should have read access and the file owner should also have write access. Note that symbolic masks currently do not work as intended. @@ -42,4 +42,4 @@ Note that symbolic masks currently do not work as intended. Example ------------ -`umask 177` or `umask u=rw` sets the file creation mask to read and write for the owner and no permissions at all for any other users. +``umask 177`` or ``umask u=rw`` sets the file creation mask to read and write for the owner and no permissions at all for any other users. diff --git a/sphinx_doc_src/cmds/vared.rst b/sphinx_doc_src/cmds/vared.rst index c8f43db08..91ab9028b 100644 --- a/sphinx_doc_src/cmds/vared.rst +++ b/sphinx_doc_src/cmds/vared.rst @@ -10,10 +10,10 @@ vared VARIABLE_NAME Description ------------ -`vared` is used to interactively edit the value of an environment variable. Array variables as a whole can not be edited using `vared`, but individual array elements can. +``vared`` is used to interactively edit the value of an environment variable. Array variables as a whole can not be edited using ``vared``, but individual array elements can. Example ------------ -`vared PATH[3]` edits the third element of the PATH array +``vared PATH[3]`` edits the third element of the PATH array diff --git a/sphinx_doc_src/cmds/wait.rst b/sphinx_doc_src/cmds/wait.rst index 904ae557e..7afa01edf 100644 --- a/sphinx_doc_src/cmds/wait.rst +++ b/sphinx_doc_src/cmds/wait.rst @@ -10,12 +10,12 @@ wait [-n | --any] [PID | PROCESS_NAME] ... Description ------------ -`wait` waits for child jobs to complete. +``wait`` waits for child jobs to complete. - If a pid is specified, the command waits for the job that the process with the pid belongs to. - If a process name is specified, the command waits for the jobs that the matched processes belong to. - If neither a pid nor a process name is specified, the command waits for all background jobs. -- If the `-n` / `--any` flag is provided, the command returns as soon as the first job completes. If it is not provided, it returns after all jobs complete. +- If the ``-n`` / ``--any`` flag is provided, the command returns as soon as the first job completes. If it is not provided, it returns after all jobs complete. Example ------------ @@ -27,7 +27,7 @@ Example sleep 10 & wait $last_pid -spawns `sleep` in the background, and then waits until it finishes. +spawns ``sleep`` in the background, and then waits until it finishes. :: @@ -44,4 +44,4 @@ spawns five jobs in the background, and then waits until all of them finishes. hoge & wait sleep -spawns five jobs and `hoge` in the background, and then waits until all `sleep`s finishes, and doesn't wait for `hoge` finishing. +spawns five jobs and ``hoge`` in the background, and then waits until all ``sleep``s finishes, and doesn't wait for ``hoge`` finishing. diff --git a/sphinx_doc_src/cmds/while.rst b/sphinx_doc_src/cmds/while.rst index af1429afe..6bc372767 100644 --- a/sphinx_doc_src/cmds/while.rst +++ b/sphinx_doc_src/cmds/while.rst @@ -10,14 +10,14 @@ while CONDITION; COMMANDS...; end Description ------------ -`while` repeatedly executes `CONDITION`, and if the exit status is 0, then executes `COMMANDS`. +``while`` repeatedly executes ``CONDITION``, and if the exit status is 0, then executes ``COMMANDS``. -If the exit status of `CONDITION` is non-zero on the first iteration, `COMMANDS` will not be -executed at all, and the exit status of the loop set to the exit status of `CONDITION`. +If the exit status of ``CONDITION`` is non-zero on the first iteration, ``COMMANDS`` will not be +executed at all, and the exit status of the loop set to the exit status of ``CONDITION``. The exit status of the loop is 0 otherwise. -You can use `and` or `or` for complex conditions. Even more complex control can be achieved with `while true` containing a break. +You can use ``and`` or ``or`` for complex conditions. Even more complex control can be achieved with ``while true`` containing a break. Example ------------ From c8dc306b189fb4d7699298f77e6f7781319b8411 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 2 Jan 2019 20:10:47 -0800 Subject: [PATCH 110/191] Fix command section separator line lengths --- sphinx_doc_src/cmds/abbr.rst | 10 ++--- sphinx_doc_src/cmds/alias.rst | 6 +-- sphinx_doc_src/cmds/and.rst | 6 +-- sphinx_doc_src/cmds/argparse.rst | 16 ++++---- sphinx_doc_src/cmds/begin.rst | 6 +-- sphinx_doc_src/cmds/bg.rst | 6 +-- sphinx_doc_src/cmds/bind.rst | 10 ++--- sphinx_doc_src/cmds/block.rst | 8 ++-- sphinx_doc_src/cmds/break.rst | 6 +-- sphinx_doc_src/cmds/breakpoint.rst | 4 +- sphinx_doc_src/cmds/builtin.rst | 6 +-- sphinx_doc_src/cmds/case.rst | 6 +-- sphinx_doc_src/cmds/cd.rst | 8 ++-- sphinx_doc_src/cmds/cdh.rst | 6 +-- sphinx_doc_src/cmds/command.rst | 6 +-- sphinx_doc_src/cmds/commandline.rst | 6 +-- sphinx_doc_src/cmds/complete.rst | 6 +-- sphinx_doc_src/cmds/contains.rst | 6 +-- sphinx_doc_src/cmds/continue.rst | 6 +-- sphinx_doc_src/cmds/count.rst | 6 +-- sphinx_doc_src/cmds/dirh.rst | 4 +- sphinx_doc_src/cmds/dirs.rst | 4 +- sphinx_doc_src/cmds/disown.rst | 6 +-- sphinx_doc_src/cmds/echo.rst | 8 ++-- sphinx_doc_src/cmds/else.rst | 6 +-- sphinx_doc_src/cmds/emit.rst | 8 ++-- sphinx_doc_src/cmds/end.rst | 4 +- sphinx_doc_src/cmds/eval.rst | 6 +-- sphinx_doc_src/cmds/exec.rst | 6 +-- sphinx_doc_src/cmds/exit.rst | 4 +- sphinx_doc_src/cmds/false.rst | 4 +- sphinx_doc_src/cmds/fg.rst | 6 +-- sphinx_doc_src/cmds/fish.rst | 4 +- .../cmds/fish_breakpoint_prompt.rst | 6 +-- sphinx_doc_src/cmds/fish_config.rst | 6 +-- sphinx_doc_src/cmds/fish_indent.rst | 4 +- sphinx_doc_src/cmds/fish_key_reader.rst | 6 +-- sphinx_doc_src/cmds/fish_mode_prompt.rst | 6 +-- sphinx_doc_src/cmds/fish_opt.rst | 6 +-- sphinx_doc_src/cmds/fish_prompt.rst | 6 +-- sphinx_doc_src/cmds/fish_right_prompt.rst | 6 +-- .../cmds/fish_update_completions.rst | 4 +- sphinx_doc_src/cmds/fish_vi_mode.rst | 4 +- sphinx_doc_src/cmds/for.rst | 8 ++-- sphinx_doc_src/cmds/funced.rst | 4 +- sphinx_doc_src/cmds/funcsave.rst | 4 +- sphinx_doc_src/cmds/function.rst | 8 ++-- sphinx_doc_src/cmds/functions.rst | 6 +-- sphinx_doc_src/cmds/help.rst | 6 +-- sphinx_doc_src/cmds/history.rst | 10 ++--- sphinx_doc_src/cmds/if.rst | 6 +-- sphinx_doc_src/cmds/isatty.rst | 6 +-- sphinx_doc_src/cmds/jobs.rst | 8 ++-- sphinx_doc_src/cmds/math.rst | 18 ++++----- sphinx_doc_src/cmds/nextd.rst | 6 +-- sphinx_doc_src/cmds/not.rst | 6 +-- sphinx_doc_src/cmds/open.rst | 6 +-- sphinx_doc_src/cmds/or.rst | 6 +-- sphinx_doc_src/cmds/popd.rst | 6 +-- sphinx_doc_src/cmds/prevd.rst | 6 +-- sphinx_doc_src/cmds/printf.rst | 6 +-- sphinx_doc_src/cmds/prompt_pwd.rst | 4 +- sphinx_doc_src/cmds/psub.rst | 6 +-- sphinx_doc_src/cmds/pushd.rst | 6 +-- sphinx_doc_src/cmds/pwd.rst | 2 +- sphinx_doc_src/cmds/random.rst | 6 +-- sphinx_doc_src/cmds/read.rst | 8 ++-- sphinx_doc_src/cmds/realpath.rst | 4 +- sphinx_doc_src/cmds/return.rst | 6 +-- sphinx_doc_src/cmds/set.rst | 8 ++-- sphinx_doc_src/cmds/set_color.rst | 10 ++--- sphinx_doc_src/cmds/source.rst | 6 +-- sphinx_doc_src/cmds/status.rst | 6 +-- sphinx_doc_src/cmds/string.rst | 40 +++++++++---------- sphinx_doc_src/cmds/suspend.rst | 4 +- sphinx_doc_src/cmds/switch.rst | 6 +-- sphinx_doc_src/cmds/test.rst | 16 ++++---- sphinx_doc_src/cmds/trap.rst | 6 +-- sphinx_doc_src/cmds/true.rst | 4 +- sphinx_doc_src/cmds/type.rst | 6 +-- sphinx_doc_src/cmds/ulimit.rst | 6 +-- sphinx_doc_src/cmds/umask.rst | 6 +-- sphinx_doc_src/cmds/vared.rst | 6 +-- sphinx_doc_src/cmds/wait.rst | 6 +-- sphinx_doc_src/cmds/while.rst | 6 +-- 85 files changed, 287 insertions(+), 287 deletions(-) diff --git a/sphinx_doc_src/cmds/abbr.rst b/sphinx_doc_src/cmds/abbr.rst index 7aff46d13..1346c8adb 100644 --- a/sphinx_doc_src/cmds/abbr.rst +++ b/sphinx_doc_src/cmds/abbr.rst @@ -1,5 +1,5 @@ abbr - manage fish abbreviations -========================================== +================================ Synopsis -------- @@ -11,14 +11,14 @@ abbr --show abbr --list Description ------------- +----------- ``abbr`` manages abbreviations - user-defined words that are replaced with longer phrases after they are entered. For example, a frequently-run command like ``git checkout`` can be abbreviated to ``gco``. After entering ``gco`` and pressing @key{Space} or @key{Enter}, the full text ``git checkout`` will appear in the command line. Options ------------- +------- The following options are available: @@ -40,7 +40,7 @@ In addition, when adding abbreviations: See the "Internals" section for more on them. Examples ------------- +-------- @@ -83,7 +83,7 @@ Erase the ``gco`` abbreviation. Import the abbreviations defined on another_host over SSH. Internals ------------- +--------- Each abbreviation is stored in its own global or universal variable. The name consists of the prefix ``_fish_abbr_`` followed by the WORD after being transformed by ``string escape style=var``. The WORD cannot contain a space but all other characters are legal. Defining an abbreviation with global scope is slightly faster than universal scope (which is the default). But in general you'll only want to use the global scope when defining abbreviations in a startup script like ``~/.config/fish/config.fish`` like this: diff --git a/sphinx_doc_src/cmds/alias.rst b/sphinx_doc_src/cmds/alias.rst index 39cad912f..487b35c5c 100644 --- a/sphinx_doc_src/cmds/alias.rst +++ b/sphinx_doc_src/cmds/alias.rst @@ -1,5 +1,5 @@ alias - create a function -========================================== +========================= Synopsis -------- @@ -10,7 +10,7 @@ alias [OPTIONS] NAME=DEFINITION Description ------------- +----------- ``alias`` is a simple wrapper for the ``function`` builtin, which creates a function wrapping a command. It has similar syntax to POSIX shell ``alias``. For other uses, it is recommended to define a function. @@ -28,7 +28,7 @@ The following options are available: - ``-s`` or ``--save`` Automatically save the function created by the alias into your fish configuration directory using funcsave. Example ------------- +------- The following code will create ``rmi``, which runs ``rm`` with additional arguments on every invocation. diff --git a/sphinx_doc_src/cmds/and.rst b/sphinx_doc_src/cmds/and.rst index 79ae303e1..a5614c4ad 100644 --- a/sphinx_doc_src/cmds/and.rst +++ b/sphinx_doc_src/cmds/and.rst @@ -1,5 +1,5 @@ and - conditionally execute a command -========================================== +===================================== Synopsis -------- @@ -8,7 +8,7 @@ COMMAND1; and COMMAND2 Description ------------- +----------- ``and`` is used to execute a command if the previous command was successful (returned a status of 0). @@ -17,7 +17,7 @@ Description ``and`` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. Example ------------- +------- The following code runs the ``make`` command to build a program. If the build succeeds, ``make``'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and ``make clean`` is run, which removes the files created by the build process. diff --git a/sphinx_doc_src/cmds/argparse.rst b/sphinx_doc_src/cmds/argparse.rst index 3628a0a0e..c328e205b 100644 --- a/sphinx_doc_src/cmds/argparse.rst +++ b/sphinx_doc_src/cmds/argparse.rst @@ -1,5 +1,5 @@ argparse - parse options passed to a fish script or function -========================================== +============================================================ Synopsis -------- @@ -8,7 +8,7 @@ argparse [OPTIONS] OPTION_SPEC... -- [ARG...] Description ------------- +----------- This command makes it easy for fish scripts and functions to handle arguments in a manner 100% identical to how fish builtin commands handle their arguments. You pass a sequence of arguments that define the options recognized, followed by a literal ``--``, then the arguments to be parsed (which might also include a literal ``--``). More on this in the usage section below. @@ -19,7 +19,7 @@ Each option that is seen in the ARG list will result in a var name of the form ` For example ``_flag_h`` and ``_flag_help`` if ``-h`` or ``--help`` is seen. The var will be set with local scope (i.e., as if the script had done ``set -l _flag_X``). If the flag is a boolean (that is, does not have an associated value) the values are the short and long flags seen. If the option is not a boolean flag the values will be zero or more values corresponding to the values collected when the ARG list is processed. If the flag was not seen the flag var will not be set. Options ------------- +------- The following ``argparse`` options are available. They must appear before all OPTION_SPECs: @@ -36,7 +36,7 @@ The following ``argparse`` options are available. They must appear before all OP - ``-h`` or ``--help`` displays help about using this command. Usage ------------- +----- Using this command involves passing two sets of arguments separated by ``--``. The first set consists of one or more option specifications (``OPTION_SPEC`` above) and options that modify the behavior of ``argparse``. These must be listed before the ``--`` argument. The second set are the arguments to be parsed in accordance with the option specifications. They occur after the ``--`` argument and can be empty. More about this below but here is a simple example that might be used in a function named ``my_function``: @@ -73,7 +73,7 @@ But this is not: The first ``--`` seen is what allows the ``argparse`` command to reliably separate the option specifications from the command arguments. Option Specifications ------------- +--------------------- Each option specification is a string composed of @@ -98,7 +98,7 @@ See the ``fish_opt`` command for a friendlier but more v In the following examples if a flag is not seen when parsing the arguments then the corresponding _flag_X var(s) will not be set. Flag Value Validation ------------- +--------------------- It is common to want to validate the the value provided for an option satisfies some criteria. For example, that it is a valid integer within a specific range. You can always do this after ``argparse`` returns but you can also request that ``argparse`` perform the validation by executing arbitrary fish script. To do so simply append an ``!`` (exclamation-mark) then the fish script to be run. When that code is executed three vars will be defined: @@ -115,7 +115,7 @@ The script should write any error messages to stdout, not stderr. It should retu Fish ships with a ``_validate_int`` function that accepts a ``--min`` and ``--max`` flag. Let's say your command accepts a ``-m`` or ``--max`` flag and the minimum allowable value is zero and the maximum is 5. You would define the option like this: ``m/max=!_validate_int --min 0 --max 5``. The default if you just call ``_validate_int`` without those flags is to simply check that the value is a valid integer with no limits on the min or max value allowed. Example OPTION_SPECs ------------- +-------------------- Some OPTION_SPEC examples: @@ -144,6 +144,6 @@ After parsing the arguments the ``argv`` var is set with local scope to any valu If an error occurs during argparse processing it will exit with a non-zero status and print error messages to stderr. Notes ------------- +----- Prior to the addition of this builtin command in the 2.7.0 release there were two main ways to parse the arguments passed to a fish script or function. One way was to use the OS provided ``getopt`` command. The problem with that is that the GNU and BSD implementations are not compatible. Which makes using that external command difficult other than in trivial situations. The other way is to iterate over ``$argv`` and use the fish ``switch`` statement to decide how to handle the argument. That, however, involves a huge amount of boilerplate code. It is also borderline impossible to implement the same behavior as builtin commands. diff --git a/sphinx_doc_src/cmds/begin.rst b/sphinx_doc_src/cmds/begin.rst index a9b626f98..101d7e89b 100644 --- a/sphinx_doc_src/cmds/begin.rst +++ b/sphinx_doc_src/cmds/begin.rst @@ -1,5 +1,5 @@ begin - start a new block of code -========================================== +================================= Synopsis -------- @@ -8,7 +8,7 @@ begin; [COMMANDS...;] end Description ------------- +----------- ``begin`` is used to create a new block of code. @@ -20,7 +20,7 @@ The block is unconditionally executed. ``begin; ...; end`` is equivalent to ``if Example ------------- +------- The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends. diff --git a/sphinx_doc_src/cmds/bg.rst b/sphinx_doc_src/cmds/bg.rst index 7db38aa7f..a90e8cfb9 100644 --- a/sphinx_doc_src/cmds/bg.rst +++ b/sphinx_doc_src/cmds/bg.rst @@ -1,5 +1,5 @@ bg - send jobs to background -========================================== +============================ Synopsis -------- @@ -8,7 +8,7 @@ bg [PID...] Description ------------- +----------- ``bg`` sends jobs to the background, resuming them if they are stopped. @@ -20,7 +20,7 @@ When at least one of the arguments isn't a valid job specifier (i.e. PID), When all arguments are valid job specifiers, bg will background all matching jobs that exist. Example ------------- +------- ``bg 123 456 789`` will background 123, 456 and 789. diff --git a/sphinx_doc_src/cmds/bind.rst b/sphinx_doc_src/cmds/bind.rst index dacf10cfd..76c182793 100644 --- a/sphinx_doc_src/cmds/bind.rst +++ b/sphinx_doc_src/cmds/bind.rst @@ -1,5 +1,5 @@ bind - handle fish key bindings -========================================== +=============================== Synopsis -------- @@ -17,7 +17,7 @@ bind (-e | --erase) [(-M | --mode) MODE] Description ------------- +----------- ``bind`` adds a binding for the specified key sequence to the specified command. @@ -62,7 +62,7 @@ The following parameters are available: - ``--preset`` and ``--user`` specify if bind should operate on user or preset bindings. User bindings take precedence over preset bindings when fish looks up mappings. By default, all ``bind`` invocations work on the "user" level except for listing, which will show both levels. All invocations except for inserting new bindings can operate on both levels at the same time. ``--preset`` should only be used in full binding sets (like when working on ``fish_vi_key_bindings``). Special input functions ------------- +----------------------- The following special input functions are available: - ``accept-autosuggestion``, accept the current autosuggestion completely @@ -147,7 +147,7 @@ The following special input functions are available: Examples ------------- +-------- @@ -176,7 +176,7 @@ Turns on Vi key bindings and rebinds @key{Control,C} to clear the input line. Special Case: The escape Character ------------- +---------------------------------- The escape key can be used standalone, for example, to switch from insertion mode to normal mode when using Vi keybindings. Escape may also be used as a "meta" key, to indicate the start of an escape sequence, such as function or arrow keys. Custom bindings can also be defined that begin with an escape character. diff --git a/sphinx_doc_src/cmds/block.rst b/sphinx_doc_src/cmds/block.rst index acd7e7c37..db9914d0b 100644 --- a/sphinx_doc_src/cmds/block.rst +++ b/sphinx_doc_src/cmds/block.rst @@ -1,5 +1,5 @@ block - temporarily block delivery of events -========================================== +============================================ Synopsis -------- @@ -8,7 +8,7 @@ block [OPTIONS...] Description ------------- +----------- ``block`` prevents events triggered by ``fish`` or the ``emit`` command from being delivered and acted upon while the block is in place. @@ -28,7 +28,7 @@ The following parameters are available: Example ------------- +------- @@ -49,6 +49,6 @@ Example Notes ------------- +----- Note that events are only received from the current fish process as there is no way to send events from one fish process to another. diff --git a/sphinx_doc_src/cmds/break.rst b/sphinx_doc_src/cmds/break.rst index 9251df0b6..b4b55870e 100644 --- a/sphinx_doc_src/cmds/break.rst +++ b/sphinx_doc_src/cmds/break.rst @@ -1,5 +1,5 @@ break - stop the current inner loop -========================================== +=================================== Synopsis -------- @@ -8,7 +8,7 @@ LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] end Description ------------- +----------- ``break`` halts a currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. @@ -16,7 +16,7 @@ There are no parameters for ``break``. Example ------------- +------- The following code searches all .c files for "smurf", and halts at the first occurrence. diff --git a/sphinx_doc_src/cmds/breakpoint.rst b/sphinx_doc_src/cmds/breakpoint.rst index 4db33f5ee..6486fbf5a 100644 --- a/sphinx_doc_src/cmds/breakpoint.rst +++ b/sphinx_doc_src/cmds/breakpoint.rst @@ -1,5 +1,5 @@ breakpoint - Launch debug mode -========================================== +============================== Synopsis -------- @@ -8,7 +8,7 @@ breakpoint Description ------------- +----------- ``breakpoint`` is used to halt a running script and launch an interactive debugging prompt. diff --git a/sphinx_doc_src/cmds/builtin.rst b/sphinx_doc_src/cmds/builtin.rst index 48d413a59..651064e1a 100644 --- a/sphinx_doc_src/cmds/builtin.rst +++ b/sphinx_doc_src/cmds/builtin.rst @@ -1,5 +1,5 @@ builtin - run a builtin command -========================================== +=============================== Synopsis -------- @@ -8,7 +8,7 @@ builtin BUILTINNAME [OPTIONS...] Description ------------- +----------- ``builtin`` forces the shell to use a builtin command, rather than a function or program. @@ -18,7 +18,7 @@ The following parameters are available: Example ------------- +------- diff --git a/sphinx_doc_src/cmds/case.rst b/sphinx_doc_src/cmds/case.rst index 2ed89819e..2568f4fd0 100644 --- a/sphinx_doc_src/cmds/case.rst +++ b/sphinx_doc_src/cmds/case.rst @@ -1,5 +1,5 @@ case - conditionally execute a block of commands -========================================== +================================================ Synopsis -------- @@ -8,7 +8,7 @@ switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end Description ------------- +----------- ``switch`` executes one of several blocks of commands, depending on whether a specified value matches one of several values. ``case`` is used together with the ``switch`` statement in order to determine which block should be executed. @@ -20,7 +20,7 @@ Note that command substitutions in a case statement will be evaluated even if it Example ------------- +------- Say \$animal contains the name of an animal. Then this code would classify it: diff --git a/sphinx_doc_src/cmds/cd.rst b/sphinx_doc_src/cmds/cd.rst index 0707d40a3..2a6fcc748 100644 --- a/sphinx_doc_src/cmds/cd.rst +++ b/sphinx_doc_src/cmds/cd.rst @@ -1,5 +1,5 @@ cd - change directory -========================================== +===================== Synopsis -------- @@ -8,7 +8,7 @@ cd [DIRECTORY] Description ------------- +----------- ``cd`` changes the current working directory. If ``DIRECTORY`` is supplied, it will become the new directory. If no parameter is given, the contents of the ``HOME`` environment variable will be used. @@ -22,7 +22,7 @@ Fish also ships a wrapper function around the builtin ``cd`` that understands `` As a special case, ``cd .`` is equivalent to ``cd $PWD``, which is useful in cases where a mountpoint has been recycled or a directory has been removed and recreated. Examples ------------- +-------- @@ -36,6 +36,6 @@ Examples See Also ------------- +-------- See also the ``cdh`` command for changing to a recently visited directory. diff --git a/sphinx_doc_src/cmds/cdh.rst b/sphinx_doc_src/cmds/cdh.rst index 60b58fe46..a29a53a9d 100644 --- a/sphinx_doc_src/cmds/cdh.rst +++ b/sphinx_doc_src/cmds/cdh.rst @@ -1,5 +1,5 @@ cdh - change to a recently visited directory -========================================== +============================================ Synopsis @@ -9,13 +9,13 @@ cdh [ directory ] Description ------------- +----------- ``cdh`` with no arguments presents a list of recently visited directories. You can then select one of the entries by letter or number. You can also press @key{tab} to use the completion pager to select an item from the list. If you give it a single argument it is equivalent to ``cd directory``. Note that the ``cd`` command limits directory history to the 25 most recently visited directories. The history is stored in the ``$dirprev`` and ``$dirnext`` variables which this command manipulates. If you make those universal variables your ``cd`` history is shared among all fish instances. See Also ------------- +-------- See also the ``prevd`` and ``pushd`` commands which also work with the recent ``cd`` history and are provided for compatibility with other shells. diff --git a/sphinx_doc_src/cmds/command.rst b/sphinx_doc_src/cmds/command.rst index b72f79b34..82114a468 100644 --- a/sphinx_doc_src/cmds/command.rst +++ b/sphinx_doc_src/cmds/command.rst @@ -1,5 +1,5 @@ command - run a program -========================================== +======================= Synopsis -------- @@ -8,7 +8,7 @@ command [OPTIONS] COMMANDNAME [ARGS...] Description ------------- +----------- ``command`` forces the shell to execute the program ``COMMANDNAME`` and ignore any functions or builtins with the same name. @@ -25,7 +25,7 @@ With the ``-s`` option, ``command`` treats every argument as a separate command For basic compatibility with POSIX ``command``, the ``-v`` flag is recognized as an alias for ``-s``. Examples ------------- +-------- ``command ls`` causes fish to execute the ``ls`` program, even if an ``ls`` function exists. diff --git a/sphinx_doc_src/cmds/commandline.rst b/sphinx_doc_src/cmds/commandline.rst index d13dcac84..7782c02d2 100644 --- a/sphinx_doc_src/cmds/commandline.rst +++ b/sphinx_doc_src/cmds/commandline.rst @@ -1,5 +1,5 @@ commandline - set or get the current command line buffer -========================================== +======================================================== Synopsis -------- @@ -8,7 +8,7 @@ commandline [OPTIONS] [CMD] Description ------------- +----------- ``commandline`` can be used to set or get the current contents of the command line buffer. @@ -60,7 +60,7 @@ The following options output metadata about the commandline state: Example ------------- +------- ``commandline -j $history[3]`` replaces the job under the cursor with the third item from the command line history. diff --git a/sphinx_doc_src/cmds/complete.rst b/sphinx_doc_src/cmds/complete.rst index 6e4cf79e6..ab3ba1007 100644 --- a/sphinx_doc_src/cmds/complete.rst +++ b/sphinx_doc_src/cmds/complete.rst @@ -1,5 +1,5 @@ complete - edit command specific tab-completions -========================================== +================================================ Synopsis -------- @@ -21,7 +21,7 @@ complete ( -C[STRING] | --do-complete[=STRING] ) Description ------------- +----------- For an introduction to specifying completions, see Writing your own completions in @@ -95,7 +95,7 @@ When erasing completions, it is possible to either erase all completions for a s Example ------------- +------- The short style option ``-o`` for the ``gcc`` command requires that a file follows it. This can be done using writing: diff --git a/sphinx_doc_src/cmds/contains.rst b/sphinx_doc_src/cmds/contains.rst index e5338c80c..081e15fd3 100644 --- a/sphinx_doc_src/cmds/contains.rst +++ b/sphinx_doc_src/cmds/contains.rst @@ -1,5 +1,5 @@ contains - test if a word is present in a list -========================================== +============================================== Synopsis -------- @@ -8,7 +8,7 @@ contains [OPTIONS] KEY [VALUES...] Description ------------- +----------- ``contains`` tests whether the set ``VALUES`` contains the string ``KEY``. If so, ``contains`` exits with status 0; if not, it exits with status 1. @@ -19,7 +19,7 @@ The following options are available: Note that, like GNU tools and most of fish's builtins, ``contains`` interprets all arguments starting with a ``-`` as options to contains, until it reaches an argument that is ``--`` (two dashes). See the examples below. Example ------------- +------- If $animals is a list of animals, the following will test if it contains a cat: diff --git a/sphinx_doc_src/cmds/continue.rst b/sphinx_doc_src/cmds/continue.rst index 39cddf805..b5cac1b57 100644 --- a/sphinx_doc_src/cmds/continue.rst +++ b/sphinx_doc_src/cmds/continue.rst @@ -1,5 +1,5 @@ continue - skip the remainder of the current iteration of the current inner loop -========================================== +================================================================================ Synopsis -------- @@ -8,12 +8,12 @@ LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end Description ------------- +----------- ``continue`` skips the remainder of the current iteration of the current inner loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement. Example ------------- +------- The following code removes all tmp files that do not contain the word smurf. diff --git a/sphinx_doc_src/cmds/count.rst b/sphinx_doc_src/cmds/count.rst index fe89b2261..058ea1102 100644 --- a/sphinx_doc_src/cmds/count.rst +++ b/sphinx_doc_src/cmds/count.rst @@ -1,5 +1,5 @@ count - count the number of elements of an array -========================================== +================================================ Synopsis -------- @@ -8,7 +8,7 @@ count $VARIABLE Description ------------- +----------- ``count`` prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains. @@ -18,7 +18,7 @@ Description Example ------------- +------- diff --git a/sphinx_doc_src/cmds/dirh.rst b/sphinx_doc_src/cmds/dirh.rst index 847c64df7..2b9749521 100644 --- a/sphinx_doc_src/cmds/dirh.rst +++ b/sphinx_doc_src/cmds/dirh.rst @@ -1,5 +1,5 @@ dirh - print directory history -========================================== +============================== Synopsis -------- @@ -8,7 +8,7 @@ dirh Description ------------- +----------- ``dirh`` prints the current directory history. The current position in the history is highlighted using the color defined in the ``fish_color_history_current`` environment variable. diff --git a/sphinx_doc_src/cmds/dirs.rst b/sphinx_doc_src/cmds/dirs.rst index 6dff26d1a..d888489e4 100644 --- a/sphinx_doc_src/cmds/dirs.rst +++ b/sphinx_doc_src/cmds/dirs.rst @@ -1,5 +1,5 @@ dirs - print directory stack -========================================== +============================ Synopsis -------- @@ -9,7 +9,7 @@ dirs -c Description ------------- +----------- ``dirs`` prints the current directory stack, as created by the ``pushd`` command. diff --git a/sphinx_doc_src/cmds/disown.rst b/sphinx_doc_src/cmds/disown.rst index 701c62b3a..65732b389 100644 --- a/sphinx_doc_src/cmds/disown.rst +++ b/sphinx_doc_src/cmds/disown.rst @@ -1,5 +1,5 @@ disown - remove a process from the list of jobs -========================================== +=============================================== Synopsis -------- @@ -8,7 +8,7 @@ disown [ PID ... ] Description ------------- +----------- ``disown`` removes the specified job from the list of jobs. The job itself continues to exist, but fish does not keep track of it any longer. @@ -21,7 +21,7 @@ If a job is stopped, it is sent a signal to continue running, and a warning is p ``disown`` returns 0 if all specified jobs were disowned successfully, and 1 if any problems were encountered. Example ------------- +------- ``firefox &; disown`` will start the Firefox web browser in the background and remove it from the job list, meaning it will not be closed when the fish process is closed. diff --git a/sphinx_doc_src/cmds/echo.rst b/sphinx_doc_src/cmds/echo.rst index 0d366296f..065023e3c 100644 --- a/sphinx_doc_src/cmds/echo.rst +++ b/sphinx_doc_src/cmds/echo.rst @@ -1,5 +1,5 @@ echo - display a line of text -========================================== +============================= Synopsis -------- @@ -8,7 +8,7 @@ echo [OPTIONS] [STRING] Description ------------- +----------- ``echo`` displays a string of text. @@ -23,7 +23,7 @@ The following options are available: - ``-e``, Enable interpretation of backslash escapes Escape Sequences ------------- +---------------- If ``-e`` is used, the following sequences are recognized: @@ -52,7 +52,7 @@ If ``-e`` is used, the following sequences are recognized: - ``\xHH`` byte with hexadecimal value HH (1 to 2 digits) Example ------------- +------- diff --git a/sphinx_doc_src/cmds/else.rst b/sphinx_doc_src/cmds/else.rst index 8c8f0e1d6..71523a694 100644 --- a/sphinx_doc_src/cmds/else.rst +++ b/sphinx_doc_src/cmds/else.rst @@ -1,5 +1,5 @@ else - execute command if a condition is not met -========================================== +================================================ Synopsis -------- @@ -8,13 +8,13 @@ if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end Description ------------- +----------- ``if`` will execute the command ``CONDITION``. If the condition's exit status is 0, the commands ``COMMANDS_TRUE`` will execute. If it is not 0 and ``else`` is given, ``COMMANDS_FALSE`` will be executed. Example ------------- +------- The following code tests whether a file ``foo.txt`` exists as a regular file. diff --git a/sphinx_doc_src/cmds/emit.rst b/sphinx_doc_src/cmds/emit.rst index a4326eb51..1a5cbc386 100644 --- a/sphinx_doc_src/cmds/emit.rst +++ b/sphinx_doc_src/cmds/emit.rst @@ -1,5 +1,5 @@ emit - Emit a generic event -========================================== +=========================== Synopsis -------- @@ -8,13 +8,13 @@ emit EVENT_NAME [ARGUMENTS...] Description ------------- +----------- ``emit`` emits, or fires, an event. Events are delivered to, or caught by, special functions called event handlers. The arguments are passed to the event handlers as function arguments. Example ------------- +------- The following code first defines an event handler for the generic event named 'test_event', and then emits an event of that type. @@ -31,6 +31,6 @@ The following code first defines an event handler for the generic event named 't Notes ------------- +----- Note that events are only sent to the current fish process as there is no way to send events from one fish process to another. diff --git a/sphinx_doc_src/cmds/end.rst b/sphinx_doc_src/cmds/end.rst index 3ed4d66b6..e1e7b2182 100644 --- a/sphinx_doc_src/cmds/end.rst +++ b/sphinx_doc_src/cmds/end.rst @@ -1,5 +1,5 @@ end - end a block of commands. -========================================== +============================== Synopsis -------- @@ -12,7 +12,7 @@ switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end Description ------------- +----------- ``end`` ends a block of commands. diff --git a/sphinx_doc_src/cmds/eval.rst b/sphinx_doc_src/cmds/eval.rst index bd76f9743..f34dbd767 100644 --- a/sphinx_doc_src/cmds/eval.rst +++ b/sphinx_doc_src/cmds/eval.rst @@ -1,5 +1,5 @@ eval - evaluate the specified commands -========================================== +====================================== Synopsis -------- @@ -8,13 +8,13 @@ eval [COMMANDS...] Description ------------- +----------- ``eval`` evaluates the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator. If your command does not need access to stdin, consider using ``source`` instead. Example ------------- +------- The following code will call the ls command. Note that ``fish`` does not support the use of shell variables as direct commands; ``eval`` can be used to work around this. diff --git a/sphinx_doc_src/cmds/exec.rst b/sphinx_doc_src/cmds/exec.rst index e9b77c6e6..8acc7d6be 100644 --- a/sphinx_doc_src/cmds/exec.rst +++ b/sphinx_doc_src/cmds/exec.rst @@ -1,5 +1,5 @@ exec - execute command in current process -========================================== +========================================= Synopsis -------- @@ -8,12 +8,12 @@ exec COMMAND [OPTIONS...] Description ------------- +----------- ``exec`` replaces the currently running shell with a new command. On successful completion, ``exec`` never returns. ``exec`` cannot be used inside a pipeline. Example ------------- +------- ``exec emacs`` starts up the emacs text editor, and exits ``fish``. When emacs exits, the session will terminate. diff --git a/sphinx_doc_src/cmds/exit.rst b/sphinx_doc_src/cmds/exit.rst index cd793b884..bc9fe2de1 100644 --- a/sphinx_doc_src/cmds/exit.rst +++ b/sphinx_doc_src/cmds/exit.rst @@ -1,5 +1,5 @@ exit - exit the shell -========================================== +===================== Synopsis -------- @@ -8,7 +8,7 @@ exit [STATUS] Description ------------- +----------- ``exit`` causes fish to exit. If ``STATUS`` is supplied, it will be converted to an integer and used as the exit code. Otherwise, the exit code will be that of the last command executed. diff --git a/sphinx_doc_src/cmds/false.rst b/sphinx_doc_src/cmds/false.rst index 47f526508..d972f5864 100644 --- a/sphinx_doc_src/cmds/false.rst +++ b/sphinx_doc_src/cmds/false.rst @@ -1,5 +1,5 @@ false - return an unsuccessful result -========================================== +===================================== Synopsis -------- @@ -8,6 +8,6 @@ false Description ------------- +----------- ``false`` sets the exit status to 1. diff --git a/sphinx_doc_src/cmds/fg.rst b/sphinx_doc_src/cmds/fg.rst index a1bb08b9f..33831232b 100644 --- a/sphinx_doc_src/cmds/fg.rst +++ b/sphinx_doc_src/cmds/fg.rst @@ -1,5 +1,5 @@ fg - bring job to foreground -========================================== +============================ Synopsis -------- @@ -8,12 +8,12 @@ fg [PID] Description ------------- +----------- ``fg`` brings the specified job to the foreground, resuming it if it is stopped. While a foreground job is executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group ID is put in the foreground. Example ------------- +------- ``fg`` will put the last job in the foreground. diff --git a/sphinx_doc_src/cmds/fish.rst b/sphinx_doc_src/cmds/fish.rst index 1325818ef..b3b8a090b 100644 --- a/sphinx_doc_src/cmds/fish.rst +++ b/sphinx_doc_src/cmds/fish.rst @@ -1,5 +1,5 @@ fish - the friendly interactive shell -========================================== +===================================== Synopsis -------- @@ -8,7 +8,7 @@ fish [OPTIONS] [-c command] [FILE [ARGUMENTS...]] Description ------------- +----------- ``fish`` is a command-line shell written mainly with interactive use in mind. The full manual is available in HTML by using the help command from inside fish. diff --git a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst index e8519b279..4d4bd2ac6 100644 --- a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst +++ b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst @@ -1,5 +1,5 @@ fish_breakpoint_prompt - define the appearance of the command line prompt when in the context of a ``breakpoint`` command -========================================== +========================================================================================================================= Synopsis -------- @@ -10,7 +10,7 @@ end Description ------------- +----------- By defining the ``fish_breakpoint_prompt`` function, the user can choose a custom prompt when asking for input in response to a ``breakpoint`` command. The ``fish_breakpoint_prompt`` function is executed when the prompt is to be shown, and the output is used as a prompt. @@ -20,7 +20,7 @@ The exit status of commands within ``fish_breakpoint_prompt`` will not modify th Example ------------- +------- A simple prompt that is a simplified version of the default debugging prompt: diff --git a/sphinx_doc_src/cmds/fish_config.rst b/sphinx_doc_src/cmds/fish_config.rst index c761479bb..386797299 100644 --- a/sphinx_doc_src/cmds/fish_config.rst +++ b/sphinx_doc_src/cmds/fish_config.rst @@ -1,9 +1,9 @@ fish_config - start the web-based configuration interface -========================================== +========================================================= Description ------------- +----------- ``fish_config`` starts the web-based configuration interface. @@ -17,6 +17,6 @@ If the ``BROWSER`` environment variable is set, it will be used as the name of t Example ------------- +------- ``fish_config`` opens a new web browser window and allows you to configure certain fish settings. diff --git a/sphinx_doc_src/cmds/fish_indent.rst b/sphinx_doc_src/cmds/fish_indent.rst index 10da3ee1d..56dd7e798 100644 --- a/sphinx_doc_src/cmds/fish_indent.rst +++ b/sphinx_doc_src/cmds/fish_indent.rst @@ -1,5 +1,5 @@ fish_indent - indenter and prettifier -========================================== +===================================== Synopsis -------- @@ -8,7 +8,7 @@ fish_indent [OPTIONS] Description ------------- +----------- ``fish_indent`` is used to indent a piece of fish code. ``fish_indent`` reads commands from standard input and outputs them to standard output or a specified file. diff --git a/sphinx_doc_src/cmds/fish_key_reader.rst b/sphinx_doc_src/cmds/fish_key_reader.rst index 4290ec7b6..ea8f4d4c3 100644 --- a/sphinx_doc_src/cmds/fish_key_reader.rst +++ b/sphinx_doc_src/cmds/fish_key_reader.rst @@ -1,5 +1,5 @@ fish_key_reader - explore what characters keyboard keys send -========================================== +============================================================ Synopsis -------- @@ -8,7 +8,7 @@ fish_key_reader [OPTIONS] Description ------------- +----------- ``fish_key_reader`` is used to study input received from the terminal and can help with key binds. The program is interactive and works on standard input. Individual characters themselves and their hexadecimal values are displayed. @@ -27,7 +27,7 @@ The following options are available: - ``-v`` or ``--version`` prints fish_key_reader's version and exits. Usage Notes ------------- +----------- The delay in milliseconds since the previous character was received is included in the diagnostic information written to stderr. This information may be useful to determine the optimal ``fish_escape_delay_ms`` setting or learn the amount of lag introduced by tools like ``ssh``, ``mosh`` or ``tmux``. diff --git a/sphinx_doc_src/cmds/fish_mode_prompt.rst b/sphinx_doc_src/cmds/fish_mode_prompt.rst index 97d84da8f..88e1cb2e7 100644 --- a/sphinx_doc_src/cmds/fish_mode_prompt.rst +++ b/sphinx_doc_src/cmds/fish_mode_prompt.rst @@ -1,18 +1,18 @@ fish_mode_prompt - define the appearance of the mode indicator -========================================== +============================================================== The fish_mode_prompt function will output the mode indicator for use in vi-mode. Description ------------- +----------- The default ``fish_mode_prompt`` function will output indicators about the current Vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. You can also define an empty ``fish_mode_prompt`` function to remove the Vi mode indicators. The ``$fish_bind_mode variable`` can be used to determine the current mode. It will be one of ``default``, ``insert``, ``replace_one``, or ``visual``. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/fish_opt.rst b/sphinx_doc_src/cmds/fish_opt.rst index a844fe330..0d3516500 100644 --- a/sphinx_doc_src/cmds/fish_opt.rst +++ b/sphinx_doc_src/cmds/fish_opt.rst @@ -1,5 +1,5 @@ fish_opt - create an option spec for the argparse command -========================================== +========================================================= Synopsis -------- @@ -10,7 +10,7 @@ fish_opt ( -s X | --short=X ) [ -l LONG | --long=LONG ] [ --long-only ] \ Description ------------- +----------- This command provides a way to produce option specifications suitable for use with the ``argparse`` command. You can, of course, write the option specs by hand without using this command. But you might prefer to use this for the clarity it provides. @@ -31,7 +31,7 @@ The following ``argparse`` options are available: - ``-h`` or ``--help`` displays help about using this command. Examples ------------- +-------- Define a single option spec for the boolean help flag: diff --git a/sphinx_doc_src/cmds/fish_prompt.rst b/sphinx_doc_src/cmds/fish_prompt.rst index 4e03fa28c..99a047a1c 100644 --- a/sphinx_doc_src/cmds/fish_prompt.rst +++ b/sphinx_doc_src/cmds/fish_prompt.rst @@ -1,5 +1,5 @@ fish_prompt - define the appearance of the command line prompt -========================================== +============================================================== Synopsis -------- @@ -10,7 +10,7 @@ end Description ------------- +----------- By defining the ``fish_prompt`` function, the user can choose a custom prompt. The ``fish_prompt`` function is executed when the prompt is to be shown, and the output is used as a prompt. @@ -20,7 +20,7 @@ The exit status of commands within ``fish_prompt`` will not modify the value of Example ------------- +------- A simple prompt: diff --git a/sphinx_doc_src/cmds/fish_right_prompt.rst b/sphinx_doc_src/cmds/fish_right_prompt.rst index 701cb65ad..01e8cc263 100644 --- a/sphinx_doc_src/cmds/fish_right_prompt.rst +++ b/sphinx_doc_src/cmds/fish_right_prompt.rst @@ -1,5 +1,5 @@ fish_right_prompt - define the appearance of the right-side command line prompt -========================================== +=============================================================================== Synopsis -------- @@ -10,7 +10,7 @@ end Description ------------- +----------- ``fish_right_prompt`` is similar to ``fish_prompt``, except that it appears on the right side of the terminal window. @@ -18,7 +18,7 @@ Multiple lines are not supported in ``fish_right_prompt``. Example ------------- +------- A simple right prompt: diff --git a/sphinx_doc_src/cmds/fish_update_completions.rst b/sphinx_doc_src/cmds/fish_update_completions.rst index a1f5de530..b269d56bf 100644 --- a/sphinx_doc_src/cmds/fish_update_completions.rst +++ b/sphinx_doc_src/cmds/fish_update_completions.rst @@ -1,9 +1,9 @@ fish_update_completions - Update completions using manual pages -========================================== +=============================================================== Description ------------- +----------- ``fish_update_completions`` parses manual pages installed on the system, and attempts to create completion files in the ``fish`` configuration directory. diff --git a/sphinx_doc_src/cmds/fish_vi_mode.rst b/sphinx_doc_src/cmds/fish_vi_mode.rst index 9a8e7ff73..590538b3b 100644 --- a/sphinx_doc_src/cmds/fish_vi_mode.rst +++ b/sphinx_doc_src/cmds/fish_vi_mode.rst @@ -1,5 +1,5 @@ fish_vi_mode - Enable vi mode -========================================== +============================= Synopsis -------- @@ -8,7 +8,7 @@ fish_vi_mode Description ------------- +----------- This function is deprecated. Please call ``fish_vi_key_bindings directly`` diff --git a/sphinx_doc_src/cmds/for.rst b/sphinx_doc_src/cmds/for.rst index e7881b114..cfb02bf01 100644 --- a/sphinx_doc_src/cmds/for.rst +++ b/sphinx_doc_src/cmds/for.rst @@ -1,5 +1,5 @@ for - perform a set of commands multiple times. -========================================== +=============================================== Synopsis -------- @@ -8,12 +8,12 @@ for VARNAME in [VALUES...]; COMMANDS...; end Description ------------- +----------- ``for`` is a loop construct. It will perform the commands specified by ``COMMANDS`` multiple times. On each iteration, the local variable specified by ``VARNAME`` is assigned a new value from ``VALUES``. If ``VALUES`` is empty, ``COMMANDS`` will not be executed at all. The ``VARNAME`` is visible when the loop terminates and will contain the last value assigned to it. If ``VARNAME`` does not already exist it will be set in the local scope. For our purposes if the ``for`` block is inside a function there must be a local variable with the same name. If the ``for`` block is not nested inside a function then global and universal variables of the same name will be used if they exist. Example ------------- +------- @@ -28,7 +28,7 @@ Example Notes ------------- +----- The ``VARNAME`` was local to the for block in releases prior to 3.0.0. This means that if you did something like this: diff --git a/sphinx_doc_src/cmds/funced.rst b/sphinx_doc_src/cmds/funced.rst index b554dcaad..5c9bfe5ad 100644 --- a/sphinx_doc_src/cmds/funced.rst +++ b/sphinx_doc_src/cmds/funced.rst @@ -1,5 +1,5 @@ funced - edit a function interactively -========================================== +====================================== Synopsis -------- @@ -8,7 +8,7 @@ funced [OPTIONS] NAME Description ------------- +----------- ``funced`` provides an interface to edit the definition of the function ``NAME``. diff --git a/sphinx_doc_src/cmds/funcsave.rst b/sphinx_doc_src/cmds/funcsave.rst index 53e46d31b..fad1550b6 100644 --- a/sphinx_doc_src/cmds/funcsave.rst +++ b/sphinx_doc_src/cmds/funcsave.rst @@ -1,5 +1,5 @@ funcsave - save the definition of a function to the user's autoload directory -========================================== +============================================================================= Synopsis -------- @@ -8,7 +8,7 @@ funcsave FUNCTION_NAME Description ------------- +----------- ``funcsave`` saves the current definition of a function to a file in the fish configuration directory. This function will be automatically loaded by current and future fish sessions. This can be useful if you have interactively created a new function and wish to save it for later use. diff --git a/sphinx_doc_src/cmds/function.rst b/sphinx_doc_src/cmds/function.rst index 40e158941..bf6623d93 100644 --- a/sphinx_doc_src/cmds/function.rst +++ b/sphinx_doc_src/cmds/function.rst @@ -1,5 +1,5 @@ function - create a function -========================================== +============================ Synopsis -------- @@ -8,7 +8,7 @@ function NAME [OPTIONS]; BODY; end Description ------------- +----------- ``function`` creates a new function ``NAME`` with the body ``BODY``. @@ -58,7 +58,7 @@ By using one of the event handler switches, a function can be made to run automa - ``fish_exit`` is emitted right before fish exits. Example ------------- +------- @@ -110,6 +110,6 @@ This will beep when the most recent job completes. Notes ------------- +----- Note that events are only received from the current fish process as there is no way to send events from one fish process to another. diff --git a/sphinx_doc_src/cmds/functions.rst b/sphinx_doc_src/cmds/functions.rst index e4675fece..abb1d4398 100644 --- a/sphinx_doc_src/cmds/functions.rst +++ b/sphinx_doc_src/cmds/functions.rst @@ -1,5 +1,5 @@ functions - print or erase functions -========================================== +==================================== Synopsis -------- @@ -12,7 +12,7 @@ functions [ -e | -q ] FUNCTIONS... Description ------------- +----------- ``functions`` prints or erases functions. @@ -60,7 +60,7 @@ The exit status of ``functions`` is the number of functions specified in the arg Examples ------------- +-------- :: diff --git a/sphinx_doc_src/cmds/help.rst b/sphinx_doc_src/cmds/help.rst index 4ec33f9fd..314f3c0fc 100644 --- a/sphinx_doc_src/cmds/help.rst +++ b/sphinx_doc_src/cmds/help.rst @@ -1,5 +1,5 @@ help - display fish documentation -========================================== +================================= Synopsis -------- @@ -8,7 +8,7 @@ help [SECTION] Description ------------- +----------- ``help`` displays the fish help documentation. @@ -22,6 +22,6 @@ Note that most builtin commands display their help in the terminal when given th Example ------------- +------- ``help fg`` shows the documentation for the ``fg`` builtin. diff --git a/sphinx_doc_src/cmds/history.rst b/sphinx_doc_src/cmds/history.rst index 9b36e6f19..3056f262e 100644 --- a/sphinx_doc_src/cmds/history.rst +++ b/sphinx_doc_src/cmds/history.rst @@ -1,5 +1,5 @@ history - Show and manipulate command history -========================================== +============================================= Synopsis -------- @@ -13,7 +13,7 @@ history ( -h | --help ) Description ------------- +----------- ``history`` is used to search, delete, and otherwise manipulate the history of interactive commands. @@ -52,7 +52,7 @@ These flags can appear before or immediately after one of the sub-commands liste - ``-h`` or ``--help`` display help for this command. Example ------------- +------- @@ -70,7 +70,7 @@ Example Customizing the name of the history file ------------- +---------------------------------------- By default interactive commands are logged to ``$XDG_DATA_HOME/fish/fish_history`` (typically ``~/.local/share/fish/fish_history``). @@ -81,7 +81,7 @@ You can change ``fish_history`` at any time (by using ``set -x fish_history "ses Other shells such as bash and zsh use a variable named ``HISTFILE`` for a similar purpose. Fish uses a different name to avoid conflicts and signal that the behavior is different (session name instead of a file path). Also, if you set the var to anything other than ``fish`` or ``default`` it will inhibit importing the bash history. That's because the most common use case for this feature is to avoid leaking private or sensitive history when giving a presentation. Notes ------------- +----- If you specify both ``--prefix`` and ``--contains`` the last flag seen is used. diff --git a/sphinx_doc_src/cmds/if.rst b/sphinx_doc_src/cmds/if.rst index 3ba43ae9d..ba90693ba 100644 --- a/sphinx_doc_src/cmds/if.rst +++ b/sphinx_doc_src/cmds/if.rst @@ -1,5 +1,5 @@ if - conditionally execute a command -========================================== +==================================== Synopsis -------- @@ -11,7 +11,7 @@ end Description ------------- +----------- ``if`` will execute the command ``CONDITION``. If the condition's exit status is 0, the commands ``COMMANDS_TRUE`` will execute. If the exit status is not 0 and ``else`` is given, ``COMMANDS_FALSE`` will be executed. @@ -20,7 +20,7 @@ You can use ``and`` or ``or`` in the condit The exit status of the last foreground command to exit can always be accessed using the $status variable. Example ------------- +------- The following code will print ``foo.txt exists`` if the file foo.txt exists and is a regular file, otherwise it will print ``bar.txt exists`` if the file bar.txt exists and is a regular file, otherwise it will print ``foo.txt and bar.txt do not exist``. diff --git a/sphinx_doc_src/cmds/isatty.rst b/sphinx_doc_src/cmds/isatty.rst index fc231e314..744003049 100644 --- a/sphinx_doc_src/cmds/isatty.rst +++ b/sphinx_doc_src/cmds/isatty.rst @@ -1,5 +1,5 @@ isatty - test if a file descriptor is a tty. -========================================== +============================================ Synopsis -------- @@ -8,7 +8,7 @@ isatty [FILE DESCRIPTOR] Description ------------- +----------- ``isatty`` tests if a file descriptor is a tty. @@ -18,7 +18,7 @@ If the specified file descriptor is a tty, the exit status of the command is zer Examples ------------- +-------- From an interactive shell, the commands below exit with a return value of zero: diff --git a/sphinx_doc_src/cmds/jobs.rst b/sphinx_doc_src/cmds/jobs.rst index 3ba255e8c..3874f2f8d 100644 --- a/sphinx_doc_src/cmds/jobs.rst +++ b/sphinx_doc_src/cmds/jobs.rst @@ -1,5 +1,5 @@ jobs - print currently running jobs -========================================== +=================================== Synopsis -------- @@ -8,7 +8,7 @@ jobs [OPTIONS] [PID] Description ------------- +----------- ``jobs`` prints a list of the currently running jobs and their status. @@ -29,10 +29,10 @@ On systems that supports this feature, jobs will print the CPU usage of each job The exit code of the ``jobs`` builtin is ``0`` if there are running background jobs and ``1`` otherwise. no output. ------------- +---------- Example ------------- +------- ``jobs`` outputs a summary of the current jobs. diff --git a/sphinx_doc_src/cmds/math.rst b/sphinx_doc_src/cmds/math.rst index 170d86357..cb75f327b 100644 --- a/sphinx_doc_src/cmds/math.rst +++ b/sphinx_doc_src/cmds/math.rst @@ -1,5 +1,5 @@ math - Perform mathematics calculations -========================================== +======================================= Synopsis -------- @@ -8,7 +8,7 @@ math [-sN | --scale=N] [--] EXPRESSION Description ------------- +----------- ``math`` is used to perform mathematical calculations. It supports all the usual operations such as addition, subtraction, etc. As well as functions like ``abs()``, ``sqrt()`` and ``log2()``. @@ -23,19 +23,19 @@ The following options are available: - ``-sN`` or ``--scale=N`` sets the scale of the result. ``N`` must be an integer. A scale of zero causes results to be rounded down to the nearest integer. So ``3/2`` returns ``1`` rather than ``2`` which ``1.5`` would normally round to. This is for compatibility with ``bc`` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. Return Values ------------- +------------- If the expression is successfully evaluated and doesn't over/underflow or return NaN the return ``status`` is zero (success) else one. Syntax ------------- +------ ``math`` knows some operators, constants, functions and can (obviously) read numbers. For numbers, ``.`` is always the radix character regardless of locale - ``2.5``, not ``2,5``. Scientific notation (``10e5``) is also available. Operators ------------- +--------- ``math`` knows the following operators: @@ -52,7 +52,7 @@ Operators They are all used in an infix manner - ``5 + 2``, not ``+ 5 2``. Constants ------------- +--------- ``math`` knows the following constants: @@ -62,7 +62,7 @@ Constants Use them without a leading ``$`` - ``pi - 3`` should be about 0. Functions ------------- +--------- ``math`` supports the following functions: @@ -92,7 +92,7 @@ Functions All of the trigonometric functions use radians. Examples ------------- +-------- ``math 1+1`` outputs 2. @@ -107,7 +107,7 @@ Examples ``math "sin(pi)"`` outputs ``0``. Compatibility notes ------------- +------------------- Fish 1.x and 2.x releases relied on the ``bc`` command for handling ``math`` expressions. Starting with fish 3.0.0 fish uses the tinyexpr library and evaluates the expression without the involvement of any external commands. diff --git a/sphinx_doc_src/cmds/nextd.rst b/sphinx_doc_src/cmds/nextd.rst index d954b7142..df8e10a05 100644 --- a/sphinx_doc_src/cmds/nextd.rst +++ b/sphinx_doc_src/cmds/nextd.rst @@ -1,5 +1,5 @@ nextd - move forward through directory history -========================================== +============================================== Synopsis -------- @@ -8,7 +8,7 @@ nextd [ -l | --list ] [POS] Description ------------- +----------- ``nextd`` moves forwards ``POS`` positions in the history of visited directories; if the end of the history has been hit, a warning is printed. @@ -19,7 +19,7 @@ Note that the ``cd`` command limits directory history to the 25 most recently vi You may be interested in the ``cdh`` command which provides a more intuitive way to navigate to recently visited directories. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/not.rst b/sphinx_doc_src/cmds/not.rst index 50438fc39..524f69605 100644 --- a/sphinx_doc_src/cmds/not.rst +++ b/sphinx_doc_src/cmds/not.rst @@ -1,5 +1,5 @@ not - negate the exit status of a job -========================================== +===================================== Synopsis -------- @@ -8,13 +8,13 @@ not COMMAND [OPTIONS...] Description ------------- +----------- ``not`` negates the exit status of another command. If the exit status is zero, ``not`` returns 1. Otherwise, ``not`` returns 0. Example ------------- +------- The following code reports an error and exits if no file named spoon can be found. diff --git a/sphinx_doc_src/cmds/open.rst b/sphinx_doc_src/cmds/open.rst index 4b86a0641..b4e5ac63d 100644 --- a/sphinx_doc_src/cmds/open.rst +++ b/sphinx_doc_src/cmds/open.rst @@ -1,5 +1,5 @@ open - open file in its default application -========================================== +=========================================== Synopsis -------- @@ -8,7 +8,7 @@ open FILES... Description ------------- +----------- ``open`` opens a file in its default application, using the appropriate tool for the operating system. On GNU/Linux, this requires the common but optional ``xdg-open`` utility, from the ``xdg-utils`` package. @@ -16,6 +16,6 @@ Note that this function will not be used if a command by this name exists (which Example ------------- +------- ``open *.txt`` opens all the text files in the current directory using your system's default text editor. diff --git a/sphinx_doc_src/cmds/or.rst b/sphinx_doc_src/cmds/or.rst index 7f04d8af0..258d22158 100644 --- a/sphinx_doc_src/cmds/or.rst +++ b/sphinx_doc_src/cmds/or.rst @@ -1,5 +1,5 @@ or - conditionally execute a command -========================================== +==================================== Synopsis -------- @@ -8,7 +8,7 @@ COMMAND1; or COMMAND2 Description ------------- +----------- ``or`` is used to execute a command if the previous command was not successful (returned a status of something other than 0). @@ -18,7 +18,7 @@ for ``if`` and ``while`` for examples. ``or`` does not change the current exit status itself, but the command it runs most likely will. The exit status of the last foreground command to exit can always be accessed using the $status variable. Example ------------- +------- The following code runs the ``make`` command to build a program. If the build succeeds, the program is installed. If either step fails, ``make clean`` is run, which removes the files created by the build process. diff --git a/sphinx_doc_src/cmds/popd.rst b/sphinx_doc_src/cmds/popd.rst index 126d331d2..945912777 100644 --- a/sphinx_doc_src/cmds/popd.rst +++ b/sphinx_doc_src/cmds/popd.rst @@ -1,5 +1,5 @@ popd - move through directory stack -========================================== +=================================== Synopsis -------- @@ -8,14 +8,14 @@ popd Description ------------- +----------- ``popd`` removes the top directory from the directory stack and changes the working directory to the new top directory. Use ``pushd`` to add directories to the stack. You may be interested in the ``cdh`` command which provides a more intuitive way to navigate to recently visited directories. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/prevd.rst b/sphinx_doc_src/cmds/prevd.rst index 9087249f7..10a749803 100644 --- a/sphinx_doc_src/cmds/prevd.rst +++ b/sphinx_doc_src/cmds/prevd.rst @@ -1,5 +1,5 @@ prevd - move backward through directory history -========================================== +=============================================== Synopsis -------- @@ -8,7 +8,7 @@ prevd [ -l | --list ] [POS] Description ------------- +----------- ``prevd`` moves backwards ``POS`` positions in the history of visited directories; if the beginning of the history has been hit, a warning is printed. @@ -19,7 +19,7 @@ Note that the ``cd`` command limits directory history to the 25 most recently vi You may be interested in the ``cdh`` command which provides a more intuitive way to navigate to recently visited directories. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/printf.rst b/sphinx_doc_src/cmds/printf.rst index d951e16ab..e883bdd72 100644 --- a/sphinx_doc_src/cmds/printf.rst +++ b/sphinx_doc_src/cmds/printf.rst @@ -1,5 +1,5 @@ printf - display text according to a format string -========================================== +================================================== Synopsis -------- @@ -8,7 +8,7 @@ printf format [argument...] Description ------------- +----------- printf formats the string FORMAT with ARGUMENT, and displays the result. The string FORMAT should contain format specifiers, each of which are replaced with successive arguments according to the specifier. Specifiers are detailed below, and are taken from the C library function ``printf(3)``. @@ -61,7 +61,7 @@ The ``format`` argument is re-used as many times as necessary to convert all of This file has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try ``command printf``. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/prompt_pwd.rst b/sphinx_doc_src/cmds/prompt_pwd.rst index 3d914d0cc..3d9ac5b37 100644 --- a/sphinx_doc_src/cmds/prompt_pwd.rst +++ b/sphinx_doc_src/cmds/prompt_pwd.rst @@ -8,14 +8,14 @@ prompt_pwd Description ------------- +----------- prompt_pwd is a function to print the current working directory in a way suitable for prompts. It will replace the home directory with "~" and shorten every path component but the last to a default of one character. To change the number of characters per path component, set $fish_prompt_pwd_dir_length to the number of characters. Setting it to 0 or an invalid value will disable shortening entirely. Examples ------------- +-------- diff --git a/sphinx_doc_src/cmds/psub.rst b/sphinx_doc_src/cmds/psub.rst index 6229ea2f9..f61a183f2 100644 --- a/sphinx_doc_src/cmds/psub.rst +++ b/sphinx_doc_src/cmds/psub.rst @@ -1,5 +1,5 @@ psub - perform process substitution -========================================== +=================================== Synopsis -------- @@ -8,7 +8,7 @@ COMMAND1 ( COMMAND2 | psub [-F | --fifo] [-f | --file] [-s SUFFIX]) Description ------------- +----------- Some shells (e.g., ksh, bash) feature a syntax that is a mix between command substitution and piping, called process substitution. It is used to send the output of a command into the calling command, much like command substitution, but with the difference that the output is not sent through commandline arguments but through a named pipe, with the filename of the named pipe sent as an argument to the calling program. ``psub`` combined with a regular command substitution provides the same functionality. @@ -21,7 +21,7 @@ The following options are available: - ``-s`` or ``--suffix`` will append SUFFIX to the filename. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/pushd.rst b/sphinx_doc_src/cmds/pushd.rst index 68cd3b5ae..a524ac93f 100644 --- a/sphinx_doc_src/cmds/pushd.rst +++ b/sphinx_doc_src/cmds/pushd.rst @@ -1,5 +1,5 @@ pushd - push directory to directory stack -========================================== +========================================= Synopsis -------- @@ -8,7 +8,7 @@ pushd [DIRECTORY] Description ------------- +----------- The ``pushd`` function adds ``DIRECTORY`` to the top of the directory stack and makes it the current working directory. ``popd`` will pop it off and return to the original directory. @@ -23,7 +23,7 @@ See also ``dirs`` and ``dirs -c``. You may be interested in the ``cdh`` command which provides a more intuitive way to navigate to recently visited directories. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/pwd.rst b/sphinx_doc_src/cmds/pwd.rst index 9845e1533..0521514a5 100644 --- a/sphinx_doc_src/cmds/pwd.rst +++ b/sphinx_doc_src/cmds/pwd.rst @@ -8,7 +8,7 @@ pwd Description ------------- +----------- ``pwd`` outputs (prints) the current working directory. diff --git a/sphinx_doc_src/cmds/random.rst b/sphinx_doc_src/cmds/random.rst index 43bbc1809..9b5a19ab2 100644 --- a/sphinx_doc_src/cmds/random.rst +++ b/sphinx_doc_src/cmds/random.rst @@ -1,5 +1,5 @@ random - generate random number -========================================== +=============================== Synopsis -------- @@ -12,7 +12,7 @@ random choice [ITEMS...] Description ------------- +----------- ``RANDOM`` generates a pseudo-random integer from a uniform distribution. The range (inclusive) is dependent on the arguments passed. @@ -31,7 +31,7 @@ You should not consider ``RANDOM`` cryptographically secure, or even statistically accurate. Example ------------- +------- The following code will count down from a random even number between 10 and 20 to 1: diff --git a/sphinx_doc_src/cmds/read.rst b/sphinx_doc_src/cmds/read.rst index 974ad6ab8..a420b5382 100644 --- a/sphinx_doc_src/cmds/read.rst +++ b/sphinx_doc_src/cmds/read.rst @@ -1,5 +1,5 @@ read - read line of input into variables -========================================== +======================================== Synopsis -------- @@ -8,7 +8,7 @@ read [OPTIONS] [VARIABLE ...] Description ------------- +----------- ``read`` reads from standard input and either writes the result back to standard output (for use in command substitution), or stores the result in one or more shell variables. By default, ``read`` reads a single line and splits it into variables on spaces or tabs. Alternatively, a null character or a maximum number of characters can be used to terminate the input, and other delimiters can be given. Unlike other shells, there is no default variable (such as ``REPLY``) for storing the result - instead, it is printed on standard output. @@ -73,12 +73,12 @@ is set to empty and the exit status is set to 122. This limit can be altered wit ``fish_read_limit`` variable. If set to 0 (zero), the limit is removed. Using another read history file ------------- +------------------------------- The ``read`` command supported the ``-m`` and ``--mode-name`` flags in fish versions prior to 2.7.0 to specify an alternative read history file. Those flags are now deprecated and ignored. Instead, set the ``fish_history`` variable to specify a history session ID. That will affect both the ``read`` history file and the fish command history file. You can set it to an empty string to specify that no history should be read or written. This is useful for presentations where you do not want possibly private or sensitive history to be exposed to the audience but do want history relevant to the presentation to be available. Example ------------- +------- The following code stores the value 'hello' in the shell variable ``$foo``. diff --git a/sphinx_doc_src/cmds/realpath.rst b/sphinx_doc_src/cmds/realpath.rst index 4b6700c66..859c6458b 100644 --- a/sphinx_doc_src/cmds/realpath.rst +++ b/sphinx_doc_src/cmds/realpath.rst @@ -1,5 +1,5 @@ realpath - Convert a path to an absolute path without symlinks -========================================== +============================================================== Synopsis -------- @@ -8,7 +8,7 @@ realpath path Description ------------- +----------- This is implemented as a function and a builtin. The function will attempt to use an external realpath command if one can be found. Otherwise it falls back to the builtin. The builtin does not support any options. It's meant to be used only by scripts which need to be portable. The builtin implementation behaves like GNU realpath when invoked without any options (which is the most common use case). In general scripts should not invoke the builtin directly. They should just use ``realpath``. diff --git a/sphinx_doc_src/cmds/return.rst b/sphinx_doc_src/cmds/return.rst index edf51aa9a..6de7c1dd7 100644 --- a/sphinx_doc_src/cmds/return.rst +++ b/sphinx_doc_src/cmds/return.rst @@ -1,5 +1,5 @@ return - stop the current inner function -========================================== +======================================== Synopsis -------- @@ -8,7 +8,7 @@ function NAME; [COMMANDS...;] return [STATUS]; [COMMANDS...;] end Description ------------- +----------- ``return`` halts a currently running function. The exit status is set to ``STATUS`` if it is given. @@ -16,7 +16,7 @@ It is usually added inside of a conditional block such as an ifshell variables. @@ -84,7 +84,7 @@ In assignment mode, ``set`` does not modify the exit status. This allows simulta Examples ------------- +-------- :: @@ -115,7 +115,7 @@ Examples Notes ------------- +----- Fish versions prior to 3.0 supported the syntax ``set PATH[1] PATH[4] /bin /sbin``, which worked like ``set PATH[1 4] /bin /sbin``. This syntax was not widely used, and was ambiguous and inconsistent. diff --git a/sphinx_doc_src/cmds/set_color.rst b/sphinx_doc_src/cmds/set_color.rst index 77aa432a0..e616fb58e 100644 --- a/sphinx_doc_src/cmds/set_color.rst +++ b/sphinx_doc_src/cmds/set_color.rst @@ -1,5 +1,5 @@ set_color - set the terminal color -========================================== +================================== Synopsis -------- @@ -8,7 +8,7 @@ set_color [OPTIONS] VALUE Description ------------- +----------- ``set_color`` is used to control the color and styling of text in the terminal. ``VALUE`` corresponds to a reserved color name such as *red* or a RGB color value given as 3 or 6 hexadecimal digits. The *br*-, as in 'bright', forms are full-brightness variants of the 8 standard-brightness colors on many terminals. *brblack* has higher brightness than *black* - towards gray. A special keyword *normal* resets text formatting to terminal defaults. @@ -32,7 +32,7 @@ The following options are available: Using the *normal* keyword will reset foreground, background, and all formatting back to default. Notes ------------- +----- 1. Using the *normal* keyword will reset both background and foreground colors to whatever is the default for the terminal. 2. Setting the background color only affects subsequently written characters. Fish provides no way to set the background color for the entire terminal window. Configuring the window background color (and other attributes such as its opacity) has to be done using whatever mechanisms the terminal provides. @@ -40,7 +40,7 @@ Notes 4. ``set_color`` works by printing sequences of characters to *stdout*. If used in command substitution or a pipe, these characters will also be captured. This may or may not be desirable. Checking the exit code of ``isatty stdout`` before using ``set_color`` can be useful to decide not to colorize output in a script. Examples ------------- +-------- @@ -53,7 +53,7 @@ Examples Terminal Capability Detection ------------- +----------------------------- Fish uses a heuristic to decide if a terminal supports the 256-color palette as opposed to the more limited 16 color palette of older terminals. Support can be forced on by setting ``fish_term256`` to *1*. If ``$TERM`` contains "256color" (e.g., *xterm-256color*), 256-color support is enabled. If ``$TERM`` contains *xterm*, 256 color support is enabled (except for MacOS: ``$TERM_PROGRAM`` and ``$TERM_PROGRAM_VERSION`` are used to detect Terminal.app from MacOS 10.6; support is disabled here it because it is known that it reports ``xterm`` and only supports 16 colors. diff --git a/sphinx_doc_src/cmds/source.rst b/sphinx_doc_src/cmds/source.rst index 8c1d2f710..33b5dc0c3 100644 --- a/sphinx_doc_src/cmds/source.rst +++ b/sphinx_doc_src/cmds/source.rst @@ -1,5 +1,5 @@ source - evaluate contents of file. -========================================== +=================================== Synopsis -------- @@ -9,7 +9,7 @@ somecommand | source Description ------------- +----------- ``source`` evaluates the commands of the specified file in the current shell. This is different from starting a new process to perform the commands (i.e. ``fish < FILENAME``) since the commands will be evaluated by the current shell, which means that changes in shell variables will affect the current shell. If additional arguments are specified after the file name, they will be inserted into the ``$argv`` variable. The ``$argv`` variable will not include the name of the sourced file. @@ -21,7 +21,7 @@ The return status of ``source`` is the return status of the last job to execute. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/status.rst b/sphinx_doc_src/cmds/status.rst index 40503f60b..8dda9dde6 100644 --- a/sphinx_doc_src/cmds/status.rst +++ b/sphinx_doc_src/cmds/status.rst @@ -1,5 +1,5 @@ status - query fish runtime information -========================================== +======================================= Synopsis -------- @@ -24,7 +24,7 @@ status test-feature FEATURE Description ------------- +----------- With no arguments, ``status`` displays a summary of the current login and job control status of the shell. @@ -64,7 +64,7 @@ The following operations (sub-commands) are available: - ``test-feature FEATURE`` returns 0 when FEATURE is enabled, 1 if it is disabled, and 2 if it is not recognized. Notes ------------- +----- For backwards compatibility each subcommand can also be specified as a long or short option. For example, rather than ``status is-login`` you can type ``status --is-login``. The flag forms are deprecated and may be removed in a future release (but not before fish 3.0). diff --git a/sphinx_doc_src/cmds/string.rst b/sphinx_doc_src/cmds/string.rst index bbfca183e..8b97ec3c0 100644 --- a/sphinx_doc_src/cmds/string.rst +++ b/sphinx_doc_src/cmds/string.rst @@ -1,5 +1,5 @@ string - manipulate strings -========================================== +=========================== Synopsis -------- @@ -29,7 +29,7 @@ string upper [(-q | --quiet)] [STRING...] Description ------------- +----------- ``string`` performs operations on strings. @@ -42,7 +42,7 @@ Most subcommands accept a ``-q`` or ``--quiet`` switch, which suppresses the usu The following subcommands are available. "escape" subcommand ------------- +------------------- ``string escape`` escapes each STRING in one of three ways. The first is ``--style=script``. This is the default. It alters the string such that it can be passed back to ``eval`` to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If ``-n`` or ``--no-quoted`` is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise. @@ -55,7 +55,7 @@ The following subcommands are available. ``string unescape`` performs the inverse of the ``string escape`` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing ``string unescape --style=var (string escape --style=var $str)`` will return the original string. There is no support for unescaping pcre2. "join" subcommand ------------- +----------------- ``string join`` joins its STRING arguments into a single string separated by SEP, which can be an empty string. Exit status: 0 if at least one join was performed, or 1 otherwise. @@ -64,17 +64,17 @@ The following subcommands are available. ``string join`` joins its STRING arguments into a single string separated by the zero byte (NUL), and adds a trailing NUL. This is most useful in conjunction with tools that accept NUL-delimited input, such as ``sort -z``. Exit status: 0 if at least one join was performed, or 1 otherwise. "length" subcommand ------------- +------------------- ``string length`` reports the length of each string argument in characters. Exit status: 0 if at least one non-empty STRING was given, or 1 otherwise. "lower" subcommand ------------- +------------------ ``string lower`` converts each string argument to lowercase. Exit status: 0 if at least one string was converted to lowercase, else 1. This means that in conjunction with the ``-q`` flag you can readily test whether a string is already lowercase. "match" subcommand ------------- +------------------ ``string match`` tests each STRING against PATTERN and prints matching substrings. Only the first match for each STRING is reported unless ``-a`` or ``--all`` is given, in which case all matches are reported. @@ -91,12 +91,12 @@ If ``--invert`` or ``-v`` is used the selected lines will be only those which do Exit status: 0 if at least one match was found, or 1 otherwise. "repeat" subcommand ------------- +------------------- ``string repeat`` repeats the STRING ``-n`` or ``--count`` times. The ``-m`` or ``--max`` option will limit the number of outputted char (excluding the newline). This option can be used by itself or in conjunction with ``--count``. If both ``--count`` and ``--max`` are present, max char will be outputed unless the final repeated string size is less than max, in that case, the string will repeat until count has been reached. Both ``--count`` and ``--max`` will accept a number greater than or equal to zero, in the case of zero, nothing will be outputed. If ``-N`` or ``--no-newline`` is given, the output won't contain a newline character at the end. Exit status: 0 if yielded string is not empty, 1 otherwise. "replace" subcommand ------------- +-------------------- ``string replace`` is similar to ``string match`` but replaces non-overlapping matching substrings with a replacement string and prints the result. By default, PATTERN is treated as a literal substring to be matched. @@ -107,7 +107,7 @@ If you specify the ``-f`` or ``--filter`` flag then each input string is printed Exit status: 0 if at least one replacement was performed, or 1 otherwise. "split" subcommand ------------- +------------------ ``string split`` splits each STRING on the separator SEP, which can be an empty string. If ``-m`` or ``--max`` is specified, at most MAX splits are done on each STRING. If ``-r`` or ``--right`` is given, splitting is performed right-to-left. This is useful in combination with ``-m`` or ``--max``. With ``-n`` or ``--no-empty``, empty results are excluded from consideration (e.g. ``hello\n\nworld`` would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise. @@ -120,22 +120,22 @@ See also ``read --delimiter``. ``split0`` has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as ``find -print0`` or ``sort -z``. See split0 examples below. "sub" subcommand ------------- +---------------- ``string sub`` prints a substring of each string argument. The start of the substring can be specified with ``-s`` or ``--start`` followed by a 1-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with ``-l`` or ``--length``. If the length is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise. "trim" subcommand ------------- +----------------- ``string trim`` removes leading and trailing whitespace from each STRING. If ``-l`` or ``--left`` is given, only leading whitespace is removed. If ``-r`` or ``--right`` is given, only trailing whitespace is trimmed. The ``-c`` or ``--chars`` switch causes the characters in CHARS to be removed instead of whitespace. Exit status: 0 if at least one character was trimmed, or 1 otherwise. "upper" subcommand ------------- +------------------ ``string upper`` converts each string argument to uppercase. Exit status: 0 if at least one string was converted to uppercase, else 1. This means that in conjunction with the ``-q`` flag you can readily test whether a string is already uppercase. Regular Expressions ------------- +------------------- Both the ``match`` and ``replace`` subcommand support regular expressions when used with the ``-r`` or ``--regex`` option. The dialect is that of PCRE2. @@ -186,7 +186,7 @@ And some other things: - ``|`` is "alternation", i.e. the "or". Examples ------------- +-------- @@ -270,7 +270,7 @@ Examples Match Glob Examples ------------- +------------------- @@ -306,7 +306,7 @@ Match Glob Examples Match Regex Examples ------------- +-------------------- @@ -362,7 +362,7 @@ Match Regex Examples Replace Literal Examples ------------- +------------------------ @@ -381,7 +381,7 @@ Replace Literal Examples Replace Regex Examples ------------- +---------------------- @@ -399,7 +399,7 @@ Replace Regex Examples Repeat Examples ------------- +--------------- diff --git a/sphinx_doc_src/cmds/suspend.rst b/sphinx_doc_src/cmds/suspend.rst index 21559783a..7e1b92129 100644 --- a/sphinx_doc_src/cmds/suspend.rst +++ b/sphinx_doc_src/cmds/suspend.rst @@ -1,5 +1,5 @@ suspend - suspend the current shell -========================================== +=================================== Synopsis -------- @@ -8,7 +8,7 @@ suspend [--force] Description ------------- +----------- ``suspend`` suspends execution of the current shell by sending it a SIGTSTP signal, returning to the controlling process. It can be diff --git a/sphinx_doc_src/cmds/switch.rst b/sphinx_doc_src/cmds/switch.rst index 92779c03c..d0a106b2f 100644 --- a/sphinx_doc_src/cmds/switch.rst +++ b/sphinx_doc_src/cmds/switch.rst @@ -1,5 +1,5 @@ switch - conditionally execute a block of commands -========================================== +================================================== Synopsis -------- @@ -8,7 +8,7 @@ switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end Description ------------- +----------- ``switch`` performs one of several blocks of commands, depending on whether a specified value equals one of several wildcarded values. ``case`` is used together with the ``switch`` statement in order to determine which block should be executed. @@ -20,7 +20,7 @@ Note that command substitutions in a case statement will be evaluated even if it Example ------------- +------- If the variable \$animal contains the name of an animal, the following code would attempt to classify it: diff --git a/sphinx_doc_src/cmds/test.rst b/sphinx_doc_src/cmds/test.rst index b807fb8c5..834415e32 100644 --- a/sphinx_doc_src/cmds/test.rst +++ b/sphinx_doc_src/cmds/test.rst @@ -1,5 +1,5 @@ test - perform tests on files and text -========================================== +====================================== Synopsis -------- @@ -9,7 +9,7 @@ test [EXPRESSION] Description ------------- +----------- Tests the expression given and sets the exit status to 0 if true, and 1 if false. An expression is made up of one or more operators and their arguments. @@ -20,7 +20,7 @@ This test is mostly POSIX-compatible. When using a variable as an argument for a test operator you should almost always enclose it in double-quotes. There are only two situations it is safe to omit the quote marks. The first is when the argument is a literal string with no whitespace or other characters special to the shell (e.g., semicolon). For example, ``test -b /my/file``. The second is using a variable that expands to exactly one element including if that element is the empty string (e.g., ``set x ''``). If the variable is not set, set but with no value, or set to more than one value you must enclose it in double-quotes. For example, ``test "$x" = "$y"``. Since it is always safe to enclose variables in double-quotes when used as ``test`` arguments that is the recommended practice. Operators for files and directories ------------- +----------------------------------- - ``-b FILE`` returns true if ``FILE`` is a block device. @@ -59,7 +59,7 @@ Operators for files and directories - ``-x FILE`` returns true if ``FILE`` is marked as executable. Operators for text strings ------------- +-------------------------- - ``STRING1 = STRING2`` returns true if the strings ``STRING1`` and ``STRING2`` are identical. @@ -70,7 +70,7 @@ Operators for text strings - ``-z STRING`` returns true if the length of ``STRING`` is zero. Operators to compare and examine numbers ------------- +---------------------------------------- - ``NUM1 -eq NUM2`` returns true if ``NUM1`` and ``NUM2`` are numerically equal. @@ -87,7 +87,7 @@ Operators to compare and examine numbers Both integers and floating point numbers are supported. Operators to combine expressions ------------- +-------------------------------- - ``COND1 -a COND2`` returns true if both ``COND1`` and ``COND2`` are true. @@ -105,7 +105,7 @@ Expressions can be grouped using parentheses. Examples ------------- +-------- If the ``/tmp`` directory exists, copy the ``/etc/motd`` file to it: @@ -185,7 +185,7 @@ which is logically equivalent to the following: Standards ------------- +--------- ``test`` implements a subset of the IEEE Std 1003.1-2008 (POSIX.1) standard. The following exceptions apply: diff --git a/sphinx_doc_src/cmds/trap.rst b/sphinx_doc_src/cmds/trap.rst index 76279ba8f..318fbd1b4 100644 --- a/sphinx_doc_src/cmds/trap.rst +++ b/sphinx_doc_src/cmds/trap.rst @@ -1,5 +1,5 @@ trap - perform an action when the shell receives a signal -========================================== +========================================================= Synopsis -------- @@ -8,7 +8,7 @@ trap [OPTIONS] [[ARG] REASON ... ] Description ------------- +----------- ``trap`` is a wrapper around the fish event delivery framework. It exists for backwards compatibility with POSIX shells. For other uses, it is recommended to define an event handler. @@ -33,7 +33,7 @@ Signal names are case insensitive and the ``SIG`` prefix is optional. The return status is 1 if any ``REASON`` is invalid; otherwise trap returns 0. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/true.rst b/sphinx_doc_src/cmds/true.rst index 98ce568a4..c8607d6ff 100644 --- a/sphinx_doc_src/cmds/true.rst +++ b/sphinx_doc_src/cmds/true.rst @@ -1,5 +1,5 @@ true - return a successful result -========================================== +================================= Synopsis -------- @@ -8,6 +8,6 @@ true Description ------------- +----------- ``true`` sets the exit status to 0. diff --git a/sphinx_doc_src/cmds/type.rst b/sphinx_doc_src/cmds/type.rst index c1fdfeb07..a793ee3a9 100644 --- a/sphinx_doc_src/cmds/type.rst +++ b/sphinx_doc_src/cmds/type.rst @@ -1,5 +1,5 @@ type - indicate how a command would be interpreted -========================================== +================================================== Synopsis -------- @@ -8,7 +8,7 @@ type [OPTIONS] NAME [NAME ...] Description ------------- +----------- With no options, ``type`` indicates how each ``NAME`` would be interpreted if used as a command name. @@ -30,7 +30,7 @@ The ``-q``, ``-p``, ``-t`` and ``-P`` flags (and their long flag aliases) are mu Example ------------- +------- diff --git a/sphinx_doc_src/cmds/ulimit.rst b/sphinx_doc_src/cmds/ulimit.rst index 032333aa0..846e06993 100644 --- a/sphinx_doc_src/cmds/ulimit.rst +++ b/sphinx_doc_src/cmds/ulimit.rst @@ -1,5 +1,5 @@ ulimit - set or get resource usage limits -========================================== +========================================= Synopsis -------- @@ -8,7 +8,7 @@ ulimit [OPTIONS] [LIMIT] Description ------------- +----------- ``ulimit`` builtin sets or outputs the resource usage limits of the shell and any processes spawned by it. If a new limit value is omitted, the current value of the limit of the resource is printed; otherwise, the specified limit is set to the new value. @@ -62,7 +62,7 @@ The ``fish`` implementation of ``ulimit`` should behave identically to the imple Example ------------- +------- ``ulimit -Hs 64`` sets the hard stack size limit to 64 kB. diff --git a/sphinx_doc_src/cmds/umask.rst b/sphinx_doc_src/cmds/umask.rst index f67e710dc..8775c8a5c 100644 --- a/sphinx_doc_src/cmds/umask.rst +++ b/sphinx_doc_src/cmds/umask.rst @@ -1,5 +1,5 @@ umask - set or get the file creation mode mask -========================================== +============================================== Synopsis -------- @@ -8,7 +8,7 @@ umask [OPTIONS] [MASK] Description ------------- +----------- ``umask`` displays and manipulates the "umask", or file creation mode mask, which is used to restrict the default access to files. @@ -40,6 +40,6 @@ Note that symbolic masks currently do not work as intended. Example ------------- +------- ``umask 177`` or ``umask u=rw`` sets the file creation mask to read and write for the owner and no permissions at all for any other users. diff --git a/sphinx_doc_src/cmds/vared.rst b/sphinx_doc_src/cmds/vared.rst index 91ab9028b..2fb29bf98 100644 --- a/sphinx_doc_src/cmds/vared.rst +++ b/sphinx_doc_src/cmds/vared.rst @@ -1,5 +1,5 @@ vared - interactively edit the value of an environment variable -========================================== +=============================================================== Synopsis -------- @@ -8,12 +8,12 @@ vared VARIABLE_NAME Description ------------- +----------- ``vared`` is used to interactively edit the value of an environment variable. Array variables as a whole can not be edited using ``vared``, but individual array elements can. Example ------------- +------- ``vared PATH[3]`` edits the third element of the PATH array diff --git a/sphinx_doc_src/cmds/wait.rst b/sphinx_doc_src/cmds/wait.rst index 7afa01edf..763d42191 100644 --- a/sphinx_doc_src/cmds/wait.rst +++ b/sphinx_doc_src/cmds/wait.rst @@ -1,5 +1,5 @@ wait - wait for jobs to complete -========================================== +================================ Synopsis -------- @@ -8,7 +8,7 @@ wait [-n | --any] [PID | PROCESS_NAME] ... Description ------------- +----------- ``wait`` waits for child jobs to complete. @@ -18,7 +18,7 @@ Description - If the ``-n`` / ``--any`` flag is provided, the command returns as soon as the first job completes. If it is not provided, it returns after all jobs complete. Example ------------- +------- diff --git a/sphinx_doc_src/cmds/while.rst b/sphinx_doc_src/cmds/while.rst index 6bc372767..8827dd75f 100644 --- a/sphinx_doc_src/cmds/while.rst +++ b/sphinx_doc_src/cmds/while.rst @@ -1,5 +1,5 @@ while - perform a command multiple times -========================================== +======================================== Synopsis -------- @@ -8,7 +8,7 @@ while CONDITION; COMMANDS...; end Description ------------- +----------- ``while`` repeatedly executes ``CONDITION``, and if the exit status is 0, then executes ``COMMANDS``. @@ -20,7 +20,7 @@ The exit status of the loop is 0 otherwise. You can use ``and`` or ``or`` for complex conditions. Even more complex control can be achieved with ``while true`` containing a break. Example ------------- +------- From fb75d0f848f4303444282655c57792cf93d66807 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 10 Feb 2019 14:38:04 -0800 Subject: [PATCH 111/191] Parse out command descriptions from files for Sphinx man pages sphinx expects that the description for a command (as appearing in its man page) be provided in conf.py, not in the rst file itself. LLVM handles this with some custom Python code that parses it out of the file. Do the same thing in fish. --- sphinx_doc_src/conf.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sphinx_doc_src/conf.py b/sphinx_doc_src/conf.py index 2ffcc5f3c..ffd8a2ee8 100644 --- a/sphinx_doc_src/conf.py +++ b/sphinx_doc_src/conf.py @@ -144,6 +144,16 @@ latex_documents = [ # -- Options for manual page output ------------------------------------------ +def get_command_description(path): + """ Return the description for a command, by parsing its first line """ + with open(path) as fd: + title = fd.readline() + if ' - ' not in title: + raise SphinxWarning('No description in file %s' % os.path.basename(path)) + _, desc = title.split(' - ', 1) + return desc.strip() + + # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ @@ -153,7 +163,7 @@ man_pages = [ for path in sorted(glob.glob('cmds/*')): docname = strip_ext(path) cmd = os.path.basename(docname) - man_pages.append((docname, cmd, '', '', 1)) + man_pages.append((docname, cmd, get_command_description(path), '', 1)) # -- Options for Texinfo output ---------------------------------------------- From 3debfe753425f4ecf2fb697c3766a2cc21c35798 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 10 Feb 2019 18:01:37 -0800 Subject: [PATCH 112/191] Break out commands into its own file --- sphinx_doc_src/commands.rst | 12 ++++++++++++ sphinx_doc_src/conf.py | 2 +- sphinx_doc_src/index.rst | 15 ++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 sphinx_doc_src/commands.rst diff --git a/sphinx_doc_src/commands.rst b/sphinx_doc_src/commands.rst new file mode 100644 index 000000000..f95eef343 --- /dev/null +++ b/sphinx_doc_src/commands.rst @@ -0,0 +1,12 @@ +.. highlight:: fish + +Commands +============ + +fish ships with the following commands: + +.. toctree:: + :glob: + :maxdepth: 1 + + cmds/* diff --git a/sphinx_doc_src/conf.py b/sphinx_doc_src/conf.py index ffd8a2ee8..52a49debb 100644 --- a/sphinx_doc_src/conf.py +++ b/sphinx_doc_src/conf.py @@ -104,7 +104,7 @@ html_static_path = ['_static'] # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', # 'searchbox.html']``. # -# html_sidebars = {} +html_sidebars = { '**': ['globaltoc.html', 'localtoc.html', 'searchbox.html'] } # -- Options for HTMLHelp output --------------------------------------------- diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index 4b23d4dd1..e4a5fcde1 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -5,13 +5,6 @@ Introduction This is the documentation for ``fish``, the friendly interactive shell. fish is a user friendly commandline shell intended mostly for interactive use. A shell is a program used to execute other programs. For the latest information on fish, please visit the `fish homepage `_. -.. toctree:: - :glob: - :maxdepth: 1 - - cmds/* - - .. _syntax: Syntax overview @@ -318,6 +311,14 @@ Help Help on a specific builtin can also be obtained with the ``-h`` parameter. For instance, to obtain help on the ``fg`` builtin, either type ``fg -h`` or ``help fg``. +Commands +======== + +.. toctree:: + :maxdepth: 1 + + commands + Autosuggestions =============== From d5e03929643accda7539d6a3542b3d517ac20924 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 15:01:16 -0800 Subject: [PATCH 113/191] Incorporate most new doc changes since branch Adds most documentation changes since 72c0213d42b77b2f01223b5515669840110ea9b9 --- sphinx_doc_src/cmds/abbr.rst | 3 +++ sphinx_doc_src/cmds/builtin.rst | 4 +++- sphinx_doc_src/cmds/command.rst | 4 ++-- sphinx_doc_src/cmds/math.rst | 10 +++++---- sphinx_doc_src/cmds/printf.rst | 2 +- sphinx_doc_src/cmds/status.rst | 5 ++++- sphinx_doc_src/cmds/string.rst | 2 +- sphinx_doc_src/cmds/type.rst | 4 ++-- sphinx_doc_src/cmds/while.rst | 5 +---- sphinx_doc_src/index.rst | 39 +++++++++++++++++++++++++-------- 10 files changed, 53 insertions(+), 25 deletions(-) diff --git a/sphinx_doc_src/cmds/abbr.rst b/sphinx_doc_src/cmds/abbr.rst index 1346c8adb..a4bcad137 100644 --- a/sphinx_doc_src/cmds/abbr.rst +++ b/sphinx_doc_src/cmds/abbr.rst @@ -9,6 +9,7 @@ abbr --erase word abbr --rename [SCOPE] OLD_WORD NEW_WORD abbr --show abbr --list +abbr --query WORD... Description ----------- @@ -32,6 +33,8 @@ The following options are available: - ``-e WORD`` or ``--erase WORD`` Erase the abbreviation WORD. +- ``-q`` or ``--query`` Return 0 (true) if one of the WORDs is an abbreviation. + In addition, when adding abbreviations: - ``-g`` or ``--global`` to use a global variable. diff --git a/sphinx_doc_src/cmds/builtin.rst b/sphinx_doc_src/cmds/builtin.rst index 651064e1a..ff6643724 100644 --- a/sphinx_doc_src/cmds/builtin.rst +++ b/sphinx_doc_src/cmds/builtin.rst @@ -4,7 +4,8 @@ builtin - run a builtin command Synopsis -------- -builtin BUILTINNAME [OPTIONS...] +builtin [OPTIONS...] BUILTINNAME +builtin --query BUILTINNAMES... Description @@ -15,6 +16,7 @@ Description The following parameters are available: - ``-n`` or ``--names`` List the names of all defined builtins +- ``-q`` or ``--query`` tests if any of the specified builtins exists Example diff --git a/sphinx_doc_src/cmds/command.rst b/sphinx_doc_src/cmds/command.rst index 82114a468..6b9c1f026 100644 --- a/sphinx_doc_src/cmds/command.rst +++ b/sphinx_doc_src/cmds/command.rst @@ -16,7 +16,7 @@ The following options are available: - ``-a`` or ``--all`` returns all the external commands that are found in ``$PATH`` in the order they are found. -- ``-q`` or ``--quiet``, in conjunction with ``-s``, silences the output and prints nothing, setting only the exit code. +- ``-q`` or ``--quiet``, silences the output and prints nothing, setting only the exit code. Implies ``--search``. - ``-s`` or ``--search`` returns the name of the external command that would be executed, or nothing if no file with the specified name could be found in the ``$PATH``. @@ -31,4 +31,4 @@ Examples ``command -s ls`` returns the path to the ``ls`` program. -``command -sq git; and command git log`` runs ``git log`` only if ``git`` exists. +``command -q git; and command git log`` runs ``git log`` only if ``git`` exists. diff --git a/sphinx_doc_src/cmds/math.rst b/sphinx_doc_src/cmds/math.rst index cb75f327b..254055047 100644 --- a/sphinx_doc_src/cmds/math.rst +++ b/sphinx_doc_src/cmds/math.rst @@ -14,13 +14,13 @@ Description By default, the output is as a float with trailing zeroes trimmed. To get a fixed representation, the ``--scale`` option can be used, including ``--scale=0`` for integer output. -Keep in mind that parameter expansion takes before expressions are evaluated. This can be very useful in order to perform calculations involving shell variables or the output of command substitutions, but it also means that parenthesis and the asterisk glob character have to be escaped or quoted. +Keep in mind that parameter expansion takes before expressions are evaluated. This can be very useful in order to perform calculations involving shell variables or the output of command substitutions, but it also means that parenthesis (``()``) and the asterisk (``*``) glob character have to be escaped or quoted. ``math`` ignores whitespace between arguments and takes its input as multiple arguments (internally joined with a space), so ``math 2 +2`` and ``math "2 + 2"`` work the same. ``math 2 2`` is an error. The following options are available: -- ``-sN`` or ``--scale=N`` sets the scale of the result. ``N`` must be an integer. A scale of zero causes results to be rounded down to the nearest integer. So ``3/2`` returns ``1`` rather than ``2`` which ``1.5`` would normally round to. This is for compatibility with ``bc`` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. +- ``-sN`` or ``--scale=N`` sets the scale of the result. ``N`` must be an integer or the word "max" for the maximum scale. A scale of zero causes results to be rounded down to the nearest integer. So ``3/2`` returns ``1`` rather than ``2`` which ``1.5`` would normally round to. This is for compatibility with ``bc`` which was the basis for this command prior to fish 3.0.0. Scale values greater than zero causes the result to be rounded using the usual rules to the specified number of decimal places. Return Values ------------- @@ -41,13 +41,13 @@ Operators - ``+`` for addition and ``-`` for subtraction. -- ``*`` for multiplication, ``/`` for division. +- ``*`` for multiplication, ``/`` for division. (Note that ``*`` is the glob character and needs to be quoted or escaped.) - ``^`` for exponentiation. - ``%`` for modulo. -- ``(`` and ``)`` for grouping. +- ``(`` and ``)`` for grouping. (These need to be quoted or escaped because ``()`` denotes a command substitution.) They are all used in an infix manner - ``5 + 2``, not ``+ 5 2``. @@ -106,6 +106,8 @@ Examples ``math "sin(pi)"`` outputs ``0``. +``math 5 \* 2`` or ``math "5 * 2"`` or ``math 5 "*" 2`` all output ``10``. + Compatibility notes ------------------- diff --git a/sphinx_doc_src/cmds/printf.rst b/sphinx_doc_src/cmds/printf.rst index e883bdd72..6c1717be0 100644 --- a/sphinx_doc_src/cmds/printf.rst +++ b/sphinx_doc_src/cmds/printf.rst @@ -75,6 +75,6 @@ Will print "flounder fish" (separated with a tab character), followed by a newli :: - printf '%s:%d' "Number of bananas in my pocket" 42 + printf '%s: %d' "Number of bananas in my pocket" 42 Will print "Number of bananas in my pocket: 42", _without_ a newline. diff --git a/sphinx_doc_src/cmds/status.rst b/sphinx_doc_src/cmds/status.rst index 8dda9dde6..397933939 100644 --- a/sphinx_doc_src/cmds/status.rst +++ b/sphinx_doc_src/cmds/status.rst @@ -13,6 +13,7 @@ status is-command-substitution status is-no-job-control status is-full-job-control status is-interactive-job-control +status current-command status filename status fish-path status function @@ -30,7 +31,7 @@ With no arguments, ``status`` displays a summary of the current login and job co The following operations (sub-commands) are available: -- ``is-command-sub`` returns 0 if fish is currently executing a command substitution. Also ``-c`` or ``--is-command-substitution``. +- ``is-command-substitution`` returns 0 if fish is currently executing a command substitution. Also ``-c`` or ``--is-command-substitution``. - ``is-block`` returns 0 if fish is currently executing a block of code. Also ``-b`` or ``--is-block``. @@ -46,6 +47,8 @@ The following operations (sub-commands) are available: - ``is-no-job-control`` returns 0 if no job control is enabled. Also ``--is-no-job-control`` (no short flag). +- ``current-command`` prints the name of the currently-running function or command, like the deprecated ``_`` variable. + - ``filename`` prints the filename of the currently running script. Also ``current-filename``, ``-f`` or ``--current-filename``. - ``fish-path`` prints the absolute path to the currently executing instance of fish. diff --git a/sphinx_doc_src/cmds/string.rst b/sphinx_doc_src/cmds/string.rst index 8b97ec3c0..fafb3b013 100644 --- a/sphinx_doc_src/cmds/string.rst +++ b/sphinx_doc_src/cmds/string.rst @@ -52,7 +52,7 @@ The following subcommands are available. ``--style=regex`` escapes an input string for literal matching within a regex expression. The string is first converted to UTF-8 before being encoded. -``string unescape`` performs the inverse of the ``string escape`` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing ``string unescape --style=var (string escape --style=var $str)`` will return the original string. There is no support for unescaping pcre2. +``string unescape`` performs the inverse of the ``string escape`` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing ``string unescape --style=var (string escape --style=var $str)`` will return the original string. There is no support for unescaping ``--style=regex``. "join" subcommand ----------------- diff --git a/sphinx_doc_src/cmds/type.rst b/sphinx_doc_src/cmds/type.rst index a793ee3a9..5f2347084 100644 --- a/sphinx_doc_src/cmds/type.rst +++ b/sphinx_doc_src/cmds/type.rst @@ -20,9 +20,9 @@ The following options are available: - ``-t`` or ``--type`` prints ``function``, ``builtin``, or ``file`` if ``NAME`` is a shell function, builtin, or disk file, respectively. -- ``-p`` or ``--path`` returns the name of the disk file that would be executed, or nothing if ``type -t name`` would not return ``file``. +- ``-p`` or ``--path`` prints the path to ``NAME`` if ``NAME`` resolves to an executable file in $PATH, the path to the script containing the definition of the function ``NAME`` if ``NAME`` resolves to a function loaded from a file on disk (i.e. not interactively defined at the prompt), or nothing otherwise. -- ``-P`` or ``--force-path`` returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the $PATH. +- ``-P`` or ``--force-path`` returns the path to the executable file ``NAME``, presuming ``NAME`` is found in ``$PATH``, or nothing otherwise. ``--force-path`` explicitly resolves only the path to executable files in ``$PATH``, regardless of whether ``$NAME`` is shadowed by a function or builtin with the same name. - ``-q`` or ``--quiet`` suppresses all output; this is useful when testing the exit status. diff --git a/sphinx_doc_src/cmds/while.rst b/sphinx_doc_src/cmds/while.rst index 8827dd75f..ccc022857 100644 --- a/sphinx_doc_src/cmds/while.rst +++ b/sphinx_doc_src/cmds/while.rst @@ -12,10 +12,7 @@ Description ``while`` repeatedly executes ``CONDITION``, and if the exit status is 0, then executes ``COMMANDS``. -If the exit status of ``CONDITION`` is non-zero on the first iteration, ``COMMANDS`` will not be -executed at all, and the exit status of the loop set to the exit status of ``CONDITION``. - -The exit status of the loop is 0 otherwise. +The exit status of the while loop is the exit status of the last iteration of the ``COMMANDS`` executed, or 0 if none were executed. (This matches other shells and is POSIX-compatible.) You can use ``and`` or ``or`` for complex conditions. Even more complex control can be achieved with ``while true`` containing a break. diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index e4a5fcde1..191fa9971 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -156,7 +156,7 @@ Any file descriptor can be redirected in an arbitrary way by prefixing the redir - To redirect output of FD N, write ``N>DESTINATION`` - To append the output of FD N to a file, write ``N>>DESTINATION_FILE`` -Example: ``echo Hello 2>output.stderr`` and ``echo Hello 2>output.stderr`` are equivalent, and write the standard error (file descriptor 2) of the target program to ``output.stderr``. +Example: ``echo Hello 2>output.stderr`` writes the standard error (file descriptor 2) of the target program to ``output.stderr``. Piping ------ @@ -335,8 +335,9 @@ Autosuggestions are a powerful way to quickly summon frequently entered commands Tab Completion ============== -Tab completion is one of the most time saving features of any modern shell. By tapping the tab key, the user asks ``fish`` to guess the rest of the command or parameter that the user is currently typing. If ``fish`` can only find one possible completion, ``fish`` will write it out. If there is more than one completion, ``fish`` will write out the longest prefix that all completions have in common. If the completions differ on the first character, a list of all possible completions is printed. The list features descriptions of the completions and if the list doesn't fit the screen, it is scrollable by using the arrow keys, the page up/page down keys, the tab key or the space bar. Once the list has been entered, pressing any other key will start a search. If the list has not been entered, pressing any other key will exit the list and insert the pressed key into the command line. +Tab completion is one of the most time saving features of any modern shell. By tapping the tab key, the user asks ``fish`` to guess the rest of the command or parameter that the user is currently typing. If ``fish`` can only find one possible completion, ``fish`` will write it out. If there is more than one completion, ``fish`` will write out the longest prefix that all completions have in common. If the completions differ on the first character, a list of all possible completions is printed. The list features descriptions of the completions and if the list doesn't fit the screen, it is scrollable by using the arrow keys, the page up/page down keys, the tab key or the space bar. +If the list is visible, pressing control-S (or the ``pager-toggle-search`` binding) will allow filtering the list. Shift-tab (or the ``complete-and-search`` binding) will trigger completion with the search field immediately visible. These are the general purpose tab completions that ``fish`` provides: - Completion of commands (builtins, functions and regular programs). @@ -450,7 +451,7 @@ If a star (``*``) or a question mark (``?``) is present in the parameter, ``fish - ``*`` can match any string of characters not containing '/'. This includes matching an empty string. -- ``**`` matches any string of characters. This includes matching an empty string. The matched string may include the ``/`` character; that is, it recurses into subdirectories. Note that augmenting this wildcard with other strings will not match files in the current working directory (``$PWD``) if you separate the strings with a slash ("/"). This is unlike other shells such as zsh. For example, ``**\/*.fish`` in zsh will match ``.fish`` files in the PWD but in fish will only match such files in a subdirectory. In fish you should type ``***.fish`` to match files in the PWD as well as subdirectories. +- ``**`` matches any string of characters. This includes matching an empty string. The matched string may include the ``/`` character; that is, it recurses into subdirectories. Note that augmenting this wildcard with other strings will not match files in the current working directory (``$PWD``) if you separate the strings with a slash ("/"). This is unlike other shells such as zsh. For example, ``**\/*.fish`` in zsh will match ``.fish`` files in the PWD but in fish will only match such files in a subdirectory. In fish you should type ``**.fish`` to match files in the PWD as well as subdirectories. Other shells, such as zsh, provide a rich glob syntax for restricting the files matched by globs. For example, ``**(.)``, to only match regular files. Fish prefers to defer such features to programs, such as ``find``, rather than reinventing the wheel. Thus, if you want to limit the wildcard expansion to just regular files the fish approach is to define and use a function. For example, @@ -949,7 +950,7 @@ The user can change the settings of ``fish`` by changing the values of certain v - ``fish_ambiguous_width`` controls the computed width of ambiguous East Asian characters. This should be set to 1 if your terminal emulator renders these characters as single-width (typical), or 2 if double-width. -- ``fish_escape_delay_ms`` overrides the default timeout of 300ms (default key bindings) or 10ms (vi key bindings) after seeing an escape character before giving up on matching a key binding. See the documentation for the bind builtin command. This delay facilitates using escape as a meta key. +- ``fish_escape_delay_ms`` overrides the default timeout of 30ms after seeing an escape character before giving up on matching a key binding. See the documentation for the bind builtin command. This delay facilitates using escape as a meta key. - ``fish_greeting``, the greeting message printed on startup. @@ -973,7 +974,7 @@ The user can change the settings of ``fish`` by changing the values of certain v ``fish`` also sends additional information to the user through the values of certain environment variables. The user cannot change the values of most of these variables. -- ``_``, the name of the currently running command. +- ``_``, the name of the currently running command (though this is deprecated, and the use of ``status current-command`` is preferred). - ``argv``, an array of arguments to the shell or function. ``argv`` is only defined when inside a function call, or if fish was invoked with a list of arguments, like ``fish myscript.fish foo bar``. This variable can be changed by the user. @@ -981,6 +982,8 @@ The user can change the settings of ``fish`` by changing the values of certain v - ``HOME``, the user's home directory. This variable can be changed by the user. +- ``hostname``, the machine's hostname. + - ``IFS``, the internal field separator that is used for word splitting with the read builtin. Setting this to the empty string will also disable line splitting in `command substitution <#expand-command-substitution>`_. This variable can be changed by the user. - ``PWD``, the current working directory. @@ -1078,15 +1081,31 @@ The following variables are available to change the highlighting colors in fish: Additionally, the following variables are available to change the highlighting in the completion pager: +- ``fish_pager_color_progress``, the color of the progress bar at the bottom left corner + +- ``fish_pager_color_background``, the background color of a line + - ``fish_pager_color_prefix``, the color of the prefix string, i.e. the string that is to be completed - ``fish_pager_color_completion``, the color of the completion itself - ``fish_pager_color_description``, the color of the completion description -- ``fish_pager_color_progress``, the color of the progress bar at the bottom left corner +- ``fish_pager_color_secondary_background``, ``fish_pager_color_background`` of every second unselected completion. Defaults to ``fish_pager_color_background`` -- ``fish_pager_color_secondary``, the background color of the every second completion +- ``fish_pager_color_secondary_ prefix``, ``fish_pager_color_prefix`` of every second unselected completion. Defaults to ``fish_pager_color_prefix`` + +- ``fish_pager_color_secondary_completion``, ``fish_pager_color_completion`` of every second unselected completion. Defaults to ``fish_pager_color_completion`` + +- ``fish_pager_color_secondary_description``, ``fish_pager_color_description`` of every second unselected completion. Defaults to ``fish_pager_color_description`` + +- ``fish_pager_color_selected_background``, ``fish_pager_color_background`` of the selected completion. Defaults to ``fish_color_search_match`` + +- ``fish_pager_color_selected_prefix``, ``fish_pager_color_prefix`` of the selected completion. Defaults to ``fish_pager_color_prefix`` + +- ``fish_pager_color_selected_completion``, ``fish_pager_color_completion`` of the selected completion. Defaults to ``fish_pager_color_completion`` + +- ``fish_pager_color_selected_description``, ``fish_pager_color_description`` of the selected completion. Defaults to ``fish_pager_color_description`` Example: @@ -1142,7 +1161,9 @@ Some bindings are shared between emacs- and vi-mode because they aren't text edi - @key{Tab} `completes <#completion>`_ the current token. @key{Shift, Tab} completes the current token and starts the pager's search mode. -- @key{Alt,←,Left} and @key{Alt,→,Right} move the cursor one word left or right, or moves forward/backward in the directory history if the command line is empty. If the cursor is already at the end of the line, and an autosuggestion is available, @key{Alt,→,Right} (or @key{Alt,F}) accepts the first word in the suggestion. +- @key{Alt,←,Left} and @key{Alt,→,Right} move the cursor one word left or right (to the next space or punctuation mark), or moves forward/backward in the directory history if the command line is empty. If the cursor is already at the end of the line, and an autosuggestion is available, @key{Alt,→,Right} (or @key{Alt,F}) accepts the first word in the suggestion. + +- @key{Shift,←,Left} and @key{Shift,→,Right} move the cursor one word left or right, without stopping on punctuation. - @cursor_key{↑,Up} and @cursor_key{↓,Down} (or @key{Control,P} and @key{Control,N} for emacs aficionados) search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match. See the `history <#history>`_ section for more information on history searching. @@ -1352,7 +1373,6 @@ On startup, Fish evaluates a number of configuration files, which can be used to Configuration files are evaluated in the following order: - Configuration shipped with fish, which should not be edited, in ``$__fish_data_dir/config.fish`` (usually ``/usr/share/fish/config.fish`). -- System-wide configuration files, where administrators can include initialization that should be run for all users on the system - similar to ``/etc/profile`` for POSIX-style shells - in ``$__fish_sysconf_dir``` (usually ``/etc/fish/config.fish``); - Configuration snippets in files ending in ``.fish``, in the directories: - ``$__fish_config_dir/conf.d`` (by default, ``~/.config/fish/conf.d/``) - ``$__fish_sysconf_dir/conf.d`` (by default, ``/etc/fish/conf.d``) @@ -1361,6 +1381,7 @@ Configuration files are evaluated in the following order: If there are multiple files with the same name in these directories, only the first will be executed. They are executed in order of their filename, sorted (like globs) in a natural order (i.e. "01" sorts before "2"). +- System-wide configuration files, where administrators can include initialization that should be run for all users on the system - similar to ``/etc/profile`` for POSIX-style shells - in ``$__fish_sysconf_dir``` (usually ``/etc/fish/config.fish``); - User initialization, usually in `~/.config/fish/config.fish` (controlled by the ``XDG_CONFIG_HOME`` environment variable, and accessible as ``$__fish_config_dir``). These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above. From 2b89cbc6786c9f7203f965cf7279b19c100ab7fa Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 15:46:10 -0800 Subject: [PATCH 114/191] Incorporate sabine's index changes into sphinx docs Adds: f6974e5a7676d0cd5c4b32300688eb669fe8992b 20c51b7da9cf468fd74af3056dceb0701fe60e63 --- sphinx_doc_src/index.rst | 205 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 202 insertions(+), 3 deletions(-) diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index 191fa9971..e12b046eb 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -3,7 +3,208 @@ Introduction ============ -This is the documentation for ``fish``, the friendly interactive shell. fish is a user friendly commandline shell intended mostly for interactive use. A shell is a program used to execute other programs. For the latest information on fish, please visit the `fish homepage `_. +This is the documentation for *fish*: the **f**\ riendly **i**\ nteractive **sh**\ ell. + +A shell is a commandline interpreter. It reads text input from the commandline and interpretes it as commands to operating system, see: `What is a Shell`_. + +So shells serve as user-interface between applications and the operating system. There are many different shells. They differ on how this interface is implemented. *fish* specializes in the following ways: + +- **Extensive UI**: *fish* supports the user with syntax highlighting, autosuggestions, tab completions and selections lists, that can be navigated and filtered, see: `Autosuggestions`_ and `Tab Completion`_. + +- **No configuration needed**: *fish* comes preconfigured so that it will be an efficient helper on the commandline out of the box. + +- **Add new commands easily**: in *fish* new commands can be added on the fly. The syntax is easy to learn and there is no administrative overhead, see `Functions`_. + +- **Interactive shell**: *fish* focuses on commands that will be run in an interactive session: While it supports job control for external commands, its own commands share the process of the shell, that started them. + +What is a Shell +=============== + +This section is about the basics of shells. *fish* is a shell and shells have a lot in common: + +- `Shell Standards`_ Why shells adjust to standards +- `Manual Pages`_: Commands usually come with a standardized manual page +- `Command Syntax`_: Shell commands have a standard syntax +- `Commands versus Programs`_: Commands differ from normal programs +- `Shebang Line`_: How the shell knows the language of a script + +Shell Standards +--------------- + +A shell is an interface to the operating system that reads from the commandline of a terminal. A shell's task is to identify and interpret commands. The commands can come from different applications and can be written in different programming languages. + +This can only work smoothly if shells adapt to some common standards. For shells there is the POSIX standard, see `Command-line interpreters `_. ``fish`` tries to satisfy the POSIX standard wherever it does not get into the way of its own design principles, see ``fish`` Design. + +Manual Pages +------------ + +There is a common standard on how to receive help on shell commands: applications provide a manual page to their commands that can be opened with the ``man`` command: + + +:: + + > man COMMAND + + +This convention helps to make sure help can be found on commands no matter where they originate from. *fish*'s internal commands all come with a manual page. + +Command Syntax +-------------- + +Shells also support some common syntax for executing commands. That way a command can be started in the same way, regardless of the application, where it comes from, and the shell, where it is executed in. + +The pattern below is a basic pattern: + + + +:: + + COMMAND [OPTIONS] ARGUMENTS + + +- **COMMAND**: the name of the executeable + +- **[OPTIONS]**: options can change the behaviour of a command + +- **ARGUMENTS**: input to the command + +For external **commands** the executable is usually stored on file and the file path must be included in the variable ``$PATH``, so that the file can be found: see `Special Variables`_. + +**Options** come in two forms: a short name, that is a hyphen with a single letter; or a long name, consisting of two hyphens with words connected by hyphens. Example: ``-h`` and ``--help`` are often used to print a help message. Options are a fixed set, described in the manual pages of the command, see Manual Pages + +**Arguments** are the arbitrary input part of a command: often it is a file or directory name, sometimes it is a string or a list. + +Example: + + + +:: + + >echo -s Hallo World! + HalloWorld! + + +- both ``Hallo`` and ``World!`` are arguments to the echo command +- ``-s`` is an option that suppresses spaces in the output of the command + +Commands versus Programs +------------------------ + +**Programs** in other languages can often be regarded as black boxes: they get complex input and return complex output. Sometimes they produce side effects such as writing to a file or reporting an error, but the emphasis is on: arguments in and return values out: + +Arguments → |Program| → Return Values + +**Shell commands** are different: + +- the side effects take the center of the stage: they transform an **input stream of data** into an **output stream of data**. Both of these streams are usually the terminal, but they can be redirected. +- the arguments become options or switches paired with data: the switches influence the behaviour of the command +- the return value shrinks to an **exit code**: this exit code is 0 when the command executes normally and between 1 and 255 otherwise. + + +
Input Stream ⇒|Shell Command|⇒ Output Stream +
switch and data as arguments →→ exit code +
+ +This leads to another way of programming and especially of combining commands: + +There are two ways to combine shell commands: + +- Commands can pass on their streams to each other: one command takes the output stream of another command as its input stream and the two commands execute in parallel. This is called piping, see `Piping`_. + +Example:: + + # Every line of the ``ls`` command is immediatelly passed on to the ``grep`` command + >ls -l | grep "my topic" + + +- Commands can pass on all their output as a chunk: the output stream of one command is bundled and taken as data argument for the second command. This is called command substitution, see `Command Substitution`_. + +Example:: + + # the output of the inner ``ls`` command is taken as the input argument for the outer ``echo`` command + >echo (ls a*) + + +Shebang Line +------------ + +Since script for shell commands can be written in many different languages, they need to carry information about what interpreter is needed to execute them: For this they are expected to have a first line, the shebang line, which names an executable for this purpose: + +Example: + +A scripts written in ``bash`` it would need a first line like this:: + + #!/bin/bash + + +This line tells the shell to execute the file with the *bash* interpreter, that is located at the path ``/bin/bash``. + +For a script, written in another language, just replace the interpreter ``/bin/bash`` with the language interpreter of that other language (for example ``/bin/python`` for a ``python`` script) + +This line is only needed when scripts are executed by another interpreter, so for *fish* internal commands, that are executed by *fish* the shebang line is not necessary. + + +Installation and Start +====================== + +This section is on how to install, uninstall, start and exit a *fish* shell and on how to make *fish* the default shell: + +- `Installation`_: How to install *fish* +- `Default Shell`_: How to switch to *fish* as the default shell +- `Starting and Exiting`_ How to start and exit a *fish* shell +- `Uninstalling`_: How to uninstall *fish* +- `Executing Bash`_: How to execute *bash* commands in *fish* + +Installation +------------ + +Instructions for installing fish are on the `fish homepage `_. Search that page for "Go fish". + +To install the development version of *fish* see the instructions at the `project's GitHub page Switching to *fish*. + +Uninstalling +------------ + +For uninstalling *fish*: see FAQ: Uninstalling *fish* + +Starting and Exiting +-------------------- + +Once *fish* has been installed, open a terminal. If *fish* is not the default shell: + +- Enter ``fish`` to start a *fish* shell:: + + > fish + + +- Enter ``exit`` to exit a *fish* shell:: + + > exit + + +Executing Bash +-------------- + +If *fish* is your default shell and you want to copy commands from the internet, that are written in a different shell language, *bash* for example, you can proceed in the following way: + +Consider, that ``bash`` is also a command. With ``man bash`` you can see that there are two ways to do this: + +- ``bash`` has a switch ``-c`` to read from a string:: + + > bash -c SomeBashCommand + + +or ``bash`` without a switch, opens a *bash* shell that you can use and ``exit`` afterwards. + .. _syntax: @@ -330,8 +531,6 @@ To accept the autosuggestion (replacing the command line contents), press right Autosuggestions are a powerful way to quickly summon frequently entered commands, by typing the first few characters. They are also an efficient technique for navigating through directory hierarchies. -.. _completion: - Tab Completion ============== From 9a35df059a193434530d476f7b3124e659a7697f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 16:11:07 -0800 Subject: [PATCH 115/191] Clean up fish_breakpoint_prompt sphinx docs --- sphinx_doc_src/cmds/fish_breakpoint_prompt.rst | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst index 4d4bd2ac6..b60eee2b2 100644 --- a/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst +++ b/sphinx_doc_src/cmds/fish_breakpoint_prompt.rst @@ -1,12 +1,12 @@ -fish_breakpoint_prompt - define the appearance of the command line prompt when in the context of a ``breakpoint`` command -========================================================================================================================= +fish_breakpoint_prompt - define the prompt when stopped at a breakpoint +======================================================================= Synopsis -------- -function fish_breakpoint_prompt - ... -end + function fish_breakpoint_prompt + ... + end Description @@ -22,11 +22,7 @@ The exit status of commands within ``fish_breakpoint_prompt`` will not modify th Example ------- -A simple prompt that is a simplified version of the default debugging prompt: - - - -:: +A simple prompt that is a simplified version of the default debugging prompt:: function fish_breakpoint_prompt -d "Write out the debug prompt" set -l function (status current-function) From 6cd88564841e96c96ebfed978e24a2e1a895378a Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 16:20:25 -0800 Subject: [PATCH 116/191] Add the vcs prompts to sphinx docs --- sphinx_doc_src/cmds/fish_git_prompt.rst | 95 +++++++++++++++++++++++++ sphinx_doc_src/cmds/fish_hg_prompt.rst | 47 ++++++++++++ sphinx_doc_src/cmds/fish_svn_prompt.rst | 85 ++++++++++++++++++++++ sphinx_doc_src/cmds/fish_vcs_prompt.rst | 27 +++++++ 4 files changed, 254 insertions(+) create mode 100644 sphinx_doc_src/cmds/fish_git_prompt.rst create mode 100644 sphinx_doc_src/cmds/fish_hg_prompt.rst create mode 100644 sphinx_doc_src/cmds/fish_svn_prompt.rst create mode 100644 sphinx_doc_src/cmds/fish_vcs_prompt.rst diff --git a/sphinx_doc_src/cmds/fish_git_prompt.rst b/sphinx_doc_src/cmds/fish_git_prompt.rst new file mode 100644 index 000000000..298e436ae --- /dev/null +++ b/sphinx_doc_src/cmds/fish_git_prompt.rst @@ -0,0 +1,95 @@ +fish_git_prompt - output git information for use in a prompt +============================================================ + +Description +----------- + +The fish_git_prompt function can be used to display information about the current git repository, if any. + +For obvious reasons, it requires having git installed. + +There are numerous configuration options, either as fish variables or git config variables. If a git config variable is supported, it will be used if set, and the fish variable will only be used if it isn't. + +- $__fish_git_prompt_showdirtystate or the git config option "bash.showDirtyState" can be set to show if the repository is "dirty", i.e. has uncommitted changes. + +- $__fish_git_prompt_showuntrackedfiles or the git config option "bash.showUntrackedFiles" can be set to show if the repository has untracked files (that aren't ignored). + +- $__fish_git_prompt_show_informative_status or the git config option "bash.showInformativeStatus" can be set to enable the "informative" display, which will show a large amount of information - the number of untracked files, dirty files, unpushed/unpulled commits, etc... In large repositories, this can take a lot of time, so it is recommended to disable it there. + +- $__fish_git_prompt_showupstream can be set to a number of values to determine how changes between HEAD and upstream are shown: + + verbose show number of commits ahead/behind (+/-) upstream + name if verbose, then also show the upstream abbrev name + informative similar to verbose, but shows nothing when equal (fish only) + git always compare HEAD to @{upstream} + svn always compare HEAD to your SVN upstream + none disables (fish only, useful with show_informative_status) + +- $__fish_git_prompt_showstashstate can be set to display the state of the stash. + +- $__fish_git_prompt_shorten_branch_len can be set to the number of characters that the branch name will be shortened to. + +- $__fish_git_prompt_describe_style can be set to a number of styles that describe the current HEAD: + + contains + branch + describe + default + +- $__fish_git_prompt_showcolorhints can be set to enable coloring for certain things. + +A number of variables to set characters and color used to indicate things. + +- $__fish_git_prompt_char_cleanstate +- $__fish_git_prompt_char_dirtystate +- $__fish_git_prompt_char_invalidstate +- $__fish_git_prompt_char_stagedstate +- $__fish_git_prompt_char_stashstate +- $__fish_git_prompt_char_stateseparator +- $__fish_git_prompt_char_untrackedfiles +- $__fish_git_prompt_char_upstream_ahead +- $__fish_git_prompt_char_upstream_behind +- $__fish_git_prompt_char_upstream_diverged +- $__fish_git_prompt_char_upstream_equal +- $__fish_git_prompt_char_upstream_prefix +- $__fish_git_prompt_color +- $__fish_git_prompt_color_prefix +- $__fish_git_prompt_color_suffix +- $__fish_git_prompt_color_bare +- $__fish_git_prompt_color_merging +- $__fish_git_prompt_color_cleanstate +- $__fish_git_prompt_color_invalidstate +- $__fish_git_prompt_color_upstream + +Colors used with showcolorhints: + +- $__fish_git_prompt_color_flags +- $__fish_git_prompt_color_branch +- $__fish_git_prompt_color_dirtystate +- $__fish_git_prompt_color_stagedstate +- $__fish_git_prompt_color_flags +- $__fish_git_prompt_color_branch +- $__fish_git_prompt_color_dirtystate +- $__fish_git_prompt_color_stagedstate +- $__fish_git_prompt_color_branch_detached + +Colors used with their respective flags enabled: +- $__fish_git_prompt_color_stashstate +- $__fish_git_prompt_color_untrackedfiles + +Note that all colors can also have a corresponding "_done" color. E.g. $__fish_git_prompt_color_upstream_done, used right _after_ the upstream. + +See also fish_vcs_prompt, which will call all supported vcs-prompt functions, including git, hg and svn. + +Example +-------- + +A simple prompt that displays git info:: + + function fish_prompt + ... + set -g __fish_git_prompt_showupstream auto + printf '%s %s$' $PWD (fish_git_prompt) + end + + diff --git a/sphinx_doc_src/cmds/fish_hg_prompt.rst b/sphinx_doc_src/cmds/fish_hg_prompt.rst new file mode 100644 index 000000000..5c8a1a0cb --- /dev/null +++ b/sphinx_doc_src/cmds/fish_hg_prompt.rst @@ -0,0 +1,47 @@ +fish_hg_prompt - output mercurial information for use in a prompt +================================================================= + +Description +----------- + +The fish_hg_prompt function can be used to display information about the current mercurial repository, if any. + +For obvious reasons, it requires having hg installed. + +There are numerous configuration options: + +- $fish_color_hg_clean, $fish_color_hg_modified and $fish_color_hg_dirty: The color to use when the repo has the respective status + +Some colors for status symbols: + +- $fish_color_hg_added +- $fish_color_hg_renamed +- $fish_color_hg_copied +- $fish_color_hg_deleted +- $fish_color_hg_untracked +- $fish_color_hg_unmerged + +And the status symbols themselves: + +- $fish_prompt_hg_status_added, default '✚' +- $fish_prompt_hg_status_modified, default '*' +- $fish_prompt_hg_status_copied, default '⇒' +- $fish_prompt_hg_status_deleted, default '✖' +- $fish_prompt_hg_status_untracked, default '?' +- $fish_prompt_hg_status_unmerged, default '!' + +And $fish_prompt_hg_status_order, which can be used to change the order the status symbols appear in. It defaults to ``added modified copied deleted untracked unmerged``. + +See also fish_vcs_prompt, which will call all supported vcs-prompt functions, including git, hg and svn. + +Example +------- + +A simple prompt that displays hg info:: + + function fish_prompt + ... + printf '%s %s$' $PWD (fish_hg_prompt) + end + + diff --git a/sphinx_doc_src/cmds/fish_svn_prompt.rst b/sphinx_doc_src/cmds/fish_svn_prompt.rst new file mode 100644 index 000000000..f467f31e2 --- /dev/null +++ b/sphinx_doc_src/cmds/fish_svn_prompt.rst @@ -0,0 +1,85 @@ +fish_svn_prompt - output svn information for use in a prompt +============================================================ + +Description +----------- + + +The fish_svn_prompt function can be used to display information about the current svn repository, if any. + +For obvious reasons, it requires having svn installed. + +There are numerous configuration options: + + +- $__fish_svn_prompt_color_revision, the colour of the revision number to display in the prompt +# setting the prompt status separator character +- $__fish_svn_prompt_char_separator, the separator between status characters + +And +- $__fish_svn_prompt_char_added_display +- $__fish_svn_prompt_char_added_color + +- $__fish_svn_prompt_char_conflicted_display +- $__fish_svn_prompt_char_conflicted_color + +- $__fish_svn_prompt_char_deleted_display +- $__fish_svn_prompt_char_deleted_color + +- $__fish_svn_prompt_char_ignored_display +- $__fish_svn_prompt_char_ignored_color + +- $__fish_svn_prompt_char_modified_display +- $__fish_svn_prompt_char_modified_color + +- $__fish_svn_prompt_char_replaced_display +- $__fish_svn_prompt_char_replaced_color + +- $__fish_svn_prompt_char_unversioned_external_display +- $__fish_svn_prompt_char_unversioned_external_color + +- $__fish_svn_prompt_char_unversioned_display +- $__fish_svn_prompt_char_unversioned_color + +- $__fish_svn_prompt_char_missing_display +- $__fish_svn_prompt_char_missing_color + +- $__fish_svn_prompt_char_versioned_obstructed_display +- $__fish_svn_prompt_char_versioned_obstructed_color + +- $__fish_svn_prompt_char_locked_display +- $__fish_svn_prompt_char_locked_color + +- $__fish_svn_prompt_char_scheduled_display +- $__fish_svn_prompt_char_scheduled_color + +- $__fish_svn_prompt_char_switched_display +- $__fish_svn_prompt_char_switched_color + +- $__fish_svn_prompt_char_token_present_display +- $__fish_svn_prompt_char_token_present_color + +- $__fish_svn_prompt_char_token_other_display +- $__fish_svn_prompt_char_token_other_color + +- $__fish_svn_prompt_char_token_stolen_display +- $__fish_svn_prompt_char_token_stolen_color + +- $__fish_svn_prompt_char_token_broken_display +- $__fish_svn_prompt_char_token_broken_color + +to choose the color and symbol for different parts of the prompt. + +See also fish_vcs_prompt, which will call all supported vcs-prompt functions, including git, hg and svn. + +Example +------- + +A simple prompt that displays svn info:: + + function fish_prompt + ... + printf '%s %s$' $PWD (fish_svn_prompt) + end + + diff --git a/sphinx_doc_src/cmds/fish_vcs_prompt.rst b/sphinx_doc_src/cmds/fish_vcs_prompt.rst new file mode 100644 index 000000000..716c26d98 --- /dev/null +++ b/sphinx_doc_src/cmds/fish_vcs_prompt.rst @@ -0,0 +1,27 @@ +fish_vcs_prompt - output vcs information for use in a prompt +============================================================ + +Description +----------- + +The fish_vcs_prompt function can be used to display information about the current vcs repository, if any. + +It calls out to vcs-specific functions. The currently supported ones are: + +- fish_git_prompt +- fish_hg_prompt +- fish_svn_prompt + +If a vcs isn't installed, the respective function does nothing. + +For more information, see their documentation. + +\subsection fish_vcs_prompt-example Example + +A simple prompt that displays vcs info:: + + function fish_prompt + ... + set -g __fish_git_prompt_showupstream auto + printf '%s %s$' $PWD (fish_vcs_prompt) + end From 6241bd8453b4f1da39c0868300f892de92252e88 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 17:13:01 -0800 Subject: [PATCH 117/191] Add tutorial to sphinx docs build --- sphinx_doc_src/index.rst | 1 + sphinx_doc_src/tutorial.rst | 699 ++++++++++++++++++++++++++++++++++++ 2 files changed, 700 insertions(+) create mode 100644 sphinx_doc_src/tutorial.rst diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index e12b046eb..288064aeb 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -519,6 +519,7 @@ Commands :maxdepth: 1 commands + tutorial Autosuggestions diff --git a/sphinx_doc_src/tutorial.rst b/sphinx_doc_src/tutorial.rst new file mode 100644 index 000000000..30b22a29d --- /dev/null +++ b/sphinx_doc_src/tutorial.rst @@ -0,0 +1,699 @@ +.. highlight:: fish + +Tutorial +======== + +Why fish? +--------- + +``fish`` is a fully-equipped command line shell (like bash or zsh) that is smart and user-friendly. ``fish`` supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure. + +If you want to make your command line more productive, more useful, and more fun, without learning a bunch of arcane syntax and configuration options, then ``fish`` might be just what you're looking for! + + +Getting started +--------------- + +Once installed, just type in ``fish`` into your current shell to try it out! + +You will be greeted by the standard fish prompt, +which means you are all set up and can start using fish:: + + > fish + Welcome to fish, the friendly interactive shell + Type help for instructions on how to use fish + you@hostname ~>____ + + +This prompt that you see above is the ``fish`` default prompt: it shows your username, hostname, and working directory. +- to change this prompt see `how to change your prompt `_ +- to switch to fish permanently see `switch your default shell to fish <#switching-to-fish>`_. + +From now on, we'll pretend your prompt is just a '``>``' to save space. + + +Learning fish +------------- + +This tutorial assumes a basic understanding of command line shells and Unix commands, and that you have a working copy of ``fish``. + +If you have a strong understanding of other shells, and want to know what ``fish`` does differently, search for the magic phrase unlike other shells, which is used to call out important differences. + + +Running Commands +---------------- + +``fish`` runs commands like other shells: you type a command, followed by its arguments. Spaces are separators:: + + >_ echo hello world + hello world + + +You can include a literal space in an argument with a backslash, or by using single or double quotes:: + + >_ mkdir My\ Files + >_ cp ~/Some\ File 'My Files' + >_ ls "My Files" + Some File + + +Commands can be chained with semicolons. + + +Getting Help +------------ + +``fish`` has excellent help and man pages. Run ``help`` to open help in a web browser, and ``man`` to open it in a man page. You can also ask for help with a specific command, for example, ``help set`` to open in a web browser, or ``man set`` to see it in the terminal. + + + +:: + + >_ man set + set - handle shell variables + Synopsis... + + + +Syntax Highlighting +------------------- + +You'll quickly notice that ``fish`` performs syntax highlighting as you type. Invalid commands are colored red by default:: + + >_ /bin/mkd + + +A command may be invalid because it does not exist, or refers to a file that you cannot execute. When the command becomes valid, it is shown in a different color:: + + >_ /bin/mkdir + + +``fish`` will underline valid file paths as you type them:: + + >_ cat ~/somefi___ + + +This tells you that there exists a file that starts with '``somefi``', which is useful feedback as you type. + +These colors, and many more, can be changed by running ``fish_config``, or by modifying variables directly. + + +Wildcards +--------- + +``fish`` supports the familiar wildcard ``*``. To list all JPEG files:: + + >_ ls *.jpg + lena.jpg + meena.jpg + santa maria.jpg + + +You can include multiple wildcards:: + + >_ ls l*.p* + lena.png + lesson.pdf + + +Especially powerful is the recursive wildcard ** which searches directories recursively:: + + >_ ls /var/**.log + /var/log/system.log + /var/run/sntp.log + + +If that directory traversal is taking a long time, you can @key{Control,C} out of it. + + +Pipes and Redirections +---------------------- + +You can pipe between commands with the usual vertical bar:: + + >_ echo hello world | wc + 1 2 12 + + +stdin and stdout can be redirected via the familiar < and >. stderr is redirected with a 2>. + + + +:: + + >_ grep fish < /etc/shells > ~/output.txt 2> ~/errors.txt + + + +Autosuggestions +--------------- + +``fish`` suggests commands as you type, and shows the suggestion to the right of the cursor, in gray. For example:: + + >_ /bin/h___ostname + + +It knows about paths and options:: + + >_ grep --i___gnore-case + + +And history too. Type a command once, and you can re-summon it by just typing a few letters:: + + >_ r<___sync -avze ssh . myname@somelonghost.com:/some/long/path/doo/dee/doo/dee/doo + + +To accept the autosuggestion, hit @cursor_key{→,right arrow} or @key{Control,F}. To accept a single word of the autosuggestion, @key{Alt,→} (right arrow). If the autosuggestion is not what you want, just ignore it. + +Tab Completions +--------------- + +``fish`` comes with a rich set of tab completions, that work "out of the box." + +Press @key{Tab}, and ``fish`` will attempt to complete the command, argument, or path:: + + >_ /pri @key{Tab} → /private/ + + +If there's more than one possibility, it will list them:: + + >_ ~/stuff/s @key{Tab} + ~/stuff/script.sh (Executable, 4.8kB) \mtch{~/stuff/sources/ (Directory)} + + +Hit tab again to cycle through the possibilities. + +``fish`` can also complete many commands, like git branches:: + + >_ git merge pr @key{Tab} → git merge prompt_designer + >_ git checkout b @key{Tab} + builtin_list_io_merge (Branch) \mtch{builtin_set_color (Branch) busted_events (Tag)} + + +Try hitting tab and see what ``fish`` can do! + +Variables +--------- + +Like other shells, a dollar sign performs variable substitution:: + + >_ echo My home directory is $HOME + My home directory is /home/tutorial + + +Variable substitution also occurs in double quotes, but not single quotes:: + + >_ echo "My current directory is $PWD" + My current directory is /home/tutorial + >_ echo 'My current directory is $PWD' + My current directory is $PWD + + +Unlike other shells, ``fish`` has no dedicated syntax for setting variables. Instead it has an ordinary command: ``set``, which takes a variable name, and then its value. + + + +:: + + >_ set name 'Mister Noodle' + >_ echo $name + Mister Noodle + + +(Notice the quotes: without them, ``Mister`` and ``Noodle`` would have been separate arguments, and ``$name`` would have been made into a list of two elements.) + +Unlike other shells, variables are not further split after substitution:: + + >_ mkdir $name + >_ ls + Mister Noodle + + +In bash, this would have created two directories "Mister" and "Noodle". In ``fish``, it created only one: the variable had the value "Mister Noodle", so that is the argument that was passed to ``mkdir``, spaces and all. Other shells use the term "arrays", rather than lists. + + +Exit Status +----------- + +Unlike other shells, ``fish`` stores the exit status of the last command in ``$status`` instead of ``$?``. + + + +:: + + >_ false + >_ echo $status + 1 + + +Zero is considered success, and non-zero is failure. + + +Exports (Shell Variables) +------------------------- + +Unlike other shells, ``fish`` does not have an export command. Instead, a variable is exported via an option to ``set``, either ``--export`` or just ``-x``. + + + +:: + + >_ set -x MyVariable SomeValue + >_ env | grep MyVariable + MyVariable=SomeValue + + +You can erase a variable with ``-e`` or ``--erase`` + + + +:: + + >_ set -e MyVariable + >_ env | grep MyVariable + (no output) + + + +Lists +----- + +The ``set`` command above used quotes to ensure that ``Mister Noodle`` was one argument. If it had been two arguments, then ``name`` would have been a list of length 2. In fact, all variables in ``fish`` are really lists, that can contain any number of values, or none at all. + +Some variables, like ``$PWD``, only have one value. By convention, we talk about that variable's value, but we really mean its first (and only) value. + +Other variables, like ``$PATH``, really do have multiple values. During variable expansion, the variable expands to become multiple arguments:: + + >_ echo $PATH + /usr/bin /bin /usr/sbin /sbin /usr/local/bin + + +Note that there are three environment variables that are automatically split on colons to become lists when fish starts running: ``PATH``, ``CDPATH``, ``MANPATH``. Conversely, they are joined on colons when exported to subcommands. All other environment variables (e.g., ``LD_LIBRARY_PATH``) which have similar semantics are treated as simple strings. + +Lists cannot contain other lists: there is no recursion. A variable is a list of strings, full stop. + +Get the length of a list with ``count``:: + + >_ count $PATH + 5 + + +You can append (or prepend) to a list by setting the list to itself, with some additional arguments. Here we append /usr/local/bin to $PATH:: + + >_ set PATH $PATH /usr/local/bin + + + +You can access individual elements with square brackets. Indexing starts at 1 from the beginning, and -1 from the end:: + + >_ echo $PATH + /usr/bin /bin /usr/sbin /sbin /usr/local/bin + >_ echo $PATH[1] + /usr/bin + >_ echo $PATH[-1] + /usr/local/bin + + +You can also access ranges of elements, known as "slices:" + + + +:: + + >_ echo $PATH[1..2] + /usr/bin /bin + >_ echo $PATH[-1..2] + /usr/local/bin /sbin /usr/sbin /bin + + +You can iterate over a list (or a slice) with a for loop:: + + >_ for val in $PATH + echo "entry: $val" + end + entry: /usr/bin/ + entry: /bin + entry: /usr/sbin + entry: /sbin + entry: /usr/local/bin + + +Lists adjacent to other lists or strings are expanded as cartesian products unless quoted (see Variable expansion):: + + >_ set a 1 2 3 + >_ set 1 a b c + >_ echo $a$1 + 1a 2a 3a 1b 2b 3b 1c 2c 3c + >_ echo $a" banana" + 1 banana 2 banana 3 banana + >_ echo "$a banana" + 1 2 3 banana + + +This is similar to Brace expansion. + +Command Substitutions +--------------------- + +Command substitutions use the output of one command as an argument to another. Unlike other shells, ``fish`` does not use backticks `` for command substitutions. Instead, it uses parentheses:: + + >_ echo In (pwd), running (uname) + In /home/tutorial, running FreeBSD + + +A common idiom is to capture the output of a command in a variable:: + + >_ set os (uname) + >_ echo $os + Linux + + +Command substitutions are not expanded within quotes. Instead, you can temporarily close the quotes, add the command substitution, and reopen them, all in the same argument:: + + >_ touch "testing_"(date +%s)".txt" + >_ ls *.txt + testing_1360099791.txt + + +Unlike other shells, fish does not split command substitutions on any whitespace (like spaces or tabs), only newlines. This can be an issue with commands like ``pkg-config`` that print what is meant to be multiple arguments on a single line. To split it on spaces too, use ``string split``. + + + +:: + + >_ printf '%s\n' (pkg-config --libs gio-2.0) + -lgio-2.0 -lgobject-2.0 -lglib-2.0 + >_ printf '%s\n' (pkg-config --libs gio-2.0 | string split " ") + -lgio-2.0 + -lgobject-2.0 + -lglib-2.0 + + + +Separating Commands (Semicolon) +------------------------------- + +Like other shells, fish allows multiple commands either on separate lines or the same line. + +To write them on the same line, use the semicolon (";"). That means the following two examples are equivalent:: + + echo fish; echo chips + + # or + echo fish + echo chips + + + +Combiners (And, Or, Not) +------------------------ + +fish supports the familiar ``&&`` and ``||`` to combine commands, and ``!`` to negate them:: + + >_ ./configure && make && sudo make install + + +fish also supports ``and``, ``or``, and ``not``. The first two are job modifiers and have lower precedence. Example usage:: + + >_ cp file1.txt file1_bak.txt && cp file2.txt file2_bak.txt ; and echo "Backup successful"; or echo "Backup failed" + Backup failed + + +As mentioned in the section on the semicolon, this can also be written in multiple lines, like so:: + + cp file1.txt file1_bak.txt && cp file2.txt file2_bak.txt + and echo "Backup successful" + or echo "Backup failed" + + + +Conditionals (If, Else, Switch) +------------------------------- + +Use ``if``, ``else if``, and ``else`` to conditionally execute code, based on the exit status of a command. + + + +:: + + if grep fish /etc/shells + echo Found fish + else if grep bash /etc/shells + echo Found bash + else + echo Got nothing + end + + +To compare strings or numbers or check file properties (whether a file exists or is writeable and such), use test, like + + + +:: + + if test "$fish" = "flounder" + echo FLOUNDER + end + + # or + + if test "$number" -gt 5 + echo $number is greater than five + else + echo $number is five or less + end + + +Combiners can also be used to make more complex conditions, like + + + +:: + + if grep fish /etc/shells; and command -sq fish + echo fish is installed and configured + end + + +For even more complex conditions, use ``begin`` and ``end`` to group parts of them. + +There is also a ``switch`` command:: + + switch (uname) + case Linux + echo Hi Tux! + case Darwin + echo Hi Hexley! + case FreeBSD NetBSD DragonFly + echo Hi Beastie! + case '*' + echo Hi, stranger! + end + + +Note that ``case`` does not fall through, and can accept multiple arguments or (quoted) wildcards. + + +Functions +--------- + +A ``fish`` function is a list of commands, which may optionally take arguments. Unlike other shells, arguments are not passed in "numbered variables" like ``$1``, but instead in a single list ``$argv``. To create a function, use the ``function`` builtin:: + + >_ function say_hello + echo Hello $argv + end + >_ say_hello + Hello + >_ say_hello everybody! + Hello everybody! + + +Unlike other shells, ``fish`` does not have aliases or special prompt syntax. Functions take their place. + +You can list the names of all functions with the ``functions`` keyword (note the plural!). ``fish`` starts out with a number of functions:: + + >_ functions + alias, cd, delete-or-exit, dirh, dirs, down-or-search, eval, export, fish_command_not_found_setup, fish_config, fish_default_key_bindings, fish_prompt, fish_right_prompt, fish_sigtrap_handler, fish_update_completions, funced, funcsave, grep, help, history, isatty, ls, man, math, nextd, nextd-or-forward-word, open, popd, prevd, prevd-or-backward-word, prompt_pwd, psub, pushd, seq, setenv, trap, type, umask, up-or-search, vared + + +You can see the source for any function by passing its name to ``functions``:: + + >_ functions ls + function ls --description 'List contents of directory' + command ls -G $argv + end + + + +Loops +----- + +While loops:: + + >_ while true + echo "Loop forever" + end + Loop forever + Loop forever + Loop forever + ... + + +For loops can be used to iterate over a list. For example, a list of files:: + + >_ for file in *.txt + cp $file $file.bak + end + + +Iterating over a list of numbers can be done with ``seq``:: + + >_ for x in (seq 5) + touch file_$x.txt + end + + + +Prompt +------ + +Unlike other shells, there is no prompt variable like PS1. To display your prompt, ``fish`` executes a function with the name ``fish_prompt``, and its output is used as the prompt. + +You can define your own prompt:: + + >_ function fish_prompt + echo "New Prompt % " + end + New Prompt % ___ + + +Multiple lines are OK. Colors can be set via ``set_color``, passing it named ANSI colors, or hex RGB values:: + + >_ function fish_prompt + set_color purple + date "+%m/%d/%y" + set_color FF0 + echo (pwd) '>' + set_color normal + end + 02/06/13 + /home/tutorial >___ + + +You can choose among some sample prompts by running ``fish_config prompt``. ``fish`` also supports RPROMPT through ``fish_right_prompt``. + +$PATH +----- + +``$PATH`` is an environment variable containing the directories in which ``fish`` searches for commands. Unlike other shells, $PATH is a [list](#tut_lists), not a colon-delimited string. + +To prepend /usr/local/bin and /usr/sbin to ``$PATH``, you can write:: + + >_ set PATH /usr/local/bin /usr/sbin $PATH + + +To remove /usr/local/bin from ``$PATH``, you can write:: + + >_ set PATH (string match -v /usr/local/bin $PATH) + + +You can do so directly in ``config.fish``, like you might do in other shells with ``.profile``. See [this example](#path_example). + +A faster way is to modify the ``$fish_user_paths`` [universal variable](#tut_universal), which is automatically prepended to ``$PATH``. For example, to permanently add ``/usr/local/bin`` to your ``$PATH``, you could write:: + + >_ set -U fish_user_paths /usr/local/bin $fish_user_paths + + +The advantage is that you don't have to go mucking around in files: just run this once at the command line, and it will affect the current session and all future instances too. (Note: you should NOT add this line to ``config.fish``. If you do, the variable will get longer each time you run fish!) + +Startup (Where's .bashrc?) +-------------------------- + +``fish`` starts by executing commands in ``~/.config/fish/config.fish``. You can create it if it does not exist. + +It is possible to directly create functions and variables in ``config.fish`` file, using the commands shown above. For example: + + + + +:: + + >_ cat ~/.config/fish/config.fish + + set -x PATH $PATH /sbin/ + + function ll + ls -lh $argv + end + + +However, it is more common and efficient to use autoloading functions and universal variables. + +Autoloading Functions +--------------------- + +When ``fish`` encounters a command, it attempts to autoload a function for that command, by looking for a file with the name of that command in ``~/.config/fish/functions/``. + +For example, if you wanted to have a function ``ll``, you would add a text file ``ll.fish`` to ``~/.config/fish/functions``:: + + >_ cat ~/.config/fish/functions/ll.fish + function ll + ls -lh $argv + end + + +This is the preferred way to define your prompt as well:: + + >_ cat ~/.config/fish/functions/fish_prompt.fish + function fish_prompt + echo (pwd) "> " + end + + +See the documentation for funced and funcsave for ways to create these files automatically. + +Universal Variables +------------------- + +A universal variable is a variable whose value is shared across all instances of ``fish``, now and in the future – even after a reboot. You can make a variable universal with ``set -U``:: + + >_ set -U EDITOR vim + + +Now in another shell:: + + >_ echo $EDITOR + vim + + +.. _switching-to-fish: + +Switching to fish? +------------------ + +If you wish to use fish (or any other shell) as your default shell, +you need to enter your new shell's executable ``/usr/local/bin/fish`` in two places: +- add ``/usr/local/bin/fish`` to ``/etc/shells`` +- change your default shell with ``chsh -s /usr/local/bin/fish`` + +You can use the following commands for this: + +Add the fish shell ``/usr/local/bin/fish`` +to ``/etc/shells`` with:: + + >echo /usr/local/bin/fish | sudo tee -a /etc/shells + + +Change your default shell to fish with:: + + >chsh -s /usr/local/bin/fish + + +(To change it back to another shell, just substitute ``/usr/local/bin/fish`` +with ``/bin/bash``, ``/bin/tcsh`` or ``/bin/zsh`` as appropriate in the steps above.) + + +Ready for more? +--------------- + +If you want to learn more about fish, there is lots of detailed documentation, an official mailing list, the IRC channel \#fish on ``irc.oftc.net``, and the github page. From db90f421c0aa5cb49449a2a3c81f864f89b4a651 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 17:13:49 -0800 Subject: [PATCH 118/191] Add design doc to Sphinx docs build --- sphinx_doc_src/design.rst | 100 ++++++++++++++++++++++++++++++++++++++ sphinx_doc_src/index.rst | 1 + 2 files changed, 101 insertions(+) create mode 100644 sphinx_doc_src/design.rst diff --git a/sphinx_doc_src/design.rst b/sphinx_doc_src/design.rst new file mode 100644 index 000000000..757cc9158 --- /dev/null +++ b/sphinx_doc_src/design.rst @@ -0,0 +1,100 @@ +Design +====== + +This is a description of the design principles that have been used to design fish. The fish design has three high level goals. These are: + +1. Everything that can be done in other shell languages should be possible to do in fish, though fish may rely on external commands in doing so. + +2. Fish should be user friendly, but not at the expense of expressiveness. Most tradeoffs between power and ease of use can be avoided with careful design. + +3. Whenever possible without breaking the above goals, fish should follow the Posix syntax. + +To achieve these high-level goals, the fish design relies on a number of more specific design principles. These are presented below, together with a rationale and a few examples for each. + + +The law of orthogonality +------------------------ + +The shell language should have a small set of orthogonal features. Any situation where two features are related but not identical, one of them should be removed, and the other should be made powerful and general enough to handle all common use cases of either feature. + +Rationale: + +Related features make the language larger, which makes it harder to learn. It also increases the size of the source code, making the program harder to maintain and update. + +Examples: + +- Here documents are too similar to using echo inside of a pipeline. + +- Subshells, command substitution and process substitution are strongly related. ``fish`` only supports command substitution, the others can be achieved either using a block or the psub shellscript function. + +- Having both aliases and functions is confusing, especially since both of them have limitations and problems. ``fish`` functions have none of the drawbacks of either syntax. + +- The many Posix quoting styles are silly, especially $''. + + +The law of responsiveness +------------------------- + +The shell should attempt to remain responsive to the user at all times, even in the face of contended or unresponsive filesystems. It is only acceptable to block in response to a user initiated action, such as running a command. + +Rationale: +Bad performance increases user-facing complexity, because it trains users to recognize and route around slow use cases. It is also incredibly frustrating. + +Examples: + +- Features like syntax highlighting and autosuggestions must perform all of their disk I/O asynchronously. + +- Startup should minimize forks and disk I/O, so that fish can be started even if the system is under load. + +Configurability is the root of all evil +--------------------------------------- + +Every configuration option in a program is a place where the program is too stupid to figure out for itself what the user really wants, and should be considered a failure of both the program and the programmer who implemented it. + +Rationale: +Different configuration options are a nightmare to maintain, since the number of potential bugs caused by specific configuration combinations quickly becomes an issue. Configuration options often imply assumptions about the code which change when reimplementing the code, causing issues with backwards compatibility. But mostly, configuration options should be avoided since they simply should not exist, as the program should be smart enough to do what is best, or at least a good enough approximation of it. + +Examples: + +- Fish allows the user to set various syntax highlighting colors. This is needed because fish does not know what colors the terminal uses by default, which might make some things unreadable. The proper solution would be for text color preferences to be defined centrally by the user for all programs, and for the terminal emulator to send these color properties to fish. + +- Fish does not allow you to set the number of history entries, different language substyles or any number of other common shell configuration options. + +A special note on the evils of configurability is the long list of very useful features found in some shells, that are not turned on by default. Both zsh and bash support command-specific completions, but no such completions are shipped with bash by default, and they are turned off by default in zsh. Other features that zsh supports that are disabled by default include tab-completion of strings containing wildcards, a sane completion pager and a history file. + +The law of user focus +--------------------- + +When designing a program, one should first think about how to make an intuitive and powerful program. Implementation issues should only be considered once a user interface has been designed. + +Rationale: + +This design rule is different than the others, since it describes how one should go about designing new features, not what the features should be. The problem with focusing on what can be done, and what is easy to do, is that too much of the implementation is exposed. This means that the user must know a great deal about the underlying system to be able to guess how the shell works, it also means that the language will often be rather low-level. + +Examples: +- There should only be one type of input to the shell, lists of commands. Loops, conditionals and variable assignments are all performed through regular commands. + +- The differences between built-in commands and shellscript functions should be made as small as possible. Built-ins and shellscript functions should have exactly the same types of argument expansion as other commands, should be possible to use in any position in a pipeline, and should support any I/O redirection. + +- Instead of forking when performing command substitution to provide a fake variable scope, all fish commands are performed from the same process, and fish instead supports true scoping. + +- All blocks end with the ``end`` built-in. + +The law of discoverability +-------------------------- + +A program should be designed to make its features as easy as possible to discover for the user. + +Rationale: +A program whose features are discoverable turns a new user into an expert in a shorter span of time, since the user will become an expert on the program simply by using it. + +The main benefit of a graphical program over a command-line-based program is discoverability. In a graphical program, one can discover all the common features by simply looking at the user interface and guessing what the different buttons, menus and other widgets do. The traditional way to discover features in command-line programs is through manual pages. This requires both that the user starts to use a different program, and then they remember the new information until the next time they use the same program. + +Examples: +- Everything should be tab-completable, and every tab completion should have a description. + +- Every syntax error and error in a built-in command should contain an error message describing what went wrong and a relevant help page. Whenever possible, errors should be flagged red by the syntax highlighter. + +- The help manual should be easy to read, easily available from the shell, complete and contain many examples + +- The language should be uniform, so that once the user understands the command/argument syntax, they will know the whole language, and be able to use tab-completion to discover new features. diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index 288064aeb..09bc003fc 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -519,6 +519,7 @@ Commands :maxdepth: 1 commands + design tutorial From 2d75ab8e9bd1f49fd8db20abc48fad78b9f90c6f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 17:19:26 -0800 Subject: [PATCH 119/191] Add FAQ to sphinx docs build --- sphinx_doc_src/faq.rst | 253 +++++++++++++++++++++++++++++++++++++++ sphinx_doc_src/index.rst | 1 + 2 files changed, 254 insertions(+) create mode 100644 sphinx_doc_src/faq.rst diff --git a/sphinx_doc_src/faq.rst b/sphinx_doc_src/faq.rst new file mode 100644 index 000000000..cb1eafa99 --- /dev/null +++ b/sphinx_doc_src/faq.rst @@ -0,0 +1,253 @@ +Frequently asked questions +========================== + +How do I set or clear an environment variable? +---------------------------------------------- +Use the ``set`` command:: + + set -x key value + set -e key + + +How do I run a command every login? What's fish's equivalent to .bashrc? +------------------------------------------------------------------------ +Edit the file ``~/.config/fish/config.fish``, creating it if it does not exist (Note the leading period). + + +How do I set my prompt? +----------------------- +The prompt is the output of the ``fish_prompt`` function. Put it in ``~/.config/fish/functions/fish_prompt.fish``. For example, a simple prompt is:: + + function fish_prompt + set_color $fish_color_cwd + echo -n (prompt_pwd) + set_color normal + echo -n ' > ' + end + + +You can also use the Web configuration tool, ``fish_config``, to preview and choose from a gallery of sample prompts. + + +How do I run a command from history? +------------------------------------ +Type some part of the command, and then hit the @cursor_key{↑,up} or @cursor_key{↓,down} arrow keys to navigate through history matches. + + +How do I run a subcommand? The backtick doesn't work! +----------------------------------------------------- +``fish`` uses parentheses for subcommands. For example:: + + for i in (ls) + echo $i + end + + +My command (pkg-config) gives its output as a single long string? +----------------------------------------------------------------- +Unlike other shells, fish splits command substitutions only on newlines, not spaces or tabs or the characters in $IFS. + +That means if you run + +:: + + echo x(printf '%s ' a b c)x + + +It will print ``xa b c x``. But if you do + +:: + + echo x(printf '%s\n' a b c)x + + +it will print ``xax xbx xcx``. + +In the overwhelming majority of cases, splitting on spaces is unwanted, so this is an improvement. + +However sometimes, especially with ``pkg-config`` and related tools, splitting on spaces is needed. + +In these cases use ``string split " "`` like:: + + g++ example_01.cpp (pkg-config --cflags --libs gtk+-2.0 | string split " ") + + +How do I get the exit status of a command? +------------------------------------------ +Use the ``$status`` variable. This replaces the ``$?`` variable used in some other shells. + +:: + + somecommand + if test $status -eq 7 + echo "That's my lucky number!" + end + + +If you are just interested in success or failure, you can run the command directly as the if-condition:: + + if somecommand + echo "Command succeeded" + else + echo "Command failed" + end + + +See the documentation for ``test`` and ``if`` for more information. + +~~ +How do I set an environment variable for just one command? +---------------------------------------------------------- +``SOME_VAR=1 command`` produces an error: ``Unknown command "SOME_VAR=1"``. + +Use the ``env`` command. + +``env SOME_VAR=1 command`` + +You can also declare a local variable in a block:: + + begin + set -lx SOME_VAR 1 + command + end + + +Why doesn't ``set -Ux`` (exported universal variables) seem to work? +-------------------------------------------------------------------- +A global variable of the same name already exists. + +Environment variables such as ``EDITOR`` or ``TZ`` can be set universally using ``set -Ux``. However, if +there is an environment variable already set before fish starts (such as by login scripts or system +administrators), it is imported into fish as a global variable. The variable scopes are searched from the "inside out", which +means that local variables are checked first, followed by global variables, and finally universal +variables. + +This means that the global value takes precedence over the universal value. + +To avoid this problem, consider changing the setting which fish inherits. If this is not possible, +add a statement to your user initialization file (usually +``~/.config/fish/config.fish``):: + + set -gx EDITOR vim + + +How do I customize my syntax highlighting colors? +------------------------------------------------- +Use the web configuration tool, ``fish_config``, or alter the ``fish_color`` family of environment variables. + +~~ +How do I update man page completions? +------------------------------------- +Use the ``fish_update_completions`` command. + +~~ +I accidentally entered a directory path and fish changed directory. What happened? +---------------------------------------------------------------------------------- +If fish is unable to locate a command with a given name, and it starts with '``.``', '``/``' or '``~``', fish will test if a directory of that name exists. If it does, it is implicitly assumed that you want to change working directory. For example, the fastest way to switch to your home directory is to simply press ``~`` and enter. + + +The open command doesn't work. +------------------------------ +The ``open`` command uses the MIME type database and the ``.desktop`` files used by Gnome and KDE to identify filetypes and default actions. If at least one of these environments is installed, but the open command is not working, this probably means that the relevant files are installed in a non-standard location. Consider asking for more help. + + +How do I make fish my default shell? +------------------------------------ +If you installed fish manually (e.g. by compiling it, not by using a package manager), you first need to add fish to the list of shells by executing the following command (assuming you installed fish in /usr/local):: + + echo /usr/local/bin/fish | sudo tee -a /etc/shells + + +If you installed a prepackaged version of fish, the package manager should have already done this for you. + +In order to change your default shell, type:: + + chsh -s /usr/local/bin/fish + + +You may need to adjust the above path to e.g. ``/usr/bin/fish``. Use the command ``which fish`` if you are unsure of where fish is installed. + +Unfortunately, there is no way to make the changes take effect at once. You will need to log out and back in again. + + +I'm seeing weird output before each prompt when using screen. What's wrong? +--------------------------------------------------------------------------- +Quick answer: + +Run the following command in fish:: + + function fish_title; end; funcsave fish_title + + +Problem solved! + +The long answer: + +Fish is trying to set the titlebar message of your terminal. While screen itself supports this feature, your terminal does not. Unfortunately, when the underlying terminal doesn't support setting the titlebar, screen simply passes through the escape codes and text to the underlying terminal instead of ignoring them. It is impossible to detect and resolve this problem from inside fish since fish has no way of knowing what the underlying terminal type is. For now, the only way to fix this is to unset the titlebar message, as suggested above. + +Note that fish has a default titlebar message, which will be used if the fish_title function is undefined. So simply unsetting the fish_title function will not work. + + +How do I change the greeting message? +------------------------------------- +Change the value of the variable ``fish_greeting`` or create a ``fish_greeting`` function. For example, to remove the greeting use:: + + set fish_greeting + + + +Why doesn't history substitution ("!$" etc.) work? +-------------------------------------------------- +Because history substitution is an awkward interface that was invented before interactive line editing was even possible. Fish drops it in favor of perfecting the interactive history recall interface. Switching requires a small change of habits: if you want to modify an old line/word, first recall it, then edit. E.g. don't type "sudo !!" - first press Up, then Home, then type "sudo ". + +Fish history recall is very simple yet effective: + +- As in any modern shell, the Up arrow, @cursor_key{↑,Up} recalls whole lines, starting from the last line executed. A single press replaces "!!", later presses replace "!-3" and the like. + + - If the line you want is far back in the history, type any part of the line and then press Up one or more times. This will constrain the recall to lines that include this text, and you will get to the line you want much faster. This replaces "!vi", "!?bar.c" and the like. + +- @key{Alt,↑,Up} recalls individual arguments, starting from the last argument in the last line executed. A single press replaces "!$", later presses replace "!!:4" and the like. + + - If the argument you want is far back in history (e.g. 2 lines back - that's a lot of words!), type any part of it and then press @key{Alt,↑,Up}. This will show only arguments containing that part and you will get what you want much faster. Try it out, this is very convenient! + + - If you want to reuse several arguments from the same line ("!!:3*" and the like), consider recalling the whole line and removing what you don't need (@key{Alt,D} and @key{Alt,Backspace} are your friends). + +See documentation for more details about line editing in fish. + + +How can I use ``-`` as a shortcut for ``cd -``? +----------------------------------------------- +In fish versions prior to 2.5.0 it was possible to create a function named ``-`` that would do ``cd -``. Changes in the 2.5.0 release included several bug fixes that enforce the rule that a bare hyphen is not a valid function (or variable) name. However, you can achieve the same effect via an abbreviation:: + + abbr -a -- - 'cd -' + + +Uninstalling fish +----------------- +Should you wish to uninstall fish, first ensure fish is not set as your shell. Run ``chsh -s /bin/bash`` if you are not sure. + +Next, do the following (assuming fish was installed to /usr/local):: + + rm -Rf /usr/local/etc/fish /usr/local/share/fish ~/.config/fish + rm /usr/local/share/man/man1/fish*.1 + cd /usr/local/bin + rm -f fish fish_indent + + + +Unicode private-use characters reserved by fish +----------------------------------------------- +Fish reserves the Unicode private-use character range from U+F600 thru U+F73F for internal use. Any attempt to feed characters in that range to fish will result in them being replaced by the Unicode "replacement character" U+FFFD. This includes both interactive input as well as any file read by fish (but not programs run by fish). + + +Where can I find extra tools for fish? +-------------------------------------- +The fish user community extends fish in unique and useful ways via scripts that aren't always appropriate for bundling with the fish package. Typically because they solve a niche problem unlikely to appeal to a broad audience. You can find those extensions, including prompts, themes and useful functions, in various third-party repositories. These include: + +- `Fisher `_ +- `Fundle `_ +- `Oh My Fish `_ +- `Tacklebox `_ + +This is not an exhaustive list and the fish project has no opinion regarding the merits of the repositories listed above or the scripts found therein. diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index 09bc003fc..3d057a746 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -521,6 +521,7 @@ Commands commands design tutorial + faq Autosuggestions From a1f122f603ae417e888cf80c9c0148a589b6bb7f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 17:37:53 -0800 Subject: [PATCH 120/191] Add license to sphinx docs build --- sphinx_doc_src/index.rst | 1 + sphinx_doc_src/license.rst | 388 +++++++++++++++++++++++++++++++++++++ 2 files changed, 389 insertions(+) create mode 100644 sphinx_doc_src/license.rst diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index 3d057a746..469f745db 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -522,6 +522,7 @@ Commands design tutorial faq + license Autosuggestions diff --git a/sphinx_doc_src/license.rst b/sphinx_doc_src/license.rst new file mode 100644 index 000000000..36153bd6b --- /dev/null +++ b/sphinx_doc_src/license.rst @@ -0,0 +1,388 @@ +License +======== + +``fish`` Copyright © 2005-2009 Axel Liljencrantz. ``fish`` is released under the GNU General Public License, version 2. + +``fish`` includes other code licensed under the GNU General Public License, version 2, including GNU ``printf``. + +Copyright © 1990-2007 Free Software Foundation, Inc. Printf (from GNU Coreutils 6.9) is released under the GNU General Public License, version 2. + +The GNU General Public License agreement follows. + +**GNU GENERAL PUBLIC LICENSE** + +Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + +**Preamble** + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software - to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. + + +**TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION** + +- This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". + + Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. + + You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + -# You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + + -# You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + + -# If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) + + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + + Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + + In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + + -# Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + -# Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + -# Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) + + The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + + If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + + If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + + It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + + This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + + __NO WARRANTY__ + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +---- + +**License for PCRE2** + +``fish`` contains code from the [PCRE2](http://www.pcre.org) library to support regular expressions. This code, created by Philip Hazel, is distributed under the terms of the BSD license. Copyright © 1997-2015 University of Cambridge. + +The BSD license follows. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + -# Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + -# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + -# Neither the name of the University of Cambridge nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---- + +**License for CMake** + +The ``fish`` source code contains files from [CMake](https://cmake.org) to support the build system. +This code is distributed under the terms of a BSD-style license. Copyright 2000-2017 Kitware, Inc. +and Contributors. + +The BSD license for CMake follows. + +CMake - Cross Platform Makefile Generator +Copyright 2000-2017 Kitware, Inc. and Contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Kitware, Inc. nor the names of Contributors + may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---- + +**License for wcslcpy and code derived from tmux** + +``fish`` also contains small amounts of code under the OpenBSD license, namely a version of the function strlcpy, modified for use with wide character strings. This code is copyrighted by Todd C. Miller (1998). It also contains code from [tmux](http://tmux.sourceforge.net), copyrighted by Nicholas Marriott (2007), and made available under an identical license. + +The OpenBSD license is included below. + +Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +---- + +**License for glibc** + +Fish contains code from the glibc library, namely the wcstok function. This code is licensed under the LGPL, version 2 or later. Version 2 of the LPGL license agreement is included below. + +**GNU LESSER GENERAL PUBLIC LICENSE** + +Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + +[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] + +**Preamble** + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software - to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some specially designated software packages - typically libraries - of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. + +We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users'freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. + +**TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION** + +- This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) + + "Source code for a work" means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. + + Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. + + You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + 1. The modified work must itself be a software library. + + 2. You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. + + 3. You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. + + 4. If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. + + (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) + + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + + Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. + + In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. + + Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: + + 1. Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine- readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) + + 2. Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. + + 3. Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. + + 4. If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. + + 5. Verify that the user has already received a copy of these materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + + It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side- by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: + + 1. Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. + + 2. Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients'exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. + + If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. + + It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + + This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + + **NO WARRANTY** + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +---- + +**License for UTF8** + +``fish`` also contains small amounts of code under the ISC license, namely the UTF-8 conversion functions. This code is copyright © 2007 Alexey Vatchenko \. + +The ISC license agreement follows. + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +---- + +**License for flock** + +``fish`` also contains small amounts of code from NetBSD, namely the ``flock`` fallback function. This code is copyright 2001 The NetBSD Foundation, Inc., and derived from software contributed to The NetBSD Foundation by Todd Vierling. + +The NetBSD license follows. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +---- + +**MIT License** + +``fish`` includes a copy of AngularJS, which is copyright 2010-2012 Google, Inc. and licensed under the MIT License. + +The MIT license follows. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 2ec33be90fe92354339698ba38847a3c8f592785 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 18:44:29 -0800 Subject: [PATCH 121/191] CMake BUILD_DOCS option to look for sphinx instead of Doxygen --- cmake/Docs.cmake | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cmake/Docs.cmake b/cmake/Docs.cmake index d7a5907f6..2ee17c64a 100644 --- a/cmake/Docs.cmake +++ b/cmake/Docs.cmake @@ -1,5 +1,3 @@ -FIND_PACKAGE(Doxygen 1.8.7) - FIND_PROGRAM(SPHINX_EXECUTABLE NAMES sphinx-build HINTS $ENV{SPHINX_DIR} @@ -35,14 +33,14 @@ ADD_CUSTOM_TARGET(sphinx-manpages "${SPHINX_MANPAGE_DIR}" COMMENT "Building man pages with Sphinx") -IF(DOXYGEN_FOUND) - OPTION(BUILD_DOCS "build documentation (requires Doxygen)" ON) -ELSE(DOXYGEN_FOUND) - OPTION(BUILD_DOCS "build documentation (requires Doxygen)" OFF) -ENDIF(DOXYGEN_FOUND) +IF(SPHINX_EXECUTABLE) + OPTION(BUILD_DOCS "build documentation (requires Sphinx)" ON) +ELSE(SPHINX_EXECUTABLE) + OPTION(BUILD_DOCS "build documentation (requires Sphinx)" OFF) +ENDIF(SPHINX_EXECUTABLE) -IF(BUILD_DOCS AND NOT DOXYGEN_FOUND) - MESSAGE(FATAL_ERROR "build documentation selected, but Doxygen could not be found") +IF(BUILD_DOCS AND NOT SPHINX_EXECUTABLE) + MESSAGE(FATAL_ERROR "build documentation selected, but sphinx-build could not be found") ENDIF() IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/user_doc/html From 4da38df43b6457c2a89c8175f664a9d008c1743c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 19:02:39 -0800 Subject: [PATCH 122/191] Remove last vestiges of Doxygen from Docs.cmake --- cmake/Docs.cmake | 107 ++--------------------------------------------- 1 file changed, 3 insertions(+), 104 deletions(-) diff --git a/cmake/Docs.cmake b/cmake/Docs.cmake index 2ee17c64a..4d2774e8a 100644 --- a/cmake/Docs.cmake +++ b/cmake/Docs.cmake @@ -59,114 +59,13 @@ ENDIF() ADD_FEATURE_INFO(Documentation INSTALL_DOCS "user manual and documentation") IF(BUILD_DOCS) - # Files in ./share/completions/ - FILE(GLOB COMPLETIONS_DIR_FILES share/completions/*.fish) - - # Files in ./share/functions/ - FILE(GLOB FUNCTIONS_DIR_FILES share/functions/*.fish) - - # Files in doc_src - FILE(GLOB DOC_SRC_FILES doc_src/*) - - # .txt files in doc_src - FILE(GLOB HELP_SRC doc_src/*.txt) - - # These files are the source files, they contain a few @FOO@-style substitutions. - # Note that this order defines the order that they appear in the documentation. - SET(HDR_FILES_SRC doc_src/index.hdr.in doc_src/tutorial.hdr doc_src/design.hdr - doc_src/license.hdr doc_src/commands.hdr.in doc_src/faq.hdr) - - # These are the generated result files. - STRING(REPLACE ".in" "" HDR_FILES "${HDR_FILES_SRC}") - - # Header files except for index.hdr - SET(HDR_FILES_NO_INDEX ${HDR_FILES}) - LIST(REMOVE_ITEM HDR_FILES_NO_INDEX doc_src/index.hdr) - - # Copy doc_src files - FILE(COPY ${DOC_SRC_FILES} DESTINATION doc_src) - - # Build lexicon_filter. - ADD_CUSTOM_COMMAND(OUTPUT lexicon_filter - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/build_lexicon_filter.sh - ${CMAKE_CURRENT_SOURCE_DIR}/share/functions/ - ${CMAKE_CURRENT_SOURCE_DIR}/share/completions/ - ${CMAKE_CURRENT_SOURCE_DIR}/lexicon_filter.in - ${SED} - > ${CMAKE_CURRENT_BINARY_DIR}/lexicon_filter - && chmod a+x ${CMAKE_CURRENT_BINARY_DIR}/lexicon_filter - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${FUNCTIONS_DIR_FILES} ${COMPLETIONS_DIR_FILES} - doc_src/commands.hdr ${CMAKE_CURRENT_SOURCE_DIR}/lexicon_filter.in - share/functions/__fish_config_interactive.fish - build_tools/build_lexicon_filter.sh command_list_toc.txt) - - # Other targets should depend on this target, otherwise the lexicon - # filter can be built twice. - ADD_CUSTOM_TARGET(build_lexicon_filter DEPENDS lexicon_filter) - - # - # commands.hdr collects documentation on all commands, functions and - # builtins - # - FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc_src) - ADD_CUSTOM_COMMAND(OUTPUT doc_src/commands.hdr command_list_toc.txt - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/build_commands_hdr.sh ${HELP_SRC} - < doc_src/commands.hdr.in - > ${CMAKE_CURRENT_BINARY_DIR}/doc_src/commands.hdr - DEPENDS ${HELP_SRC} - ${CMAKE_CURRENT_SOURCE_DIR}/doc_src/commands.hdr.in - ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/build_commands_hdr.sh) - - # doc.h is a compilation of the various snippets of text used both for - # the user documentation and for internal help functions into a single - # file that can be parsed by Doxygen to generate the user - # documentation. - ADD_CUSTOM_COMMAND(OUTPUT doc.h - COMMAND cat ${HDR_FILES} > ${CMAKE_CURRENT_BINARY_DIR}/doc.h - DEPENDS ${HDR_FILES}) - - # toc.txt: $(HDR_FILES:index.hdr=index.hdr.in) build_tools/build_toc_txt.sh | show-SED - # FISH_BUILD_VERSION=${FISH_BUILD_VERSION} build_tools/build_toc_txt.sh \ - # $(HDR_FILES:index.hdr=index.hdr.in) > toc.txt - # Note we would like to add doc_src/index.hdr.in as a dependency but CMake replaces this with - # doc_src/index.hdr; CMake bug? - ADD_CUSTOM_COMMAND(OUTPUT toc.txt - COMMAND env `cat ${FBVF} | tr -d '\"'` ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/build_toc_txt.sh - doc_src/index.hdr.in ${HDR_FILES_NO_INDEX} - > ${CMAKE_CURRENT_BINARY_DIR}/toc.txt - DEPENDS ${CFBVF} ${HDR_FILES_NO_INDEX}) - - # doc_src/index.hdr: toc.txt doc_src/index.hdr.in | show-AWK - # @echo " AWK CAT $(em)$@$(sgr0)" - # $v cat $@.in | $(AWK) '{if ($$0 ~ /@toc@/){ system("cat toc.txt");} else{ print $$0;}}' >$@ - ADD_CUSTOM_COMMAND(OUTPUT doc_src/index.hdr - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/build_index_hdr.sh toc.txt - < doc_src/index.hdr.in - > ${CMAKE_CURRENT_BINARY_DIR}/doc_src/index.hdr - DEPENDS toc.txt) - - # doc: $(HDR_FILES_SRC) Doxyfile.user $(HTML_SRC) $(HELP_SRC) doc.h $(HDR_FILES) lexicon_filter - # @echo " doxygen $(em)user_doc$(sgr0)" - # $v (cat Doxyfile.user; echo INPUT_FILTER=./lexicon_filter; echo PROJECT_NUMBER=$(FISH_BUILD_VERSION) | $(SED) "s/-.*//") | doxygen - && touch user_doc - # $v rm -f $(wildcard $(addprefix ./user_doc/html/,arrow*.png bc_s.png bdwn.png closed.png doc.png folder*.png ftv2*.png nav*.png open.png splitbar.png sync_*.png tab*.* doxygen.* dynsections.js jquery.js pages.html)) ADD_CUSTOM_TARGET(doc ALL - COMMAND env `cat ${FBVF}` - ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/build_user_doc.sh - ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.user ./lexicon_filter - DEPENDS ${CFBVF} Doxyfile.user ${DOC_SRC_FILES} doc.h ${HDR_FILES} build_lexicon_filter command_list_toc.txt) - - ADD_CUSTOM_COMMAND(OUTPUT share/man/ - COMMAND env `cat ${FBVF} | tr -d '\"' ` - INPUT_FILTER=lexicon_filter ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/build_documentation.sh ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.help doc_src ./share - DEPENDS ${CFBVF} ${HELP_SRC} build_lexicon_filter) - - ADD_CUSTOM_TARGET(BUILD_MANUALS ALL DEPENDS share/man/) + DEPENDS sphinx-docs sphinx-manpages) # Group docs targets into a DocsTargets folder - SET_PROPERTY(TARGET doc BUILD_MANUALS build_lexicon_filter + SET_PROPERTY(TARGET doc sphinx-docs sphinx-manpages PROPERTY FOLDER cmake/DocTargets) + ELSEIF(HAVE_PREBUILT_DOCS) IF(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) # Out of tree build - link the prebuilt documentation to the build tree From 0b26b55676faccc48d3ff94d418651acafe1c891 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 19:37:00 -0800 Subject: [PATCH 123/191] Remove docs target from autotools build Now it just errors and redirects the user to CMake. --- Makefile.in | 161 ++-------------------------------------------------- 1 file changed, 4 insertions(+), 157 deletions(-) diff --git a/Makefile.in b/Makefile.in index beb3b9253..18b657d8f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -136,34 +136,6 @@ FISH_TESTS_OBJS := $(FISH_OBJS) obj/fish_tests.o # FISH_ALL_OBJS := $(sort $(FISH_OBJS) $(FISH_INDENT_OBJS) $(FISH_TESTS_OBJS) $(FISH_KEYREAD_OBJS) obj/fish.o) -# -# Files containing user documentation -# - -# -# These files are the source files, they contain a few @FOO@-style substitutions -# Note that this order defines the order that they appear in the documentation -# -HDR_FILES_SRC := doc_src/index.hdr.in doc_src/tutorial.hdr doc_src/design.hdr doc_src/license.hdr doc_src/commands.hdr.in doc_src/faq.hdr - -# -# These are the generated result files -# -HDR_FILES := $(HDR_FILES_SRC:.hdr.in=.hdr) - -# Use a pattern rule so that Make knows to only issue one invocation -# per http://www.gnu.org/software/make/manual/make.html#Pattern-Intro - -# -# Files containing documentation for external commands. -# -HELP_SRC := $(wildcard doc_src/*.txt) - -# -# HTML includes needed for HTML help -# -HTML_SRC := doc_src/user_doc.header.html doc_src/user_doc.footer.html doc_src/user_doc.css - # # Files in the test directory # @@ -184,23 +156,6 @@ FUNCTIONS_DIR_FILES := $(wildcard share/functions/*.fish) # PROGRAMS := fish fish_indent fish_key_reader -# -# Manual pages to install -# -MANUALS := $(addsuffix .1, $(addprefix share/man/man1/, $(PROGRAMS))) -HELP_MANPAGES = $(wildcard share/man/man1/*.1) - -# Determine which man pages we don't want to install -# On OS X, don't install a man page for open, since we defeat fish's open -# function on OS X. -# This is also done in build_tools/build_documentation.sh, but because the -# tarball includes this page, we need to skip it in the Makefile too (see -# https://github.com/fish-shell/fish-shell/issues/2561). -ifeq ($(shell uname), Darwin) - CONDEMNED_PAGES := open.1 - HELP_MANPAGES = $(filter-out share/man/man1/open.1, $(wildcard share/man/man1/*.1)) -endif - # # All translation message catalogs, filter files based on LINGUAS. # @@ -216,17 +171,6 @@ else TRANSLATIONS := endif -# -# If Doxygen is not available, don't attempt to build the documentation -# -ifeq ($(HAVE_DOXYGEN), 1) - user_doc=doc - share_man=share/man -else - user_doc= - share_man= -endif - t_co:=$(shell tput colors || echo '') 2> /dev/null green := $(shell ( tput setaf 2 || tput AF 2 ) 2> /dev/null ) @@ -260,7 +204,7 @@ show-%: # # Make everything needed for installing fish # -all: show-CXX show-CXXFLAGS $(PROGRAMS) $(user_doc) $(share_man) $(TRANSLATIONS) fish.pc share/__fish_build_paths.fish +all: show-CXX show-CXXFLAGS $(PROGRAMS) $(TRANSLATIONS) fish.pc share/__fish_build_paths.fish ifneq (,$(findstring install,$(MAKECMDGOALS))) # Fish has been built, but if the goal was 'install', we aren't done yet and this output isnt't desirable @echo "$(green)fish has now been built.$(sgr0)" @@ -301,26 +245,9 @@ prof: LDFLAGS += -pg prof: all .PHONY: prof -# -# User documentation, describing the features of the fish shell. -# -# Depend on the sources (*.hdr.in) and manually make the intermediate *.hdr -# and doc.h files if needed. The sed command deletes everything including and -# after the first -, for simpler version numbers. Cleans up the user_doc/html -# directory once Doxygen is done. -# -doc: $(HDR_FILES_SRC) Doxyfile.user $(HTML_SRC) $(HELP_SRC) doc.h $(HDR_FILES) lexicon_filter - @echo " doxygen $(em)user_doc$(sgr0)" - $v env FISH_BUILD_VERSION=$(FISH_BUILD_VERSION) ./build_tools/build_user_doc.sh Doxyfile.user ./lexicon_filter - -# -# PDF version of the source code documentation. -# -doc/refman.pdf: doc - @echo " MAKE $(em)doc/latex$(sgr0)" - $v cd doc/latex - $v $(MAKE) V=$(V) - $v mv refman.pdf .. +doc: + @echo "Docs build from autotools is no longer supported - use CMake to build documentation" + @false # # Prep the environment for running the unit tests. When specifying DESTDIR on @@ -392,58 +319,11 @@ test_interactive: $(call filter_up_to,test_interactive,$(active_test_goals)) .PHONY: test_interactive -# -# commands.hdr collects documentation on all commands, functions and -# builtins -# -doc_src/commands.hdr:$(HELP_SRC) doc_src/commands.hdr.in build_tools/build_commands_hdr.sh - build_tools/build_commands_hdr.sh ${HELP_SRC} < doc_src/commands.hdr.in > $@ - toc.txt: $(HDR_FILES:index.hdr=index.hdr.in) build_tools/build_toc_txt.sh | show-SED FISH_BUILD_VERSION=${FISH_BUILD_VERSION} build_tools/build_toc_txt.sh \ $(HDR_FILES:index.hdr=index.hdr.in) > toc.txt -doc_src/index.hdr: toc.txt doc_src/index.hdr.in | show-AWK - @echo " AWK CAT $(em)$@$(sgr0)" - $v build_tools/build_index_hdr.sh toc.txt < $@.in > $@ -# -# Compile Doxygen Input Filter from the lexicon. This is an executable sed -# script as Doxygen opens it via popen()(3) Input (doc.h) is piped through and -# matching words inside /fish../endfish blocks are marked up, contextually, -# with custom Doxygen commands in the form of @word_type{content}. These are -# trapped by ALIASES in the various Doxyfiles, allowing the content to be -# transformed depending on output type (HTML, man page, developer docs). In -# HTML, a style context can be applied through the /fish{style} block and -# providing suitable CSS in user_doc.css.in -# -lexicon_filter: doc_src/commands.hdr $(FUNCTIONS_DIR_FILES) $(COMPLETIONS_DIR_FILES) \ - lexicon_filter.in build_tools/build_lexicon_filter.sh \ - share/functions/__fish_config_interactive.fish - $v build_tools/build_lexicon_filter.sh share/functions/ share/completions/ lexicon_filter.in $(SED) > $@ - $v chmod a+x lexicon_filter - -# -# doc.h is a compilation of the various snipptes of text used both for -# the user documentation and for internal help functions into a single -# file that can be parsed by Doxygen to generate the user -# documentation. -# -doc.h: $(HDR_FILES) - @echo " HDR_FILES $(em)$@$(sgr0)" - $v cat $(HDR_FILES) >$@ - -# -# This rule creates complete doxygen headers from each of the various -# snipptes of text used both for the user documentation and for -# internal help functions, that can be parsed to Doxygen to generate -# the internal help function text. -# -%.doxygen:%.txt - @echo " cat * $(em)$@$(sgr0)" - $v echo "/** \page " `basename $*` >$@; - $v cat $*.txt >>$@; - $v echo "*/" >>$@ # # Depend on Makefile because I don't see a better way of rebuilding @@ -497,39 +377,6 @@ ifdef EXTRA_PCRE2 src/builtin_string.cpp: $(PCRE2_H) endif -# -# Generate the internal help functions by making doxygen create -# man-pages. The convertion path looks like this: -# -# .txt file -# || -# (make) -# || -# \/ -# .doxygen file -# || -# (doxygen) -# || -# \/ -# roff file -# || -# (__fish_print_help) -# || -# \/ -# formated text -# with escape -# sequences -# -# -# There ought to be something simpler. -# -share/man: $(HELP_SRC) lexicon_filter | show-FISH_BUILD_VERSION show-SED - -$v $(MKDIR_P) share/man - @echo " doxygen $(em)$@$(sgr0)" - $v touch share/man - -$v rm -Rf share/man/man1 - $v echo "$(dim)" && FISH_BUILD_VERSION=${FISH_BUILD_VERSION} INPUT_FILTER=./lexicon_filter \ - build_tools/build_documentation.sh Doxyfile.help ./doc_src ./share; # # The build rules for installing/uninstalling fish From c99fa08f21e6d97dac9c97bdd4a686ecf3bb4c10 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 24 Feb 2019 19:38:32 -0800 Subject: [PATCH 124/191] Remove all of the documentation build helper scripts --- Doxyfile | 2358 --------------------------- Doxyfile.help | 2357 -------------------------- Doxyfile.user | 2357 -------------------------- build_tools/build_commands_hdr.sh | 20 - build_tools/build_documentation.sh | 163 -- build_tools/build_index_hdr.sh | 5 - build_tools/build_lexicon_filter.sh | 51 - build_tools/build_toc_txt.sh | 17 - build_tools/build_user_doc.sh | 16 - lexicon_filter.in | 652 -------- 10 files changed, 7996 deletions(-) delete mode 100644 Doxyfile delete mode 100644 Doxyfile.help delete mode 100644 Doxyfile.user delete mode 100755 build_tools/build_commands_hdr.sh delete mode 100755 build_tools/build_documentation.sh delete mode 100755 build_tools/build_index_hdr.sh delete mode 100755 build_tools/build_lexicon_filter.sh delete mode 100755 build_tools/build_toc_txt.sh delete mode 100755 build_tools/build_user_doc.sh delete mode 100644 lexicon_filter.in diff --git a/Doxyfile b/Doxyfile deleted file mode 100644 index 056ccc0a4..000000000 --- a/Doxyfile +++ /dev/null @@ -1,2358 +0,0 @@ -# Doxyfile 1.8.7 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project. -# -# All text after a double hash (##) is considered a comment and is placed in -# front of the TAG it is preceding. -# -# All text after a single hash (#) is considered a comment and will be ignored. -# The format is: -# TAG = value [value, ...] -# For lists, items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (\" \"). - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all text -# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv -# for the list of possible encodings. -# The default value is: UTF-8. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by -# double-quotes, unless you are using Doxywizard) that should identify the -# project for which the documentation is generated. This name is used in the -# title of most generated pages and in a few other places. -# The default value is: My Project. - -PROJECT_NAME = fish - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. This -# could be handy for archiving the generated documentation or if some version -# control system is used. - -PROJECT_NUMBER = 1 - -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer a -# quick idea about the purpose of the project. Keep the description short. - -PROJECT_BRIEF = - -# With the PROJECT_LOGO tag one can specify an logo or icon that is included in -# the documentation. The maximum height of the logo should not exceed 55 pixels -# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo -# to the output directory. - -PROJECT_LOGO = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path -# into which the generated documentation will be written. If a relative path is -# entered, it will be relative to the location where doxygen was started. If -# left blank the current directory will be used. - -OUTPUT_DIRECTORY = doc - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- -# directories (in 2 levels) under the output directory of each output format and -# will distribute the generated files over these directories. Enabling this -# option can be useful when feeding doxygen a huge amount of source files, where -# putting all generated files in the same directory would otherwise causes -# performance problems for the file system. -# The default value is: NO. - -CREATE_SUBDIRS = NO - -# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII -# characters to appear in the names of generated files. If set to NO, non-ASCII -# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode -# U+3044. -# The default value is: NO. - -ALLOW_UNICODE_NAMES = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, -# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), -# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, -# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), -# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, -# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, -# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, -# Ukrainian and Vietnamese. -# The default value is: English. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member -# descriptions after the members that are listed in the file and class -# documentation (similar to Javadoc). Set to NO to disable this. -# The default value is: YES. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief -# description of a member or function before the detailed description -# -# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. -# The default value is: YES. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator that is -# used to form the text in various listings. Each string in this list, if found -# as the leading text of the brief description, will be stripped from the text -# and the result, after processing the whole list, is used as the annotated -# text. Otherwise, the brief description is used as-is. If left blank, the -# following values are used ($name is automatically replaced with the name of -# the entity):The $name class, The $name widget, The $name file, is, provides, -# specifies, contains, represents, a, an and the. - -ABBREVIATE_BRIEF = YES - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# doxygen will generate a detailed section even if there is only a brief -# description. -# The default value is: NO. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. -# The default value is: NO. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path -# before files name in the file list and in the header files. If set to NO the -# shortest path that makes the file name unique will be used -# The default value is: YES. - -FULL_PATH_NAMES = YES - -# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. -# Stripping is only done if one of the specified strings matches the left-hand -# part of the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the path to -# strip. -# -# Note that you can specify absolute paths here, but also relative paths, which -# will be relative from the directory where doxygen is started. -# This tag requires that the tag FULL_PATH_NAMES is set to YES. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the -# path mentioned in the documentation of a class, which tells the reader which -# header file to include in order to use a class. If left blank only the name of -# the header file containing the class definition is used. Otherwise one should -# specify the list of include paths that are normally passed to the compiler -# using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but -# less readable) file names. This can be useful is your file systems doesn't -# support long names like on DOS, Mac, or CD-ROM. -# The default value is: NO. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = YES - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a -# multi-line C++ special comment block (i.e. a block of //! or /// comments) as -# a brief description. This used to be the default behavior. The new default is -# to treat a multi-line C++ comment block as a detailed description. Set this -# tag to YES if you prefer the old behavior instead. -# -# Note that setting this tag to YES also means that rational rose comments are -# not recognized any more. -# The default value is: NO. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the -# documentation from any documented member that it re-implements. -# The default value is: YES. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a -# new page for each member. If set to NO, the documentation of a member will be -# part of the file/class/namespace that contains it. -# The default value is: NO. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen -# uses this value to replace tabs by spaces in code fragments. -# Minimum value: 1, maximum value: 16, default value: 4. - -TAB_SIZE = 4 - -# This tag can be used to specify a number of aliases that act as commands in -# the documentation. An alias has the form: -# name=value -# For example adding -# "sideeffect=@par Side Effects:\n" -# will allow you to put the command \sideeffect (or @sideeffect) in the -# documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. - -# Simplify Fish output from Doxygen for developer doc pages. (see lexicon_filter.in) - -ALIASES = "key{1}=\1" -ALIASES += "key{2}=\1-\2" -ALIASES += "key{3}=\1-\3" -ALIASES += "cursor_key{2}=\2" - -ALIASES += "fish=
"
-ALIASES += "fish{1}=
"
-ALIASES += "endfish=
\n" - -ALIASES += "asis{1}=\1" -ALIASES += "outp{1}=\1" -ALIASES += "blah{1}=#\1" -ALIASES += "bltn{1}=\1" -ALIASES += "func{1}=\1" -ALIASES += "cmnd{1}=\1" -ALIASES += "args{1}=\1" -ALIASES += "opts{1}=\1" -ALIASES += "vars{1}=\1" -ALIASES += "optr{1}=\1" -ALIASES += "redr{1}=\1" -ALIASES += "fsfo{1}=\1" -ALIASES += "path{1}=\1" -ALIASES += "clrv{1}=\1" - -ALIASES += "strg{1}=\1" -ALIASES += "sglq{1}='\1'" -ALIASES += "dblq{1}=\"\1\"" - -ALIASES += "prmt=>" -ALIASES += "prmt{1}=\1>" -ALIASES += "sgst{1}=\1" -ALIASES += "mtch{1}=\1" -ALIASES += "smtc{1}=\1" -ALIASES += "eror{1}=\1" -ALIASES += "curs=_" -ALIASES += "curs{1}=\1" - -ALIASES += "bold{1}=\1" -ALIASES += "emph{1}=\1" -ALIASES += "undr{1}=\1" -ALIASES += "span{2}=\2" -ALIASES += "spcl{2}=\2" - -ALIASES += "bksl{1}=\\\1" -ALIASES += "pcnt{1}=\%\1" -ALIASES += "atat{1}=\@" - -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. - -TCL_SUBST = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. For -# instance, some of the names that are used will be different. The list of all -# members will be omitted, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or -# Python sources only. Doxygen will then generate output that is more tailored -# for that language. For instance, namespaces will be presented as packages, -# qualified scopes will look different, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources. Doxygen will then generate output that is tailored for Fortran. -# The default value is: NO. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for VHDL. -# The default value is: NO. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given -# extension. Doxygen has a built-in mapping, but you can override or extend it -# using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: -# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: -# Fortran. In the later case the parser tries to guess whether the code is fixed -# or free formatted code, this is the default for Fortran type files), VHDL. For -# instance to make doxygen treat .inc files as Fortran files (default is PHP), -# and .f files as C (default is Fortran), use: inc=Fortran f=C. -# -# Note For files without extension you can use no_extension as a placeholder. -# -# Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments -# according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you can -# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in -# case of backward compatibilities issues. -# The default value is: YES. - -MARKDOWN_SUPPORT = YES - -# When enabled doxygen tries to link words that correspond to documented -# classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by by putting a % sign in front of the word -# or globally by setting AUTOLINK_SUPPORT to NO. -# The default value is: YES. - -AUTOLINK_SUPPORT = YES - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should set this -# tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); -# versus func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. -# The default value is: NO. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. -# The default value is: NO. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen -# will parse them like normal C++ but will assume all classes use public instead -# of private inheritance when no explicit protection keyword is present. -# The default value is: NO. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate -# getter and setter methods for a property. Setting this option to YES will make -# doxygen to replace the get and set methods by a property in the documentation. -# This will only work if the methods are indeed getting or setting a simple -# type. If this is not the case, or you want to show the methods anyway, you -# should set this option to NO. -# The default value is: YES. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. -# The default value is: NO. - -DISTRIBUTE_GROUP_DOC = NO - -# Set the SUBGROUPING tag to YES to allow class member groups of the same type -# (for instance a group of public functions) to be put as a subgroup of that -# type (e.g. under the Public Functions section). Set it to NO to prevent -# subgrouping. Alternatively, this can be done per class using the -# \nosubgrouping command. -# The default value is: YES. - -SUBGROUPING = YES - -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions -# are shown inside the group in which they are included (e.g. using \ingroup) -# instead of on a separate page (for HTML and Man pages) or section (for LaTeX -# and RTF). -# -# Note that this feature does not work in combination with -# SEPARATE_MEMBER_PAGES. -# The default value is: NO. - -INLINE_GROUPED_CLASSES = NO - -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions -# with only public data fields or simple typedef fields will be shown inline in -# the documentation of the scope in which they are defined (i.e. file, -# namespace, or group documentation), provided this scope is documented. If set -# to NO, structs, classes, and unions are shown on a separate page (for HTML and -# Man pages) or section (for LaTeX and RTF). -# The default value is: NO. - -INLINE_SIMPLE_STRUCTS = NO - -# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or -# enum is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically be -# useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. -# The default value is: NO. - -TYPEDEF_HIDES_STRUCT = NO - -# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This -# cache is used to resolve symbols given their name and scope. Since this can be -# an expensive process and often the same symbol appears multiple times in the -# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small -# doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range -# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 -# symbols. At the end of a run doxygen will report the cache usage and suggest -# the optimal cache size from a speed point of view. -# Minimum value: 0, maximum value: 9, default value: 0. - -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. Private -# class members and static file members will be hidden unless the -# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. -# Note: This will also disable the warnings about undocumented members that are -# normally produced when WARNINGS is set to YES. -# The default value is: NO. - -EXTRACT_ALL = NO - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will -# be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal -# scope will be included in the documentation. -# The default value is: NO. - -EXTRACT_PACKAGE = NO - -# If the EXTRACT_STATIC tag is set to YES all static members of a file will be -# included in the documentation. -# The default value is: NO. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO -# only classes defined in header files are included. Does not have any effect -# for Java sources. -# The default value is: YES. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local methods, -# which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO only methods in the interface are -# included. -# The default value is: NO. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base name of -# the file that contains the anonymous namespace. By default anonymous namespace -# are hidden. -# The default value is: NO. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all -# undocumented members inside documented classes or files. If set to NO these -# members will be included in the various overviews, but no documentation -# section is generated. This option has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. If set -# to NO these classes will be included in the various overviews. This option has -# no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO these declarations will be -# included in the documentation. -# The default value is: NO. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO these -# blocks will be appended to the function's detailed documentation block. -# The default value is: NO. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation that is typed after a -# \internal command is included. If the tag is set to NO then the documentation -# will be excluded. Set it to YES to include the internal documentation. -# The default value is: NO. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. -# The default value is: system dependent. - -CASE_SENSE_NAMES = YES - -# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES the -# scope will be hidden. -# The default value is: NO. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of -# the files that are included by a file in the documentation of that file. -# The default value is: YES. - -SHOW_INCLUDE_FILES = YES - -# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each -# grouped member an include statement to the documentation, telling the reader -# which file to include in order to use the member. -# The default value is: NO. - -SHOW_GROUPED_MEMB_INC = NO - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include -# files with double quotes in the documentation rather than with sharp brackets. -# The default value is: NO. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the -# documentation for inline members. -# The default value is: YES. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the -# (detailed) documentation of file and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. -# The default value is: YES. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief -# descriptions of file, namespace and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. Note that -# this will also influence the order of the classes in the class list. -# The default value is: NO. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the -# (brief and detailed) documentation of class members so that constructors and -# destructors are listed first. If set to NO the constructors will appear in the -# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. -# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief -# member documentation. -# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting -# detailed member documentation. -# The default value is: NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy -# of group names into alphabetical order. If set to NO the group names will -# appear in their defined order. -# The default value is: NO. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by -# fully-qualified names, including namespaces. If set to NO, the class list will -# be sorted only by class name, not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the alphabetical -# list. -# The default value is: NO. - -SORT_BY_SCOPE_NAME = NO - -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper -# type resolution of all parameters of a function it will reject a match between -# the prototype and the implementation of a member function even if there is -# only one candidate or it is obvious which candidate to choose by doing a -# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still -# accept a match between prototype and implementation in such cases. -# The default value is: NO. - -STRICT_PROTO_MATCHING = NO - -# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the -# todo list. This list is created by putting \todo commands in the -# documentation. -# The default value is: YES. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the -# test list. This list is created by putting \test commands in the -# documentation. -# The default value is: YES. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug -# list. This list is created by putting \bug commands in the documentation. -# The default value is: YES. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) -# the deprecated list. This list is created by putting \deprecated commands in -# the documentation. -# The default value is: YES. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional documentation -# sections, marked by \if ... \endif and \cond -# ... \endcond blocks. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the -# initial value of a variable or macro / define can have for it to appear in the -# documentation. If the initializer consists of more lines than specified here -# it will be hidden. Use a value of 0 to hide initializers completely. The -# appearance of the value of individual variables and macros / defines can be -# controlled using \showinitializer or \hideinitializer command in the -# documentation regardless of this setting. -# Minimum value: 0, maximum value: 10000, default value: 30. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES the list -# will mention the files that were used to generate the documentation. -# The default value is: YES. - -SHOW_USED_FILES = YES - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This -# will remove the Files entry from the Quick Index and from the Folder Tree View -# (if specified). -# The default value is: YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces -# page. This will remove the Namespaces entry from the Quick Index and from the -# Folder Tree View (if specified). -# The default value is: YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command command input-file, where command is the value of the -# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided -# by doxygen. Whatever the program writes to standard output is used as the file -# version. For an example see the documentation. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. You can -# optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. -# -# Note that if you run doxygen from a directory containing a file called -# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE -# tag is left empty. - -LAYOUT_FILE = - -# The CITE_BIB_FILES tag can be used to specify one or more bib files containing -# the reference definitions. This must be a list of .bib files. The .bib -# extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. -# For LaTeX the style of the bibliography can be controlled using -# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. Do not use file names with spaces, bibtex cannot handle them. See -# also \cite for info how to create references. - -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES -# this implies that the warnings are on. -# -# Tip: Turn warnings on while writing the documentation. -# The default value is: YES. - -WARNINGS = YES - -# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES - -# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some parameters -# in a documented function, or documenting parameters that don't exist or using -# markup commands wrongly. -# The default value is: YES. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that -# are documented, but have no documentation for their parameters or return -# value. If set to NO doxygen will only warn about wrong or incomplete parameter -# documentation, but not about the absence of documentation. -# The default value is: NO. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that doxygen -# can produce. The string should contain the $file, $line, and $text tags, which -# will be replaced by the file and line number from which the warning originated -# and the warning text. Optionally the format may contain $version, which will -# be replaced by the version of the file (if it could be obtained via -# FILE_VERSION_FILTER) -# The default value is: $file:$line: $text. - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning and error -# messages should be written. If left blank the output is written to standard -# error (stderr). - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag is used to specify the files and/or directories that contain -# documented source files. You may enter file names like myfile.cpp or -# directories like /usr/src/myproject. Separate the files or directories with -# spaces. -# Note: If this tag is empty the current directory is searched. - -INPUT = - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses -# libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of -# possible encodings. -# The default value is: UTF-8. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank the -# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, -# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, -# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, -# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, -# *.qsf, *.as and *.js. - -FILE_PATTERNS = *.h \ - *.cpp - -# The RECURSIVE tag can be used to specify whether or not subdirectories should -# be searched for input files as well. -# The default value is: NO. - -RECURSIVE = NO - -# The EXCLUDE tag can be used to specify files and/or directories that should be -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# -# Note that relative paths are relative to the directory from which doxygen is -# run. - -EXCLUDE = - -# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded -# from the input. -# The default value is: NO. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories use the pattern */test/* - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or directories -# that contain example code fragments that are included (see the \include -# command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank all -# files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude commands -# irrespective of the value of the RECURSIVE tag. -# The default value is: NO. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or directories -# that contain images that are to be included in the documentation (see the -# \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command: -# -# -# -# where is the value of the INPUT_FILTER tag, and is the -# name of an input file. Doxygen will then use the output that the filter -# program writes to standard output. If FILTER_PATTERNS is specified, this tag -# will be ignored. -# -# Note that the filter must not add or remove lines; it is applied before the -# code is scanned, but not when the output code is generated. If lines are added -# or removed, the anchors will not be placed correctly. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: pattern=filter -# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how -# filters are used. If the FILTER_PATTERNS tag is empty or if none of the -# patterns match the file name, INPUT_FILTER is applied. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER ) will also be used to filter the input files that are used for -# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). -# The default value is: NO. - -FILTER_SOURCE_FILES = NO - -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and -# it is also possible to disable source filtering for a specific pattern using -# *.ext= (so without naming a filter). -# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. - -FILTER_SOURCE_PATTERNS = - -# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that -# is part of the input, its contents will be placed on the main page -# (index.html). This can be useful if you have a project on for instance GitHub -# and want to reuse the introduction page also for the doxygen output. - -USE_MDFILE_AS_MAINPAGE = - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will be -# generated. Documented entities will be cross-referenced with these sources. -# -# Note: To get rid of all source code in the generated output, make sure that -# also VERBATIM_HEADERS is set to NO. -# The default value is: NO. - -SOURCE_BROWSER = NO - -# Setting the INLINE_SOURCES tag to YES will include the body of functions, -# classes and enums directly into the documentation. -# The default value is: NO. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any -# special comment blocks from generated source code fragments. Normal C, C++ and -# Fortran comments will always remain visible. -# The default value is: YES. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. -# The default value is: NO. - -REFERENCED_BY_RELATION = YES - -# If the REFERENCES_RELATION tag is set to YES then for each documented function -# all documented entities called/used by that function will be listed. -# The default value is: NO. - -REFERENCES_RELATION = YES - -# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES, then the hyperlinks from functions in REFERENCES_RELATION and -# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will -# link to the documentation. -# The default value is: YES. - -REFERENCES_LINK_SOURCE = YES - -# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the -# source code will show a tooltip with additional information such as prototype, -# brief description and links to the definition and documentation. Since this -# will make the HTML file larger and loading of large files a bit slower, you -# can opt to disable this feature. -# The default value is: YES. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -SOURCE_TOOLTIPS = YES - -# If the USE_HTAGS tag is set to YES then the references to source code will -# point to the HTML generated by the htags(1) tool instead of doxygen built-in -# source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version -# 4.8.6 or higher. -# -# To use it do the following: -# - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file -# - Make sure the INPUT points to the root of the source tree -# - Run doxygen as normal -# -# Doxygen will invoke htags (and that will in turn invoke gtags), so these -# tools must be available from the command line (i.e. in the search path). -# -# The result: instead of the source browser generated by doxygen, the links to -# source code will now point to the output of htags. -# The default value is: NO. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a -# verbatim copy of the header file for each class for which an include is -# specified. Set to NO to disable this. -# See also: Section \class. -# The default value is: YES. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all -# compounds will be generated. Enable this if the project contains a lot of -# classes, structs, unions or interfaces. -# The default value is: YES. - -ALPHABETICAL_INDEX = NO - -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all classes will -# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag -# can be used to specify a prefix (or a list of prefixes) that should be ignored -# while generating the index headers. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output -# The default value is: YES. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each -# generated HTML page (for example: .htm, .php, .asp). -# The default value is: .html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a user-defined HTML header file for -# each generated HTML page. If the tag is left blank doxygen will generate a -# standard header. -# -# To get valid HTML the header file that includes any scripts and style sheets -# that doxygen needs, which is dependent on the configuration options used (e.g. -# the setting GENERATE_TREEVIEW). It is highly recommended to start with a -# default header using -# doxygen -w html new_header.html new_footer.html new_stylesheet.css -# YourConfigFile -# and then modify the file new_header.html. See also section "Doxygen usage" -# for information on how to generate the default header that doxygen normally -# uses. -# Note: The header is subject to change so you typically have to regenerate the -# default header when upgrading to a newer version of doxygen. For a description -# of the possible markers and block names see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each -# generated HTML page. If the tag is left blank doxygen will generate a standard -# footer. See HTML_HEADER for more information on how to generate a default -# footer and what special commands can be used inside the footer. See also -# section "Doxygen usage" for information on how to generate the default footer -# that doxygen normally uses. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style -# sheet that is used by each HTML page. It can be used to fine-tune the look of -# the HTML output. If left blank doxygen will generate a default style sheet. -# See also section "Doxygen usage" for information on how to generate the style -# sheet that doxygen normally uses. -# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as -# it is more robust and this tag (HTML_STYLESHEET) will in the future become -# obsolete. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_STYLESHEET = - -# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- -# defined cascading style sheet that is included after the standard style sheets -# created by doxygen. Using this option one can overrule certain style aspects. -# This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefor more robust against future updates. -# Doxygen will copy the style sheet file to the output directory. For an example -# see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that the -# files will be copied as-is; there are no commands or markers available. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the stylesheet and background images according to -# this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value -# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 -# purple, and 360 is red again. -# Minimum value: 0, maximum value: 359, default value: 220. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use grayscales only. A -# value of 255 will produce the most vivid colors. -# Minimum value: 0, maximum value: 255, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the -# luminance component of the colors in the HTML output. Values below 100 -# gradually make the output lighter, whereas values above 100 make the output -# darker. The value divided by 100 is the actual gamma applied, so 80 represents -# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not -# change the gamma. -# Minimum value: 40, maximum value: 240, default value: 80. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_TIMESTAMP = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_SECTIONS = NO - -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries -# shown in the various tree structured indices initially; the user can expand -# and collapse entries dynamically later on. Doxygen will expand the tree to -# such a level that at most the specified number of entries are visible (unless -# a fully collapsed tree already exceeds this amount). So setting the number of -# entries 1 will produce a full collapsed tree by default. 0 is a special value -# representing an infinite number of entries and will result in a full expanded -# tree by default. -# Minimum value: 0, maximum value: 9999, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_INDEX_NUM_ENTRIES = 100 - -# If the GENERATE_DOCSET tag is set to YES, additional index files will be -# generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_DOCSET = NO - -# This tag determines the name of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# The default value is: Doxygen generated docs. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# This tag specifies a string that should uniquely identify the documentation -# set bundle. This should be a reverse domain-name style string, e.g. -# com.mycompany.MyDocSet. Doxygen will append .docset to the name. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. -# The default value is: org.doxygen.Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. -# The default value is: Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three -# additional HTML index files: index.hhp, index.hhc, and index.hhk. The -# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. -# -# The HTML Help Workshop contains a compiler that can convert all HTML output -# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML -# files are now used as the Windows 98 help format, and will replace the old -# Windows help format (.hlp) on all Windows platforms in the future. Compressed -# HTML files also contain an index, a table of contents, and you can search for -# words in the documentation. The HTML workshop also contains a viewer for -# compressed HTML files. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_HTMLHELP = NO - -# The CHM_FILE tag can be used to specify the file name of the resulting .chm -# file. You can add a path in front of the file if the result should not be -# written to the html output directory. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_FILE = - -# The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler ( hhc.exe). If non-empty -# doxygen will try to run the HTML help compiler on the generated index.hhp. -# The file has to be specified with full path. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -HHC_LOCATION = - -# The GENERATE_CHI flag controls if a separate .chi index file is generated ( -# YES) or that it should be included in the master .chm file ( NO). -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -GENERATE_CHI = NO - -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) -# and project file content. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_INDEX_ENCODING = - -# The BINARY_TOC flag controls whether a binary table of contents is generated ( -# YES) or a normal table of contents ( NO) in the .chm file. Furthermore it -# enables the Previous and Next buttons. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members to -# the table of contents of the HTML help documentation and to the tree view. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that -# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help -# (.qch) of the generated HTML documentation. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify -# the file name of the resulting .qch file. The path specified is relative to -# the HTML output folder. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help -# Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt -# Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). -# The default value is: doc. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_VIRTUAL_FOLDER = doc - -# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom -# filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_SECT_FILTER_ATTRS = - -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be -# generated, together with the HTML files, they form an Eclipse help plugin. To -# install this plugin and make it available under the help contents menu in -# Eclipse, the contents of the directory containing the HTML and XML files needs -# to be copied into the plugins directory of eclipse. The name of the directory -# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. -# After copying Eclipse needs to be restarted before the help appears. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the Eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have this -# name. Each documentation set should have its own identifier. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# If you want full control over the layout of the generated HTML pages it might -# be necessary to disable the index and replace it with your own. The -# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top -# of each HTML page. A value of NO enables the index and the value YES disables -# it. Since the tabs in the index contain the same information as the navigation -# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -DISABLE_INDEX = NO - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. If the tag -# value is set to YES, a side panel will be generated containing a tree-like -# index structure (just like the one that is generated for HTML Help). For this -# to work a browser that supports JavaScript, DHTML, CSS and frames is required -# (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can -# further fine-tune the look of the index. As an example, the default style -# sheet generated by doxygen has an example that shows how to put an image at -# the root of the tree instead of the PROJECT_NAME. Since the tree basically has -# the same information as the tab index, you could consider setting -# DISABLE_INDEX to YES when enabling this option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_TREEVIEW = NO - -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that -# doxygen will group on one line in the generated HTML documentation. -# -# Note that a value of 0 will completely suppress the enum values from appearing -# in the overview section. -# Minimum value: 0, maximum value: 20, default value: 4. -# This tag requires that the tag GENERATE_HTML is set to YES. - -ENUM_VALUES_PER_LINE = 4 - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used -# to set the initial width (in pixels) of the frame in which the tree is shown. -# Minimum value: 0, maximum value: 1500, default value: 250. -# This tag requires that the tag GENERATE_HTML is set to YES. - -TREEVIEW_WIDTH = 250 - -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to -# external symbols imported via tag files in a separate window. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of LaTeX formulas included as images in -# the HTML documentation. When you change the font size after a successful -# doxygen run you need to manually remove any form_*.png images from the HTML -# output directory to force them to be regenerated. -# Minimum value: 8, maximum value: 50, default value: 10. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are not -# supported properly for IE 6.0, but are supported on all modern browsers. -# -# Note that when changing this option you need to delete any form_*.png files in -# the HTML output directory before the changes have effect. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_TRANSPARENT = YES - -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using prerendered bitmaps. Use this if you do not have LaTeX -# installed or if you want to formulas look prettier in the HTML output. When -# enabled you may also need to install MathJax separately and configure the path -# to it using the MATHJAX_RELPATH option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -USE_MATHJAX = NO - -# When MathJax is enabled you can set the default output format to be used for -# the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. -# Possible values are: HTML-CSS (which is slower, but has the best -# compatibility), NativeMML (i.e. MathML) and SVG. -# The default value is: HTML-CSS. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_FORMAT = HTML-CSS - -# When MathJax is enabled you need to specify the location relative to the HTML -# output directory using the MATHJAX_RELPATH option. The destination directory -# should contain the MathJax.js script. For instance, if the mathjax directory -# is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax -# Content Delivery Network so you can quickly see the result without installing -# MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest - -# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax -# extension names that should be enabled during MathJax rendering. For example -# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_EXTENSIONS = - -# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces -# of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an -# example see the documentation. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_CODEFILE = - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for -# the HTML output. The underlying search engine uses javascript and DHTML and -# should work on any modern browser. Note that when using HTML help -# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) -# there is already a search function so this one should typically be disabled. -# For large projects the javascript based search engine can be slow, then -# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to -# search using the keyboard; to jump to the search box use + S -# (what the is depends on the OS and browser, but it is typically -# , /