This removes the caret as a shorthand for redirecting stderr.
Note that stderr may be redirected to a file via 2>/some/path...
and may be redirected with a pipe via 2>|.
Fixes#4394
Variables set in if and while conditions are in the enclosing block, not
the if/while statement block. For example:
if set -l var (somecommand) ; end
echo $var
will now work as expected.
Fixes#4820. Fixes#1212.
This promotes "and" and "or" from a type of statement to "job
decorators," as a possible prefix on a job. The point is to rationalize
how they interact with && and ||.
In the new world 'and' and 'or' apply to a entire job conjunction, i.e.
they have "lower precedence." Example:
if [ $age -ge 0 ] && [ $age -le 18 ]
or [ $age -ge 75 ] && [ $age -le 100 ]
echo "Child or senior"
end
This now reports "TOO_MANY_ARGS" instead of no error (and triggering
an assertion).
We might want to add a new error type or report the missing operator
before, but this is okay for now.
This enables some limited use of arguments for wrapping completions. The
simplest example is that complete gco -w 'git checkout' now works like
you would want: `gco <tab>` now invokes git's completions with the
`checkout` argument prepended.
Fixes#1976
`argparse`, `read`, `set`, `status`, `test` and `[` now can't be used
as function names anymore.
This is because (except for `test` and `[`) there is no way to wrap these properly, so any
function called that will be broken anyway.
For `test` (and `[`), there is nothing that can be added and there
have been confused users who created a function that then broke
everything.
Fixes#3000.
This switches function execution from the function's source code to
its stored node and pstree. This means we no longer have to re-parse
the function every time we execute it.
Some of these were failing on Travis quite often, and this is probably
the result of too tight a window.
E.g. one emacs test (transpose words, default timeout, short delay)
waited 250ms to enter something else, with a timeout of 300ms. That
meant a window of 50ms.
The psub tests create a fifo and launch a background job to write to it.
However fifos have this obnoxious behavior where opening the file blocks
until both sides are ready. In one of the tests we don't actually read
from the fifo we create, so the background job hangs, and the tests
never complete. Fix this by just reading from the fifo.
This was caused by it prepending "-s" to argv always,
and later checking $argv[1].
As it turns out, that is kinda superfluous, so we can just add "-s" to
the `bind` calls.
Also adjust the tests so the vi-bindings are enabled via the function,
which would have caught this.
Fixes#4494.
Prior to this fix, a "bare variable" in math like 'x + 1' would be
looked up in the environment, i.e. equivalent to '$x + 1'. This appears
to have been done for performance. However this breaks the orthogonality
of fish; performance is not a sufficient justification to give math this
level of built-in power, especially because the performance of math is
not a bottleneck. The implementation is also ugly.
Remove this feature so that variables must be prefixed with the dollar
sign and undergo normal variable expansion. Reading 'git grep' output
does not show any uses of this in fish functions or completions.
Also added to changelog.
Fixes#4393
Instead of treating the search term as a literal string to be matched
treat it as a glob. This allows the user to get a more useful set of
results by using the `*` glob character in the search term.
Partial fix for #3136
* Implement `history search --reverse`
It should be possible to have `history search` output ordered oldest to
newest like nearly every other shell including bash, ksh, zsh, and csh.
We can't make this the default because too many people expect the
current behavior. This simply makes it possible for people to define
their own abbreviations or functions that provide behavior they are
likely used to if they are transitioning to fish from another shell.
This also fixes a bug in the `history` function with respect to how it
handles the `-n` / `--max` flag.
Fixes#4354
* Fix comment for format_history_record()
* Hoist `for` loop control var to enclosing scope
It should be possible to reference the last value assigned to a `for`
loop control var when the loop terminates. This makes it easier to detect
if we broke out of the loop among other things. This change makes fish
`for` loops behave like most other shells.
Fixes#1935
* Remove redundant line
cherry-picked from krader1961/fish-shell commit b69df4fe72
Fixes#4353 (regression in indexing of history contents) and introduces
new unit tests to catch bad $history indexing in the future.
Remove our `math` function that wraps `bc`. Our math builtin is now good
enough that it can be the default implementation.
Another step in resolving #3157.
Using a read-only variable like `status` as a for loop control variable
has never worked. But without this change you simply get non-sensical
behavior that leaves you scratching your head in puzzlement. This change
replaces the non-sensical behavior with an explicit error message.
Fixes#4342
Internally fish should store vars as a vector of elements. The current
flat string representation is a holdover from when the code was written
in C.
Fixes#4200
A semi-empty var is one with a single empty string element. The
`env_var_t::empty()` method returns true for such vars but we want
`set --show` to report that it has a single empty element.
This makes command substitutions impose the same limit on the amount
of data they accept as the `read` builtin. It does not limit output of
external commands or builtins in other contexts.
Fixes#3822
This adds a new capability to the `set` command. It is similar to
running `set` with no other arguments but provides far more detail about
each variable. Such as whether it is set in each of the local, global,
and universal scopes. And the values in each scope. You can also ask for
specific variables to be shown.
Fixes#4265
Rewrite the `abbr` function to store each abbreviation in a separate
variable. This greatly improves the efficiency. For the common case
it is 5x faster. For pathological cases it is upwards of 100x faster.
Most people should be able to unconditionally define abbreviations in
their config.fish without a noticable slow down.
Fixes#4048
This takes a string that is then split upon like `string split`.
Unlike $IFS, the string is used as one piece, not a set of characters.
There is still a fallback to IFS if no delimiter is given, that
behaves exactly as before.
Fixes#4156.
This completes the refactoring of the `set` builtin. It also removes a
seemingly never used feature of the `set` command. It also eliminates all
the lint warnings about this module.
Fixes#4236
When reporting whether a boolean flag was seen report the actual flags
rather than a summary count. For example, if you have option spec `h/help`
and we parse `-h --help -h` don't do the equivalent of `set _flag_h 3`
do `set _flag_h -h --help -h`.
Partial fix for #4226
The recent change to switch `psub` to use `argparse` caused it to use
a fifo by default because it inadvertently fixed a long standing bug in
the fish script. This changes the behavior back to `psub --file` being
the default behavior and introduces a `--fifo` flag. It also updates the
documentation to make it clearer when and why `--fifo` mode should not
be used.
Fixes#4222
While updating the `history` function to use `argparse` I realized it is
useful to define an option that can be used in three ways. First by
using the short flag; e.g., `-n NNN`. Second by using the long flag;
e.g., `--max NNN`. Third, as an implicit int flag; e.g., `-NNN`. This
use case is now supported by a spec of the form `n#max`.
A recent regression to the `alias` command points out the need for more
unit tests of its behavior. I also decided to use it as an opportunity
to normalize the output of just `alias` to list aliases.
The previous change to use `argparse` for parity with every other
builtin and function introduced a regression. Invocations that start
with a negative number can fail because the negative value looks like an
invalid flag.
This implements support for numeric flags without an associated short or
long flag name. This pattern is used by many commands. For example `head
-3 /a/file` to emit the first three lines of the file.
Fixes#4214
This implements a `fish_opt` command that provides a way for people
to create option specs for the `argparse` command as an alternative to
creating such strings by hand.
Fixes#4190
The count command should not treat any flag specially. Not even `-h` and
`--help`. It should simply return a count of the number of arguments it
received.
Fixes#4189
Don't import the bash history if the user has specified that a non-default
fish history file should be used. Also, rename the var that specifies
the fish history session ID from `FISH_HISTFILE` to `FISH_HISTORY`.
Fixes#4172
Using the FISH_HISTFILE variable will let people customise the session
to use for the history file. The resulting history file is:
`$XDG_DATA_HOME/fish/name_history`
Where `name` is the name of the session. The default value is `fish`
which results in the current history file.
If it's set to an empty string, the history will not be stored to a
file.
Fixes#102
Because the 'getopt' library differs between systems, it's likely
that there will be different output. This is the case between the
GNU-based Linux and the BSD-based Darwin, for the 'getopt' library,
it seems. It causes the tests to produce different results.
To allow us to test, and check for regressions, on the different
platforms, the invocation code has been updated to allow a
system-specific suffix to be used on the test files. If this suffix
is found, the test will also be flagged as being system-specific
which should ensure the change in behaviour is noted.
The Travis macOS test systems do not appear to have colordiff present, so any
failures would mean that no output would be shown. This may also be a
problem for the other test scripts as well, but the invocation tests are
the ones being affected here.
We change our behaviour to downgrade to the plain diff tool if colordiff is
not present.
The invocation tests were not especially clear on how they should be
used, without reading the code. And who really wants to do that? So,
a description of what the test does (and thus what each file is) is
now present in the file prologue comment.
Some more of the invocations are tested in this change:
- bad switches
- errors in configuration files
- regular command, configuration and init command ordering
- persistence of variables over command invocation.
- interactive and login switch use
- terminal exit code return
- version request
There are sure to be other invocations that should be tested, but
these give a fair number of them a go.
The new '-C' initial command needs some tests, and as there are no
tests just yet for the command invocation, this change adds a harness
and calls it from the high-level tests in the Makefile.
The tests are similar in style to the other high level tests, in that
we capture the output and compare it to that which we expect. The
harness itself is written in bash - sorry - because we're testing the
fish shell's invocation, and trying to do that with the fish we've
just built wouldn't actually make for a very useful test when things
go wrong.
The 'tests/invocation.sh' script can be executed manually, or as part
of the 'make test' target, to make it easy to use both as part of the
development and as part of automation.
The harness has only been tested on linux with bash 4.3.11, and requires
grep and sed. Although not tested with OS X, I believe I have avoided
the syntax which is inconsistent.
The tests added here cover just the initial command's basic execution,
and when it is mixed with the regular '-c' command.
We need a way to encode arbitrary strings into valid fish variable
names. It would also be nice if we could convert strings to valid URLs
without using the slow and hard to understand `__fish_urlencode` function.
In particular, eliminating the need to manipulate the locale.
Fixes#4150
This just removes every invalid index.
That means with `set foo a b c` and the "show" function from tests/expand.in:
- `show $foo[-5..-1]` prints "3 a b c"
- `show $foo[-10..1]` prints "1 a"
- `show $foo[2..5]` prints "2 b c"
- `show $foo[1 3 7 2]` prints "3 a c b"
and similar for command substitutions.
Fixes#826.
This implements `status is-breakpoint` that returns true if the current
shell prompt is displayed in the context of a `breakpoint` command.
This also fixes several bugs. Most notably making `breakpoint` a no-op if
the shell isn't interactive. Also, typing `breakpoint` at an interactive
prompt should be an error rather than creating a new nested debugging
context.
Partial fix for #1310
This changes all of the builtins to behave like `string` to return
STATUS_INVALID_ARGS (121) if the args passed to the command don't make
sense. Also change several of the builtins to use the existing symbols
(e.g., STATUS_CMD_OK and STATUS_CMD_ERROR) rather than hardcoded "0"
and "1" for consistency and to make it easier to find such values in
the future.
Fixes#3985
Per discussion in PR#3998 to review adding a `--filter` flag to `string
replace` rename the same flag in the `string match` subcommand to avoid
confusion about the meaning of the flag.
Discussion in issue #3295 resulted in a decisions to rename the
functions --metadata flag to --details.
This also fixes a bug in the definition of the short flags for the
`functions` command. The `-e` flag does not take an argument and
therefore should not be defined as `e:`. Notice that the long form,
`--erase`, specifies `no_argument`. This discrepency happened to work
due to a quirk of how the flag parsing loop was written.
The bind mode names can be, and are, used in the construction of fish
variable names. So don't allow users to use names that are not legal as
a variable name. This should not break anything since, AFAICT, no
existing fish scripts, including those provided by Oh-My-Fish and
Fisherman define bind modes that would not be legal with this change.
Fixes#3965
This is to fix tests on Travis, since that stores the commit message in an environment variable.
`env | grep MANPATH` of course picks it up and generates unwanted output.
Yes.
Fixes invalid character in variable name $fish_cursor_replace-one (used by fish_vi_cursor[_handle]) by renaming bind mode 'replace-one' to 'replace_one'.
Reviewing a PR for a completion script caused me to look at the
implementation for the `__fish_complete_directories` function. Which in
turn lead me to create this change to improve its implementation and add
unit tests for the function.
- Error out if anything that is not a PID is given
- Otherwise background all matching existing jobs, even if not all
PIDs exist (but print a message for the non-existing ones)
Fixes#3909.
If the first word of the alias body ends with a semicolon we need to
strip that character, and otherwise escape the extracted command, to
ensure the subsequent function definition is valid.
Fixes#3860
The previous change neglected to consider that numbers too large for the
long long datatype will result in calling strerror(ERANGE) whose return
value can vary depending on the platform. Which breaks the unit test.
This puts a hard upper bound of 10 MiB on the amount of data that read
will consume. This is to avoid having the shell consume an unreasonable
amount of memory, possibly causing the system to enter a OOM condition,
if the user does something non-sensical.
Fixes#3712
read_in_chunks does not clear the intermediate string 'str'
between iterations, so every chunk has every other chunk prepended
to it.
A secondary issue is that it calls str2wcstring() on an intermediate
chunk, which may split multi-byte sequences. This needs to be deferred
to the end.
Test added. Fixes#3756
This implements a way to use the `functions` command to perform
introspection to learn about the characteristics of a function. Such as
where it came from.
Fixes#3295
After 'x' is used to delete a character at the end of a line the cursor
should be repositioned at the last character, i.e. repeatedly pressing
'x' in normal mode should delete the entire string.
The abbr function doesn't have the possiblity to rename abbreviations.
You have to delete the old one and create a new one. This commit adds
this functionality and uses the syntax:
abbr -r OLD_KEY NEW_KEY
Fixes#2155.
This augments the previous change for issue #3346 by adding an error
message when an invalid integer is seen. This change is likely to be
controversial so I'm not going to squash it into the previous change.
There isn't a good reason to disallow an explicitly empty completion
description. Since I'm touching the code also modify the argument
parsing the match the style of most of the builtins.
Fixes#3557.
There was a discussion recently on Gitter about `set_color reset`. The
result was @floam creating commit bd03c3fbc to change it to `set_color
normal` in share/functions/vared.fish. This does the same for
tests/test_util.fish.
The `status` command currently silently allows incompatible flags (i.e.,
subcommands). Too, using flags to specify subcommands misleads the user
into thinking they can specify multiple subcommands.
We recently modified the `history` command to deprecate using flags for
subcommands. This change does the same for the `status` command.
Fixes#3509
After implementing `builtin fish_realpath` it was noticed that it did
not behave like GNU `realpath` without options. Which is super annoying
since that was the whole point of implementing the command. Major
failure on my part since I wrote the unit tests to match the behavior of
the existing `wrealpath()` function that I simply exposed as a builtin
command. Rather than actually verifying it behaved in a manner
compatible with GNU realpath.
Also, while the decision to call the builtin `fish_realpath` seemed to
make sense at the time of the original commit further reflection has
shown that to be a silly, idiosyncratic, thing to have done. So rename
it to simply `realpath`.
Fixes 3400
This deprecates the use of long options for history sub-commands (e.g.,
`history --delete`) in favor of proper sub-commands (e.g., `history
delete`). It also eliminates the short options for those sub-commands.
Also change option processing to allow options anywhere on the command
line to match how the vast majority of fish builtins handle flags.
Replace --with-time with --show-time.
Fixes#3367
Update history docs.
Note - the omission of a mention of timezone was intentional. These were recorded as naive timestamps lacking timezone information in the first place.
Another dev noticed that tests/printf.in was failing because they didn't have
the fr_FR.UTF-8 locale installed. Make that test more resilient by trying
other locales and if no suitable locale is found skipping the test.
Implementing the --shadow-builtin flag has proven to be highly controversial.
Revert the introduction of that flag to the `function` command. If someone
shoots themselves in the foot by redefining a builtin as a function that's
their problem and not our responsibility to protect them from doing so.
Fixes#3319
The recent change to reconcile the history builtin command and function
broke an undocumented behavior of `history --delete`. This change
reinstates that behavior. It also adds an explicit `--exact` search mode
for the `--search` and `--delete` subcommands.
Fixes#3270
This undoes the inheritance since it shared too much.
The idea here is to share bindings that aren't something the editors we're inspired by do - there's no "execute" in vi.
The basic editing and moving bindings are now vi-style in vi-mode and emacs-style in default mode.
This fixes several problems with how the builtin `history` command handles
arguments. It now complains and refuses to do anything if the user specifies
incompatible actions (e.g., `--search` and `--clear`). It also fixes a
regression introduced by previous changes with regard to invocations that
don't explicitly specify `--search` or a search term.
Enhances the history man page to clarify the behavior of various options.
This change is already far larger than I like so unit tests will be added
in a separate commit.
Fixes#3224.
Note: This fixes only a couple problems with the interactive `history
--delete` command in the `history` function. The main problem will be
dealt with via issue #31.
Attempting to execute something like `exec "$test"` results in a fish internal
token (a Unicode private use char) being printed in the resulting error
message. That's obviously not desirable as well as confusing.
Fixes#3187
Someone running fish in an unusual locale reported that an `assert()` was
firing when they typed `pkill c`. I traced it to two bugs. First, the
__fish_make_completion_signals command was producing a weird result. Second,
the builtin `complete` command wasn't adequately verifying its arguments.
Fixes#3129
The tests/*.status files aren't useful so eliminate them. Just verify whether
a given test module exited with a success status. There isn't any point in
having a "status" file that indicates the test module should exit with a
success (zero) status.
Closes#3208Closes#3209
I did some research and experiments. For good or bad the `bind` command
requires the use of wide char codepoints (e.g., \u1234) for non-ASCII
chars. So don't force the use of the POSIX locale, but do provide it as
an option for people who want to see the individual bytes rather than a
decoded wide char.
Simplify the format of the information displayed for each character. There
really isn't much point in providing decimal, octal, and hexadecimal. Just
print hex and symbolic representations.
Add an example `bind` command that a user can copy/paste.
Closes#3183
Another developer noticed that redirecting stdin of `fish_key_reader`
results in weird behavior. Which is not at all surprising. So add checks
to ensure stdin and stdout are attached to a tty.
Add some rudimentary unit tests for this program.
For example, an argument 12345^ is a real argument, not a redirection
There's no reason to use ^ here instead of >, and it's annoying to git
users.
Fixes#1873
Fix test setup bogosities. Specifically, they weren't hermetic with respect to
locale env vars.
Rewrite the handling of locale vars to simplify the code and make it more like
the pattern most programs employ.
Fixes#3110
Configure the tty driver to ignore the lnext (\cV) and werase (\cW) characters
so they can be bound to fish functions.
Correct the `fish_key_bindings` program to initialize the tty in the same
manner as the `fish` program.
Fixes#3064
Previously, `--erase` would not accept any options and wouldn't read
"--" as option-separator. Now it does like every other "command", and it
could conceivably gain e.g. a "--prefix" option.
This change does several things. First, and most important, it allows
dumping the "n" most recent stack frames on each debug() call. Second,
it demangles the C++ symbols. Third, it prepends each debug() message
with the debug level.
Unrelated to the above I've replaced all `assert(!is_forked_child());`
statements with `ASSERT_IS_NOT_FORKED_CHILD()` for consistency.
It's currently too easy for someone to bork their shell by doing something
like `function test; return 0; end`. That's obviously a silly, contrived,
example but the point is that novice users who learn about functions are
prone to do something like that without realizing it will bork the shell. Even
expert users who know about the `test` builtin might forget that, say, `pwd`
is a builtin.
This change adds a `--shadow-builtin` flag that must be specified to
indicate you know what you're doing.
Fixes#3000
This makes it easy for the user to request floating point output with the
desired number of digits after the decimal point (not to be confused with
significant digits).
Note that this is just a thin wrapper so someone can say `math -s3 10 / 3`
rather than `math "scale=3; 10 /3"`.
Resolves#1643
In my rush to get the fix for the wrong default Vi mode escape delay merged
(commit 3e24ae80b3) I neglected to update the
unit test. This change corrects that oversight.
Fish keywords can be quoted and split across lines. Prior to this change
`fish_indent` would retain such odd, obfuscated, formatting. This change
results in all keywords being converted to their canonical form.
This required fixing a bug: the keyword member of parse_node_t wasn't being
populated. This hadn't been noticed prior to now because it wasn't used.
Fixes#2921
Prior to this fix, when completing a command that doesn't have a /, we
would prepend each component of PATH and then expand the whole thing. So
any special characters in the PATH would be interpreted when performing
tab completion.
With this fix, we pull the PATH resolution out of complete.cpp and
migrate it to expand.cpp. This unifies nicely with the CDPATH resolution
already in that file. This requires introducing a new expand flag
EXPAND_SPECIAL_FOR_COMMAND, which is analogous to EXPAND_SPECIAL_CD
(which is renamed to EXPAND_SPECIAL_FOR_CD). This flag tells expand to
resolve paths against PATH instead of the working directory.
Fixes#952
Modify `fish_indent` to emit redirections without a space before the target of
the redirection; e.g., "2>&1" rather than "2>& 1" as the former is clearer to
humans.
Fixes#2899
The relevant standards allow the mbtowc/mbrtowc functions to reject
non-ASCII characters (i.e., chars with the high bit set) when the locale
is C or POSIX. The BSD libraries (e.g., on OS X) don't do this but
the GNU libraries (e.g., on Linux) do. Like most programs we need the
C/POSIX locales to allow arbitrary bytes. So explicitly check if we're
in a single-byte locale (which would also include ISO-8859 variants)
and simply pass-thru the chars without encoding or decoding.
Fixes#2802.
I noticed while fixing issue #2702 that the fish program being tested
was sourcing config.fish files outside of the current build. This also
happens when Travis CI runs the tests but isn't an issue there because
of how Travis is configured to execute the tests.
I also noticed that running `make test` was polluting my personal fish
history; which will become a bigger problem if and when the fishd universal
var file is moved from $XDG_CONFIG_HOME to $XDG_DATA_HOME.
This change makes it possible for an individual to run the tests on
their local machine secure in the knowledge that only the config.fish and
related files from their git repository will be used and doing so won't
pollute their personal fish history.
Resolves#469
pcre2_substitute() now sets the output buffer length to PCRE2_UNSET (~0)
if the output buffer is determined to be too small. This change keeps
track of the buffer size separately where pcre2 can't touch it.
A better fix would be to let pcre2 tell fish what size buffer it needs.
This can be done with PCRE2_SUBSTITUTE_OVERFLOW_LENGTH, but this
requires pcre2 10.21 or later (released January 12), which may be too
new to introduce as a dependency at this point.
Fixes#2743
I've run this more than twenty times through Travis CI (by adding/removing
a comment line). Without this tweak the longest sequence seems to be
around six successful runs.
Expand globs to zero arguments (nullglob) only for set, for and count.
The warning about failing globs, and setting the accompanying $status,
now happens regardless of mode, interactive or not.
It is assumed that the above commands are the common cases where
nullglob behaviour is desirable.
More importantly, doing this with `set` is a real feature enabler,
since the resulting empty array can be passed on to any command.
The previous behaviour was actually all nullglob (since commit
cab115c8b9), but this was undocumented;
the failglob warning was still printed in interactive mode,
and the documentation was bragging about failglob behaviour.
This changes the default escape timeout for the default keybindings (emacs
mode) to 300ms and the default for vi keybindings to 10ms.
I couldn't resist fixing a few nits in the fish_vi_key_bindings.fish file
since I was touching it to set the escape timeout.
My previous commit failed in the travis-ci environment despite passing on my
local computer. This appears to be due to expect timing out looking for the
expected input. See if increasing the expect timeout slightly fixes the
problem.
Introduce a "fish_escape_delay_ms" variable to allow the user to configure the
delay used when seeing a bare escape before assuming no other characters will
be received that might match a bound character sequence. This is primarily
useful for vi mode so that a bare escape character (i.e., keystroke) can
switch to vi "insert" to "normal" mode in a timely fashion.
This fails on e.g. an abbr that uses `env a=b`, like the included test demonstrates.
Unfortunately it decreases the speed again (2s vs 2.2s vs 4s original),
but correctness is more important.
The fix for #2075 inadvertently started unescaping the strings emitted
from `commandline -b`. Only strings emitted with the `-o` flag are
supposed to be unescaped.
Fixes#2210.