Commit Graph

1418 Commits

Author SHA1 Message Date
Fabian Homborg
81a987c39c Fix range expansion with negative ends
If just one of the range ends is negative, this now forces direction away from it.

I.e. if the beginning is negative, we go in reverse.
If the end is negative, we go forwards.

This fixes cases like

    $var[2..-1]

if $var only has one element.
2018-06-25 17:52:56 +02:00
ridiculousfish
5692adbdf6 Teach fish_wcwidth about variation selectors
System wcwidth() misreports variation selectors as width 1. Special
case these to width -1 (unprintable).

See #2652
2018-06-23 16:40:25 -07:00
ridiculousfish
44bae29039 Add a debug_escape function
This function for debugging makes it easier to understand what special
characters are present in a string.
2018-06-23 13:15:32 -07:00
Mahmoud Al-Qudsi
cda18be6b4 fixup! Replace \e with \x1B, as the former is a gcc extension 2018-06-18 00:34:31 -05:00
Mahmoud Al-Qudsi
27cd74e16c Fix warning about extra ';' being ignored
It is both present at the end of the #define and explicitly included
after the define is called in the main code, leading to an expansion of
`;;`.
2018-06-18 00:05:31 -05:00
Mahmoud Al-Qudsi
dcced5f1bc Replace \e with \x1B, as the former is a gcc extension
While supported by gcc and clang, \e is a gcc-specific extension and not
formally defined in the C or C++ standards.

See [0] for a list of valid escapes.

[0]: https://stackoverflow.com/a/10220539/17027
2018-06-18 00:01:47 -05:00
Mahmoud Al-Qudsi
d16d463e0d Silence EACCES errors upon setpgid after posix_spawn()
We've tried numerous approaches to mitigate the race condition between
`posix_spawn` and the `setpgid` call, but unfortunately due to the flags
we pass to `posix_spawn`, it (rarely? never?) results in `vfork()` being
used, which means it is never executed atomically. Since it is executed
out-of-band, we must manually call `setpgid` in case `posix_spawn`
hasn't gotten around to doing that yet, but in the event that it has, an
EACCES error can be returned.

Closes #4884. Closes #4715. See also #4778.
2018-06-17 22:32:52 -05:00
Mahmoud Al-Qudsi
8f166cbb2a Prevent fish from crashing if non-essential terminfo strings not found
On systems where the terminfo for TERM does not contain a string for
attributes such as enter_underline_mode, etc. fish was crashing with a
fatal error message and a note to email the developers.

