Commit Graph

4209 Commits

Author SHA1 Message Date
ridiculousfish
1da952450f Migrate the "Apple Term hacks" from set_color to init_curses
Apple's terminfo has missing support for enter_italics_mode,
exit_italics_mode, and enter_dim_mode. Previously we would hack in such
support in set_color; migrate that to init_curses so we do it up-front
instead of opportunistically.
2022-04-16 13:26:42 -07:00
ridiculousfish
4b96dd9908 Mild refactoring of initialize_curses_using_fallbacks
No functional change here.
2022-04-16 12:45:25 -07:00
ridiculousfish
3d98fd4308 clang-format env.cpp and env_dispatch.cpp 2022-04-16 12:22:44 -07:00
ridiculousfish
1a4b1c3298 Remove the is_first parameter from tok_is_string_character
This parameter is unused now that carets are no longer special, per
7f905b082.
2022-04-16 10:47:01 -07:00
Fabian Homborg
2fa51f1843 Add $EUID and use it in fish_is_root_user
Fixes #8866
2022-04-15 15:58:39 +02:00
Fabian Homborg
c2bca939be Let stderr-nocaret description say it's read-only 2022-04-15 13:42:38 +02:00
Fabian Homborg
49eb07f98f Enable ampersand-nobg-in-token by default
To recap, this means `&` in the middle of a word no longer
backgrounds.

So:

```fish
echo foo&bar # prints foo&bar
echo foo& bar # backgrounds an echo that prints "foo" and runs "bar"
```
2022-04-15 13:42:38 +02:00
Fabian Homborg
7f905b082d Remove caret redirection code
It's dead, Jim.
2022-04-15 13:42:38 +02:00
Fabian Homborg
74be3e847f Force stderr-nocaret feature flag on
This can no longer be changed. If "no-stderr-nocaret" is in
$fish_features it will simply be ignored.

The "^" redirection that was deprecated in fish 3.0 is now gone for good.

Note: For testing reasons, it can still be set _internally_ by running
"feature_flags_t::set". We simply shouldn't do that.
2022-04-15 13:42:38 +02:00
Fabian Homborg
59c2ed9acf Turn on regex-easyesc by default
This was introduced in fish 3.1. It removes a superfluous round of
escaping in the replacement for `string replace -r`.

Part of #8857.
2022-04-15 13:42:38 +02:00
Michael Jarvis
970cf45166 Remove test for italics_mode and dim_mode on Apple
This resolves an issue where fish crashes with SIGSEGV if the TERM environment
variable is not set.

See:
- https://github.com/fish-shell/fish-shell/issues/8873
- https://github.com/microsoft/vscode/issues/147320
2022-04-14 15:05:13 +02:00
Fabian Homborg
fd942e04cd Also change the MAX_ARG_STRLEN message
Missed in 1326c286fa
2022-04-13 17:07:42 +02:00
Fabian Homborg
a5ce01cc38 Print a hint if the exported variables appear too large
If we get an E2BIG while executing a process, we check how large the
exported variables are. We already did this, but then immediately
added it to the total.

So now we keep the tally just for the variables around, and if it's
over half (which is an atypical value if your system has an ARG_MAX of
2MB), we mention that in the error.

