Commit Graph

11323 Commits

Author SHA1 Message Date
ridiculousfish
b691d3130e Don't give job IDs to block processes either
Extend the commit 8e17d29e04 to block processes, for example:

    begin ; stuff ; end

or if/while blocks as well.

Note there's an existing optimization where we do not create a job for a
block if it has no redirections.
2019-12-31 13:12:24 -08:00
ridiculousfish
a6e5583b5b Correct reordering of jobs in job_promote
job_promote attempts to bring the most recently "touched" job to the front
of the job list. It did this via:

    std::rotate(begin, job, end)

However this has the effect of pushing job-1 to the end. That is,
promoting '2' in [1, 2, 3] would result in [2, 3, 1].

Correct this by replacing it with:

    std::rotate(begin, job, job+1);

now we get the desired [2, 1, 3].

Also add a test.
2019-12-31 12:41:11 -08:00
Dan Zimmerman
8e17d29e04 Introduce the internal jobs for functions
This PR is aimed at improving how job ids are assigned. In particular,
previous to this commit, a job id would be consumed by functions (and
thus aliases). Since it's usual to use functions as command wrappers
this results in awkward job id assignments.

For example if the user is like me and just made the jump from vim -> neovim
then the user might create the following alias:
```
alias vim=nvim
```
Previous to this commit if the user ran `vim` after setting up this
alias, backgrounded (^Z) and ran `jobs` then the output might be:
```
Job	Group	State	Command
2	60267	stopped	nvim  $argv
```
If the user subsequently opened another vim (nvim) session, backgrounded
and ran jobs then they might see what follows:
```
Job	Group	State	Command
4	70542	stopped	nvim  $argv
2	60267	stopped	nvim  $argv
```
These job ids feel unnatural, especially when transitioning away from
e.g. bash where job ids are sequentially incremented (and aliases/functions
don't consume a job id).

See #6053 for more details.

As @ridiculousfish pointed out in
https://github.com/fish-shell/fish-shell/issues/6053#issuecomment-559899400,
we want to elide a job's job id if it corresponds to a single function in the
foreground. This translates to the following prerequisites:

- A job must correspond to a single process (i.e. the job continuation
    must be empty)
- A job must be in the foreground (i.e. `&` wasn't appended)
- The job's single process must resolve to a function invocation

If all of these conditions are true then we should mark a job as
"internal" and somehow remove it from consideration when any
infrastructure tries to interact with jobs / job ids.

I saw two paths to implement these requirements:

- At the time of job creation calculate whether or not a job is
  "internal" and use a separate list of job ids to track their ids.
  Additionally introduce a new flag denoting that a job is internal so
  that e.g. `jobs` doesn't list internal jobs
  - I started implementing this route but quickly realized I was
    computing the same information that would be computed later on (e.g.
    "is this job a single process" and "is this jobs statement a
    function"). Specifically I was computing data that populate_job_process
    would end up computing later anyway. Additionally this added some
    weird complexities to the job system (after the change there were two
    job id lists AND an additional flag that had to be taken into
    consideration)
- Once a function is about to be executed we release the current jobs
  job id if the prerequisites are satisfied (which at this point have
  been fully computed).
  - I opted for this solution since it seems cleaner. In this
  implementation "releasing a job id" is done by both calling
  `release_job_id` and by marking the internal job_id member variable to
  -1. The former operation allows subsequent child jobs to reuse that
  same job id (so e.g. the situation described in Motivation doesn't
  occur), and the latter ensures that no other job / job id
  infrastructure will interact with these jobs because valid jobs have
  positive job ids. The second operation causes job_id to become
  non-const which leads to the list of code changes outside of `exec.c`
  (i.e. a codemod from `job_t::job_id` -> `job_t::job_id()` and moving the
   old member variable to a non-const private `job_t::job_id_`)

Note: Its very possible I missed something and setting the job id to -1
will break some other infrastructure, please let me know if so!

I tried to run `make/ninja lint`, but a bunch of non-relevant issues
appeared (e.g. `fatal error: 'config.h' file not found`). I did
successfully clang-format (`git clang-format -f`) and run tests, though.
This PR closes #6053.
2019-12-31 10:08:50 -08:00
Fabian Homborg
033a832687
Merge pull request #6447 from neheb/clang2
Several more small clang-tidy cleanups
2019-12-31 18:47:24 +01:00
Fabian Homborg
9f61512e67 CHANGELOG prompt improvements
[ci skip]
2019-12-30 14:07:10 +01:00
Fabian Homborg
4a47e212f8 Color the default prompt host if running via SSH
This is part of our (well, my) quest to spice up the default prompt.

In this case we color the host if $SSH_TTY is set, which is easy to
detect and helps draw attention to the host.

See #6398.
See #6375.
2019-12-30 14:03:36 +01:00
Johannes Altmanninger
0afc5258cf Unify detection of fish version upgrade with $__fish_initialized
This variable holds an integer that resembles the fish version up to
that initializations were performed. It should be incremented whenever
some new initialization is required after upgrading fish.  This should
not change the behavior for existing fish installations, except for a
minor message on installations that upgrade from fish<2.3.0.

[ci skip]
2019-12-30 14:00:22 +01:00
ridiculousfish
c963442999 Collapse io_data switch statements
Now that each io_data knows its source and target fd, we don't need to switch
on its types any more.
2019-12-29 15:51:22 -08:00
ridiculousfish
0af5608ce8 io_data_t to store the source_fd directly
Now that all io_data_ts know their source fd, just store it directly in
the base class. This will simplify some uses of io_data_t.
2019-12-29 15:14:08 -08:00
ridiculousfish
5d55004841 Stop adding close actions in pipe and bufferfills
Now that all pipes are marked CLOEXEC, there is no reason to add explicit
close calls here.
2019-12-29 15:00:12 -08:00
ridiculousfish
d0cefe8b65 Always mark pipes as cloexec
There is never a reason to keep these open in exec.
2019-12-29 14:57:16 -08:00
ridiculousfish
b784a0caa3 dup2_list_t::resolve_chain to stop returning maybe
It can no longer fail.
2019-12-29 14:49:05 -08:00
ridiculousfish
94dcd1cc07 Use the given parser when fetching certain histories 2019-12-29 14:26:46 -08:00
ridiculousfish
9f7972a08b clang-format C++ files 2019-12-29 14:25:42 -08:00
Johannes Altmanninger
3d9c0d3c69 Show the first few history entries in set | grep history
As before, but do so efficiently. See #6290
2019-12-29 17:43:25 +01:00
Fabian Homborg
d0edd984d5 Let pacman-derived tools complete zst as well
Arch is switching to zst as the default compression method
2019-12-28 17:10:23 +01:00
Fabian Homborg
b0e3cc4b5c __fish_complete_suffix: Remove eval
This use of eval is unsafe, not really all that useful and can spew
errors that can't be suppressed. So let's remove it, and in future add
a thing that can do expansions in a safe manner

Fixes #6456.
2019-12-28 17:10:23 +01:00
Fabian Homborg
0866013280 Stop using __fish_complete_suffix with a braced argument
__fish_complete_suffix accepts a first argument containing a
brace-expansion, like

    __fish_complete_suffix '.{c,cpp,py}'

We're gonna be removing the `eval` that does that shortly, so let's
remove all uses in our code.
2019-12-28 17:10:23 +01:00
Rosen Penev
06cb0bbe9a
[clang-tidy] Add several references
Found with performance-unnecessary-value-param

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-12-26 21:55:53 -08:00
Rosen Penev
5501953c07
[clang-tidy] Add ending namespace comment
Found with llvm-namespace-comment
2019-12-26 21:37:17 -08:00
Rosen Penev
b1349f44f6
[clang-tidy] Add const to reference
Found with performance-unnecessary-copy-initialization
2019-12-26 21:37:15 -08:00
Rosen Penev
5d1ad8de91
[clang-tidy] Use std::move
Found with modernize-pass-by-value
2019-12-26 21:36:23 -08:00
Rosen Penev
49fbca8a8b
[clang-tidy] Remove redundant const in function declarations
Found with readability-avoid-const-params-in-decls
2019-12-26 21:25:12 -08:00
Rosen Penev
856fa0ca42
[clang-tidy] Use override instead of virtual
Found with modernize-use-override
2019-12-26 21:25:12 -08:00
Rosen Penev
f2e7def667
[clang-tidy] Remove const from strings
Found with readability-const-return-type
2019-12-26 21:25:12 -08:00
Rosen Penev
668f73c0d6
[clang-tidy] Fix wrong declaration
Found with readability-inconsistent-declaration-parameter-name
2019-12-26 21:25:12 -08:00
Rosen Penev
9e42b0100a
[clang-tidy] Remove redudant .get on smart pointer
Found with readability-redundant-smartptr-get
2019-12-26 21:25:11 -08:00
Rosen Penev
2ecc386121
[clang-tidy] Remove redundant c_str
Found with readability-redundant-string-cstr
2019-12-26 21:25:07 -08:00
Rosen Penev
d1e82b59bb
[clang-tidy] Switch from size to empty check
Found with readability-container-size-empty
2019-12-26 20:07:53 -08:00
ridiculousfish
df0681d393 Remove process_generation_count_t
It was unused.
2019-12-26 13:33:14 -08:00
ridiculousfish
126e6a929f Remove the ARRAY_SEP define
It's unused.
2019-12-26 13:17:34 -08:00
Fabian Homborg
0e0d63c0df completions/pipenv: Really force it to print fish completions
"To assume" and such.

It doesn't check $SHELL, so it might have some other automagic that
can fail (probably still because of the login shell, but I have no
idea).

Override the special variable that
click-completion (https://github.com/click-contrib/click-completion)
uses to force it instead.

Really fixes #6454.

[ci skip]
2019-12-25 16:29:10 +01:00
Fabian Homborg
aba5beaeb4 completions/pipenv: Force it to print fish completions
This checks $SHELL to determine which completions to print, and $SHELL
is typically set by your login program.

So if the login shell isn't fish, this will print the wrong
completions.

Fixes #6454

[ci skip]
2019-12-25 16:16:08 +01:00
Fabian Homborg
bd8fd9fd0d docs/bind: Document and
[ci skip]
2019-12-25 10:46:46 +01:00
Fabian Homborg
e986970f4d Remove vi_arg_digit and vi_delete_to
They don't do anything anymore.
2019-12-25 10:44:27 +01:00
Fabian Homborg
c0f2e842ad Document missing bind functions
Turns out we never documented the "jump" ones.

That means the still-undocumented bind functions are

- vi-arg-digit
- vi-delete-to
- and

Mostly because I'd have to look up what they actually *do*, and
possibly rename them to be generic.

[ci skip]
2019-12-25 10:26:03 +01:00
Johannes Altmanninger
9f48fc6285 Fix status when function/block evaluation is cancelled
It looks like the last status already contains the signal that cancelled
execution.

Also make `fish -c something` always return the last exit status of
"something", instead of hardcoded 127 if exited or signalled.

Fixes #6444
2019-12-23 17:38:19 +01:00
David Adam
8ca936aea6 cmake: use C++ extension options when checking features
This matches the CMake default of extensions turned on.
2019-12-23 22:26:57 +08:00
David Adam
4d325dcd7a cmake: tidy up adding C++11 compile flags
Two blocks of code were trying to do the same thing in different ways;
standardise on one, and only add the compile flags if CMake won't do it
itself (policy CMP0067).
2019-12-23 22:26:57 +08:00
David Adam
74ab9e72ac cmake: pass C++ standard compiler options to tests
Enables CMake policy 0067.
2019-12-23 22:26:57 +08:00
Mathieu Duponchelle
15c1b3ed4b Place fish in its own process group when launched with -i
Fixes #5909
2019-12-23 10:32:37 +01:00
ridiculousfish
c19407ab0f Default parser_t::eval()'s block type to top
This is the parameter value at every call site except one. Just make it the
default.
2019-12-22 16:27:03 -08:00
ridiculousfish
0c49dce75d Factor block description part of stack traces into a new function 2019-12-22 16:22:20 -08:00
ridiculousfish
a59f35a378 Make block_type_t an enum class 2019-12-22 15:37:14 -08:00
ridiculousfish
4529e7d183 Reverse the order of the block stack
Previously, the block stack was a true stack. However in most cases, you
want to traverse the stack from the topmost frame down. This is awkward
to do with range-based for loops.

Switch it to pushing new blocks to the front of the block list.
This simplifies some traversals.
2019-12-22 15:07:41 -08:00
ridiculousfish
82baf74785 Attempt to fix the build
Move the CMake changes down in the file after the FIND_PACKAGE calls.
2019-12-22 12:31:14 -08:00
ridiculousfish
87854c81f5 Allow C++ standard to be passed to CHECK_CXX_SOURCE_COMPILES
Work around the issue in CMake where C++ standard doesn't get propagated
to CHECK_CXX_SOURCE_COMPILES. Also correctly check for std::make_unique;
the define was missing from the config.h header.
2019-12-22 12:07:46 -08:00
ridiculousfish
10ac83ae32 lru to use std::map, not std::unordered_map
We depend on pointer stability here and it just seems easier
to think about it with std::map.
2019-12-21 17:09:21 -08:00
Sergei Morozov
624e76ae89 Added the --cleanup option completion for the git commit command 2019-12-21 20:03:54 +01:00
David Adam
45633f4a54 cmake: force C++11 in CHECK_CXX_SOURCE_COMPILES for atomic
GCC 4.8 requires the use of `-std=gnu++11` or similar to enable atomic
features. However, older versions of CMake don't pick up the
project-wide target for C++11 when building the configure check targets.
Although CMake policy 0067 could be set to NEW to enable this, it only
exists on CMake 3.8 and newer, while many of our supported platforms are
on an older version.
2019-12-21 22:00:22 +08:00