Commit Graph

1690 Commits

Author SHA1 Message Date
ridiculousfish
f7a020ad33 Rename launch process to exec_process_in_job
This avoids a name collision with another launch_process
2018-09-03 11:18:39 -07:00
ridiculousfish
48c510572b Factor out launch_process from exec.cpp
Makes the monster function slightly more tractable.
2018-09-01 14:54:23 -07:00
ridiculousfish
753639aa9c Reduce the scope of pid in exec_job 2018-09-01 14:39:32 -07:00
ridiculousfish
ec9c592edc Adopt autoclose_fd_t in exec_job 2018-09-01 14:27:58 -07:00
ridiculousfish
274c77cf0c Add autoclose_fd_t for helping to manage file descriptors 2018-09-01 14:27:36 -07:00
ridiculousfish
9269a5e0a8 Clean up abbreviation implementation a bit 2018-09-01 13:18:34 -07:00
ridiculousfish
051605b593 Cleap up owning_lock interface
Use some operator overloading to avoid the weird interface of acquired_lock.
2018-09-01 13:11:42 -07:00
ridiculousfish
1a9e3761ae Add highlighting tests for empty variables 2018-09-01 12:05:52 -07:00
ridiculousfish
7bd26f9ff0 Teach syntax highlighting about variables in commands 2018-09-01 12:00:56 -07:00
ridiculousfish
865a4647ae Allow variables in commands
Syntax highlighting for these coming in next commit.

Fixes #154
2018-09-01 12:00:56 -07:00
ridiculousfish
59d78e8afa Clean up syntax highlighting test 2018-09-01 10:17:57 -07:00
ridiculousfish
de2b0d1ae8 Remove some #if 0 code 2018-08-26 02:36:28 -07:00
ridiculousfish
2a680ebd12 Fix some miscellaneous warnings 2018-08-26 00:43:40 -07:00
ridiculousfish
67c4da9dbf Correct formatting in argparse 2018-08-25 16:18:49 -07:00
ridiculousfish
4abdf8c301 Some refactoring of argparse implicit ints 2018-08-25 16:14:16 -07:00
ridiculousfish
d046452cdf Increased const correctness in argparse 2018-08-25 16:09:04 -07:00
ridiculousfish
9f436c3750 Clean up bits of wgetopter_t interface 2018-08-25 16:09:04 -07:00
Mahmoud Al-Qudsi
1b1bc28c0a Protect against loss of background jobs on exec
`exec` now exhibits the same behavior as `exit` and prompts the user to
confirm their intention to end the current process if there are
background jobs running. Running `exec` again immediately thereafter
will force the exec to go through.

Additionally, background jobs are reaped upon exec to prevent process
leaking (same as `exit`).
2018-08-20 22:52:47 -05:00
ridiculousfish
54d8d169b5 Remove some compatibility juk from wgetopt 2018-08-18 17:22:55 -07:00
ridiculousfish
d9f34147c3 builtins to only acquire terminal if owned by their pgroup
Fix #5133 changed builtins to acquire the terminal, but this regressed
caused fish to be stopped when running in background via `sudo fish`.
Fix this by only acquiring the terminal if the terminal was owned by the
builtin's pgroup.

Fixes #5147
2018-08-18 16:56:01 -07:00
ridiculousfish
cbcabf6d00 Add support for fish_ambiguous_width
fish_ambiguous_width is a variable which controls the width of ambiguous CJK
characters.

Fixes #5149
2018-08-18 15:38:05 -07:00
ridiculousfish
d40a82b4d3 Mark reader.cpp jump as static 2018-08-18 14:48:46 -07:00
Chris
1d68b52cbc Add till/repeat/reverse jump bindings
- Add support for:
  - Jumping to the character before a target.
  - Repeating the previous jump (same direction, same precision).
  - Repeating the previous jump in the reverse order.
- Enhance vi bindings.
2018-08-18 14:42:29 -07:00
Mahmoud Al-Qudsi
1c59a3f1a8 Fix traversal order of tokens in history completion
Fixes an issue introduced by e51e854. Closes #5150.
2018-08-16 14:07:38 -05:00
ridiculousfish
fa66ac8d8c Acquire tty if interactive when running builtins
When running a builtin, if we are an interactive shell and stdin is a tty,
then acquire ownership of the terminal via tcgetpgrp() before running the
builtin, and set it back after.

