Commit Graph

3153 Commits

Author SHA1 Message Date
ridiculousfish
03208acb60 Don't call redirect_tty_output when restoring the front process group
redirect_tty_output was a clumsy attempt to work around a glibc bug, but
it's not necessary if fish is about to exit.
2020-05-31 13:51:47 -07:00
ridiculousfish
a2ae2d6c36 Attempt to truncate prompts that are too wide
Prior to this change, if the user's prompt was wider than the terminal, we
would reduce it to just `> `. With this change, attempt to truncate the
prompt.

For each line of the prompt, calculate its width. If the width exceeds
COLUMNS, prepend ellipsis to that line, and start removing characters
until it fits. Escape sequences are skipped.

Fixes #904
2020-05-31 09:58:47 -07:00
ridiculousfish
67a4b35838 Migrate cached_layouts into layout_cache_t 2020-05-30 15:00:28 -07:00
ridiculousfish
7cc99a2d80 Rename job_tree to job_group
Initially I wanted to pick a different name to avoid confusion with
process groups, but really job trees *are* process groups. So name them
to reflect that fact.

Also rename "placeholder" to "internal" which is clearer.
2020-05-30 14:22:44 -07:00
ridiculousfish
b119c4b3bb Eliminate pgroup_provenance_t
Now that job trees are a single source of truth for a job's pgid, we no
longer need fancy logic around how the pgroup is assigned.
2020-05-30 14:22:44 -07:00
ridiculousfish
f37a44db16 Migrate job pgid from job to job tree
Prior to this, jobs all had a pgid, and fish has to work hard to ensure
that pgids were inherited properly for nested jobs. But now the job tree
is the source of truth and there is only one location for the pgid.
2020-05-30 14:22:44 -07:00
ridiculousfish
a86d3f4136 Remove job_lineage_t
Its responsibilities are now subsumed by job_tree_t except for
the block_io which we pass around explicitly.
2020-05-30 14:22:44 -07:00
ridiculousfish
55db918d59 Start to unwind lineages
job_lineage was used to track "where jobs came from" but the job tree idea is
a better abstraction. It groups jobs together similar to how a process group
would in other shells. Begin to remove the notion of lineage.
2020-05-30 14:22:44 -07:00
ridiculousfish
a4b66d948b Add a property describing when a job is initially backgrounded
Track separately whether a job is in the background now, and whether
it was constructed in the background via the & syntax.
2020-05-30 14:22:44 -07:00
ridiculousfish
123f3e6f93 Put job_id into job_tree
Job IDs are really a property of a job tree, not individual jobs. Reflect
that fact by migrating job IDs into job_tree.
2020-05-30 14:22:44 -07:00
ridiculousfish
fe60f2ef16 Move root_has_job_control from lineage to job_tree
Whether we have job control is a property of the job tree, not of
individual jobs. Reflect that fact directly by moving it into the job tree.
2020-05-30 14:22:43 -07:00
ridiculousfish
e95bcfb074 Teach a job to decide its job tree
Job trees come in two flavors: “placeholders” for jobs which are only fish
functions, and non-placeholders which need to track a pgid. This adds
logic to allow a job to decide if its parent's job tree is appropriate,
and allocating a new tree if not.
2020-05-30 14:22:43 -07:00
ridiculousfish
4e01c06256 Introduce job_tree
job_tree represents the data that should be shared between a job and any
jobs that may be spawned by functions or eval run as part of that job. It
reifies shared data that before was handled piecemeal.
2020-05-30 14:22:43 -07:00
Mahmoud Al-Qudsi
7e61205294 Make sure p->last_jiffies doesn't change after sanity checking
See 821525e503 and #7066
2020-05-30 16:05:29 -05:00
Mahmoud Al-Qudsi
821525e503 Defend against race condition calculating job cpu usage
Closes #7066
2020-05-30 16:00:34 -05:00
Mahmoud Al-Qudsi
f4ae69a905 fixup! Recover from bad redirections in the middle of a job pipeline
Fix inadvertent early abort (thanks, nested switch-in-for-loop!) that
led to subsequent shell input being broken.
2020-05-30 10:37:46 -05:00
Mahmoud Al-Qudsi
bc756a981e Recover from bad redirections in the middle of a job pipeline
Currently fish aborts execution mid-pipeline if a file redirection
failed, which can leave the shell in a broken state (job abandoned after
giving control of the terminal to an already-executed job in the
pipeline).

This patch replaces a failed fd with a closed fd and continues execution
if the affected process wasn't the first in the pipeline.

While this is a hack to address the regression behind fish-shell/#7038
introduced in d62576c, it can also be argued that this behavior is
actually more correct... right?

