Commit Graph

2686 Commits

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

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

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

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

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

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

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

As discussed in #6099, this caused a regression in some completions (eg
dd).
2019-09-19 14:38:16 +08:00
Aaron Gyes
f35e18bb9b complete.cpp: don't double escape commands in complete output
The argument to --command was escaped both here and in
append_switch(), potentially producing incorrect output
2019-09-18 16:21:21 -07:00
Johannes Altmanninger
8baea8b157 Do not add a space after completion if one is already there
Example: type `cd --help --help`, move the cursor inside the first `--help` and press tab.
This used to add redundant spaces.
2019-09-18 14:02:24 -05:00
Aaron Gyes
22811ebcf6 Remove unused macros
Most just left behind after actual code was moved into different files.
2019-09-18 01:31:03 -07:00
Aaron Gyes
715836cb0a builtin_set_color.cpp: remove unnecessary .c_str() 2019-09-18 00:09:23 -07:00
Aaron Gyes
5f05d9734c builtin_set_color.cpp: colorize set_color --print-colors
Each named color is now printed in that color, only if
hooked up to a TTY. Shouldn't affect scripts.
2019-09-18 00:05:09 -07:00
Aaron Gyes
61f0756fe6 builtins: Use standard builtin.h error macros more 2019-09-17 22:04:33 -07:00
ridiculousfish
533ee65963 Allow binding nul (zero byte)
This sequence can be generatd by control-spacebar. Allow it to be bound
properly.

