Commit Graph

4410 Commits

Author SHA1 Message Date
Aaron Gyes
9c96986b36 set_color: only fixup sitm/ritm/dim if NULL/empty
So we'll skip the hack should someone have a fixed terminfo or
only do it on the first set_color command.
2022-03-28 11:26:17 -07:00
Fabian Homborg
cc689290cd Autoload: Call the parser directly instead of going via "subshell"
This used to call exec_subshell, which has two issues:

1. It creates a command substitution block which shows up in a stack
trace
2. It does much more work than necessary

This removes a useless "in command substitution" from an error message
in an autoloaded file, and it speeds up autoloading a bit (not
measurable in actual benchmarks, but microbenchmarks are 2x).
2022-03-27 09:35:12 +02:00
Fabian Homborg
7469495459 complete: Stop wcslen just to figure out if string is not empty 2022-03-25 16:15:28 +01:00
Fabian Homborg
351cd5bd4b set: Skip a wcslen 2022-03-25 16:06:10 +01:00
Fabian Homborg
bac2eef496 Remove useless use of wcslen 2022-03-25 16:06:10 +01:00
Fabian Homborg
42ea2758b6 Overload fish_wcstod for wcstring and length
This lets us skip wcslen a bunch
2022-03-25 16:06:10 +01:00
Fabian Homborg
fa1ecb8c67 reader: Some light stringification 2022-03-25 16:06:10 +01:00
Fabian Homborg
f98398b418 event: Pass name as wcstring
This passed a wchar_t, only to then construct a wcstring out of it.
Instead let's just pass it directly and move it.
2022-03-25 16:06:10 +01:00
ridiculousfish
ac888ac6af Migrate 'within_fish_init' to a parser-local variable
We need special handling when reporting backtraces for commands run
during startup, i.e. config.fish. Previously we had a global variable;
make it local to the parser to eliminate a global.

No functional change here.
2022-03-24 21:43:58 -07:00
David Adam
a7eebff916 ulimit: return a specific error if option is not supported by the OS 2022-03-24 10:23:04 +08:00
David Adam
8c4c526698 ulimit: add new limits from FreeBSD/NetBSD
Short option names are taken from sh for those platforms where possible.
2022-03-24 10:23:04 +08:00
David Adam
2c2b87af07 ulimit: add new limits from Linux
Short options are taken from prlimit(1) where appropriate.

Closes #8786.
2022-03-24 10:23:04 +08:00
David Adam
ee69a2467e ulimit: some corrections to descriptions and documentation 2022-03-24 10:23:04 +08:00
Fabian Homborg
2101dd4add Let nextd-or-forward-word binding move like normal forward_word
Broken in #8358, this caused nextd-or-forward-word to actually be
nextd-or-forward-bigword.

See #8790.
2022-03-22 22:09:42 +01:00
Fabian Homborg
1f997de8bf Fix job run flog
The arguments didn't match the format string.
2022-03-21 16:26:01 +01:00
ridiculousfish
d0d5c62ec7 Fix case-changing autosuggestions generated mid-token
This fixes a bug where a case-changing autosuggestion generated from the
middle of a token would append too much to the end of the token.

Fixes #8820
2022-03-20 20:16:01 -07:00
ridiculousfish
1763e7d3bc Remove some dead code
These functions were unused.
2022-03-20 14:48:44 -07:00
ridiculousfish
7b1321f9a1 Remove cancellation groups
Cancellation groups were meant to reflect the following idea: if you ran a
simple block:

    begin
        cmd1
        cmd2
    end

then under job control, cmd1 and cmd2 would get separate groups; however if
either exits due to SIGINT or SIGQUIT we also want to propagate that to the
outer block. So the outermost block and its interior jobs would share a
cancellation group. However this is more complex than necessary; it's
sufficient for the execution context to just store an int internally.

This ought not to affect anything user-visible.
2022-03-20 14:39:00 -07:00
Fabian Homborg
5926a75cc5 highlight: Also use the fallback variable if the main is empty
Currently, when a variable like $fish_color_command is set but empty:

    set -g fish_color_command

what happens is that highlight parses it and ends up with a "normal"
color.

Change it so instead it sees that the variable is empty and goes
on to check the fallback variable, e.g. fish_color_normal.

That makes it easier to make themes that override variables.

This means that older themes that expect an empty variable to be
"normal" need to be updated to set it to "normal".

Following from this, we could make writing .theme files easier by no
longer requiring them to list all variables with specific values.
Either the theme reader could be updated to implicitly set known color
variables to empty, or the themes could feature empty values.

See #8787.
2022-03-20 17:04:28 +01:00
ridiculousfish
3e5284aaf2 Stop restoring tty modes when run non-interactively
fish reads the tty modes at startup, and tries to restore them to the
original values on exit, to be polite. However this causes problems when
fish is run in a pipeline with another process which also messes with the
tty modes. Example:

    fish -c 'echo foo' | vim -

Here vim's manipulation of the tty would race with fish, and often vim
would end up with broken modes.

Only restore the tty if we are interactive. Fixes #8705.
2022-03-19 14:55:54 -07:00
ridiculousfish
df2cbe321c Refactor tty transfer to be more deliberate
This is a big cleanup to how tty transfer works. Recall that when job
control is active, we transfer the tty to jobs via tcsetpgrp().

Previously, transferring was done "as needed" in continue_job. That is, if
we are running a job, and the job wants the terminal and does not have it,
we will transfer the tty at that point.

This got pretty weird when running mixed pipelines. For example:

    cmd1 | func1 | cmd2

Here we would run `func1` before calling continue_job. Thus the tty
would be transferred by the nested function invocation, and also restored
by that invocation, potentially racing with tty manipulation from cmd1 or
cmd2.

In the new model, migrate the tty transfer responsibility outside of
continue_job. The caller of continue_job is then responsible for setting up
the tty. There's two places where this gets done:

1. In `exec_job`, where we run a job for the first time.

2. In `builtin_fg` where we continue a stopped job in the foreground.

Fixes #8699
2022-03-19 14:48:36 -07:00
ridiculousfish
3f585cddfc Refactor job pgroup assignment
This is a cleanup of job groups, rationalizing a bunch of stuff. Some
notable changes (none user-visible hopefully):

1. Previously, if a job group wanted a pgid, then we would assign it to the
   first process to run in the job group. Now we deliberately mark which
   process will own the pgroup, via a new `leads_pgrp` flag in process_t. This
   eliminates a source of ambiguity.

2. Previously, if a job were run inside fish's pgroup, we would set fish's
   pgroup as the group of the job. But this meant we had to check if the job
   had fish's pgroup in lots of places, for example when calling tcsetpgrp.
   Now a job group only has a pgrp if that pgrp is external (i.e. the job is
   under job control).
