Commit Graph

2601 Commits

Author SHA1 Message Date
ridiculousfish
ac2eed2ffa Make io_chain_t store const io_data_t
This will make it easier to reason about with concurrent execution.
2019-11-10 14:00:30 -08:00
ridiculousfish
521d0e84f5 Remove non-const get_io_for_fd
These could be made unused.
2019-11-10 13:41:12 -08:00
ridiculousfish
424c56006d Add a paranoid assert to io_chain_t::append 2019-11-10 13:31:47 -08:00
ridiculousfish
f2093aef43 Remove io_chain_t::push_front
It was unused.
2019-11-10 13:25:55 -08:00
ridiculousfish
87f4f33600 Remove vars parameter from function_exists_no_autoload
This variable was unused.
2019-11-10 13:13:56 -08:00
ridiculousfish
2555ecf757 Remove the forbidden function stack
Detect forbidden functions directly from the associated block_t.
Also unify where we do stack overflow detection.
2019-11-10 12:36:46 -08:00
ridiculousfish
7bd134f795 Reformat all .cpp files 2019-11-09 16:07:33 -08:00
ridiculousfish
896ef65f8c Rename error_offset to error_offset_within_token
Hopefully clarify the role of this variable.
2019-11-08 16:56:50 -08:00
ridiculousfish
ef8b5e4fa0 Correct certain tokenizer error reporting for unclosed subshells
There was some confusion about the different pointers and offsets
in tokenizer_t::call_error.

Fixes #6281
2019-11-08 16:56:43 -08:00
ridiculousfish
eb2386f3e3 Rename tokenizer_t::buff to token_cursor
That should clarify its role vis-a-vis 'start'.
2019-11-08 16:56:18 -08:00
ridiculousfish
7f59a7e7cf Only dispatch variable changes for the principal variable stack or globals
fish will react to certain variable modifications, such as "TZ." Only do
this if the main stack is modified. This has no effect now because there
is always a single stack, but will become important when concurrent
execution is supported.
2019-11-07 23:15:35 -08:00
ridiculousfish
8f3d745e60 Teach env_stack_impl_t to report whether it modifies a global
This will help in limiting variable dispatch changes to global and
principal modifications.
2019-11-07 23:15:35 -08:00
Johannes Altmanninger
e94b9ccf3e Do import bash history commands containing && or || 2019-11-07 23:33:35 +01:00
Johannes Altmanninger
1cfa3fa819 Speed up import of bash history
Fixes #6295
2019-11-07 23:33:35 +01:00
Johannes Altmanninger
08eac28bd8 Add individual documentation pages for string's subcommands
This adds string-x.rst for each subcommand x of string. The main page
(string.rst) is not changed, except that examples are shown directly after
each subcommand.  The subcommand sections in string.rst are created by
textual inclusion of parts of the string-x.rst files.

Subcommand man pages can be viewed with either of:

```
man string collect
man string-collect
string collect <press F1 or Alt-h>
string collect -h
```

While `string -h ...` still prints the full help.

Closes #5968
2019-11-07 09:54:25 +01:00
Johannes Altmanninger
939d4674e4 Do not compute $history in builtin set.
Most uses of set don't care about the value of $history, and it
can be expensive to compute.

See #6290
2019-11-05 16:53:06 +01:00
Johannes Altmanninger
23eb6e9c09 Don't compute $history for variable completion description
Fixes #6288
2019-11-05 13:06:52 +01:00
Johannes Altmanninger
277fca9c6a Complete all available commands on empty commandline 2019-11-05 09:50:37 +01:00
Johannes Altmanninger
4c73382231 Fix function definitions potentially leaking as completions 2019-11-05 09:50:37 +01:00
Fabian Homborg
d77c465d23 string: Allow -eq again
Instead of forbidding it for both modes, allow it for both and make it
quiet for string.

Fixes #6282
2019-11-04 17:34:37 +01:00
Johannes Altmanninger
6fb7f9b6b8 Fix completion for builtins (with subcommands)
Presently the completion engine ignores builtins that are part of the
fish syntax. This can be a problem when completing a string that was
based on the output of `commandline -p`.  This changes completions to
treat these builtins like any other command.

This also disables generic (filename) completion inside comments and
after strings that do not tokenize.

Additionally, comments are stripped off the output of `commandline -p`.

