Commit Graph

241 Commits

Author SHA1 Message Date
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
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
835c6ffa67 clang-format all files 2019-05-27 19:47:13 -07:00
ridiculousfish
ea9d1ad82f Convert debug(0) calls to FLOG 2019-05-27 17:31:17 -07:00
ridiculousfish
b405b979ec Eliminate the CHECK() macro
This thing was pretty useless.
2019-05-27 17:24:19 -07:00
ridiculousfish
5a4df9dd3a Use sigint_checker_t in debug_thread_error 2019-05-25 19:19:03 -07: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
967c1d51ee Only do brace expansion if they contain a variable or ","
Brace expansion with single words in it is quite useless - `HEAD@{0}`
expanding to `HEAD@0` breaks git.

So we complicate the rule slightly - if there is no variable expansion
or "," inside of braces, they are just treated as literal braces.

Note that this is technically backwards-incompatible, because

    echo foo{0}

will now print `foo{0}` instead of `foo0`. However that's a
technicality because the braces were literally useless in that case.

Our tests needed to be adjusted, but that's because they are meant to
exercise this in weird ways.

I don't believe this will break any code in practice.

Fixes #5869.
2019-05-19 18:23:27 +02:00
ridiculousfish
277db64804 Force termsize back to valid in get_current_winsize()
get_current_winsize() is intended to be lazy. It does the following:

1. Gets the termsize from the kernel
2. Compares it against the current value
3. If changed, sets COLUMNS and LINES variables

Upon setting these variables, we notice that the termsize has changed
and invalidate the termsize. Thus we were doing this work multiple times
on every screen repaint.

Put back an old hack that just marked the termsize as valid at the end
of get_current_winsize().
2019-05-13 14:05:42 -07:00
ridiculousfish
234c97e6d2 Remove some unused variables 2019-05-12 18:23:00 -07:00
ridiculousfish
8031fa3bdb Stop using atomic types for non-primitives
atomic<winsize> requires linking libatomic on some platforms which is
annoying. Remove the one use.

Fixes #5865
2019-05-12 13:07:37 -07:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
ridiculousfish
e2c66a8131 Make termsize thread safe 2019-05-04 20:58:35 -07:00
ridiculousfish
fe68287cb0 Make miscellaneous variables thread-safe 2019-05-04 20:58:35 -07:00
ridiculousfish
f66e010949 Turn a lot of common.h variables into getter functions
Improves thread safety.
2019-05-04 20:58:35 -07:00
ridiculousfish
ec45f31ad1 Make debug_level an atomic
Fixes a tsan warning
2019-05-04 15:28:44 -07:00
Aaron Gyes
4e555aebec Remove is_whitespace and whitespace character string declarations
I don't doubt such functions and character arrays could be useful,
to keep things consistent, but they are not actually being used.
2019-04-06 02:07:56 -07:00
ridiculousfish
71f26a6813 Remove INPUT_COMMON_BASE
We no longer store readline commands as characters, so there's no need to
reserve character space for them.
2019-03-23 23:31:37 -07:00
Mahmoud Al-Qudsi
c50cce298d Allow the omitted new line character to be more than one char
The code already allowed for variable width (multicell) *display* of the
newline omitted character, but there was no way to define it as being
more than one `wchar_t`.

This lets us use a string on console sessions (^J aka newline feed)
instead of an ambiguous character like `@` (used in some versions of
vim for ^M) or `~` (what we were using).
2019-03-20 21:47:34 -05:00
Mahmoud Al-Qudsi
753d489376 Fall back to simpler special characters in console sessions 2019-03-20 21:47:34 -05:00
Mahmoud Al-Qudsi
4aded78fc9 Add is_console_session() to detect physical vty 2019-03-20 21:47:32 -05: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
2bf554ae5e Simplify valid_var_name 2019-03-14 10:29:16 -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
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
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
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
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
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
a333c2f01d Fix some compile warnings 2019-01-10 20:59:47 -08:00
ridiculousfish
3b1709180f Instantize env_get 2019-01-10 20:07:53 -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
Mahmoud Al-Qudsi
bfe08a471d Remove fish_mutex_t wrapper around std::mutex
@ridiculousfish had introduced this in 3a45cad12e
to work around an issue with Coverity Scan where it couldn't tell the
mutex was correctly locked, but even with the `fish_mutex_t` hack, it
still emits the same warnings, so there's no pointing in keeping it.
2018-12-30 20:37:36 -06:00
Mahmoud Al-Qudsi
077d656b87 Allow redeclaration of main process via setup_fork_guards()
This is necessary for the history race condition test to succeed.