Fixes #4540
2018-08-12 03:41:56 -07:00
ridiculousfish
c0a332743f Escape less aggressively when showing completions in pager
Stop escaping [, spaces, etc. in the pager.
2018-08-12 03:37:13 -07:00
ridiculousfish
9b22ae7c74 Remove a gnarly macro from builtin_history 2018-08-12 02:41:09 -07:00
ridiculousfish
d87f00bdc9 Simplify history search
Remove features related to navigating forwards in history that are no
longer used.
2018-08-12 02:41:09 -07:00
ridiculousfish
e51e854d8d Clean up reader history search
Factor the history search fields into a new class.
As a side effect, this shares the deduplication logic, so that token search
no longer returns duplicates.

Fixes #4795
2018-08-12 02:40:15 -07:00
ridiculousfish
1473f952d4 Make contains() more general
Allow contains() to find arbitrary values in arbitrary vectors, and adopt it
in place of std::find.
2018-08-11 22:23:20 -07:00
ridiculousfish
b0dc715d18 Factor update_autosuggestion to use can_autosuggest 2018-08-11 17:40:06 -07:00
ridiculousfish
4fdcc2e400 Begin to rationalize reader data stack
Switch from a manually maintained linked list to an explicit stack.
2018-08-11 13:17:00 -07:00
ridiculousfish
68c7ecd777 Remove reader_t::app_name field
It was unused
2018-08-11 13:02:50 -07:00
ridiculousfish
f7d846ad8b Make reader_push accept wcstring instead of wchar_t* 2018-08-11 12:43:11 -07:00
ridiculousfish
82bff2d692 Modernize some reader code for C++11 2018-08-11 12:39:24 -07:00
ridiculousfish
1f2b2b119a Remove some disabled (commented or ifdef'd out) code 2018-08-10 20:48:02 -07:00
Jon Eyolfson
c3ca108dbe Added const to methods which 'ought to be const' based on Const Checker 2018-08-09 19:05:47 -07:00
ridiculousfish
9c957eeef3 Prefer to not autosuggest existing arguments
This teaches autosuggestions to demote completions whose text matches an already
present argument.
2018-08-07 02:04:43 -07:00
ridiculousfish
459c01df76 Slightly refactor completion calculation
Move more stuff into completer_t
2018-08-07 00:40:01 -07:00
ridiculousfish
3175ccf266 Use move semantics when returning completions
Avoids some string copies
2018-08-06 23:58:48 -07:00
ridiculousfish
20cec8611d Remove a stale comment 2018-08-04 16:51:57 -07:00
ridiculousfish
cbff87fe17 Minor cleanup and const correctness 2018-08-04 16:45:16 -07:00
ridiculousfish
2b0c54dfc8 Ignore return value of system() in tests
Fixes some warnings on Linux
2018-08-04 16:33:31 -07:00
ridiculousfish
acff2516d4 Straighten out some wchar_t** casts
Embrace the fact that builtins expect to modify their argv array and get rid
of a bunch of const.
2018-08-04 16:25:51 -07:00
ridiculousfish
5eada4b623 Put some of builtin_test in an anonymous namespace
Reduces the binary size a bit
2018-08-04 15:49:20 -07:00
ridiculousfish
d2bee105c9 Default math scale to 6
This changes the behavior of builtin math to floating point by default.
If the result of a computation is an integer, then it will be printed as an
integer; otherwise it will be printed as a floating point decimal with up to
'scale' digits past the decimal point (default is 6, matching printf).
Trailing zeros are trimmed. Values are rounded following printf semantics.

Fixes #4478
2018-08-04 15:32:09 -07:00
David Adam
22ccee3380 wutil.h: fix build on newer glibc
https://sourceware.org/glibc/wiki/Release/2.26#Removal_of_.27xlocale.h.27
2018-08-03 22:35:50 +08:00
ridiculousfish
40e37c4a87 Teach test to handle floating point values 2018-08-03 00:48:50 -07:00
ridiculousfish
42c648ab35 Create an immortal C locale
This adds a function fish_c_locale() which returns an immortal locale_t
corresponding to the C locale, and switches builtin_printf to use wcstod_l.
2018-08-03 00:48:50 -07:00
ridiculousfish
9d1fc1045e Implement 'functions -d' to set function description
This was documented, but didn't actually work.

Fixes #5105
2018-07-22 11:28:05 -07:00
ridiculousfish
7af3adc344 Revert "Don't require ./etc to exist in relocatable fish"
This reverts commit e2a3dae58b.

This idea failed because ./share was not complete when bliding via cmake;
it misses critical files such as config.fish.
2018-07-21 20:57:21 -07:00
ridiculousfish
8b83fe1ff7 Simplify yet more memory management in argparse 2018-07-21 19:13:10 -07:00
ridiculousfish
c269ef2c5d Copy strings less in argparse 2018-07-21 18:53:03 -07:00
ridiculousfish
3c4c47f516 Clean up some memory usage in argparse
Clarify some ownership models
2018-07-21 18:52:54 -07:00
ridiculousfish
a374b8ede7 Simplify splitting on commas in argparse 2018-07-21 17:25:16 -07:00
ridiculousfish
e2a3dae58b Don't require ./etc to exist in relocatable fish
fish tries to be relocatable by looking for directories relative to its
executable. These directories are not found when running fish from
within a cmake build because the etc directory is not present. Stop requiring
this directory to be present since it's not critical for running fish.

Fixes #4825
2018-07-21 16:47:00 -07:00
ridiculousfish
57cc3d950d Remove some unnecessary test output 2018-07-21 15:31:14 -07:00
ridiculousfish
dae2809531 Fix a few warnings 2018-07-21 14:35:39 -07:00
ridiculousfish
a11e955c84
Merge pull request #5097 from ridiculousfish/history_read
Don't mmap history files on remote file systems

This merges some changes to history that may help to mitigate the crashes seen in #5088 . These SIGBUS crashes occur when reading a memory mapping whose underlying file was truncated. It's not clear why this should occur more often on NFS (or ever). However memory mapping over NFS is sketchy anyways so this is desirable regardless.
2018-07-21 13:51:49 -07:00
ridiculousfish
c636a455a0 Add locking to try_complete_user
This uses the thread-unsafe getpwent(). Add a lock around the whole section
to avoid the crash identified in #5088
2018-07-15 15:50:56 -07:00
ridiculousfish
4d1eeef3db Stop trying to mmap the history file on remote fs
When the history file is on a remote filesystem, memory mapping is suspicious.
Never mmap in this case.
2018-07-15 15:26:36 -07:00
ridiculousfish
679437d6a9 Implement fd_check_is_remote
This adds a new function fd_check_is_remote() which is designed to determine
if a file lies on a remote (SMB, NFS, etc.) filesystem.
2018-07-15 15:26:36 -07:00
ridiculousfish
a39734cbed Encapsulate history mmap logic
Migrate the mmap() logic into a new class history_file_contents_t which
will serve to encapsulate conditional logic if we choose to use read()
instead of mmap().
2018-07-15 15:26:27 -07:00
ridiculousfish
63e0a3d7c2 Misc cleanup in history_t
Add some C++11
2018-07-15 14:33:38 -07:00
ridiculousfish
2ce0240fc8 Add a time_profiler for reading old history items 2018-07-15 14:33:38 -07:00
ridiculousfish
28455235b1 Migrate to widechar_wcwidth
Adopt the new widechar_wcwidth() function from
https://github.com/ridiculousfish/widecharwidth

Fixes #5081
2018-07-09 20:31:16 -07:00
ridiculousfish
73c747d162 Add string join0
string join0 joins its arguments using NUL byte, which complements
string split0. For example it allows piping a variable through sort -z.
2018-07-01 15:56:34 -07:00
ridiculousfish
d34a300818 Add string split0
This adds a new string command split0, which splits on zero bytes.
split0 has superpowers because its output is not further split on
newlines when used in command substitutions.
2018-07-01 15:56:33 -07:00
ridiculousfish
f998afaa23 Adopt separated_buffer_t in io_buffer_t 2018-07-01 15:56:33 -07:00
ridiculousfish
90a4af5112 Add separated_buffer_t and adopt it in output_stream_t
separated_buffer_t encapsulates the logic around discarding (which
was previously duplicated between output_stream_t and io_buffer_t),
and will also encapsulate the logic around explicitly separated
output.
2018-07-01 15:56:33 -07:00
ridiculousfish
5b9331ade0 Teach io_buffer_t to append from output_stream_t directly
This will simplify logic when we teach output_stream_t about explicitly
split outputs, i.e. for 'string split0'
2018-07-01 15:56:33 -07:00
ridiculousfish
369890cdd9 Clean up io_buffer_t interface 2018-07-01 15:56:33 -07:00
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
ridiculousfish
8a96f283ba Allow setting feature flags on the command line
This introduces a new command line option --features which can be used for
enabling or disabling features for a particular fish session.

Examples:
  fish --features stderr-nocaret
  fish --features 3.0,no-stderr-nocaret
  fish --features all

Note that the feature set cannot be changed in an existing session.
2018-05-06 11:20:14 -07:00
ridiculousfish
782cae2d21 Add status subcomannds: features and test-feature
This teaches the status command to work with features.
'status features' will show a table listing all known features and whether
they are currently on or off.
`status test-feature` will test an individual feature, setting the exit status to
0 if the feature is on, 1 if off, 2 if unknown.
2018-05-06 11:20:14 -07:00
ridiculousfish
14f766b66d Add support for feature flags
This introduces a new type features_t that exposes feature flags. The intent
is to allow a deprecation/incremental adoption path. This is not a general
purpose configuration mechanism, but instead allows for compatibility during
the transition as features are added/removed.

Each feature has a user-presentable short name and a short description. Their
values are tracked in a struct features_t.

We start with one feature stderr_nocaret, but it's not hooked up yet.
2018-05-06 11:20:14 -07:00
Fabian Homborg
1a1ee352ff [commandline] Change "--selection" to "--current-selection"
Plus documentation.

Work towards #4255.
2018-05-05 21:41:03 +02:00
Fabian Homborg
b0368fd85b Set $IFS in C++
This was done in share/config.fish, but leads to surprising results if
that isn't read - e.g. because someone just built fish in the git
directory to test it without installing.

It's also not something that is any more or less complicated.

For compatibility, keep it in config.fish as well for the time being.
2018-05-03 12:49:21 +02:00
Fabian Homborg
baeeef3233 Remove triggerable assert in unescape_string_internal
Fixes #4954 - in a hacky way.
2018-05-02 16:35:56 +02:00
Kevin Ballard
e03db61dac
Merge pull request #4909 from kballard/history_delete_err_msg
Tweak the error message for `history delete --exact foo`
2018-04-18 22:36:18 -07:00
Mahmoud Al-Qudsi
c8af566330 Stop completion skipping in case of valid ./command
complete.cpp strips the path from commands before parsing for
completions, meaning that when we called `path_get_path()` against
`cmd`, if `./cmd` were typed in at the command line but `cmd` does not
exist in the PATH, then the command would incorrectly be flagged as not
present and the completions would be skipped.

This is also faster when an absolute/relative path is used for a
command, as we now search with the original path which skips searching
PATH directories unnecessarily.

Found when debugging why completions for `./configure` wouldn't work.
2018-04-17 21:34:22 -05:00
Mahmoud Al-Qudsi
3742a7827f Support multiple read --line variable outputs
ref #4861. Also closes #4917.
2018-04-17 21:34:22 -05:00
Mahmoud Al-Qudsi
bd8c8ceb59 Add line-delimited read presets with --line and --all-lines
Refer to changes in doc_src/read.txt for more info. Closes #4861.
2018-04-17 21:34:22 -05:00
Mahmoud Al-Qudsi
d00474f0fc Optimize split_about 2018-04-17 21:34:22 -05:00
Kevin Ballard
afc5c0a6e7 Tweak the error message for history delete --exact foo
The old message made it sound like the `--exact` flag wasn't supported.
2018-04-14 21:59:18 -07:00
Mahmoud Al-Qudsi
a9b582d2a8 Block .dll files from completion as potential heads under WSL 2018-04-14 23:56:30 -05:00
Mahmoud Al-Qudsi
1c8bbfdb6d Support job expansion for jobs builtin
This brings back expansion of `%n` where `n` is a job id, but not as a
general parser syntax. This makes `jobs -p %n` work, which can be used
as part of the job control command chain, i.e.

```
cat &
fg (jobs -p %1)
```

fg/bg/wait can either be wrapped in a function to call `jobs -p` for
`%n` arguments, or they can be updated to take `%n` arguments
themselves.
2018-04-14 16:47:05 -05:00
Fabian Homborg
d53750bee6 Let read -s also output to stdout
This was caused by "to_stdout" being automatically enabled if argc was
0 _before_ removing options.

Fixes #4859.
2018-04-10 21:46:43 +02:00
Fabian Homborg
ea49c14c62 Fix read to stdout output appearing first
echo banana (read)

will output whatever read reads _first_ because it uses a direct
write_loop().

This also removes some duplicate code.
2018-04-10 21:45:28 +02:00
Kevin Ballard
f7ba2a6a00 Don't corrupt memory when setting a slice with wrong # of args
Fixes #4881.
2018-04-10 21:09:31 +08:00
Mahmoud Al-Qudsi
d8a1928c24 Convert list of builtins from sorted array to unordered_set
The order of this list does not need to be strictly maintained any
longer.

Benchmarked with `hyperfine` as follows, where `bench1` is the existing
approach of binary search and `bench2` is the new unordered_set code,
(executed under bash because fish would always return non-zero). The
benchmark code checks each argv to see if it is a builtin keyword (both
return the same result):

```
hyperfine './bench1 $(shuf /usr/share/dict/words)' './bench2 $(shuf /usr/share/dict/words)'
Benchmark #1: ./bench1 $(shuf /usr/share/dict/words)

  Time (mean ± σ):      68.4 ms ±   3.0 ms    [User: 28.8 ms, System: 38.9 ms]

  Range (min … max):    60.4 ms …  75.4 ms

Benchmark #2: ./bench2 $(shuf /usr/share/dict/words)

  Time (mean ± σ):      61.4 ms ±   2.3 ms    [User: 23.1 ms, System: 39.8 ms]

  Range (min … max):    58.1 ms …  67.1 ms

Summary

'./bench2 $(shuf /usr/share/dict/words)' ran
    1.11x faster than './bench1 $(shuf /usr/share/dict/words)'
```
2018-04-03 15:47:21 -05:00
Mahmoud Al-Qudsi
cc50103e53 Unblock builtins from completions
The `head_exists` value was being reset after being set to true for most
builtins, causing completions to not trigger.
2018-04-03 14:05:11 -05:00
ridiculousfish
f922875dbc Fix the Linux build 2018-04-01 17:59:42 -07:00
ridiculousfish
a98cc75f9e Reword warning inside fish_universal_variables file
Prior to this fix, the fish universal variables file claimed that
changes to it would be overwritten. This no longer true and has not
been true for a long time. Remove that warning.
2018-04-01 17:51:53 -07:00
ridiculousfish
ff10e504a1 Remove MAC address from universal variables file
This switches the universal variables file from a machine-specific
name to the fixed '.config/fish/fish_universal_variables'. The old file
name is migrated if necessary.

Fixes #1912
2018-04-01 17:43:12 -07:00
ridiculousfish
222a45f07a Add acquire() to maybe_t
Easy way to pull the value out.
2018-04-01 16:10:59 -07:00
Peter Ammon
5b489ca30f Remove caret redirection
This removes the caret as a shorthand for redirecting stderr.

Note that stderr may be redirected to a file via 2>/some/path...
and may be redirected with a pipe via 2>|.

Fixes #4394
2018-04-01 13:48:21 -07:00
Mahmoud Al-Qudsi
01452da5bf Add and use new exit code for env_remove() when var doesn't exist
The previous commit caused the tests to fail since env_remove() was
returning a blanket `!0` when a variable couldn't be unset because it
didn't exist in the first place. This caused the wrong message to be
emitted since the code clashed with a return code for `env_set()`.

Added `ENV_NOT_FOUND` to signify that the variable requested unset
didn't exist in the first place, but _not_ printing the error message
currently so as not to break existing behavior before checking if this
is something we want.
2018-03-31 22:12:52 -05:00
Mahmoud Al-Qudsi
0e0168ef18 Display error message on set -e PROTECTED
Previously unsetting a variable would fail silently. Now sharing error
printing code from regular `set PROTECTED` call.
2018-03-31 21:44:54 -05:00
ridiculousfish
abcc9647da Fix some unused variable warnings 2018-03-31 17:06:13 -07:00
ridiculousfish
6e56637cf0 Remove support for the ? wildcard
Fixes #4520
2018-03-31 16:54:50 -07:00
ridiculousfish
4b079e16e5 Execute the conditions of if and while statements outside of their block
Variables set in if and while conditions are in the enclosing block, not
the if/while statement block. For example:

    if set -l var (somecommand) ; end
    echo $var

will now work as expected.

Fixes #4820. Fixes #1212.
2018-03-31 14:57:24 -07:00
slama
d88866ccf7 deleted no longer necessary codes due to removing process expansion. 2018-03-31 12:12:27 -07:00
Fabian Homborg
535617623b Make pager background cover the entire candidate
Currently, there are two possibilities for holes in the background:

- When there are two candidates with the same meaning (a long and a
  short option or two candidates with the same description)

- When a candidate does not have a description (meaning the color
  won't continue after it)

This changes both so the background just goes on.

In addition, it avoids making the background multiple times.

Fixes #4866.
2018-03-31 13:04:30 +02:00
Mahmoud Al-Qudsi
999728670d Default string split to keeping empty entries with option to remove
The official fish documentation makes no mention of how `string split`
treats empty tokens, e.g. splitting 'key1##key2' on '#' or (more
confusingly) splitting '/path' on '/'. With this commit, `string split`
now has an option to exclude zero-length substrings from the resulting
array with a new `--no-empty/-n`. The default behavior of preserving
empty entries is kept so as to avoid breakage.
2018-03-29 08:12:08 -05:00
Mahmoud Al-Qudsi
412c5aeaa6 Use alternative Unicode glyphs if compiled under Windows/WSL
The two unicode glyphs used to represent missing new lines and redacted
characters for secure entry are both not present in the glyph tables of
the default font under Windows (Consolas and Lucida Console), use an
alternative glyph instead.

The "return" symbol is replaced with a pilcrow (¶) and the "redacted
character" symbol is replaced with a bullet (•). Both of these are
well-defined in almost all fonts as they're very old symbols. This
change only takes place if -DWSL is supplied by the build toolchain.

Note: this means a Windows SSH client connecting to a fish remote
instance on a non-Windows machine will still use the (unavailable)
default glyphs instead.
2018-03-28 14:27:25 -05:00
ridiculousfish
669eafb55f Stop exporting empty variables as ENV_NULL
Localize the encoding of empty variables as ENV_NULL into the universal
variables component, and ensure they are not exported as ENV_NULL.

Fixes #4846
2018-03-24 23:42:09 -07:00
slama
bb1956fd8d fix the problem that wait command doesn't work correctly in fish script. 2018-03-25 14:22:27 +09:00
Aaron Miller
517b77ca74 Fix handling of signals (#4851) 2018-03-24 12:37:15 -07:00
slama
b758f84976 wait for processes by their name
- You can now specify the process name instead of process ids and wait for jobs.
- Refactor the code of wait command
2018-03-25 02:21:15 +09:00
Mahmoud Al-Qudsi
8bbecb66cf Fix accidental rename of --pid parameter to jobs builtin 2018-03-24 12:13:58 -05:00
Mahmoud Al-Qudsi
515fc509ec Deprecate $_ in favor of (status current-command)
Closes #813.
2018-03-24 11:58:19 -05:00
Mahmoud Al-Qudsi
6d80ab8d74 Rename $pid (née %self) to $fish_pid 2018-03-24 11:54:27 -05:00
Mahmoud Al-Qudsi
5a561bcfce Source : function without any C++ hacks
Thanks, @faho
2018-03-15 18:19:08 -05:00
Mahmoud Al-Qudsi
2477a894e7 Drop read + parse of /proc/sys/kernel/osrelease on startup
This has been obviated by the CMake-defined WSL #define.
2018-03-14 18:28:16 -05:00
Mahmoud Al-Qudsi
3996e437b6 Autoload : function on startup.
The newly added `:` command is implemented as a function (to avoid
increasing complexity by making it a builtin), but it is saved to a path
that does not match its filename (since its name is somewhat of a
special character that might cause problems during installation).
Directly probing the `colon` function for autoload causes `:` to be
correctly loaded, so doing just that after function paths are loaded
upon startup.

This is a hack since the CPP code shouldn't really be aware of
individual functions, perhaps there is a better way of doing this.
2018-03-14 18:22:10 -05:00
Amos Bird
06c8440d72 fix compile error on gcc 7.3 2018-03-14 13:13:59 +01:00
Mahmoud Al-Qudsi
3889079f48 Omit debug(0) log message on invalid completion, leftover from debugging 2018-03-13 19:47:51 -05:00
Mahmoud Al-Qudsi
4caf4ec5e5 Fix completions for functions in custom paths
Fixes an issue introduced in 4414d5c888
where functions loaded from custom directories are not detected as being
valid for purposes of determining whether or not completions should be
called.
2018-03-13 19:41:24 -05:00
Mahmoud Al-Qudsi
1441cca9c5 Restore localization to tokenizer error strings
Work around #4810 by retrieving localizations at runtime to avoid issues
possibly caused by inserting into the static unordered_map during static
initialization.

Closes #810.
2018-03-13 13:45:15 -05:00
Mahmoud Al-Qudsi
054bc88b82 Add gettext operator back to strings in tokenizer
This was purposely disabled as it causes a floating point exception immediately on run:

    Program received signal SIGFPE, Arithmetic exception.
    0x000000000056eae8 in std::__detail::_Mod_range_hashing::operator()(unsigned long, unsigned long) const ()
    (gdb) bt
    #0  0x000000000056eae8 in std::__detail::_Mod_range_hashing::operator()(unsigned long, unsigned long) const ()
    #1  0x00000000005bb4f1 in std::__detail::_Hash_code_base<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::pair<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::__detail::_Select1st, std::hash<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::_M_bucket_index(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, unsigned long, unsigned long) const ()
    #2  0x00000000005bb22a in std::_Hashtable<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::pair<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<std::pair<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > >, std::__detail::_Select1st, std::equal_to<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::hash<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_bucket_index(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, unsigned long) const ()
    #3  0x00000000005bb115 in std::__detail::_Map_base<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::pair<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<std::pair<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > >, std::__detail::_Select1st, std::equal_to<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::hash<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true>, true>::operator[](std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) ()
    #4  0x00000000005af388 in std::unordered_map<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::hash<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::equal_to<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<std::pair<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > > > >::operator[](std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) ()
    #5  0x000000000067dc6b in wgettext[abi:cxx11](wchar_t const*) ()
    #6  0x0000000000551df7 in __cxx_global_var_init.1 ()
    #7  0x000000000055225e in _GLOBAL__sub_I_tokenizer.cpp ()
    #8  0x000000000069d45d in __libc_csu_init ()
    #9  0x00007ffffdc907bf in __libc_start_main (main=0x552500 <main>, argc=1, argv=0x7ffffffed298, init=0x69d410 <__libc_csu_init>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffffffed288) at ../csu/libc-start.c:247
    #10 0x0000000000552389 in _start ()
    (gdb)
2018-03-12 12:44:11 -05:00
Mahmoud Al-Qudsi
0f6c763d9e Revert "Restore sanity to line continuations"
This reverts commit 2cdacbdce4.
Our fish scripts need to be audited for compliance before this can be
safely merged. cc @faho
2018-03-12 08:35:09 -05:00
Mahmoud Al-Qudsi
c51abd04ff Clean up $__fish_*dir variable names
Closes #4429
2018-03-12 08:34:20 -05:00
Mahmoud Al-Qudsi
2cdacbdce4 Restore sanity to line continuations
Line continuations (i.e. escaped new lines) now make sense again. With
the smart pipe support (pipes continue on to next line) recently added,
this hack to have continuations ignore comments makes no sense.

This is valid code:

```fish
echo hello |
# comment here
tr -d 'l'
```

this isn't:
```fish
echo hello | \
# comment here
tr -d 'l'
```

Reverts @snnw's 318daaffb2
Closes #2928. Closes #2929.
2018-03-12 08:12:23 -05:00
Mahmoud Al-Qudsi
0b96b516d5 Improve and expand is_whitespace helper functions 2018-03-12 08:06:50 -05:00
Mahmoud Al-Qudsi
857a89e4bd fixup! Fix oob memory access in expand's call to trim() 2018-03-12 07:31:28 -05:00
Mahmoud Al-Qudsi
ee069baf42 Fix oob memory access in expand's call to trim() 2018-03-12 07:22:27 -05:00
Mahmoud Al-Qudsi
4e48b084d7 Remove duplicate trim() call in parameter expansion 2018-03-12 07:20:50 -05:00
Mahmoud Al-Qudsi
d385248cc8 Merge branch 'fix_brace_parsing'
Closes #3802 and improves tokenizer handling of invalid expressions
involving braces, parentheses, and brackets.
2018-03-12 07:05:47 -05:00
Mahmoud Al-Qudsi
24afff1c77 Handle whitespace within parameter expansion tokens
From the discussion in #3802, handling spaces within braces more
gracefully. Leading and trailing whitespace that isn't quoted or escaped
is stripped, whitespace in the middle is preserved. Any whitespace
encountered within expansion tokens is treated as a single space,
similar to how programming languages that don't hard break tokens/quotes
on line endings would.
2018-03-11 22:02:43 -05:00
Mahmoud Al-Qudsi
364115f818 fixup! Properly parse spaces and escaped/quoted spaces in expansion braces 2018-03-11 20:18:21 -05:00
Mahmoud Al-Qudsi
0620cdf711 Fix tokenizer errors for nested, alternating {} and () 2018-03-11 20:18:03 -05:00
Mahmoud Al-Qudsi
1629d339de Properly parse spaces and escaped/quoted spaces in expansion braces 2018-03-11 19:51:54 -05:00
Mahmoud Al-Qudsi
00f95a978e Make { and } valid, first-class tokenizer elements 2018-03-11 19:36:10 -05:00
Mahmoud Al-Qudsi
7447432471 Fix tests for new ) token error 2018-03-11 17:16:53 -05:00
Mahmoud Al-Qudsi
df89d71237 Correct escaping behavior in new tokenizer code 2018-03-11 17:10:16 -05:00
Mahmoud Al-Qudsi
f508a1f274 Reset tokenizer state on start and improve slice error detection 2018-03-11 12:13:55 -05:00
Mahmoud Al-Qudsi
8a7104a0a4 Rename $_/$fish_title to $current_cmd 2018-03-10 21:33:16 -06:00
Mahmoud Al-Qudsi
9ca89fce6a Remove $_ and replace with $fish_title
Not sure about the new name. We've been using $version unprefixed and
now we also have $pid and $last_pid. $title is very generic.
2018-03-10 20:41:47 -06:00
Mahmoud Al-Qudsi
fb1c7a3d68 Simplify token parser 2018-03-10 18:42:56 -06:00
Mahmoud Al-Qudsi
65a03c86cb Rename BRACKET in reference to { to BRACE instead per #3802
This `{` is a curly brace. This `[` is a square bracket.
2018-03-10 13:16:53 -06:00
Mahmoud Al-Qudsi
c98ed6d07a Rename BRACKET to BRACE per #3802 2018-03-10 13:16:07 -06:00
ridiculousfish
9a5afe3913 Clean up and document functions --handlers 2018-03-10 02:27:25 -08:00
Benoit Hamon
3819437e0e add option --handlers to functions to display function hooks 2018-03-10 02:18:46 -08:00
ridiculousfish
7764f27170 Correct failure to set 'filled' flag in maybe_t constructors 2018-03-10 02:17:35 -08:00
Mahmoud Al-Qudsi
d9be55e504 Optimize sort_and_prioritize_completions
Don't continuously shift items in the vector by using std::remove_if
instead, followed by a single call to ->erase().
2018-03-09 21:40:03 -06:00
Mahmoud Al-Qudsi
a756049dac Implement $hostname variable
The value is not electrified or tied and is read-only. It isn't cached
in the get_hostname_identifier() function as the ENV_GLOBAL $hostname
will cache it for its duration.
2018-03-09 15:02:32 -06:00
Mahmoud Al-Qudsi
ed9c0a7f82 Unify gethostname() behavior across different versions of libc
The behavior of `gethostname` in case of an insufficient buffer is
library and version dependent. Work around this by using a big enough
buffer then truncating the output to our desired max length.
2018-03-09 14:52:29 -06:00
Mahmoud Al-Qudsi
a991fd5a1a Add wcstringutil.h truncate function 2018-03-09 14:52:12 -06:00
Mahmoud Al-Qudsi
1fbf810946 Unify ellipsis_str[ing] with common variable set once 2018-03-09 14:40:35 -06:00
Mahmoud Al-Qudsi
3314135cc9 Move fixed test outside of input_mapping_is_match loop
The 0th index of the array was tested inside the loop instead of just
once outside it.

Also explain `input_mapping_is_match` control code behavior and
reasoning and simplify control flow.
2018-03-09 14:11:43 -06:00
Mahmoud Al-Qudsi
86362e72fe Emit deprecation error when read -i is used for --silent 2018-03-09 11:48:51 -06:00
Mahmoud Al-Qudsi
db8ec59ac4 Change read to use -s/--silent and -S/--shell
Closes #4490
2018-03-09 11:48:20 -06:00
Mahmoud Al-Qudsi
0866653a87 Merge branch 'no_percent'
Drops the % notation for process expansion. The existing notation was a
mess and expanded jobs, process ids, and process names via dark magic.
With this change, % is no longer a special character and can be used
unescaped with impunity.

The variables %self and %last, referring to fish's own pid and the pid
of the last backgrounded job respectively, have been replaced with $pid
and $last_pid. These are read-only variables, protected against being
redefined by the user.

Author's note: I would have personally preferred $fish_pid instead of
$pid but since we debated changing $version to $fish_version and then
reverted that change (with much acrimony), it makes no sense to break
with that precedent here. Additionally, $fish_last_pid is quite wordy.

Closes #4230. Closes #1202.
2018-03-09 09:16:31 -06:00
Mahmoud Al-Qudsi
26cc112096 Implement $last_pid, taking the place of %last
Set as a global variable upon the execution of a background job.
2018-03-09 08:56:13 -06:00
Mahmoud Al-Qudsi
f7e0cbc7a4 Drop % test for illegal commands
% is perfectly valid in commands, now :)
2018-03-09 04:02:29 -06:00
Mahmoud Al-Qudsi
b236ab6e5d Update %self references with $pid instead 2018-03-09 03:56:19 -06:00
Mahmoud Al-Qudsi
90d0f91bcd Define read-only $pid as %self replacement 2018-03-09 03:47:32 -06:00
Mahmoud Al-Qudsi
f42f7b7208 Clean up detritus of process expansion 2018-03-09 03:39:53 -06:00
Mahmoud Al-Qudsi
e45e2bf20e Initial removal of '%' syntax for process/job expansion 2018-03-09 03:36:10 -06:00
Fabian Homborg
2d08b5ee8a [math] Add tests for runtime errors
And fix "isinfinite" - it's called "isinf".
2018-03-07 18:13:26 +01:00
Fabian Homborg
9fc3d1215b [math] Check for runtime errors
When number is infinite, not a number, larger than LONG_MAX or smaller
than LONG_MIN, print a corresponding error and return STATUS_CMD_ERROR.

This should fix the worst of the problems, by at least making them clear.

Fixes #4479.
Fixes #4768.
2018-03-07 18:03:44 +01:00
Fabian Homborg
98d29b53de Refresh winsize before printing prompt
This allows prompts to react to $COLUMNS by e.g. omitting some parts.

We still fallback to a ">" prompt if that's still not short enough,
but now the user has a way of making a nicer prompt.

Fixes #904.
Fixes #4381.
2018-03-07 17:46:48 +01:00
Mahmoud Al-Qudsi
4414d5c888 Block custom/user completions for all invalid heads
If the head is not a valid, existent command, do not load and run custom
completion sources. This applies to both the autosuggestion provider and
manual user completions. File-based completions will still be offered.

Supersedes #4782 and #4783. Closes #4783. Closes #4782. Closes #2365.
2018-03-06 12:52:42 -06:00
Mahmoud Al-Qudsi
3c895c2839 Add whitespace helpers to complete.h/cpp 2018-03-06 12:52:42 -06:00
ridiculousfish
3b2de931cd Simplify tokenize_variable_array() 2018-03-05 22:05:05 -08:00
ridiculousfish
37e748ad54 Remove an unused type 2018-03-05 21:58:22 -08:00
ridiculousfish
c7f16439bf Add support for ! as an analog to 'not'
! and not are effectively interchangeable now.
Mark them both as operators for syntax highlighting.
2018-03-05 14:04:49 -08:00
ridiculousfish
f83742d579 Highlight && and || as operators
This also switches 'and' and 'or' to operators as well.
2018-03-05 13:51:05 -08:00
ridiculousfish
357d3b8c6d Rework 'and' and 'or' to be "job decorators"
This promotes "and" and "or" from a type of statement to "job
decorators," as a possible prefix on a job. The point is to rationalize
how they interact with && and ||.

In the new world 'and' and 'or' apply to a entire job conjunction, i.e.
they have "lower precedence." Example:

if [ $age -ge 0 ] && [ $age -le 18 ]
   or [ $age -ge 75 ] && [ $age -le 100 ]
   echo "Child or senior"
end
2018-03-05 13:41:36 -08:00
ridiculousfish
e1dafeab01 Add && and || support to the conditions of if and while
This updates the "boolean tail" feature of the if and while conditions
to know about job_conjunction, thereby respecting && and ||
2018-03-05 13:39:36 -08:00
ridiculousfish
8e9670ccd5 Implement execution of && and ||
This adds support for basic constructs. if and while is not yet
supported.
2018-03-05 12:20:56 -08:00
ridiculousfish
23d4f93556 Add && and || to fish grammar
This teaches the parser about && and ||, implemented via a new
production "job_conjunction".

These do not yet have execution support.
2018-03-05 12:20:56 -08:00
ridiculousfish
8ded041352 Add && and || support to tokenizer 2018-03-05 12:20:56 -08:00
ridiculousfish
a5dd96558f Remove special && and || error detection
Soon these will no longer be errors.
2018-03-05 12:20:56 -08:00
Mahmoud Al-Qudsi
2f2a221c56 Don't spawn keepalive for WSL when only one command
This should speed things up on slower PCs given that the vast majority
of shell commands are simple jobs consisting of a single command without
any pipelines, in which case there's no need for a keepalive process at
all. Applies to WSL only.
2018-03-04 21:54:12 -06:00
Mahmoud Al-Qudsi
000892e315 Use constexpr for is_windows_subsystem_for_linux()
To guarantee that at runtime there will be no branching, using a CMAKE
test/define combined with a constexpr wrapper for code-friendliness.
2018-03-04 21:13:31 -06:00
Mahmoud Al-Qudsi
cf8850a33f Add temporary fix for #4778 (background processes on WSL)
As a temporary workaround for the behavior described in
Microsoft/WSL#2997 wherein WSL does not correctly assign the spawned
child its own PID as its PGID, explicitly set the PGID for the newly
spawned process.
2018-03-04 20:18:38 -06:00
Mahmoud Al-Qudsi
912dbd85d8 Sprinkle in some job control asserts 2018-03-04 20:17:26 -06:00
Mahmoud Al-Qudsi
6814f29cd7 Add a -/--quiet option to jobs for silent evaluation 2018-03-04 15:20:14 -06:00
Fabian Homborg
0da8022081 [math] Fail without arguments
See #4768.
2018-03-01 22:27:24 +01:00
ridiculousfish
b49e1d7703 Minor cleanup
Mark a function as static and use a std::string instead of malloc.
2018-03-01 21:35:49 +01:00
Fabian Homborg
84043e425d [math] Keep LC_NUMERIC=C for output as well
Otherwise, we'd have issues with people putting math's output back
into math because of "," vs ".".
2018-03-01 13:09:35 +01:00
Fabian Homborg
642a1db4fc [math] Add two error strings as fallback 2018-03-01 13:09:35 +01:00
Fabian Homborg
f60e1549a9 [math] Better error for 2 + 2 4
This now reports "TOO_MANY_ARGS" instead of no error (and triggering
an assertion).

We might want to add a new error type or report the missing operator
before, but this is okay for now.
2018-03-01 13:09:35 +01:00
Fabian Homborg
6a38eb4f7d [math] Better error for 2 -
Instead of the catch-all, report too few arguments.
2018-03-01 13:09:35 +01:00
Fabian Homborg
0d9123ec91 [math] Return STATUS_CMD_ERROR when an error occured 2018-03-01 13:09:35 +01:00
Fabian Homborg
d90d0ee08e [tinyexpr] Let specific errors take precedence over generic ones
Fixes the case where `sin()` reported the generic "bogus" error
instead of "too few arguments".

Also rename the constant to "TE_ERROR_UNKNOWN".
2018-03-01 13:09:35 +01:00
Fabian Homborg
4f39cc4d82 [tinyexpr] Remove closures
These are only available as a customization point. Since we don't use
that, it's dead code.
2018-03-01 13:09:35 +01:00
Fabian Homborg
4f56ce6d33 [math] Improve error formatting
This looked like

    math: Error in expression
    'sin(5,4)'
          ^
    Too many arguments

Now it looks like

    math: Too many arguments
    'sin(5,4)'
          ^
2018-03-01 13:09:35 +01:00
Fabian Homborg
0fa0b620b3 [tinyexpr] Remove list()
This just read comma-separated expressions and returned the last of
them, which is useless and confusing.
2018-03-01 13:09:35 +01:00
Fabian Homborg
ea2934e644 [tinyexpr] Make unary functions fail with too many arguments
As it turns out, this was, for some reason, actual wanted behavior.

We _don't_ want it, so just remove the code.
2018-03-01 13:09:35 +01:00
Fabian Homborg
7b9c75094c [tinyexpr] Add error handling
This turns a bunch of ifs on their heads.

We often see this pattern in te:

```c
if (s->type != SOME_TYPE) {
   // error handling
}  else {
   // normal code
}
```

Only, since we want to return the first error, we do

```c
if (s->type == SOME_TYPE) {
    // normal code
} else if (s->type != TOK_ERROR) {
    // Add a new error - if it already has type error
    // this should already be handled.
}
```

One big issue is the comma operator, that means arity-1 functions can
take an arbitrary number of arguments. E.g.

```fish
math "sin(5,9)"
```

will return the value of sin for _9_, since this is read as "5 COMMA
9".
2018-03-01 13:09:35 +01:00
Fabian Homborg
b9a3938a2b [tinyexpr] Add change notice 2018-03-01 13:09:35 +01:00
Fabian Homborg
2ab1466c8f [tinyexpr] Remove #ifdefs
We don't use them, so we don't need them.
2018-03-01 13:09:35 +01:00
Fabian Homborg
ce28891c76 [math] Set LC_NUMERIC to C
This allows us to always use "." as radix character, so e.g.

    math 2.5 - 2

is always valid, regardless of locale.
2018-03-01 13:09:35 +01:00
Fabian Homborg
b75c3b968c Replace muparser with tinyexpr 2018-03-01 13:09:35 +01:00
ridiculousfish
bb7b649132 Wrapping completions to allow injecting arguments
This enables some limited use of arguments for wrapping completions. The
simplest example is that complete gco -w 'git checkout' now works like
you would want: `gco <tab>` now invokes git's completions with the
`checkout` argument prepended.

Fixes #1976
2018-02-27 14:12:44 -08:00
Fabian Homborg
c793570f2c Fix punctuation movement with one char tokens
Previously, in

    ls ^a bcd

(with "^" as the cursor), kill-word would delete the "a" and then go
on, remove the space and the "bcd".

With this, it will only kill the "a".

Fixes #4747.
2018-02-27 22:56:15 +01:00
ridiculousfish
5282d3e711 Add fish_emoji_width variable to control computed emoji width
This is part of an effort to improve fish's Unicode handling. This commit
attempts to grapple with the fact that, certain characters (principally
emoji) were considered to have a wcwidth of 1 in Unicode 8, but a width of
2 in Unicode 9.

The system wcwidth() here cannot be trusted; terminal emulators do not
respect it. iTerm2 even allows this to be set in preferences.

This commit introduces a new function is_width_2_in_Uni9_but_1_in_Uni8() to
detect characters of version-ambiguous width. For these characters, it
returns a width guessed based on the value of TERM_PROGRAM and
TERM_VERSION, defaulting to 1. This value can be overridden by setting the
value of a new variable fish_emoji_width (presumably either to 1 or 2).

Fixes #4539, #2652.
2018-02-25 23:38:10 -08:00
ridiculousfish
7bd4af51a1 Switch to Unicode 9 savvy wcwidth
Previously fish used the venerable wcwidth implementation from Markus Kuhn.
This switches to wcwidth9() from https://github.com/joshuarubin/wcwidth9
2018-02-25 23:12:37 -08:00