Fixes #5415
Fixes #2705
2019-11-04 16:44:51 +01:00
ridiculousfish
47c0b5f931 Simplify history searching and fix deduplication
The history search logic had a not very useful "fast path" which was also
buggy because it neglected to dedup. Switch the "fast path" to just a
history search type which always matches.

Fixes #6278
2019-11-02 19:33:45 -07:00
ridiculousfish
52e900690b Make history_search_type_t an enum class 2019-11-02 18:56:16 -07:00
ridiculousfish
be35b858c5 Minor allocation reduction in format_history_record
Reuse some storage across calls.
2019-11-02 18:35:19 -07:00
ridiculousfish
72bf5898d3 Clean up how PATH and CDPATH munging occurs
PATH and CDPATH have special behavior around empty elements. Express this
directly in env_stack_t::set rather than via variable dispatch; this is
cleaner.
2019-11-02 16:48:08 -07:00
ridiculousfish
a7f1d2c0c7 Add support for fish_trace variable to trace execution
This adds support for `fish_trace`, a new variable intended to serve the
same purpose as `set -x` as in bash. Setting this variable to anything
non-empty causes execution to be traced. In the future we may give more
specific meaning to the value of the variable.

The user's prompt is not traced unless you run it explicitly. Events are
also not traced because it is noisy; however autoloading is.

