Commit Graph

2183 Commits

Author SHA1 Message Date
Aaron Gyes
74a22ff426 wcsfilecmp: punctuation [\]^_` after A-Z.
This tweaks wcsfilecmp such that certain punctuation characters will
come after A-Z.

A big win with `set <TAB>` - the __prefixed fish junk now comes
after the stuff users should care about.
2019-03-16 01:18:16 -07:00
ridiculousfish
88d20e257b Remove some unused variables 2019-03-15 20:21:05 -07:00
Fabian Homborg
864bb1f7a6 Add string-replace-fewer-backslashes feature
This disables an extra round of escaping in the `string replace -r`
replacement string.

Currently, to add a backslash to an a or b (to "escape" it):

    string replace -ra '([ab])' '\\\\\\\$1' a

7 backslashes!

This removes one of the layers, so now 3 or 4 works (each one escaped
for the single-quotes, so pcre receives two, which it reads as one literal):

    string replace -ra '([ab])' '\\\\$1' a

This is backwards-incompatible as replacement strings will change
meaning, so we put it behind a feature flag.

The name is kinda crappy, though.

Fixes #5474.
2019-03-15 15:18:19 +01:00
Fabian Homborg
e7a964fdfa [count] Allow counting lines from stdin
As a simple replacement for `wc -l`.

This counts both lines on stdin _and_ arguments.

So if "file" has three lines, then `count a b c < file` will print 6.

And since it counts newlines, like wc, `echo -n foo | count` prints 0.
2019-03-15 14:31:36 +01:00
Aaron Gyes
cb36a9ca36 builtin.cpp: ensure builtin_get_desc returns something initialized 2019-03-14 21:45:31 -07:00
Aaron Gyes
9a5022514f builtin_argparse: use std::swap 2019-03-14 16:47:23 -07:00
Aaron Gyes
d837eee09d remove some wcstring -> wchar_t* -> wcstring conversions
Mostly related to usage _(L"foo"), keeping in mind the _
macro does a wcstring().c_str() already.

And a smattering of other trivial micro-optimizations certain
to not help tangibly.
2019-03-14 15:21:08 -07:00
Aaron Gyes
477b2e8d7c std::vector<wcstring> is wcstring_list_t 2019-03-14 11:17:26 -07:00
Aaron Gyes
0ee9862809 Write out backtrace in one debug(), add \n after it.
The goal here is to make fish -dn -Dn output a little easier
to scan visually.
2019-03-14 10:56:24 -07:00
Aaron Gyes
cf570d4b11 fixup previous commit 2019-03-14 10:37:13 -07:00
Aaron Gyes
2636876472 simplify append_yaml_to_buffer 2019-03-14 10:29:16 -07:00
Aaron Gyes
2bf554ae5e Simplify valid_var_name 2019-03-14 10:29:16 -07:00
Fabian Homborg
f798a02a2a Remove unused variable 2019-03-14 13:23:47 +01:00
Aaron Gyes
6fc542dfca Revert "simplify append_yaml_to_buffer"
This reverts commit f0998fed6a.
2019-03-13 14:05:23 -07:00
Aaron Gyes
f0998fed6a simplify append_yaml_to_buffer 2019-03-13 13:52:11 -07:00
Aaron Gyes
b879a2650c Fix 32-bit build
Fixes #5740
2019-03-13 07:44:05 -07:00
Fabian Homborg
05b9c07816 wcwidth: Return 0 for median/final jamo
Fixes #5729.
2019-03-13 12:39:08 +01:00
Fabian Homborg
5a9d153363 input: Use range-for
Also adds a couple of consts.
2019-03-13 12:39:08 +01:00
Aaron Gyes
f92c2921d2 Remove mini() and maxi()
C++11 provides std::min/std::max which we're using all over,
obviating the need for our own templates for this.

util.h now only provides two things: get_time and wcsfilecmp.
This commit removes everything that includes it which doesn't
use either; most because they no longer need mini or maxi from
it but some others were #including it unnecessarily.
2019-03-12 23:25:15 -07:00
Fabian Homborg
b318ab17d2 wcwidth: Classify some Hangul Jamo as combiners
Hangul uses three codepoints to combine to one glyph. The first has a
width of 2 (like the final glyph), but the second and third were
assigned a width of 1, which seems to match EastAsianWidth.txt:

> 1160..11FF;N # Lo [160] HANGUL JUNGSEONG FILLER..HANGUL JONGSEONG SSANGNIEUN

Instead, we override that and treat the middle and end codepoint as combiners,
always, because there's no way to figure out what the terminal will
think and that's the way it's supposed to work.

If they stand by themselves or in another combination, they'll indeed
show up with a width of 1 so we'll get it wrong, but that's less
likely and not expressible with wcwidth().

Fixes #5729.
2019-03-12 23:42:50 +01:00
Aaron Gyes
2e4948e1f4 Fix switch nesting in handler_matches
I guess this worked, but whoops.
2019-03-12 15:27:13 -07:00
Aaron Gyes
b7c069a765 Remove two duplicated #includes 2019-03-12 15:09:36 -07:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
Fabian Homborg
ecfe4acd0c complete: Do fuzzy match for --do-complete
This only did prefix matching, which is generally less useful.

All existing users _should_ be okay with this since they want to
provide completions.

Fixes #5467.
Fixes #2318.
2019-03-12 20:27:20 +01:00
Aaron Gyes
66887ca4bc Fix OpenSUSE build
They treat -Wreturn-type as a critical thing apparently.
2019-03-12 09:45:39 -07:00
Aaron Gyes
2ae6e5a585 Explicitly handle all enum values in more switch statements
This addresses a few places where -Wswitch-enum showed one or two missing
case's for enum values.

It did uncover and fix one apparent oversight:

$ function asd -p 100
   echo foo
end

$ functions --handlers-type exit
Event exit
asd

It looks like this should be showing a PID before 'asd' just like
job_exit handlers show the job id. It was falling
through to default: which just printed the function name.

$ functions --handlers-type exit
Event exit
100 asd
2019-03-11 15:02:18 -07:00
Fabian Homborg
1cd5b2f4e1 Pass string length instead of recomputing
This called `writestr(char*)`, which then just called `writestr(char*,
strlen(char*))`, when it had the string length right there!
2019-03-07 10:04:18 +01:00
Fabian Homborg
2b0b3d3193 Outputter_t: Handle C locale like everything else
This tried to skip conversion if the locale had MB_CUR_MAX == 1, but
in doing so it just entered an infinite recursion (because
writestr(wchar_t*) called writestr(wchar_t*)).

Instead, just let wcstombs handle it.

Fixes #5724.
2019-03-07 10:04:18 +01:00
Fabian Homborg
c633c06e11 Guess emoji width via system wcwidth
Since Unicode 9, the width of some characters changed to 2.

Depending on the system, it might have support for it, or it might
not.

Instead of hardcoding specific glibc etc versions, we check what the
system wcwidth says to "😃", U+1F603 "Grinning Face With Big Eyes".

The intention is to, in most cases, make setting $fish_emoji_width
unnecessary, but since it sets the "guessed_emoji_width", that variable still takes precedence if it is set.

Unfortunately this approach has some caveats:

- It relies on the locale being set to a unicode-supporting one.
  (C.UTF-8 is unfortunately not standard, so we can't use it)
- It relies on the terminal's wcwidth having unicode9 support IFF the
  system wcwidth does.

This is like #5722, but at runtime.

The additional caveat is that we don't try to achieve a unicode
locale, but since we re-run the heuristic when the locale changes (and
we try to get a unicode locale), we should still often get the correct
value.

Plus if you use a C locale and your terminal still displays emoji,
you've misconfigured your system.

Fixes #5722.
2019-03-06 22:27:21 +01:00
David Adam
b443808452 event.cpp: die if invalid event type passed
Fixes the build with -Wreturn-type.
2019-03-05 07:27:56 +08:00
ridiculousfish
89a7cc5da3 Switch s_write to accepting const vector & instead of raw pointers 2019-03-03 18:49:57 -08:00
ridiculousfish
ccbc9d57f2 Remove reader_data_t::next
It's no longer used
2019-03-03 18:14:41 -08:00
ridiculousfish
9b9c1aa745 Fix some unused variable warnings 2019-03-03 18:06:31 -08:00
ridiculousfish
717ac9a8d5 Switch highlight_spec_t to a struct
Rather than a janky bitmask, use a real struct with real fields.
2019-03-03 18:04:22 -08:00
ridiculousfish
d165d1df27 Remove highlight_modifier_sloppy_background
It's no longer ever set
2019-03-03 17:56:08 -08:00
ridiculousfish
43a11af5e4 Reorganize reader.cpp to separate te current_data users from reader_data_t 2019-03-03 15:49:56 -08:00
ridiculousfish
c09544b288 Migrate more functions to instance methods on reader_data_t 2019-03-03 15:10:47 -08:00
ridiculousfish
29db076f4a exec_prompt to be an instance method on reader_data_t 2019-03-03 14:38:53 -08:00
ridiculousfish
7ff4b5e5fe Switch highlighting to instance methods on reader_data_t 2019-03-03 14:34:52 -08:00
ridiculousfish
e477b99a8b Switch more autosuggestions to instance methods on reader_data_t 2019-03-03 14:30:32 -08:00
ridiculousfish
b014c327a2 reader_data_t to become enable_shared_from_this
For background operations such as autosuggestions, we need a way for the
completion handler to keep the reader_data alive.
2019-03-03 14:21:15 -08:00
ridiculousfish
c334a41f96 Switch accept_autosuggestion to an instance method on reader_data_t 2019-03-03 14:11:09 -08:00
ridiculousfish
d7a156e7d9 Switch clear_pager to an instance method on reader_data_t 2019-03-03 14:09:23 -08:00
ridiculousfish
164c5b1c18 Migrate a lot of free functions in reader into reader_data_t 2019-03-03 14:02:27 -08:00
ridiculousfish
ecf51b575e Clean up input initialization and destruction 2019-03-03 12:59:55 -08:00
ridiculousfish
dc1073f905 reader_set_buffer_maintaining_pager to take reader_data directly 2019-03-03 12:19:46 -08:00
ridiculousfish
0bc08c6197 highlight_search to take reader_data directly 2019-03-03 12:11:32 -08:00
ridiculousfish
b07345ed18 set_command_line_and_position to take reader_data directly 2019-03-03 12:07:51 -08:00
ridiculousfish
968152ddc7 clear_pager to accept reader_data directly 2019-03-03 12:00:09 -08:00
ridiculousfish
e11c3f352f Clean up handle_child_status
Now that we only call waitpid() on specific processes, we no longer need
to search to find the process returned by waitpid.
2019-03-03 11:47:32 -08:00
ridiculousfish
dac5d79059 Switch wait command to use topics
Prior to this fix, the wait command used waitpid() directly. Switch it to
calling process_mark_finished_children() along with the rest of the job
machinery. This centralizes the waitpid call to a single location.
2019-03-02 16:58:27 -08:00
ridiculousfish
dc27de8190 Rename reader_interrupted to reader_test_and_clear_interrupted 2019-03-02 15:17:00 -08:00
ridiculousfish
1a4bb50cd5 Combine status and pipestatus into statuses_t
In most places where we set one, we want to set both. Make this less
error-prone by combining them into a single type statuses_t.
2019-02-26 20:07:37 -08:00
Fabian Homborg
47ff060b89 string: Fix split0 return status
It turns out that `string split0` didn't actually ever do any
splitting. The arg_iterator_t already split stdin on NUL, and split0 just
performed an additional search that could never succeed (since
arguments from argv already can't contain NUL).

Let the arg_iterator_t not perform any splitting if asked, and then
let split0 split in 0.

One slight wart is that split0 ignores a trailing NUL, which normal
split doesn't.

Fixes #5701.
2019-02-26 20:03:40 +01:00
Fabian Homborg
c66015c2c1 Readd tparm unconst-cast
Fixes the build on NetBSD.

CC @ridiculousfish.
2019-02-25 22:17:56 +01:00
Fabian Homborg
92b1f4df07 Include wait.h in proc.h, not proc.cpp
Should fix the build in FreeBSD - https://builds.sr.ht/~faho/job/33304.
2019-02-25 22:12:09 +01:00
Fabian Homborg
2418e1e50b Don't mix up pgroup and pid
This is another case where we used pid when we meant pgroup.

Since 55b3c45f95, the assumption that
both are the same no longer holds in all cases, so this check was wrong.

Might fix #5663.
2019-02-25 20:23:34 +01:00
zabereer
a5659132f6 Compilation error on gcc8.2.1 2019-02-25 20:19:52 +01:00
ridiculousfish
bb36274e6b Introduce proc_status_t
In fish we play fast and loose with status codes as set directly (e.g. on
failed redirections), vs status codes returned from waitpid(), versus the
value $status. Introduce a new value type proc_status_t to encapsulate
this logic.
2019-02-25 10:14:45 -08:00
ridiculousfish
24efa45e3e Remove an unused variable 2019-02-25 09:01:48 -08:00
ridiculousfish
2c3214cabd Make $pipestatus thread safe and other misc cleanup 2019-02-24 23:29:33 -08:00
zabereer
2c8abdf5cb add $pipestatus support 2019-02-24 21:46:52 -08:00
Janczar Kurek
efa88b171a prettify_node function now does not use recursion
prettify_node_recursive is replaced with prettify_node_nrecursive
explicite stack is used instead.

Signed-off-by: Janczar Kurek <janczar.kurek@student.uj.edu.pl>
2019-02-24 21:01:45 -08:00
ridiculousfish
31dc1f9a8c Correct the builtin.cpp comment about how to add a new builtin
Teach it about Sphinx
2019-02-24 19:41:51 -08:00
ridiculousfish
0a29eb3142 reader_readline to return maybe_t<wcstring>
Stop returning a raw pointer.
2019-02-24 14:00:22 -08:00
ridiculousfish
47f1b026e6 Simplify reader generation count using thread_local
Replaces pthread_set_specific
2019-02-24 13:39:43 -08:00
ridiculousfish
4b292c777d Clean up and clarify reader_exit() 2019-02-24 13:24:03 -08:00
ridiculousfish
144e37b8ba Remove some empty code 2019-02-24 13:14:36 -08:00
ridiculousfish
a81bfbb805 Rename end_loop to noni_end_loop
This helps distinguish between the global (noni_)end_loop and the reader
specific one.
2019-02-24 12:20:20 -08:00
ridiculousfish
815e20066b parser_t to become enable_shared_from_this 2019-02-24 12:12:24 -08:00
ridiculousfish
5134949a14 Factor color and terminal sequence outputting into outputter_t
Removes some static variables and simplifies the behavior of the tputs
singletone receiver.
2019-02-23 20:07:29 -08:00
ridiculousfish
9715db9434 Fix a "no return value" warning 2019-02-23 14:09:17 -08:00
ridiculousfish
130f2266d0 Remove the last of the signal blocking and checks
fish's signal handlers are now sufficiently innocuous that there should
be no reason to block signals (outside of temporarily, when creating a
thread and we need to manipulate the signal mask).
2019-02-23 14:07:35 -08:00
ridiculousfish
ec65ba3427 Remove signal_block_t
Bravely removing more signal blocks, now that our signal handling is so
simple.
2019-02-23 13:48:16 -08:00
ridiculousfish
0ff4046b8c Remove signal blocks from terminal_return_from_job
There's nothing justifying having these here.
2019-02-23 13:45:26 -08:00
ridiculousfish
f1b208997c Cleanup events
Prior to this fix, an "event" was used as both a predicate on which events
to match, and also as the event itself. Re-express these concepts
distinctly: an event is something that happened, an event_handler is the
predicate and name of the function to execute.
2019-02-23 13:33:12 -08:00
ridiculousfish
780b53ba73 Convert event_type_t to an enum class 2019-02-23 13:17:28 -08:00
ridiculousfish
1b8ddacfed Reimplement signal handling event machinery
Prior to this fix, fish had a signal_list_t that accumulated signals.
Signals were added to an array of integers, with an overflow flag.
The event machinery would attempt to atomically "swap in" the other list.

After this fix, there is a single list of pending signal events, as an array
of atomic booleans. The signal handler sets the boolean corresponding to its
signal.
2019-02-23 13:03:33 -08:00
ridiculousfish
003998c921 Event blocks just block all events
In a galaxy far, far away, event_blockage_t was intended to block only cetain
events. But it always just blocked everything. Eliminate the event block
mask.
2019-02-23 13:02:07 -08:00
ridiculousfish
0f30f05e16 Remove EVENT_ANY_SIGNAL
This appeared to have been intended to allow functions to handle all signals,
but this has not been exposed and it doesn't seem useful.
2019-02-23 12:19:59 -08:00
ridiculousfish
6bddf2c83b Add basic signal test 2019-02-23 11:57:19 -08:00
ridiculousfish
da04f757f9 Minor cleanup to process_clean_after_marking 2019-02-22 22:50:52 -08:00
ridiculousfish
38d86acbc3 Fix s_var_dispatch_table initialization
It has to be declared after the variables it uses.
2019-02-20 16:33:54 -08:00
George Christou
de0b64409c Teach autosuggestions to respect forward-bigword
Closes #5336
2019-02-20 16:06:38 -08:00
ridiculousfish
75e83cac29 pwd short_options to be const 2019-02-20 16:06:05 -08:00
ridiculousfish
13b2ff336d Make var_dispatch_table const 2019-02-20 16:06:05 -08:00
Aaron Gyes
11a1403219 Remove extra semicolons 2019-02-19 16:50:58 -08:00
Aaron Gyes
6aa2f29901 Don't increase the width for variation selector 15.
See discussion in #5668 and #5583
2019-02-19 04:27:17 -08:00
Fabian Homborg
38f37b7abc commandline: Remove stray "w" short option
Fun fact: `commandline -w` hits an assert and crashes.
2019-02-19 11:02:58 +01:00
Aaron Gyes
6fa8b028fc fish_tests.cpp: fixup: I didn't notice the comma here. 2019-02-18 23:19:57 -08:00
Aaron Gyes
c2bc0c67f2 Don't use printf("%d") just to convert an int to a string.
std::to_string, std::to_wstring are more appropriate
2019-02-18 23:15:54 -08:00
ridiculousfish
59cb2d02a8 Only inherit a PWD if it resolves to "."
Fixes #5647
2019-02-18 13:20:40 -08:00
Fabian Homborg
11009de431 Revert "Explicitly close input fd to fish_title"
This reverts commit b247c8d9ad.

It breaks the title entirely.

[ci skip]
2019-02-18 15:04:01 +01:00
Fabian Homborg
7958e1d5c4 fish_tests: s/rand()/random()/g
As it turns out, NetBSD's rand(3) is awful - it's possible that in any
given run it'll only return odd numbers, which means

    while (rand() % 10)

will never stop.

Since random(3) is also standardized and works, let's use that!
2019-02-18 14:46:11 +01:00
ridiculousfish
0b3eca1743 Cleanup handle_builtin_output
Now that we use an internal process to perform builtin output, simplify the
logic around how it is performed. In particular we no longer have to be
careful about async-safe functions since we do not fork.

Also fix a bunch of comments that no longer apply.
2019-02-17 14:17:44 -08:00
ridiculousfish
4a2fd443b2 Use internal processes to write builtin output
This uses the new internal process mechanism to write output for builtins.
After this the only reason fish ever forks is to execute external processes.
2019-02-17 13:08:00 -08:00
ridiculousfish
ada8ea954e Use "internal" processes to write buffered output
This introduces "internal processes" which are backed by a pthread instead
of a normal process. Internal processes are reaped using the topic
machinery, plugging in neatly alongside the sigchld topic; this means that
process_mark_finished_children() can wait for internal and external
processes simultaneously.

Initially internal processes replace the forked process that fish uses to
write out the output of blocks and functions.
2019-02-17 13:05:20 -08:00
ridiculousfish
061f8f49c6 Add dup2_list_t::fd_for_target_fd
This adds an "in-process" interpretation of dup2s, allowing for fish to
output directly to the correct file descriptor without having to perform
an in-kernel dup2 sequence.
2019-02-17 13:01:59 -08:00
ridiculousfish
ebe2dc2766 Processes to record topic generations before execution
The sigchld generation expresses the idea that, if we receive a sigchld
signal, the generation will be different than when we last recorded it. A
process cannot exit before it has launched, so check the generation count
before process launch. This is an optimization that reduces failing
waitpid calls.
2019-02-17 13:01:59 -08:00
ridiculousfish
a95bc849c5 Rewrite process_mark_finished_children using topics
This is a big change to how process reaping works, reimplenting it using
topics. The idea is to simplify the logic in
process_mark_finished_children around blocking, and also prepare for
"internal processes" which do not correspond to real processes.

Before this change, fish would use waitpid() to wait for a process group,
OR would individually poll processes if the process group leader was
unreapable.

After this change, fish no longer ever calls blocking waitpid(). Instead
fish uses the topic mechanism. For each reapable process, fish checks if
it has received a SIGCHLD since last poll; if not it waits until the next
SIGCHLD, and then polls them all.
2019-02-17 13:01:59 -08:00
ridiculousfish
a4dc04a28e Add sighupint topic
This corresponds to SIGHUP and SIGINT. This will be used to break out of
process_mark_finished_children().
2019-02-17 13:01:59 -08:00
ridiculousfish
fc9d238642 Introduce topic monitoring
topic_monitor allows for querying changes posted to one or more topics,
initially sigchld. This will eventually replace the waitpid logic in
process_mark_finished_children().

Comment from the new header:

Topic monitoring support. Topics are conceptually "a thing that can
happen." For example, delivery of a SIGINT, a child process exits, etc. It
is possible to post to a topic, which means that that thing happened.

Associated with each topic is a current generation, which is a 64 bit
value. When you query a topic, you get back a generation. If on the next
query the generation has increased, then it indicates someone posted to
the topic.

For example, if you are monitoring a child process, you can query the
sigchld topic. If it has increased since your last query, it is possible
that your child process has exited.

Topic postings may be coalesced. That is there may be two posts to a given
topic, yet the generation only increases by 1. The only guarantee is that
after a topic post, the current generation value is larger than any value
previously queried.

Tying this all together is the topic_monitor_t. This provides the current
topic generations, and also provides the ability to perform a blocking
wait for any topic to change in a particular topic set. This is the real
power of topics: you can wait for a sigchld signal OR a thread exit.
2019-02-17 13:01:59 -08:00
ridiculousfish
ccc45235b0 Introduce enum_array_t
Allows for indexing an array via an enum class.
2019-02-17 13:01:59 -08:00
ridiculousfish
78ed659151 Fancify enum_set and introduce enum_iter_t
Allow iterating over the values of an enum class.
2019-02-17 13:01:59 -08:00
Fabian Homborg
fdbbe9f69d fish_tests: Initialize some collections
For some reason this'd crash on NetBSD otherwise.
2019-02-16 16:40:13 +01:00
ridiculousfish
b6b7550477 Restyle redirection.h 2019-02-16 02:30:21 -08:00
ridiculousfish
f75fe823b8 Minor cleanup of process_t 2019-02-16 01:20:08 -08:00
Mahmoud Al-Qudsi
828a704282 Fix is_wsl() #ifdef guards on non-Linux platforms 2019-02-14 18:30:10 -06:00
Mahmoud Al-Qudsi
552af31ab0 Emit warning when running under an unsupported version of WSL
Closes #5661. Ping #5298.
2019-02-14 18:21:11 -06:00
Mahmoud Al-Qudsi
9796a331bc Make WSL detection dynamic rather than statically compiled
This resolves the issue where running pre-compiled Linux packages from
binary package manager repositories lead fish to think that we are not
running under WSL.

- Closes #5619.
- Ping neovim/neovim#7330
2019-02-14 18:21:11 -06:00
Fabian Homborg
f037b0f30f fallback: Use passed locale in wcstod_l
Strange idea, but it just might work.
2019-02-14 10:57:38 +01:00
Mahmoud Al-Qudsi
553bf47191 Fix short arg -S for --shell
Closes #5660
2019-02-13 20:55:19 -06:00
Fabian Homborg
4562f8f4e3 fallback: Set LC_ALL in wcstod_l fallback
Apparently some wcstod's don't care about LC_NUMERIC.
2019-02-13 20:32:07 +01:00
Fabian Homborg
c0dc1870f0 io: Return from read even if return == -1 and errno == 0
This happens on OpenIndiana/Solaris/Illumos/SunOS.

Elsewhere we use read_blocked, which already returned in this
case (and which we might want to use here as well!).
2019-02-13 20:15:09 +01:00
Fabian Homborg
556ddfa456 Include stdarg.h again
This is needed on NetBSD, and should be harmless elsewhere.
2019-02-13 14:09:14 +01:00
Fabian Homborg
3e2e44b673 output: One more unconst-cast for tputs
Needed on Solaris/OpenIndiana/Illumos/SunOS.
2019-02-13 13:28:13 +01:00
Fabian Homborg
7508865374 Include string.h where we use memset
This is needed on Solaris/Illumos/OpenIndiana/SunOS.

Presumably it's harmless elsewhere.
2019-02-13 13:27:20 +01:00
Fabian Homborg
ca5b7c0ec4 math: Allow --scale=max 2019-02-13 12:54:58 +01:00
Mrmaxmeier
6e9250425a src/exec: fix assertion on failed exec redirection
Minimal reproducer: `fish -c "exec cat<x"`
2019-02-12 20:52:03 -08:00
Mahmoud Al-Qudsi
b247c8d9ad Explicitly close input fd to fish_title
`fish_title` as invoked by fish itself is not running in an interactive
context, and attempts to read from the input fd (e.g. via `read`) cause
fish to segfault, go into an infinite loop, or hang at the read prompt
depending on the exact command line and fish version.

This patch addresses that by explicitly closing the input fd when
invoking `fish_title`.

Reported by @floam in #5629. May close that issue, but situation is
unclear.
2019-02-12 19:55:20 -06:00
Aaron Gyes
717718353e Remove unused macros 2019-02-12 16:10:18 -08:00
Aaron Gyes
8d9089c78b Revert "io.cpp: use BUFFER_SIZE"
This reverts commit c931e33759.
2019-02-12 15:50:43 -08:00
Aaron Gyes
c931e33759 io.cpp: use BUFFER_SIZE
-Wunused-macros showed that a recent change used 4096 instead of
BUFFER_SIZE as previously (also 4096).
2019-02-12 15:37:09 -08:00
Aaron Gyes
a19206036c output.{h,cpp}: remove unused enum and correct a comment 2019-02-12 13:53:49 -08:00
Fabian Homborg
dc0746bc45 Let command -q work
This required "-sq" to be used and errored if just "-q" was given.

Instead, if only "-q" is given, we behave just as if "-sq" was.
2019-02-12 20:34:19 +01:00
Fabian Homborg
fb7a6e5f34 Add builtin -q
Used to query for a builtin's existence, like `type -q` and `functions
-q` can be used to query for a things and a functions existence respectively.
2019-02-12 20:34:19 +01:00
Aaron Gyes
bbc3fecbeb env.cpp: Simplify update_fish_color_support
Taking advantage of the maybe_t's, the logic and nesting here
can be a bit less intense.

Small adjustments to debug output, and found a more accurate
version number for Lion Terminal.app.

Longer term we should have a terminal_t class or something
encapsulating all the kinds of terminal detection we have
with methods that return the color support, and also stuff
like whether the terminal has the newline glitch, the
ambiguous width character behavior, etc.
2019-02-12 01:37:47 -08:00
Aaron Gyes
634e97a85e Remove unnecessary _NSGetExecutablePath declaration
We do this in common.cpp now, and are including dyld.h anyhow.
2019-02-10 16:47:05 -08:00
Aaron Gyes
038fea1a47 Fix builtin $var expansion
A special case added for #1252 needed adjustment.

Fixes #5639
2019-02-10 14:45:03 -08:00
ridiculousfish
1701e2c558 Revert "add $pipestatus support"
This reverts commit ec290209db.
2019-02-10 13:46:58 -08:00
ridiculousfish
6da9d96241 Revert "Make $pipestatus thread safe and other misc cleanup"
This reverts commit 34c1f24716.
2019-02-10 13:46:49 -08:00
ridiculousfish
34c1f24716 Make $pipestatus thread safe and other misc cleanup 2019-02-10 13:43:02 -08:00
zabereer
ec290209db add $pipestatus support 2019-02-10 13:30:40 -08:00
ridiculousfish
83884c2c13 Improve reliability of signal handling in child processes
fish forks child processes when (for example) writing out builtin output.
After fork it resets signal handlers, but if a signal is delivered before
the signal handlers are reset, it will inherit fish's default handlers,
which do things like swallow SIGINT. Teach fish's default signal handlers
to detect this case and re-raise signals with default handlers.

This improves the reliability of control-C in the face of builtins.
2019-02-10 12:57:54 -08:00
ridiculousfish
28e2cfeb4b Switch signal table lookups to range-based for loops 2019-02-10 12:07:48 -08:00
Aaron Gyes
34fa8ef2d2 Prefer c++11-style [[attr]] syntax over __attribute__ (attr)
Where Clang and GCC both support __attribute__ (attr) and
GCC supports [[gnu::attr]], Clang promises it will support
[[gnu::attr]]
2019-02-10 04:22:40 -08:00
David Adam
662708e72d src/exec: drop unused parameter in can_use_posix_spawn_for_job
Process object is not checked since 084ff64f4f.
2019-02-10 15:57:06 +08:00
Mahmoud Al-Qudsi
a00ef4aa2e Wrap long lines 2019-02-10 00:14:42 -06:00
Aaron Gyes
c1504576f9 redirection.cpp: remove unused error message macro
LOCAL_PIPE_ERROR is no longer used anywhere.
2019-02-09 20:32:13 -08:00
Aaron Gyes
1049bed5f8 string completions: add -e, -f, --no-empty, shorten -d's
I hope this is now complete.

Also, shorten enough descriptions to make `string match --<TAB>`
show a two column pager with 80 cols.

We really should have shown more retraint in the design of `string`,
not all of the flags required both a long and short option created.
2019-02-07 04:13:38 -08:00
Fabian Homborg
7c8b444927 Reduce default escape delay
300ms was waaay too long, and even 100ms wasn't necessary.

Emacs' evil mode uses 10ms (0.01s), so let's stay a tad higher in case
some terminals are slow.

If anyone really wants to be able to type alt+h with escape, let them
raise the timeout.

Fixes #3904.
2019-02-07 12:19:36 +01:00
Fabian Homborg
87e71bcde7 input: Remove useless .c_str
(Also removes some dead code)
2019-02-06 23:48:16 +01:00
ridiculousfish
d4e3f49571 Correct the read_blocked comment 2019-02-05 23:21:47 -08:00
ridiculousfish
26ada583a0 Fix te_expr's flexible array member
te_expr has a flexible array member, but it's declared as size 1.
Stop declaring its size so UBSan stops complaining.

Noted in #2852
2019-02-05 23:03:59 -08:00
Brian Malehorn
6025c28efc Create function to retrieve tmpdir
`/tmp` isn't present / writeable on every system. Instead of always
using `/tmp`, try to use standard environment variables and
configuration to find a temporary directory.

Adapted from #3974, with updates based on those comments.

Closes #3845.
2019-02-05 22:18:51 -08:00
ridiculousfish
2e542d7822 Initialize shutdown_fillthread_ to false
It was left uninitialized which was causing certain command substitutions
to exit too early.

Fixes #5616
2019-02-05 21:44:43 -08:00
David Adam
a042a4cb62 low level tests: set pwd from getcwd before starting
Fixes the tests in Debian pbuilder environments. Closes #5599.
2019-02-06 06:51:33 +08:00
Fabian Homborg
c7656e6622 Remove run_as_keepalive
Dead code, innit?
2019-02-04 17:11:34 +01:00
Fabian Homborg
ddfad001eb Remove unnecessary string copy
This called function_exists_no_autoload with a c_str().

Only that takes a wcstring, so the constructor gets called which
copies that.
2019-02-04 17:10:53 +01:00
Fabian Homborg
9f469e576b tinyexpr: Prevent possible division by zero
This is possibly not actually undefined behavior because IEEE754
defines _more_ of division-by-zero, but let's be careful.

Fixes #2852.
2019-02-04 16:32:53 +01:00
ridiculousfish
d3fa58d621 Cleanup common.h
Remove a bunch of headers, simplify lots of code, migrate it into .cpp files.

Debug build time improves by ~3 seconds on my Mac.
2019-02-03 18:22:38 -08:00
ridiculousfish
6f682c8405 Fill io_buffer via background thread
This is a large change to how io_buffers are filled. The essential problem
comes about with code like (example):

    echo ( /bin/pwd )

The output of /bin/pwd must go to fish, not the tty. To arrange for this,
fish does the following:

1. Invoke pipe() to create a pipe.
2. Add an io_bufferfill_t redirection that owns the write end of the pipe.
3. After fork (or equiv), call dup2() to replace pwd's stdout with this  pipe.

Now when /bin/pwd writes, it will send output to the read end of the pipe.
But who reads it?

Prior to this fix, fish would do the following in a loop:

1. select() on the pipe with a 10 msec timeout
2. waitpid(WNOHANG) on the pwd proc

This polling is ugly and confusing and is what is replaced here.

With this new change, fish now reads from the pipe via a background thread:

1. Spawn a background pthread, which select()s on the pipe's read end with
a long (100 msec) timeout.
2. In the foreground, waitpid() (allowing hanging) on the pwd proc.

The big win here is a major simplification of job_t::continue_job() since
it no longer has to worry about filling buffers. This will make things
easier for concurrent execution.

It may not be obvious why the background thread still needs a poll (100 msec).
The answer is for cases where the write end of the fd escapes, in particular
background processes invoked inside command substitutions. psub is perhaps
the only important case of this (other shells typically just hang here).
2019-02-03 01:58:49 -08:00
ridiculousfish
ec29a5b913 Introduce make_pthread
This allows creating a pthread directly, which can be joined.
iothread_spawn wraps this.
2019-02-03 01:58:49 -08:00
ridiculousfish
178b72b2fd io_buffer_t becomes io_bufferfill_t
This makes some significant architectual improvements to io_pipe_t and
io_buffer_t.

Prior to this fix, io_buffer_t subclassed io_pipe_t. io_buffer_t is now
replaced with a class io_bufferfill_t, which does not subclass pipe.

io_pipe_t no longer remembers both fds. Instead it has an autoclose_fd_t,
so that the file descriptor ownership is clear.
2019-02-03 01:58:49 -08:00
ridiculousfish
084ff64f4f Allow posix_spawn more often
Now that we no longer open files after fork, we can correctly report errors
for failed file opens. So allow posix_spawn even if there's redirections.
2019-02-03 01:58:49 -08:00
ridiculousfish
2742267b9e Use dup2_list_t in posix_spawn
This simplifies the posix_spawn path and unifies it with the fork execution
path.
2019-02-03 01:58:49 -08:00
ridiculousfish
d62576ce22 Adopt dup2_list_t in fork execution path
This switches IO redirections after fork() to use the dup2_list_t,
instead of io_chain_t. This results in simpler code with much simpler
error handling.
2019-02-03 01:58:49 -08:00
ridiculousfish
dbe906b79e Introduce dup2_list_t
This represents a "resolved" io_chain_t, where all of the different io_data_t
types have been reduced to a sequence of dup2() and close(). This will
eliminate a lot of the logic duplication around posix_spawn vs fork, and pave
the way for in-process redirections.
2019-02-03 01:58:49 -08:00
ridiculousfish
e3dcb01e67 Fix travis via a user-declared ctor 2019-02-02 19:13:09 -08:00
ridiculousfish
22d05dc18b Try once more to fix the Travis build 2019-02-02 17:45:21 -08:00
ridiculousfish
6ba0d4c88a Revert io_bufferfill_t stack
This reverts commit 88dc484858 onwards.
2019-02-02 17:53:40 -08:00
ridiculousfish
f4e1d7c97e Satisfy the compiler harder 2019-02-02 17:38:12 -08:00
Fabian Homborg
38b4d47560 Initialize empty_ios emptier
This placates the compiler.

The compiler is pleased.
2019-02-03 00:14:03 +01:00
ridiculousfish
9a4153f5e2 Fill io_buffer via background thread
This is a large change to how io_buffers are filled. The essential problem
comes about with code like (example):

    echo ( /bin/pwd )

The output of /bin/pwd must go to fish, not the tty. To arrange for this,
fish does the following:

1. Invoke pipe() to create a pipe.
2. Add an io_bufferfill_t redirection that owns the write end of the pipe.
3. After fork (or equiv), call dup2() to replace pwd's stdout with this  pipe.

Now when /bin/pwd writes, it will send output to the read end of the pipe.
But who reads it?

Prior to this fix, fish would do the following in a loop:

1. select() on the pipe with a 10 msec timeout
2. waitpid(WNOHANG) on the pwd proc

This polling is ugly and confusing and is what is replaced here.

With this new change, fish now reads from the pipe via a background thread:

1. Spawn a background pthread, which select()s on the pipe's read end with
a long (100 msec) timeout.
2. In the foreground, waitpid() (allowing hanging) on the pwd proc.

The big win here is a major simplification of job_t::continue_job() since
it no longer has to worry about filling buffers. This will make things
easier for concurrent execution.

It may not be obvious why the background thread still needs a poll (100 msec).
The answer is for cases where the write end of the fd escapes, in particular
background processes invoked inside command substitutions. psub is perhaps
the only important case of this (other shells typically just hang here).
2019-02-02 14:21:46 -08:00
ridiculousfish
6e0dd06f43 Introduce make_pthread
This allows creating a pthread directly, which can be joined.
iothread_spawn wraps this.
2019-02-02 14:21:46 -08:00
ridiculousfish
78bbcef356 io_buffer_t becomes io_bufferfill_t
This makes some significant architectual improvements to io_pipe_t and
io_buffer_t.

Prior to this fix, io_buffer_t subclassed io_pipe_t. io_buffer_t is now
replaced with a class io_bufferfill_t, which does not subclass pipe.

io_pipe_t no longer remembers both fds. Instead it has an autoclose_fd_t,
so that the file descriptor ownership is clear.
2019-02-02 14:21:46 -08:00
ridiculousfish
7c256e7e51 Allow posix_spawn more often
Now that we no longer open files after fork, we can correctly report errors
for failed file opens. So allow posix_spawn even if there's redirections.
2019-02-02 14:21:46 -08:00
ridiculousfish
4c0b6a6add Use dup2_list_t in posix_spawn
This simplifies the posix_spawn path and unifies it with the fork execution
path.
2019-02-02 14:21:46 -08:00
ridiculousfish
d895075d9b Adopt dup2_list_t in fork execution path
This switches IO redirections after fork() to use the dup2_list_t,
instead of io_chain_t. This results in simpler code with much simpler
error handling.
2019-02-02 14:21:46 -08:00
ridiculousfish
88dc484858 Introduce dup2_list_t
This represents a "resolved" io_chain_t, where all of the different io_data_t
types have been reduced to a sequence of dup2() and close(). This will
eliminate a lot of the logic duplication around posix_spawn vs fork, and pave
the way for in-process redirections.
2019-02-02 14:21:46 -08:00
Mahmoud Al-Qudsi
b54f1842d5 Switch to wait_by_process when waitpid without WNOHANG returns nothing
By exclusively waiting by pgrp, we can fail to reap processes that
change their own pgrp then either crash or close their fds. If we wind
up in a situation where `waitpid(2)` returns 0 or ECHLD even though we
did not specify `WNOHANG` but we still have unreaped child processes,
wait on them by pid.

Closes #5596.
2019-02-02 16:05:57 -06:00
Fabian Homborg
ff89c61afa functions -q: Return false without an argument
This erroneously listed functions and returned true.
2019-02-01 18:34:45 +01:00
ridiculousfish
b00f039489 Clean up the io_chain_t interface 2019-01-31 18:49:52 -08:00
ridiculousfish
371f67f1b5 Remove pipe_read_fd
In practice it was always STDIN_FILENO.
2019-01-31 17:58:59 -08:00
ridiculousfish
a2aab24db7 Switch io_mode to an enum class 2019-01-31 12:12:46 -08:00
Fabian Homborg
0770fd1f89 src/function.cpp: Fix possible NULL-dereference
UBSan complained, so let's check.
2019-01-31 16:02:02 +01:00
Aaron Gyes
46c967903d env.cpp: swap entries of fallback PATH
I had this backwards. Thanks @mqudsi
2019-01-28 19:28:02 -08:00
Fabian Homborg
ac3d3c399c Quit immediately with R_EOF
If we read an R_EOF, we'd try to match mappings to it.

In emacs mode, that's not an issue because the generic binding was
always available, but in vi-normal mode there is no generic binding,
so we'd endlessly loop, waiting for another character.

Fixes #5528.
2019-01-28 18:12:48 +01:00
Dan Zimmerman
50448e4319 Enable configuring more pager colors
Originally I sought out to configure the foreground color of the
selected text in the pager. After reading a thread on a github issue I
was inpired to do more: now you can conifgure any part of the pager when
selected, and when a row is secondary. More specifically this commit adds the
ability to specify a pager row's:

- Prefix
- Completion text
- Description
- Background

when said row is selected or secondary.
2019-01-26 15:43:23 -08:00
Dan Zimmerman
f73b4fb746 Connect highlight env vars to their specs better
I was hacking on this part of the codebase and found this comment
mentioning to keep two things in sync, and felt like we could do better.
2019-01-26 15:43:23 -08:00
Aaron Gyes
6ef617f8e7 tinyexpr: use math.h constants, constexpr 2019-01-25 17:08:15 -08:00
Aaron Gyes
aafefb2300 Report the guessed/effective emoji width with -d2 on startup
This will print out along with the stuff we've guessed about color
support. We get a lot of bug reports about these messing up rendering,
this is useful diagnostic output.
2019-01-25 13:51:20 -08:00
Aaron Gyes
290d07a833 env.cpp: Better fallback for missing PATH
Ask the system where utilities are available with confstr (POSIX).

This is the same string printed by `getconf PATH`, which likely
includes more directories.
2019-01-24 10:46:16 -08:00
Aaron Gyes
09d0f7741d set_color: don't set color to black before resetting attributes
I was surprised to see:

> set_color normal | string escape
\e\[30m\e\(B\e\[m

I only expected to see a sgr0 here.

Cleanup a nearby `else { if (...) {` and comment with a bogus example.
2019-01-23 13:37:52 -08:00
ridiculousfish
87b7b6b2bb Make control-S begin navigating the pager contents
In addition to showing the search field, actually allow the user to type in
it.
2019-01-22 14:41:13 -08:00
ridiculousfish
91a9c98974 Correctly inherit a virtual PWD
PWD is not set in fish vars because it is read only.
Use getenv() to fetch it, allowing fish to inherit a virtual PWD.

Fixes #5525
2019-01-22 13:34:04 -08:00
Fabian Homborg
82b4d7225c env_get_runtime_path: Check for getpwuid() failure
Otherwise this is a NULL dereference and then crash.

Fixes #5550.
2019-01-22 19:30:04 +01:00
Mahmoud Al-Qudsi
0edaf42d10 Fix regression for #4178 and others introduced by 364c839
...while still keeping intact the fix for #5519.
2019-01-21 20:29:31 -06:00
Mahmoud Al-Qudsi
462cb6044c Use standard __CYGWIN__ define for Cygwin detection 2019-01-21 20:06:16 -06:00
ridiculousfish
3cc581fbb0 Unconditionally set the tty mode in reader_readline
There was a bogus check for is_interactive_session. But if we are in
reader_readline we are necessarily interactive (even if we are not in
an interactive session, i.e. a fish script invoked some interactive
functionality).

Remove this check.

Fixes #5519
2019-01-20 17:36:31 -08:00
ridiculousfish
1680b741b2 Make while loops evaluate to the last executed command status
A while loop now evaluates to the last executed command in the body, or
zero if the loop body is empty. This matches POSIX semantics.

Add a bunch of tricky tests.

See #4982
2019-01-20 16:37:20 -08:00
ridiculousfish
fec10830d3 Correctly handle exited jobs in process_mark_finished_children
This is effectively a pick of 2ebdcf82ee
and the subsequent fixup. However we also avoid setting WNOHANG unless
waitpid() indicates a process was reaped.

Fixes #5438
2019-01-20 15:07:08 -08:00
ridiculousfish
2a190c6f3b exec to only warn on background jobs in interactive sessions
Extension of fix for #5449 in b007248
2019-01-20 13:53:11 -08:00
Fabian Homborg
c66b3128ec Use wcstod_l on NetBSD
It has wcstod_l, but not uselocale, so we can't use the fallback.
2019-01-20 18:35:38 +01:00
ridiculousfish
b1f5cb9bf4 Revert "Revert "Fix unsafe locale usage in wcstod_l fallback""
This reverts commit c15a702f18.

The tests are no longer broken after rerunning CMake.
2019-01-19 13:27:28 -08:00
Fabian Homborg
3847d2e9d1 Also set the read-only flag for non-electric vars
For some reason, we have two places where a variable can be read-only:

- By key in env.cpp:is_read_only(), which is checked via set*

- By flag on the actual env_var_t, which is checked e.g. in
  parse_execution

The latter didn't happen for non-electric variables like hostname,
because they used the default constructor, because they were
constructed via operator[] (or some such C++-iness).

This caused for-loops to crash on an assert if they used a
non-electric read-only var like $hostname or $SHLVL.

Instead, we explicitly set the flag.

We might want to remove one of the two read-only checks, or something?

Fixes #5548.
2019-01-18 19:27:41 +01:00
Dan Zimmerman
857561ca14 Fix warnings when compiling on macos
These warnings were appearing and annoying me so Im making a PR to fix
them.
2019-01-17 13:56:17 -06:00
Fabian Homborg
58b696bed1 complete: Don't allow wrapping a command with itself
Double-fixes #5541, by not allowing it to happen.
2019-01-17 09:49:50 +01:00
Mahmoud Al-Qudsi
dd31933c09 Remove spurious initialization in profiling_cmd_name_for_redirectable_block 2019-01-16 15:48:25 -06:00
Mahmoud Al-Qudsi
20cdcfadac Remove write-only assignments from autload.cpp 2019-01-16 15:46:11 -06:00
Mahmoud Al-Qudsi
53355885c8 Clean up dead code in builtin_read.cpp 2019-01-16 15:44:10 -06:00
Mahmoud Al-Qudsi
333bf1fd9f Remove write-only desc_width local variable 2019-01-16 15:38:27 -06:00
Mahmoud Al-Qudsi
bad3c5d79d Remove dead assignment and clarify ENV_NOT_FOUND behavior for set -e 2019-01-16 15:27:23 -06:00
Aaron Gyes
2abd0cde85 builtin_printf.cpp: remove is_hex_digit, redo is_octal_digit
Our is_hex_digit() was redundant, we can just use iswxdigit; the libc
implementation is a more efficient table lookup anyhow.

Do is_octal_digit() in terms of iswdigit instead of using wcschr.
2019-01-15 02:05:12 -08:00
Mahmoud Al-Qudsi
027fc43736 Fix result after explicit return in a while block
Closes #5513.
2019-01-13 18:56:19 -06:00
ridiculousfish
2d3e8ec0a9 Correct highlighting of abbreviations
Abbreviation highlighting cannot use the snapshot environment because we do
not know up-front which variables to capture. Will revisit this later.
2019-01-11 20:43:52 -08:00
ridiculousfish
82170b0862 Add HOME as a snapshotted variable
Corrects certain autosuggestions involving tildes.
2019-01-11 15:12:17 -08:00
ridiculousfish
59d62fdd53 Thread the right PWD through autosuggestions
These were getting / as the PWD, resulting in bogus suggestions.
2019-01-11 15:04:09 -08:00
ridiculousfish
a333c2f01d Fix some compile warnings 2019-01-10 20:59:47 -08:00
ridiculousfish
77884bc21a Instantize env_get
This removes env_get(). All fish variable accesses must go through an
environment_t.
2019-01-10 20:08:06 -08:00
ridiculousfish
b98812dd1a Remove last vestiges of env_set 2019-01-10 20:07:58 -08:00
ridiculousfish
3b1709180f Instantize env_get 2019-01-10 20:07:53 -08:00
ridiculousfish
6f52e6bb1c Instantize contents of exec.cpp and others 2019-01-10 20:07:47 -08:00
ridiculousfish
038f3cca6d Remove the abbreviation cache
Read abbreviations directly from the environment.
2019-01-10 20:07:41 -08:00
ridiculousfish
9f62a53077 Instantize env_get inside highlighting 2019-01-10 20:07:35 -08:00
ridiculousfish
50c83463f1 Switch some uses of env_get to instanced environment_t 2019-01-10 20:07:31 -08:00
ridiculousfish
3eb15109cf Instantize env_set in env.h and env.cpp 2019-01-10 20:07:23 -08:00
ridiculousfish
abcd24f716 Eliminate env_snapshot_t::current()
These uses are better served by passing in the real environment stack,
now that we have environment_t as a shared base class.
2019-01-10 20:07:14 -08:00
ridiculousfish
03b92ffe00 Clean up path_get_cdpath and path_can_be_implicit_cd 2019-01-10 20:07:10 -08:00
ridiculousfish
c1dd284b3e Instantize env_set
Switch env_set to an instance method on environmnet_t.
2019-01-10 20:05:45 -08:00
ridiculousfish
421fbdd52a Instantize env_get_pwd_slash
This requires threading environment_t through many places, such as completions
and history. We introduce null_environment_t for when the environment isn't
important.
2019-01-10 20:01:28 -08:00
ridiculousfish
26fc705c07 Instance env_set_empty 2019-01-10 20:01:20 -08:00
ridiculousfish
a00de96a57 Instance env_remove 2019-01-10 20:01:15 -08:00
ridiculousfish
ede66ccaac Instance env_set_argv and env_set_pwd 2019-01-10 20:29:10 -08:00
ridiculousfish
5055621e02 Eliminate env_push and env_pop 2019-01-10 20:29:10 -08:00
ridiculousfish
94adb53b1f Eliminate complete_set_variable_names 2019-01-10 20:29:10 -08:00
ridiculousfish
e6b13c6bac Begin to thread environments explicitly through completions 2019-01-10 20:29:10 -08:00
ridiculousfish
e6872b83b0 Eliminate global env_export_arr()
This assumes the set of exported variables is a global property; but we
want it to be a local property.
2019-01-10 20:29:10 -08:00
ridiculousfish
a47f6859bd Equip parser_t with a variable stack
Prepares to eliminate env_get and env_set by accessing variables through
a parser.
2019-01-10 20:29:10 -08:00
ridiculousfish
bba66a3ecc Use shared_ptr instead of unique_ptr in environments
This prepares for multiple environment stacks sharing the same parent.
2019-01-10 20:29:10 -08:00
ridiculousfish
8d7cae63ff Introduce env_stack_t
This will instance environment variable stacks.
2019-01-10 20:29:10 -08:00
ridiculousfish
391af6af0c Introduce class environment_t
This will be used as a base class for variable snapshots and variable stacks.
2019-01-10 20:29:10 -08:00
ridiculousfish
895c2c4af0 Minor cleanup of parser interface 2019-01-10 20:29:10 -08:00
Mahmoud Al-Qudsi
2bb53f7253 Fix locale_t under macOS 10.10
`xlocale.h` is not available on Linux, so we can't just universally
include it.

`HAVE_XLOCALE_H` was already being tested/set in the CMake script as a
possible requirement for `wcstod_l` support, this just adds it to
`config_cmake_h.in` and uses it in `wutil.h` to gate the include.
2019-01-10 20:03:38 -06:00
David Adam
d518b01281 fish_tests.cpp: mock the home directory
Removes the dependency on the current user's home directory, instead
overriding it to be within the current hierarchy.

Fixes the tests on Debian buildd, where the home directory is
deliberately unwriteable to pick up errors in builds.
2019-01-10 21:22:44 +08:00
ridiculousfish
c15a702f18 Revert "Fix unsafe locale usage in wcstod_l fallback"
This reverts commit 3444e1db18.

The reverted commit broke tests on the Mac.
2019-01-09 15:23:55 -08:00
John McKay
a6fa237db2 print --help to stdout like other builtins (#5495) 2019-01-09 15:07:09 -08:00
Stephen M. Coakley
d776a366fa Pass final Fish exit status to fish_exit event
For fish_exit to be a suitable replacement for --on-process-exit, we need to be able to provide scripts with access to the shell's final exit code.
2019-01-05 21:27:13 +01:00
Fabian Homborg
b8b0c39c77 fish_tests: Use std::isnan
Fixes the tests on Ubuntu 16.04 "xenial".
2019-01-05 12:58:52 +01:00
Fabian Homborg
9d4e460b29 string: Fix crash with _GLIBCXX_ASSERTIONS
This asserted because we accessed wcstring::front() when it was empty.

Instead, check explicitly for it being empty before.

Fixes #5479
2019-01-04 08:45:53 +01:00
Fabian Homborg
12d7c7feb6 Switch to readdir from readdir_r
It's deprecated in glibc, and does not work properly on Solaris.

Fixes #5458.
2019-01-03 11:19:45 +01:00
Mahmoud Al-Qudsi
3444e1db18 Fix unsafe locale usage in wcstod_l fallback
Using `setlocale` is both not thread-safe and not correct, as
a) The global locale is usually stored in static storage, so
   simultaneous calls to `setlocale` can result in corruption, and
b) `setlocale` changes the locale for the entire application, not
   just the calling thread. This means that even if we wrapped the
   `wcstod_l` in a mutex to prevent the previous point, the results
   would still be incorrect because this would incorrectly influence the
   results of locale-aware functions executed in other threads while
   this thread is executing.

The previous comment mentioned that `uselocale` hadn't worked. I'm not
sure what the failing implementation looked like, but `uselocale` can be
tricky. The committed implementation passes the tests for me under Linux
and FreeBSD.
2019-01-02 18:43:43 -06:00
Mahmoud Al-Qudsi
bc0a0b4bc8 Fix wcstod_l infinite recursion under FreeBSD
This was the actual issue leading to memory corruption under FreeBSD in
issue #5453, worked around by correcting the detection of `wcstod_l` so
that our version of the function is not called at all.

If we are 100% certain that `wcstod_l` does not exist, then then the
existing code is fine. But given that our checks have failed seperately
on two different platforms already (FreeBSD and Cygwin/newlib), it's a
good precaution to take.
2019-01-02 18:43:43 -06:00
Mahmoud Al-Qudsi
ef23923c8d Drop use of deprecated bzero(3)
Use `memset(__, 0, __)` instead. Also fixes #5461 by not needing `bzero`
from `strings.h` anymore.
2019-01-02 00:28:25 -06:00
Mahmoud Al-Qudsi
d1913f0df0 Add workaround for Cygwin process management and job control bugs
We cannot wait by pgroup under Cygwin for unknown reasons. Always
wait on jobs by individual processes. See code for more information.
2019-01-02 00:14:07 -06:00
Fabian Homborg
217486e547 math: Use simpler format string
It seems like musl's printf here fails on `%*lc`. So we use `%*ls`,
which we already use in string, so it should work.
2019-01-01 14:52:26 +01:00
Fabian Homborg
9b980f5e6e Use fstatvfs if ST_LOCAL is available
Allows us to sometimes use mmap on NetBSD (proper capitalization is
important).
2018-12-31 14:24:24 +01:00
Fabian Homborg
e9ad88d4b0 Don't set the title on NetBSD's wscon
We might want to check the terminfo "XT" capability here, but for now
let's do the quick fix.
2018-12-31 14:24:23 +01:00
Fabian Homborg
b77a909a4f Make a few variables const
These are then passed to tparm, but we explicitly cast the const
away.
2018-12-31 14:24:23 +01:00