Closes #7038.
2020-05-30 00:27:11 -05:00
Fabian Homborg
4785440f65
Add an "_" builtin to call into gettext (#7036)
* Add an "_" builtin to call into gettext

We already have gettext in C++ (if available), so it seems weird to
fork off a command to start it from script.

This is only for fish's own translations. There's no way to call into
other catalogs, it just translates all arguments separately.

This is faster by a factor of ~1000, which allows us to call
translations much more, especially from scripts.

E.g. making fish_greeting global by default would hurt cost-wise,
given that my fish starts up in 8ms and just calling the current `_`
function takes 2ms, and that would have two calls.

Incidentally, this also makes us rely on a weirdly defined function
less, so it:
Fixes #6804.

* docs: Add `_` docs

Let's see if that filename works out.

* Reword _ docs
2020-05-29 20:53:44 +02:00
Fabian Homborg
7cb452c7e7 Computed variables are global
Variables like $status and $history showed up in all scopes, including
universal, when querying with `set -q` or `set -S`.

This makes it so they all only count as set in global scope, because
we already only allow assignment to electric variables in global scope.

Fixes #7032
2020-05-27 19:59:20 +02:00
Joel Kuhn
6853705b0b Fix underflow in commandline jump functions
This patch fixes an underflow in the jump family of readline commands
when called via `commandline -f` outside of a bind context such as
`commandline -f backward-jump`. To reproduce, run that command at a
prompt and the shell will crash with a buffer underlow.

This happens because the jump commands have non-zero arity, requiring a
character event to be pushed on the function args stack. Pushing the
character event is handled in `function_push_args`, called by
`inputter_t::mapping_execute`, which checks the arity of the function
and enqueues the required number of charcter events. However,
`builtin_commandline` calls `reader_queue_ch`, which in turn calls
`inputter_t::queue_ch`, which immediately enqueues the readline event
without calling `function_push_args`, so the character event is never
pushed on the arg stack.

This patch adds a check in inputter_t::queue_ch which checks if the
character event is a readline event, and if so, calls
`function_push_args`.
2020-05-26 19:53:09 -07:00
Mahmoud Al-Qudsi
2d52335fed Don't fire fish_prompt when read is used
Apart from being semantically incorrect, this was causing `fish_prompt`
to fire twice after commands that used `read` (e.g. `cdh`).

Closes #7039.
2020-05-26 15:24:31 -05:00
ksralgp
f55f98b064
Show autosuggestions when (left prompt + command) exceed right prompt (#7035)
* Show autosuggestions when (left prompt + command) exceed right prompt

* Fix indentation whitespace and run build_tools/fish.style on src/screen.cpp
2020-05-24 21:54:00 +02:00
ridiculousfish
84e0c8d32e Guard thread_local
Mac OS X 10.9 supports __thread but not C++11 thread_local.
Teach CMake to detect support for thread_local and use the proper
define guard.

Fixes #7023
2020-05-22 13:41:05 -07:00
ridiculousfish
1fd0cd5510 Avoid forming owning_lock of incomplete type in history
Older libstdc++ will error on this.

Partially addresses #7023
2020-05-22 13:36:46 -07:00
Johannes Altmanninger
285861d346 Do notify about jobs that were continued outside fish
When sending SIGCONT to a stopped job, this behaves now
a bit more like a job that was continued by the bg builtin;
bg uses job_t::continue_job which seems overkill here.
2020-05-22 21:28:54 +02:00
Fabian Homborg
e51f4e5fc9 Don't print a warning about tcgetattr if stdin is not a tty
I don't know why this doesn't happen more often, but if stdin is not a
tty not being able to get terminal attributes from it is *expected*?
2020-05-21 10:31:32 +02:00
Fabian Homborg
3af715d36f test_helper: Limit signal numbers more
This just produced a spurious "Unknown signal" error on NetBSD and OpenBSD, and
the number picked was arbitrary. So let's just use the maximum that
appears to work everywhere.

(I will hate this if I test it elsewhere and need to reduce it to 62)

(This is a squashed commit, I did indeed hate it when I moved from
NetBSD to OpenBSD)
2020-05-21 10:30:54 +02:00
Johannes Altmanninger
91ccaae5bf fish_indent: fix error message on ENOENT 2020-05-19 21:15:11 +02:00
Charles Gould
a0faac400d Print warning on failure to match debug category 2020-05-19 21:07:33 +02:00
Charles Gould
a7aca37f9b Print enabled debug categories 2020-05-19 21:07:33 +02:00
Soumya
518170b299 Also call fish_job_summary for foreground sigint
The default implementation will not print any output in that case, but this provides users with additional flexibility when it comes to customising the shell's behaviour.
2020-05-19 20:39:10 +02:00
Soumya
324fa64114 Add fish_job_summary, called whenever a job ends, stops, or is signalled
This allows users to customise the behaviour of the shell by redefining the function. This is similar to how fish_title or fish_greeting behave, where the default implementation can be easily overridden.

The function receives as arguments the job id, command line, signal name and signal description.
2020-05-19 20:39:10 +02:00
Fabian Homborg
56f24f08d7 printf: Don't print an error if not given an argument 2020-05-18 20:48:36 +02:00
Fabian Homborg
29754f3540 Keep terminal modes for external commands
This allows tools like `stty` to set the terminal modes and fish will
honor them, for external commands.

The modes for fish are kept as they are.

Until now, the only change fish would do to the external modes is to
disable flow control *every time*, this changes it to only disabling
it on startup.

After that we don't apply *any* changes to the external modes (no
checks or validation or...), because we've never done that (other than
flow control), and it's not been a problem.

Fixes #2315.
2020-05-16 13:04:51 +02:00
Johannes Altmanninger
e03c375ee3 Purge remnants of process expansion, document {fish,last}_pid 2020-05-16 11:58:12 +02:00
Johannes Altmanninger
83c657c010 Fix IO error handling in non-interactive reader
This used to use fread(2) which returns size_t, but read(2) returns
an ssize_t of -1 on error.

Fixes #6990
2020-05-10 22:33:22 +02:00
David Adam
6bd563ca32 history: use mode 0600 for creating history file
Fixes #6926.
2020-05-10 21:28:16 +08:00
Johannes Altmanninger
5cd7c3a30b Teach builtin functions about -t for --handlers-type
Fixes #6985
2020-05-08 22:47:40 +02:00
David Adam
c2942a70d6 common.h: drop some unused macros
Last use removed in 81ded4c0ab.
2020-05-08 22:17:26 +08:00
Fabian Homborg
81ded4c0ab Don't default term size if it is too small
This is unlikely to achieve anything sensible.

Fixes #6980.
2020-05-07 17:42:02 +02:00
Charles Gould
ad020e84dd Exit key reader normally on help, version 2020-05-05 12:33:22 +08:00
ridiculousfish
aa8c9df2d0 Stop copying a string in hash<const wcstring> 2020-05-01 13:30:56 -07:00
Rosen Penev
0668513138 Change C casts to C++ ones
Some were kept for compatibility.

Found with -Wold-style-cast

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-05-01 13:30:56 -07:00
ridiculousfish
4116829292 Do not issue clr_eos if we think the cursor will end up on its own line
If we output text and end up in the last column, the sticky right edge
will cause a clr_eos to erase the last character. Ensure this doesn't
happen by not issuing clr_eos in that case.