To do this we must be sure that we never round-trip the key sequence
through a C string.
2019-09-14 16:37:57 -07:00
ridiculousfish
5afcc439a5 Clean up input_terminfo_get_sequence 2019-09-14 14:59:01 -07:00
ridiculousfish
5ebcd3de98 Remove some unnecessary string formatting 2019-09-14 14:22:37 -07:00
ridiculousfish
06269ed67d Remove NOT_A_WCHAR
It's now unused.
2019-09-14 13:18:04 -07:00
ridiculousfish
8747018cbc Use maybe_t in unescape_string_internal 2019-09-14 13:17:22 -07:00
ridiculousfish
fa1dab040b Use maybe_t in read_unquoted_escape 2019-09-14 12:54:38 -07:00
ridiculousfish
cc5e29734b Use maybe_t in string_last_char 2019-09-14 11:56:02 -07:00
Johannes Altmanninger
0ecfc25961 Fix highlighting of redirection to - (close file descriptor)
Fixes #6092
2019-09-14 13:04:27 -05:00
David Adam
77ef2ef6c3 jobs: return success when a job is found via --last
Closes #6104.
2019-09-14 13:01:36 -05:00
ridiculousfish
56d2942f59 Minor cleanup of how jobs store their command string 2019-09-09 09:07:25 -07:00
ridiculousfish
535a448d0e Remove an errant fprintf 2019-09-08 15:44:07 -07:00
ridiculousfish
b2fe2f9ff3 Correct escaping and add tests for bracket completion
Add some tests for new bracket completion behavior, and fix an escaping
bug where \\[ was incorrectly marked as escaping.
2019-09-08 15:43:20 -07:00
Johannes Altmanninger
bc3dde997d escape square brackets in an argument before completing it
fixes #5831
2019-09-08 12:27:58 -07:00
ridiculousfish
e79df33e3a Disallow parsing 'and' and 'or' as commands
Except for and --help and or --help

Fixes #6089
2019-09-08 11:09:32 -07:00
ridiculousfish
fa6bac1283 Correctly implement and --help and or --help 2019-09-08 10:42:24 -07:00
Johannes Altmanninger
962bfa9668 Escape literal dollar signs in quoted completions
Closes #6060.
2019-09-07 13:52:40 -05:00
Mahmoud Al-Qudsi
f854e3dc29 Try fixing __has_attribute errors on Travis macOS 2019-09-05 23:11:59 -05:00
Mahmoud Al-Qudsi
80610addf8 Avoid warnings about unsupported clang::weak_import w/ GCC on macOS 2019-09-05 23:00:46 -05:00
ridiculousfish
b760fd9064 Correctly set g_use_posix_spawn at launch again 2019-09-05 11:00:52 -07:00
Johannes Altmanninger
f7dac82ed6 Escape separators (colon and equals) to improve completion
Fish completes parts of words split by the separators, so things like
`dd if=/dev/sd<TAB>` work.
This commit improves interactive completion if completion strings legitimately
contain '=' or ':'.  Consider this example where completion will suggest
a🅰️1 and other files in the cwd in addition to a:1

touch a:1; complete -C'ls a:'

This behavior remains unchanged, but this commit allows to quote or escape
separators, so that e.g. `ls "a:<TAB>` and `ls a\:<TAB>` successfully complete
the filename.

This also makes the completion insert those escapes automatically unless
already quoted.
So `ls a<TAB>` will give `ls a\:1`.

Both changes match bash's behavior.
2019-09-02 14:27:21 -07:00
ridiculousfish
9fd9f70346 Restore terminal modes after sending SIGCONT
Fixes #2214

Thanks to @bruce-hill for the patch.
2019-09-01 17:24:23 -07:00
Johannes Altmanninger
068aba1902 remove redundant call (done in constructor of completion_t) 2019-08-31 12:05:49 -07:00
Mahmoud Al-Qudsi
af4b54e635 Change WSL version check to a hard error, but include a bypass
Instead of warning (debug level 1), we now emit an error (debug level 0) if a known bad version of
WSL is detected. However, `FISH_NO_WSL_CHECK` can now be defined to skip both the check and the
startup message.
2019-08-25 18:50:17 -05:00
Mahmoud Al-Qudsi
44022e65c2 Revert "Remove the WSL warning"
This reverts commit 5101bdeb9f.
2019-08-25 18:29:46 -05:00
ridiculousfish
99c498d3d7 Use move semantics in trim and history_item_t 2019-08-25 13:37:06 -07:00
David Adam
225b1204d6 read: add --list as synonym for --array
Work on #5846.
2019-08-22 21:24:17 +08:00
ridiculousfish
903e7c6d5e history_lru_cache_t to use move semantics 2019-08-18 12:14:07 -07:00
ridiculousfish
9b2b7f787e Migrate history profiling to flog 2019-08-18 11:14:45 -07:00
ridiculousfish
0da87d3e5f Equip history_item_t with a default constructor 2019-08-17 20:01:44 -07:00
ridiculousfish
5101bdeb9f Remove the WSL warning
This warning is annoying and there is no way to disable it.

Ping #5661. Ping #5298. Closes #6038
2019-08-16 20:59:53 -07:00
ridiculousfish
f137f24d75 Initialize a const variable
Fixes #6041
2019-08-16 17:50:41 -07:00
ridiculousfish
a87e0183df Stop rewriting the history file on every command
fish is designed to append to the history file in most cases. However
save_internal_via_appending was never returning success, so we were
always doing the slow rewrite path. Correctly return success.

Fixes #6042
2019-08-15 13:49:17 -07:00
ridiculousfish
7ab291775a Add flog logging to history 2019-08-15 13:42:23 -07:00
Aaron Gyes
edc8d5d7a3 string-replace-fewer-backslashes -> regex-easyesc
This shortens a very long feature name.

See discussion in #5805
2019-08-13 22:32:04 -07:00
ridiculousfish
ce178fd6fd Make escape_yaml_fish_2_0 and unescape_yaml_fish_2_0 static
They no longer need to be exposed.
2019-08-12 09:22:21 -07:00
ridiculousfish
3ae5b23971 Migrate append_history_item_to_buffer to history_file.cpp
Also eliminate history_output_buffer_t, which no longer does anything useful.
2019-08-12 09:17:10 -07:00
ridiculousfish
6eebe4cc83 Eliminate history_lru_item_t
history_item_t is enough
2019-08-11 14:26:22 -07:00
ridiculousfish
6b008c3eae Stop caching the lowercase string contents in history items 2019-08-11 13:41:04 -07:00
ridiculousfish
92e9a34b47 Simplify history_output_buffer_t 2019-08-11 13:08:31 -07:00
ridiculousfish
2ddde381d4 Clean up next_line() interface and implementation 2019-08-11 12:57:09 -07:00
ridiculousfish
91987a4548 Migrate history file format stuff into new file history_file.cpp
Breaks up the history.cpp monolith.
2019-08-11 12:45:04 -07:00
ridiculousfish
74357bac91 Remove an errant semicolon 2019-08-10 16:47:45 -07:00
ridiculousfish
fd5d8c1949 Remove __packed
We can use the new C++11 enum type feature to stop using this non-portable
__packed.
2019-08-10 16:04:05 -07:00
ridiculousfish
30fd526fc1 Correct an out-of-bounds index in screen
Fixes #6037
2019-08-10 14:32:55 -07:00
ridiculousfish
0dc5eaeb97 reader_expand_abbreviation_in_command to return maybe_t<wcstring> 2019-08-06 16:09:23 -07:00
Fabian Homborg
2c32885a2d Fix build on old gcc by using old-school initialization
It appears Gcc 4.8 doesn't get this particular expression, so we just
revert to the old `type foo = bar` style from the new `type foo{bar}`.

Fixes #6027.
2019-08-05 18:08:13 +02:00
ridiculousfish
29dede8139 Migrate parse_util_detect_errors to a free function 2019-08-04 14:49:56 -07:00
ridiculousfish
73bf60754c Don't assign jobs to fish's pgrp if there's no external process
Fixes #6011
2019-08-03 14:43:55 -07:00
ridiculousfish
95c97619c6 Use cbegin() in one place in reader 2019-07-31 14:23:41 -07:00
Fabian Homborg
6500765256 Allow switch with something that expands to nothing
Meaning empty variables, command substitutions that don't print
anything.

A switch without an argument

```fish
switch
   case ...
end
```

is still a syntax error, and more than one argument is still a runtime
error.

The none-argument matches either an empty-string `case ''` or a
catch-all `case '*'`.

Fixes #5677.

Fixes #4943.
2019-07-31 14:08:28 +02:00
ridiculousfish
5b90fa0bda Add a missing reference to a range-based for loop 2019-07-29 21:39:05 -07:00
ridiculousfish
a33f0eb636 Clean up some logic around when process exit events are sent 2019-07-28 14:36:57 -07:00
ridiculousfish
a40a4c0c54 Add some new tricks to fish_test_helper
Allow fish_test_helper to report if it is in the foreground, and to SIGINT
its parent.
2019-07-27 11:00:07 -07:00
ridiculousfish
822b53c67a Don't color a whole string invalid because of an unclosed quote
When syntax highlighting a quoted string, if the string is not closed,
only show the opening quote as an error, not the whole string.
2019-07-24 12:43:47 -07:00
ridiculousfish
c0053ceef5 highlighter_t to return color array directly
Saves some copying and allocations.
2019-07-24 12:42:18 -07:00
ridiculousfish
554ee240b3 Correct handling of explicitly separated output when all elements are empty
Previously when propagating explicitly separated output, we would early-out
if the buffer was empty, where empty meant contains no characters. However
it may contain one or more empty strings, in which case we should propagate
those strings.

Remove this footgun "empty" function and handle this properly.

Fixes #5987
2019-07-21 14:00:27 -07:00
ridiculousfish
e8c6de8055 Correctly export empty universal variables
Fixes #5992
2019-07-21 12:45:29 -07:00
ridiculousfish
1f854ec284 Accept a pwd in resolve_file_redirections_to_fds
Conceptually allow multiple of these to run in parallel
2019-07-20 17:25:25 -07:00
ridiculousfish
8ec568d21f Add some tests to path_apply_working_directory 2019-07-15 17:56:06 -07:00
ridiculousfish
8181883111 Minor refactoring of logic around when a job wants to claim the terminal
Introduce should_claim_terminal() which encapsulates an && exprsesion which
was previously repeated a lot.
2019-07-12 13:31:56 -07:00
ridiculousfish
d577eb4aaa Only use the global fish_complete_path and fish_function_path
Prior to this fix, fish would attempt to react if a local fish_complete_path
or fish_function_path were set. However this has never been very well tested
and will become impossible with concurrent execution. Always use the global
values.
2019-07-12 12:40:12 -07:00
ridiculousfish
0e4fe53718 clang-format some files 2019-07-06 13:11:50 -07:00
ridiculousfish
bc0329f775 Add wcstolower
Converts a string to lowercase. Eliminates some loops that did this
explicitly.
2019-07-06 12:19:34 -07:00
ridiculousfish
b1a1b617f1 child_setup_process to accept new termowner directly
Soon we will have more complicated logic around whether to call tcsetpgrp.
Prepare to centralize the logic by passing in the new term owner pgrp,
instead of having child_setup_process perform the decision.
2019-07-03 18:06:35 -07:00
ridiculousfish
8282369f45 child_setup_process to stop passing the process
child_setup_process only cares about whether we are in a forked child, not
the entire process structure. Narrow the parameter.
2019-07-03 17:48:52 -07:00
Fabian Homborg
8013686d17 delete-or-exit: Only exit if the commandline is empty
This exitted if the cursor was at the end of the line as well (i.e. if
delete-char failed). That's a bit too eager.

Also documentation, which should have already been included.
2019-07-03 11:48:38 +02:00
ridiculousfish
09e4f8ff42 Refactor how the terminal is transferred to jobs
Centralize the logic around when a job acquires the terminal.
2019-06-29 15:58:36 -07:00
ridiculousfish
2931d869d5 Remove the foreground job property
This was not used consistently and was confused with the foreground job
flag. Whether a job is foreground is mutable, so it should remain a flag.
2019-06-29 15:54:49 -07:00
ridiculousfish
98ba7d7790 Simplify maybe_assign_terminal()
Move this out of postfork, it is not called after fork.
2019-06-29 14:36:14 -07:00
ridiculousfish
f58960ba01 Add a DIE("unreachable") in should_claim_process_group_for_job
Fixes a gcc warning.
2019-06-29 11:40:52 -07:00
ridiculousfish
4a2c709fb1 Eliminate shell_is_interactive
We used to have a global notion of "is the shell interactive" but soon we
will want to have multiple independent execution threads, only some of
which may be interactive. Start tracking this data per-parser.
2019-06-29 11:28:26 -07:00
ridiculousfish
3f1d7bbdc5 Call tcsetpgrp in child processes before resetting signal handlers
Also ignore SIGTTIN and SIGTTOU across the tcsetpgrp call.

Hopeful fix for #5963
2019-06-28 11:54:55 -07:00
ridiculousfish
262fe65121 Correctly mark a node when erasing an exported variable
Fixes #5965
2019-06-28 11:22:49 -07:00
ridiculousfish
3c800e0608 Make history tests more robust
history now often writes to the history file asynchronously, but the history
test expects to find the text in the file immediately after running the
command. Hack a bit in history to make this test more reliable.
2019-06-28 11:16:27 -07:00
ridiculousfish
e3f94f4b72 Centralize signal handling into a single function
Prior to this diff, fish had different signal handling functions for
different signals. However it was hard to coordinate when a signal needed
to be the default handler, and when it was custom. In #5962 we overwrote
fish's custom WINCH handler with the default_handler when fish script asked
for WINCH to be handled.

Just have a single big signal handler function. That way it can never be
set to the wrong thing.

Fixes #5969
2019-06-28 10:51:22 -07:00
ridiculousfish
8254342339 Remove the useless second parameter from signal_handle
It was always set to 1.
2019-06-28 10:33:03 -07:00
ridiculousfish
f3736e8fdf fish to claim a job's pgroup if the first process is fish internal
When executing a job, if the first process is fish internal, then have
fish claim the job's pgroup.

The idea here is that the terminal must be owned by a pgroup containing
the process reading from the terminal. If the first process is fish
internal (a function or builtin) then the pgroup must contain the fish
process.

This is a bit of a workaround of the behavior where the first process that
executes in a job becomes the process group leader. If there's a deferred
process, then we will execute processes out of order so the pgroup can be
wrong. Fix this by setting the process group leader explicitly as fish
when necessary.

Fixes #5855
2019-06-26 17:30:51 -07:00
ridiculousfish
f7e2e7d26b Don't generate exit events for jobs created from within event handlers
Add a new job property from_event_handler, and do not create exit events for
such jobs. This prevents easy accidental infinite recursion.
2019-06-26 17:30:51 -07:00
Fabian Homborg
d7a9bdf5c3 reader: Do the "delete" part for delete-or-exit
For some reason this is supposed to do a delete-*char*.

I was assuming the function was broken and it should delete the entire
line.

Fixes #5967.
2019-06-26 22:53:19 +02:00
Fabian Homborg
d415350aaf reader: Add delete-or-exit bind function
This is an important binding and should therefore be in C++.
2019-06-25 19:57:00 +02:00
Fabian Homborg
77d8487078 string: Also stop printing documentation
Especially as, in this case, the documentation is quite massive.

Caught by porting string's test to littlecheck.

See #3404 - this was already supposed to be included.
2019-06-25 17:26:30 +02:00
Fabian Homborg
caedf01c00 Revert "Latch signal handlers"
This reverts commit 7ed1022cf4.

Fixes #5962.
2019-06-25 11:25:09 +02:00
ridiculousfish
27e4d1d62d Revert "Revert "Don't service ioport completions if data is available on stdin""
This reverts commit 005e6f2ab8.

This allows new text entry to take priority over highlighting, improving the
performance of pasting.
2019-06-23 16:45:06 -07:00
ridiculousfish
89fb408eb6 Migrate some job flags into const properties struct
This helps clarify which parts of a job are mutable, and which are constant.
2019-06-23 12:42:44 -07:00
ridiculousfish
5362161343 Call tcsetgrp() in child processes again
25afc9b377 made this unnecessary by
having child processes wait for a signal after fork(), but this change
was later reverted. If we artificially slow down fish (e.g. with a sleep)
after the fork call, we see commands getting backgrounded by mistake.

Put back the tcsetgrp() call.
2019-06-23 12:42:44 -07:00
ridiculousfish
8255c01edb Rename setup_child_process to child_setup_process
Try to name all functions called after fork with "child" prefix.
2019-06-23 12:42:44 -07:00
Fabian Homborg
9b54a53758
Prevent not-yet-loaded functions from loaded when erased (#5951)
* Prevent not-yet-loaded functions from loaded when erased

Today, `functions --erase $function` does nothing if the function
hasn't been autoloaded yet.

E.g. run, in an interactive session

    > functions --erase ls
    > type ls

and be amazed that it still shows our default `ls --color=auto`
wrapper function.

This seems counter-intuitive - removing a function ought to remove it,
whether it had been executed before or not.

* doc/changelog
2019-06-22 11:08:36 +02:00
Lily Ballard
fe2ec1e4f8
Merge pull request #5943 from lilyball/string_collect
Add new `string` subcommand `string collect`
2019-06-22 00:30:20 -07:00
Fabian Homborg
370f5356a1 Move "character has no narrow representation" to flog
This was a warning, which is kind of ridiculous, as it's inactionable
error spew.

Fixes #2815.
2019-06-19 12:36:38 +02:00
Lily Ballard
181e44d331 Invert the flag for string collect
Instead of requiring a flag to enable newline trimming, invert it so the
flag (now `--no-trim-newlines`) disables newline trimming. This way our
default behavior matches that of sh's `"$(cmd)"`.

Also change newline trimming to trim all newlines instead of just one,
again to match sh's behavior.
2019-06-16 16:40:14 -07:00
Lily Ballard
b41e5cbbb7 Add string collect
The `string collect` subcommand behaves quite similarly in practice to
`string split0 -m 0` in that it doesn't split its output, but it also
takes an optional `--trim-newline` flag to trim a single trailing
newline off of the output.

See issue #159.
2019-06-16 15:51:57 -07:00
ridiculousfish
5b5887ea99 Correct capitalization of complete_and_search 2019-06-16 14:38:27 -07:00
ridiculousfish
360116221a Switch history_t to use owning_lock internally
This removes a lot of tricky manual locking. It also removes the "main
thread" dependency.
2019-06-14 20:49:17 -07:00
yogendra
6bed255a52 Fix Issue 5910 2019-06-14 08:56:42 -07:00
ridiculousfish
1c66d56d3a Add debug categories for reaping processes 2019-06-13 14:29:13 -07:00
Fabian Homborg
e363552ef0 screen: Include termios for NetBSD
Otherwise it won't build.
2019-06-11 11:34:14 +02:00
Mahmoud Al-Qudsi
cfe1f1db9e Fix build on FreeBSD 12.0 with stock Clang
`isspace()` is in `ctype.h`.
2019-06-10 16:51:42 -05:00
ridiculousfish
aa950e5c13 Provide an optimized override of get_pwd_slash() 2019-06-10 10:26:33 -07:00
Fabian Homborg
38a7c77e4b Re-double-super-fix tilde completion crash
Yeah, I was too clever with the operators here.

Fixes #5929.
2019-06-10 18:50:40 +02:00
Fabian Homborg
d1ca392393 math: Allow "x" for multiplication
It's always a bit annoying that `*` requires quoting.

So we allow "x" as an alternative, only it needs to be followed by
whitespace to distinguish it from "0x" hexadecimal notation.
2019-06-10 18:45:10 +02:00
ridiculousfish
42138f00c6 Remove wchdir()
It's unused, and will soon be dangerous as the process-wide cwd will
lose meaning.
2019-06-10 09:37:08 -07:00
ridiculousfish
6637ccd3a2 Keep an fd for the cwd in the parser
To support distinct parsers having different working directories, we need
to keep the working directory alive, and also retain a non-path reference
to it.
2019-06-10 09:27:51 -07:00
ridiculousfish
6ce85aebc6 Switch file_io_t to store a wcstring
We no longer use file_io_t after fork(). We don't need to use a malloc'd
string any more. Use a wcstring.
2019-06-09 17:43:25 -07:00
ridiculousfish
1baa479bbf Eliminate the global list of scoped transient commandlines
Store this in a parser's libdata instead.
2019-06-09 14:11:25 -07:00
ridiculousfish
421cf92380 Use a generation count for uvars exports
Because an exported universal variable must be exported in all variable
stacks, explicit invalidation is infeasible. Switch the universal variables
to a generation count.
2019-06-09 13:48:07 -07:00
ridiculousfish
7dffaf1a02 Reimplement exported variable change detection
Prior to this fix, fish would invalidate the exported variable list
whenever an exported variable changes. However we soon will not have a
single "exported variable list." If a global variable changes, it is
infeasible to find all exported variable lists and invalidate them.

Switch to a new model where we store a list of generation counts. Every
time an exported variable changes, the node gets a new generation. If the
current generation list does not match the cached one, then we know that
our exported variable list is stale.
2019-06-09 13:25:30 -07:00
ridiculousfish
79ee59adc0 Convert the create_export_array message to flog 2019-06-09 13:22:18 -07:00
Per Bothner
e05a0716e5 Make sure initial indentation is done using cursor move, not spaces.
The goal to allow a terminal to reliably distinguish user input
from indentation and prompts, in the context of shell integration.
2019-06-09 11:36:47 -07:00
Per Bothner
7448e7825f Avoid code duplication relating to screen clearning in s_update. 2019-06-09 11:32:26 -07:00
Mahmoud Al-Qudsi
c9a77bb474 Optimize history search reset checking
`history_search.active()` is an atomic read, whereas
`command_ends_history_search(..)` is a little bit heavier.
2019-06-08 21:07:32 -05:00
ridiculousfish
be97499106 Revert "Revert "Add a test for autoload_t""
This reverts commit 2507162f80.

Put back the autoload test.
2019-06-07 12:12:43 -07:00
Per Bothner
18cf2b8509 Rename incorrect is_single_byte_escape_seq to is_three_byte_escape_seq. 2019-06-07 08:31:52 +02:00
Per Bothner
060a068a3c Fix comment for is_single_byte_escape_seq. 2019-06-07 08:31:52 +02:00
Fabian Homborg
ae59fdeda5 src/builtin_read: Remove more references to fish_history 2019-06-06 15:07:46 +02:00
Fabian Homborg
51fcb79d96 Remove read history
This was undocumented, not all that useful and potentially unwanted.

In particular it means that things like

   mysql -p(read)

will still keep the password in history.

Also it allows us to simply implement asking for the history deletion
term.

See #5791.
2019-06-06 15:07:46 +02:00
ridiculousfish
fc99d6c7af clang-format all files 2019-06-03 20:30:48 -07:00
ridiculousfish
d1fc8d5f71 Improve the iothread port structure
Mark both fds in the ioport as non-blocking, and allow bulk reads.
2019-06-03 16:42:51 -07:00
ridiculousfish
b478f877ee Clean up g_fork_count
Make it static and atomic
2019-06-03 12:58:59 -07:00
ridiculousfish
bc103c2ea6 Make the list of event handlers thread safe 2019-06-03 12:33:10 -07:00
ridiculousfish
ead16958b2 Make set_signal_observed thread-safe 2019-06-03 12:32:48 -07:00
ridiculousfish
ad301ab3a0 Remove an incorrect shadowing use of principal_parser 2019-06-03 02:55:36 -07:00
ridiculousfish
ff55249447 Make events per-parser
This makes the following changes:

1. Events in background threads are executed in those threads, instead of
being silently dropped

2. Blocked events are now per-parser instead of global

3. Events are posted in builtin_set instead of within the environment stack

The last one means that we no longer support event handlers for implicit
sets like (example) argv. Instead only the `set` builtin (and also `cd`)
post variable-change events.

Events from universal variable changes are still not fully rationalized.
2019-06-03 02:48:35 -07:00
ridiculousfish
890c1188ab Instantize and rationalize locking around the input mapping set
Hypothetically a background thread could invoke builtin_bind, etc.
Protect the set of input bindings with a lock.
2019-06-02 22:54:01 -07:00
ridiculousfish
2ef4d982df Clean up some dependencies in input.h 2019-06-02 17:49:52 -07:00
ridiculousfish
ad35fb7457 Make the bind mode per-parser
Eliminates a use of principal_parser
2019-06-02 16:57:52 -07:00
ridiculousfish
671df14178 Thread a parser into inputter_t 2019-06-02 16:41:13 -07:00
ridiculousfish
a48dbf23b8 Instantize the character event queue
Wrap this stuff up in structs so it's no longer global.
2019-06-02 16:37:05 -07:00
Fabian Homborg
6c1d29e14d fixup! Fix build
I deleted the lines that defined "narrow_path" and
"explicit_vars_path", but didn't see the two remaining uses.

Sorry!
2019-06-01 10:32:30 +02:00
Fabian Homborg
7525befadb path_get_path: Narrow string before
This cuts down on the wcs2string here by ~25%.

The better solution would be to cache narrow versions of $PATH, since
we compute that over and over and over and over again, while it rarely changes.

Or we could add a full path-cache (where which command is), but that's
much harder to invalidate.

See #5905.
2019-06-01 09:57:18 +02:00
Fabian Homborg
5ca14904d0 Store narrow version of uvar path
This sets the explicit path to the default one, which should be okay,
since the default path never changes (not even if $XDG_CONFIG_HOME
does).

Then it saves a narrow version of that, which saves most of the time
needed to `sync` in most cases.

Fixes #5905.
2019-06-01 09:56:57 +02:00
Fabian Homborg
bc19647be2 wutil: Give narrow versions of a few functions
Note that this isn't technically *w*util, but the differences between
the functions are basically just whether they do the wcs2string
themselves or not.
2019-06-01 09:34:47 +02:00
ridiculousfish
4e03d3c264 Correct a race in topic monitor
This fixes a race condition in the topic monitor. A thread may decide to
enter the wait queue, but before it does the generation list changes, and
so our thread will wait forever, resulting in a hang.

It also simplifies the implementation of the topic monitor considerably;
on reflection the whole "metagen" thing isn't providing any value and we
should just compare generations directly.

In the new design, we have a lock-protected list of current generations,
along with a boolean as to whether someone is reading from the pipe. The
reader (only one at a time) is responsible for broadcasting notifications
via a condition variable.
2019-05-31 09:31:42 -07:00
ridiculousfish
d920a618de Add FLOG logging to the topic monitor 2019-05-31 09:31:42 -07:00
ridiculousfish
b20bdcebfa FLOG narrow-string output to use fwprintf
This avoids mixing narrow and wide I/O on the same stream.
Extends the fix in #5900 by allowing narrow string literals again.
2019-05-31 09:31:42 -07:00
Fabian Homborg
4ebb6cf39e complete: Add "--force-files"
This allows a completion to specify that *it* takes files.

Useful for things like `sudo -e`, because sudo usually doesn't take
any files.
2019-05-30 19:13:42 +02:00
Fabian Homborg
87971e1f2e Widen the rest of the FLOGs
Fixes #5900.
2019-05-30 13:08:35 +02:00
Fabian Homborg
d73ee4d54b More using FLOGF when formatting is needed
sed-patched, every time a "%" is used in a call to `FLOG`, we use
`FLOGF` instead.
2019-05-30 11:54:09 +02:00
Fabian Homborg
9d62d8e3fd Use FLOGF when formatting is needed
This passed a format string in a variable which is why it was
presumably overlooked.

[ci skip]
2019-05-30 11:48:56 +02:00
ridiculousfish
ee9e5d4996 Allow disabling debug categories with leading -
This was always supposed to work but the string_prefixes_string call
had the wrong order.
2019-05-29 14:21:50 -07:00
ridiculousfish
0863c237b0 Make thread_id a visible thing
Every thread now has a non-recyclable thread id. This will be an aid in
debugging.
2019-05-29 12:34:11 -07:00
ridiculousfish
f3ee6a99c3 Add some FLOG logging around internal processes 2019-05-29 12:34:11 -07:00
Fabian Homborg
61292b0c6c fish_tests: Fix warnings 2019-05-29 21:11:08 +02:00
Fabian Homborg
6617c4d79e Use C++11 value-initialization instead of { 0 }
Removes a warning in GCC.
2019-05-29 20:50:35 +02:00
Fabian Homborg
1259b32ecc Mark some variables as unused
These triggered warnings.
2019-05-29 20:50:35 +02:00
Fabian Homborg
39099ceb10 Remove R_BEGIN_INPUT_FUNCTIONS
The enum starts at 0 (defined to be!), so we can eliminate this one.

That allows us to remove a reliance on the position of
beginning_of_line, and it would trigger a "type-limits" warning.

Also leave a comment because I actually hit that.
2019-05-29 20:50:35 +02:00
Fabian Homborg
4a6a354675 Placate compiler warnings 2019-05-29 20:50:35 +02:00
Fabian Homborg
364bc3fd63 test: Fix return type
This just returns a success signifier, not an error code.
2019-05-29 20:50:35 +02:00
Fabian Homborg
a5b633d3a5 env: Correct type
We'd be comparing "int" and "mode_t", and "mode_t" might be unsigned.

Found via GCC warning.
2019-05-29 20:50:35 +02:00
Fabian Homborg
e895cef245 tinyexpr: Correct pi type 2019-05-29 20:50:35 +02:00
Fabian Homborg
97507a24a2 Increase default read limit to 100MiB
Someone has hit the 10MiB limit (and of course it's the number of
javascript packages), and we don't handle it fantastically currently.

And even though you can't pass a variable of that size in one go, it's
plausible that someone might do it in multiple passes.

See #5267.
2019-05-29 11:01:45 +02:00
Fabian Homborg
66e238fad0 More wide IO for FLOG
This widens the remaining ones that don't take a char
anywhere.

The rest either use a char _variable_ or __FUNCTION__, which from my
reading is narrow and needs to be widened manually. I've been unable
to test it, though.

See #5900.
2019-05-29 08:07:04 +02:00
Fabian Homborg
32949eefbe src/exec: Use wide IO for FLOG
Another step towards #5900.
2019-05-28 23:08:35 +02:00
Fabian Homborg
7c1a40fe86 flog: Use wide literals with wide chars
This solves the main part of (careful linebreak)
issue #5900.

I'm betting all the errors that do use narrow IO are broken, including
a bunch of asserts.
2019-05-28 22:39:47 +02:00
David Adam
7fe93c7518 src/expand: update comment for fallthrough to GCC standard
As suggested in 75db3b4ff4 (r33153119)
2019-05-28 23:20:20 +08:00
David Adam
b5cf9e52ca wcsfilecmp: be clearer about sorting "-" after letters 2019-05-28 22:05:23 +08:00
David Adam
c848787107 add extra test for wcsfilecmp
Test changes added for #5634 in 6e525cc5d9.
2019-05-28 22:03:03 +08:00
David Adam
ba4f4bfce2 Convert further debug(0) calls to FLOG
Follow on from ea9d1ad82f.
2019-05-28 21:06:42 +08:00
ridiculousfish
29c627d020 Stop calling principal_parser() inside parse_execution.cpp 2019-05-27 19:56:35 -07:00
ridiculousfish
835c6ffa67 clang-format all files 2019-05-27 19:47:13 -07:00
ridiculousfish
0150d505de Allow underscores to be treated as dashes in debug categories 2019-05-27 17:38:09 -07:00
ridiculousfish
ea9d1ad82f Convert debug(0) calls to FLOG 2019-05-27 17:31:17 -07:00
ridiculousfish
6282ac5713 Convert locale variable changes from debug to flog 2019-05-27 17:24:52 -07:00
ridiculousfish
46a9da83e8 Convert terminal ownership logging from debug to flog 2019-05-27 17:24:52 -07:00
ridiculousfish
d9676bb2a8 Convert fork events from debug to flog 2019-05-27 17:24:52 -07:00
ridiculousfish
8774860468 Convert job logging from debug to FLOG 2019-05-27 17:24:52 -07:00
ridiculousfish
63a16befd4 Introduce the fish log, a replacement for debug()
This adds a new mechanism for logging, intended to replace debug().

The entry points are FLOG and FLOGF. FLOG can be used to log a sequence of
arguments, FLOGF is for printf-style formatted strings.

Each call to FLOG and FLOGF requires a category. If logging for a category
is not enabled, there is no effect (and arguments are not evaluated).

Categories may be enabled on the command line via the -d option.
2019-05-27 17:24:52 -07:00
ridiculousfish
b405b979ec Eliminate the CHECK() macro
This thing was pretty useless.
2019-05-27 17:24:19 -07:00
Fabian Homborg
9ae3b345c8 Handle empty strings in compare_completions_by_tilde
Fixes #5895.
2019-05-27 08:17:05 +02:00
ridiculousfish
d5f2d472d0 Thread a parser into reader
Eliminates uses of principal_parser
2019-05-26 18:51:47 -07:00
ridiculousfish
7ed1022cf4 Latch signal handlers
Now that our interactive signal handlers are a strict superset of
non-interactive ones, there is no reason to "reset" signals or take action
when becoming non-interactive. Clean up how signal handlers get installed.
2019-05-26 18:04:03 -07:00
ridiculousfish
ead7f28026 Unify the SIGQUIT handlers and remove set_non_interactive_handlers
Interactive signal handlers are now a strict superset of non-interactive
ones. Remove set_non_interactive_handlers()
2019-05-26 13:18:06 -07:00
ridiculousfish
d729d57d94 Unify the interactive and non-interactive signal handlers
The signal handlers for interactive and non-interactive SIGINT were distinct
and talked to the reader. This wasn't really justified and will complicate
having multiple threads. Unify these into a single signal handler.
2019-05-26 00:32:11 -07:00
ridiculousfish
5a4df9dd3a Use sigint_checker_t in debug_thread_error 2019-05-25 19:19:03 -07:00
ridiculousfish
ea3ad0c099 Introduce sigint_checker_t and use it in wait
Allow a simpler way to check for sigint via sigint_checker_t.
Adopt it in builtin_wait, instead of hooking into the reader.
2019-05-25 19:08:04 -07:00
ridiculousfish
f8ba0ac5bf Remove is_interactive_read
is_interactive_read is a suspicious flag which prevents a call to
parser_t::skip_all_blocks from a ^C signal handler. However we end
up skipping the blocks later when we exit the read loop.

This flag seems unnecessary. Bravely remove it.
2019-05-25 18:46:03 -07:00
ridiculousfish
2924751488 Correct priority of universal and global variable setting
When setting a variable without a specified scope, we should give priority
to an existing local or global above an existing universal variable with
the same name.

In 16fd780484 there was a regression that
made universal variables have priority.

Fixes #5883
2019-05-25 17:35:19 -07:00
Fabian Homborg
e339e0f389 fish_indent: Fix pygments 2019-05-25 11:38:05 +02:00
Fabian Homborg
6c0ae7477e reader: Only abort history search on cancel
Otherwise we'd undo the history search when you press e.g. execute,
which means you'd execute the search term.

Only `cancel` should walk it back, like it previously did hardcoded to
escape.

Fixes #5891.
2019-05-25 08:32:50 +02:00
ridiculousfish
a5a5ccb73d Revert "exec: If a job includes a builtin, it stays in our pgroup"
This reverts commit 711260593c.

This ended up breaking the tests; moreover it may have other problems
like preventing backgrounding.

Reopens #5855
2019-05-24 18:00:31 -07:00
ridiculousfish
43e3d3bcf2 Fix the argparse tests 2019-05-24 16:51:40 -07:00
ridiculousfish
a379e9ffeb Make the expect tests run again
These were inadvertently disabled by a bug which was introduced in
cd7e8f4103 . Fix the bug so the tests run
again.

They don't all pass yet; they regressed during the period they were
disabled.
2019-05-24 16:10:44 -07:00
Fabian Homborg
1fd627ebd3 reader: Don't handle escape specially
Escape is just another ordinary character that you can bind, or not.
2019-05-24 19:02:53 +02:00
Fabian Homborg
dd4e0a3b6d Actually end history search
Fixes #5818.
2019-05-24 19:01:24 +02:00
Fabian Homborg
d0bd238657 Don't hardcode enum numbers
"1" in the context of `escape_string(..., 1)` is referring to
`ESCAPE_ALL`, so we should use that.
2019-05-24 18:19:11 +02:00
Fabian Homborg
711260593c exec: If a job includes a builtin, it stays in our pgroup
Fixes #5855.
2019-05-24 18:04:20 +02:00
Fabian Homborg
f2bb1c8c1f expand: Simplify expand_escape_variable 2019-05-24 17:03:43 +02:00
ridiculousfish
84febe8f2e Make disowned pid reaping thread-safe 2019-05-22 17:10:33 -07:00
ridiculousfish
4d929720ce Clean up and rename io_transmorgrify 2019-05-22 16:36:22 -07:00
ridiculousfish
7915831939 Wrap setenv() and unsetenv() calls in a lock 2019-05-22 16:13:31 -07:00
ridiculousfish
e91d68266c Eliminate reader_current_filename
Store this in the parser libdata instead.
2019-05-22 13:51:27 -07:00
ridiculousfish
686b84396c Migrate the return bool outside of block_t
This is a flag that gets set by the return function. But we only need one,
not per-block. Move it into libdata.
2019-05-22 13:51:27 -07:00
Fabian Homborg
9a541d9ed4 expand: Use wcstring for the abbr prefix
This mainly is conceptually a bit simpler. The comment about making it
cheaper is entirely misplaced since this is quite far away from being
important.

Even expanding 1000 abbrs, it doesn't show up in the profile.
2019-05-22 22:31:45 +02:00
Fabian Homborg
212246ecaa fish_indent: Fix reading from stdin for 0 args
I have no idea why this passes the tests, we *have* tests reading from
stdin!
2019-05-22 22:21:28 +02:00
Fabian Homborg
1faffa515e Don't crash if CDPATH is "./"
Fixes #5887.
2019-05-22 21:48:40 +02:00
ridiculousfish
363652ad76 debug_thread_error to wait for a signal instead of sleep
Allows for control-C out of it
2019-05-21 20:15:59 -07:00
Fabian Homborg
6d20b3984a Revert "src/screen: Stop falling back to wchar_t"
This was, under some circumstances, apparently off by one.

If a suggestion was really long, like

```fish
infocmp | string split , | string trim | string match -re . | while read -d = -l key val; test -z "$val"; and continue; string match -q '*%*' -- $val; and continue; test (string replace -ra '\e([\[\]]|\(B).*[\comJKsu]' '' -- a(tput $key)b) = ab; or echo $key $val; end > xterm
```

(I'm assuming longer than $COLUMNS), it would staircase like with a wrong wcwidth.

This reverts commit 15a5c0ed5f.
2019-05-21 23:35:31 +02:00
ridiculousfish
11209b7553 Switch the block stack to a deque instead of vector of shared pointers
That makes the block stack easier to copy.
2019-05-21 10:25:48 -07:00
ridiculousfish
ad57133c7f Switch parser_t to hold its variables via shared_ptr
Preparation for variable stacks with finite lifetimes.
2019-05-21 10:25:48 -07:00
Aaron Gyes
714b8420a9 %s -> %ls for wchar_t
I noticed my debug output for 24bit color mode was garbled due to
this being wrong. I spent a little time trying to get the compiler
to tell us about these, but -Wformat doesn't do anything for wchar
printf functions, and __attribute__((format(printf, n, m))) will
cause an error with wchar_t's, so I gave up and decided to manually
check out every '%s' in the entire project. I found (only) one
more.

debug(0, "%s", wchars) will report warnings for incorrect
specifiers but debug(0, L"%s", wchars) is unable. Thus there may
be reason to prefer not using L"..." as an argument if all else
is equal and it's not necessary.
2019-05-20 13:48:35 -07:00
Fabian Homborg
c2b7e9b2e6 fish_indent: Allow multiple file arguments
Allows `fish_indent -w **.fish` to restyle all fish files under the
current directory.

(This also has the sideeffect of reducing style.fish time by ~10s, as
we only need to invoke `fish_indent` once, instead of once per-file)
2019-05-20 21:04:51 +02:00
ridiculousfish
8e640cdcc5 fish_indent to stop stripping quotes from keywords 2019-05-19 20:56:28 -07:00
ridiculousfish
159d6d669a Remove all block_t subclasses 2019-05-19 14:44:40 -07:00
ridiculousfish
eff4873eca Stop creating subclasses of block_t
Move all block_t creation methods to static methods, and stop creating
subclasses (all of which are now empty).
2019-05-19 14:40:35 -07:00
ridiculousfish
cf92b7626c Migrate event_block's event into block_t 2019-05-19 13:07:06 -07:00
ridiculousfish
8697fa063b Migrate source_block's source_file into block_t
Continue to work towards flattening this hierarchy.
2019-05-19 13:01:59 -07:00
ridiculousfish
fec0e40b5e Migrate function_block name and args into block_t
The goal is to eliminate this block hierarchy.
2019-05-19 12:56:07 -07:00
ridiculousfish
cd7e8f4103 Migrate loop status from blocks into libdata
Blocks will soon need to be shared across parsers. Migrate the loop status
(like break or continue) from the block into the libdata. It turns out we
only ever need one, we don't need to track this per-block.

Make it an enum class.
2019-05-19 12:50:05 -07:00
Fabian Homborg
3efa2ad93b Replace wcslen with math 2019-05-19 18:23:33 +02:00
Fabian Homborg
1e9d41f2c1 Remove now-useless code for detecting {}
This can't happen anymore.
2019-05-19 18:23:33 +02:00