2022-03-19 14:06:18 -07:00
Fabian Homborg
0bc6a7b2ed
Make --no-config mode more comfortable (#8493)
* Turn on default bindings for --no-config mode

The fallback bindings are super awkward to use.

This was called out specifically in #7921, I'm going for the targeted
fix for now.

* Only change keybindings when interactive

That's also when we'd source them normally.
2022-03-17 19:02:12 +01:00
Fabian Homborg
ef28931293 Stop migrating legacy uvar paths
These were changed in fish 3.0 in December 2018.

This means upgrading from fish 2.7.1 or earlier to the next fish
version will require users to set their universal variable again.
2022-03-17 18:15:11 +01:00
Fabian Homborg
a7b80c9881 Remove misleading comment 2022-03-17 18:15:11 +01:00
Fabian Homborg
03c188086c Remove wcsndup and wcslcpy
We no longer use these anywhere.
2022-03-17 18:15:11 +01:00
Fabian Homborg
753f29df4c Stringify reformat_for_screen
This is the only usage of wcsndup, and we can just use wcstring::substr.
2022-03-17 18:15:11 +01:00
Fabian Homborg
534646f9d3 read: Actually only fire fish_read, not fish_prompt event
Fixes #8797.
2022-03-16 20:14:59 +01:00
Fabian Homborg
4e2ce0af4e pwd: Add newline to error message
This would keep the cursor on the same line, which is annoying.
2022-03-16 19:20:58 +01:00
Fabian Homborg
695e20c47f Fix build on NetBSD
This missed a change to "dir_remoteness_t" from bool

Fixes #8788
2022-03-14 18:13:39 +01:00
Fabian Homborg
a76ed9942d Fix tparm kludge
This just defines a constant to whichever tparm implementation we're
using (either the actual, working one the system provides, or our
kludge to paper over Solaris' inadequacies).

This means that there won't be so much ping-ponging of what "tparm"
stands for. "tparm" is the system's function. Only we don't use it,
just like we don't use wcstod directly.

Fixes #8780
2022-03-14 15:36:17 +01:00
Fabian Homborg
cd62771d12 read: Don't use chunking read with --line
Fixes a regression from #8552.
2022-03-14 08:04:35 +01:00
joao-vitor-sr
4ae4ea0169
New -n flag for string join. (#8774)
* New -n flag for string join command.

This is an argument that excludes empty result items. Fixes #8351

* New documentation for string-join.

The new argument --no-empty was added at string-join manpage.

* New completions for the new -n flag for string join.

* Remove the documentation of the new -n flag of string join0

The reason to remove this new argument in the join0 is that this flag basically doesn't make any difference in the join0.

* Refactor the validation for the string join.

The string join command was using the length of the argument, this commit changes the validation to use the empty function.

* Revert #4b56ab452

The reason for the revert is thath the build broke on the ubuntu in the Github actions.

* Revert #e72e239a1

The reason the compilation on GitHub broke is that the test was weird, it didn't even run it, Common CI systems are typically very very resource-constrained.

* Resolve conflicts in the string-join.rst.

* Resolve conflicts in the "string-join.rst".

commit #1242d0fd7 not fixed all conflicts.
2022-03-13 11:47:33 +01:00
Fabian Homborg
a7859191b2 Remove is_color_escape_seq
This is supposed to detect color escape sequences, to figure out how
long an escape sequence is, for use in width calculations.

However, the typical color sequences are already taken care of by
is_csi_style_escape_seq because they look like a csi sequence starting
with `\e[` and ending in `m`.

In the entire terminfo database shipped with ncurses 6.3, these are
the terminals that have non-csi color sequences:

at-color
atari-color
atari_st-color
d220-dg
d230-dg
d230c-dg
d430-dg
d430-unix
d430-unix-25
d430-unix-s
d430-unix-sr
d430-unix-w
d430c-dg
d430c-unix
d430c-unix-25
d430c-unix-s
d430c-unix-sr
d430c-unix-w
d470-dg
d470c-dg
dg+fixed
dgmode+color
dgmode+color8
dgunix+fixed
emu
fbterm
i3164
ibm3164
linux-m1b
linux-m2
minitel1
minitel1b
putty-m1b
putty-m2
st52-color
tt52
tw52
tw52-color
xterm-8bit

Most of these were discontinued in the 90s and their manufacturers no
longer exist (like Data General, which went defunct in 1999). The last one is a special mode for xterm that is
fundamentally UTF-8 incompatible because it encodes a CSI as \X9b.

The linux/putty m1b and m2 entries (also for minitel) don't support
color to begin with and the sequences they have in their terminfo
entries are control characters anyway, so the calculation would still
add up.

In turn, what we gain from this is much faster width calculations with
unrecognized escapes -
e.g. `string length -V \efoo` is sped up by a factor of 20.

An alternative would be to skip this if max_colors is > 16 as that is
the most any of these entries can do. The runtime scales linearly with
the number of colors so on those systems it would be reasonably quick anyway.

But given just *how* outdated these are I believe it is okay to just
remove support outright. I do not believe anyone has ever run fish on
any of these.
2022-03-13 11:32:53 +01:00
Fabian Homborg
972752aa1c
Merge branch 'master' into te-refactor 2022-03-13 11:24:31 +01:00
Andrey Mishchenko
59e50f77bc
Allow underscores as separators in the math builtin (#8611)
* Implement fish_wcstod_underscores

* Add fish_wcstod_underscores unit tests

* Switch to using fish_wcstod_underscores in tinyexpr

* Add tests for math builtin underscore separator functionality

* Add documentation for underscore separators for math builtin

* Add a changelog entry for underscore numeric separators
2022-03-13 11:23:35 +01:00
Fabian Homborg
9ada7d9aad read: Also read in chunks when directly redirected
We can't always read in chunks because we often can't bear to
overread:

```fish
echo foo\nbar | begin
    read -l foo
    read -l bar
end
```

needs to have the first read read `foo` and the second read `bar`. So
here we can only read one byte at a time.

However, when we are directly redirected:

```fish
echo foo | read foo
```

we can, because the data is only for us anyway. The stream will be
closed after, so anything not read just goes away. Nobody else is
there to read.

This dramatically speeds up `read` of long lines through a pipe. How
much depends on the length of the line.

With lines of 5000 characters it's about 15x, with lines of 50
characters about 2x, lines of 5 characters about 1.07x.

See #8542.
2022-03-13 11:22:48 +01:00
Fabian Homborg
a0e639e1fa read: Remove super old TODO
This was never a problem. If we need it, it's in the git log
2022-03-13 11:22:48 +01:00
Fabian Homborg
585d1de653
Merge branch 'master' into string-preserve-missing-newline 2022-03-13 11:21:53 +01:00
Fabian Homborg
cf85bf9be3 Let function-scoped variables be queried
This uses the same logic we use to create the variables to find them -
go through the scopes, the topmost local scope *is* function-scope.

Fixes #8684
2022-03-10 18:28:50 +01:00
Fabian Homborg
c1900ed41c Disable history race test on Github Actions
Same as ever: Flaky test, makes reviews more annoying. It should be
fixed, but until that happens it's better not to have it fail in
unrelated PRs.
2022-03-05 18:36:26 +01:00
Fabian Homborg
f284cdce5b Make byte/unicode escapes with no digits a tokenizer error
This is the simple fix - if we have no valid digit, we have nothing to
return. So instead of returning a NULL, we return an error.

This is already the case for invalid octal escapes (like `\777`).

Fixes #8545
2022-03-03 12:18:13 +01:00
Fabian Homborg
6fcb6f77be Revert changes to time formatting
This reverts commits:

2d9e51b43e
d1d9f147ec
346ce8081b

The box drawing because it's entangled with the rest and we don't
currently use this anywhere I know of. Nor was it gated on terminfo,
so it could have broken things, for subjectively little gain.

Fixes #8727.
2022-02-21 22:48:43 +01:00
Johannes Altmanninger
2f5edfd617 Call pthread_attr_destroy even if pthread_create failed
As suggested in
63bfab9975 (commitcomment-66542462)

Also, check for errors.
2022-02-19 14:15:22 +01:00
Fabian Homborg
34f4be1149 Update widecharwidth
This updates widechar_width.h to one generated from
15e782aa3df9dfef436516f66f745a90b421329.

The change here is a rationalization of doublewide vs widened-in-9.

Many emoji have been moved to widened-in-9 because we now use the
correct version (this uses the *emoji* version, and emoji version 3.0
corresponds to Unicode 9).
2022-02-14 22:19:28 +01:00
ridiculousfish
133e359d70 Add a test that stdin is always handed-off as blocking
No functional change here, just closing a gap in our coverage.
2022-02-12 11:41:03 -08:00
Johannes Altmanninger
210e7a9cc9 Correct error on when complete -C is used without argument
The new --escape option means that -C is not necessarily the last option;
We have this scenario where we produce a bogus error

    $ fish -c 'complete -C --escape'
    complete: --escape: option requires an argument

--escape doesn't take arguments, so let the error message say -C.
2022-02-09 08:57:05 +01:00
Nadav Zingerman
9e0f74eb6c Add --escape option to complete -C
An example use case is an external completion pager:

    bind \cg "commandline -rt (complete -C --escape|fzf|cut -d\t -f1)\ "

Fixes #3469
2022-02-09 08:34:03 +01:00
Aaron Gyes
d1d9f147ec Update tests for time output. 2022-02-08 16:57:01 -08:00
Aaron Gyes
63bfab9975 Start threads detached. 2022-02-08 16:44:20 -08:00
Aaron Gyes
e0c8e1cd70 iothread: Remove most of a comment
Remove the narrative here that can set a reader up for confusion.

018e51c935
2022-02-08 16:44:20 -08:00
Aaron Gyes
346ce8081b time: use box drawing characterts for the separator
This spruces up output slightly to render a solid
line instead of a bunch of dashes for the horizontal
rule shown in time output.
2022-02-08 16:44:20 -08:00
Aaron Gyes
2d9e51b43e builtin time: Use more familiar time unit abbreviations
Use ms, μs as opposed to "millis", etc.
2022-02-08 16:44:20 -08:00
Shay Aviv
2ef12af60e Fix comment parsing inside command substitutions and brackets 2022-02-08 16:20:31 +01:00
ridiculousfish
627033f447 fish_wcswidth_visible to use int instead of size_t
Credit to lilyball for spotting this.
2022-02-07 22:17:47 -08:00
Johannes Altmanninger
8b9f7dbf45 Commit transient edit when history search ends
A history search ends when you move the cursor, but the commandline inserted by
history search is still marked as transient. This means that the next history
search will clear the transient commandline. This means we are dropping an undo
point, for example:

	echo 11
	echo 1
	echo autosuggestion
	echo^P # commandline is "echo 1"
	^A # stop history search
	^P # commandline is "echo 11"
	^Z # Bug: commandline goes back to "echo", but it should be "echo 1"

In the worst case, we are switching from line-search to token-search (see
the attached test case).  Clearing the transient edit means the line is gone
and only the token is left on the command line.
2022-02-07 17:38:11 +01:00
ridiculousfish
7f31acbf9b Prevent fish_title output from triggering a bel
fish outputs the result of fish_title inside an escape sequence, which
happens to be terminated by \a (BEL). It may happen that the initial
output is interrupted; fish then emits the closing BEL and that makes an
annoying beep. Output the fish_title all at once, even if a signal is
delivered (so we don't get "stuck inside" the sequence).

This is related to #8628 in that it's a "torn escape sequence."
2022-02-05 13:18:37 -08:00
ridiculousfish
1bdd629326 Prevent signals from tearing multi-char bindings
Say the user has a multi-char binding (typically an escape sequence), and a
signal arrives partway through the binding. The signal has an event handler
which enques some readline event, for example, `repaint`. Prior to this
change, the readline event would cause the multi-char binding to fail. This
would cause bits of the escape sequence to be printed to the screen.

Fix this by noticing when a sequence was "interrupted" by a non-char event,
and then rotating a sequence of such interruptions to the front of the
queue.

Fixes #8628
2022-02-05 13:18:36 -08:00
ridiculousfish
43e5004b6e readch_timed to block signals
readch_timed is called after reading the escape character \x1b. The escape
char may be a standalone key press or part of an escape sequence; fish
waits for a little bit (per the fish_escape_delay_ms variable) to see if
something else arrives, before treating it as standalone escape-key press.

It may happen that a signal is delivered while fish waits. Prior to this
change we would treat this signal as a "nothing was read" event, causing
escape to be wrongly treated as standalone.

Avoid this by using pselect() with a full signal mask, to ensure this call
completes.
2022-02-05 13:17:45 -08:00
ridiculousfish
8a4ed096ed Stop passing check_exit events to match key bindings
check_exit events are generated to give the reader a chance to respond to
commands, or otherwise to return control to the reader loop. Prior to this
change they were being passed to match key bindings. This is useless since
no key binding can match a check_exit event. FLOG noisily complains about
unmatched events. So just don't pass these to mapping_execute.
2022-02-05 13:17:45 -08:00
Mahmoud Al-Qudsi
d059c3b5b2 src/reader.cpp: Remove needless use of macro 2022-01-31 16:28:21 -06:00
Mahmoud Al-Qudsi
05cdacc8d4 Prevent queued-up flash() calls from blocking input
Closes #8610.
2022-01-31 16:25:42 -06:00
Aaron Gyes
c6166f8ced Shorten more.
More vain attempts to get a bare <TAB> showing as 2 columns in the
pager. This now happens in a 101 column terminal.
2022-01-27 16:21:22 -08:00
ridiculousfish
2369eb61e2 Try to fix the launchpad build
A recent change used a C++14 overload of std::string::assign which
defaulted the last parameter. Explicitly pass npos to make it C++11
friendly again.
2022-01-26 22:29:06 -08:00
Johannes Altmanninger
c48b02e418 fixup! Fix commandline state for custom completions with variable overrides
The previous commit added transient commandlines when completing
commands with variable overrides. Transient commandlines require a
parser, but perform_one_completion_cd_test() asked for completions
without giving a parser, which is only okay when asking for
autosuggestions (like perform_one_autosuggestion_cd_test() does).
Let's pass a parser to fix the test.
2022-01-27 04:19:30 +01:00
Johannes Altmanninger
df3b0bd89f Fix commandline state for custom completions with variable overrides
Today, a command like "var=val status " has custom completions
because we skip over the var=val variable override when detecting
the command token.
However if the custom completions read the commandline state (via
"commandline -opc") they do see they variable override, which breaks
them, most likely. Try "a=b git ".

For completions of wrapped commands, we already set a transient
commandline. Do the same for commands with  leading variable overrides;
then git completions for "a=b git " will think the commandline is
"git ".
2022-01-27 03:51:32 +01:00
Aaron Gyes
275601665f Shorten more commands
We're at 2 columns @ 115-wide terminal.
2022-01-22 21:21:21 -08:00
Aaron Gyes
81c46183fd breakpoint: shorter 2022-01-22 21:18:24 -08:00
Aaron Gyes
1262469aea Shorten two more command's descriptions
Two columns at 119 width.
2022-01-22 21:04:26 -08:00
Aaron Gyes
cd47411bbb Shorten breakpoint description 2022-01-22 20:52:29 -08:00
Fabian Homborg
f40c054a6a Replace hangul hack with widecharwidth version
This updates widecharwidth to
6d3d55b419db93934517cb568d1a3d95909b4c7b, which includes the same
Hangul Jamo check in a separate table.

This should slightly speed up most width calculation because we no
longer need to do it for most chars, including the overwhelmingly
common ascii ones.

Also the range is increased and should better match reality.
2022-01-21 17:10:52 +01:00
ridiculousfish
1f8ce5ff6c Stop ignoring initial command in read -c
`read` allows specifying the initial command line text. This was
text got accidentally ignored starting in a32248277f. Fix this
regression and add a test.

Fixes #8633
2022-01-16 13:36:48 -08:00
Juho Eerola
a9ad49e81b
Enforce order of functions array statically 2022-01-16 23:04:55 +02:00
Juho Eerola
c7abd09aea
Make min and max functions variadic 2022-01-16 23:01:55 +02:00
Juho Eerola
3badcfe58d
Add support for variadic functions
Variadic functions require at least one argument.
2022-01-16 22:42:21 +02:00
Juho Eerola
074537a8ac
Switch to direct evaluation
Both constant values and functions are represented as `te_fun_t`.
This struct defines `operator()` which evaluates the function with the
given arguments.
2022-01-15 14:46:05 +02:00
Fabian Homborg
0781473564 argparse: Jump to the next option after an unknown one
Previously, when we got an unknown option with --ignore-unknown, we
would increment woptind but still try to read the same contents.

This means in e.g.

```
argparse -i h -- -ooo -h
```

The `-h` would also be skipped as an option, because after the first
`-o` getopt reads the other two `-o` and skips that many options.

This could be handled more extensively in wgetopt, but the simpler fix
is to just skip to the next argv entry once we have an unknown option
- there's nothing more we can do with it anyway!

Additionally, document this and clearly explain that we currently
don't transform the option.

Fixes #8637
2022-01-15 12:17:43 +01:00
Juho Eerola
73bc453eaf
Make parser functions members of state struct
Also some cleanup:
- removed unnecessary `typedef`s and `using`s
- removed unused TE_FUNCTION3
- separate types for function based on arity
2022-01-13 20:56:15 +02:00
Fabian Homborg
1eb58f9054 Tests: Merge "notifiers" and "universal" groups
The sole notifiers test recreated the uvar directory, so if it was
called while the universal test was running it would stop it from
completing correctly.

This happened reasonably often on Ubuntu with tsan on Github Actions.
2022-01-09 23:26:33 +01:00
David Adam
b49dd30179 builtins/block: correct an errant comment 2022-01-09 22:00:58 +08:00
ridiculousfish
57a9fe492e Allow using poll() to check for readability
Cygwin tests are failing because cygwin has a low limit of only 64 fds in
select(). Extend select_wrapper_t to also support using poll(), according to
a FISH_USE_POLL new define. All systems now use poll() except for Mac.

Rename select_wrapper_t to fd_readable_set_t since now it may not wrap
select().

This allows the deep-cmdsub.fish test to pass on Cygwin.
2022-01-02 16:36:33 -08:00
ridiculousfish
a5976f5b0d Disable certain autosuggestion tests on Cygwin
Cygwin disallows backslashes in filenames, so these tests cannot
possibly succeed there. Just disable them.
2021-12-30 11:44:14 -08:00
ridiculousfish
ab7a07e97c Disable a string length test on Cygwin
This test was failing because it assumed wchar_t is 32 bit.
No functional change here.
2021-12-30 11:36:06 -08:00
Fabian Homborg
940f52d717 math: Report missing operators between the tokens
This affects the caret position. In an expression like

123 456

we previously reported:

123 456
      ^ missing operator

Now we do:

123 456
   ^ missing operator

We do it on the first space, which should be acceptable.

(no need for a changelog entry, we have already ignored #8511)
2021-12-30 13:26:44 +01:00
Fabian Homborg
2c03cfecba Shebang error: Use /path/to/fish
Otherwise this looks like `#! fish` is a valid shebang, which it is
not. We don't interpret $PATH here, and the kernel typically doesn't.
2021-12-30 13:04:47 +01:00
ridiculousfish
3feb41f78f Correct the test_expand test
This unit test was passing 0 instead of a pointer to indicate the end of
a varargs; this might fail on 64 bit, and indeed did fail on Cygwin. This
fixes the Cygwin expand test.
2021-12-30 01:18:14 -08:00
David Adam
a52305e11c postfork: further updates to error messages
Only show the shebang warning for .fish commands.

Use the phrase "interpreter directive" as the formal name for the
shebang.

Switch from windows to Windows for the operating system.
2021-12-29 22:33:24 +08:00
ridiculousfish
ef281c7c4e Remove expand_flag::skip_home_directories
This could in principle be used to prevent home directory expansion, but
no call site uses it, so just remove it. No functional change here.
2021-12-28 15:13:50 -08:00
ridiculousfish
284427a6da Revert "Fix undefined behavior in closing a moved pipe"
There is no undefined behavior in closing a moved pipe, since the
move constructor simply sets the fd to -1, which is ignored by close().
The move constructor of autoclose_fd_t is "fully specified" (like
unique_ptr).

It's good practice to eagerly close pipes which may be inherited by
child processes, since otherwise the writer may not get EPIPE correctly.
Closing the pipe explicitly makes it clear that the pipe does not stay
open across continue_job().

This reverts commit c014c23662.
2021-12-28 14:25:24 -08:00
Johannes Altmanninger
65b34a12c0 Declare that two "not" keywords cancel each other out
"not not return 34" exits with 34, not 1.  This behavior is pretty
surprising but benign. I think it's very unlikely that anyone relies
on the opposite behavior, because using two "not" decorators in one
job is weird, and code that compares not's raw exit code is rare.

The behavior doesn't match our docs, but it's not worth changing the
docs because that would confuse newcomers. Add a test to cement the
behavior and a comment to explain this is intentional.

I considered adding the comment at
parse_execution_context_t::populate_not_process where this behavior
is implemented but the field defintion seems even better, because I
expect programmers to read that first.

Closes #8377
2021-12-28 19:32:30 +01:00
Fabian Homborg
4ceed7c482 Improve error message for fish scripts without shebang
When we execute something and it doesn't have a shebang, typically we
fall back on running it with /bin/sh. For .fish scripts, we still
refuse to do this (assuming that /bin/sh won't handle .fish scripts properly).

Only the error wasn't great. So we now explicitly mention when there's
a missing shebang, and point towards the shebang line otherwise.
2021-12-28 15:30:04 +01:00
David Adam
2e6bfe5c68 fish_tests: actually test fish_wcstod
The test was running against the standard library rather than the fish
replacement.
2021-12-27 14:07:17 +08:00
Aaron Gyes
29ccc08a53 unusued find_entry member: use it
Assuming this was meant to be used when created, simplify
two other spots to make use of find_entry().
2021-12-24 19:06:00 -08:00
Fabian Homborg
77bac22741 test: Also print proper caret for too many arguments
This case is handled specially for unknown reasons and was missed in #6030.
2021-12-24 16:08:41 +01:00
Aaron Gyes
89ba9f76e2 env.cpp: unusued var_table_t table in create_export_array() 2021-12-21 04:31:54 -08:00
Aaron Gyes
365a6ee384 Use source_offset_t (uint32) in tokenizer.
Seems like size_t is unnecessarily large as well, as elsewhere
in the code we are clamping down to uint32_t / source_offset_t.

This makes tok_t more like 16 bytes. More cleanup seems desirable,
this is not very well hamrnoized across our code base.
2021-12-21 02:32:52 -08:00
Aaron Gyes
8e1173bac9 Revert "common.h: use emplace in vec_append"
This was dumb, and not intended for commit.
This reverts commit ab353ce0e4.
2021-12-21 02:08:23 -08:00
Aaron Gyes
35253900cb rearrange tok_t fields in decreasing order
We can have vectors of these, maybe it adds up.
40 bytes -> 32 bytes
2021-12-21 01:29:26 -08:00
Aaron Gyes
ab353ce0e4 common.h: use emplace in vec_append 2021-12-20 22:54:59 -08:00
Aaron Gyes
9abbcc0ba6 ast.cpp: initialization order
member 'extras_' is used to initialize 'tokens_'.
members are initialized in the order they are declared in a class
2021-12-20 22:43:58 -08:00
ridiculousfish
0d67dd19a1 Switch path_get_data_is_remote to returning a real class enum
End the tricky use of maybe_t<bool> by using a real class enum.
2021-12-18 20:48:13 -08:00
Fabian Homborg
f082b6c1bd Only act on the locale vars we care about
Instead of 7a80ad74f, which adds ifdeffery, we simply drop the
variables we don't care about. This leaves two presumably
glibc-specific variables, but drops 5 variables like LC_MONETARY, so
it's overall a win.

This reverts commit 7a80ad74f4.
2021-12-13 11:52:17 +01:00
Aaron Gyes
7a80ad74f4 Cordon off glibc locale vars just for glibc 2.2
Phew
2021-12-13 01:56:48 -08:00
Aaron Gyes
b05757ee56 Fit status feaetures in 80 columns 2021-12-13 01:24:47 -08:00
ridiculousfish
68ee2ff9f3 Bravely stop removing quotes in builtin history delete
The builtin history delete call has some code that removes a leading and
trailing quote from its arguments. This code dates back to ec34f2527a,
when the builtin was introduced.  It seems wrong and tests pass
without it. Let's bravely remove it.
2021-12-12 14:26:45 -08:00
Aaron Gyes
76eef0fea9 Fix some extra arguments for string format functions. 2021-12-12 14:06:17 -08:00
Aaron Gyes
04a4693b5b history.h:
some typedefs -> using declarations
make the documentation comments work
2021-12-12 13:36:14 -08:00
Aaron Gyes
549fae1400 ast.h: remove unused private member finished() 2021-12-12 13:05:48 -08:00
Johannes Altmanninger
8208fc4f87 Cleanup comment to match implementation
This was recently changed to return bool.
2021-12-12 18:21:35 +01:00
Aaron Gyes
f464bbebfe command -v: exit 127 if command not found
Align with the spec
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html

Fixes #8547
2021-12-11 22:15:26 -08:00
Aaron Gyes
ccf0b69c3d Apply Johannes' patch.
I goofed this up.
2021-12-11 10:49:40 -08:00
Andrey Mishchenko
fb73a4b2e2 Implement nextd-or-forward-word and prevd-or-backward-word in C++ 2021-12-11 10:19:18 +01:00
Aaron Gyes
e181d825fa fix maybe_lock_file
introduced in previous commit
2021-12-09 00:58:05 -08:00
Aaron Gyes
ce475c0b4c more int -> bool
all the things
2021-12-09 00:52:45 -08:00
Aaron Gyes
b3a4b23d9b sanity.{cpp,h}: remove, entirely unused
insane in the brain
2021-12-09 00:41:47 -08:00
Aaron Gyes
815502fa9e missed a spot in history.cpp.
path_get_data_is_remote is a bool, mostly.
2021-12-09 00:33:20 -08:00
Aaron Gyes
e65405ef52 int -> maybe_t<bool> 2021-12-09 00:29:37 -08:00
thibault
ceade1629d builtin commandline: add option to determine if pager is fully disclosed
Use the remaining_to_disclose count to determine if all completions
are shown (allows consistent behavior between short and long completion
lists).

Closes #8485
2021-12-04 22:43:39 +01:00
Johannes Altmanninger
4a575b26f5 Fix error check for repeated quoted command substitution
Commit e40eba358 (Treat text following quoted command substitution
as quoted) made parse_util_locate_cmdsubst_range() aware of quoted
command substitutions, by skipping surrounding text via quote_end().

However, it was not quite right. We fail to properly parse
two consecutive command substitutions in the same string,
because we don't maintain the quoting context across calls to
parse_util_locate_cmdsubst_range().  Let's track that bit in a
parameter. This allows us to get rid of the quote_end() hack.

Also apply this to the other place where we call
parse_util_locate_cmdsubst_range() in a loop (highlighting).

Fixes #8500
2021-12-04 16:56:07 +01:00
Johannes Altmanninger
c706b1d6cb Reword confusing comments about quoted cmdsub tokenization 2021-12-04 16:52:13 +01:00
Johannes Altmanninger
b5739ddacf Report sub-token error locations again
This fixes a regression about where we report errors:

	echo error(here
	old: ^
	   fixed: ^

Commit 0c22f67bd (Remove the old parser bits, 2020-07-02) removed
uses of "error_offset_within_token" so we always report errors at
token start. Add it back, hopefully restoring the 3.1.2 behavior.

Note that for cases like

	echo "$("

we report "unbalanced quotes" because we treat the $( as double
quote.  Giving a better error seems hard because of the ambguity -
we don't know if quote is meant to be inside or outside the command
substitution.
2021-12-04 16:52:13 +01:00
Fabian Homborg
3700247b55 Use the full path for noshebang'd scripts
If you make a script called `foo` somewhere in $PATH, and did not give
it a shebang, this would end up calling

    sh foo

instead of

    sh /usr/bin/foo

which might not match up.

Especially if the path is e.g. `--version` or `-` that would end up
being misinterpreted *by sh*.

So instead we simply pass the actual_cmd to sh, because we need it
anyway to get it to fail to execute before.
2021-12-02 21:10:57 +01:00
Aaron Gyes
9b9e2f9f87 timer.cpp: fix format specifiers and type confusion
I think the auto-all-the-things here was a making this a little
hard to follow, so replace these things that will be used in printf
with what they really are. And change the * lengths to ints.

should clear up the alerts.
2021-12-02 05:33:21 -08:00
Johannes Altmanninger
0cd3ed4b84 Fix completion pager rendering when there are lines after cursor
When the completion pager fills up all lines of the screen, we subtract
from the pager size the number of lines occupied by the prompt +
command line buffer (typically 1), so the command line is always
visible.  However, we only subtract the number of lines *before* the
cursor, so on some multiline commandlines we draw a pager that is
too large for our screen, clobbering the commandline rendering.
Fix this by counting all lines.

Fixes #8509
Possibly fixes #8405
2021-12-02 04:58:46 +01:00
Johannes Altmanninger
667bedad3d Fix stale comment referencing s_write
s_write is no more since 887867201 (Switch screen.h free functions
to member functions on screen_t, 2021-09-21).
2021-12-02 04:58:46 +01:00
Fabian Homborg
fbac70ab38 math: For two adjacent numbers, complain about missing operator
Simply a nicer error message.
2021-12-01 16:56:18 +01:00
Fabian Homborg
24cdb896d3 Readd braces for single-line if
This is misleading, especially because it's in a section of code where
the other branches are using braces.
2021-12-01 16:47:00 +01:00
Aaron Gyes
de0cbd2984 tinyexpr: report errors for extra args in parens correctly.
Usages like `math (1 1)` should report too many arguments,
same as `math 1 1`. Check for these cases and add tests.

Fixes #8511
2021-12-01 04:49:50 -08:00
Aaron Gyes
abf119918f fkr: do not do should_exit() thing for continuous mode.
Fixes #8510.
2021-12-01 02:15:58 -08:00
Fabian Homborg
a07187f46f Return proper exec error also for relative shebangs
As seen in
https://stackoverflow.com/questions/70139844/how-to-execute-custom-fish-scripts-in-custom-path-folder,
making a shebang like

   #!usr/bin/fish

won't work, and will error with the default "file does not exist"
error *pointing to the file, not the interpreter*.

Detect that interpreter properly.

We might want to make this an even more specific error, but now it
says

```
exec: Failed to execute process '/home/alfa/.local/bin/borken.fish': The file specified the interpreter 'usr/bin/fish', which is not an executable command.
```

Which is okay.
2021-11-28 14:19:01 +01:00
ridiculousfish
54a844b08e Clean up wildcard_has
wildcard_has was a "conservative" function which would sometimes falsely
report wildcards. Make it exact and add some tests.
2021-11-27 12:48:04 -08:00
Johannes Altmanninger
745129e825 builtin string: don't print final newline if it's missing from stdin
A command like "printf nonewline | sed s/x/y/" does not print a
concluding newline, whereas "printf nnl | string replace x y" does.
This is an edge case -- usually the user input does have a newline at
the end -- but it seems still better for this command to just forward
the user's data.

Teach most string subcommands to check if stdin is missing the trailing
newline, and stop adding one in that case.
This does not apply when input is read from commandline arguments.

* Most subcommands stop adding the final newline, because they don't
  really care about newlines, so besides their normal processing,
  they just want to preserve user input. They are:
  * string collect
  * string escape/unescape
  * string join¹
  * string lower/upper
  * string pad
  * string replace
  * string repeat
  * string sub
  * string trim

* string match keeps adding the newline, following "grep". Additionally,
  for string match --regex, it's important to output capture groups
  separated by newlines, resulting in multiple output lines for an
  input line. So it is not obvious where to leave out the newline.

* string split/split0 keep adding the newline for the same reason --
  they are meant to output multiple elements for a single input line.

¹) string join0 is not changed because it already printed a trailing
   zero byte instead of the trailing newline. This is consistent
   with other tools like "find -print0".

Closes #3847
2021-11-27 19:11:24 +01:00
Collin Styles
4a3e55f69c Don't escape tildes that come from custom completions
A completion entry like «complete -a '\\~'» results in completions
that insert \~ into the command line.  However we usually want to
insert ~, but there is no way to do that.

There are a couple of longstanding issues about completion escaping
[1].  Until we fix those in a general way, fix the common case by
never escaping tildes when applying custom completions to the command
line. This is a hack but will probably work out fine because we don't
expect literal tildes in arguments.

The tilde is included in completions for cdh, or
__fish_complete_suffix, which simply forwards results from "complete
-C". Revert a workaround to cdh that expanded ~, because we can now
render that without escaping.

Closes #4570, #8441

[ja: tweak patch and commit message]

[1]: https://github.com/fish-shell/fish-shell/pull/8441#discussion_r748803338
2021-11-27 17:05:46 +01:00
Johannes Altmanninger
d1683958cf Expand tildes and variables in command for custom completions
A «complete -C '~/fish-shell/build/fish '» fails to load custom
completions because we do not expand the ~, so
complete_param_for_command() thinks that this command is invalid.
Expand command tokens before loading custom completions.

Fixes #8442
2021-11-27 10:14:13 +01:00
Fabian Homborg
47e45704b1
Allow set --query to check for pathvarness (#8494)
Currently,

    set -q --unpath PATH

simply ignores the "--unpath" bit (and same for "--path").

This changes it, so just like exportedness you can check pathness.
2021-11-26 18:29:10 +01:00
Fabian Homborg
f2fd30df03
Make fish_key_reader's output simpler (#8467)
* fish_key_reader: Simplify default output

It now only prints the bind statement. Timing information and such is
relegated to a separate "verbose" mode.

* Adjust fish_key_reader docs

* Adjust tests
2021-11-22 17:22:22 +01:00
Fabian Homborg
ef33ec2f62 Keep narrow directory name around some more
What this did was

1. Find directory
2. Turn name into wcstring and return it
3. Turn name back into string for some operations

Instead, let's unglue the wcstringing from this, return the narrow
string and then widen it when we need.
2021-11-20 20:10:18 +01:00
Fabian Homborg
91ce41a2b4 Make script file error a bit more obvious
This didn't even mention that it was a script file, it was just

filename: File not found

Which would be rather confusing if e.g. someone forgot that
`--profile` requires an argument.
2021-11-20 17:44:06 +01:00
Fabian Homborg
707f042fc4 printf: Explain what couldn't be converted 2021-11-20 17:44:05 +01:00
Fabian Homborg
8391f94081 Improve error for redirections to invalid paths
This finds the first broken component, to help people figure out where
they misspelt something.

E.g.

```
echo foo >/usr/lob/systemd/system/machines.target.wants/var-lib-machines.mount
```

will now show:

```
warning: Path '/usr/lob' does not exist
```

which would help with seeing that it should be "/usr/lib".
2021-11-20 17:44:05 +01:00
Fabian Homborg
c82ce5132b Rename "rotten" to "broken" symlinks in completions as well
Now consistent again with cd - eae9ee7f35.
2021-11-20 17:44:05 +01:00
Johannes Altmanninger
4c598b504f Follow include-what-you-use for our custom iswdigit()
Commit fe63c8ad3 (Shadow/override iswdigit instead of changing it at
individual call sites, 2021-10-04) added our own implementation of
iswdigit() to common.h. The "include-what-you-use" rule means that
files that use iswdigit() should now include common.h. Do that.
2021-11-18 15:06:12 +01:00
Johannes Altmanninger
9d38553384 fish_tests: format elapsed seconds with two decimal places, that's enough 2021-11-18 15:06:12 +01:00
ridiculousfish
a47f498516 Correct syntax highlighting for variables spanning multiple lines
A variable may be broken across multiple lines with a backslash, for
example:

     > echo $FISH_\
       VERSION

Teach syntax highlighting about this line breaking. Fixes #8444
2021-11-15 23:04:45 -08:00
ridiculousfish
15a3caf244 Refactor env_universal_callbacks
Reduce some allocations and simplify how events are emitted.
2021-11-14 17:39:52 -08:00
ridiculousfish
485a945004 Clean up check_global_scope_exists
check_global_scope_exists is meant to warn if the user creates a
universal variable shadowing a global. In practice it always returned
success (though it may print an error). Remove its return value and
clean up the call sites. Also rename it to
`warn_if_uvar_shadows_global`. No functional change in this commit.
2021-11-14 13:07:02 -08:00
Johannes Altmanninger
64dddfc6ce Only expand abbreviations if cursor is directly at command token
On a commandline like "ls arg" (cursor at end) we do not expand
abbrevations on enter.  OTOH, on "ls " we do expand. This can be
frustrating because it means that the two obvious ways to suppress
abbrevation expansion (C-Space or post-expansion C-Z) cannot be used to
suppress expansion of a command without arguments.  (One workaround is
"ls #".)

Only expand-on-execute if the cursor is at the command name (no space
in between).

This is a strict improvement for realistic scenarios, because if there
is a space, the user has already expressed the intent to not expand
the abbreviation. (I hope no one is using recursive abbreviations.)

Closes #8423
2021-11-14 11:52:10 +01:00
Johannes Altmanninger
a32fa8fac9 Read $fish_autosuggestion_enabled on interactive startup
This allows to disable autosuggestions in config or with

	fish -C 'set -g fish_autosuggestion_enabled 0'

instead of only in existing interactive sessions.

I'm not sure if passing the env var table is actually necessary here,
since we already have a reader.
2021-11-14 11:52:10 +01:00
Fabian Homborg
aa470e12b2 Defer escape bindings as well
This allows rebinding escape in the user list without breaking e.g.
arrow keys (which send escape and then `[A` and similar, so escape is
a prefix of them).

Fixes #8428.
2021-11-10 20:40:21 +01:00
Aaron Gyes
197f93e784 ulimit.cpp: doesn't need to #include io.h 2021-11-09 17:51:58 -08:00
Aaron Gyes
eb990c07c8 Let's make src/ easier to grok, move builins to src/builtins
+ No functional change here, just renames and #include changes.
+ CMake can't have slashes in the target names. I'm suspciious of
  that weird machinery for test, but I made it work.
+ A couple of builtins did not include their own headers, that
  is no longer the case.
2021-11-09 17:39:10 -08:00
Fabian Homborg
66566c1650 ast: Stop dropping down to wchar_t needlessly
Very slight performance increase (1% when parsing *all .fish scripts
in fish-shell*), but this removes a useless variable and some
.c_str()inging.

Theoretically it should also remove some wcslen() calls, but those
seem to be optimized out?
2021-11-08 21:24:00 +01:00
ridiculousfish
389b75fe42 Restyle codebase with clang-format 2021-11-08 12:21:11 -08:00
ridiculousfish
25f47729e7 math: Correct printing of negative and large values in octal and hex
This fixes printing octal and hex values that are negative or larger
than UINT_MAX.

Negative values get a leading -, like:

    > math --base hex -10
    -0xa

Fixes #8417.
2021-11-07 16:43:30 -08:00
Aaron Gyes
3de63f7e21 fallback.h: this header guard was broken
... not that we had things in here that I think it would
have really affected, I hope.
2021-11-06 23:09:20 -07:00
Aaron Gyes
40a781a89f Use correct types for format specifers
(or use the correct specifiers for the type if we can.)

These are hard to track down because we can't get compile-time
warnings for the wprintf family of in libc like is possible for
the narrow versions.
2021-11-06 17:15:32 -07:00
Aaron Gyes
45de6d167d Remove file size for executables in the pager, and call them commands 2021-11-04 06:17:47 -07:00
Aaron Gyes
40dcfaa90a Completions: do not show directory file size.
Try to shorten these, too.
2021-11-04 04:05:12 -07:00
Aaron Gyes
72c04d11ad builtin.cpp: show a short options' - for BUILTIN_ERR_MISSING 2021-11-03 22:54:55 -07:00
Aaron Gyes
710639f5d6 builtins: work on error messages
- Introduce BUILTIN_ERR_COMBO2_EXCLUSIVE
- Distill generally more terse, unambiguous error descriptions.
  Remember English is not everyone's language.
- Do not capitalize sentence fragments
- Use the modality where problem input is in a %s: prefix, then
  is explained.
- Do not address the user (the "You cannot do ..." kraderism)
- Spell out 'arguments' rather than 'args' for consistency
- Mention 'function' as a scope
2021-11-03 22:54:55 -07:00
ridiculousfish
1b6ef6670f Optimize exit event generation
Watching for exit events is rare, so check if we have any exit events
before actually emitting them. This saves about 2% of time in
external_cmds benchmark.
2021-11-03 17:38:30 -07:00
ridiculousfish
7bd9f1bb23 Rename job_t::notified to job_t::notified_of_stop
This makes it clear that the flag is only used to report whether a job
is stopped.

Also remove process_t::marked_exit_event as we no longer need it.
2021-11-03 15:40:26 -07:00
ridiculousfish
c4fb857dac Refactor process_clean_after_marking
This untangles some of the complicated logic and loops around posting
job exit events, and invoking the fish_job_summary function. No
functional change here (hopefully).
2021-11-03 15:40:18 -07:00
ridiculousfish
00a1df3811 Bravely do not report completed jobs as stopped
Prior to this change, job_t::is_stopped() returned true if there were
zero running processes in the job. This meant that completed jobs were
reported as stopped. Stop doing this, it's a footgun.
2021-11-03 12:23:25 -07:00
ridiculousfish
9b1e04dba2 Use a real flag to mark that a process has generated an exit event
Exited processes generate event_t::process_exit if they exit with a
nonzero status. Prior to this change, to avoid sending duplicate events,
we would clear the status. This is ugly since we're lying about the
process exit status. Use a real flag to prevent sending duplicate
notifications.
2021-11-03 10:28:00 -07:00
Fabian Homborg
86b8cc2097 Allow turning off autosuggestions
This adds a variable, $fish_autosuggestion_enabled.

When set to 0, it will turn off autosuggestions/highlighting.
Setting it to anything else will enable it (which also
means this remains enabled by default).
2021-11-02 21:40:56 +01:00
ridiculousfish
d81f817f70 Correct a dropped lock
When iterating the event handler list, we inadverently dropped a lock
because of how range-based for loops work. Hold the lock outside of the
loop.
2021-11-02 12:46:32 -07:00
ridiculousfish
73ea7d257e Remove reader_set_buffer
It was unused.
2021-11-01 11:20:28 -07:00
Johannes Altmanninger
c94dec5d0e Fix assertion error trying to highlight cmdsubs inside unbalanced quotes
I initially put this logic + assertion in another function, where we
always get balanced quotes. Not for highlighting.
2021-10-31 14:28:54 +01:00
Johannes Altmanninger
db377385f6 Fix copy paste error 2021-10-31 14:28:54 +01:00
Aaron Gyes
8ab05a4036 mark some functions static 2021-10-31 03:51:38 -07:00
Aaron Gyes
70186f2abb don't use size_t for a loop counter that is decremented 2021-10-31 03:51:38 -07:00
Johannes Altmanninger
e40eba3585 Treat text following quoted command substitution as quoted
Commit ec3d3a481 (Support "$(cmd)" command substitution without line
splitting, 2021-07-02) started treating an input string like
"a$()b" as if it were "a"$()"b". Yet, we do not actually insert the
virtual quotes. Instead we just adapted the definition of when quotes
are closed - hence the changes to quote_end().

parse_util_locate_cmdsubst_range() is aware
of the changes to quote_end() but some of its
callers like parse_util_detect_errors_in_argument() and
highlighter_t::color_as_argument() are not.  They split strings at
command substitution boundaries without handling the special quoting
rules. (Only the expansion logic did it right.)

Fix this by handling the special quoting rules inside
parse_util_locate_cmdsubst_range(). This is a bit hacky since it
makes it harder for callers to process some substrings in between
command substitutions, but that's okay because current callers only
care about what's inside the command substitutions.

Fixes #8394
2021-10-30 18:02:10 +02:00
Fabian Homborg
5c6c405b9e Cache if tracing is enabled
Like the comment said: That var lookup was kind of expensive.

So we simply use variable dispatch like we do for countless other things.
2021-10-28 19:39:30 +02:00
ridiculousfish
e89bd95d58 Mild refactoring of wait handles 2021-10-28 10:37:43 -07:00
Fabian Homborg
357f49c781 Revert "Use unescape_string_in_place"
This reverts commit 2ef8a9c1af.

This doesn't work everywhere, not sure why.
2021-10-28 18:09:25 +02:00
Fabian Homborg
292c9d5381 Force uselocale if glibc is in use
For some reason on a current glibc 2.33, the configure check fails.
The man page says we'd have to define XOPEN_SOURCE>=700, but I don't
want to do that since it changes a bunch of other things, and it
didn't work in my tests.

So we just force it, since we know it works (since glibc 2.3).

This is a performance difference of ~20% for printf, so it's a
reasonably big deal.
2021-10-28 17:54:35 +02:00
Fabian Homborg
2ef8a9c1af Use unescape_string_in_place
We already get a copy, so we might as well just use it.
2021-10-28 17:32:52 +02:00
Fabian Homborg
31d6abb177 Don't fire variable set event before entering a for-loop
Since #4376, for-loops would set the loop variable outside, so it
stays valid.

They did this by doing the equivalent of

```fish
set -l foo $foo
for foo in 1 2 3
```

And that first imaginary `set -l` would also fire a set-event.

Since there's no use for it and the variable isn't actually set, we
remove it.

Fixes #8384.
2021-10-28 16:32:58 +02:00
Aaron Gyes
575decc35b also not a thread id: nullptr 2021-10-28 02:14:29 -07:00
Aaron Gyes
362319d25f Cleanup on aisle haphazard-everywhere 2021-10-28 01:47:49 -07:00
ridiculousfish
3848a68e5c Fix a misspeeling 2021-10-27 14:16:32 -07:00
Fabian Homborg
6941c94c4a
cd: Set var via the string
This was meant to trigger the wcstring_list_t overload by constructing one with `{norm_dir}`. Older gcc can't figure out what to do.

So instead we use the wcstring overload for now.
2021-10-27 10:20:14 +02:00
Fabian Homborg
f1fe6a5e94 Update widechar_width to Unicode 14
Generated with f438dbf6c4648ec94e154d2e475a3052370ea218
2021-10-26 18:26:25 +02:00
Fabian Homborg
76f3564e2a Remove now unused out_events parameter 2021-10-26 17:38:40 +02:00
Fabian Homborg
0c3c3eaa99 Reuse the variable event for for-loops
This used to construct a vector, which was then passed down and filled
with a new event_t each go around the loop. That's useless - we fire
one event here, and it's simply the variable event.

This reduces the overhead of a for-loop by ~10%:

```fish
for i in (seq 100000)
    true
end
```

runs in about 90% of the time now.
2021-10-26 17:38:35 +02:00
Fabian Homborg
452675d458 Use set_vars_and_fire where possible
This just did the same thing manually.
2021-10-26 17:33:36 +02:00
Fabian Homborg
da201ee8ac Let parser::set_var_and_fire fire the event directly
The vector here gives us *nothing*
2021-10-26 17:33:27 +02:00
Fabian Homborg
d9f094db1a Check if the for variable is invalid before trying to set it 2021-10-26 16:59:03 +02:00
ridiculousfish
e84dad5432 Rationalize null handling in disown_job
disown_job had some extraneous null checks that could not happen in
practice. Simplify this code.
2021-10-25 16:13:00 -07:00
ridiculousfish
ec244c3975 Add tests for dynamically invoked break and continue 2021-10-25 12:43:30 -07:00
ridiculousfish
cb79548c49 Revert "break/continue: Stop checking if it's in a loop again"
This reverts commit 61cd05efb0.

It is true that we detect break and continue errors statically, but they can
still be invoked dynamically, example:

    set sneaky break
    $sneaky # dynamically breaks from the loop

or just `eval break`.

A followup commit will add tests for this.
2021-10-25 12:42:53 -07:00
Fabian Homborg
61cd05efb0 break/continue: Stop checking if it's in a loop again
This is already checked in the parse_util_detect_errors (and might
actually be done in the ast - that's where we check "end")
2021-10-25 18:57:10 +02:00
Fabian Homborg
18bb5f1f7e builtin_count: Remove superfluous L'' prefix
(not sure if this broke anything anywhere, but since we're comparing
an actual char* we should use '' without the L)
2021-10-25 18:40:43 +02:00
ridiculousfish
a6a1879481 Remove reader_get_history
It was unused.
2021-10-24 14:17:33 -07:00
Aaron Gyes
a7e62a538e Revert "Swap file size and file type description position in pager"
This reverts commit d8722a3ddf.

I underestimated the value of having the file sizes easier to
eyeball and compair. Back to the drawing board.
2021-10-23 22:17:09 -07:00
Aaron Gyes
d8722a3ddf Swap file size and file type description position in pager
File sizes are are always of variable length, while we there
are just a few different typrs of files. Since we right align,
this makes things look more lined up.

…ocal/bin/afsctool                (Executable, 74.0kB)
…ocal/bin/clang-format        (Executable link, 1.9MB)
…ocal/bin/clone_checker             (Executable, 33kB)
…ocal/bin/cryptest.exe              (Executable, 11MB)
…ocal/bin/cscc                      (Executable, 22kB)
…ocal/bin/cscout                   (Executable, 902kB)
…ocal/bin/csmake                    (Executable, 22kB)
…ocal/bin/cswc                     (Executable, 5.7kB)
…ocal/bin/dirb                      (Executable, 90kB)
…ocal/bin/ethminer-m1              (Executable, 4.8MB)
…ocal/bin/fork                (Executable link, 206kB)

vs

…ocal/bin/afsctool                (74.0kB, Executable)
…ocal/bin/clang-format        (1.9MB, Executable link)
…ocal/bin/clone_checker             (33kB, Executable)
…ocal/bin/cryptest.exe              (11MB, Executable)
…ocal/bin/cscc                      (22kB, Executable)
…ocal/bin/cscout                   (902kB, Executable)
…ocal/bin/csmake                    (22kB, Executable)
…ocal/bin/cswc                     (5.7kB, Executable)
…ocal/bin/dirb                      (90kB, Executable)
…ocal/bin/ethminer-m1              (4.8MB, Executable)
…ocal/bin/fork                (206kB, Executable link)
…ocal/bin/fish                     (2.4MB, Executable)
2021-10-23 15:37:43 -07:00
ridiculousfish
2ed0105692 Use std::move to populate a processes's args
This could save quite a few string copies.
2021-10-23 10:35:05 -07:00
ridiculousfish
4a6d622733 Continue to refactor functions
Now that we have immutable props, we can remove a bunch of 'helper'
functions.
2021-10-23 10:12:52 -07:00
ridiculousfish
7d7b930b08 Rename function_get_properties to function_get_props
We're calling it a lot so let's make it shorter.
2021-10-23 10:12:52 -07:00
ridiculousfish
089da2314d Eliminate function_info_t
function_info_t was the "mutable bits" of a function, like its
description. But we have eliminated all of those, so we can eliminate
the class.

No functional change here.
2021-10-23 10:12:52 -07:00
ridiculousfish
1c5208cf5c Migrate a function's description into its immutable properties
No functional change here.
2021-10-23 10:12:52 -07:00
ridiculousfish
17d9ae16be Migrate the function's is_autoload field into its immutable properties
Continuing to simplify functions. No functional change here.
2021-10-23 10:12:52 -07:00
ridiculousfish
12134c19d9 Migrate the function's definition file into its immutable properties
This never changes once initialized, so we can make it immutable. No
functional change here.
2021-10-23 10:12:52 -07:00
ridiculousfish
d904cc4964 Stop passing null function properties in testing
This allows us to assert that our functions are not null.
2021-10-23 10:12:52 -07:00
ridiculousfish
59b63f3aab Use vec_append when expanding a command into arguments
This saves some lines and some allocations.
2021-10-23 10:10:26 -07:00
ridiculousfish
a634e78633 Remove an extra use of process_type_for_command
This just duplicated a previous call above.
2021-10-23 10:07:24 -07:00
Fabian Homborg
144778dc28 Complete: Fix long-form of "-r" in complete output
This was never `--requires-param`, AFAICT.
2021-10-20 21:05:17 +02:00
Fabian Homborg
b15dc2b2e8 argparse: Prevent duplicate error trailer
This was already printed by builtin_missing_argument/unknown_option.

Since we need more control (because we add our own errors in other
places), teach builtin_unknown_option to suppress the trailer, like
missing_argument already could.

And then use it.

Fixes #8368.
2021-10-19 17:43:54 +02:00
Fabian Homborg
43c58df873 Test option highlighting in command substitutions 2021-10-19 17:30:45 +02:00
Fabian Homborg
9700a75f38 fish_tests: Make a fancy caret for highlighting errors
Now looks like

```
Error: Wrong color in test at index 8-11 in text (expected 0x6, actual 0x2):
command echo abc foo &
        ^^^^
```

instead of repeating the error for every character that is wrong.
2021-10-19 17:27:35 +02:00
Fabian Homborg
711796ad13 Highlight options differently
This introduces a new variable, $fish_color_option, that can be used
to highlight options differently.

Options are tokens starting with `-`, but only up to (and including!)
the first `--`.

Fixes #8292.
2021-10-19 17:20:21 +02:00
Erik Serrander
049104e8df Adds sub-command clear-session to history command.
Issue #5791
This clears all history for the current session. Documentation and
autocompletion for the new subcommand is added.
2021-10-17 19:27:46 -07:00
ridiculousfish
f0d4fd85b1 Use __GLIBC_PREREQ instead of parsing gnu_get_libc_version
__GLIBC_PREREQ is the preferred way to conditionally enable features
based on glibc versions. Use it to avoid expensive parsing and
locale sensitivity. See #8204
2021-10-15 21:12:26 -07:00
Fabian Homborg
ec8844d834 Drop tests with resetting match start inside lookaround
This seems to be of little use

Fixes #8353
2021-10-14 18:18:51 +02:00
Fabian Homborg
c54b8dca33 Read glibc's version in a locale-independent way
We want to enable posix_spawn only for glibc >= 2.24, so we check
gnu_get_libc_version() at runtime. This returns a string with the
version number.

Because it's a version number it's spelt with a "." and never a ",",
but we interpret it as a float. This is iffy to begin with, but simple
enough. Only when the locale uses a ",", things break - it'll read it
as "2" and fail the check, which absolutely *tanks* performance on WSL1.

I'm unsure if this gives the proper runtime glibc version - it might,
whereas __GLIBC_MINOR__ and such definitely would not.

So fix the immediate problem by at least using a c locale - this is
already masked by 8dc3982408, but better
safe than sorry.
2021-10-14 17:02:50 +02:00
Fabian Homborg
7850a10c45 Stop some wcs2stringing
These are paths that barely change, narrowing them *twice* per file
load makes absolutely no sense.
2021-10-14 17:02:50 +02:00
Fabian Homborg
8dc3982408
Always use LC_NUMERIC=C internally (#8204)
In most cases, like math, we want C-semantics for floating point
numbers. In particular "." needs to be the decimal separator.

Instead, we pay the price in printf, which is currently the sole place
to output in locale-specific numbers and attempt to read them and
C-style ones.
2021-10-13 21:09:40 +02:00
Aaron Gyes
172601299f builtin _ is now a reserved keyword
Similar to `test`, `_` is so likely to at least slow down if not
break all things catastrophically that it ought not be allowed as a
function name. Fixes #8342
2021-10-11 00:27:44 -07:00
Fabian Homborg
6af3896217 wcsfilecmp: Stop actually computing the numbers
This just compares two longs as strings on the go.

We can simply

1. ignore leading zeroes - they have no influence on the value
2. compare the digits char-by-char
3. keep the comparison for the first differing digit
4. if one number is longer than the other, that is larger
5. if the numbers have the same length, the one larger in the first
differing digit is larger

This makes this comparison quite a bit faster, which makes globs in
directories with numbered files up to 20% faster.

Note that, for historical reasons, this still ignores whitespace right
after the numbers!
2021-10-07 17:57:52 +02:00
Aaron Gyes
8259bf7c7e Remove hack for Terminal.app that did not support 256 colors
We didn't support that version of macOS even before we bumped to
10.10.
2021-10-06 19:36:18 -07:00
Mahmoud Al-Qudsi
fe63c8ad32 Shadow/override iswdigit instead of changing it at individual call sites
1ab81ab90d removed one usage of iswdigit()
but there are others; more importantly, the knowledge that iswdigit() is
slow isn't preserved anywhere apart from the git history, so there's
nothing to prevent its use from creeping back into the codebase.

Another alternative is to blacklist iswdigit() (shadow it with a
function of the same name that throws a static_assert) but if we're
going to shadow it anyway, might as well make it useful.
2021-10-04 18:44:16 -05:00
Mahmoud Al-Qudsi
72e50d1ab2 Revert "wcsfilecmp: Don't use iswdigit"
This reverts commit 1ab81ab90d.
2021-10-04 18:08:18 -05:00
Aaron Gyes
f9def20180 Update ConfigureChecks, only do the mtime hack for Linux.. on Linux
- Only check for HAVE_CLOCK_GETTIME and HAVE_FUTIMENS on Linux, since
they are only used to implement a Linux-specific workaround related
to mtime precision.
- Make sure that hack is limited to Linux builds
- HAVE_SYS_SYSCTL_H was unused, but we should have been using it
- HAVE_TERMIOS_H was unused, remove it

The only functional change is that unix machines with clock_gettime
and futimens will not bother with a Linux-specific hack, and won't
waste time checking for either during cmake configuration either.
2021-10-02 17:02:53 -07:00
Fabian Homborg
1ab81ab90d wcsfilecmp: Don't use iswdigit
For some godforsaken reason it's slow on glibc

Like, actually, this manages to somehow make "echo **" 10% faster now?

The spec says this matches 0 through 9 always, so this is safe. We
also use this logic in a variety of other places already.
2021-10-01 19:14:27 +02:00
Fabian Homborg
71a0d839a7 wildcard: Use fstatat
This allows us to skip re-wcs2stringing the base_dir again and again
by simply using the fd. It's about 10% faster in my testing.

fstatat is defined by POSIX, so it should be available everywhere.
2021-10-01 19:14:27 +02:00
Aaron Gyes
2f29bb5b51 remove unused macros 2021-10-01 09:07:08 -07:00
Aaron Gyes
dcaa9c7959 fix incorrect error message for 'end --foo' 2021-10-01 04:54:02 -07:00
Aaron Gyes
55ab2f6e6d Remove some unsued macros and a template 2021-10-01 04:50:19 -07:00
Aaron Gyes
d2f47e0523 add missing header 2021-10-01 03:40:32 -07:00
Aaron Gyes
831e9082d7 enum_map stuff to enum_map.h 2021-10-01 03:39:43 -07:00
ridiculousfish
15cee66df1 Wrap even more stuff in anonymous namespaces 2021-09-30 11:33:03 -07:00
ridiculousfish
89c02cfe81 Put lots of things in anonymous namespaces
This is an attempt to help prevent ODR violations by making stuff local
to a file, instead of emitting weak symbols.
2021-09-30 11:33:03 -07:00
ridiculousfish
accba09709 Remove entry_was_evicted from LRU
This was no longer used. This allows us to remove the CRTP bits as well.
2021-09-30 11:33:03 -07:00
ridiculousfish
a6010519df Put ast_t::populator_t into an anonymous namespace
This is part of an effort to reduce the number of weak symbols, so we
can help prevent ODR errors. No functional change here.
2021-09-30 11:33:03 -07:00
Fabian Homborg
78fcbed6f2 wcsfilecmp: Skip towlower/upper if unnecessary
Also for the glob version, because this is just a performance thing.

Makes `echo **` 20% faster - 100ms to 80ms for the fish repo.

This also applies to the future `path` builtin.

Still not a speed demon, but this is a very very easy win.

Now we probably gotta do globbing all in string instead of wcs2stringing ourselves to death.
2021-09-30 18:09:58 +02:00
Fabian Homborg
4ffabd44be Don't add expansion error offset twice
Like the $status commit, this would add the offset to already existing
errors, so

```fish
(foo)
(bar)

something
```

would see the "(foo)" error, store the correct error location, then
see the "(bar)" error, and *add the offset of (bar)* to the "(foo)"
error location.

Solve this by making a new error list and appending it to the existing
ones.

There's a few other ways to solve this, including:

- Stopping after the first error (we only display the first anyway, I
think?)
- Making it so the source location has an "absolute" flag that shows
the offset has already been added (but do we ever need to add two offsets?)

I went with the simpler fix.
2021-09-30 18:09:58 +02:00
Fabian Homborg
6774a514fa Don't set error offset for $status
This would break the location of any prior errors without doing
anything of value.

E.g.

```fish
echo foo | exec grep # this exec is not allowed!

$status

somethingelse # The error might be found here!
```

Would apply the offset of `$status` to the offset of `exec`, locating
the error for `exec` somewhere after $status!
2021-09-30 18:09:58 +02:00
Aaron Gyes
fb32872f6b don't use __has_builtin
GCC doesn't have this until GCC 10. Just assume it exists, as
our compiler requirements mean it should exist.
2021-09-28 23:54:17 -07:00
Aaron Gyes
97bb53e32d Add likely() and unlikely() for our assertions
Allows the compiler to know our bespoke assert functions
are cold paths. This would normally occur somehow for real assert().
Assembly does appear it will save some branches.

Also don't worry about NDEBUG

(This doesn't matter because we rolled our own assert functions.
Thanks @zanchey.)
2021-09-28 23:39:54 -07:00
Aaron Gyes
3fd2da951e remove unused futimes check 2021-09-28 22:02:14 -07:00
ridiculousfish
0c06ca3c3f Mark parser_t::principal as const 2021-09-24 21:09:28 -07:00
Aaron Gyes
5fc9a3c31e exec.h: remove unused declaration 2021-09-24 09:30:25 -07:00
ridiculousfish
13fd3f7a76 Pass in variables directly to screen_t::update
This fixes a TODO. No functional change.
2021-09-23 10:32:55 -07:00
ridiculousfish
8878672014 Switch screen.h free functions to member functions on screen_t
Refactoring only, no functional change here.
2021-09-23 10:32:54 -07:00
ridiculousfish
26f3cee86c History variable expansion to use passed-in vars
This eliminates a call to principal_parser.
2021-09-23 10:29:34 -07:00
Fabian Homborg
45714eb29d Add function scope to read as well
Fixes #8295.
2021-09-23 17:12:37 +02:00
Fabian Homborg
8b093e2651 Remove guessed_emoji_width
Just guess anew when it's not set.

(this still uses the value of $fish_emoji_width, but clamped to 1 or 2
- we could also guess if it's an unusable value, but that's a
different issue and tbh this variable is becoming less and less useful
as time moves on and things move to the new widths by default)

Fixes #8274.
2021-09-23 15:31:05 +02:00
Fabian Homborg
bb115c847e Handle backspaces for visible width
This makes it so we treat backspaces as width -1, but never go below a
0 total width when talking about *lines*, like in screen or string
length --visible.

Fixes #8277.
2021-09-23 12:58:35 +02:00
Fabian Homborg
82a809e2db Check for tputs type via cmake
Instead of testing for ncurses and netbsd.

Fixes #8087.
2021-09-23 10:41:54 +02:00
Aaron Gyes
5a685c16c5 Fix build 2021-09-21 18:33:14 -07:00
Aaron Gyes
933bb96983 remove accidental change 2021-09-21 18:26:44 -07:00
Aaron Gyes
db72a05e89 Tighten up includes, some typedefs -> using
clangd was unable to resolve some symbols
2021-09-21 18:05:53 -07:00
Aaron Gyes
b4b84f6847 builtin.cpp: don't check exit code if not a normal exit
Fixes #8308
2021-09-21 17:49:08 -07:00
Aaron Gyes
cedf9c4d90 builtin_read.cpp: include <termios.h> not "termios.h" 2021-09-21 17:49:08 -07:00
ridiculousfish
971073d429 Disable posix_spawn on OpenBSD
OpenBSD has a posix_spawn implementation which fails to return ENOEXEC
on a shebangless script, causing us to fail the shebangless tests.
Disable posix_spawn on OpenBSD.
2021-09-18 14:08:18 -07:00
ridiculousfish
3ed8a57bc5 Don't use mmap for history files on OpenBSD
OpenBSD's mmap is famously unsychronized with file IO. In theory fsync
and msync can be used to synchronize but I was unable to get it to work.
Just don't use mmap for history on OpenBSD. This fixes the history merge
tests.
2021-09-18 14:08:08 -07:00
ridiculousfish
881b987934 Explicitly error when reading directories
FreeBSD will allow read() on arbitrary directories, causing fish to
produce a nonsense error. Use fstat() to check for directories before
reading.
2021-09-17 20:48:58 -07:00
ridiculousfish
9a2482557d get_hostname_identifier to not return empty hostnames
When getting the hostname to construct the legacy uvar path, if the
hostname is empty, we will create a path pointing at a directory. On
BSDs this path can be successfully open'd and we will produce errors
about invalid uvar files.
2021-09-17 11:18:39 -07:00
ridiculousfish
5a6b966bfe Fix acidentally quadratic wildcard_match
The "linear" wildcard_match actually contained a bug that compared two
strings on every iteration, causing this to be much slower than
necessary. Fix this.
2021-09-16 17:38:03 -07:00
ridiculousfish
d6075885ef Reduce named pipe uvar notifier poll time from 100 msec to 10 msec
To broadcast a uvar change on Linux, we write to a named pipe, wait a bit,
and then read it back. While the pipe is readable, fish will enter a "polling
mode" where it will check for uvar changes every N msec, until the pipe is no
longer readable. If the pipe stays readable for too long (5 seconds), fish
will try to drain it; this may happen if broadcasting instance of fish is
killed before it can read back its data.

In #8209 we have a case where fish is launched in the background to set a
uvar, and then immediately exits, leaving data on the pipe. This means that
we are perpetually in a polling mode until we hit that timeout. Reduce the
timeout to 1 second and the polling interval to 10 msec.

This improves #8209; it doesn't fix it fully but I think it's the best we can
do absent some other IPC mechanism.
2021-09-16 15:25:31 -07:00
Johannes Altmanninger
7f71df0905 builtin cd: recognize EPERM, as it's returned by MacOS
Now that we removed EROTTEN which had the same error code as EPERM,
we can give a less confusing error in case a user has not allowed
their terminal access to a directory.

See #8264
2021-09-17 00:43:12 +02:00
Johannes Altmanninger
eae9ee7f35 builtin cd: print error about broken symlinks
When cd is passed a broken symlink, this changes the error message from
"no such directory" to "broken symbolic link".  This scenario probably
won't happen very often since completion won't suggest broken symlinks
but it can't hurt to give a good error.

Fish used to do this until 7ac5932.  This logic used to be in
path_get_cdpath, however, that is only used for highlighting, so we
don't need error messages there. Changing cd is enough.

Reword from "rotten" to "broken" since that's what file(1) uses.
Clean-up leftovers from old "rotten" code (nomen est omen).

See #8264
2021-09-17 00:43:12 +02:00
Fabian Homborg
41d6a5b9c4 screen: If prompt ends in newline, last line width is 0
This makes us start drawing the commandline at the beginning of the
line again.

See https://github.com/kovidgoyal/kitty/issues/4032#issuecomment-920094245
2021-09-15 17:49:58 +02:00
Fabian Homborg
600dd3bd0f range-for! range-for! range-for! 2021-09-15 17:49:58 +02:00
Fabian Homborg
0e8beab7bf lru: Make parameter const-ref
This has no effect here, but it's used in the tests, where the
override is constref.
2021-09-15 17:49:58 +02:00
Fabian Homborg
4c5d586249 tinyexpr: Check for null-pointer 2021-09-15 17:49:58 +02:00
Fabian Homborg
e38de3df64 iothread: Stop casting intptr_t to void*
This works without, and clang-tidy tells me there's "optimisation
opportunities" that may be concealed.
2021-09-15 17:49:58 +02:00
ridiculousfish
29413665c5 Treat Fitzpatrick emoji modifiers as width 0
Fixes #8275
2021-09-09 18:06:59 -07:00
Fabian Homborg
4046b4cedf Remove redundant variable
normalize_path returns a wcstring, so the check can't fail.

Just pass it directly.
2021-09-09 18:41:38 +02:00
Fabian Homborg
a78d9d8e9a normalize_path: Squash leading slashes even without allow_leading
This currently changes builtin realpath with the "-s" option:

    builtin realpath -s ///tmp

previously would print "///tmp", now it prints "/tmp".

The only thing "allow_leading_double_slashes" does is allow *two*
slashes.

This is important for `path match`, to be introduced in #8265.
2021-09-09 18:41:11 +02:00
ridiculousfish
9aac663bb0 Remove operator< from builtin_data_t
It was unused.
2021-09-06 18:13:47 -07:00
Fabian Homborg
ac7e3a53c1 screen: Allow for doubled escapes in the tmux sequence
See
https://github.com/tmux/tmux/wiki/FAQ#what-is-the-passthrough-escape-sequence-and-how-do-i-use-it.
2021-08-30 18:11:34 +02:00
Fabian Homborg
c02cc110e0 screen: Support tmux escape sequences
Tmux has support for wrapping arbitrary escape sequences inside

```
\ePtmux;\e%s\e\\
```

Since this ends like the screen title escape, we just reuse that.

Characteristically, this is basically undocumented, but we already use
it in e.g. fish_vi_cursor.
2021-08-30 16:55:14 +02:00
Mahmoud Al-Qudsi
069d396ebc Merge branch 'ctest' 2021-08-29 13:03:16 -05:00
Rosen Penev
e62e6c35f7 add constexpr
This was not const before.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-29 19:14:27 +02:00
Mahmoud Al-Qudsi
c82d1980bf Prevent same history test from running multiple times at once
The default matching logic for fish_tests was prefix based, so when we
were running `history` we were also running all history tests. This
causes the test to fail for an unknown reason.
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
aaac759d9a Make test a custom target again and add top-level test targets
Even though we are using CMake's ctest for testing, we still define our
own `make test` target rather than use its default for many reasons:

 * CMake doesn't run tests in-proc or even add each tests as an
   individual node in the ninja dependency tree, instead it just bundles
   all tests into a target called `test` that always just shells out to
   `ctest`, so there are no build-related benefits to not doing that
   ourselves.
 * CMake devs insist that it is appropriate for `make test` to never
   depend on `make all`, i.e. running `make test` does not require any
   of the binaries to be built before testing.
 * The only way to have a test depend on a binary is to add a fake test
   with a name like "build_fish" that executes CMake recursively to
   build the `fish` target.
 * It is not possible to set top-level CTest options/settings such as
   CTEST_PARALLEL_LEVEL from within the CMake configuration file.
 * Circling back to the point about individual tests not being actual
   Makefile targets, CMake does not offer any way to execute a named
   test via the `make`/`ninja`/whatever interface; the only way to
   manually invoke test `foo` is to to manually run `ctest` and specify
   a regex matching `foo` as an argument, e.g. `ctest -R ^foo$`... which
   is really crazy.

With this patch, it is now possible to execute any single test by name,
by invoking the build directly, e.g. to run the `universal.fish` check:
`cmake --build build --target universal.fish` or
`ninja -C build universal.fish`. Unfortunately, this is not integrated
into the Makefile wrapper, so `make universal.fish` won't work (although
this can potentially be hacked around).
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
26092456d4 Add CMake enumeration of low-level fish_tests.cpp tests
Instead of compiling `fish_tests.cpp` dynamically with weakly-linked
symbols and asking it to print the list of all available tests, we
use a magic string `#define`'d as a no-op to allow CMake to regex search
for matching test groups. This speeds up configuration somewhat (by not
compiling anything), but more importantly, it's much less brittle and
doesn't involve and linker dark magic.

There's of course still no getting around the fact that it's really ugly.
2021-08-29 08:56:12 +02:00
Fabian Homborg
4c3cb119fc Actually return when reading file failed
Fixes #8258.
2021-08-29 08:36:54 +02:00
ridiculousfish
7a1c005b42 Switch to using timef instead of gettimeofday
This encapsulates the tricky arithmetic inside timef(), which uses
gettimeofday.
2021-08-27 16:25:33 -07:00
ridiculousfish
7d537eefbb proc_get_jiffies to accept pid directly
No need to accept the mutable proc here.
2021-08-27 13:05:27 -07:00
ridiculousfish
f577c221eb Introduce get_by_sorted_name
Given that we have several lists of things sorted by name, replace a
bunch of ad-hoc lower_bound calls with a single function.
2021-08-26 13:40:37 -07:00
Fabian Homborg
ee2d2caeaa escape_code_length: Test colors last
We have a *lot* of color sequences to try and tparm is slow (on the
whole, when you do this thousands of times).

So let's just check colors last, which makes everything else (which is
comparatively nothing) faster, while barely impacting
colors (benchmarking confirms no measurable difference).

Fixes #8253.
2021-08-26 21:01:55 +02:00
Rosen Penev
a36a26c28b clang-tidy: replace NULL with nullptr
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-25 16:10:17 -07:00
Rosen Penev
ffd5716e70 clang-tidy: replace push_back with emplace_back
clang-tidy marks these as needing emplace_back as the types to not
match.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-25 03:19:46 +02:00
Rosen Penev
a9b4127f68 clang-tidy: run through normal checks
There's a .clang-tidy file in here.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-21 21:59:05 +02:00
Fabian Homborg
70e3e0beac Also remove ephemeral item if command is effectively empty
Fixes #8232.

Note that this needed to have expect_prompt used in the pexpect test -
we might want to add a "catchup" there so you can just ignore the
prompt counter for a bit and pick it back up later.
2021-08-20 19:38:16 +02:00
Rosen Penev
b748417af7 clang-tidy: replace size comparisons with empty
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 18:32:45 +02:00
Rosen Penev
1af9e5d21e clang-tidy: simplify two bool returns
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 18:32:15 +02:00
Fabian Homborg
d4f7e25584
Replace strerror/sys_errlist after fork with our own errors (#8234)
* Remove safe_strerror, safe_perror and safe_append

This no longer works on new glibcs because they removed sys_errlist.

So just hardcode the relevant errno messages (and phrase them better).

Fixes #4183.

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
2021-08-20 17:17:01 +02:00
Rosen Penev
90f006b1cd clang-tidy: use delete
The clang warning for pending_signals_t was about the operator=
return type being wrong (misc-unconventional-assign-operator).

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:33:33 +02:00
Johannes Altmanninger
5de05a810c Tell clang-tidy that expander_t::stage_variables intentionally takes values
We don't want to convert the input to a "wcstring &" because
"stage_variables" needs to have the same type as other stages, so we
can use it in a loop. Communicate that to clang-tidy.

We also don't want to take "wcstring &&". As the Google style guide
states, it's not really beneficial here, and it potentially hurts
readability because it's a relatively obscure feature.
The rest of our code contains a bunch of && parameters.  We might
want to get rid of some of them.

Closes #8227
2021-08-20 01:21:21 +02:00
Rosen Penev
ffa3e0b4f4 convert const ref to value
clang-tidy wrongly sees an std::move to a const ref parameter and
believes it to be pointless. The copy constructor however is deleted.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:16:24 +02:00
Rosen Penev
4ea5189c4f clang-tidy: const reference conversions
These are only read from.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:15:48 +02:00
Rosen Penev
f9af33f223 clang-tidy: remove pointless virtual
override is already used.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:15:23 +02:00
Rosen Penev
faf51e0693 clang-tidy: use for range loops
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:14:25 +02:00
ridiculousfish
2ca66cff53 Disable job control inside command substitutions
This disables job control inside command substitutions. Prior to this
change, a cmdsub might get its own process group. This caused it to fail
to cancel loops properly. For example:

    while true ; echo (sleep 5) ; end

could not be control-C cancelled, because the signal would go to sleep,
and so the loop would continue on. The simplest way to fix this is to
match other shells and not use job control in cmdsubs.

Related is #1362
2021-08-18 22:20:03 +08:00
Mahmoud Al-Qudsi
3291102045 Refactor deferred_process handling to be more clearly safe
The previous layout confused me for a minute as it suggested it was
possible for `pipe_next_read` to be moved twice (once in the first
conditional block, then again when the deferred process conditional
called `continue` - if and only if the deferred process *was* the last
process in the job. This patch clarifies that can't be the case.
2021-08-17 20:10:19 -05:00
Mahmoud Al-Qudsi
c014c23662 Fix undefined behavior in closing a moved pipe
`pipe_next_read` is moved in the body of the loop, and not
re-initialized the last go around. However, we call
`pipe_next_read.close()` after the loop, which is undefined behavior (as
it's been moved).

Best case scenario, the compiler passed the address of our copy of the
struct to `exec_process_in_job` and beyond, it went out of scope there,
the value of `fd` was set to closed (minus one), and we explicitly call
`.close()` again, in which case it does nothing.

Worst case scenario, the compiler re-uses the storage for the now-moved
struct for something else and our call to `.close()` ends up closing
some other value of `fd` (valid or invalid) and things break.

Aside from the fact that we obviously don't need to close it since it's
not assigned for the last process in the job, it's a RAII object so we
don't have to worry about manually closing it in the first place.
2021-08-17 19:52:15 -05:00