Fixes #6951
2020-04-29 14:22:54 -07:00
ridiculousfish
8c4c9d050d Clear cancellation signals after handling a readline command
If a readline command is bound to a key sequence which also sends a
signal, then fish will set the cancel flag in addition to handling the
command. But this cancel flag is then persistent. Ensure it gets cleared
after each command.

Fixes #6937
2020-04-29 13:38:15 -07:00
David Adam
8d43439640 wutil: add SMB2 file type to fd_check_is_remote
The manual page for statfs(2) only lists SMB_SUPER_MAGIC and
CIFS_MAGIC_NUMBER, but it turns out there's a third type of CIFS/SMB
mount, represented by SMB2_MAGIC_NUMBER.

Haunting me from #6609.
2020-04-29 23:34:13 +08:00
ridiculousfish
2951c05934 Do not consider dumb terminals to have wrapping
For the purpose of cursor_is_wrapped_to_own_line, always return false
for dumb terminals. Fixes the tests.
2020-04-28 16:30:52 -07:00
ridiculousfish
4f103d74fb Do not emit newline when running commands if the cursor is on its own line
If the cursor has been wrapped to the last line, and is the only thing
on that line, do not emit a newline when executing a command.

Fixes #6826
2020-04-28 11:51:46 -07:00
ridiculousfish
81af389258 Modernize screen_t
Use inline initializers rather than the constructor, and adopt some
maybe_t.

Also move post_buff_1 and post_buff_2 to local variables instead of
member variables.
2020-04-28 11:26:06 -07:00
ridiculousfish
520c83cbbf Make screen_reset_mode_t an enum class instead of an enum
Improves type safety.
2020-04-28 11:00:26 -07:00
ridiculousfish
844ae48dc0 Apply code review from #6806 2020-04-28 10:54:48 -07:00
ridiculousfish
80e92581aa Allow eval to see the tty if its output is not piped
Commit 5fccfd83ec, with the fix for #6806,
switched eval to buffer its output (like other builtins do). But this
prevents using eval with commands that wants to see the tty, especially
fzf. So only buffer the output if the output is piped to the next process.

This will solve #6955 (which needs to go into a point release).
2020-04-28 10:08:00 -07:00
ridiculousfish
607779257c Introduce out_is_piped and err_is_piped on io_streams_t
builtin_eval needs to know whether to set up bufferfills to capture its
output and/or errput; it should do this specifically if the output and
errput is piped (and not, say, directed to a file). In preparation for
this change, add bools to io_streams_t which track whether stdout and
stderr are specifically piped.
2020-04-28 09:59:55 -07:00
ridiculousfish
a1f1b9c2d9 builtin_eval to direct output to its iostreams
Prior to this fix, builtin_eval would direct output to the io_chain of the
job. The problem is with pipes: `builtin_eval` might happily attempt to
write unlimited output to the write end of a pipe, but the corresponding
reading process has not yet been launched. This results in deadlock.

The fix is to buffer all the output from `builtin_eval`. This is not fun
but the best that can be done until we have real concurrent processes.

Fixes #6806
2020-04-26 11:05:50 -07:00
ridiculousfish
82f2d86718 Thread pgroups into builtin_eval
Ensure that if eval is invoked as part of a pipeline, any jobs spawned
by eval will have the same pgroup as the parent job.

Partially fixes #6806
2020-04-26 11:05:50 -07:00
ridiculousfish
938b683895 Thread pgroups into command substitutions
Give string expansion an (optional) parent pgroup. This is threaded all
the way into eval(). This ensures that in a mixed pipeline like:

   cmd | begin ; something (cmd2) ; end

that cmd2 and cmd have the same pgroup.

Add a test to ensure that command substitutions inherit pgroups
properly.

Fixes #6624
2020-04-26 11:05:50 -07:00
Fabian Homborg
6990c44443 Shorten set --show output
Changes it from

```
$fish_color_user: not set in local scope
$fish_color_user: set in global scope, unexported, with 1 elements
$fish_color_user[1]: length=3 value=|080|
$fish_color_user: set in universal scope, unexported, with 1 elements
$fish_color_user[1]: length=7 value=|brgreen|

```

(with the trailing empty line - not just a newline)

to

