Commit Graph

3609 Commits

Author SHA1 Message Date
ridiculousfish
d5d09c993e io_buffer_t to explicitly poke its item when closing
io_buffer_t is used to buffer output from a command substitution, so we
can split it into arguments. Typically io_buffer_t reads from its pipe
until it gets EOF and then stops reading. However it may be that the
cmdsub ends but EOF is not delivered because the stdout of the cmdsub
escaped with a background process.

Prior to this change we would wake up every 100 msec (select timeout) to
check if the cmdsub is finished. However this 100 msec adds latency if a
background process is launched from e.g. fish_prompt.

Switch to the new poke() function. Now when the cmdsub is finished, it
pokes its item, which explicitly wakes it up. This removes the extra
latency.

Fixes #7559
2021-01-07 11:54:31 -08:00
ridiculousfish
fd08b660c0 Add a poke function to fd_monitor
In preparation for fixing #7559, add a function poke_item to fd_monitor.

fd_monitor has a list of file descriptors, and invokes a callback when an
fd becomes readable. With this change, we assign each item a unique ID and
return it when the item is added; the ID may then be used to invoke the
callback explicitly.

The idea is that we can stop reading from the pipe associated with the
cmdsub when the job is finished, even if the pipe is still open.
2021-01-07 11:51:04 -08:00
Mahmoud Al-Qudsi
7669e8e497 Add concept of edit groups
This allows for multiple edits to be undone/redone in one go, as if they
were one edit.

Useful when a function is editing the commandline buffer via scripted
changes or via a keybinding so the internal changes to the buffer can be
abstracted away.

(Having extreme difficulty getting pexpect to play nice with the concept
of undo/redo...)
2021-01-05 15:43:34 -06:00
Fabian Homborg
6eeb8861e7 Add exit bind function
Currently binding `exit` to a key checks too late that it's exitted,
so it leaves the shell hanging around until the user does an execute
or similar.

As I understand it, the `exit` builtin is supposed to only exit the
current "thread" (once that actually becomes a thing), and the
bindings would probably run in a dedicated one, so the simplest
solution here is to just add an `exit` bind function.

Fixes #7604.
2021-01-04 09:45:34 +01:00
Fabian Homborg
85ba2ed790 type: Add missing newline
Otherwise this would print

    # Defined interactivelyfunction foo

for interactively defined functions.
2021-01-03 17:48:25 +01:00
ridiculousfish
118f710e99 Allow fish_private_mode to change at runtime
Prior to this change, `fish_private_mode` worked by just suppressing
history outright. With this change, `fish_private_mode` can be toggled on
and off. Commands entered while `fish_private_mode` is set are stored but
in memory only; they are not written to disk.

Fixes #7590
Fixes #7589
2021-01-02 22:01:47 -08:00
ridiculousfish
9fdc4f903b Explicitly track persistence mode in history_item_t
Commands that start with a space should not be written to the history
file. Prior to this change, that was implemented by simply not adding them
to history. Items with leading spaces were simply dropped.

With this change, we add a 'history_persistence_mode_t' to
history_item_t, which tracks how the item persists. Items with leading
spaces are now marked as "ephemeral": they can be recovered via up arrow,
until the user runs another command, or types a space and hits return.
This matches zsh's HIST_IGNORE_SPACE feature.

