Commit Graph

3352 Commits

Author SHA1 Message Date
Fabian Homborg
5ee3eeff5d Remove the final two debug() calls 2020-11-07 10:20:52 +01:00
Mahmoud Al-Qudsi
640f4444f5 Disable SIGIO notifier on WSL
It currently does not trigger the uvar notifier and fails the automated
tests.

See #7429.
2020-11-06 20:49:44 -06:00
Fabian Homborg
65c5433662 Delete unused field
Fixes #7456.

[ci skip]
2020-11-06 17:44:09 +01:00
ridiculousfish
d3192d37a2 Allow timing-out I/O-able syntax highlighting after expanding abbreviation
It may happen that the user types an abbreviation and then hits return.
Prior to this commit, we would perform a form of syntax highlighting
that does not require I/O, so as to not block the user. However this
could cause invalid commands to be colored as valid.

More generally if the user has e.g a slow NFS mount, then syntax
highlighting may lag behind the user's typing, and be incorrect at the
time the user hits return. This is an unavoidable race, since proper
syntax highlighting may take arbitrarily long.

Introduce a new function `finish_highlighting_before_exec`, which waits
for any outstanding syntax highlighting to complete, BUT has a timeout
(250 milliseconds). After this, it falls back to the no-I/O variant, which
colors all commands as valid and nothing as paths.

Fixes #7418
Fixes #5912
2020-11-05 20:07:05 -08:00
ridiculousfish
c861fdadcf Remove return value from iothread_perform
It was not actually used by any test.
2020-11-05 19:28:26 -08:00
ridiculousfish
a2ff32d904 Stop caching line breaks in the prompt calculation
These are fast enough to find on demand.
2020-11-01 14:45:35 -08:00
Soumya
80aaae5b74 Clear to end of each line in left prompt 2020-11-01 13:29:26 -08:00
Fabian Homborg
2a07673561 Don't call a variable "stdin"
Musl has a macro that interferes.
2020-10-31 18:15:19 +01:00
Fabian Homborg
0951a706cf Let read read from fds other than 0
This allows

read </dev/tty

to work.

Fixes #7358
2020-10-31 13:39:20 +01:00
Fabian Homborg
d334dc6643 Let cancel after an unambiguous completion was accepted undo it
In some cases the completion we come up with may be unexpected, e.g.
if you have files like

/etc/realfile

and

/etc/wrongfile

and enter "/etc/gile", it will accept "wrongfile" because "g" and
"ile" are in there - it's a substring insertion match.

The underlying cause was a typo, so it should be easy to go back.

So we do a bit of magic and let "cancel" undo, but only right after a
completion was accepted via complete or complete-and-search.

That means that just reflexively pressing escape would, by default, get you back to
the old token and let you fix your mistake.

We don't do this when the completion was accepted via the pager,
because 1. there's more of a chance to see the problem there and 2.
it's harder to redo in that case.