```
$fish_color_user: set in global scope, unexported, with 1 elements
$fish_color_user[1]: |080|
$fish_color_user: set in universal scope, unexported, with 1 elements
$fish_color_user[1]: |brgreen|
```
2020-04-26 08:49:01 +02:00
ridiculousfish
feb40f0cd6 Make io_file_t::print more useful 2020-04-25 20:25:28 -07:00
Per Bothner
a93ee3a4e9
Fire fish_posterror event on tokenization error (#6880)
* Fire fish_postexec event after tokenization error

This is a fix for issue #6816 "shell integration with tokenization error"

* Pass command-line to fish_postexec on tokenization error

* Rename and move event for tokenization error
2020-04-25 09:23:15 +02:00
Johannes Altmanninger
28d67c8f0f Show completion list on Tab also if a common prefix was inserted
Fixes #6924
2020-04-23 20:19:57 +02:00
Johannes Altmanninger
095614ac54 Do not insert a space after completions ending in a comma or dot
For the last 15 years the space was only skipped when the completion
ended in one of "/=@:". Add ".," since they are also sometimes used to
separate independent words within a token.

Fixes #6928
Improves on #6833
2020-04-23 20:11:55 +02:00
Fabian Homborg
1d57da7291 commandline: Don't complain if insert mode has nothing to insert
That's just, like, a normal thing to happen.

We can return false, but it's not an error worth complaining about.

See #6931.
2020-04-23 17:17:19 +02:00
Fabian Homborg
02baa321ae Restyle
More of that weird reflowing that clang-format loves to do
2020-04-21 21:11:26 +02:00
Jason Nader
6a839519b9 string split: add --allow-empty flag to be used with --fields 2020-04-20 22:39:48 +02:00
Jason Nader
3bb86d3a61 string split --fields: handle multi-line/arg input 2020-04-20 22:39:48 +02:00
Johannes Altmanninger
0fb58ab625 highlight: normalize path when validating path for cd
As builtin cd does.

Fixes #6915.
2020-04-19 07:01:25 +02:00
Johannes Altmanninger
9f45ff63d3 refactor: use mark_repaint_needed over reader_repaint_needed in reader
Making the reader_data_t member functions consistent, some already used
mark_repaint_needed.
2020-04-19 05:51:25 +02:00
ridiculousfish
3e8422f472 terminal_maybe_give_to_job to stop returning error on ENOTTY
Prior to this fix, if job control is enabled but stdin is not a tty, we
would return an error from terminal_maybe_give_to_job which would cause us
to avoid waiting for the job. Instead just return notneeded.

Fixes #6573.
2020-04-18 16:26:54 -07:00
Joel Kuhn
a3dfa21737 Change vi-mode tilde to toggle character case
This updates the behavior of tilde to match the behavior found in vim.
In vim, tilde toggles the case of the character under the cursor and
advances one character. In visual mode, the case of each selected
character is toggled, the cursor position moves to the beginning of
the selection, and the mode is changed to normal. In fish, tilde
capitalizes the current letter and advances one word. There is no
current tilde command for visual mode in fish.

This patch adds the readline commands `togglecase-letter` and
`togglecase-selection` to match the behavior of vim more closely. The
only difference is that in visual mode, the cursor is not modified.
Modifying the cursor in visual mode would require either moving it in
`togglecase-selection`, which seems outside its scope or adding
something like a `move-to-selection-start` readline command.
2020-04-18 14:59:37 +02:00
Johannes Altmanninger
17ed8d25a4 Fix builtin "read" up-arrow search skipping first entry
Fixes #6892
2020-04-14 01:30:54 +02:00
Rosen Penev
d9ad5a2627 remove unreachable break statements
Found with clang's -Wunreachable-code-break

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-12 17:02:17 -07:00
Rosen Penev
6ab2da0e25 Fix -Wundef warnings
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-12 17:02:17 -07:00
Rosen Penev
ca57bcbb00 add several noreturn statements
Found with clang's -Wmissing-noreturn

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-12 17:02:17 -07:00
Rosen Penev
202fe39d34 fix unreachable code warning
Found with clang's -Wunreachable-code

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-12 17:02:17 -07:00
Weisi Dai
07fb55d342 fish_indent: Add notes on SPACES_PER_INDENT. 2020-04-12 13:43:45 -07:00
Mahmoud Al-Qudsi
c249b1f2f0 Also catch zero-index errors when indexing into a command substiution
We had previously added a more helpful error message when a literal zero
index was specified when indexing into an array. This patch extends that
coverage to cases indexing into a command substitution, e.g.

```fish
echo (printf "hello\nworld\n")[0]
```
2020-04-07 20:05:50 -05:00
Johannes Altmanninger
77d33a8eb9 Ignore SIGINT and SIGQUIT in non-interactive background processes
Fixes #6828
2020-04-07 22:18:15 +02:00
Johannes Altmanninger
90f67e4009 fish_test_helper: print only blocked 64 blocked signals
Otherwise it would print "Unknown Signal" on Linux.  I didn't see an
obvious way to check signal validity, plus it hardly matters.

Also mimic the output from BSD strsignal on Linux.
2020-04-07 22:18:15 +02:00
Johannes Altmanninger
c1b2b6b7da Rename comp_empty to complete_did_insert and fix comments 2020-04-06 23:43:29 +02:00
Lior Stern
ca91c201c3 Remove unnecessary string duplication in handle_flag_f.
Prevents a memory leak.
2020-04-06 19:13:48 +02:00
Fabian Homborg
4eccc0f6d1 true/false: Stop erroring out for arguments
For `true`, this makes uses like the

    : some description of the job &

we used to have impossible, also it's just *wrong* that true can
return something that isn't true.

For false it's not super important but it should generally be
symmetrical with true.
2020-04-06 18:56:19 +02:00
Fabian Homborg
5dfaff4281 Make "." a builtin as well
Yeah, it's not going anywhere. This is one line in builtin.cpp vs 9
lines of script, most of which used to print an error that is never triggered.
2020-04-06 18:55:59 +02:00
Fabian Homborg
be0de5e2de Just define a ":" builtin
It's *less code* to define this as a builtin, and it's not going
anywhere. Plus it makes fish just a little more usable without share/config.fish.
2020-04-06 18:55:59 +02:00
ridiculousfish
3df05af809 Revert "Do not prevent multiple tab-completions with the same command line"
This reverts commit 41dcf84386.

This seems to have broken a lot of interactive scenarios.
2020-04-05 19:05:53 -07:00
ridiculousfish
41dcf84386 Do not prevent multiple tab-completions with the same command line
The comp_empty variable was assigned a sucecss value, leading fish
to think that the set of completions was empty when it is not.

Fixes #6863
2020-04-05 18:55:28 -07:00
ridiculousfish
866d506d11 Add a fish_test_helper command to print blocked signals 2020-04-05 15:07:42 -07:00
Rosen Penev
385b069eb2 [clang-tidy] remove pointless public
Found with readability-redundant-access-specifiers

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:43 +02:00
Rosen Penev
68467eeca7 [clang-tidy] remove redundant string initialization
Found with readability-redundant-string-init

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
473a5250ae [clang-tidy] change several member functions to const
Found with readability-make-member-function-const

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
312b575424 [clang-tidy] numeric literals to uppercase
Found with hicpp-uppercase-literal-suffix

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
194fa4a548 [clang-tidy] performance
Found with performance*

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
8d3377e923 [clang-tidy] Use C++ using instead of typedef
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
be036c443e [clang-tidy] use bool literals
Found with modernize-use-bool-literals

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
27f607ae8b [clang-tidy] use range based loop
Found with modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
220f0a132d [clang-tidy] use auto when casting
Found with modernize-use-auto

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Lior Stern
321e1ed26a Check that parser is not nullptr before calling libdata.
Avoids a possible nullptr dereference in
parse_execution_context_t::check_end_execution
2020-04-04 14:47:58 -07:00
Lior Stern
1b23e5471d check the value of nodeptr in tnode_t::source_range.
Avoids a possible nullptr dereference
2020-04-04 14:47:58 -07:00
Johannes Altmanninger
bd91497de2 Refactor read_init, it is not meant to fail 2020-04-04 19:19:50 +02:00
Jason Nader
21bbd2ecb4 Return 1 if non-existent field is given 2020-04-04 15:30:09 +02:00
Jason Nader
1329a40e87 Allow simple ranges to be specified for --fields 2020-04-04 15:30:08 +02:00
Jason Nader
46dfc5ce0d IWYU keeps falsely flagging this 2020-04-04 15:30:08 +02:00
Jason Nader
7cb1d3a646 Add string split --fields 2020-04-04 15:30:08 +02:00
Soumya
61a9cdaa74 Add $fish_kill_signal to track the signal that terminated a command.
Set to `0` if the command exited normally.
2020-04-02 09:32:32 +02:00
Johannes Altmanninger
66ae1a1edb Add -h flag to builtin wait 2020-04-02 09:25:08 +02:00
Johannes Altmanninger
33d963dad9 Make job a background job when its child process is stopped
Fixes #6830

For some reason, with this change, typing "vi", Control-Z, and 2 x Control-D,
results in the cursor not moving correctly, but this only
seems to happen when starting fish from a fish that doesnt have this fix.
I hope that is a temporary glitch.
2020-03-30 07:32:57 +02:00
Soumya
8c0ee6ebc9 Use an unlikely to collide username for tests
The prefix 'haha' is short enough, (and phonetic enough), that it could collide with an existing user on the system where the tests are running, causing the test to fail.
2020-03-28 05:41:53 +01:00
Johannes Altmanninger
6699a72e0e Handle child receiving SIGCONT
Fixes #6818
2020-03-27 20:30:58 +01:00
Fabian Homborg
1406d63b85 Restyle
I kinda hate how fussy clang-format is. It reflows text
constantly (line limit), forces things onto one line *except* when
they're too long, and wants to turn this:

```c++
    return true;;
```

into this:

```c++
    return true;
    ;
```

instead of, you know, eliminating the second semicolon?

Anyway, it is what it is and we use it, I'll just look into getting some
more slack.
2020-03-26 20:45:40 +01:00
Soumya
654a266b22 Fix typo: '\E' is not an escape sequence. 2020-03-26 17:09:52 +01:00
Soumya
96563d6eff jobs: suppress "No suitable job" if -q is given
This allows code of the form `if jobs -q $some_pid` in scripts to check whether a previously started job is still running. Previously this would return the correct value, but also print an error message.

The invalid argument errors will still be printed.
Added test cases for both.
2020-03-26 17:09:09 +01:00
Johannes Altmanninger
64a89f882d Fix directory highlighting with custom CDPATH
Reproduce: `set CDPATH . /usr; mkdir foo` Then type "cd foo" and notice
that foo is highlighted incorrectly, because there is no /usr/foo.
2020-03-25 20:36:58 +01:00
Fabian Homborg
26c51817f2 Print better error if one argument is too long
Fixes #6800
2020-03-24 17:23:41 +01:00
George Christou
a45ffb7993 string/trim: Add VT to list of default chars 2020-03-23 18:37:08 +01:00
George Christou
a3436110c1
Add string sub --end (#6765) 2020-03-22 15:53:09 +01:00
Fabian Homborg
638a66c8ff pwd: Add "--physical" and "--logical" long options
These were already mentioned in the completions, and we don't
typically add short-only options.

Fixes #6787.
2020-03-21 16:21:15 +01:00
Johannes Altmanninger
75ae172ba2 token search: replace only until the end of the token
Fixes #6774
2020-03-20 14:05:49 +01:00
Johannes Altmanninger
390647ae34 Suppress history autosuggestion for command lines prefixed with a space
Currently we do not add such command lines to the history, so there
won't be a suggestion from history anyway.

Fixes #6763 which occurs because midnight commander feeds fish commands
like this one (note the loading space)

` cd (printf '%b' '\0057home\0057johannes\0057git\0057fish\0055shell\0057build')`
2020-03-19 18:59:20 +01:00
Fabian Homborg
4a9f52466a Set locale during timer test
Fixes #6757
2020-03-15 21:01:11 +01:00
Fabian Homborg
cb16d9e741 fish_indent: Allow escaped newlines only for certain things
Things like

```fish
\
echo foo
```

or

```fish
echo foo; \
echo bar
```

are a formatting blunder and should be handled.

This makes it so the escaped newline is removed, and the
semicolon/token_type_end handling will then put the statements on
different lines.

One case this doesn't handle brilliantly is an escaped newline after a
pipe:

```fish
echo foo | \
cat
```

is turned into

```fish
echo foo | cat
```

which here works great, but in long pipelines can cause issues.

Pipes at the end of the line cause fish to continue parsing on the
next line, so this can just be written as

```fish
echo foo |
cat
```

for now.
2020-03-15 21:01:00 +01:00
ridiculousfish
f9f5775ccc Switch to C++ random number generator for history vacuum interval 2020-03-14 15:22:46 -07:00
ridiculousfish
87b1c02832 Reformat C++ files 2020-03-14 15:07:54 -07:00
Rosen Penev
fee08a87e9 [cppcheck] add const in several places
Found with constParameter, functionConst, constVariable, constArgument

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-14 15:07:54 -07:00
Rosen Penev
39861d54c5 [cppcheck] add some std::move
Found with passedByValue

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-14 15:07:54 -07:00
Rosen Penev
c3cb44cd22 [cppcheck] don't use rand_r
POSIX 2008 marks it as obsolete.

Found with rand_rCalled

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-14 15:03:14 -07:00
Rosen Penev
fdb2837bc7 [cppcheck] fix wrong format
Found with invalidPrintfArgType_uint

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-14 15:03:14 -07:00
Johannes Altmanninger
3816c4bb39 Add comment about rounding in timer and appease clang-format 2020-03-14 13:34:31 +01:00
afg
f864bd83ad time builtin: align output columns on rare cases
1. When the wall time and cpu time rows has different units
   e.x. running multiple cores
2. When duration is around 1E3 or 1E6 microseconds
   printf("%6.2F", 999.995) gives 1000.00 which is 7 digits
2020-03-14 13:20:14 +01:00
Fabian Homborg
6237a24573 Fix output with C locale
If given a prompt that includes a non-ascii char and a C locale, fish
currently fails to properly display it.

So you set `function fish_prompt; echo 😃; end` and it shows empty
space.

While the underlying cause is obviously using a C locale and non-C
characters to begin with, this is an unacceptable failure mode.

Apparently I misunderstood wcstombs, so I inadvertently broke this in
2b0b3d3 while trying to fix 5134949's crash.

Just return the offending bit to pre-5134949 levels, so instead of an
infinite recursion we just call a lame function a couple of times.
2020-03-11 20:37:00 +01:00
Delapouite
4ba98b4d6c fix(cd): remove duplicated comment introducing the cd builtin 2020-03-10 18:24:07 +01:00
Fabian Homborg
6deef37c66 fish_indent: Add more acceptable chars for unquoted words
This adds "_", "-" and "/" as characters for words we strip quotes
from.

The list is admittedly a tad arbitrary.
2020-03-09 19:46:43 +01:00
Fabian Homborg
dc228432d2 fish_indent: Don't unescape backslash-escapes 2020-03-09 19:46:43 +01:00
Fabian Homborg
2f56462e46 unescape_string: Add flag to skip backslash-unescaping
This is sometimes not wanted, like in the case of fish_indent.
2020-03-09 19:46:43 +01:00
Fabian Homborg
b25f72f391 Teach fish_indent to remove useless quotes
This tries to see if quotes guard some expansion from happening. If it
detects a "weird" character it'll leave the quotes in place, even in
some cases where it might not trigger.

So

    for i in 'c' 'color'

turns into

    for i in c color

The rationale here is that these quotes are useless, wasting
space (and line length), but more importantly that they are
superstitions. They don't do anything, but look like they do.

The counter argument is that they can be kept in case of later
changes, or that they make the intent clear - "this is supposed to be
a string we pass".
2020-03-09 19:46:43 +01:00
ridiculousfish
5886b961d8 Send events more often for variable sets outside of builtin_set
When changing certain variables programmatically, ensure that events
are sent. Fixes #6653
2020-03-08 23:28:37 -07:00
ridiculousfish
77ad459aae Pull char_input_style_t into a top-level enum
Review feedback from
https://github.com/fish-shell/fish-shell/pull/6713#pullrequestreview-369853776
2020-03-07 13:55:19 -08:00
ridiculousfish
f73e324618 Teach the reader fast path about self-insert-notfirst
This teaches the reader fast-path to use self-insert-notfirst, allowing
it to handle spaces. This greatly increases the performance of paste by
reducing redraws.

Fixes #6603. Somewhat improves #6704
2020-03-07 13:31:55 -08:00
ridiculousfish
b8a7cdacb6 Implement self-insert-notfirst in reader
This adds basic support for self-insert-notfirst. When we see a
self-insert-nonempty char event, we kick it back to the outer loop,
which only inserts the character if the cursor is not at the beginning.
2020-03-07 13:31:55 -08:00
ridiculousfish
2e4cb15880 Add self-insert-notfirst readline command
This adds a new readline command self-insert-notfirst, which is
analogous to self-insert, except that it does nothing if the cursor
is at the beginning. This will serve as a higher-performance implementation
for stripping leading spaces on paste.
2020-03-07 13:31:55 -08:00
ridiculousfish
e334becefb Adopt debounce for highlighting and autosuggestions
This prevents a thundering herd of threads for certain interactive
scenarios.
2020-03-06 17:15:23 -08:00
ridiculousfish
bde2f2111d Introduce debounce_t
debounce_t will be used to limit thread creation from background highlighting
and autosuggestion scenarios. This is a one-element queue backed by a
single thread. New requests displace any existing queued request; this
reflects the fact that autosuggestions and highlighting only care about
the most recent result.

A timeout allows for abandoning hung threads, which may happen if you
attempt to e.g. access a dead hard-mounted NFS server. We don't want
this to defeat autosuggestions and highlighting permanently, so allow
spawning a new thread after the timeout (here 500 ms).
2020-03-06 17:15:21 -08:00
ridiculousfish
a6b565d502 Optimize parse_util_compute_indents
Exploit the fact that most input strings will not contain newlines,
in which case we do not have to parse anything.
2020-03-06 16:15:37 -08:00
afg
f0d42ea602 time: decide unit using largest value 2020-03-06 22:16:24 +01:00
ridiculousfish
f10ef4f948 Remove cancellable.h
This should never have been checked in, it's unused. Mea culpa.
2020-03-04 21:11:39 -08:00
Norio Nomura
4f0fab04ad Clear cancellation_signal before firing fish_postexec event
Fix #2356
2020-03-03 21:35:29 -08:00
Sacha Delanoue
0fac2e0496 Fix 256 color detection on xterm-like
bbc3fecbe introduced a regression where support for 256 color was not
detected on xterm-like terminals that did not define the TERM_PROGRAM
env variable. Almost no terminal on linux define this variable.
2020-03-03 18:03:15 +01:00
ridiculousfish
f6e5a5c521 Thread a cancellation function into is_potential_path
Allows sooner cancellation of redundant operations like highlighting.
2020-03-02 22:10:43 -08:00
ridiculousfish
a65e3f1876 Check for cancellation more often in highlighting 2020-03-02 22:02:03 -08:00
ridiculousfish
8355285736 Add a category for screen repainting 2020-03-02 18:31:24 -08:00
ridiculousfish
bd17262e17 Reduce iteration count in thread torture test
Helps the test pass on 32 bit.
2020-03-02 13:46:08 -08:00
ridiculousfish
bb4e36da47 Do not remove jobs that need to print a status message
55e3270 introduced a regression where we would remove all completed
jobs. But jobs that want to print a status message get skipped, so
the status message (and associated event handlers) might not get run.

Fix this by making it explicit which jobs are safe to process, and which
should be skipped.

Fixes #6679.
2020-03-02 12:34:07 -08:00
ridiculousfish
bc702ccb31 Fix interactive --on-signal INT handlers
f8ba0ac5bf introduced a bug where INT handlers would themselves be
cancelled, due to the signal. Defer processing handlers until the
parser is ready to execute more fish script.

Fixes the interactive case of #6649.
2020-03-01 13:31:59 -08:00
Fabian Homborg
bfc1de9ef4 argparse: Pass validation variables as exported
This was written before local-exported variables did anything useful.

Passing these vars as local-exports removes the need to define the
validation function with `--no-scope-shadowing` which is quite the
hack.
2020-03-01 19:28:51 +01:00
mczoden
5d03ca9de0
Fix expand.cpp compile failed with old SDK version (#6688)
* Fix expand.cpp compile failed with old SDK version

* add a comment to stop clang-format from recording
2020-03-01 13:44:06 +01:00
ridiculousfish
d4103d582b Correct the speeling of sentinel 2020-02-29 15:56:52 -08:00
ridiculousfish
c5fa580948 Rationalize background-in-background procs
If a background process runs a fish function which launches another
background process, ensure that these background procs get different
pgroups. Add a test for it.
2020-02-29 15:07:09 -08:00
ridiculousfish
eb83794783 Add some additional proc_pgroup FLOGging 2020-02-29 14:41:08 -08:00
Johannes Altmanninger
8eadef81a4 Fix crash on escape in complete-and-search pager
Reproduce with `: <Shift+Tab><Escape>`.
Introduced in 8a033b9f3 Add undo
2020-02-29 21:19:28 +01:00
Johannes Altmanninger
91fcb8c42c Revert "read: discard IFS delimiters before the last token"
See #6650.

This reverts commit 1410f938aa.
2020-02-29 09:53:53 +01:00
Johannes Altmanninger
99851c09b3 Fix selection going out of bounds
Which happened when starting the selection at the end of the commandline.
In this case, selections still interact weirdly with autosuggestions (the
first character of the suggestion appears to be part of the selection
when it's not).

Fixes #6680
2020-02-29 09:47:12 +01:00
Fabian Homborg
70b8fb22e1 test: Reject nan/inf instead of crashing
I really don't want to get into the business of explaining to people
how nan != nan.

Fixes #6655.
2020-02-26 16:43:12 +01:00
Johannes Altmanninger
aa0e16b1a5 Skip variable assignments in status current command
Fixes #6635
2020-02-24 00:16:12 +01:00
Johannes Altmanninger
ebde9a6a44 move variable_assignment_equal_pos to tokenizer
we'll need it for tok_command
2020-02-24 00:14:39 +01:00
Johannes Altmanninger
7ef7f93a90 List time as builtin, support time --help
`a=b time foo` will no longer call an external `time` command
(like it does in bash).

Fixes #6598
2020-02-23 23:42:57 +01:00
Rosen Penev
a410dcb5c2 [clang-tidy] use empty() instead of comparing
Found with readability-container-size-empty

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:34:03 +01:00
Rosen Penev
33351d7657 [clang-tidy] remove static from namespace
Found with readability-static-definition-in-anonymous-namespace

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:34:02 +01:00
Rosen Penev
8b76fe93bf [clang-tidy] fix small loop variable
Found with bugprone-too-small-loop-variable

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:58 +01:00
Rosen Penev
925c7a998a [clang-tidy] mark single argument constructors explicit
Found with hicpp-explicit-conversions

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:17 +01:00
Rosen Penev
aff6a74770 [clang-tidy] use emplace_back
Found with hicpp-use-emplace

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:17 +01:00
Rosen Penev
1f01423f46 [clang-tidy] use dynamic_cast for unrelated types
Found with cppcoreguidelines-pro-type-static-cast-downcast

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:17 +01:00
Rosen Penev
aae9ebfbd4 [clang-tidy] use using instead of typedef
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:16 +01:00
Rosen Penev
dd704ae30c [clang-tidy] pass-by-value
Found with modernize-pass-by-value

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:16 +01:00
Rosen Penev
b266370428 [clang-tidy] convert to range for loops
Found with modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:16 +01:00
Fabian Homborg
e5d50db215 Add missing include to fish_test_helper
This broke the build on new-ish gcc

Fixes #6632.
2020-02-20 21:53:45 +01:00
ridiculousfish
9538b8bf73 Give fish_test_helper slightly better argument parsing and help 2020-02-20 11:51:02 -07:00
Fabian Homborg
ee943a0821 Make unusable path warnings their own FLOG category
Fixes #6630.
2020-02-20 17:30:14 +01:00
ridiculousfish
05b8d4de97 Make hup_background_jobs accept the job list directly 2020-02-19 20:35:04 -07:00
ridiculousfish
59c6663a16 Migrate the "are you sure you want to exit" logic from parse_execution to exec
This feels more like the sort of logic that should live in the point where
jobs are executed, instead of where jobs are created from parse trees.
2020-02-19 18:25:36 -07:00
ridiculousfish
1c8093fc50 Bravely remove the "temporary backgrounding" code
Prior to this commit, when executing a builtin, we mark the job as not
foreground. After this commit we no longer modify the foreground state
of the job just for the builtin.

There was the following comment:

    // Since this may be the foreground job, and since a builtin may execute another
    // foreground job, we need to pretend to suspend this job while running the
    // builtin, in order to avoid a situation where two jobs are running at once.

The concern seemed to be in the `bg` and `fg` builtins, which might attempt
to foreground or background the jobs associated with `bg` and `fg` themselves.
But the builtins run before the job is marked constructed, so it cannot
actually happen.

Bravely remove this code.
2020-02-19 18:25:36 -07:00
Aaron Gyes
85a0ca66e0 We no longer have two doc systems, move sphinx_doc_src back to doc_src 2020-02-19 17:00:35 -08:00
Fabian Homborg
fba4363c1d Stop fish --no-execute harder from executing stuff
I'm not quite sure what it executed - I think it's just constructing jobs and
stuff, but it did show up in the profile - 21% spent on "job_reap".
2020-02-17 14:26:30 +01:00
Fabian Homborg
65883e0e40 Restyle
Mostly line breaks, one instance of tabs!

For some reason clang-format insists on two spaces before a same-line comment?

(I continue to be unimpressed with super-strict line length limits,
but I continue to believe in automatic styling, so it is what it is)

[ci skip]
2020-02-17 14:14:05 +01:00
Fabian Homborg
5f9c33b50a Don't time --no-execute
This made some output for non-execution.

See #977.
2020-02-17 11:39:53 +01:00
Fabian Homborg
3f5c60e634 Silence some errors for fish --no-execute
It used to error out when a command wasn't known, even when it was a
function that would only be discovered via autoloading.

Now we just accept that a command doesn't exist when no-execute is
given - we're not gonna execute it anyway.

Also, in the same breath stop counting empty commands after expansion
and empty wildcard expansions as errors - these depend on runtime
values, so we can't verify them without executing.

Fixes #977.

(note that it still executes "time", but that's another commit)
2020-02-17 11:39:53 +01:00
Fabian Homborg
aba900a71f Reallow "2>>&1" as a redirection
Appending to an fd doesn't really make sense, but we allowed the
syntax previously and it was actually used.

It's not too harmful to allow it, so let's just do that again.

For the record: Zsh also allows it, bash doesn't.

Fixes #6614
2020-02-17 08:57:41 +01:00
Johannes Altmanninger
7517128b68 Update exports when an exported universal variable changes
Fixes #6612
2020-02-16 18:51:19 +01:00
Lily Ballard
47aeaa1535 Work around compilation failure with old Apple SDKs
When building fish-shell with the macOS 10.12 SDK, <sys/proc.h> does not
include <sys/time.h> but references `struct itimerval`. This causes a
compilation failure if we don't import <sys/time.h> ourselves.

This was previously masked by an import of <sys/sysctl.h>, which was
removed in fc0c39b6fd.
2020-02-15 10:58:22 +01:00
Fabian Homborg
399a71645e Fix build on 32-bit systems
This was a weird case of the integer converseys.

Fixes #6609.
2020-02-15 10:13:56 +01:00
Fabian Homborg
f79ff72096 iothread: include cstdint, correctly
Yeah, this was needed in the *header*.

God I hate headers.

Fixes #6604, for real this time
2020-02-14 20:52:14 +01:00
Fabian Homborg
d80d39dd6a iothread: Include cstdint
For uint64_t.

Needed for some configurations with glibc.

Fixes #6604.
2020-02-14 20:43:05 +01:00
Fabian Homborg
13b470af07 Readd ^&1 redirection
This was lost in 35671dd9f0.

Even tho we plan to drop caret redirection, while it's there it should
fully work.

Fixes #6591.
2020-02-14 20:28:46 +01:00
Fabian Homborg
f053cd27c6 Return glob ordering to pre-3.1 state
Glob ordering is used in a variety of places, including figuring out
conf.d and really needs to be stable.

Other ordering, like completions, is really just cosmetic and can
change if it makes for a nicer experience.

So we uncouple it by copying the wcsfilecmp from 3.0.2, which will
return the ordering to what it was in that release.

Fixes #6593
2020-02-14 19:06:19 +01:00
Fabian Homborg
ceba851d44 parser: Stop crashing when cwd isn't readable
Everything seems to be working, so instead of crashing just print an
error and return.

Fixes #6597
2020-02-14 17:57:07 +01:00
ridiculousfish
35a50d5aff Clean up the "press a key" prompt in fish_key_reader
No need for two newlines.
2020-02-13 01:08:35 -08:00
ridiculousfish
c5d2a69378 Remove debug_level from fish_key_reader
These were not useful.
2020-02-13 01:08:35 -08:00
ridiculousfish
89644911a1 Eliminate fish_key_reader signal handlers
They call wgettext, wfprintf, etc. and are so wildly unsafe.
2020-02-13 01:06:30 -08:00
Fabian Homborg
fa7a2975d8 Include sys/select.h for fd_set
Fixes build on musl.
2020-02-12 22:02:32 +01:00
Fabian Homborg
a6bd5fac0c Fix compiler warning in the tests
pid_t might be a long, so let's format it as a long and cast it explicitly.
2020-02-12 22:02:32 +01:00
Fabian Homborg
f44f9f1e89 Drop "invalid wide character string" warning down to a debug
This is *super annoying* if you have a non-ascii char in your prompt
and accidentally have a C locale. Renders fish borderline unusable.

Fixes #6584
2020-02-12 15:00:40 +01:00
Aaron Gyes
d556f04823 Revert "timer.cpp: use units like 'ms', etc. vs. "millis""
This reverts commit c01356ddd1.

Tests broken
2020-02-12 02:06:30 -08:00
Aaron Gyes
c01356ddd1 timer.cpp: use units like 'ms', etc. vs. "millis"
Change wording and omit '.00' decimal points in times
2020-02-12 01:53:48 -08:00