Figuring out which variable is too big (in case it's just one) is probably too complicated,
but we can at least complain if things seem suspect.

Untested because I don't know *how* to do so portably
2022-04-12 19:41:26 +02:00
Fabian Homborg
1326c286fa Reword ARG_MAX error messages
We're the shell. The "environment list" is our exported variables
2022-04-12 19:37:15 +02:00
Fabian Homborg
29e02ac7a5 Add missing argument to MAX_ARG_STRLEN error
This was missed in b395b33776.

No need to relnote, it's trivial
2022-04-12 15:23:45 +02:00
ridiculousfish
143757e8c6 Expand wildcards on tab
Prior to this change, if you tab-completed a token with a wildcard (glob), we
would invoke ordinary completions. Instead, expand the wildcard, replacing
the wildcard with the result of expansions. If the wildcard fails to expand,
flash the command line to signal an error and do not modify it.

Example:

    > touch file(seq 4)
    > echo file*<tab>

becomes:

    > echo file1 file2 file3 file4

whereas before the tab would have just added a space.

Some things to note:

1. If the expansion would produce more than 256 items, we flash the command
line and do nothing, since it would make the commandline overfull.

2. The wildcard token can be brought back through Undo (ctrl-Z).

3. This only kicks in if the wildcard is in the "path component
   containing the cursor." If the wildcard is in a previous component,
   we continue using completions as normal.

Fixes #954.
2022-04-10 13:53:22 -07:00
ridiculousfish
1023d322e5 Rationalize tilde unexpansion
When fish expands a string that starts with a tilde, like `~/stuff/*`, it
first must resolve the tilde (e.g. to the user's home directory) before
passing it to wildcard expansion. The wildcard expansion will produce full
paths like `/home/user/stuff/file`. fish then "unexpands" the home directory
back to a tilde.

Previously this was only used during completions, but in the next commit
we plan to use it for string expansions as well.

Rationalize this behavior by adding an explicit flag to request it and
explain some subtleties about completions.
2022-04-10 13:41:21 -07:00
ridiculousfish
2d945afd58 Factor applying completions out of handle_readline_command
The handle_readline_command function is getting unwieldy, so factor it
better to reduce its length. No functional change here.
2022-04-10 13:41:21 -07:00
ridiculousfish
cb027bfdc0 str2hex to work in std::string instead of malloc
Reimplement a test function using nicer C++ types. No functional change here.
2022-04-09 15:19:18 -07:00
ridiculousfish
031b26584b Revert "input.cpp: remove unused describe_char()"
This reverts commit 99cfca8498.

describe_char is quite useful for debugging.
2022-04-09 13:48:03 -07:00
ridiculousfish
1c7b934402 Revert "Replace some simple loops with STL algorithms"
This commit was problematic for a few reasons:

1. It silently changed the behavior of argparse, by switching which
characters were replaced with `_` from non-alphanumeric to punctuation.
This is a potentially breaking change and there doesn't appear to be any
justification for it.

2. It combines a one-line if with a multi-line else which we should try
   to avoid.

This reverts commit 63bd4eda55.
This reverts commit 4f835a0f0f.
2022-04-09 12:12:16 -07:00
ridiculousfish
735962d306 Remove macros for block descriptions
These macros were historically used only in internal error messages which
should never happen! Now we are able to enforce they never happen at
compile time so we can remove them.

No functional change here.
2022-04-09 11:42:58 -07:00
Aaron Gyes
0118eafee1 Remove unused functions, members (and a variable)
If we ever need any of these... they're in this commit:

fish_wcswidth_visible()
status_cmd_opts_t::feature_name
completion_t::is_naturally_less_than()
parser_t::set_empty_var_and_fire()
parser_t::get_block_desc()
parser_keywords_skip_arguments()
parser_keywords_is_block()
job_t::has_internal_proc()
fish_wcswidth_visible()
2022-04-09 10:10:44 -07:00
Aaron Gyes
63bd4eda55 iswpunct not available in std:: namespace on some machines
Fixes the tests
2022-04-08 19:54:42 -07:00
Aaron Gyes
4f835a0f0f Replace some simple loops with STL algorithms
src/builtins/argparce.cpp: replace_if
src/builtins/set.cpp: count_if
src/topic_monitor.h: any_of
2022-04-08 17:59:09 -07:00
Aaron Gyes
7d1d43744a trivial cleanup 2022-04-08 17:59:09 -07:00
Aaron Gyes
99cfca8498 input.cpp: remove unused describe_char() 2022-04-08 17:59:09 -07:00
Aaron Gyes
9c1b3d6712 fix cppcheck missing return errors 2022-04-08 17:59:09 -07:00
Fabian Homborg
b0c2d083d6 set: Add special error for set foo=bar
Fixes #8694

Only for setting, erasing with a value makes no sense.
2022-04-08 16:50:34 +02:00
Fabian Homborg
31e2476fc8 Clarify that the variable/mode *name* is invalid
When you do

```fish
set foo-bar baz
```

"foo-baz" isn't usable as a variable *name*. When you just say the
"variable" is invalid that could also be interpreted to be a special
type of variable or something.
2022-04-08 16:38:46 +02:00
Aaron Gyes
7031a736a7 don't check if unsigned el->position() < 0 2022-04-07 10:16:26 -07:00
Aaron Gyes
77d02c1bd6 parse_execution: remove unused 'job' parameters 2022-04-07 09:36:54 -07:00
Aaron Gyes
8ea2be2648 decrease scope of a couple variables, prefix incr non-primitives 2022-04-07 09:25:16 -07:00
Aaron Gyes
5861358238 const size_t vals[4] 2022-04-07 09:25:16 -07:00
Aaron Gyes
b514ec5fe6 append_narrow_buffer takes const reference 2022-04-07 09:25:16 -07:00
Aaron Gyes
c06d85d175 proc.cpp: remove unused s_is_within_fish_initialization 2022-04-07 09:25:16 -07:00
Johannes Altmanninger
4b5b56452b Make string syntax error location a bit more precise
String tokens are subdivided by command substitutions. Some syntax errors
can occur in the gap between two command substitutions. Make the caret point
to the start of that gap, instead of the token start.
2022-04-03 16:34:46 +02:00
Johannes Altmanninger
e717b13e75 Fix spurious syntax error on escaped $@ inside quoted command substitution
We detect use of unsupported features like $@ by scanning string tokens
as a whole. With quoted command substitution, this has false positives,
as reported in [1]. We already recursively run the same error checks on
command substitutions, so limit the remaining checks to the gaps in-between
command substitutions.

[1]: 5f94dfd094/.config/fish/README/bug.md (cannot-use-dollar-anchor-in-sed-regex-in-quoted-command-substitution)
2022-04-03 16:18:47 +02:00
Johannes Altmanninger
3e3f507012 Fix regression expanding \$()
When expanding command substitutions, we use a naïve way of detecting whether
the cmdsub has the optional leading dollar. We check if the last character was
a dollar, which breaks if it's an escaped dollar.  We wrongly expand
\$(echo "") to the empty string. Fix this by checking if the dollar was escaped.

The parse_util_* functions have a bunch of output parameters. We should
return a parameter bag instead (I think I tried once and failed).
2022-04-03 15:54:08 +02:00
Johannes Altmanninger
1b668f5675 Don't use results of quoted command substitution in adjacent variable expansion
Given

    set var a
    echo "$var$(echo b)"

the double-quoted string is expanded right-to-left, so we construct an
intermediate "$varb".  Since the variable "varb" is undefined, this wrongly
expands to the empty string (should be "ab"). Fix this by isolating the
expanded command substitution internally. We do the same when handling
unquoted command substitutions.

Fixes #8849
2022-04-03 11:24:55 +02:00
ridiculousfish
1a0b1ae238 Rename indent test test_t to indent_test_t
This satifies VSCode's C++ extension which otherwise throws up a bogus
error. No functional change here.
2022-04-02 19:07:27 -07:00
ridiculousfish
a80e680125 Clean up woption
1. Bravely use a real enum for has_arg, despite the warnings.

2. Use some C++11 initializers so we don't have to pass an int for this
   parameter.

No functional change expected here.
2022-04-02 11:28:30 -07:00
ridiculousfish
002c2b6170 Correct a cast when measuring history file size
If the history file is larger than 4GB on a 32 bit system, fish will
refuse to read it. However the check was incorrect because it cast the
file size to size_t, which may be 32 bit. Switch to using uint64.
2022-04-01 10:25:05 -07:00
ridiculousfish
a91e1a8cab Revert "history_file_contents_t::create: remove constant comparison"
This reverts commit d7b4193978.

off_t may be wider than size_t on a 32 bit system so the comparison is
justified (though the cast is not).
2022-04-01 10:18:06 -07:00
Aaron Gyes
d7b4193978 history_file_contents_t::create: remove constant comparison
static_cast<unsigned long>(off_t len) is always < SIZE_MAX
2022-04-01 09:23:44 -07:00
ridiculousfish
338d587f2a Correct bug causing early teardown of fd_monitor
fd_monitor is used when an external command pipes into a buffer, e.g. for
command substitutions. It monitors the read end of the external command's
pipe in the background, and fills the buffer as data arrives. fd_monitor is
multiplexed, so multiple buffers can be monitored at once by a single
thread.

It may happen that there's no active buffer fill; in this case fd_monitor
wants to keep its thread alive for a little bit in case a new one arrives.
This is useful for e.g. handling loops where you run the same command
multiple times.

However there was a bug due to a refactoring which caused fd_monitor to
exit too aggressively. This didn't affect correctness but it meant more
thread creation and teardown.

Fix this; this improves the aliases.fish benchmark by about 20 msec.

No need to changelog this IMO.
2022-03-31 20:41:58 -07:00
ridiculousfish
a960a3cde6 Emit an error if time is used past the first command in a pipeline
Fixes #8841
2022-03-31 16:14:59 -07:00
ridiculousfish
247d4b2c8f Rename EXEC_ERR_MSG to INVALID_PIPELINE_CMD_ERR_MSG
This error message was used for more than exec.
No functional change here.
2022-03-31 15:49:15 -07:00
Fabian Homborg
f13979bfbb Move executable-check to C++
This was already apparently supposed to work, but didn't because we
just overrode errno again.

This now means that, if a correctly named candidate exists, we don't
start the command-not-found handler.

See #8804
2022-03-31 15:16:01 +02:00
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