Commit Graph

4027 Commits

Author SHA1 Message Date
Fabian Homborg
3db78232c6 Show if a var is read-only with set --show
Fixes #8179.
2021-07-28 21:13:03 +02:00
Fabian Homborg
8939a71ec6 An empty string means we're on the first line
Oops, this broke up-or-search!
2021-07-27 20:11:32 +02:00
Fabian Homborg
48e696bbb4 Update commandline state before completion
Fixes #8175.
2021-07-27 19:03:35 +02:00
Fabian Homborg
35ca42413d Simplify some parse_util functions
Don't just reflexively drop down to wchar_t.
2021-07-27 18:39:56 +02:00
Fabian Homborg
29e9f4838a Run parse_util_detect_errors on -c commands
This didn't do all the syntax checks, so something like

    fish -c 'echo foo; and $status'

complained of a missing command `0` (i.e. $status), and

    fish -c 'echo foo | exec grep'

hit an assert!

So we do what read_ni does, parse each command into an ast, run
parse_util_detect_errors on it if it worked and then eval the ast.

It is possible to do this neater by modifying parser::eval, but I
can't find where.
2021-07-27 18:37:20 +02:00
Fabian Homborg
08209b3d9a Forbid $status as a command
This is slightly unclean. Even tho it would otherwise be syntactically
valid, using $status as a command is very very very likely to be an
error, like

    if not $status

We have reports of this surprisingly regularly, including #2773.

Because $status can only ever be a value from 0 to 255, it is also
very unlikely to be an actual command, and that command is very
unlikely to do what you want.

So we simply point the user towards the "conditions" help section,
that should explain things.
2021-07-27 18:37:20 +02:00
Fabian Homborg
b9ba3020f8 Don't check config directories with --no-config
If we don't use 'em, we should not complain about 'em.
2021-07-27 18:35:20 +02:00
Fabian Homborg
d32e1c12be tinyexpr: Check for nan in ncr
Turns out this takes ages.

Fixes #8170
2021-07-26 18:40:50 +02:00
Fabian Homborg
4bb1c72a91 Revert "Clear to eol before outputting line in multi-line prompt"
This means, if we repaint with a shorter prompt, we won't overwrite the longer parts.

This reintroduces #8002, but that's a much rarer usecase - having a prompt that fills the entire screen,
in certain terminals.

This reverts commit d3ceba107e.

Fixes #8163.
2021-07-24 09:28:39 +02:00
Johannes Altmanninger
a2b30053dc Teach fish_indent about our feature flags
So it can handle syntax changes that call for different formatting.
2021-07-23 22:58:51 +02:00
Johannes Altmanninger
cc32b4f2a7 Make '&' only background if followed by a separating character
This is opt-in through a new feature flag "ampersand-nobg-in-token".

When this flag and "qmark-noglob" are enabled, this command no longer
needs quoting:

	curl https://example.com/thing?foo=bar&duran=duran

