Commit Graph

4027 Commits

Author SHA1 Message Date
Johannes Altmanninger
d1683958cf Expand tildes and variables in command for custom completions
A «complete -C '~/fish-shell/build/fish '» fails to load custom
completions because we do not expand the ~, so
complete_param_for_command() thinks that this command is invalid.
Expand command tokens before loading custom completions.

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

    set -q --unpath PATH

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

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

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

* Adjust fish_key_reader docs

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

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

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

filename: File not found

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

E.g.

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

will now show:

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

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

     > echo $FISH_\
       VERSION

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

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

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

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

	fish -C 'set -g fish_autosuggestion_enabled 0'

instead of only in existing interactive sessions.

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

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

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

Negative values get a leading -, like:

    > math --base hex -10
    -0xa

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

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

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

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

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

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

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

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

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

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

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

They did this by doing the equivalent of

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

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

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

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

So instead we use the wcstring overload for now.
2021-10-27 10:20:14 +02:00