Fixes #7433.
2020-10-30 19:37:44 +01:00
Johannes Altmanninger
5ff2d38d4c builtin time: print help on invalid syntax
I always mix up the order with variable assignments.
2020-10-26 19:25:41 +01:00
Fabian Homborg
a84d57b02b math: Actually report closing paren error
This was typically overridden by "too many/few arguments", but it's
actually incorrect:

    sin(55

has the correct number of arguments to `sin`, but it's lacking
the closing `)`.
2020-10-26 18:13:43 +01:00
Rosen Penev
cef84cf2c2 clang-tidy: use append
Found with performance-inefficient-string-concatenation

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-25 22:54:51 -07:00
Rosen Penev
334be56021 run codebase through clang-tidy
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-25 22:48:49 -07:00
Mahmoud Al-Qudsi
332287708b Prevent fish from re-importing an exported fish_user_paths
fish_user_paths is a fish-specific variable that can be persisted by
making it a universal variable or by making it a global variable set at
startup in `config.fish`.

Since it is not defined in a clean installation, a user could
inadvertently create it as `set -Ux fish_user_paths ....` the first
time, creating a horrible, ugly, self-loathing mess that will have you
chasing ghosts and bisecting for naught once fish re-imports
fish_user_paths as a *global* variable that shadows the universal one.

While that is true for any universal variable that is re-imported as a
global variable, only fish_user_paths has the potential to really screw
things up because we also re-export PATH based off of its value in turn.
2020-10-25 21:45:45 -05:00
ridiculousfish
a34b9036ba Enable SIGIO notifier on FreeBSD
Now that SIGIO works on FreeBSD, switch to that uvar notifier
2020-10-25 14:53:56 -07:00
ridiculousfish
e669c41d1b Fix up SIGIO notifier tests
FreeBSD has the behavior where SIGIO is delivered on a read. Teach the
tests how to handle this behavior.
2020-10-25 14:53:31 -07:00
ridiculousfish
8bb20a8d91 Remove use of POLL_IN in SIGIO uvar notifier
This fixes up the SIGIO notifier in preparation for using it on BSD. It
removes the reliance on the signal's si_code, which is not available in
BSD, and it properly handles the BSD behavior where SIGIO is delivered on
a read even if the read returns EAGAIN.
2020-10-25 14:52:37 -07:00
Mahmoud Al-Qudsi
3652bcf731 fixup! Fix assertion failure on job redirection error 2020-10-24 17:59:11 -05:00
Mahmoud Al-Qudsi
64671c64a1 Fix assertion failure on job redirection error
Fix an error caused by `exec_job()` assuming a job launched with the
intention of being backgrounded would have a pgid assigned in all cases,
without considering the status of `exec_error` which could have resulted
in the job failing before it was launched into its own process group.

Fixes (but doesn't close) #7423 - that can be closed if this assertion
failure doesn't happen in any released fish versions.
2020-10-24 16:15:40 -05:00
ridiculousfish
bbbbe00c81 Handle being launched with control of the tty, but not in own pgroup
It is apparently possible to launch fish such that its pid owns the tty,
but its pid is in a different pgroup. In that case, do not attempt to stop
with SIGTTIN; instead simply attempt to place fish in its own pgroup.

Fixes #7388
2020-10-18 14:37:31 -07:00
Fabian Homborg
5abc6060a4 Disable sigio notifier on FreeBSD
This fails for unknown reasons.

Not looking like a great *replacement* for the named pipe now, tbh.

See #7400.
2020-10-14 20:40:15 +02:00
Collin Styles
da0acb28ba Don't chomp foo= when completing foo=br
`complete_param_expand` knows how to handle cases like `foo=br` so we
don't need to bother sending just the `br` part. Furthermore, sending
just `br` is incorrect because we will end up replacing the entirety of
`foo=br` with the result of the completion. That is, `foo=br` will be
replaced with `bar` instead of being completed to `foo=bar`.
2020-10-14 18:35:54 +02:00
Johannes Altmanninger
ddf0a8e461 Refactor: slightly rework how variables are assigned during completion
Seems better since we now have two callers. This would be a good use case for
[[nodiscard]].
2020-10-10 13:00:47 +02:00
Johannes Altmanninger
8ef8fb3d94 Refactor: omit parens in lambdas with no parameters
TIL []{} is a thing.  We already do that in some places, so this improves
consistency, although it may be less obvious.
2020-10-10 13:00:24 +02:00
Johannes Altmanninger
c325603d73 Honor variable assignments on the commandline when completing files
This had already worked before although the implementation used to be rather
crude and was cleaned up in
e88eb508d0 (r42759188)
2020-10-10 12:59:55 +02:00
Johannes Altmanninger
eca2a8ba55 complete: print completions without the implied -c switch
This switch is no longer necessary when only one command is given.
Internally completions are stored separately for each command,
so we only every print one command name per "complete" line anyway.
2020-10-10 11:54:52 +02:00
Fabian Homborg
cc0e366037 history: Skip lines with tabs when importing from bash
Fixes #6923.
2020-10-09 18:54:47 +02:00
ridiculousfish
e9902159c2 Send fish_cancel event on control-C again
This adds support for sending fish_cancel, and a test for it.
Fixes #7384.
2020-10-06 17:49:55 -07:00
Fabian Homborg
e949b1de02 ifdef SIGIO handling
This relies on POLL_IN which apparently isn't a thing on OpenBSD
2020-10-06 17:34:50 +02:00
Fabian Homborg
289bce2f25 Add event flog
I needed this, and it should be there.

[ci skip]
2020-10-06 17:25:45 +02:00
Fabian Homborg
00ab51bedc set: Allow erasing multiple variables at once
See #7377.
2020-10-04 12:24:11 +02:00
ridiculousfish
f9e426813c Do not complain about fcntl(F_SETOWN) failing
On WSL1, fcntl(F_SETOWN) will fail and this would report an error.
Suppress this error message since it is not very interesting.
The effect is to disable real-time universal variable propagation.
2020-10-03 15:54:27 -07:00
ridiculousfish
558dd6e53d Add sigio-based universal notifier strategy
Introduce a new strategy for notifying other fish processes of universal
variable changes, as a planned replacement for the complex
strategy_named_pipe. The new strategy still uses a named pipe, but instead
of select() on it, it arranges for SIGIO to be delivered when data is
available. If a SIGIO has been seen since the last check, it means the file
needs to be re-read.
2020-10-01 13:19:41 -07:00
ridiculousfish
700fe4f131 Moderize universal variable notifiers
Use some C++11 features.
2020-10-01 13:27:13 -07:00
Fabian Homborg
bbdfe126a7 Flash if history search found nothing
This makes it clearer that we're at the end.

Fixes #7362.
2020-09-30 18:02:22 +02:00
Fabian Homborg
d6d3abf59a Introduce $FISH_DEBUG and $FISH_DEBUG_OUTPUT variables
Same as the `--debug` and `--debug-output` options, can be enabled
when the option can't be passed, e.g. in linux shebangs.

Fixes #7359.
2020-09-28 17:46:37 +02:00
ridiculousfish
c89c72f431 Invert sense of expand_flag::no_descriptions
When expanding a string, you may or may not want to generate
descriptions alongside the expanded string. Usually you don't want to
but descriptions were opt out. This commit makes them opt in.
2020-09-27 16:50:40 -07:00
Johannes Altmanninger
f758d39535 string pad: handle padding characters of width > 1
If the padding is not divisible by the char's width without remainder,
we pad the remainder with spaces, so the total width of the output is correct.

Also add completions, changelog entry, adjust documentation, add examples
with emoji and some tests.  Apply some minor style nitpicks and avoid extra
allocations of the input strings.
2020-09-27 21:59:15 +02:00
Johannes Altmanninger
5ae03414d7 Sort string subcommands, and use binary search for lookup
I have no idea if this is better, and did not attempt to measure it, but we
do the same for electric variables which are even fewer.
2020-09-27 21:59:15 +02:00
Andrew Prokhorenkov
92511b09c4 New command "string pad" to pad text to a given width (#7340)
Pads text to a given width, or the maximum width of all inputs.
2020-09-27 21:59:15 +02:00
Johannes Altmanninger
e8859b4ce2 Do not treat newlines special in bigword movements
Improves on #7328.

I believe this is the correct behavior, simply skip all whitespace before
a word. Try with

	./fish -C 'bind \ef forward-bigword; bind \eb backward-bigword; bind \ed kill-bigword; bind \cw backward-kill-bigword'

Also unrelated formatting fixes. I don't think a CI failure on unformatted
code is warranted but I wish it could do that behind the scenes.
2020-09-27 18:04:09 +02:00
Johannes Altmanninger
791d23502f Do not add a space after completing flag with optional argument
For example "grep --color"<TAB> can complete to "grep --color=".  Don't add
a space in this case; we do the same for arguments that end in =.

In GNU-style getopt, equal sign means that the flag has an argument. Without
the = it would not consume the next argument as opposed to Python's argparse.
2020-09-27 17:56:21 +02:00
sgrj
ab2cb03189
Consistency-fix for word motions (#7354)
* change word motion test to include start cursor in specification

* add test case for bug

* fix bug
2020-09-27 15:34:34 +02:00
Fabian Homborg
adb1f993a7 Reader: Turn *off* INLCR for external commands
That's how it worked previously, and it makes ctrl-j usable again.

Fixes #7352
2020-09-27 13:54:47 +02:00
Fabian Homborg
0f7e2ca99c Don't put commandline on a new line if prompt is "long"
This was a weird special behavior where we'd put the commandline on a
new line if it wrapped *and* the prompt was > 33% of the screen.

It seems to be more confusing than anything.

Fixes #5118.
2020-09-27 13:12:06 +02:00
ridiculousfish
e88eb508d0 Rework variable assignments during tab completion
Prior to this change, tab completing with a variable assignment like
`VAR=val cmd<tab>` would parse out and apply VAR=val, then recursively
invoke completions. This caused some awkwardness around the wrap chain -
if a wrapped command had a variable completion we risked infinite
recursion. A secondary problem is that we would run any command
substitutions inside variable assignment, which the user does not expect
to run until pressing enter.

With this change, we explicitly track variable assignments encountered
during tab completion, including both those explicitly given on the
command line and those found during wrap chain walk. We then apply them
while suppressing command substitutions.
2020-09-26 18:39:38 -07:00
ridiculousfish
cc07716dc1 Separate out variable assignments when completing
In preparation for applying variable assignments (VAR=VAL cmd), separate
them out from the command when performing completions. This includes both
those that the user typed, and any that come about through
completion --wraps.
2020-09-26 17:30:25 -07:00
ridiculousfish
3ef83de866 Rename cmd to cmdline in completer_t::perform_for_command
This makes it clear that the commandline contains arguments, etc.
2020-09-26 17:30:13 -07:00
ridiculousfish
757dda43ac Factor custom completion information into custom_arg_data_t
When completing and walking a wrap chain, we pass around a lot of
information. Factor this together into a new struct custom_arg_data_t
which reduces the number of parameters needed.
2020-09-26 17:30:10 -07:00