Compared to the previous approach e1570a4 ("Let '&' only separate as
the first char of a word"), this has some advantages:

1. "&&" and "&>" are no longer affected. They are still special, even
   if used between tokens without spaces, like "echo bar&>foo".
   Maybe this is not really *better*, but it avoids risking to annoy
   users by breaking the old variant.

2. "&" is still special if at the end of a token, like in "sleep 1&".

Word movement is not affected by the semantics change, so Alt-F and
friends still stop at every "&".
2021-07-23 22:58:51 +02:00
ridiculousfish
938879a85a Remove a stale comment and add a missing initializer 2021-07-23 11:22:45 -07:00
ridiculousfish
5f7e03ccf4 Introduce noncopyable_t and nonmovable_t
These are little helper types that allow us to get rid of lots of
'=delete' declarations.
2021-07-23 11:19:42 -07:00
ridiculousfish
e9ff3f2e65 Remove a stale comment. 2021-07-23 11:19:42 -07:00
Fabian Homborg
859edc9c2c Implicitly use $PWD in $CDPATH in completions and highlighting
We already do for the actual cd-ing itself.

Missed in #4484.

Fixes #8161.
2021-07-23 17:22:06 +02:00
ridiculousfish
ce371e1881 Put back support for undocumented -I option to commandline
This allows operating on a user-specified commandline instead of the
true contents. This was inadvertently removed in a32248277f.
2021-07-21 15:35:22 -07:00
Fabian Homborg
3359e5d2e9
Let "return" exit a script (#8148)
Currently, if a "return" is given outside of a function, we'd just
throw an error.

That always struck me as a bit weird, given that scripts can also
return a value.

So simply let "return" outside also exit the script, kinda like "exit"
does.

However, unlike "exit" it doesn't quit an interactive shell - it seems
weird to have "return" do that as well. It sets $status, so it can be
used to quickly set that, in case you want to test something.
2021-07-21 22:33:39 +02:00
ridiculousfish
a32248277f Make commandline state thread safe
Today the reader exposes its internals directly, e.g. to the commandline
builtin. This is of course not thread safe. For example in concurrent
execution, running `commandline` twice in separate threads would cause a
race and likely a crash.

Fix this by factoring all the commandline state into a new type
'commandline_state_t'. Make it a singleton (there is only one command
line
after all) and protect it with a lock.

No user visible change here.
2021-07-21 11:51:46 -07:00
ridiculousfish
49c8ed9765 Migrate the fix for 6892 into reader itself
No functional change here; this migrates the fix ensuring that history
items are available in the builtin interactive read command into the
reader itself, in preparation for removing reader_get_history().
2021-07-21 11:51:46 -07:00
Evan Miller
c4773d4052 Work around setpgid error on older Apple platforms
Expand the #7474 fix to Apple platforms. The issue affects older
OS versions, including Mac OS X 10.4.11.
2021-07-20 17:27:10 +02:00
ridiculousfish
b0dc72ee78 Minor clean up of set_buffer_maintaining_pager 2021-07-18 13:18:55 -07:00
Johannes Altmanninger
52f7e83113 Complete revert of faulty polling workaround
62d8f7277 ("Revert "Avoid excessive polling of universal variable
file"") was not a complete revert, which seems to have caused the
problem reported in https://github.com/IlanCosman/tide/issues/171.

See #8088
2021-07-18 18:41:04 +02:00
ridiculousfish
8abc8315de Remove some more ASSERT_IS_MAIN_THREADs
These aren't helping and are blocking testing of concurrent execution.
No functional change here.
2021-07-17 12:20:54 -07:00
Fabian Homborg
e9a793532e Stop cd "" from crashing
Fixes #8147.
2021-07-17 19:03:15 +02:00
Fabian Homborg
f3f6e4a982 string: Add "--groups-only" to match
This adds a simple way of picking bits from a string that might be a
bit nicer than having to resort to a full `replace`.

Fixes #6056
2021-07-16 20:27:54 +02:00
ridiculousfish
f345464879 Simplify ASSERT_SORT_ORDER
In practice this only looked at the name property, so we can simplify it
by using an ordinary template function instead of a macro.
2021-07-15 13:15:24 -07:00
ridiculousfish
a638c4f01d const_strlen to be aware of interior nul chars
Prior to this change, const_strlen would only look for trailing nul
chars. Teach it about interior nul chars and add some tests.
2021-07-15 13:07:09 -07:00
ridiculousfish
ccd1b4e4f4 Clean up of get_function_name
Have it return a real string, instead of a pointer with uncertain
lifetime.
2021-07-15 11:36:43 -07:00
ridiculousfish
bad1b84513 Remove the index parameter from parser_t::is_function
It was always 0 in practice.
2021-07-15 11:04:06 -07:00
ridiculousfish
8bed818039 Remove some main thread assertions that are not helping
This is to make experimenting with concurrent execution easier.
No functional change in this commit.
2021-07-15 10:49:27 -07:00
ridiculousfish
6960a56f29 parse_util_locate_brackets_of_type to only find cmdsubs
Now that we have a separate function for parsing slices, we no longer
need to support parsing slices in the same function as cmdsubs.
2021-07-14 13:59:48 -07:00
ridiculousfish
52c354a60f Simplify slice parsing in highlighting
Factor out parsing of slices, which is only used for highlighting.
2021-07-14 13:59:48 -07:00
ridiculousfish
a2dfd87928 Simplify parse_util_get_parameter_info
We no longer use any part of the "parameter info" except its quote type.
Just return the quote type directly.
2021-07-14 13:59:48 -07:00
ridiculousfish
083d8c5d23 Minor cleanup of certain parsing and quote finding functions
This makes more variables const and removes some suspicious casts.
2021-07-14 13:59:46 -07:00
Johannes Altmanninger
0ab6735450 Support $(cmd) command substitution as alternative to (cmd)
For consistency with "$(cmd)" and with other shells.
2021-07-13 21:33:42 +02:00
Johannes Altmanninger
ec3d3a481b Support "$(cmd)" command substitution without line splitting
This adds a hack to the parser. Given a command

	echo "x$()y z"

we virtually insert double quotes before and after the command
substitution, so the command internally looks like

	echo "x"$()"y z"

This hack allows to reuse the existing logic for handling (recursive)
command substitutions.

This makes the quoting syntax more complex; external highlighters
should consider adding this if possible.

The upside (more Bash compatibility) seems worth it.

Closes #159
2021-07-13 21:33:42 +02:00
ridiculousfish
179073ce62 Clear the control-C cancel flag earlier, allowing event handlers to run
When the user presses control-C, fish marks a cancellation signal which
prevents fish script from running, allowing it to properly unwind.
Prior to this commit, the signal was cleared in the reader. However this
missed the case where a binding would set $fish_bind_mode which would
trigger event handlers: the event handlers would be skipped because of
the cancellation flag was still set. This is similar to #6937.

Let's clear the flag earlier, as soon as we it's set, in inputter_t.
Fixes #8125.
2021-07-11 18:04:44 -07:00
Fabian Homborg
0e1f5108ae
string: Allow collect --allow-empty to avoid empty ellision (#8054)
* string: Allow `collect --no-empty` to avoid empty ellision

Currently we still have that issue where

    test -n (thing | string collect)

can return true if `thing` doesn't print anything, because the
collected argument will still be removed.

So, what we do is allow `--no-empty` to be used, in which case we
print one empty argument.

This means

    test -n (thing | string collect -n)

can now be safely used.

"no-empty" isn't the best name for this flag, but string's design
really incentivizes reusing names, and it's not *terrible*.

* Switch to `--allow-empty`

`--no-empty` does the exact opposite for `string split` and split0.

Since `-a`/`--allow-empty` already exists, use it.
2021-07-09 21:20:58 +02:00
Jean Mertz
2575145682 Enable OSC 0 when running in WezTerm 2021-07-08 16:10:11 +02:00
ridiculousfish
b395b33776 Migrate remaining calls from debug_safe to FLOGF_SAFE
This removes debug_level and remaining debug bits.

We also simplify some of the exec errors, reducing them to a single
line.
2021-07-05 15:47:56 -07:00
ridiculousfish
28bf44d698 Add async-safe flog support
This allows using flog in a limited way after calling fork, or from
signal handlers.
2021-07-05 14:56:38 -07:00
Johannes Altmanninger
62d8f7277b Revert "Avoid excessive polling of universal variable file"
This reverts commit b56b230076.
which somehow made us miss repaints on uvar notifications.

The commit was a workaround for a polling bug which was later properly
fixed by 7c5b8b855 ("Use the uvar notifier pipe timestamp to avoid
excessive polling"), so it's no longer necessary.

Add a system test. If I had a better understanding of the bug I could
probably write a better test.

Fixes #8088
2021-07-03 14:31:37 +02:00
Johannes Altmanninger
874fc439dd Remove stale path validation logic
We used to warn about PATH and CDPATH that are not valid directories,
but only if they contain colons.
However, the warning was a false positive because we would split
those values by colons anyway. So there is nothing left we want to
warn about.

Fixes #8095
2021-07-03 08:45:47 +02:00
Evan Miller
23518e7ad8 FISH_USE_POSIX_SPAWN and HAVE_SPAWN_H fixes
FISH_USE_POSIX_SPAWN is always defined, thanks to the line

   #define FISH_USE_POSIX_SPAWN HAVE_SPAWN_H

So replace #ifdef with #if to fix compilation on platforms lacking
spawn.h. Also make the spawn.h inclusion condition consistent across
files.
2021-07-01 14:34:30 +02:00
Mahmoud Al-Qudsi
ba44c4242f Fix incorrect comparison of function pointers
The sort routine was using the address of the **function pointer**
`signal(int signal)` rather than the union payload of the same name.

Perhaps one of the two should be renamed.
2021-06-28 18:06:04 -05:00
ridiculousfish
8ddbf85768 Correct a suspicious assigning of a value to a reference 2021-06-26 20:06:40 -07:00
Johannes Altmanninger
48c1550f61 Point to builtins begin/end when a failed command starts with "{"
Closes #6415
2021-06-23 21:47:40 +02:00
Johannes Altmanninger
565a7e4bc5 Minor refactoring to use early return in "handle_command_not_found" 2021-06-23 21:47:40 +02:00
Johannes Altmanninger
be0b451207 commandline: allow to get/set cursor position relative to token/process/job
With a command line like

	a | b <cursor> | c

 "commandline -C 0 --current-process" will place the cursor just left of "b".
2021-06-23 20:51:20 +02:00
Johannes Altmanninger
016569905e commandline: move handling of cursor option
No behavior change intended.
Will use the "buffer_part" computation in the next commit.
2021-06-23 20:51:20 +02:00
ridiculousfish
3b4c71c546 Catch invalid function names in highlighting and autosuggestion
Prior to this change, if you were to type `./fish_indent` it woul dbe
colored as valid, because the path
`$fish_functions_path/./fish_indent.fish` is a real file. However of
course this is not actually executed as a function. Teach
function_exists to return false for function names which are invalid.
2021-06-22 12:37:45 -07:00
Johannes Altmanninger
2bc8057780 Remove redundant parens 2021-06-15 03:27:55 +02:00
Johannes Altmanninger
4908f9bb40 Remove spurious character escape 2021-06-15 01:19:01 +02:00
ridiculousfish
1c20bdcbf9 Minor improvements to file_id_t 2021-06-13 17:20:04 -07:00
ridiculousfish
ba2e7db7e8 Notice when exit has been run from within fish_prompt
This allows `exit` to tell the reader to stop, when run inside
fish_prompt. Fixes #8033.
2021-06-12 10:20:49 -07:00
Fabian Homborg
7059eaa4ab Revert "Disallow escaped characters in variable expansion"
This reverts commit 555af37616.
2021-06-10 16:46:17 +02:00
Fabian Homborg
95103893e6 output: Allow "--background foo" and "-b foo" for background colors
This only accepted "--background=". Really what we need to do is do an
actual getopt, but that wants a null-terminated array and is tightly
coupled to set_color.

Fixes #8053.
2021-06-10 10:42:30 +02:00
Fabian Homborg
046db09f90
Try to set LC_CTYPE to something UTF-8 capable (#8031)
* Try to set LC_CTYPE to something UTF-8 capable

When fish is started with LC_CTYPE=C (even just effectively, often via
LC_ALL=C!), it's basically broken. There's no way to handle non-ASCII
characters with a C locale unless we want to write our
locale-independent replacements for all of the system functions.

Since we're not going to do that, let's try to find *some locale* for
LC_CTYPE.

We already do that in __fish_setlocale, but that's

- a bit of a weird thing that reads unstandardized system
  configuration files
- allows setting locale to C explicitly

So it's still easily possible to end up in a broken configuration.

Now, the issue with this is that there is (AFAICT) no portable way to
get a list of all allowed locales and C.UTF-8 is not standardized, so
we have no one locale to fall back on and are forced to try a few. The
list we have here is quite arbitrary, but it's a start.

Python does something similar and only tries C.UTF-8, C.utf8 and
"UTF-8".

Once C.UTF-8 is (hopefully) standardized, that will just start
working (tm).

Note that we do not *export* the fixed LC_CTYPE variable, so external
programs still have to deal with the C locale, but we have no real
business messing with the user's environment.

To turn it off: $fish_allow_singlebyte_locale, if set to something true (like "1"),
will re-run the locale initialization and skip the bit where we force
LC_CTYPE to be utf8-capable.

This is mainly used in our tests, but might also be useful if people
are trying to do something weird.
2021-06-06 09:28:32 +02:00
ridiculousfish
e74b9d53df Do not use posix_spawn on glibc < 2.24
This concerns the behavior of posix_spawn for shebangless scripts. At some
point, glibc started executing them using `sh`, which is desirable for
fish's shebangless support (see #7802). On glibcs without that behavior
the shebangless test fails. So this change disables posix_spawn on older
glibcs.

It's not easy to figure out when that happened but it definitely happens
in glibc 2.28, and does not happen in glibc 2.17. Presumably the new
behavior is present in glibc 2.24 (see BZ#23264) so that's the cutoff:
posix_spawn is no longer allowed on glibc < 2.24.

This fixes the noshebang test failures on Ubuntu Xenial and Centos 7.
See discussion at bottom of #8021.
2021-05-31 13:38:56 -07:00
ridiculousfish
50c851d10e Clean up use_posix_spawn
Switch from a global variable to a real function. Make the value atomic.
Clean up handle_fish_use_posix_spawn_change().
2021-05-31 13:38:56 -07:00
Fabian Homborg
671d820277 set_color: Print an error for unknown options
This was forgotten, so e.g. calling `set_color --bg foo` results in
nothing being printed, which might result in strings being removed - #5443.
2021-05-27 19:03:55 +02:00
ridiculousfish
9820307d23 Move builtin_bind to out-of-line
There was no point in inlining this code.
2021-05-25 17:39:55 -07:00
ridiculousfish
08950b1077 Revert "Bravely set job control to full at startup"
Now that `$last_pid` is never fish's pid, we no longer need to force
jobs to run in their own pgroup. Restore the job control behavior to
what it was prior, so that signals may be delivered properly in
non-interactive mode.

This reverts commit 3255999794
2021-05-25 15:28:53 -07:00
ridiculousfish
33f3c03dae Allow on-job-exit handlers to be added for any pid in the job
Prior to this change, a function with an on-job-exit event handler must be
added with the pgid of the job. But sometimes the pgid of the job is fish
itself (if job control is disabled) and the previous commit made last_pid
an actual pid from the job, instead of its pgroup.

Switch on-job-exit to accept any pid from the job (except fish itself).
This allows it to be used directly with $last_pid, except that it now
works if job control is off. This is implemented by "resolving" the pid to
the internal job id at the point the event handler is added.

Also switch to passing the last pid of the job, rather than its pgroup.
This aligns better with $last_pid.
2021-05-25 15:28:53 -07:00
ridiculousfish
f3d78e21d1 Switch last_pid from the pgroup to the actual last pid
When a job is placed in the background, fish will set the `$last_pid`
variable. Prior to this change, `$last_pid` was set to the process group
leader of the job. However this caussed problems when the job ran in
fish's process group, because then fish itself would be the process group
leader and commands like `wait` would not work.

Switch `$last_pid` to be the actual last pid of the pipeline. This brings
it in line with the `$!` variable from zsh and bash.

This is technically a breaking change, but it is unlikely to cause
problems, because `$last_pid` was already rather broken.

Fixes #5036
Fixes #5832
Fixes #7721
2021-05-25 15:28:53 -07:00
David Dorfman
f2448e3f0e env: remove trailing null-terminator from default path 2021-05-25 08:12:21 +02:00
ridiculousfish
35f77a5473 Switch locale_variables and curses_variables from vector to array
No reason to have these be a heap-allocated vector.
2021-05-22 12:50:26 -07:00
Fabian Homborg
fe4eaba563 Fix set_cloexec check
Fixes #8023.
2021-05-22 18:09:15 +02:00
ridiculousfish
9d696ba7d2 Remove some assignments of wcs2string to references
wcs2string returns a std::string by value; it should not be assigned to a
reference variable.
2021-05-21 13:11:56 -07:00
ridiculousfish
9928404920 Remove some static_asserts out of the common.h header
These asserts require a recursive template instantiation and are currently
checked for every file that pulls in common.h. Place them in a .cpp file so
they are only checked once, hopefully improving compile time.
2021-05-21 13:06:43 -07:00
ridiculousfish
7123e2f25d Remove another errant negation 2021-05-20 11:10:09 -07:00
ridiculousfish
fac8f14e07 Correct a negated pgid
When printing the description of an event, there was an errant negation
from when fish stored the pgid negated. Remove it.
2021-05-20 11:07:36 -07:00
ridiculousfish
504a969a24 Separate on-job-exit and and on-process-exit events
It is possible to run a function when a process exits via `function
--on-process-exit`, or when a job exits via `function --on-job-exits`.
Internally these were distinguished by the pid in the event: if it was
positive, then it was a process exit. If negative, it represents a pgid
and is a job exit. If zero, it fires for both jobs and processes, which is
pretty weird.

Switch to tracking these explicitly. Separate out the --on-process-exit
and --on-job-exit event types into separate types. Stop negating pgids as
well.
2021-05-19 11:29:08 -07:00
Fabian Homborg
63dd046f99 screen: Remove errant line
This was an experiment that was accidentally committed. Sorry!
2021-05-18 11:27:30 +02:00
Fabian Homborg
5743a536b0 proc: Include sys/wait.h
Might fix build on FreeBSD.
2021-05-18 10:18:50 +02:00
Fabian Homborg
c19a6e912d Readd awkward unused-result dance
This was removed in 962b0f8b90,
presumably with the idea that casting to void, like before, was
enough.

It's not, at least with gcc 11.1
2021-05-18 09:44:29 +02:00
Fabian Homborg
4b2bce7b83 screen: Remove useless .c_str() and wcslen calls
This passed the wchar_t* to outputter::writestr(), which then had to
do a wcslen on it, when it already has a perfectly cromulent
wcstring overload.

Just use that one.
2021-05-18 09:11:56 +02:00
Fabian Homborg
25595a94c7 screen: Also move cursor after printing the prompt
This helps with width issues when no right prompt is used.
2021-05-18 09:09:59 +02:00
Fabian Homborg
0660ea5be7 Move the cursor to the beginning before printing right prompt
This makes the right prompt position independent of the width of the
commandline, which prevents staircase effects. That means, with "X"
standing in as a character that the terminal and fish disagree on:

```
> echo X           rightprompt
```

will stay like that instead of creating a staircase like

```
> echo X            rightpromp
t> echo X             rightpromp
pt> echo X
```

and so on.

The cursor still won't be *correct*, but it will be wrong in a less
annoying way.
2021-05-18 09:09:59 +02:00
ridiculousfish
d3ceba107e Clear to eol before outputting line in multi-line prompt
If the user has a multi-line prompt, we will emit a clr_eol on every
line except the last (see #7404). Prior to this change we would emit
clr_eol after the line, but in some terminals, if the line extended the
width of the tty, the last character would be deleted. Switch to
emitting clr_eol first; now the last character will not be cut off.

Fixes #8002
2021-05-17 21:44:17 -07:00
ridiculousfish
6d00ad1045 Ensure that on-process-exit events fire for reaped jobs
This ensures that if a job exits before we have set up the
on-process-exit handler, the handler will still fire.

Fixes #7210
2021-05-17 15:28:32 -07:00
ridiculousfish
60d75e9aa0 Remove proc_create_event
Switch to a set of factory functions inside event_t.
No user-visible change here.
2021-05-17 15:26:59 -07:00
ridiculousfish
962b0f8b90 Pass $status to process-exit event handlers in all cases
Previously, an event handler would receive -1 if the process exited due
to a signal. Instead pass the same value as $status.
2021-05-17 15:25:27 -07:00
ridiculousfish
82fd8fe9fb Refactor wait handles
In preparation for using wait handles in --on-process-exit events, factor
wait handles into their own wait handle store. Also switch them to
per-process instead of per-job, which is a simplification.
2021-05-17 15:25:21 -07:00
Fabian Homborg
a427bf207a reader: Fix crash when text is empty after stripping spaces
This crashed on Fedora with the rpm packages, but not when building
from source, so some compiler option triggers it.

But the root cause is us running `text.front()` on an empty string,
which isn't something you should do.

Fixes #8009.
2021-05-16 22:16:22 +02:00
Karolina Gontarek
31f3c16857 Resolve relative paths in command names for complete -p
Fixes #6001
2021-05-16 21:52:38 +02:00
ridiculousfish
63ee28c1de Fix a misleading comment 2021-05-15 22:05:35 -07:00
ridiculousfish
5de63c9cbb Reimplement builtin_wait using wait handles
This switches builtin_wait from waiting on jobs in the active job list, to
waiting on the wait handles. The wait handles may be either derived from
the job list itself, or from saved wait handles from jobs that exited in
the background.

Fixes #7210
2021-05-15 21:48:15 -07:00
ridiculousfish
632e150152 Introduce notion of "wait handles"
This is preparing to address the problem where fish cannot wait on a
reaped job, because it only looks at the active job list. Introduce the
idea of a "wait handle," which is a thing that `wait` can use to check if
a job is finished. A job may produce its wait handle on demand, and
parser_t will save the wait handle from wait-able jobs at the point they
are reaped.

This change merely introduces the idea; the next change makes builtin_wait
start using it.
2021-05-15 20:20:50 -07:00
ridiculousfish
aeabc76b2e Use internal job ids in builtin_wait
This avoids any potential issues due to recycled job IDs.
No user visible change.
2021-05-13 12:11:00 -07:00
ridiculousfish
786b0463b6 Fix a unique_ptr build error with gcc 4.8 2021-05-10 16:49:11 -07:00
ridiculousfish
04535e9701 Fix a few mild warnings with gcc 4.8 2021-05-10 16:49:01 -07:00
ridiculousfish
71df8f8622 Do not flock the uvars file on remote filesystems
In rare cases this may cause the universal variable file to drop
an update, if two happen at the same time and HOME is on an nfs mount.
But this is considered better than hanging if nfs is lockless.

Fixes #7968.
2021-05-10 15:24:32 -07:00
ridiculousfish
ba33b6dcc8 Mild refactoring of flock logic inside env_universal_t
This reorganizes the flock code in env_universal_t, removing a static
variable and making the behavior more explicit.
2021-05-10 15:23:57 -07:00
ridiculousfish
083f2698f9 Remove internal lock from env_universal_t
env_universal_t locking discipline is now managed by env.cpp.
That is, the shared instance of env_universal_t is managed by a lock.
We no longer need to have an internal lock, so remove it.
2021-05-10 15:23:57 -07:00
ridiculousfish
8d06357fbb Take advantage of empty uvars
Now that we allow uvars to be empty and uninitialized, we can always
instantiate it; we don't need to test whether it is null or not.
2021-05-10 15:23:56 -07:00
ridiculousfish
e2a1b25a24 Continue refactoring env_universal_t
Previously an instance of env_universal_t had to be created with a file
path. Switch to allowing it to be created as empty, and later initialized
with the file path. This will help simplify the case where universal
variables are not used; they may simply be not initialized and so just
appear empty.
2021-05-10 15:23:08 -07:00
ridiculousfish
16ba45fe64 Early work towards changing locking discipline of uvars
Rather than universal variables holding their own lock, we will wrap the
instance in a lock.
2021-05-10 14:23:07 -07:00
ridiculousfish
fa7402c415 Reorganize env_universal_t so that the public bits are at the top
No functional change here.
2021-05-10 14:23:07 -07:00
ridiculousfish
0d8cb0125a Remove the narrow_vars_path from universal variables
This was a cache of the wide vars_path, but it's not worth its
complexity.
2021-05-10 14:23:07 -07:00
ridiculousfish
6ab7945623 Mild refactoring of universal variables
This removes some unnecessary returns and other miscellaneous cleanup.
2021-05-10 14:23:07 -07:00
ridiculousfish
c8d909b2b2 Remove fd_check_is_remote
This function is no longer used; instead we detect if a given path is
remote, once, typically at startup.
2021-05-10 14:23:07 -07:00
ridiculousfish
1af441b4cc Do not lock the history file on remote filesystems
This avoids using locks for the history file if the file appears to be on
a remote file system, like NFS. This is to avoid hangs if the filesystem
does not support locking.

If locking is not enabled, then in rare cases, history items may be
dropped if multiple sessions try to write to the history file at once.
This is thought to be better than hanging. Hopefully the recent change to
require a trailing newline will avoid propagating partial items.
2021-05-10 14:23:07 -07:00
ridiculousfish
d1fd3d5825 Detect at startup whether config and data paths are remote
This is in preparation for changing the locking regime of history.
2021-05-10 14:23:07 -07:00
ridiculousfish
541e1d2fad base_directory_t to stop storing explicit success bool
This can be trivially computed from the error code.
2021-05-10 14:23:07 -07:00
ridiculousfish
f85f6a0127 Enforce that history items must end with trailing newlines
This helps prevent seeing partially written items from other sessions,
in preparation to reducing the amount of flocking done.
2021-05-10 14:23:07 -07:00
ridiculousfish
aa02cbd090 Wrap up history's mmap logic into its own type
This improves the factoring a bit.
2021-05-09 11:59:29 -07:00
ridiculousfish
d1befee19e Fix some potential leaks in history file contents
If history is corrupt and cannot be read, fish would return an error
without munmaping the file. Ensure it is properly munmapped.
2021-05-09 11:59:29 -07:00
ridiculousfish
c1f97c20b5 Pull in missing headers for MNT_LOCAL
fstatfs was only being used on Linux because MNT_LOCAL was not defined.
Pull in sys/mount.h and sys/param.h so macOS can see MNT_LOCAL.
2021-05-09 11:59:29 -07:00
ridiculousfish
37356fed44 Use wide printing when outputting debug categories
glibc doesn't like it when wide and narrow printing is mixed.
This fixes a strange beeping when running with debug enabled on glibc.
2021-05-09 11:59:29 -07:00
ridiculousfish
555af37616 Disallow escaped characters in variable expansion
Prior to this fix, an escaped character like \x41 (hex for ascii A)
was interpreted the same was as A, so that $\x41 would be the same
as $A. Fix this by inserting an INTERNAL_SEPARATOR before these escapes,
so that we no longer treat it as part of the variable name.

This also affects brackets; don't treat echo $foo\1331\135 the same as
echo $foo[1].

Fixes #7969
2021-05-05 16:23:06 -07:00
ridiculousfish
e0bf23ad26 Refactor the named pipe uvar notifier with a state machine
This attempts to simplify the named pipe notifier by switching to a state
machine model.
2021-05-04 11:59:12 -07:00
ridiculousfish
7c5b8b8556 Use the uvar notifier pipe timestamp to avoid excessive polling
In the named pipe notifier, notifications are broadcast by writing to the
pipe, waiting briefly, and then reading it back. When clients see the pipe
as readable, they report the uvars as potentially changed and fish will
sync against the uvar file.

Prior to this change, we synced repeatedly when the pipe was readable. But
we can do somewhat better by also checking the named pipe's timestamp (via
fstat). If the pipe has not changed, then we can skip the sync even if
there is currently data lingering on it.

With this change we should sync against the variable file less often
(typically once or twice per write); in the next change we refactor this
logic so it's easier to follow.
2021-05-04 11:59:12 -07:00
ridiculousfish
3a093e3ce8 Add a flog category for universal variable notifiers
Make it easier to debug this stuff.
2021-05-04 11:59:12 -07:00
ridiculousfish
8344289fac Give file_id_t a real constructor
Initialize it to invalid by default.
2021-05-04 11:59:12 -07:00
Fabian Homborg
8317b8bb8a Make ast FLOGs slightly less chatty
This removes the "did_visit" message because it doesn't really add
anything.

For example:

```
ast-construction: make job_list 0x55a6d19729f0
ast-construction: make job_conjunction 0x55a6d1971c00
ast-construction: will_visit job_conjunction 0x55a6d1971c00
ast-construction:   will_visit job 0x55a6d1971c18
ast-construction:     variable_assignment_list size: 0
ast-construction:     will_visit statement 0x55a6d1971c48
ast-construction:       make decorated_statement 0x55a6d1972650
ast-construction:       will_visit decorated_statement 0x55a6d1972650
ast-construction:         make argument_or_redirection 0x55a6d1968310
ast-construction:         will_visit argument_or_redirection 0x55a6d1968310
ast-construction:           make argument 0x55a6d197b0b0
ast-construction:         did_visit argument_or_redirection 0x55a6d1968310
ast-construction:         argument_or_redirection_list size: 1
ast-construction:       did_visit decorated_statement 0x55a6d1972650
ast-construction:     did_visit statement 0x55a6d1971c48
ast-construction:     job_continuation_list size: 0
ast-construction:   did_visit job 0x55a6d1971c18
ast-construction:   job_conjunction_continuation_list size: 0
ast-construction: did_visit job_conjunction 0x55a6d1971c00
ast-construction: job_list size: 1
```

those "did_visit" messages all correspond to "will_visit" ones. They
are effectively block delimiters like `end` or `}`.

If we remove them it turns into:

```
ast-construction: make job_list 0x55a6d19729f0
ast-construction: make job_conjunction 0x55a6d1971c00
ast-construction: will_visit job_conjunction 0x55a6d1971c00
ast-construction:   will_visit job 0x55a6d1971c18
ast-construction:     variable_assignment_list size: 0
ast-construction:     will_visit statement 0x55a6d1971c48
ast-construction:       make decorated_statement 0x55a6d1972650
ast-construction:       will_visit decorated_statement 0x55a6d1972650
ast-construction:         make argument_or_redirection 0x55a6d1968310
ast-construction:         will_visit argument_or_redirection 0x55a6d1968310
ast-construction:           make argument 0x55a6d197b0b0
ast-construction:         argument_or_redirection_list size: 1
ast-construction:     job_continuation_list size: 0
ast-construction:   job_conjunction_continuation_list size: 0
ast-construction: job_list size: 1
```

Which is still unambiguous because of the indentation.

(this is still *super verbose* and we might want to remove it from the
`*` "all" debug category and only allow turning it on explicitly)
2021-05-03 12:01:21 +02:00
Fabian Homborg
202e5e53d5 Handle exit in keybindings immediately
This simply checks if the parser requested exit after running any
binding scripts (in read_normal_chars).

I think this means we no longer need the `exit` bind function.

Fixes #7967.
2021-05-02 20:27:08 +02:00
Johannes Altmanninger
b56b230076 Avoid excessive polling of universal variable file
Reproducible at least on Linux, where the "named pipe" universal
variable notifier is used:

	rm -rf build/test/xdg_config
	XDG_CONFIG_HOME=build/test/xdg_config ./build/fish -c "xterm -e ./build/fish"

The child fish reacts to keyboard input with a noticeable initial
delay.  This is because the universal variable file is polled over
a million times, even when I immediately press Control-D. This polling
prevents readb() from handling keyboard input.
Before commit 939aba02d ("Refactor input_common.cpp:readb"), readb()
reacted to keyboard input even when there were universal variable
notifications.  Restore this behavior, but make sure to call the
universal variable notifier after the new "prepare_to_select" logic.
Maybe the problem is in the notifier but the old behavior was sane.

Fixes the problems described in
7a556ec6f2 (commitcomment-49773677)

Adding "-d uvars-file" to the reproducesr shows that we are checking
the uvar file repeatedly:

	uvar-file: universal log sync
	uvar-file: universal log sync elided based on fast stat()
	uvar-file: universal log no modifications
2021-05-01 22:51:35 +02:00
Fabian Homborg
b16e537b66 Only set default fish_function_path when --no-config is used
Otherwise config.fish will keep $fish_function_path.
2021-05-01 19:43:31 +02:00
Fabian Homborg
2416aa5337 Let --no-config imply private mode
This stops it from saving history.
2021-05-01 18:59:25 +02:00
Fabian Homborg
5ddb1adac1 Only use DATADIR in $fish_function_path if no-config is used
This only uses the functions fish ships with, but still doesn't allow
any *customization*, which is the point of no-config.

This makes it a lot more usable, given that the actual normal prompt
and things are there.

This still doesn't set any colors, because we don't run
__fish_config_interactive because we don't read config.fish (any
config.fish), because that would run the snippets.
2021-05-01 18:59:25 +02:00
Fabian Homborg
848f7a0787 Don't do uvars if no-config is in effect 2021-05-01 18:59:25 +02:00
Fabian Homborg
980365735a If no uvars are available, fall back to global when setting
Otherwise `set -U foo bar` if uvars aren't available would simply not
set *anything*.
2021-05-01 18:59:25 +02:00
Fabian Homborg
52f56e2119 WIP Add no-config mode
This loads *no* config, *at all*. Not even share/config.fish, so
$fish_function_path is entirely unset.
2021-05-01 18:59:25 +02:00
Fabian Homborg
f768389cf7 fish_tests: Actually set locale
Otherwise this fails if the $PWD has non-ASCII characters.

Fixes #7962.
2021-04-29 08:00:05 +02:00
Johannes Altmanninger
9d7f6db792 fish_indent: preserve escaped newlines around variable assignments
In many cases we currently discard escaped newlines, since they
are often unnecessary (when used around &|;). Escaped newlines
are useful for structuring argument lists. Allow them for variable
assignments since they are similar.

Closes #7955
2021-04-27 00:13:48 +02:00
Fabian Homborg
3cccb77b52 Make test error when number is invalid nicer
This would print the default "Argument is invalid" error string, which
is *true* but not super obvious, because `test` doesn't always perform
numeric conversion, and that's the bit that failed here.
2021-04-24 11:18:58 +02:00
ridiculousfish
42d674819f Make the kill ring thread-safe
Now that the kill ring may be accessed on a background thread, ensure it
is thread safe.
2021-04-21 17:37:44 -07:00
Karolina Gontarek
9d66ddc840 Rename variable to fish_killring 2021-04-21 16:39:29 -07:00
Karolina Gontarek
539837f317 Add variable to documentation 2021-04-21 16:39:29 -07:00
Karolina Gontarek
ed64cf5e34 Implementation of variable with killring entries 2021-04-21 16:39:29 -07:00
ridiculousfish
0a559ac457 Reformat source files with clang-format 2021-04-21 13:31:58 -07:00
ridiculousfish
f4bcfd9085 Correct behavior of string match variable import with multiple arguments
This refactors the behavior of string match with capture groups to
correctly handle multiple arguments. Now the variable capture applies to
the first match, as documented. Fixes #7938.
2021-04-20 15:15:52 -07:00
ridiculousfish
abd59c50b0 Add a test for invalid regex variable names
Also apply some mild refactoring.
2021-04-20 15:15:52 -07:00
ridiculousfish
8e95bba25e Clean up and reduce some allocations in env.cpp 2021-04-20 15:15:52 -07:00
Fabian Homborg
c95a223f5e Better errors when calling a command in a command substitution fails 2021-04-19 16:47:17 +02:00
ridiculousfish
e8a6d31aea Correct behavior of string match and unmatched capture groups
string match is documented as setting an unset variable if a capture group
is unmatched in an otherwise matched regex, and if the `--all` flag is not
provided. However prior to this fix, it instead set a variable containing
the empty string as a single value. Correct the implementation to match
the documentation.

Note that if the `--all` flag is provided we continue to set empty
strings, which is documented.
2021-04-18 21:04:25 -07:00
ridiculousfish
1aa8200b96 Minor cleanup of builtin_string regex
Mark some classes as final and remove some unnecessary variables.
Add a test in preparation for the next fix.
2021-04-18 20:39:14 -07:00
ridiculousfish
092168485b Remove wcstring_tok
wcstring_tok was a funky function which was confusing and used only in
one place. Replace it with split_string_tok, which is somewhat simpler.
2021-04-18 14:46:05 -07:00
ridiculousfish
2fb0a703de Simplify rgb_color_t::try_parse_named
This came out of an investigation into making strings immutable.
This code did "lazy" lowercasing but we can simplify it by just
providing our own case-insensitive compare routine, which is good
enough for colors.
2021-04-18 12:11:38 -07:00
ridiculousfish
467755bf4a Bravely optimize job_reap
job_reap is now called more often. This optimizes it by doing an
early-out if there are no running jobs (common at the prompt) and also
skipping the save/restore status, since by inspection we also save and
restore the status when running event handlers.
2021-04-17 16:43:28 -07:00
ridiculousfish
7c153a8307 Introduce prepare_to_select, fixing job_summary.py
This concerns printing status messages for background jobs which have
stopped or finished. Previously fish would do this from two places:

1. Before running a command (including empty string)
2. If a signal is received during select()

So if the job finishes while fish is doing something else (like running an
event handler) then we would not print status messages until the user hit
return. This caused the job_summary.py test to be flaky.

Fix this by splitting the interrupt handler into two parts: a part that
handles signals (e.g. triggering exit from the reader), and a part that
always runs just before blocking in select(). This second part always
reaps jobs and prints their status messages. This narrows the window for a
job exit to be "missed" before fish blocks in select, and should make the
job_summary.py test more reliable.
2021-04-17 16:43:28 -07:00
ridiculousfish
3684c91ad2 Make input_event_queue_t a base class
This concerns the problem of "injecting" fancy fish bits like job reaping
into the "common" input stuff which is also used by fish_key_reader.
Instead of providing a callback, make the input event queue a base class
with virtual functions. This allows for a richer interface and simplifies
some memory management issues.
2021-04-17 16:43:28 -07:00
ridiculousfish
939aba02de Refactor input_common.cpp:readb
readb is used to read a single byte from stdin, or maybe update universal
variables, or maybe invoke completion handlers, etc. Previously it
returned char_event_t but this is more complex than necessary; instead we
can just have it return a single byte, or one of a few special error
codes. This makes the readb's role more clear.
2021-04-17 16:43:28 -07:00
ridiculousfish
78147abe8a Switch the interrupt handler from a global to an instance variable
"The" interrupt handler is used when we get a signal while waiting at the
prompt. Switch it from a global function pointer to an std::function. This
is a mild refactoring which itself will be replaced soon.
2021-04-17 16:43:28 -07:00
ridiculousfish
060ce4f7da Remove timeout input events
Now that timeouts are stored in the event queue peeker, we can remove the
notion of timeout events altogether. Instead you may ask for an event with
a timeout, and get back none on timeout. This simplifies how input events
work.
2021-04-17 16:43:28 -07:00
ridiculousfish
bd72791340 Use event_queue_peeker_t when matching key bindings
Previously, when attempting to match a key binding, we would dequeue
events from the queue and put them back on if the binding fails. The
tricky part is timeouts: distinguishing between an escaped character and
the escape key itself. This was handled with "timeout events" and we had
to be careful to know when to discard them.

Switch to a new model: use event_queue_peeker more pervasively.
Temporarily dequeued events are stored in the peeker, and the peeker
itself remembers when it has seen a timeout. This is in preparation for
removing the idea of "timeout events" altogether.
2021-04-17 16:43:27 -07:00
ridiculousfish
c570a14c04 Simplify event_queue_peeker_t
Make it an ordinary struct wrapping a vector, instead of a template.
This is in preparation for using it more widely, for matching bindings
as well as mouse CSI sequences.
Also add some mouse-disabling tests.
2021-04-17 16:43:27 -07:00
ridiculousfish
e8a61ef4aa Introduce select_wrapper_t
select_wrapper_t wraps up the annoying bits of using select(): keeping
track of the max fd, passing null for boring parameters, and
constructing the timeout. Introduce a wrapper struct for this and
replace the existing uses of select() with the wrapper.
2021-04-17 16:43:27 -07:00
ridiculousfish
0dd24c8f74 Correct nfds argument to select()
In readch_timed, we were passing 1 as the number of fds. This is correct if
the fd is 0 (stdin) which it typically is; however this will fail if in_ is
not stdin. Switch to in_ + 1.
2021-04-17 16:43:27 -07:00
ridiculousfish
48b42c0255 Reorganize input_event_queue_t declaration
This moves the private bits to the bottom. No functional change.
2021-04-17 16:43:27 -07:00
ridiculousfish
3b32a32dda Replace some format_strings with to_string
This is hopefully a little faster and a little safer as there's
no format string involved.
2021-04-17 16:43:27 -07:00
ridiculousfish
be9579418f Refactor to use has_external_proc instead of a manual loop
No functional change here.
2021-04-17 16:43:27 -07:00
ridiculousfish
e299f89db3 Rename print_job_summary to call_job_summary
No functional change; this is simply a less misleading name.
2021-04-17 16:43:27 -07:00
Fabian Homborg
ef96a6614b Update termsize before a sigwinch handler
This could have been one iteration off, e.g.

```fish
function on-winch --on-signal winch
    echo $LINES
end
```

Resize the terminal, it'll print e.g.

24

then run `echo $LINES` interactively, it might have a different answer.

This isn't beautiful, but it works. A better solution might be to make
the termsize vars electric and just always update them on read?
2021-04-14 17:27:53 +02:00
Fabian Homborg
3e473b9f37 io: Silence write error with EPIPE
With something like

```
history | head -n 1
```

this would error "write: Broken pipe", which is just annoying. There
is no *problem* here, `head` closes this on purpose.

Fixes #7924.
2021-04-13 10:38:17 +02:00
David Adam
a918cabf5e feature flags: default stderr-nocaret to on 2021-04-12 22:18:48 +08:00
David Adam
2e44076397 feature flags: add the notion of a default value for each flag 2021-04-12 22:18:48 +08:00
Fabian Homborg
7210261513 complete: Obey --force-files without an option
Things like

```fish
complete command -n '__fish_seen_subcommand_from subcommand'
--force-files
```

would not be obeyed because we only checked force-files when there was
an option.

Fixes #7920.
2021-04-10 21:58:40 +02:00
Fabian Homborg
bc4d597e91 Don't abandon line before the first prompt
When a terminal in a tiling WM starts, it might start the shell before
it has reached its "final" size. So we get the terminal width,
then the terminal would be resized (to appease the tiling logic),
and then we would print the abandon line with the omitted newline
char, only if the size got smaller (likely!), we would overflow the
line and land on the next.

So what we do is a bit of a hack: We don't abandon the first line.

This means that `printf %s foo; fish` will overwrite the `foo`, but
that's a super small problem and I don't see another way around this.

Fixes #7893.
2021-04-10 17:13:44 +02:00
Fabian Homborg
e2146a0eee complete: Stop using the function definition as the description
This isn't helpful, and entirely unreadable. Excerpt:

```
__fish_git_prompt_set_char  (set -l user_variable_name "$argv[1]" set -l char $argv[2] if set -q argv[3] and begin set -q __fish_git_prompt_show_informative_status or set -q __fi…)
```

Fixes #7911.
2021-04-08 15:36:59 +02:00
ridiculousfish
ed51e2baac Prevent hanging when restoring the foreground process group at exit
When fish starts, it notices which pgroup owns the tty, and then it
restores that pgroup's tty ownership when it exits. However if fish does
not own the tty, then (on Mac at least) the tcsetpgrp call triggers a
SIGSTOP and fish will hang while trying to exit.

The first change is to ignore SIGTTOU instead of defaulting it. This
prevents the hang; however it risks re-introducing #7060.

The second change somewhat mitigates the risk of the first: only do the
restore if the initial pgroup is different than fish's pgroup. This
prevents some useless calls which might potentially steal the tty from
another process (e.g. in #7060).
2021-04-05 17:44:14 -07:00
ridiculousfish
a69e94d954 add_disowned_job to accept its parameter by const pointer
It never modified the job.
2021-04-03 21:05:32 -07:00
ridiculousfish
73ec89917a Remove the SIGIO signal handler and universal notifier
If fish launches a program and that program marks stdin as O_ASYNC, then
fish will start receiving SIGIO events on Mac. This occurs even though
the file descriptor itself does not have the O_ASYNC flag set.

SIGIO is reported as interrupting select which then breaks multiple-key
bindings, especially in vi-mode.

As the SIGIO based universal notifier is disabled, remove it and the
SIGIO handler itself. This allows fish to ignore properly ignore SIGIO.

Fixes #7853
2021-04-03 18:11:29 -07:00
ridiculousfish
36ad116b34 Properly report errors when builtin output fails
This correctly sets $status when a builtin succeeds but its output fails;
for example if the output is redirected to a file and that write fails.

Fixes #7857
2021-04-03 16:11:25 -07:00
Johannes Altmanninger
ed5e5a9d49 Enhance greppability of the "return symbol" for abandoned newlines
Was looking for this for #7893
2021-04-02 08:09:56 +02:00
Fabian Homborg
dbd608cb6a tinyexpr: Use cmath with std::
The oldschool math.h imports the math functions into the global
namespace, cmath imports them into std::.

Unfortunately, we already use cmath elsewhere, and including math.h
doesn't reimport them in some systems, so now they can't find them
with std::.

Fixes #7882.
2021-03-31 17:21:46 +02:00
David Adam
0c03a0267f Revert "tinyexpr: use std:: namespace for older libstdc++"
This reverts commit f46444f106.

This commit does not build on macOS or RHEL 7.
2021-03-31 22:53:18 +08:00
David Adam
f46444f106 tinyexpr: use std:: namespace for older libstdc++
Fixes the build on Ubuntu Xenial 16.04 and CentOS 7.
2021-03-31 11:21:42 +08:00
Fabian Homborg
ed9268f99c
math: Make function parentheses optional (#7877)
* math: Make function parentheses optional

It's a bit annoying to use parentheses here because that requires
quoting or escaping.

This allows the parens to be omitted, so

math sin pi

is the same as

math 'sin(pi)'

Function calls have the lowest precedence, so

math sin 2 + 6

is the same as

math 'sin(2 + 6)'

* Add more tests

* Add a note to the docs

* even moar docs

Moar docca

* moar tests

Call me Nikola Testla
2021-03-30 17:21:28 +02:00
Fabian Homborg
18e332772d functions: Add "--no-details" flag and use it in funced
This inhibits the function path comment which is annoying in `funced`.

Fixes #7879.
2021-03-30 16:54:26 +02:00
Karolina Gontarek
da2f7999ad
Fix backward-kill-path-component erasing extra tokens (#7872)
Fixes #6258
2021-03-29 22:58:50 +02:00
Fabian Homborg
fd4803ac6a Update BEL comment
We no longer send it.
2021-03-29 18:03:36 +02:00
Fabian Homborg
312cfacf71 Don't ring the bell in reader_flash
The bell is a mechanism for important notifications. Not having things
to do in response to a keypress isn't important enough, especially
because we're already flashing and the bell might actually be a bell.

Fixes #7875.
2021-03-29 17:49:47 +02:00
Fabian Homborg
e1d19cf571 Don't touch $SHLVL if not interactive
It's not super clear what $SHLVL is useful for, but the current
definition is essentially
"number of shells in the parent processes + 1"

which isn't *super useful*?

Bash's behavior here is a bit weird in that it increments $SHLVL
basically always, but since it auto-execs the last process it will
decrement it again, so in practice it's often not incremented.

E.g.

```
> echo $SHLVL
1
> bash -c 'echo $SHLVL; bash'
2
>> echo $SHLVL
2
```

Both bashes here end up having the same $SHLVL because this is
equivalent to `echo $SHLVL; exec bash`. Running `echo $SHLVL` and then
`bash -c 'echo $SHLVL'` in an interactive bash will have a different
result (1 and 2) because that doesn't *exec* the inner bash.

That's not something we want to get into, so what we do is increment
$SHLVL in every interactive fish. Non-interactive fish will simply
import the existing value.

That means if you had e.g. a bash that runs a fish script that ends up
opening a new fish session, you would have a $SHLVL of *2* - one for the
bash, and one for the inner fish.

We key this off is_interactive_session() (which can also be enabled
via `fish -i`) because it's easy and because `fish -i` is asking for
fish to be, in some form, "interactive".

That means most of the time $SHLVL will be "how many shells am I deep,
how often do I have to `exit`", except for when you specifically asked
for a fish to be "interactive". If that's a problem, we can rethink it.

Fixes #7864.
2021-03-29 17:44:13 +02:00
ridiculousfish
0f0995cad0 Remove unused COMMAND_NOT_BUILTIN enum
This was an enum whose values were never used; we can just remove it.
2021-03-28 22:19:36 -07:00
ridiculousfish
0aec597a36 Switch a cast from C style to C++ style 2021-03-28 20:04:34 -07:00
ridiculousfish
48868e5667 Switch builtin execution to the performer model
In preparation for concurrent execution, introduce a
`get_performer_for_builtin` function. This function itself returns a
function, which when called will run the builtin. The idea is that the
function may be called on a background thread (but not in this commit).
2021-03-28 15:31:25 -07:00
ridiculousfish
fb92ad946b Rework null terminated arrays
Several functions including wgetopt and execve operate on null-terminated
arrays of nul-terminated pointers: a list of pointers to C strings where
the last pointer is null. Prior to this change, each process_t stored its
argv in such an array. This had two problems:

1. It was awkward to work with this type, instead of using std::vector,
etc.
2. The process's arguments would be rearranged by builtins which is
surprising

Our null terminated arrays were built around a fancy type that would copy
input strings and also generate an array of pointers to them, in one big
allocation.

Switch to a new model where we construct an array of pointers over
existing strings. So you can supply a `vector<string>` and now
`null_terminated_array_t` will just make a list of pointers to them. Now
processes can just store their argv in a familiar wcstring_list_t.
2021-03-28 15:31:25 -07:00
ridiculousfish
e0e4b11dbd Make arguments to builtins const
Prior to this change, builtins would take their arguments as `wchar_t **`.
This implies that the order of the arguments may be changed (which is
true, `wgetopter` does so) but also that the strings themselves may be
changed, which no builtin should do.

Switch them all to take `const wchar_t **` instead: now the arguments may
be rearranged but their contents may no longer be modified.
2021-03-28 15:31:25 -07:00
ridiculousfish
0b06a0ee07 Further refactoring of builtin_set
This rearranges some error handling to centralize it, and performs
additional cleanup.
2021-03-28 15:31:25 -07:00
ridiculousfish
6c46ea0ed2 Refactor builtin_set
This cleans up builtin_set a bit, with the meat of the change being
reworking `parse_index` into `split_var_and_indexes`.

`parse_index` was a function that split a string like `foo[1 3..5]` into
its variable name `foo` and the indexes (here `1 3 4 5`). It had a funny
interface where it would modify a C string in-place. Switch it to return a
`split_var_t` which is a little struct wrapping up the split operation.
This simplifies memory management, and also avoids modifying the arguments
to the builtin.
2021-03-28 15:31:25 -07:00
ridiculousfish
abc66511f5 Simplify main thread requests
This replaces the main_thread_request struct with just a simple
function.
2021-03-28 15:31:25 -07:00
ridiculousfish
05d8907071 Remove the completion form of iothread_perform
Previously iothread_perform could do something on a background thread, and
then do something on the main thread. But we no longer use that second
part: instead everything goes through debounce. Remove the completion
parameter from iothread_perform.
2021-03-28 15:31:25 -07:00
Ilan Cosman
c762c62464 Add max and min math functions 2021-03-28 13:22:44 -07:00
ridiculousfish
a5ea8570ae Properly syntax highlight commands that get entered too fast
This fixes the following problem: if a command is entered while the
previous command is still executing, fish will see it all at once and
execute it before syntax highlighting as a chance to start. So the
command will appear wrong on the terminal. Fix this by detecting this
case and performing a fast no-io highlight.

An example of how to reproduce this:
run `sleep 3` and then type `echo foo` while the sleep is still running.
2021-03-28 12:52:59 -07:00
Fabian Homborg
4e4852c40a history: Improve bash import check
- Check for special characters *before* attempting to parse
- Also ignore lines with `{` and `*`
- Also skip lines with `<<` because that might be a heredoc (or a
- `<<<` herestring)

Fixes #7874.
2021-03-28 20:30:37 +02:00
Fabian Homborg
e7abb52526 Remove special "default" value for $fish_history
This is really of very little use and makes checking $fish_history
harder because it makes two values mean the same thing.

Fixes #7650
2021-03-28 12:09:58 +02:00
ridiculousfish
b44f40547b Rationalize exit codes for failed execs
This cleans up some exit code processing. Previously a failed exec
would produce exit code 125 unconditionally, while a failed posix_spawn
would produce exit code 1 (!).

With this change, fish reports exit code 126 for not-executable, and 127
for file-not-found. This matches bash.
2021-03-27 21:37:46 -07:00
ridiculousfish
694e112a9b Do not implicitly pass .fish files to /bin/sh
This expands the heuristic introduced in #7802 to prevent implicitly
passing files ending in .fish to /bin/sh.
2021-03-27 19:17:18 -07:00
ridiculousfish
eb71e4555f Clean up and relnote shebangless script support
This adds a test for shebangless support from #7802, cleans up some of
its tricks, and includes it in the changelog.
2021-03-27 16:08:42 -07:00
Justine Tunney
0048730a67 Allow more scripts without #!
This change modifies the fish safety check surrounding execve / spawn so
it can run shell scripts having concatenated binary content. We're using
the same safety check as FreeBSD /bin/sh [1] and the Z-shell [5].  POSIX
was recently revised to require this behavior:

    "The input file may be of any type, but the initial portion of the
     file intended to be parsed according to the shell grammar (XREF to
     XSH 2.10.2 Shell Grammar Rules) shall consist of characters and
     shall not contain the NUL character. The shell shall not enforce
     any line length limits."

    "Earlier versions of this standard required that input files to the
     shell be text files except that line lengths were unlimited.
     However, that was overly restrictive in relation to the fact that
     shells can parse a script without a trailing newline, and in
     relation to a common practice of concatenating a shell script
     ending with an 'exit' or 'exec $command' with a binary data payload
     to form a single-file self-extracting archive." [2] [3]

One example use case of such scripts, is the Cosmopolitan C Library [4]
which configuse the GNU Linker to output a polyglot shell+binary format
that runs on Linux / Mac / Windows / FreeBSD / OpenBSD / NetBSD / BIOS.

Fixes jart/cosmopolitan#88

[1] 9a1cd36331
[2] http://austingroupbugs.net/view.php?id=1250
[3] http://austingroupbugs.net/view.php?id=1226#c4394
[4] https://justine.lol/cosmopolitan/index.html
[5] 326d9c203b
2021-03-27 13:46:11 -07:00
Fabian Homborg
df53d1415d
cd first, ask questions later (#7586)
cd: Just try to cd without checking first

Some filesystems are broken and error out on `stat(3)` of existing and
cd-able directories.

So we just try to `fchdir` and report errors later.

Fixes #7577.
2021-03-27 18:28:03 +01:00
Fabian Homborg
3255999794 Bravely set job control to full at startup
We have no idea why this was even a thing. For now simply set it to
"all"/"full" (why these two names? no idea) at startup and allow
changing it later.

Settting it *immediately* when defining the variable sets it too soon
because we don't have the interactive signal handlers
enabled (including the one for SIGTTOU), so let's first settle for
this little piece of awkwardness.

This needs widespread testing, so we merge it early, immediately after
the release.

Fixes #5036
Fixes #5832
Fixes #7721

(and probably numerous others)
2021-03-26 19:32:14 +01:00
Fabian Homborg
c1fe5be0ce parse_util: Remove locate_cmdsubst
We have *3* functions to find command substitutions, this is the most awkward.
2021-03-26 19:32:14 +01:00
Fabian Homborg
163f42ac62 tinyexpr: Remove invalid const
We const cast these, so they aren't actually const,
and const doesn't actually help with optimization or anything (because const_cast exists),
so I would rather remove this, because const_cast gives me both the heebies and the jeebies.
2021-03-26 19:30:38 +01:00
Fabian Homborg
cbd8f5f63e math: Add log2
This was already in the documentation as an example, now it is
actually working.

Fixes #7734
2021-03-26 19:30:38 +01:00
Fabian Homborg
7f7cfcf339 Only donate term if we're interactive *and* have the terminal
As it turns out otherwise fish would hang when sddm starts it as the login shell.

Belongs to #7842.
2021-03-22 17:00:43 +01:00
ridiculousfish
8d54d2b60e Skip long arguments in syntax highlighting path detection
When fish performs syntax highlighting, it attempts to determine which
arguments are valid paths and underline them. Skip paths whose length
exceeds PATH_MAX. This is an optimization: such strings are almost
certainly not valid paths and checking them may be expensive.

Relevant is #7837
2021-03-21 16:59:22 -07:00
ridiculousfish
cf35431af9 Reimplement wbasename and wdirname
Previously wbasename and wdirname wrapped the system-provided basename
and dirname. But these have thread-safety issues and some surprising
error conditions on Mac. Just reimplement these per the OpenGroup spec.

In particular these no longer trigger a null-dereference if the input
exceeds PATH_MAX.

Add some tests too.

This fixes #7837
2021-03-21 16:33:04 -07:00
ridiculousfish
6e1b324343 Add some tests for dirname and basename
This is in preparation for replacing our wrappers around the C versions,
with custom versions instead.
2021-03-21 16:32:58 -07:00
ridiculousfish
a7c37e4af4 Don't block certain error signals on background threads
Previously fish attempted to block all signals on background threads, so
that they would be delivered to the main thread. But on Mac, SIGSEGV
and probably some others just get silently dropped, leading to potential
infinite loops instead of crashing. So stop blocking these signals.

With this change the null-deref in #7837 will properly crash instead of
spinning.
2021-03-21 16:32:45 -07:00
Johannes Altmanninger
206543c55b fixup! Pass some parameters by reference/move 2021-03-21 19:46:49 +01:00
Johannes Altmanninger
508044bce1 Pass some parameters by reference/move 2021-03-21 19:41:36 +01:00
Johannes Altmanninger
516a70d9cb Misc cleanups
Some as suggested by lgtm.com
2021-03-21 19:41:36 +01:00
Fabian Homborg
1018cb2a81 echo: Buffer output and write it in one go
`streams.out.push_back` for fd_streams_t writes to the
fd *immediately*. We might want to introduce a general buffering
strategy, but in this case writing it in one go is the simplest and
seems acceptable - we already have constrained the argument size, so
just pushing it out should work well enough.

See #7836
2021-03-21 17:49:22 +01:00
Fabian Homborg
e4fd664bbb Only set modes after config.fish if we're *interactive*
013a563ed0 made it so we only try to
adjust terminal modes if we are in the terminal pgroup, but that's not
enough.

Fish starts background jobs in events inside its own pgroup, so

    function on-foo --on-event foo
        fish -c 'sleep 3' &
    end

would have the backgrounded fish try to fiddle with the terminal and
succeed.

Instead, only fiddle with the terminal if we're interactive (this
should probably be extended to other bits, but this is the particular
problematic part)

Fixes #7842.
2021-03-21 10:43:47 +01:00
Karolina Gontarek
e4eaca1032
Fix wrapping for cd (#7843) 2021-03-21 09:27:19 +01:00
Johannes Altmanninger
7fea321b3e
Use the correct case in completion pager (#7744)
Consider

	$ complete -c foo -a 'aab aaB' -f
	$ foo A<TAB>

since 28d67c8 we would insert the common prefix AND show the pager.
Due to case-insensitive comparison, "b/B" was considered to be part
of the prefix. Since the prefix is added to each pager item [1]
we get wrong results. Fix this by removing the insensitive comparison
between completions - I don't think it was of much use anyway.
Commandline tokens are still matched case-insensitively, this is
just about completions.

Test this by running interactive fish inside tmux (pexpect's terminal
emulation not have enough capabilities).  Also add tests for recent
interactive regressions #7526 and #7738.

Closes #3978

[1]: b38a23a would solve this differently by giving every pager item
its own prefix, but was reverted since it needs more fixes.
2021-03-21 09:25:29 +01:00
Fabian Homborg
d79f864072 Add a note for help thing to the missing doc error message
This should cover most cases - the user didn't install the docs and is
trying to view the man page via __fish_print_help, so we don't have a
way to show anything.

But `help thing` will fall back to the online version of the docs,
which should work if there's an internet connection.

See #7824.
2021-03-19 17:39:36 +01:00
Fabian Homborg
02699d1acc Reject empty variable names
This allowed `set "" foo`, which is bogus and results in an unusable variable.
2021-03-18 19:36:57 +01:00
Johannes Altmanninger
f9e131aa93 Show an error when "builtin -h" fails to find a man page
Prior to this commit "builtin -h" would silently fail when no
documentation is installed. This happens when running fish without
installing it, or when the docs are not installed.

See #7824
2021-03-15 23:07:08 +01:00
Johannes Altmanninger
865abebd11 Simplify highlight tests by changing into dedicated test dir 2021-03-13 17:51:49 +01:00
Fabian Homborg
29ebd4a5ff tests: Don't break when a file unexpectedly exists
Creating a file called "xfoo" could break the highlight tests because
we'd suddenly get a color with valid_path set to true.

So what we do is simply compare foreground/background and forced
underline, but only check for path validity if we're expecting a valid
path.

If we're not expecting a valid path, we don't fail whether it is there
or not.

This means that we can't check for a non-valid path, but we don't
currently do that anyway and we can just burn that bridge when we get
to it.

cc @siteshwar @krobelus, who both came across this
2021-03-13 17:25:23 +01:00
ridiculousfish
3cb105adbd Restore terminal modes after running key bindings with external commands
This concerns the behavior when running an external command from a key
binding. The history is:

Prior to 5f16a299a7, fish would run these external commands in shell
modes. This meant that fish would pick up any tty changes from external
commands (see #2114).

After 5f16a299a7, fish would save and restore its shell modes around
these external commands. This introduced a regression where anything the
user typed while a bound external command was executing would be echoed,
because external command mode has ECHO set in c_lflag. (This can be
reproed easily with `bind -q 'sleep 1'` and then pressing q and typing).
So 5f16a299a7 was reverted in fd9355966.

This commit partially reverts fd9355966. It has it both ways: external
commands are launched with shell modes, but/and shell modes are restored
after the external command completes. This allows commands to muck with
the tty, as long as they can handle getting shell modes; but it does not
enable ECHO mode so it fixes the regression found in #7770.

Fixes #7770. Fixes #2114 (for the third time!)

This partially reverts commit fd9355966e.
2021-03-10 22:36:33 -08:00
Fabian Homborg
fd9355966e Stop donating the terminal for bind functions
Unfortunately this causes input coming in while bind functions are
running to show up on screen.

Since the cure is worse than the disease let's just stop doing it.

My guess is this needs to *only* be done while running an external
command.

Fixes #7770
Reintroduces #2114

Partially reverts 5f16a299a7
2021-03-10 21:21:19 +01:00
Fabian Homborg
013a563ed0 Only modify terminal modes after config.fish if we have the terminal
This tried fiddling with the terminal even if fish didn't own it, e.g.
in

    fish -c 'sleep 5' &

Fixes #7808.
2021-03-10 09:38:16 +01:00
Fabian Homborg
daa3cc17c4 Fix crash in string pad
Try:

    string pad -w 8 he \eh
2021-03-09 18:36:02 +01:00
Fabian Homborg
a7df92e187 Fix crash with set_color --print-colors --background normal
Found in conjunction with #7805.
2021-03-09 13:46:08 +01:00
Fabian Homborg
4762d52e52 output: A background is set if it's not a special non-color
For reasons unclear to me, fish enables bold mode unconditionally if
the background is set.

However, this called a background "set" if it wasn't exactly the
"normal" color, whereas set_color --print-colors would set a color
of *none*.

We have three special non-color colors:

- "normal"
- "reset"
- "none"

All of these specify some form of absence of background color, so all
of them should be checked.

Fixes #7805
2021-03-09 13:25:00 +01:00
Ilya Grigoriev
762f3aa0ce
Rewrite the real file if history file is a symlink (#7754)
* Rewrite the real file if history file is a symlink

When the history file is a symbolic link, `fish` used to overwrite
the link with a real file whenever it saved history. This makes
it follow the symlink and overwrite the real file instead.

The same issue was fixed for the `fish_variables` file in 622f2868e
from https://github.com/fish-shell/fish-shell/pull/7728.
This makes `fish_history` behave in the same way. The implementation
is nearly identical.

Since the tests for the two issues are so similar, I combined them
together and slightly expanded the older test.

This also addresses https://github.com/fish-shell/fish-shell/issues/7553.

* Add user-facing error when history renaming fails

Currently, when history file renaming fails, no message is shown to the
user. This happens, for instance, if the history file is a symlink
pointing to another filesystem.

This copies code (with a bit of variation, after reviewer comments) from

589eb34571/src/env_universal_common.cpp (L486-L491)

into `history.cpp`, so that a message is shown to the user.

* fixup! Rewrite the real file if history file is a symlink
2021-03-08 17:46:17 +01:00
Fabian Homborg
dbb74f87ba Re-read terminal modes after config.fish
Before now, we would be getting the terminal modes before config.fish,
then running config.fish without any of the term "stealing" and modes
copying. This meant that changes made to the terminal modes in there
were simply lost.

So, what we do is simply set the modes before config and then copy
them after, once.

Note that this does *not* turn off flow control again - if you turn it
on in config.fish that should work.

Fixes #7783.
2021-03-07 11:23:59 +01:00
Fabian Homborg
371516382d Create job-exit caller events inside event handlers
f7e2e7d26b forbid any job exit events
from happening inside jobs that were themselves event handlers, but
that causes e.g.

```fish
function f --on-event fish_prompt
source (echo "echo hello world" | psub)
end
```

to not trigger psub's cleanup, so it leaves files in $TMPDIR behind.

This was hit by pyenv, because that still uses `source (thing |
psub)`.

Fixes #7792.
2021-03-07 10:00:52 +01:00
Fabian Homborg
25d85bdc64 path_get_path: Remove error on unknown errno
This seems like a good idea, but there isn't anything we or anyone
else can *do* in this case. All we ever do is pile on additional
errors on the ignore pile, we can't handle any of them differently.
The command isn't a thing, so we check the next path.

The impetus for this is Cygwin apparently returning a wonderfully
useless 0, and it's not even the first one to do so.

Fixes #7785
2021-03-06 08:12:27 +01:00
Mahmoud Al-Qudsi
11951a245f Optimize pruning of job/proc exit handlers
Pre-emptively delete the handler while we have possession of the lock
before calling the event itself. It's crude, but it works.
2021-03-05 22:40:06 -06:00
Mahmoud Al-Qudsi
e7398c0248 Prune job exit handlers after running
While pid values may be reused, it is logical to assume that fish event
handlers coded against a particular job or process id mean just the job
that is currently referred to be any given pid/pgrp rather than in
perpetuity.

This trims the list of registered event handlers nice and early, and as
a bonus avoids the issue described in #7721.

The cleanup song-and-dance is extremely ugly due to the repeated locking
and unlocking of the event handler list.

Closes #7221.
2021-03-05 22:32:57 -06:00
Fabian Homborg
6bc0064a2a demangled_backtrace: Cast a thing to const char* instead of char*
Apparently this is const char* on NetBSD, so it complains.

Since it should be harmless to allow this one to be const, just do
that.
2021-03-05 19:40:44 +01:00
Fabian Homborg
c96a07dc96 Revert "Prevent redirecting internal processes to file descriptors above 2"
FDs are inherited, and redirecting those is harmless, and forbidding
that is worse than allowing all.

Fixes #7769.

This reverts commit 11a373f121.
2021-03-03 22:26:33 +01:00
Fabian Homborg
791b42f065 Disable SIGIO notifier
It doesn't work on WSL, Solaris and Archlinux (and presumably that
means future versions of other linux distros).

In its current state I don't trust it enough to enable it anywhere by
default, especially since I'm not aware of an actual issue with the
named pipe (other than that the code is ugly).

Fixes #7774
2021-03-03 22:26:28 +01:00
Fabian Homborg
955c0003ca fd_monitor: Explicity include <thread>
Might fix issues with gcc 11.0.1.

See #7764.
2021-03-02 15:27:13 +01:00
Fabian Homborg
119b978cbc type: Add --quiet back
It's supposed to be *deprecated*, not removed. The documentation even
specifically calls it out.

Fixes #7766
2021-03-02 14:53:02 +01:00
Érico Rolim
d948b34420 Include <termios.h> instead of <sys/termios.h>.
Slipped by with ffa24eb361. Given
daf5ef1bbd, fish should be using
<termios.h> in all cases.
2021-03-02 12:05:07 +01:00
Fabian Homborg
abaa057e5c Replace our only dynamic_cast with old-school casting
dynamic_cast requires rtti to be enabled. Now, this isn't a big
problem, but since this is our only dynamic_cast in the entire
codebase, and it's not serving an important function, we can just
replace it.

See #7764
2021-03-02 09:44:23 +01:00
Fabian Homborg
6b6f8d2295 Avoid changing how custom fish_titles are called
This half-reverts commit a3cb1e2dcd,
avoiding the bit that passed arguments differently.

Note that this means the initial bug is kept in the hardcoded fallback title.

Fixes #7749.
2021-02-28 08:40:39 +01:00
Fabian Homborg
459ac2b566 Reset the readline loop state when setting the buffer
Fixes #7740.
2021-02-25 16:19:28 +01:00
Mahmoud Al-Qudsi
42d9f33e16 Use a platform whitelist for opting into the SIGIO notifier
My bet is that the Illumos, Cygwin, and WSL are not the only Unix-like
systems where the SIGIO notifier won't work, and since we have a good
enough and portable alternative that we can use be default on other
platforms where we don't specifically know it'll work, it doesn't make
sense not to go with that one instead.

Even if this patch is reverted at some point and we go back to
blacklisting platforms that *don't* support the SIGIO strategy, this is
almost certainly the right choice for inclusion in a minor release like
3.2.0.

See discussion in #6585.
2021-02-24 14:40:17 -06:00
Mahmoud Al-Qudsi
ffa24eb361 Fix build on Solaris (and hopefully OpenIndiana)
* memset/memzero needs cstring/string.h (again)
 * winsize_t requires an impl from <sys/termios.h>

With this patch, I was able to get fish master to build on Solaris 11.4
without any additional dependencies (after installing gcc 7, git, and
cmake). I think the ncurses dependency can be dropped from the
OpenIndiana package?
2021-02-23 11:02:55 -06:00
Mahmoud Al-Qudsi
d95e99f2d4 Fix missing memset/memzero on Illumos
Tested w/ GCC 9 under OpenIndiana 2020.
2021-02-22 20:58:42 -06:00
Mahmoud Al-Qudsi
17926a9197 Allow low-level tests to at least run to completion under Cygwin
They still don't pass due to path differences, but at least they run to
completion so we can tell just how broken everything is.
2021-02-22 16:27:45 -06:00
Mahmoud Al-Qudsi
d769582023 Ignore intentional redundant move under GCC
This bubbled up after Wredundant-move was added to the build script and
was observed under the CI environment running GCC 9.3.0.
2021-02-22 15:55:40 -06:00
Fabian Homborg
d0a8493844 Don't open pager with only one completion
Since smartcase, we could land in a situation where we offer one
option in the pager, which is awkward.

So detect this and just insert the option directly, we can add any
more smartness later.

Fixes #7738.
2021-02-22 22:51:52 +01:00
Mahmoud Al-Qudsi
1305a0899c Fix comparison warnings on UTF-16 platforms
Without true handling of UTF-16 surrogate pairs, all we can do is
properly detect the BMP range in UTF-16 environments and bail if the
input is in a non-BMP region.

There isn't much else we can do as it is incorrect to encode the
surrogate pairs themselves (fish doesn't know what to do with them and
they're illegal under either of UTF-8 or UTF-32).

(I'm not aware of fish being used in any UTF-16 platforms other than
Cygwin.)
2021-02-22 15:03:49 -06:00
Mahmoud Al-Qudsi
215df7eec6 Extend PCRE2 wchar_t interop support to 16-bit wchar_t impls
Previously, the interop glue for more friendly access to PCRE2's
fixed-size values was only used when char32_t/wchar_t were
interchangeable and PCRE2 was used with a global 32-bit unit width set;
this patch extends the same to char16_t when wchar_t is also 16-bits
(namely on Cygwin) to avoid compilation fpermissive warnings about casts
between types of potentially different sizes.

Reported in #6585.
2021-02-22 13:51:29 -06:00
Mahmoud Al-Qudsi
2cf5fd3d5d Avoid hard compilation errors on platforms w/out O_ASYNC
Those platforms should not be using the sigio notifier in the first
place, this just stops them from failing to be able to compile fish
altogether.

See #6585
2021-02-21 22:39:32 -06:00
ridiculousfish
11a373f121 Prevent redirecting internal processes to file descriptors above 2
The user may write for example:

    echo foo >&5

and fish would try to output to file descriptor 5, within the fish process
itself. This has unpredictable effects and isn't useful. Make this an
error.

Note that the reverse is "allowed" but ignored:

    echo foo 5>&1

this conceptually dup2s stdout to fd 5, but since no builtin writes to fd
5 we ignore it.
2021-02-20 16:16:45 -08:00
Ilya Grigoriev
622f2868e1 Fix set -U when fish_variables is a symlink
Previously, `set -U` would overwrite the symlink with a
regular file.

Fixes https://github.com/fish-shell/fish-shell/issues/7466
2021-02-20 14:24:11 -08:00
ridiculousfish
8648f52857 Use wcs2string when outputting the screen
The screen output code predates the ENCODE_DIRECT scheme, and
directly-encoded bytes were not being properly output. This manifested as
private-user characters being mangled when printed as part of fish_prompt.
Just use str2wcstring instead.

Fixes #7723
2021-02-17 15:38:46 -08:00
ridiculousfish
f1b6a5939d Introduce wcs2string_appending
wcs2string_appending is like wcs2string, but appends to a std::string
instead of creating a new one. This will be more efficient when a string
can be reused, or if we want to accumulate multiple wcstrings into a
single std::string.
2021-02-17 15:36:22 -08:00
ridiculousfish
fce485e6a8 Rename bufferCount_ to buffer_count_
fish uses snake case for naming.
2021-02-17 14:25:32 -08:00
Mahmoud Al-Qudsi
774488686c Correct handling of SGR mouse tracking events
They are of variable length, taking semicolon-separated ASCII characters
and not single chars/bytes as the parameters. Additionally, the global
maximum size for a CSI is 16 characters (NPAR), even though I believe
the maximum possible mouse-tracking CSI is 12 characters.
2021-02-17 15:45:35 -06:00