Fixes #3427
2019-11-02 14:40:57 -07:00
Per Bothner
5ece4481a5 Prefer using clr_eos to clear "remaining lines" - but reset color first
This un-reverts pull request #6190, but adds a missing
reset of the color before doing the clr_eos.
2019-11-02 14:34:04 -07:00
ridiculousfish
151e75d141 Autosuggestions to validate the first command, not the last command
When considering an autosuggestion from history, we attempt to validate the
command to ensure that we don't suggest invalid (e.g. path-dependent)
commands. Prior to this fix, we would validate the last command in the
command line (e.g. in `cd /bin && ./stuff` we would validate "./stuff".
This doesn't really make sense; we should be validating the first command
because it has the potential to change the PWD. Switch to validating the
first command.

Also remove some helper functions that became dead through this change.
2019-11-02 13:40:31 -07:00
Johannes Altmanninger
6702c84d15 Prevent buffer overflow when custom completions edit the commandline
This was introduced in a7ea7648c3
"Completion: maintain cursor position when there is no completion"
2019-11-01 13:21:49 +01:00
Fabian Homborg
c0d8439f3a math: Print special error for logical operators
Until now, something like

`math '7 = 2'`

would complain about a "missing" operator.

Now we print an error about logical operators not being supported and
point the user towards `test`.

Fixes #6096
2019-11-01 08:43:13 +01:00
0x005c
067b30208d Fix math incorrect parenthesis error on missing term 2019-10-31 22:10:54 +01:00
Fabian Homborg
ec4bbe248e Revert "Prefer using clr_eos to clear "remaining lines""
This reverts commit d502ad2c25.

Fixes #6263
2019-10-31 19:15:03 +01:00
Johannes Altmanninger
61486954bc Use a pager to view long outputs of builtin --help
Every builtin or function shipped with fish supports flag -h or --help to
print a slightly condensed version of its manpage.
Some of those help messages are longer than a typical screen;
this commit pipes the help to a pager to make it easier to read.

As in other places in fish we assume that either $PAGER or "less" is a
valid pager and use that.

In three places (error messages for bg, break and continue) the help is
printed to stderr instead of stdout.  To make sure the error message is
visible in the pager, we pass it to builtin_print_help, every call of which
needs to be updated.

Fixes #6227
2019-10-28 18:36:07 +01:00
ridiculousfish
d992480204 Clean up a few string handling bits 2019-10-27 16:22:42 -07:00
ridiculousfish
eeac3333df Correctly highlight input following a tokenizer error 2019-10-27 16:08:49 -07:00
ridiculousfish
afd20b8e1a Correctly report the range of tokenizer errors
This enables proper syntax highlighting of tokenizer errors.
2019-10-27 16:05:37 -07:00
ridiculousfish
0bfd897ee0 Add a special error message for |& 2019-10-27 15:24:57 -07:00
ridiculousfish
2a92e66902 Support for &> and &| as convenience redirections
This adds support for &> and &| syntax, which both redirect stdout, and
also apply a redirection of stderr to stdout.
2019-10-27 15:24:57 -07:00
Johannes Altmanninger
a930cabb91 Update comment 2019-10-27 06:58:20 +01:00
Johannes Altmanninger
9564e4a6d6 Fix formatting in dump_tree 2019-10-27 06:58:20 +01:00
Johannes Altmanninger
785b7d9438 typo 2019-10-24 10:46:02 +02:00
LawAbidingCactus
305a657694 fix typos 2019-10-23 19:38:44 +02:00
Aaron Gyes
59e4314752 Apply --reverse for fish_color_*'s being used for a background
e.g. Allows using `--reverse` in fish_pager_color_search_match
and actually having the selected pager items display reversed.
2019-10-22 16:28:56 -07:00
Fabian Homborg
66938d206a string: Error out on match -eq
The `--entire` would enable output even though the `--quiet` should
have silenced it. These two don't make any sense together so print an
error, because the user could have just left off the `-q`.
2019-10-22 22:11:36 +02:00
Fabian Homborg
fc0c39b6fd expand: Remove unused includes
sys/sysctl.h is deprecated on glibc, so it leads to warnings.
According to fa4ec55c96, it was included for KERN_PROCARGS2 for
process expansion, but process expansion is gone, so it's unused now.

(there is another use of it in common.cpp, but that's only on FreeBSD)

Also 1f06e5f0b9 only included
tokenizer.h (present since the initial commit) if KERN_PROCARGS2
wasn't available, so it can't have been important.

This builds and passes the tests on:

- Archlinux, with glibc 2.30
- Alpine, with musl
- FreeBSD
- NetBSD
2019-10-19 14:20:53 +02:00
Johannes Altmanninger
b7f35f949e Do not import vars that are equivalent to a universal exported var
Universal exported variables (created by `set -xU`) used to show up
both as universal and global variable in child instances of fish.

As a result, when changing an exported universal variable, the
new value would only be visible after a new login (or deleting the
variable from global scope in each fish instance).

Additionally, something like `set -xU EDITOR vim -g` would be imported
into the global scope as a single word resulting in failures to
execute $EDITOR in fish.

We cannot simply give precedence to universal variables, because
another process might have exported the same variable.  Instead, we
only skip importing a variable when it is equivalent to an exported
universal variable with the same name.  We compare their values after
joining with spaces, hence skipping those imports does not change the
environment fish passes to its children. Only the representation in
fish is changed from `"vim -g"` to `vim -g`.

Closes #5258.
This eliminates the issue #5348 for universal variables.
2019-10-19 12:41:57 +02:00
Johannes Altmanninger
5e274066e3 Always return absolute path in path_get_cdpath
Fixes #6220
2019-10-19 12:38:17 +02:00
ridiculousfish
c8332bae8c sucess -> success, failiure -> failure 2019-10-18 18:36:03 -07:00
ridiculousfish
9652b3e11b Clean up job_or_process_extent
This had a bad merge which happened to work, plus some other nonsense.
2019-10-18 15:24:28 -07:00
Johannes Altmanninger
2fed311d4c builtin commandline: fix flags -p and -j not splitting on && and ||
Fixes #6214
2019-10-18 09:36:52 +02:00
ridiculousfish
3c727173c2 Include ctime in history_file.h
Fixes a build failure on FreeBSD.

Fixes #6210
2019-10-16 11:55:40 -07:00
Johannes Altmanninger
eae1683033 Completion: complete argument to last of a group of short options
Consider a group of short options, like -xzPARAM, where x and z are options and z takes an argument.

This commit enables completion of the argument to the last option (z), both within the same
token (-xzP) or in the next one (-xz P).

complete -C'-xz' will complete only parameters to z.
complete -C'-xz ' will complete only parameters to z if z requires a parameter
otherwise, it will also complete non-option parameters

To do so this implements a heuristic to differentiate such strings from single long options. To
detect whether our token contains some short options, we only require the first character after the
dash (here x) to be an option. Previously, all characters had to be short options. The last option
in our example is z. Everything after the last option is assumed to be a parameter to the last
option.

Assume there is also a single long option -x-foo, then complete -C'-x' will suggest both -x-foo and
-xy. However, when the single option x requires an argument, this will not suggest -x-foo.
However, I assume this will almost never happen in practise since completions very rarely mix
short and single long options.

Fixes #332
2019-10-16 11:30:50 +02:00
Johannes Altmanninger
41bcf77e25 fix comment 2019-10-16 11:25:11 +02:00
ridiculousfish
cc1c973025 Remove job_flags as an enum, just use a struct
This removes an over-complicated flag implementation, replacing it with
just a plain struct.
2019-10-15 14:40:58 -07:00
ridiculousfish
35671dd9f0 Clean up and unify pipes and redirections
This cleans up how pipes and redirections are recognized by the parser,
and unifies pipes and redirections into a single type.
2019-10-15 11:26:41 -07:00
Johannes Altmanninger
2d2e15b63d Silently ignore recursive calls to complete -C without parameter
In e167714899 we allowed recursive calls
to complete. However, some completions use infinite recursion in their
completions and rely on `complete` to silently stop as soon as it is
called recursively twice without parameter (thus completing the
current commandline). For example:

complete -c su -s -xa "(complete -C(commandline -ct))"
su -c <TAB>

Infinite recursion happens because (commandline -ct) is an empty list,
which would print an error message.  This commmit explicitly detects
such recursive calls where `complete` has no parameter and silently
terminates.  This enables above completion (like before raising the
recursion limit) while still allowing legitimate cases with limited
recursion.

Closes #6171
2019-10-15 13:36:28 +02:00
Johannes Altmanninger
cf3b24cf62 fix typo 2019-10-15 13:30:21 +02:00
Aaron Gyes
d1970c7f2e read_ni: be more specific in error if a file can't be read
for example, `fish /etc` now tells us "Is a directory"

make a couple char constants wchar_t constants
2019-10-14 01:43:35 -07:00
Aaron Gyes
5d84d3fe48 reader.cpp: remove unused pointer in read_ni
literally prehistoric in git blame
2019-10-14 00:42:03 -07:00
ridiculousfish
4b6de8b4a3 Clean up a stale comment. 2019-10-13 23:05:55 -07:00
ridiculousfish
c160492d42 Remove tok_t::redirected_fd
This wasn't used for anything.
2019-10-13 23:04:18 -07:00
ridiculousfish
1a65e18ba8 Clean up some tokenization
Remove TOK_NONE
Turn token_type into an enum class
Make next() turn a maybe_t<tok_t> instead of a bool
2019-10-13 16:06:16 -07:00
ridiculousfish
82eca4bc86 Run clang-format on all files
The main change here is to reorder headers.
2019-10-13 15:50:48 -07:00
Per Bothner
d502ad2c25 Prefer using clr_eos to clear "remaining lines"
This is both more efficient than multiple clr_eol sequences,
and also works better with shell-integration.
2019-10-13 12:12:44 -07:00
Aaron Miller
15ed682bfa Fix options after --argument-names to function (#6188)
This stops reading argument names after another option appears. It does not break any previous uses and in fact fixes uses like

```fish
function foo --argument-names bar --description baz
```

* `function` command handles options after argument names (Fixes #6186)

* Removed unneccesary test
2019-10-10 18:09:26 +02:00
Fabian Homborg
a7913c3a10 function: Reject invalid variable names for --argument-names
Fixes #6147.
2019-10-07 21:26:41 +02:00
Johannes Altmanninger
f91c725ff0 Fix caret position of invalid expansion in command position
Fixes #5812
2019-10-06 13:43:05 -07:00
Johannes Altmanninger
9b86d5dd16 Export all local exported variables in a new scope
Fixes #6153
2019-10-06 12:10:21 -07:00
Per Bothner
afb8f42f39 Emit omitted-newline string before fish_prompt event
See issue #6118 "omitted-newline string emitted after fish_prompt event"
2019-10-06 10:52:12 -07:00
Per Bothner
dfc45f3e10 Clear line if new indentation greater than old.
Make sure initial indentation is skipped, rather than written as spaces.
This is a tweak to pull request #5928.
2019-10-06 10:34:55 -07:00
Johannes Altmanninger
7017a2fcf9 Unexpand abbreviations' variable names before completing them
Fixes #6166
2019-10-06 14:42:42 +02:00
domdom
76f4b65981 Add prefix history search 2019-10-05 11:27:32 -07:00
Johannes Altmanninger
e167714899 Raise the recursion limit of complete
Users should generally prefer to use complete --wraps but this
corrects some unexpected behavior.

Fixes #3474
2019-10-03 21:25:19 +02:00
Johannes Altmanninger
aa011f70a8 Print an error when complete reaches its recursion limit 2019-10-03 21:25:19 +02:00
Aaron Gyes
19c575e116 builtin functions: colorize output if interactive
We can also get rid of the | fish_indent --ansi stuff in type.fish
2019-09-25 04:18:06 -07:00
Aaron Gyes
8230755bfd Make sure rgb_color_t doesn't grow
For years the comment above the class claimed it was 4 bytes, but
it had grown to 5. Add a static_assert() to prevent that from
happening again.
2019-09-24 23:34:10 -07:00
Aaron Gyes
e6c72f74a8 make rgb_color_t smaller
rgb_color_t was 5 bytes, now it's 4 again.
big arrays holding colors are going to be smaller.
2019-09-22 21:16:30 -07:00
ridiculousfish
91c4dad812 Revert "use std::tolower"
This reverts commit a3db4128bc.

This broke the build.
2019-09-22 15:33:08 -07:00
Aaron Gyes
a3db4128bc use std::tolower 2019-09-22 15:47:22 -07:00
ridiculousfish
a19d9b2e73 Add a test for #6130 2019-09-22 14:06:38 -07:00
Johannes Altmanninger
bc533ad939 Fix completion inside command substitution inserting spurious quote
Reproducer: type `: (: ""`, move the cursor after the second colon and press tab.
2019-09-22 14:06:38 -07:00
ridiculousfish
70a1d8314c Optimize parse_color 2019-09-21 19:36:56 -07:00
ridiculousfish
18b56637f7 self-insert bindings to insert their own sequence
Prior to this fix, self-insert would always wait for a new character.
Track in char_event what sequence generated the readline event, and then
if the sequence is not empty, insert that sequence.

This will support implementing the space binding via pure readline
functions.
2019-09-21 15:58:57 -07:00
ridiculousfish
1ecbe363d0 Correct an assertion message 2019-09-21 15:17:09 -07:00
ridiculousfish
3f7bc7232e yank_POP -> yank_pop 2019-09-21 14:31:22 -07:00
ridiculousfish
5f64972908 Do not try the same (command, wraps) pair more than once when completing
This prevents runaway wrap chains. Fixes #5638.
2019-09-21 14:09:38 -07:00
ridiculousfish
77dbe109e0 Allow cancellation out of expanding a runaway wrap chain
This makes it easier to control-C out of a completion.
2019-09-21 13:11:45 -07:00
ridiculousfish
3f2f44ce73 Introduce reader_test_should_cancel
This centralizes the logic around cancellation due to either sigint or a
stale threaded operation.
2019-09-21 13:07:55 -07:00
ridiculousfish
95aea7839d Show wrap targets when printing a function
Fixes #1625
2019-09-21 12:48:51 -07:00
ridiculousfish
a1f1abc137 Stop passing true to escape_string
It wants a flags, not a boolean.
2019-09-21 12:40:24 -07:00
Johannes Altmanninger
a7ea7648c3 Completion: maintain cursor position when there is no completion
Previously, tab-completion would move the cursor to the end of the current token, even
if no completion is inserted. This commit defers moving the cursor until we insert a completion.

Fixes #4124
2019-09-21 12:50:52 -07:00
Johannes Altmanninger
e9e92178a9 completions: simplify prefix computation 2019-09-21 12:50:52 -07:00
Johannes Altmanninger
6c5c0a73eb remove useless call, fix comment 2019-09-21 12:50:52 -07:00
Aaron Gyes
2b7b70a64f Ellipsis OCD 2019-09-19 11:48:37 -07:00
Aaron Gyes
fda8ad429b parse_util.cpp: remove truncate_string()
We already have something that does this
2019-09-19 10:32:07 -07:00
Aaron Gyes
cb79d8fa97 Colorize complete output
If interactive, `complete` commands are highlighted like they would
be if typed. Adds a little fun contrast and it's easier to read.

Moved a function out of fish_indent to highlight.h
2019-09-19 04:27:33 -07:00
Aaron Gyes
620761b9b9 complete: print long option names for less common ones
we now print --long options for ones I arbitrarily decided
are less likely to be remembered.

Also fixed the `--wraps` items at the end not being escaped
2019-09-19 04:21:24 -07:00
Aaron Gyes
e9ee2fb089 complete: support -k (--keep-files) in printed completions 2019-09-19 02:01:33 -07:00
Aaron Gyes
7302dcc12b complete: terser output with short options
Most of our completion scripts are written using the short options
anyhow, and this makes it less likely the output will span several
lines per command
2019-09-19 01:50:26 -07:00
David Adam
3ae12ac4d3 Revert "Escape separators (colon and equals) to improve completion"
This reverts commit f7dac82ed6 from pull
request #6059.

As discussed in #6099, this caused a regression in some completions (eg
dd).
2019-09-19 14:38:16 +08:00