Commit Graph

877 Commits

Author SHA1 Message Date
Fabian Homborg
903b7888d3 complete: Make -c optional
Currently, completions have to be specified like

```fish
complete -c foo -l opt
```

while

```fish
complete foo -l opt
```

just complains about there being too many arguments.

That's kinda useless, so we just assume if there is one left-over
argument that it's meant to be the command.

Theoretically we could also use *all* the arguments as commands to
complete, but that seems unlikely to be what the user wants.

(I don't think multi-command completions really happen)
2020-09-09 20:23:08 +02:00
Fabian Homborg
a8e237f0f9 Let complete show completions for one command if just given -c
Currently only `complete` will list completions, and it will list all
of them.

That's a bit ridiculous, especially since `complete -c foo` just does nothing.

So just make `complete -c foo` list all the completions for `foo`.
2020-09-09 18:37:39 +02:00
Fabian Homborg
fbe56a84c7 tests: Export $TERM
I think this might be causing problems on Github CI.
2020-09-06 11:15:54 +02:00
Fabian Homborg
340de73172 Call "fish_command_not_found" if a command wasn't found
Previously, when a command wasn't found, fish would emit the
"fish_command_not_found" *event*.

This was annoying as it was hard to override (the code ended up
checking for a function called `__fish_command_not_found_handler`
anyway!), the setup was ugly,
and it's useless - there is no use case for multiple command-not-found handlers.

Instead, let's just call a function `fish_command_not_found` if it
exists, or print the default message otherwise.

The event is completely removed, but because a missing event is not an error
(MEISNAE in C++-speak) this isn't an issue.

Note that, for backwards-compatibility, we still keep the default
handler function around even tho the new one is hard-coded in C++.

Also, if we detect a previous handler, the new handler just calls it.

This way, the backwards-compatible way to install a custom handler is:

```fish
function __fish_command_not_found_handler --on-event fish_command_not_found
    # do a little dance, make a little love, get down tonight
end
```

and the new hotness is

```fish
function fish_command_not_found
    # do the thing
end
```

Fixes #7293.
2020-09-06 11:15:54 +02:00
Fabian Homborg
4817f97823 tests: Print some more info in the job_summary test for debugging
This one fails a bunch on CI and I have no idea why.
2020-09-04 17:53:17 +02:00
Fabian Homborg
bfb5b28d0f Let command, jobs and type take --query instead of --quiet
Now command, jobs, type, abbr, builtin, functions and set take `-q` to
query for existence, but the long option is inconsistent.

The first three use `--quiet`, the latter use `--query`. Add `--query`
to the first three, but keep `--quiet` around.

Fixes #7276.
2020-09-04 16:55:09 +02:00
Fabian Homborg
6ca2dbecfb Remove duplicated test
Fixes #7307.
2020-09-04 16:30:13 +02:00
Fabian Homborg
3fcf4e1b20 tests: Shorten a sleep
This waited for a full second just to call `wait`.

Instead let's use 300ms, saving a full 700ms per test run.
2020-09-04 16:29:53 +02:00
ridiculousfish
30d0315b60 Add a test that fish_exit handlers run on receipt of SIGHUP 2020-08-30 15:09:34 -07:00
ridiculousfish
0379f21870 Correctly cancel on receipt of SIGHUP
When we receive SIGHUP, stop executing normal fish script (but allow
exit handlers to run).
2020-08-30 15:09:34 -07:00
Fabian Homborg
5b1c000a2e math: Add bitwise and/or functions
Just as `math "bitand(5,3)"` and `math "bitor(6,2)"`.

These cast to long long before doing their thing,
so they truncate to an integer, producing weird results with floats.

That's to be expected because float representation is *very*
different, and performing bitwise operations on floats feels quite useless.

Fixes #7281.
2020-08-26 17:48:58 +02:00
ridiculousfish
47480b2dbd Remove redraw coalescing logic
Prior to this change, if we saw more than one repaint readline command in
a row, we would try to ignore the second one. However this was never the
right thing to do since sometimes we really do need to repaint twice in a
row (e.g. the user hits Ctrl+L twice). Previously we were saved by the
buginess of this mechanism but with the repainting refactoring we see
missing redraws.

Remove the coalescing logic and add a test. Fixes #7280.
2020-08-24 13:22:35 -07:00
ridiculousfish
073334f307 Stop setting TERM in history test
Because TERM was set to something other than 'dumb', we were subject to
syntax highlighting and other interactive features that would affect the
output. In practice we were getting lucky timing-wise, but with upcoming
interactive changes syntax highlighting started to fail this test.
2020-08-22 19:15:54 -07:00
ridiculousfish
29c1139a6e Correct a missing function call in bind.py
Unclear why this test was passing...
2020-08-22 17:48:50 -07:00
Johannes Altmanninger
19943576e4 fish_indent: preserve semis in if and while conditions
It could be nice to use a heuristic for this in future, but for now let's
stick to the old behavior so we can keep formatting scripts without occasional
bad formatting changes.

A heuristic could also be used to break lines after |, && or || but I don't
think there is much need for that at the moment.

Closes #7252
2020-08-17 17:40:28 +02:00
ridiculousfish
82fed6fc2f Correctly propagate signals from cancelled jobs into parse_execution_context
This concerns code like the following:

    while true ; sleep 100; end

Here 'while' is a "simple block execution" and does not create a new job,
or get a pgid. Each 'sleep' however is an external command execution, and
is treated as a distinct job. (bash is the same way). So `while` and
`sleep` are always in different job groups.

The problem comes about if 'sleep' is cancelled through SIGINT or SIGQUIT.
Prior to 2a4c545b21, if *any* process got a SIGINT or SIGQUIT, then fish
would mark a global "stop executing" variable. This obviously prevents
background execution of fish functions.

In 2a4c545b21, this was changed so only the job's group gets marked as
cancelled. However in the case of one job group spawning another, we
weren't propagating the signal.

This adds a signal to parse_execution_context which the parser checks after
execution. It's not ideal since now we have three different places where
signals can be recorded. However it fixes this regression which is too
important to leave unfixed for long.

Fixes #7259
2020-08-13 15:30:15 -07:00
ridiculousfish
d3f8445bcb Fix the job_summary pexpect test on Mac
Macs don't have a CPU column in jobs.
2020-08-12 16:40:32 -07:00
Fabian Homborg
c46489bde8 tests/job_summary: Add jobs call
Might help figuring out where this times out on CI?

We're waiting *20 seconds* for the output to appear, there's no way
that's too slow. So maybe we're going too fast elsewhere?
2020-08-12 18:38:15 +02:00
Fabian Homborg
1c6953ce79 tests/signals: Add missing sys import
This was only used if it failed for sys.exit(1)
2020-08-12 18:38:15 +02:00
Fabian Homborg
a7305c7082 tests: Increase timeout for signals test 2020-08-10 22:03:51 +02:00
ridiculousfish
8301aa9929 Add a test that nohup works
If fish is invoked with nohup, then its children should be nohup too.
2020-08-10 12:26:30 -07:00
Johannes Altmanninger
563a2d824c fish_indent: indent comments before line continuation
See #7252
2020-08-09 23:59:30 +02:00
Johannes Altmanninger
f8f32628a6 fish_indent: no extra newline at comment after pipe
Fixes the unstable case in #7252
2020-08-09 23:59:30 +02:00
Johannes Altmanninger
14a66fad64 Use variable in tests/checks/indent.fish 2020-08-09 23:53:46 +02:00
ridiculousfish
f6c1ef58df Indent continuations after | and &&
This indents continuations after pipes and conjunctions if they contain
a newline.

Example:

    cmd1 &&
        cmd2

But it avoids the "double indent" if it indented unconditionally:

    cmd1 | begin
        cmd2
    end

More work towards improving #7252
2020-08-09 12:22:15 -07:00
ridiculousfish
9a53bf7d56 fish_indent: indent line continuations
For example:

    cmd \
        arg

Fixes one case from #7252
2020-08-09 12:22:14 -07:00
ridiculousfish
e2a26b2fdf fish_indent: Correct certain comment indenting
Prior to this change, when emitting gap text (comments, newlines, etc),
fish_indent would use the indentation of the text at the end of the gap.
But this has the wrong result for this case:

    begin
    command
    # comment
    end

as the comment would get the indent of the 'end'. Instead use the indent
computed for the gap text itself.

Addresses one case of #7252.
2020-08-09 12:22:05 -07:00
Fabian Homborg
2cdd6df257 fish_indent: Add a "--check" option to only test indentation
Fixes #7251.
2020-08-08 20:23:14 +02:00
Fabian Homborg
b4f5ba6537 tests: Exit: Try sleeping multiple times 2020-08-08 16:35:08 +02:00
Fabian Homborg
7c0ecf0d37 Increase job summary timeout more in one call 2020-08-08 16:35:08 +02:00
Fabian Homborg
46faf0869c tests: Stop sleeping before expect
It's useless - `expect` has a timeout anyway, and it defaults to 5s,
so these 0.5s sleeps just mean it'll always take at least 0.5s.

Sometimes it is useful to let things settle before *sending* text, and
it would be nice to be able to set the timeout for each expect
separately, but just adding to the timeout isn't useful.
2020-08-08 16:35:08 +02:00
Fabian Homborg
7de333f839 tests: jobs: Sleep more
This one sometimes fails with a zombie detected, so I'm assuming it's
too fast for reaping to happen, so we add another 100ms sleep.

Yeah, this isn't great but...eh
2020-08-08 16:35:08 +02:00
Fabian Homborg
05ddbb1d2e tests: Add an additional "sleep"
This sometimes fails on Travis because sending things to the
background can take a while
2020-08-08 16:35:08 +02:00
Fabian Homborg
f63d70298f tests: Use ps -o stat instead of "state"
Oh, Alpine
2020-08-07 21:06:16 +02:00
Johannes Altmanninger
b947e360db Allow newlines after && and ||
We do the same for pipes (#1285). This matches POSIX sh behavior.
2020-08-06 21:24:26 +02:00
Soumya
539e6fe8b1 Return no status from successful variable assignments 2020-08-05 12:23:49 -07:00
Soumya
a2b2bcef6e Add a $status_generation variable that's incremented for each interactive command that produces a status.
This can be used to determine whether the previous command produced a real status, or just carried over the status from the command before it. Backgrounded commands and variable assignments will not increment status_generation, all other commands will.
2020-08-05 12:23:49 -07:00
ridiculousfish
290236f7e7 Attempt to fix the fg pexpect test
Hypothesize that ^Z is being sent too quickly and add a sleep.
2020-07-31 15:31:55 -07:00
ridiculousfish
c35fe879c7 Bravely remove reclaim... param from continue_job, and rework tcsetpgrp calls
This changes how fish attempts to protect itself from calling tcsetpgrp() too
aggressively. Recall that tcsetpgrp() will "force" itself, if SIGTTOU is
ignored (which it is in fish when job control is enabled).

Prior to this fix, we avoided SIGTTINs by only transferring the tty ownership
if fish was already the owner. This dated from a time before we had really
nailed down how pgroups should be assigned. Now we more deliberately assign a
job's pgroup so we don't need this conservative check.

However we still need logic to avoid transferring the tty if fish is not the
owner. The bad case is when job control is enabled while fish is running in the
background - here fish would transfer the tty and "steal" from the foreground
process.

So retain the checks of the current tty owner but migrate them to the point of
calling tcsetpgrp() itself.
2020-07-27 14:51:37 -07:00
Fabian Homborg
84b25855b0 alias: Escape the first word again
See https://stackoverflow.com/questions/63115744/alias-with-spaces-and-arguments-in-fish-3

This was broken in 115892ccd2
2020-07-27 17:19:44 +02:00
David Adam
2c5d4937e3 disown: add tests for disowned jobs in scripts 2020-07-25 20:38:59 -05:00
Fabian Homborg
a30630a1df Add some rudimentary fg tests
See #5451
2020-07-21 20:31:32 +02:00
Fabian Homborg
825f821623 Pexpects: Increase a timeout
This failed on sr.ht's FreeBSD machines once.
2020-07-21 20:27:55 +02:00
Fabian Homborg
276c76a363 Test alias with a --option
Closes #4756.
2020-07-14 21:08:47 +02:00
Fabian Homborg
9256f37e9e Add test for redirection to variable
Closes #6443
2020-07-14 20:55:38 +02:00
Fabian Homborg
fec3a593a2 test.fish: Erase more environment variables
Unfortunately this doesn't quite fix the issue with Pantheon
Terminal (#7913), as that somehow manages to re-set $VTE_VERSION by
the time littlecheck runs.
2020-07-13 20:55:39 +02:00
ridiculousfish
886603b2ca Adopt the new AST in fish_indent
This switches fish_indent from parsing with parse_tree
to the new ast.

This is the most difficult transition because the new ast retains less
lexical information than the old parse tree. The strategy is:

1. Use parse_util_compute_indents to compute indenting for each token.

2. Compute the "gap text" between the text of significant tokens. This
contains whitespace, comments, etc.

3. "Fix up" the gap text while leaving the significant tokens alone.
2020-07-04 14:58:05 -07:00
Mahmoud Al-Qudsi
f0580b4970 [tests] Fix test to reflect whitespace changes to error message 2020-06-25 23:19:44 -05:00
Mahmoud Al-Qudsi
d0afae46ce [tests] Do not rely on env output to be sorted alphabetically 2020-06-25 21:41:06 -05:00
Fabian Homborg
149a0b98af Another formatting run
I really kinda hate how insistent clang-format is to have line
breaks *IFF THE LINE IS TOO LONG*.

Like... lemme just add a break if it looks better, will you?

But it is the style at this time, so we shall tie an onion to our
belt.
2020-06-24 20:43:56 +02:00