These are non-essential text attribute changes and should not trigger
such a failure.
2018-06-17 20:59:34 -05:00
Mahmoud Al-Qudsi
a6d64c1086 Handle odd return codes for waccess(..) in src/path.cpp under Solaris 2018-06-17 19:58:20 -05:00
ridiculousfish
2443ea92c3 Eliminate a common subexpression 2018-06-16 11:43:52 -07:00
ridiculousfish
e6737d5775 Use a std::move in expand_cmdsubst
Save an unnecessary allocation.
2018-06-16 11:40:59 -07:00
Fabian Homborg
8de5af5f9e Fix off-by-one in complete_cmd_desc
The substring constructor (string(str, pos)) includes pos, so we need
to add one. Also be careful not to go over the length again.
2018-06-03 19:17:02 +02:00
Mahmoud Al-Qudsi
56198818b0 Work around compiler warning regarding C++17 name mangling
[9/13] Building CXX object CMakeFiles/fishlib.dir/src/builtin_string.cpp.o
../src/builtin_string.cpp:1221:12: warning: mangled name of 'string_transform' will change in C++17 due to non-throwing exception specification in function signature [-Wc++17-compat-mangling]
static int string_transform(parser_t &parser, io_streams_t &streams, int argc, wchar_t **argv, decltype(std::towlower) func) {
           ^
1 warning generated.
2018-06-01 22:53:33 -05:00
Fabian Homborg
72e9d41dcc [complete] Fix crash with __fish_describe_command
Our completion machinery calls our `__fish_describe_command` function
to describe commands via apropos. Only it trusts the output a bit too
much, so it crashes when any line from that is shorter than the
original string.

Fix this by skipping any string that is shorter than the original,
since it can't be a match anyway.

Also stop doing wcslen so often - std::strings are nice!

Fixes #5014.
2018-06-01 20:16:23 +02:00
Fabian Homborg
93d40f9143 [input] Only timeout if the last character was escape
There really is no need to

- Timeout just because the _first_ character was a control character

- Timeout because of any control character other than escape

The reason to timeout because the '\e' sequence can appear by itself (signifying
pressing the escape key) and still make
sense - e.g. vi-mode has it bound to a rather important function!

But a \c can't appear by itself, so we can just block.

This allows binding sequences like \cx\ce and inputting them at a
leisurely pace rather than the frantic escape_timeout one.

It should also improve sequences that _include_ escape somewhere else.

E.g. something like a\eb ("a, then alt+b") should now time out for the "\eb" part,
allowing users to bind a\e ("a, then escape") to something else. Why you'd want to do
that, I have no idea. But it's more consistent, and that's nice!
2018-05-29 18:40:29 +02:00
Fabian Homborg
88e6930b57 [string] Be explicit about nextstr() type 2018-05-28 12:10:40 +02:00
Fabian Homborg
49c736f407 [string] Move split/repeat to wcstring 2018-05-28 12:10:40 +02:00
Fabian Homborg
e468c767b5 [String] Partially switch match/replace to string
For regex-mode, this should be enough to read NUL-delimited strings to act on, but not
quite patterns and replacements.

Glob-mode requires more work - it uses wcscmp internally, which is unsuitable.
2018-05-28 12:10:40 +02:00
Fabian Homborg
1e2fa80d3e Switch (un)escape to wcstring
Also the various styles have one function each with barely any
difference - mostly passing the corresponding STYLE argument.

Pack them into one function for escape and one for unescape to save
about 100 lines.
2018-05-28 12:10:40 +02:00
Fabian Homborg
0cfe722a93 Switch lower/upper to wcstring
Also, these are different only in that one uses "towlower", the other
"towupper". So just make one function that both call.
2018-05-28 12:10:40 +02:00
Fabian Homborg
191ca21092 Switch trim to wcstring 2018-05-28 12:10:40 +02:00
Fabian Homborg
4cc0c3bfa7 Switch string sub to wcstring 2018-05-28 12:10:40 +02:00
Fabian Homborg
583d771b10 Fix escape_string_var for UTF-16
We're now actually handling wchar_t here, so comparing the 0x80 bit
would break for UTF-16, causing ASCII false-positives.

Also simplifies a bit, since we no longer need a second variable.
2018-05-28 12:10:40 +02:00
Fabian Homborg
b2b4ab4bab constref more things
Thanks @ridiculousfish!
2018-05-28 12:10:40 +02:00
Fabian Homborg
4dc1c6ca39 [string] Allow url/var escaping to handle NULs
Fixes #4605.
2018-05-28 12:10:40 +02:00
Fabian Homborg
485fdbde41 [string] Allow length to handle NULs
printf 'a\0b' | string length

used to print "1". Now it prints "3".

Note that this switches to using C++'s std::string::length, which
might give differing results.
2018-05-28 12:10:40 +02:00
Fabian Homborg
bcd23ff971 [string] Allow join to handle NULs 2018-05-28 12:10:40 +02:00
Fabian Homborg
aedb8dc327 [string] Allow string escape to handle NULs
TODO: This currently only works for the "script" escaping style.

Work towards #4605.
2018-05-28 12:10:40 +02:00
Fabian Homborg
a229f703ae Allow escape_string_url from escape_string with wcstring
This was an oversight.
2018-05-28 12:10:39 +02:00
Fabian Homborg
338b40bb43 Trust the passed size in escape_string_script
This allows it to handle NULs.
2018-05-28 12:10:39 +02:00
ridiculousfish
ba69f8f71d Remove an unused variable 2018-05-27 15:46:30 -07:00
ridiculousfish
5492a16719 Clean up some env.cpp export code
Adopt some modern practices.
2018-05-27 15:45:30 -07:00
Swayam Raina
eb0539af60 Don't update CMD_DURATION if no command is requested
Fixes issue #4926
2018-05-27 11:37:36 -07:00
Fabian Homborg
9de28f6887 Add some more fallback key bindings
DEL (aka backspace) and the arrows.

This makes fish usable without binding functions, though not pleasant.

See #1256.
2018-05-17 11:14:02 +02:00
Mahmoud Al-Qudsi
0dd2607cac Iron out situation with setpgid() calls after posix_spawn()
Closes #4715. Ticks off a box in #4154.
2018-05-16 19:34:56 -05:00
Mahmoud Al-Qudsi
3cda5ac59b Clean up complete.cpp code
Embrace C++11 ranged for loops.
2018-05-12 11:23:43 -05:00
Fabian Homborg
feb6e9c90b Make DEFAULT_PROMPT and DEFAULT_TITLE work without functions
The prompt is a fallback that is overridden via a function file
anyway.

Do that with the title as well, so we can use just builtins.

This removes error messages when $fish_function_path is borked.
2018-05-12 13:53:45 +02:00
Mahmoud Al-Qudsi
b635863509 Fix warnings when compiling under clang
Introduced by #4849 (add wait for processes by name)

../src/builtin_wait.cpp:23:14: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
    while (j = jobs.next()) {
           ~~^~~~~~~~~~~~~
../src/builtin_wait.cpp:23:14: note: place parentheses around the assignment to silence this warning
    while (j = jobs.next()) {
             ^
           (              )
../src/builtin_wait.cpp:23:14: note: use '==' to turn this assignment into an equality comparison
    while (j = jobs.next()) {
             ^
             ==
1 warning generated.
2018-05-11 11:11:53 -05:00
Fabian Homborg
7c5297e785
Merge branch 'master' into issue_4848 2018-05-11 16:06:27 +02:00
Fabian Homborg
e35d248f64 Fix clearing abandoned line with VTE (#4243)
Turns out the segfaults we've been getting in our tests are because we set $TERM to "dumb".

So we only clear the line if the terminal isn't dumb.

This reverts commit 745a88f2f6.

Fixes #2320.
2018-05-08 13:07:47 +02:00
David Adam
21890ccac7 function: restore '%self' functionality for --on-process-exit
One key use of process expansion, used in currently-shipped code, is for running a function on
current shell exit.

Restore the use of %self as a valid argument (and add `self`) and document this change.

(faho: Remove bare "self")
2018-05-08 11:17:07 +02:00
ridiculousfish
98d736f916 Teach fish_indent about escaped newlines
Correctly indents code like:

   alpha | \
     # comment
     beta
2018-05-07 21:40:53 -07:00
ridiculousfish
6f57fef8f8 Teach the tokenizer to report escaped newlines
Add fields and flags so that escaped newlines can be reported, for the
benefit of fish_indent.
2018-05-07 21:39:30 -07:00
ridiculousfish
678fd86107 Minor cleanup of parse_ll_t::accept_tokens 2018-05-07 14:20:45 -07:00
ridiculousfish
5f787cfe55 Correct format string in dump_tree_recursive
This was passing two unused arguments to the format string. Use one
and drop the other.
2018-05-07 13:44:26 -07:00
ridiculousfish
4194b4efee Add a feature_test() function
This is a convenience over fish_features().test()
2018-05-06 11:20:15 -07:00
ridiculousfish
762c31be87 Feature flag support for ? wildcard
This partially reverts 6e56637cf0 and #4520
by bringing back the ? wildcard, guarded by the qmark-noglob feature flag.
2018-05-06 11:20:15 -07:00
ridiculousfish
dc8d603f98 Add a qmark-noglob feature flag
This adds a feature flag for controlling whether question marks are globs.
It is not yet hooked up.
2018-05-06 11:20:15 -07:00
ridiculousfish
d3201ad887 Set features from the environment
This enables users to opt in (or out) of specific features by setting
the fish_features environment variable.

For example `set -U fish_features stderr-nocaret` to opt into removing the
caret redirection.
2018-05-06 11:20:14 -07:00
ridiculousfish
902af26253 Bring back caret redirections under a feature flag
This partially reverts 5b489ca30f, with
carets acting as redirections unless the stderr-nocaret flag is set.
This flag is off by default but may be enabled on the command line:

fish --features stderr-nocaret
2018-05-06 11:20:14 -07:00