Commit Graph

11344 Commits

Author SHA1 Message Date
Fabian Homborg
611a6589ea Disable command descriptions on macOS 10.15.X
We just do a cheesy version check and hope it works out.

If this is fixed in 10.15.4, we have to reenable it. If it still isn't
fixed in 10.16, we need to adjust it.

Fixes #6270
2020-01-05 18:35:59 +01:00
Fabian Homborg
0f362b4bb2 Change c{begin,end} to begin,end
Unfortunately old distributions are old.

Fixes build failures on GCC 4.8 (RHEL6/7).
2020-01-05 15:44:05 +01:00
Fabian Homborg
23bf9661b2 Document time
This is a bit barebones, but `time` isn't super complicated to use and
it should explain the basics.

Fixes #6442

[ci skip]
2020-01-05 14:50:54 +01:00
Fabian Homborg
f3dbede2a5 Document variable overrides
[ci skip]
2020-01-05 14:44:48 +01:00
Fabian Homborg
0a379135a4 exec_job: Only call getpgrp() once
This reduces the syscall count for `fish -c exit` from 651 to 566.

We don't attempt to *cache* the pgrp or anything, we just call it once
when we're about to execute the job to see if we are in foreground and
to assign it to the job, instead of once for checking foreground and
once to give it to the job.

Caching it with a simple `static` would get the count down to 480, but
it's possible for fish to have its pgroup changed.
2020-01-05 09:41:06 +01:00
Aaron Gyes
d0b0c9a77e minor pcre2_matcher_t cleanup 2020-01-03 16:17:41 -08:00
Aaron Gyes
5281aca659 builtin_string.cpp: remove effectively dead variable 2020-01-03 16:17:41 -08:00
Mahmoud Al-Qudsi
038084b8bf Optimize generation, filtering, and sort of completions 2020-01-03 17:54:14 -06:00
ridiculousfish
62302ee172 Properly print leading comments and indentation in functions
Store the entire function declaration, not just its job list.
This allows us to extract the body of the function complete with any
leading comments and indents.

Fixes #5285
2020-01-03 14:40:28 -08:00
Johannes Altmanninger
c3374edc59 Reject time with background jobs
This check could probably done earlier in the parser but it works.
2020-01-03 01:07:49 -06:00
Johannes Altmanninger
3de95038b0 Make "time" a job prefix
In particular, this allows `true && time true`, or `true; and time true`,
and both `time not true` as well as `not time true` (like bash).

time is valid only as job _prefix_, so `true | time true` could call
`/bin/time` (same in bash)

See discussion in #6442
2020-01-03 01:07:49 -06:00
Aaron Gyes
c1140bc436 Improve kill completions
Use string split instead of cut - which we'd fork for 2*signal
count times in a loop when tab was first pressed. Noticably faster

If giving a signal num, what works everywhere is -NUM, if giving
a signal name, what works everywhere is -s NAME - don't show -sNUM
or -NAME completions; that only works on GNU and it's redundant
anyhow as we show the signal number in the description field for -s
or the signal name for the -NUM case in the pager.

Sort -sNAME completions by the signal number not alphabetical

Shorten descriptions
2020-01-02 22:53:28 -08:00
David Adam
4ccd33a9d0 debian packaging: slight bump in Debian standards version
No changes required between 3.9.4 and 3.9.7 for fish packages.

[ci skip]
2020-01-02 22:37:36 +08:00
David Adam
5df84c1998 cmake: use correct variable for C++ compiler flags
Broken in 8ca936aea6
2020-01-02 22:08:59 +08:00
ridiculousfish
89880891d0 Revert "fish_tests to set HOME and other variables to temporary dir"
This reverts commit cca57a7a87.

The tests target already sets some variables - backing this out.
2020-01-01 17:24:14 -08:00
ridiculousfish
cca57a7a87 fish_tests to set HOME and other variables to temporary dir
Rather than placing files in the user's home directory, have fish_tests
manipulate HOME to be a temporary directory.
2020-01-01 16:34:56 -08:00
ridiculousfish
65e9f31c7a Use autoclose_fd_t more pervasively in history 2020-01-01 13:49:10 -08:00
ridiculousfish
5aa22adccc Make history_filename return a maybe_t<wcstring>
This function can fail, so rather than forcing clients to check the return
value as empty, allow it to return none().
2020-01-01 12:34:42 -08:00
ridiculousfish
efa9d5dd6a Port cd tests to littlecheck 2019-12-31 14:16:20 -08:00
ridiculousfish
91404f1762 Rename job_ids check to job-ids
Other tests use a dash.
2019-12-31 13:32:04 -08:00
ridiculousfish
9a11c03097 Correct the job_ids test on the Mac
The Mac doesn't provide CPU percentages so the column is omitted, causing
the test to fail. Use a regex to cover both cases.
2019-12-31 13:17:26 -08:00
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