Fixes #1383
2021-01-02 21:31:19 -08:00
ridiculousfish
cdf05325ed Reorganize history_item_t
Move the private bits to the bottom of the class and other mild
refactoring. No user visible behavior change expected.
2021-01-02 19:51:16 -08:00
Fabian Homborg
cf8219e3ce Exit if --no-execute is enabled don't interactively read from the terminal
Don't go into implicit interactive mode without ever executing
anything - not even `exit` or reacting to ctrl-d. That just renders
the shell useless and unquittable.
2021-01-01 21:22:52 +01:00
Fabian Homborg
7ea8e20623
argparse: Make short flag names optional (#7585)
It was always a bit ridiculous that argparse required `X-longflag` if
that "X" short flag was never actually used anywhere.

Since the short letter is for getopt's benefit, we can hack around
this with our old friend: Unicode Private Use Areas.

We have a counter, starting at 0xE000 and going to 0xF8FF, that counts
up for all options that don't have a short flag and provides one. This
gives us up to 6400 long-only options.

6.4K should be enough for everybody.
2021-01-01 11:37:25 +01:00
ridiculousfish
792abf61ec Attempt to fix the tsan build
Deliberately leak the shared thread pool to avoid shutdown dtor registration
and tsan complaints at exit.
2020-12-31 17:03:53 -08:00
ridiculousfish
f03ff8cd00 Add a test for history path detection
This will support history path detection improvements in a future
commit.
2020-12-30 00:44:25 -08:00
Johannes Altmanninger
801955851b Workaround clang-tidy incorrectly assuming null
This silences a false positive linter warning about a null dereference.
2020-12-29 16:31:43 +01:00
Johannes Altmanninger
8fc9b9d61b Address some minor lints
A mildly interesting one is the call to test_wchar2utf8 with a non-null
pointer ("u1"/"dst") but 0 length. In this case we relied on malloc(0)
returning non-null which is not guaranteed.

	src/fish_tests.cpp:1619:23: warning: Call to 'malloc' has an allocation
	size of 0 bytes [clang-analyzer-optin.portability.UnixAPI]
	        mem = (char *)malloc(dlen);
	                      ^
	test_wchar2utf8(w1, sizeof(w1) / sizeof(*w1), u1, 0, 0, 0,
			"invalid params, dst is not NULL");
2020-12-29 16:31:43 +01:00
Johannes Altmanninger
69a9785f50 Refactor: pass by value, not reference, to enable move semantics
clang-tidy wrote:
> warning: passing result of std::move() as a const reference argument;
> no move will actually happen [performance-move-const-arg]
2020-12-29 16:31:43 +01:00
ridiculousfish
43505f7077 Allow ** glob segments to match zero directories
Prior to this change, a glob like `**/file.txt` would only match
`file.txt` in subdirectories; the `**` must match at least one directory.
This is historical behavior.

With this change we move a little closer to bash's implementation by
allowing a literal `**` segment to match in the current directory. That
is, `**/foo` will match both `foo` and `bar/foo`, while `b**/foo` will
only match `bar/foo`.

Fixes #7222.
2020-12-28 23:51:18 -08:00
ridiculousfish
df73964ced Clean up some comments around wildcard expansion 2020-12-28 23:51:18 -08:00
Johannes Altmanninger
322ceb7ab4 builtin realpath: use absolute path also with -s/--no-symlinks
The old test needs to be changed because $XDG_DATA_HOME can be relative.

Fixes #7574
2020-12-24 08:53:08 +01:00
ridiculousfish
e43913a547 Stop expanding globs in command position when performing error checking
Before running a command, or before importing a command from bash history,
we perform error checking. As part of error checking we expand commands
including variables and globs. If the glob is very large, like `/**`, then
we could hang expanding it.

One fix would be to limit the amount of expansion from the glob, but
instead let's just not expand command globs when performing error checking.

Fixes #7407
2020-12-22 12:38:51 -08:00
ridiculousfish
a8080e8e6f Allow specifying a limit on number of expansion in operation_context
If the user types something like `/**`, prior to this change we would
attempt to expand it in the background for both highlighting and
autosuggestions. This could thrash your disk and also consume a lot of
memory.

Add a a field to operation_context_t to allow specifying a limit, and add
a "default background" limit of 512 items.
2020-12-22 12:38:51 -08:00
ridiculousfish
0f2d73e4a3 Remove a stale comment 2020-12-22 12:38:51 -08:00
ridiculousfish
c2c729352e Eagerly abort wildcard completions for ** wildcards
Historically fish has not supported tab completing or autosuggesting
wildcards with **. Prior to this fix, we would test every file match,
discover the ** wildcard, and then ignore it. Instead look for **
wildcards at the top level.

This prevents autosuggesting with /** from chewing up your disk.
2020-12-22 12:38:51 -08:00
ridiculousfish
10362a70df Clean up parse_error_offset_source_start
Use range-based for loops and relax the requirement that we have an
error list.
2020-12-22 12:38:51 -08:00
ridiculousfish
38a30d1798 Mark subclasses of io_data_t as final 2020-12-19 20:06:36 -08:00
ridiculousfish
6f2e377fcc Clean up some unnecessary variable names in maybe.h 2020-12-19 16:10:40 -08:00
ridiculousfish
90f4c458e5 Rename insert_line_above to insert_line_over
This is for symmetry with insert_line_under. See #7442.
2020-12-19 14:31:33 -08:00
ridiculousfish
2d2efc8b2e Implement o and O bindings for vi mode
Credit to @joallard for the patch. Fixes #7442
2020-12-19 14:28:00 -08:00
Fabian Homborg
7e7355bde1 Restore $status after expanding completions
When a completion's "--arguments" script ran, it would clobber $status with its value,
so when you repainted your prompt, it would now show the completion
script's status rather than the status of what you last ran.

Solve this by just storing the status and restoring it - other places
do this by calling exec_subshell with apply_exit_status set to false,
which does basically the same thing. We can't use it here because we
don't want to run a "full" script, we only want the arguments to be
expanded, without a "real" command.

No, I have no idea how to test this automatically.

Fixes #7555.
2020-12-19 11:37:01 +01:00
Fabian Homborg
31166f4731 Simplify some duplicated path checks
This has one functional difference, in that we now report non-EACCESS
errors even for relative paths. I consider that to be a plus.

Some other sites might benefit from this, let's look into that later.
2020-12-15 18:15:59 +01:00
Fabian Homborg
0f6669f43c Stop using env_var_t::to_list in a few places
We don't need the entire list in modifiable form here - some just needs
the size, the others can just get a reference.
2020-12-15 15:47:44 +01:00
Fabian Homborg
14908322a9 Also include fallback.h
GRrrrrr
2020-12-14 23:23:00 +01:00
Fabian Homborg
0f5a226e2f math: Use fish_wcstod instead
1. This should be using our wcstod_l on platforms where we need
it (for some reason it wasn't picking it up on FreeBSD?)

2. This purports to have a "fast path". I like fast paths.
2020-12-14 23:09:01 +01:00
Fabian Homborg
3af07e6c6e math: Wcharify the error message
Dunno, this seems to work, but then this is the sort of thing
that *seems* to work.
2020-12-14 23:02:54 +01:00
Fabian Homborg
e94f86e6d2 math: Use wcstod_l
Locale-wise, we're only interested in one thing:

"." is the radix character when interpreting numbers

And for that it's enough to just use our c-locale, like elsewhere.

This saves a bunch of switching locale back and forth, and simplifies
the code.
2020-12-14 22:58:47 +01:00
Fabian Homborg
97cd87f3b2 math: Use wchar
This was doing a bunch of work narrowing strings for no reason.
2020-12-14 22:54:53 +01:00
Fabian Homborg
6e9364ab50 fish_indent: Change --debug-level to --debug with flog categories
The "debug-level" flag makes little sense since we have no more
debug *levels* left.
2020-12-14 19:36:18 +01:00
ridiculousfish
36766ea3d7 Correct $status for certain pipeline-aborting failures
If we refused to launch a job because of a "pipeline aborting" error,
then it's the caller's responsibility to set $status.

Fixes #7540
2020-12-13 17:33:34 -08:00
ridiculousfish
2caeec24f7 Tighten up pipeline-aborting errors
Prior to this change, the functions in exec.cpp would return true or false
and it was not clear what significance that value had.

Switch to an enum to make this more explicit. In particular we have the
idea of a "pipeline breaking" error which should us to skip processes
which have not yet launched; if no process launches then we can bail out
to a different path which avoids reaping processes.
2020-12-13 17:30:26 -08:00
ridiculousfish
e5cff1a2db Fix some warnings from gcc
Use ignored_result instead of void casts, to satisfy the gcc.
2020-12-13 15:35:59 -08:00
Fabian Homborg
b7f47344b0 Print nicer "defined in" for functions defined on stdin/via source
This would tell you a function was "Defined in - @ line 1" for every
function defined via `source`.

Really, ideally we'd figure out where the *source* call was, but that'
much more complicated, so we just give a comprehensible message.
2020-12-11 23:09:16 +01:00
Fabian Homborg
425dabd6b1 Change fish_trace prefix to "->" instead of plusses
This matches what we do in --profile's output:

```
> source /home/alfa/.config/fish/config.fish
--> set -gx XDG_CACHE_HOME /home/alfa/.cache
--> set -gx XDG_CONFIG_HOME /home/alfa/.config
--> set -gx XDG_DATA_HOME /home/alfa/.local/share
```

instead of

```
+ source /home/alfa/.config/fish/config.fish
+++ set -gx XDG_CACHE_HOME /home/alfa/.cache
+++ set -gx XDG_CONFIG_HOME /home/alfa/.config
+++ set -gx XDG_DATA_HOME /home/alfa/.local/share
```
2020-12-11 21:24:33 +01:00
Fabian Homborg
ff62d172e5 Stop repainting in C++
We already have a variable handler, there is no need to repaint twice.
2020-12-11 18:43:04 +01:00
ridiculousfish
a2e486966a Always become pgroup leader in interactive mode
Prior to this change, if fish were launched connected to a tty but not as
pgroup leader, it would attempt to become pgroup leader only if
--interactive is explicitly passed. But bash will unconditionally attempt
to become pgroup leader if launched interactively. This can result in
scenarios where fish is running interactively but in another pgroup. The
most obvious impact is that control-C will result in the pgroup leader
(not fish) exiting and make fish orphaned.

Switch to matching the bash behavior here - we will always try to become
pgroup leader if interactive.

Fixes #7060.
2020-12-06 13:42:35 -08:00
ridiculousfish
5f131878a9 Buffer in outputter_t::term_puts
We were calling write() once for each character; buffer these instead.
2020-12-06 13:42:35 -08:00
Fabian Homborg
ab5d7f80d0 Restyle codebase
And again clang-format does something I don't like:

-    if (found != end && std::strncmp(found->name, name, len) == 0 && found->name[len] == 0) return found;
+    if (found != end && std::strncmp(found->name, name, len) == 0 && found->name[len] == 0)
+        return found;

I *know* this is a bit of a long line. I would still quite like having
no brace-less multi-line if *ever*. Either put the body on the same
line, or add braces.

Blergh
2020-12-06 15:39:54 +01:00
Fabian Homborg
aa895645dd Add string to reserved keywords
Since `string match` now creates variables, wrapping `string`
necessarily breaks things, so we need to disallow it.

See #7459, #7509.
2020-12-06 15:39:49 +01:00
ridiculousfish
fbeff2e751 Fix the build when gettext is disabled
When gettext is disabled, completions descriptions get passed as
const wcstring & which breaks the build. Accept the descriptions
by value instead.
2020-12-05 14:26:07 -08:00
ridiculousfish
91503151c9 Bravely remove a call to wrealpath in globbing
When globbing, we have a base directory (typically $PWD) and a path
component relative to that. As PWD is "virtual" it may be a symlink. Prior
to this change we would use wrealpath to resolve symlinks before opening
the directory during a glob, but this call to wrealpath consumed roughly
half of the time during globbing, and is conceptually unnecessary as
opendir will resolve symlinks for us.

Remove it. This may have funny effects if the user's PWD is an unlinked
directory, but it roughly doubles the speed of a glob like `echo ~/**`.
2020-12-05 14:04:45 -08:00
ridiculousfish
594a6a35e8 Adopt expansion limits in wildcard expansions
This prevents e.g. `count /**` from consuming all of your memory.

Fixes #7226
2020-12-05 13:21:46 -08:00
ridiculousfish
f11a60473a Introduce expansion limits
This adds the ability to limit how many expansions are produced. For
example if $big contains 10 items, and is Cartesian-expanded as
$big$big$big$big... 10 times, we would naviely get 10^10 = 10 billion
results, which fish can't actually handle. Implement this in
completion_receiver_t, which now can return false to indicate an overflow.

The initial expansion limit 'k_default_expansion_limit' is set as 512k
items. There's no way for users to change this at present.
2020-12-05 13:19:07 -08:00
ridiculousfish
48567c37de Adopt completion_receiver_t more widely
This switches certain uses from just appending to a list to using
completion_receiver_t, in preparation for limiting how many completions
may be produced. Perhaps in time this could also be used for "streaming"
completions.
2020-12-05 13:18:14 -08:00
ridiculousfish
245f264c04 Remove a suspicious 'unused' declaration for wildcard_complete_internal
This function is used and so is its return value, at all call sites.
2020-12-05 11:46:01 -08:00
ridiculousfish
af3383e727 Introduce completion_receiver_t
completion_receiver_t wraps a completion list; it will centralize logic
around adding completions and most importantly it will enforce that we
do not exceed our expansion limit.
2020-12-05 11:46:01 -08:00
Fabian Homborg
7cefe598e9 Don't use KERN_PROC_PATHNAME on NetBSD
This returns the wrong thing and breaks the tests.

Since it's not super important anyway, just disable it and go back to
/proc, that works.
2020-12-05 14:43:08 +01:00
Fabian Homborg
02efce51a9 string match: Only import variables for the first matching argument
This makes it work the same whether it quits early (with "-q") or not,
and it's generally nice to nail this down.

See #7495.
2020-12-04 18:45:08 +01:00
Fabian Homborg
b9b84e63bf Revert "Attempt to simplify how completions get presented in the pager"
The pager cleanup missed that the existing token could already include active (as in unescaped) expansions, and just escaped them all.

This means things like `ls ~/<TAB>` would escape the `~`, which is obviously wrong and makes it awkward to use.

This reverts commit b38a23a46d.

I fully expect that we'll try again, but there's no use in keeping master broken while that happens.

Fixes #7526.
2020-12-04 16:44:48 +01:00
Fabian Homborg
720982a3cb string: Quit early if --quiet is satisfied
E.g. if we do `string match -q`, and we find a match, nothing about
the input can change anything, so we quit early.

This is mainly useful for performance, but it also allows `string`
with `-q` to be used with infinite input (e.g. `yes`).

Alternative to #7495.
2020-12-01 18:55:01 +01:00
Mahmoud Al-Qudsi
8aac537191 Silence GCC warn_unused_result warnings in tests
warn_unused_result is the persistent one that won't go away with a
simple `(void)write(...)` and needs to be assigned to a variable (that
must then also be declared unused or else you'll get a warning about
_that_).
2020-11-29 18:12:09 -06:00
ridiculousfish
74b298a6f9 Fix a gcc warning about comparison of different signedness 2020-11-29 14:06:04 -08:00
ridiculousfish
f5f0f98991 Remove expand_flag::skip_jobs
It was unused.
2020-11-29 14:01:13 -08:00
ridiculousfish
2b8d2deb0c Introduces "smartcase" completions
"smartcase" performs case-insensitive matching if the input string is all
lowercase, and case-sensitive matching otherwise. When completing e.g.
files, we will now show both case sensitive and insensitive completions if
the input string does not contain uppercase characters.

This is a delicate fix in an interactive component with low test coverage.
It's likely something will regress here.

Fixes #3978
2020-11-29 12:40:01 -08:00
ridiculousfish
b38a23a46d Attempt to simplify how completions get presented in the pager
This is an attempt to simplfy some completion logic. It mainly refactors
reader_data_t::handle_completions such that all completions have the token
prepended; this attempts to simplify the logic since now all completions
replace the token. It also changes how the pager prefix works. Previously
the pager prefix was an extra string that was prepended to all
completions. In the new model the completions already have the prefix
prepended and the prefix is used only for certain width calculations.

This is a somewhat frightening change in an interactive component with
low test coverage. It tweaks things like how long completions are
ellipsized. Buckle in!
2020-11-29 12:35:18 -08:00
ridiculousfish
4b947e0a23 Refactor string fuzzy matching
In preparation for introducing "smart case", refactor string fuzzy
matching. Specifically split out the case folding and match type into
separate fields, so that we can introduce more case folding types without
a combinatoric explosion.
2020-11-29 12:35:18 -08:00
ridiculousfish
20b98294ba Bravely remove string_fuzzy_match_t::compare
This is used to decide which fuzzy match is better, however it is used
only in wildcard expansion and not in actual completion ranking or
anywhere else where it could matter. Try removing the compare() call
and implementation.

What compare() did specially was compare distances, e.g. it ranks
lib as better than libexec when expanding /u/l/b. But the tests did not
exercise this so it's hard to know if it's working. In preparation for a
refactoring, remove it.
2020-11-29 12:35:18 -08:00
ridiculousfish
ac1ee6f1fd Make fuzzy_match_type_t an enum class
Also rename it to fuzzy_type_t and shorten some of its values.
2020-11-29 12:35:18 -08:00
ridiculousfish
9144141ded Migrate string_fuzzy_match from common.h to wcstringutil.h
This is a more appropriate location for this functionality.
Also take this opportunity to clean up subsequence_in_string.
2020-11-29 12:35:18 -08:00
ridiculousfish
639cd66ba1 Conditionally make autosuggestions case sensitive
When fish presents an autosuggestion, there is some logic around whether
to retain it or discard it as the user types "into" it. Prior to this
change, we would retain the autosuggestion if the user's input text is a
case-insensitive prefix of the autosuggestion. This is reasonable for
certain case-insensitive autosuggestions like files, but it is confusing
especially for history items, e.g. `git branch -d ...` and `git branch -D
...` should not be considered a match.

With this change, when we compute the autosuggestion we record whether it
is "icase", and that controls whether the autosuggestion permits a
case-insensitive extension.

This addresses part of #3978.
2020-11-29 12:35:18 -08:00
ridiculousfish
1094b95b6f Mild refactoring of autosuggestions
Rather than storing an autosuggestion as a string, store a struct.
This is preparing to conditionalize autosuggestion case sensitivity.
2020-11-29 12:35:18 -08:00
ridiculousfish
d9ebe13cb4 Reorganize and improve commenting of autosuggest_validate_from_history
No behavior change expected here.
2020-11-29 12:35:18 -08:00
Johannes Altmanninger
7da93e2617 builtin functions: don't mix up multiple arguments
This regressed in 2e38cf2a which is contained in 2.6.0.

Fixes #7515
2020-11-29 06:35:02 +01:00
Johannes Altmanninger
79df29e8fd Remove some dead functions in the highlighter
These are replaced by "visit" methods.
2020-11-29 05:59:16 +01:00
Mahmoud Al-Qudsi
aa0bfa0eb8 Minor cleanup
clangd needs to respect clang-format files when inserting headers up
top.

[ci skip]
2020-11-28 01:00:27 -06:00
Mahmoud Al-Qudsi
a3cb1e2dcd Fix setting terminal title after fg
The code to override the `(status current-command) was present`, but not
handled in either the default `fish_title` function or the fallback.

Closes #7444.
2020-11-28 00:56:10 -06:00
Fabian Homborg
5872f4522d math: Add --base option
Currently a bit limited, unfortunately printf's `%a` specifier is
absolutely unreadable.

So we add `hex` and `octal` with `0x` and `0` prefixes respectively,
and also take a number but currently only allow 16 and 8.

The output is truncated to integer, so scale values other than 0 are
invalid and 0 is implied.

The docs mention this may change.
2020-11-27 19:33:27 +01:00
ridiculousfish
30c7a17302 Set tty to shell mode before running fish_prompt
Prior to this change, we would run fish_prompt and then afterwards set
the shell modes. For users with an initially slow prompt, this would
mean that characters would be echoed to the tty until after the prompt
completes.

Reorder these so that we set the tty mode first. This implies we will
run the prompt in shell mode, but this was already the case up until
2a3677b386.

Fixes #7489. Note that the prior commit e0cedd4ad2 is also necessary
here, as that fixed an extra prompt execution.
2020-11-26 16:47:08 -08:00
ridiculousfish
e0cedd4ad2 Remove exec_prompt call from read_push
This prompt execution does not appear to be necessary, and spoils the
upcoming fix for #7489
2020-11-26 16:38:33 -08:00
Mahmoud Al-Qudsi
5ddafb3b79 Add support for importing named regex matches
The new commandline switch `string match --regex --import` will import
as fish variables any named capture groups with the matched captures as
the value(s).
2020-11-26 14:41:00 -06:00
Mahmoud Al-Qudsi
282fb14dcf Get rid of magic numbers in report_match() result
Replace with a class-local `enum class` instance.
2020-11-26 14:38:04 -06:00
Fabian Homborg
a14e64ed6c math: Don't override errors with "unexpected token"
As always, we want to give the most specific error we can.

Fixes #7508
2020-11-26 12:41:19 +01:00
Fabian Homborg
903a9fbf0c math: Don't match longer function names
The comparison here is a bit naive, so "n" matches "ncr", so
technically

   math 'n(2, 3)'

is equivalent to

   math 'ncr(2, 3)'

Work towards #7508.
2020-11-26 12:37:09 +01:00
ridiculousfish
7c4891407f Remove restore_attrs from terminal_return_from_job_group function
Previously this parameter was used to more-eagerly restore the terminal
mode. This was the basis for #2214. However now we restore the mode
from the reader instead, so we can remove this unused parameter.
2020-11-23 19:36:55 -08:00
ridiculousfish
5f16a299a7 Use external mode for term when running key bindings
Prior to this fix, when key binding is a script command (i.e. not a
readline command), fish would run that key binding using fish's shell
tty modes. Switch to using the external tty modes. This re-fixes
issue #2214.
2020-11-23 19:36:39 -08:00
ridiculousfish
db514df95b Stop setting tty back to shell mode when a fg proc completes
Prior to this change, when a process resumes because it is brought back
to the foreground, we would reset the terminal attributes to shell mode.
This fixed #2114 but subtly introduced #7483.

This backs out 9fd9f70346, re-introducing #2114 and re-fixing #7483.
A followup fix will re-fix #2114; these are broken out separately for
bisecting purposes.

Fixes #7483.
2020-11-23 19:36:39 -08:00
ridiculousfish
e9b683dee1 Refactor how inputter handles script commands
Prior to this change, for bindings which have script commands, the
inputter would execute them directly. However an upcoming fix for #7483
will require more integration with the reader. Switch to a new model where
the reader passes in a function to use for executing script commands.
2020-11-23 19:36:39 -08:00
ridiculousfish
994f95b845 Move inputter_t private bits to the bottom of the class
Just a reorganization to clarify what parts are the interface.
2020-11-23 19:36:39 -08:00
ridiculousfish
050a211838 Clarify the role of the 'in' param in inputter_t constructor 2020-11-23 19:36:39 -08:00
ridiculousfish
48c50d202b Save a string allocation in expand_arguments_from_nodes
This function is called a lot; we can save a little bit of memory here.
2020-11-23 19:36:39 -08:00
Fabian Homborg
2e55e34544 Reformat 2020-11-22 14:39:48 +01:00
Mahmoud Al-Qudsi
3699e50e00 Explicitly check for KERN_PROC_PATHNAME
While FreeBSD, DragonflyBSD, and NetBSD have KERN_PROC_PATHNAME,
OpenBSD does not.
2020-11-20 15:49:57 -06:00
Mahmoud Al-Qudsi
be78e9dc28 fixup! Unify handling of BSD systems where applicable 2020-11-20 15:06:19 -06:00
Mahmoud Al-Qudsi
06f1b34553 Correct reporting of setpgid (parent vs child)
Previously, it always said "own process" (e.g. child error).
2020-11-20 14:22:42 -06:00
Mahmoud Al-Qudsi
e4c052330f Handle ESRCH from setpgid(2) on FreeBSD 2020-11-20 14:18:02 -06:00
Mahmoud Al-Qudsi
76faee71a5 Unify handling of BSD systems where applicable 2020-11-20 14:11:03 -06:00
Fabian Homborg
3c14d310a0 reader: Stop converting to wchar and back to wcstring
This called completion_insert with a wchar_t*, which was then passed
to a function that takes a wcstring.
2020-11-15 15:27:19 +01:00
Fabian Homborg
263ef55ae6 reader: Use erase directly
No need to use a separate reference.

Also no need to erase from begin(), just use the indices.
2020-11-15 15:26:52 +01:00
Fabian Homborg
3eba6c5d5a signal: Remove redundant set 2020-11-15 15:20:55 +01:00
Fabian Homborg
c23fc9a365 builtin_test: Exit early on float parsing error
cppcheck complains about a possible null-dereference.
2020-11-15 15:15:20 +01:00
Fabian Homborg
a8f259f685 Remove unused debug_escape function 2020-11-15 15:15:10 +01:00
Fabian Homborg
9c2d22e452 Remove debug_stack_frames
This was unused with FLOG. We leave the option stubbed out for now, so
we don't error out for well-meaning calls.
2020-11-15 11:32:52 +01:00
Fabian Homborg
95e86cf2d2 Remove the old debug macro and impl
This should make calling `debug()` impossible. Some of the other
bits remain, to be removed later.
2020-11-15 11:28:01 +01:00
Fabian Homborg
b32540f346 proc: Remove unused function 2020-11-15 11:26:45 +01:00
Fabian Homborg
01cd6385ff reader: Make param const
const good! Fabian like const!
2020-11-15 11:26:15 +01:00
Fabian Homborg
9f924f37fb reader: Pre-increment
If we don't do it now, static analysis things are just gonna bug us
until someone does it.
2020-11-15 11:25:45 +01:00
Fabian Homborg
575d574691 ast: Remove unused variable 2020-11-15 11:19:23 +01:00
Érico Rolim
21041e3cc7 src: don't split wide char strings that are used with gettext.
A bug in xgettext leads to the generation of useless msgids in the po
files for these strings.
2020-11-13 14:34:42 +01:00
Érico Rolim
6e9d5c00e5 src/builtin_type.cpp: add missing gettext call.
The string "%ls is %ls", which is printed when `type <command>` is ran
for a command in PATH, couldn't be localized, since it was missing _()
around it.
2020-11-13 14:31:40 +01:00
ridiculousfish
17fc542082 Revert "Stop caching line breaks in the prompt calculation"
This reverts commit a2ff32d904.

Per comments on the commit, the original code had correct handling of line
breaks inside escapes.
2020-11-12 10:55:11 -08:00
Fabian Homborg
5ee3eeff5d Remove the final two debug() calls 2020-11-07 10:20:52 +01:00
Mahmoud Al-Qudsi
640f4444f5 Disable SIGIO notifier on WSL
It currently does not trigger the uvar notifier and fails the automated
tests.

See #7429.
2020-11-06 20:49:44 -06:00
Fabian Homborg
65c5433662 Delete unused field
Fixes #7456.

[ci skip]
2020-11-06 17:44:09 +01:00
ridiculousfish
d3192d37a2 Allow timing-out I/O-able syntax highlighting after expanding abbreviation
It may happen that the user types an abbreviation and then hits return.
Prior to this commit, we would perform a form of syntax highlighting
that does not require I/O, so as to not block the user. However this
could cause invalid commands to be colored as valid.

More generally if the user has e.g a slow NFS mount, then syntax
highlighting may lag behind the user's typing, and be incorrect at the
time the user hits return. This is an unavoidable race, since proper
syntax highlighting may take arbitrarily long.

Introduce a new function `finish_highlighting_before_exec`, which waits
for any outstanding syntax highlighting to complete, BUT has a timeout
(250 milliseconds). After this, it falls back to the no-I/O variant, which
colors all commands as valid and nothing as paths.

Fixes #7418
Fixes #5912
2020-11-05 20:07:05 -08:00
ridiculousfish
c861fdadcf Remove return value from iothread_perform
It was not actually used by any test.
2020-11-05 19:28:26 -08:00
ridiculousfish
a2ff32d904 Stop caching line breaks in the prompt calculation
These are fast enough to find on demand.
2020-11-01 14:45:35 -08:00
Soumya
80aaae5b74 Clear to end of each line in left prompt 2020-11-01 13:29:26 -08:00
Fabian Homborg
2a07673561 Don't call a variable "stdin"
Musl has a macro that interferes.
2020-10-31 18:15:19 +01:00
Fabian Homborg
0951a706cf Let read read from fds other than 0
This allows

read </dev/tty

to work.

Fixes #7358
2020-10-31 13:39:20 +01:00
Fabian Homborg
d334dc6643 Let cancel after an unambiguous completion was accepted undo it
In some cases the completion we come up with may be unexpected, e.g.
if you have files like

/etc/realfile

and

/etc/wrongfile

and enter "/etc/gile", it will accept "wrongfile" because "g" and
"ile" are in there - it's a substring insertion match.

The underlying cause was a typo, so it should be easy to go back.

So we do a bit of magic and let "cancel" undo, but only right after a
completion was accepted via complete or complete-and-search.

That means that just reflexively pressing escape would, by default, get you back to
the old token and let you fix your mistake.

We don't do this when the completion was accepted via the pager,
because 1. there's more of a chance to see the problem there and 2.
it's harder to redo in that case.

Fixes #7433.
2020-10-30 19:37:44 +01:00
Johannes Altmanninger
5ff2d38d4c builtin time: print help on invalid syntax
I always mix up the order with variable assignments.
2020-10-26 19:25:41 +01:00
Fabian Homborg
a84d57b02b math: Actually report closing paren error
This was typically overridden by "too many/few arguments", but it's
actually incorrect:

    sin(55

has the correct number of arguments to `sin`, but it's lacking
the closing `)`.
2020-10-26 18:13:43 +01:00
Rosen Penev
cef84cf2c2 clang-tidy: use append
Found with performance-inefficient-string-concatenation

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-25 22:54:51 -07:00
Rosen Penev
334be56021 run codebase through clang-tidy
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-25 22:48:49 -07:00
Mahmoud Al-Qudsi
332287708b Prevent fish from re-importing an exported fish_user_paths
fish_user_paths is a fish-specific variable that can be persisted by
making it a universal variable or by making it a global variable set at
startup in `config.fish`.

Since it is not defined in a clean installation, a user could
inadvertently create it as `set -Ux fish_user_paths ....` the first
time, creating a horrible, ugly, self-loathing mess that will have you
chasing ghosts and bisecting for naught once fish re-imports
fish_user_paths as a *global* variable that shadows the universal one.

While that is true for any universal variable that is re-imported as a
global variable, only fish_user_paths has the potential to really screw
things up because we also re-export PATH based off of its value in turn.
2020-10-25 21:45:45 -05:00
ridiculousfish
a34b9036ba Enable SIGIO notifier on FreeBSD
Now that SIGIO works on FreeBSD, switch to that uvar notifier
2020-10-25 14:53:56 -07:00
ridiculousfish
e669c41d1b Fix up SIGIO notifier tests
FreeBSD has the behavior where SIGIO is delivered on a read. Teach the
tests how to handle this behavior.
2020-10-25 14:53:31 -07:00
ridiculousfish
8bb20a8d91 Remove use of POLL_IN in SIGIO uvar notifier
This fixes up the SIGIO notifier in preparation for using it on BSD. It
removes the reliance on the signal's si_code, which is not available in
BSD, and it properly handles the BSD behavior where SIGIO is delivered on
a read even if the read returns EAGAIN.
2020-10-25 14:52:37 -07:00
Mahmoud Al-Qudsi
3652bcf731 fixup! Fix assertion failure on job redirection error 2020-10-24 17:59:11 -05:00
Mahmoud Al-Qudsi
64671c64a1 Fix assertion failure on job redirection error
Fix an error caused by `exec_job()` assuming a job launched with the
intention of being backgrounded would have a pgid assigned in all cases,
without considering the status of `exec_error` which could have resulted
in the job failing before it was launched into its own process group.

Fixes (but doesn't close) #7423 - that can be closed if this assertion
failure doesn't happen in any released fish versions.
2020-10-24 16:15:40 -05:00
ridiculousfish
bbbbe00c81 Handle being launched with control of the tty, but not in own pgroup
It is apparently possible to launch fish such that its pid owns the tty,
but its pid is in a different pgroup. In that case, do not attempt to stop
with SIGTTIN; instead simply attempt to place fish in its own pgroup.

Fixes #7388
2020-10-18 14:37:31 -07:00
Fabian Homborg
5abc6060a4 Disable sigio notifier on FreeBSD
This fails for unknown reasons.

Not looking like a great *replacement* for the named pipe now, tbh.

See #7400.
2020-10-14 20:40:15 +02:00
Collin Styles
da0acb28ba Don't chomp foo= when completing foo=br
`complete_param_expand` knows how to handle cases like `foo=br` so we
don't need to bother sending just the `br` part. Furthermore, sending
just `br` is incorrect because we will end up replacing the entirety of
`foo=br` with the result of the completion. That is, `foo=br` will be
replaced with `bar` instead of being completed to `foo=bar`.
2020-10-14 18:35:54 +02:00
Johannes Altmanninger
ddf0a8e461 Refactor: slightly rework how variables are assigned during completion
Seems better since we now have two callers. This would be a good use case for
[[nodiscard]].
2020-10-10 13:00:47 +02:00
Johannes Altmanninger
8ef8fb3d94 Refactor: omit parens in lambdas with no parameters
TIL []{} is a thing.  We already do that in some places, so this improves
consistency, although it may be less obvious.
2020-10-10 13:00:24 +02:00
Johannes Altmanninger
c325603d73 Honor variable assignments on the commandline when completing files
This had already worked before although the implementation used to be rather
crude and was cleaned up in
e88eb508d0 (r42759188)
2020-10-10 12:59:55 +02:00
Johannes Altmanninger
eca2a8ba55 complete: print completions without the implied -c switch
This switch is no longer necessary when only one command is given.
Internally completions are stored separately for each command,
so we only every print one command name per "complete" line anyway.
2020-10-10 11:54:52 +02:00
Fabian Homborg
cc0e366037 history: Skip lines with tabs when importing from bash
Fixes #6923.
2020-10-09 18:54:47 +02:00
ridiculousfish
e9902159c2 Send fish_cancel event on control-C again
This adds support for sending fish_cancel, and a test for it.
Fixes #7384.
2020-10-06 17:49:55 -07:00
Fabian Homborg
e949b1de02 ifdef SIGIO handling
This relies on POLL_IN which apparently isn't a thing on OpenBSD
2020-10-06 17:34:50 +02:00
Fabian Homborg
289bce2f25 Add event flog
I needed this, and it should be there.

[ci skip]
2020-10-06 17:25:45 +02:00
Fabian Homborg
00ab51bedc set: Allow erasing multiple variables at once
See #7377.
2020-10-04 12:24:11 +02:00
ridiculousfish
f9e426813c Do not complain about fcntl(F_SETOWN) failing
On WSL1, fcntl(F_SETOWN) will fail and this would report an error.
Suppress this error message since it is not very interesting.
The effect is to disable real-time universal variable propagation.
2020-10-03 15:54:27 -07:00
ridiculousfish
558dd6e53d Add sigio-based universal notifier strategy
Introduce a new strategy for notifying other fish processes of universal
variable changes, as a planned replacement for the complex
strategy_named_pipe. The new strategy still uses a named pipe, but instead
of select() on it, it arranges for SIGIO to be delivered when data is
available. If a SIGIO has been seen since the last check, it means the file
needs to be re-read.
2020-10-01 13:19:41 -07:00
ridiculousfish
700fe4f131 Moderize universal variable notifiers
Use some C++11 features.
2020-10-01 13:27:13 -07:00
Fabian Homborg
bbdfe126a7 Flash if history search found nothing
This makes it clearer that we're at the end.

Fixes #7362.
2020-09-30 18:02:22 +02:00
Fabian Homborg
d6d3abf59a Introduce $FISH_DEBUG and $FISH_DEBUG_OUTPUT variables
Same as the `--debug` and `--debug-output` options, can be enabled
when the option can't be passed, e.g. in linux shebangs.

Fixes #7359.
2020-09-28 17:46:37 +02:00
ridiculousfish
c89c72f431 Invert sense of expand_flag::no_descriptions
When expanding a string, you may or may not want to generate
descriptions alongside the expanded string. Usually you don't want to
but descriptions were opt out. This commit makes them opt in.
2020-09-27 16:50:40 -07:00
Johannes Altmanninger
f758d39535 string pad: handle padding characters of width > 1
If the padding is not divisible by the char's width without remainder,
we pad the remainder with spaces, so the total width of the output is correct.

Also add completions, changelog entry, adjust documentation, add examples
with emoji and some tests.  Apply some minor style nitpicks and avoid extra
allocations of the input strings.
2020-09-27 21:59:15 +02:00
Johannes Altmanninger
5ae03414d7 Sort string subcommands, and use binary search for lookup
I have no idea if this is better, and did not attempt to measure it, but we
do the same for electric variables which are even fewer.
2020-09-27 21:59:15 +02:00
Andrew Prokhorenkov
92511b09c4 New command "string pad" to pad text to a given width (#7340)
Pads text to a given width, or the maximum width of all inputs.
2020-09-27 21:59:15 +02:00
Johannes Altmanninger
e8859b4ce2 Do not treat newlines special in bigword movements
Improves on #7328.

I believe this is the correct behavior, simply skip all whitespace before
a word. Try with

	./fish -C 'bind \ef forward-bigword; bind \eb backward-bigword; bind \ed kill-bigword; bind \cw backward-kill-bigword'

Also unrelated formatting fixes. I don't think a CI failure on unformatted
code is warranted but I wish it could do that behind the scenes.
2020-09-27 18:04:09 +02:00
Johannes Altmanninger
791d23502f Do not add a space after completing flag with optional argument
For example "grep --color"<TAB> can complete to "grep --color=".  Don't add
a space in this case; we do the same for arguments that end in =.

In GNU-style getopt, equal sign means that the flag has an argument. Without
the = it would not consume the next argument as opposed to Python's argparse.
2020-09-27 17:56:21 +02:00
sgrj
ab2cb03189
Consistency-fix for word motions (#7354)
* change word motion test to include start cursor in specification

* add test case for bug

* fix bug
2020-09-27 15:34:34 +02:00
Fabian Homborg
adb1f993a7 Reader: Turn *off* INLCR for external commands
That's how it worked previously, and it makes ctrl-j usable again.

Fixes #7352
2020-09-27 13:54:47 +02:00
Fabian Homborg
0f7e2ca99c Don't put commandline on a new line if prompt is "long"
This was a weird special behavior where we'd put the commandline on a
new line if it wrapped *and* the prompt was > 33% of the screen.

It seems to be more confusing than anything.

Fixes #5118.
2020-09-27 13:12:06 +02:00
ridiculousfish
e88eb508d0 Rework variable assignments during tab completion
Prior to this change, tab completing with a variable assignment like
`VAR=val cmd<tab>` would parse out and apply VAR=val, then recursively
invoke completions. This caused some awkwardness around the wrap chain -
if a wrapped command had a variable completion we risked infinite
recursion. A secondary problem is that we would run any command
substitutions inside variable assignment, which the user does not expect
to run until pressing enter.

With this change, we explicitly track variable assignments encountered
during tab completion, including both those explicitly given on the
command line and those found during wrap chain walk. We then apply them
while suppressing command substitutions.
2020-09-26 18:39:38 -07:00
ridiculousfish
cc07716dc1 Separate out variable assignments when completing
In preparation for applying variable assignments (VAR=VAL cmd), separate
them out from the command when performing completions. This includes both
those that the user typed, and any that come about through
completion --wraps.
2020-09-26 17:30:25 -07:00
ridiculousfish
3ef83de866 Rename cmd to cmdline in completer_t::perform_for_command
This makes it clear that the commandline contains arguments, etc.
2020-09-26 17:30:13 -07:00
ridiculousfish
757dda43ac Factor custom completion information into custom_arg_data_t
When completing and walking a wrap chain, we pass around a lot of
information. Factor this together into a new struct custom_arg_data_t
which reduces the number of parameters needed.
2020-09-26 17:30:10 -07:00
ridiculousfish
5cadea0173 Migrate the complete_custom transient command line pop to cleanup_t
This ensures that it gets cleaned up even if there is a mid-function
return.
2020-09-26 17:25:02 -07:00
ridiculousfish
45b85d28bb Completion wrap chain visited set to store only wrapped command
The "wrap chain" refers to a sequence of commands which wrap other
commands, for completion purposes. One possibility is that a wrap chain
will produce a combinatorial explosion or even an infinite loop, so there
needs to be logic to prevent that. Part of that logic is encapsulated in a
visited set (wrap_chain_visited_set_t) to prevent exploring the same item
twice.

Prior to this change, we stored pairs (command, wrapped_command). But we
only really need to store the wrapped command. Switch to that.

One consequence is that if a command wraps another command in more than
one way, we won't explore both ways. This seems unlikely in practice.
2020-09-26 17:24:59 -07:00
Johannes Altmanninger
879e80859c Refactor: apply some lints
And reformat touched files; my editor just does that.
2020-09-26 14:56:03 +02:00
Johannes Altmanninger
45e7c709f4 Consolidate complete cycle detection and always report error on cycle
Detect recursive calls to builtin complete and the internal completion in
the same place.

In 0a0149cc2 (Prevent infinite recursion when completion wraps variable assignment)
we don't print an error when completing certain aliases like:

	alias vim "A=B vim"

But we also gave no completions.
We could make this case work, but I think that trying to salvage situations
like this one is way too complex. Instead, let the user know by printing an
error. Not sure if the style of the error fits.

We could add some heuristic to alias to not add --wraps in some cyclic cases.
2020-09-26 14:56:03 +02:00
Johannes Altmanninger
3dd9531472 Refactor: decouple the command to complete from completer_t
This allows us to reuse a completer_t for completions of commands like
"a=b ... ", instead of calling complete().
2020-09-26 14:56:03 +02:00
Johannes Altmanninger
e4e2155f5e Refactor: move wrap chain visitor into a function
The lambda has grown way too big, and it was not easy to see what the inputs
and outputs are. We always use the same visitor, so the function parameter
is not necessary.
2020-09-26 14:56:03 +02:00
Fabian Homborg
fa0c9f90f8 Read arguments with fish -c
This reads any additional positional arguments given to `fish -c` into
$argv.

We don't handle the first argument specially (as `$0`) as that's confusing and
doesn't seem very useful.

Fixes #2314.
2020-09-26 14:47:20 +02:00
Fabian Homborg
396d7e105f fish_tests: Break if unescape test failed
Otherwise this prints millions of lines of errors, which just seems
like overkill
2020-09-26 10:43:05 +02:00
Fabian Homborg
06f6436943 reader: Return true if suppress-autosuggestion suppressed
This allows

bind -k backspace suppress-autosuggestion or backward-delete-char

To remove the suggestion on the first press and then delete
chars.

Note: This requires that we then don't reenable suggestions
immediately afterwards. Currently we don't after deletion.

Fixes #1419.
2020-09-26 10:09:55 +02:00
Fabian Homborg
0d0ee473fa Detect windows line endings when executing a file
Fixes #2783.
2020-09-25 16:51:05 +02:00
Fabian Homborg
a776b08e84 Use bools, we have the technology 2020-09-24 18:53:19 +02:00
Fabian Homborg
1188a12dfd type: Print *only* the path if given --path or --force-path
This is what happens when you check your tests in the wrong tab,
folks.

Fixes #7345.
2020-09-23 17:24:51 +02:00
Fabian Homborg
1da56f9937 Make history search smartcase
This makes history searches case-insensitive, unless the search string
contains an uppercase character.

This is what vim calls "smartcase".

Fixes #7273.
2020-09-22 16:13:24 +02:00
Johannes Altmanninger
0a0149cc2a Prevent infinite recursion when completion wraps variable assignment
Closes #7344

Apply a targeted fix to the place where complete() is called to handle nested
variable assignments.  Sadly, reporting an error is probably not okay here,
because people might legitimately use aliases like:

	alias vim "A=B command vim"

This is all a bit ugly, and I hope to find a cleaner solution.  Supporting
completions on commandlines like `x=$PWD cd $x/ ` is a nice feature but it
comes with some complexity.
2020-09-22 01:11:18 +02:00
Johannes Altmanninger
ca538fa8d8 Refactor: make function static and reformat
"IndentCaseLabels: false" seems nice but not now.
2020-09-22 00:17:19 +02:00
Mahmoud Al-Qudsi
383f1d1a19 fixup! Make type a builtin
[ci skip]
2020-09-21 15:42:55 -05:00
Fabian Homborg
ef9c924960 Make type a builtin
This is too important to not be one.

For one if it couldn't be loaded for any reason it would
break a lot of fish scripts.

Also this is faster by ~20x.

Fixes #7342
2020-09-21 20:58:34 +02:00
Fabian Homborg
3a05326a39 Move functions_def to function.cpp
We're gonna be using it in two places
2020-09-21 17:44:58 +02:00
Fabian Homborg
66475732af Fix str2wcs for LANG=C
4f0ade7a73 broke the tests when LANG was
C, so the MB_CUR_MAX==1 path wasn't working.

Seemingly that cast is doing some work here?

Just revert that bit for now, since this path is unimportant
anyway (please, please, please, please use a unicode capable locale).
2020-09-20 15:05:49 +02:00
Fabian Homborg
7ec57f2c50 string: Handle unmatched capturing groups as empty
Instead of erroring out.

Fixes #7343.
2020-09-20 10:36:17 +02:00
ridiculousfish
5c3571d626 Revert accidental merge of #7340
This reverts back to commit d8e2cac83e.
I accidentally did a 'git push' during code review.
2020-09-19 19:31:44 -07:00
Andrew Prokhorenkov
2afa354c14 builtin_string: implement "width" argument for "string pad" 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
70dfece3ce builtin_string: remove quiet 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
7eccec3ce0 builtin_string: order "string_pad" before "string_replace" 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
52b0d356ff builtin_string: remove redundant statements 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
2b9158ddab builtin_string: add "--max" for "string pad" 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
886290c123 builtin_string: change npad 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
c8e1894c72 builtin_string: add pad command 2020-09-19 19:25:57 -07:00
ridiculousfish
d8e2cac83e Reimplement vectorized reads for detecting ASCII strings
This is a reimplementation of the "vectorized" ASCII detection
from str2wcs_internal. This handles the case where only part of
a string is ASCII. It also avoids pointer overflow issues and improves
commenting.
2020-09-19 17:52:17 -07:00
ridiculousfish
4f0ade7a73 Optimize str2wcs_internal more
Prior to this change, str2wcs_internal had an optimization for ASCII
inputs. However the main cost was the repeated bounds checks when
performing push_back() on the resulting wcstring.

Switch to determining the number of ASCII characters, and then appending
those all in one go. This improves the time in the 'convert_ascii' test
from ~450 usec to ~75 usec.
2020-09-19 17:47:14 -07:00
ridiculousfish
4d5d90d828 Add a simple ASCII conversion test and benchmark
Run `fish_tests perf_convert_ascii` to run the benchmark.
2020-09-19 17:47:12 -07:00
Johannes Altmanninger
291d1fbf1b Recompute completions if previous attempt failed
When pressing tab repeatedly, completions only computed on the first one. This
is because the old logic assumed that completions are present if the last
key was tab. Recompute them if there are no completions at all.

Fixes #6863
2020-09-17 18:44:54 +02:00
Fabian Homborg
181ce4a6b6 Actually create runtime path if needed
This checked if the path was readable and only then tried creating it,
which... isn't right.

Fixes #7335.
2020-09-17 12:33:56 +02:00
Fabian Homborg
58245b6fe7 set_color: Honor modifiers (bold, background..) with --print-colors
Fixes #7314
2020-09-17 12:33:56 +02:00
Fabian Homborg
709e91c1e6 builtin test: Let -t work for the standard streams
Since builtins don't actually have the streams connected, but instead
read input via the io_streams_t objects, this would just always say
what *fish's* fds were.

Instead, pass along some of the stream data to check those
specifically - nobody cares that `test`s fd 0 *technically* is stdin.
What they want to know is that, if they used another program in that
place, it would connect to the TTY.

This is pretty hacky - I abused static variables for this, but
since it's two bools and an int it's probably okay.

See #1228.

Fixes #4766.
2020-09-16 21:02:59 +02:00
Fabian Homborg
1215717d20 Set exit status with delete-or-exit
(regression from d415350aaf)

This is important especially in e.g. the new Windows Terminal, because
for some reason that lets the tab stick around if the process exited
with a non-zero status.

Will add tests as soon as I figure out how.
2020-09-16 21:02:59 +02:00
ridiculousfish
2a8e104cc8 Relax some main thread requirements around waiting for jobs
This is now correctly per-parser so the thread should no longer matter.
2020-09-13 17:54:52 -07:00
ridiculousfish
9ba12aad55 Fix the tests
Make the features_t constructor public so the tests compile. Mea culpa.
2020-09-12 19:06:28 -07:00
ridiculousfish
6e11750479 Make the global feature set an instance variable
Allow it to be inlined.
2020-09-12 17:35:21 -07:00
Fabian Homborg
5fd3ad624f screen: Show suggestion if the commandline was pushed to a new line
Pretty sure this was just overlooked, the comment mentions that it
should happen and it seems to work.

Fixes #7213.
2020-09-12 20:09:26 +02:00
Fabian Homborg
568f9031aa builtin realpath: Add --no-symlinks option
Taken from GNU realpath, this one makes realpath not resolve symlinks.

It still makes paths absolute and handles duplicate and trailing
slashes.

(useful in fish_add_path)
2020-09-12 19:26:04 +02:00
Fabian Homborg
8cf389baf2 tokenizer: Switch to !iswblank instead of iswgraph
Fixes #7328
2020-09-11 23:53:26 +02:00
Fabian Homborg
0e9b496bba Fix bigword bindings with single-character words
With a commandline like

```
a b c d
```

and the cursor at the beginning, this would eat "a b", which isn't a
sensible bigword.

Bigword should be "a word, with optional leading whitespace".

This was caused by an overly zealous state-machine that always ate one
char and only *then* started eating leading whitespace.

Instead eat *a character*, and if it was whitespace go on eating
whitespace, and if it was a printable go straight to only eating
printables.

Fixes #7325.
2020-09-11 20:13:06 +02:00