(That test is permanently disabled under WSL (as it always fails) so I
didn't catch this on my end.)
2018-12-30 20:23:39 -06:00
Mahmoud Al-Qudsi
b4301ff54f Drop initial_pid and optimize debug_shared() fast case
If we are running on the main thread, don't call `getpid()`
unnecessarily from `debug_shared()`.
2018-12-30 19:55:24 -06:00
Mahmoud Al-Qudsi
8dddc62aeb Optimize ASSERT_IS_NOT_FORKED_CHILD()
Use `pthread_atfork()` to mark child processes as dirty when `fork()` is
invoked rather than needing to call into the kernel each time
`ASSERT_IS_NOT_FORKED_CHILD()` is called.

This makes simple test cases that hit `ASSERT_IS_NOT_FORKED_CHILD()` 1.8x faster.

                        ------------------------

With a7998c4829 reverted but before this optimization:

```
mqudsi@ZBOOK ~/r/fish-shell> hyperfine -S build/fish 'for i in (seq 100000); test 1 = 1; end'
Benchmark #1: for i in (seq 100000); test 1 = 1; end

  Time (mean ± σ):     717.8 ms ±  14.9 ms    [User: 503.4 ms, System: 216.2 ms]
  Range (min … max):   692.3 ms … 740.2 ms
```

With a7998c4829 reverted and with this optimization:

```
mqudsi@ZBOOK ~/r/fish-shell> hyperfine -S build/fish 'for i in (seq 100000); test 1 = 1; end'
Benchmark #1: for i in (seq 100000); test 1 = 1; end

  Time (mean ± σ):     397.2 ms ±  22.3 ms    [User: 322.1 ms, System: 79.3 ms]
  Range (min … max):   376.0 ms … 444.0 ms
```

Without a7998c4829 reverted and with this optimization:

mqudsi@ZBOOK ~/r/fish-shell> hyperfine -S build/fish 'for i in (seq 100000); test 1 = 1; end'
Benchmark #1: for i in (seq 100000); test 1 = 1; end

  Time (mean ± σ):     423.4 ms ±  51.6 ms    [User: 363.2 ms, System: 61.3 ms]
  Range (min … max):   378.4 ms … 541.1 ms
```
2018-12-30 19:55:24 -06:00
Mahmoud Al-Qudsi
840619197e Optimize ASSERT_IS_MAIN_THREAD()
By using a user-land thread-local integer and lock-free (at least under
x86/x64) atomics, we can implement a safe `assert_is_main_thread()`
without calling into the kernel. Thread-local variables are part of
C++11.

This is called a lot in some performance-sensitive areas, so it is worth
optimizing.
2018-12-30 19:25:50 -06:00
Fabian Homborg
cf16d39872 Explicitly mark fallthrough
Silences a compiler warning (that is otherwise a good thing!)
2018-12-11 18:23:37 +01:00
Aaron Gyes
0b45b474f3 Update bugreport()
I left this out of the last commit accidentally.
2018-12-11 02:50:03 -08:00
Aaron Gyes
fe67cc4f6e Revert "Show how fish was executed, using argv[0] for program_name"
This reverts commit 1cb8b2a87b.

argv[0] has the full path in it for a user when he executes it
out of $PATH. This is really annoying in the title which uses $_.
2018-11-28 06:08:24 -08:00
Aaron Gyes
1cb8b2a87b Show how fish was executed, using argv[0] for program_name
... rather than hard code it to "fish". This affects
what is found in $_ and improves the errors:

For example, if fish was ran with ./fish, instead of
something like:

  fish: Expected 3 surprises, only got 2 surprises

we'll see:

 ./fish: Expected 3 surprises, only got 2 surprises

like most other shell utilities. It's just a tiny bit
of detail that can avoid confusion.
2018-11-27 11:57:09 -08:00
Mahmoud Al-Qudsi
31d17f4559 Rename string escape --style=pcre2 to string escape --style=regex 2018-11-16 20:22:06 -06:00
Mahmoud Al-Qudsi
e160cde606 Implement PCRE2 escaping
Closes #5309.
2018-11-15 12:00:56 -06:00
Fabian Homborg
460bc00698 Fix string escape var and url styles
Turns out I broke these in my zeal to remove wcs2string.

This reverts commit 583d771b10.

Fixes #5322.
2018-11-07 12:48:11 +01:00
Mahmoud Al-Qudsi
1015e74480 Treat _ and - alike for case-insensitive fuzzy matching
Closes #3584.
2018-10-28 10:35:32 -05:00
ridiculousfish
11d523e61a Build out support for multiple file formats in uvars
This is in preparation for adjusting the file format to support path
variables.
2018-10-21 15:56:05 -07:00
ridiculousfish
fcd4a44b98 Correct check and add a basic test for fuzzy_match_substring_case_insensitive 2018-10-21 12:02:38 -07:00
ridiculousfish
00b1dd861e Merge branch 'splitenv_1.8'
This merges support for PATH variables. Closes #5245
2018-10-20 12:51:51 -07:00
Fabian Homborg
6eccf6557f common: Pass in length for wcs2str with wcstring
Removes _two_ wcslen calls.
2018-10-20 20:52:02 +02:00
ridiculousfish
5947aa0171 Join variables by their delimiter in quoted expansion
This switches quoted expansion like "$foo" to use foo's delimiter instead of
space. The delimiter is space for normal variables and colonf or path variables.
Expansions like "$PATH" will now expand using ':'.
2018-10-19 17:35:36 -07:00
ridiculousfish
d73c487d60 Restore %self to refer to the fish pid
This brings back the %self argument. Like the original %self it only expands
if the argument is literally %self.
2018-10-19 16:17:25 -07:00
Mahmoud Al-Qudsi
dfe6bc531e Enable case-insensitive substring fuzzy matching
Adds a new match mode for `string_fuzzy_match_t` that matches against a
case-insensitive subsequence within a string, e.g. `LL` now (partially)
matches against `hello`. This is implemented as a separate mode, given a
lower priority of match than a same-case match (when present).

Note that `fuzzy_match_subsequence_insertions_only` has purposely not
been extended with a case-insensitive version as that would be a)
unlikely to match often, and b) adding a second inefficient fuzzy search
to something that's queried a lot. Perhaps `subsequence_insertions_only`
can simply be changed to be a case-insensitive comparison in the future?

Closes #1196. Affects #3978.
2018-10-16 21:45:04 -05:00
Mahmoud Al-Qudsi
1f0085bc08 fixup! Add status fish-path
Fixes broken macOS build. I'm not sure how the code used to compile
without including `dyld.h` previously, perhaps a different header used
to pull it in?
2018-10-10 00:29:45 -05:00
Mahmoud Al-Qudsi
e212269ab1 Add status fish-path
Retrieves the fully resolved path to the currently executing fish binary
(regardless of PATH). Can be used to ensure that the same fish is
launched again from a script.

`get_executable_path()` moved from fish binary to libfish, also cleaned
up some duplicated (but differing!) definitions of PATH_MAX (which was
used by that function) in the process.
2018-10-09 22:34:41 -05:00
ridiculousfish
20cb62440c Eliminate some mutable global variables
Make them const or otherwise get rid of them
2018-09-29 00:20:50 -04:00
ridiculousfish
a17a815c87 Revert "Add vector of cleanup/termination events to be executed before quit"
This reverts commit 8c14f0f30f.

This list is not reliable - there are many ways for fish to quit that does not
invoke these functions. It's also not necessary since the history is correctly
saved on exec.
2018-09-28 20:21:23 -04:00
Mahmoud Al-Qudsi
8c14f0f30f Add vector of cleanup/termination events to be executed before quit 2018-09-28 11:34:07 -05:00
ridiculousfish
a1728d61af Report errors on invalid replacements in string replace
If the replacement in `string replace` is invalid, prior to this fix we would
enter into an infinite loop trying to parse it. Instead report errors correctly.

Fixes #3381
2018-09-27 22:28:39 -04:00
ridiculousfish
ae54b66799 Fix string 2018-09-27 22:23:03 -04:00
Amos Bird
a483643626 fix enum warning. 2018-09-22 11:58:55 +02:00
ridiculousfish
ca61fc1bf8 Stop retrying close() on EINTR
https://lwn.net/Articles/576478/
http://austingroupbugs.net/view.php?id=529
https://sourceware.org/bugzilla/show_bug.cgi?id=14627
2018-09-05 21:49:31 -07:00
ridiculousfish
274c77cf0c Add autoclose_fd_t for helping to manage file descriptors 2018-09-01 14:27:36 -07:00
ridiculousfish
1473f952d4 Make contains() more general
Allow contains() to find arbitrary values in arbitrary vectors, and adopt it
in place of std::find.
2018-08-11 22:23:20 -07:00
ridiculousfish
44bae29039 Add a debug_escape function
This function for debugging makes it easier to understand what special
characters are present in a string.
2018-06-23 13:15:32 -07:00
Mahmoud Al-Qudsi
dcced5f1bc Replace \e with \x1B, as the former is a gcc extension
While supported by gcc and clang, \e is a gcc-specific extension and not
formally defined in the C or C++ standards.

See [0] for a list of valid escapes.

[0]: https://stackoverflow.com/a/10220539/17027
2018-06-18 00:01:47 -05:00
Fabian Homborg
583d771b10 Fix escape_string_var for UTF-16
We're now actually handling wchar_t here, so comparing the 0x80 bit
would break for UTF-16, causing ASCII false-positives.

Also simplifies a bit, since we no longer need a second variable.
2018-05-28 12:10:40 +02:00
Fabian Homborg
b2b4ab4bab constref more things
Thanks @ridiculousfish!
2018-05-28 12:10:40 +02:00
Fabian Homborg
4dc1c6ca39 [string] Allow url/var escaping to handle NULs
Fixes #4605.
2018-05-28 12:10:40 +02:00
Fabian Homborg
a229f703ae Allow escape_string_url from escape_string with wcstring
This was an oversight.
2018-05-28 12:10:39 +02:00
Fabian Homborg
338b40bb43 Trust the passed size in escape_string_script
This allows it to handle NULs.
2018-05-28 12:10:39 +02:00
ridiculousfish
4194b4efee Add a feature_test() function
This is a convenience over fish_features().test()
2018-05-06 11:20:15 -07:00
ridiculousfish
762c31be87 Feature flag support for ? wildcard
This partially reverts 6e56637cf0 and #4520
by bringing back the ? wildcard, guarded by the qmark-noglob feature flag.
2018-05-06 11:20:15 -07:00
ridiculousfish
902af26253 Bring back caret redirections under a feature flag
This partially reverts 5b489ca30f, with
carets acting as redirections unless the stderr-nocaret flag is set.
This flag is off by default but may be enabled on the command line:

fish --features stderr-nocaret
2018-05-06 11:20:14 -07:00
Fabian Homborg
baeeef3233 Remove triggerable assert in unescape_string_internal
Fixes #4954 - in a hacky way.
2018-05-02 16:35:56 +02:00
Mahmoud Al-Qudsi
a9b582d2a8 Block .dll files from completion as potential heads under WSL 2018-04-14 23:56:30 -05:00
Peter Ammon
5b489ca30f Remove caret redirection
This removes the caret as a shorthand for redirecting stderr.

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

Fixes #4394
2018-04-01 13:48:21 -07:00
ridiculousfish
6e56637cf0 Remove support for the ? wildcard
Fixes #4520
2018-03-31 16:54:50 -07:00
Mahmoud Al-Qudsi
412c5aeaa6 Use alternative Unicode glyphs if compiled under Windows/WSL
The two unicode glyphs used to represent missing new lines and redacted
characters for secure entry are both not present in the glyph tables of
the default font under Windows (Consolas and Lucida Console), use an
alternative glyph instead.

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

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

Fixes #4846
2018-03-24 23:42:09 -07:00
Mahmoud Al-Qudsi
0b96b516d5 Improve and expand is_whitespace helper functions 2018-03-12 08:06:50 -05:00
Mahmoud Al-Qudsi
24afff1c77 Handle whitespace within parameter expansion tokens
From the discussion in #3802, handling spaces within braces more
gracefully. Leading and trailing whitespace that isn't quoted or escaped
is stripped, whitespace in the middle is preserved. Any whitespace
encountered within expansion tokens is treated as a single space,
similar to how programming languages that don't hard break tokens/quotes
on line endings would.
2018-03-11 22:02:43 -05:00
Mahmoud Al-Qudsi
1629d339de Properly parse spaces and escaped/quoted spaces in expansion braces 2018-03-11 19:51:54 -05:00
Mahmoud Al-Qudsi
65a03c86cb Rename BRACKET in reference to { to BRACE instead per #3802
This `{` is a curly brace. This `[` is a square bracket.
2018-03-10 13:16:53 -06:00
Mahmoud Al-Qudsi
1fbf810946 Unify ellipsis_str[ing] with common variable set once 2018-03-09 14:40:35 -06:00
Mahmoud Al-Qudsi
e45e2bf20e Initial removal of '%' syntax for process/job expansion 2018-03-09 03:36:10 -06:00
Mahmoud Al-Qudsi
3c895c2839 Add whitespace helpers to complete.h/cpp 2018-03-06 12:52:42 -06:00
Mahmoud Al-Qudsi
000892e315 Use constexpr for is_windows_subsystem_for_linux()
To guarantee that at runtime there will be no branching, using a CMAKE
test/define combined with a constexpr wrapper for code-friendliness.
2018-03-04 21:13:31 -06:00
ridiculousfish
74e6a82849 Remove explicit 'void' parameters. 2018-02-18 19:12:45 -08:00
ridiculousfish
3a45cad12e Introduce fish_mutex_t wrapping std::mutex
Add a fish-specific wrapper around std::mutex that records whether it is
locked in a bool. This is to make ASSERT_IS_LOCKED() simpler (it can just
check the boolean instead of relying on try_lock) which will make Coverity
Scan happier.

Some details: Coverity Scan was complaining about an apparent double-unlock
because it's unaware of the semantics of try_lock(). Specifically fish
asserts that a lock is locked by asserting that try_lock fails; if it
succeeds fish prints an error and then unlocks the lock (so as not to leave
it locked). This unlock is of course correct, but it confused Coverity Scan.
2018-02-08 22:18:59 -08:00
Mahmoud Al-Qudsi
fbc6c68f3d Handle error opening /dev/null in redirect_tty_output
This fixes coverity scan defect number 7520299
2018-02-08 17:05:13 -06:00
Mahmoud Al-Qudsi
3083e0ea80 Work around false positive RESOURCE_LEAK in coverity scan
Fixes defect number 7520322
2018-02-08 16:59:38 -06:00
Mahmoud Al-Qudsi
82b7e6de69 Fix unused code (coverity defect #7520283)
Due to the logic above, isz cannot be zero if we take the else branch.
2018-02-08 16:54:28 -06:00