Commit Graph

1680 Commits

Author SHA1 Message Date
ridiculousfish
ac241b7132 Simplify and add tests for ifind 2018-10-21 15:53:58 -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
Fabian Homborg
d4db4f40a4 Remove another unnecessary wcstring->wchar conversion 2018-10-20 20:52:02 +02:00
Fabian Homborg
27c0ee92de Remove a few useless .c_str()
With .c_str(), these call the wchar_t* overloads, which frequently then go on to call wcslen.
Just directly use the wcstring we already have.
2018-10-20 20:51:05 +02:00
ridiculousfish
f4d666f56c Allow user to set and unset path property of variables
This adds flags --path and --unpath to builtin set, analogous to
--export and --unexport. These flags change whether a variable is
marked as a path variable.

Universal variables cannot yet be path variables.
2018-10-19 17:39:21 -07: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
3f3b3a7006 Export arrays as colon delimited, and support path-style variables
This commit begins to bake in a notion of path-style variables.

Prior to this fix, fish would export arrays as ASCII record separator
delimited, except for a whitelist (PATH, CDPATH, MANPATH). This is
surprising and awkward for other programs to deal with, and there's no way
to get similar behavior for other variables like GOPATH or LD_LIBRARY_PATH.

This commit does the following:

1. Exports all arrays as colon delimited strings, instead of RS.

2. Introduces a notion of "path variable." A path variable will be
"colon-delimited" which means it gets colon-separated in quoted expansion,
and automatically splits on colons. In this commit we only do the exporting
part.

Colons are not escaped in exporting; this is deliberate to support uses
like

    `set -x PYTHONPATH "/foo:/bar"`

which ought to work (and already do, we don't want  to make a compat break
here).
2018-10-19 17:29:39 -07:00
ridiculousfish
5fa4e0d2ee Highlight %self as an operator 2018-10-19 16:17:30 -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
6df29b2fd1 Revert "Disable ONLCR mapping of NL output to CR-NL"
This reverts commit 3f820f0edf.
While the premise described by @nbuwe is sound in #4505, we are now
apparently relying on this behavior is some places (although
inadvertently as there doesn't seem to be a deliberate acknowledgement
of that anywhere).

Turning off ONLCR causes things like indented multiline commands to not
appear correct at the tty (subsequent lines appear both at column 0 and
again indented).
2018-10-19 17:49:11 -05:00
Mahmoud Al-Qudsi
3f820f0edf Disable ONLCR mapping of NL output to CR-NL
Per @nbuwe's excellent explanation in #4505, we can save on output
to the tty by maintaining column location after NL by disabling the
ONLCR terminal mode.

Closes #4505.
2018-10-17 21:20:39 -05: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
bb829075d8 Add case-insensitive string/wcstring search 2018-10-16 21:42:55 -05:00
Mahmoud Al-Qudsi
259135b211 fixup! Simplify wildcard_complete prototype
Fix broken build under clang 8.0 under Linux.
2018-10-16 20:38:46 -05:00
ridiculousfish
202bf0bede Tab complete abbreviations
This allows abbreviations to be expanded by tab completions.

Fixes #3233
2018-10-16 16:15:27 -07:00
ridiculousfish
161196fe53 Simplify wildcard_complete prototype
Rather than accepting both a 'description' and a 'description function',
accept just the description function.
2018-10-16 15:43:42 -07:00
Mahmoud Al-Qudsi
0e62dedb26 Correct misdetection of [001] as literal zero index
The control flow in expand.cpp is a bit more complicated than it seemed
at first blush. Ref #4862.
2018-10-15 14:11:37 -05:00
Mahmoud Al-Qudsi
6bc59db721 Detect when running out of cmake build directory
Load fish docs and configuration out of the source and/or build
directories rather from the installed paths when running directly out
of the cmake build directory.

Closes #5255.
2018-10-13 21:48:28 -05:00
ridiculousfish
f212518d3e Allow SIGINT in non-interactive mode
Prior to this fix, fish would swallow SIGINT in non-interactive mode. This
meant that scripts could only be Ctrl-C'd if fish was executing an external
command.

Unblock SIGINT in non-interactive mode.

Fixes #5253
2018-10-12 23:58:14 -07:00
ridiculousfish
c76de58758 Normalize "/" path to "/"
This is one obnoxious function.

Fixes #5250
2018-10-12 22:15:16 -07:00
Mahmoud Al-Qudsi
8c3481a921 Block the history race test from running under WSL
It's always failing, and the current test scripts refuse to progress
after the first failure, making it impossible to test fish under WSL.
2018-10-11 18:54:32 -05:00
ridiculousfish
e363171b8d Switch from strdup to std::string in fish_tests 2018-10-11 09:58:16 -07:00
ridiculousfish
90d89a3262 Use more move constructors in expansion
Reduce allocations by switching to move semantics.
clang-tidy detects some use-after-moves.
2018-10-11 02:03:28 -07:00
ridiculousfish
4c08cbd050 Mark completion move ctor as noexcept
Move constructors aren't used unless we mark this ctor as noexcept.
2018-10-11 02:02:55 -07: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
Mahmoud Al-Qudsi
c6230ddfde Clean up status_builtin options and enums
Drop usage of magic numbers and sort lists where possible.
2018-10-09 22:14:42 -05:00
Mahmoud Al-Qudsi
236556ba05 Update get_executable_path() for FreeBSD
Remove dependency on the Linux compatibility layer's procfs being
installed and mounted when running under FreeBSD by directly querying
the MIB for the path to the running fish executable
(KERN_PROC_PATHNAME). Tested under FreeBSD 11.2-RELEASE.
2018-10-09 19:47:49 -05:00
ridiculousfish
0f0bb1e10f Don't resolve symlinks with cd
This switches fish to a "virtual" PWD, where it no longer uses getcwd to
discover its PWD but instead synthesizes it based on normalizing cd against
the $PWD variable.

Both pwd and $PWD contain the virtual path. pwd is taught about -P to
return the physical path, and -L the logical path (which is the default).

Fixes #3350
2018-10-06 17:03:18 -07:00
ridiculousfish
6ad4d94e12 Introduce path_normalize
This new function performs normalization of paths including dropping
/./ segments, and resolving /../ segments, in preparation for switching
fish to a "virtual" PWD.
2018-10-06 17:03:18 -07:00
ridiculousfish
767b7a2180 Migrate the completion set to owning_lock_t 2018-10-05 09:05:59 -07:00
Mahmoud Al-Qudsi
3875cc60bd Optimize literal_zero_index comparisons
No longer check literal zero after the first non-zero value.
2018-10-01 21:20:13 -05:00
Mahmoud Al-Qudsi
264d8270a7 Emit an error message on literal zero indices
Mostly resolves #4862, though there remains the lingering question of
whether or not to emit a warning to /dev/tty or stderr when a
non-literal-zero index evaluates to zero.
2018-10-01 20:58:26 -05:00
Mahmoud Al-Qudsi
e04130e145 fixup! Add overload of wcstringutil::trim that automatically trims whitespace 2018-10-01 17:22:40 -05:00
Mahmoud Al-Qudsi
f702c42068 Sanitize history item whitespace
Coalesces commands with leading (if even possible) and trailing
whitespace into the same item, improving the experience when iterating
over history entries.

Closes #4908.
2018-10-01 17:12:18 -05:00
Mahmoud Al-Qudsi
a9845dc026 Add overload of wcstringutil::trim that automatically trims whitespace 2018-10-01 17:12:18 -05:00
ridiculousfish
d7cbf3581d Remove retval global from builtin_wait 2018-10-01 09:59:27 -07:00
ridiculousfish
1bc4cf2318 More const and atomic correctness 2018-10-01 09:59:22 -07:00
ridiculousfish
070a43989f Mark a null variable const in builtin_echo 2018-10-01 09:47:45 -07:00
ridiculousfish
a722a4b967 Remove global variables from builtin_commandline
There was no reason to have builtin_commandline store its buffer in a global,
these can be local variables.
2018-10-01 09:34:58 -07:00
ridiculousfish
5735703261 Convert some static wcstring_list_t to C arrays
Saves some allocations at startup.
2018-09-30 19:57:05 -04:00
ridiculousfish
e6d09dc4fe Remove another unnecessary env_var_t creation 2018-09-30 18:30:13 -04:00
ridiculousfish
bd7fea55c4 Remove some unnecessary env_var_t usage 2018-09-30 18:20:59 -04:00
ridiculousfish
6147e9ee0d path_get_cdpath to accept string instead of env_var_t
Unclear why it ever needed an env_var_t. wcstring is sufficient and much
simpler.
2018-09-30 18:13:14 -04:00
ridiculousfish
16da066722 Convert some loops in input.cpp 2018-09-30 18:13:14 -04:00
ridiculousfish
05d14f24d6 Fix a crash in bind
444f9f8715 introduced a bug where we would
use an iterator that had been invalidated by erase(). Fix that.
2018-09-30 18:00:52 -04:00
Fabian Homborg
444f9f8715 Add separation of "preset" bindings
This allows for marking certain bindings as part of a preset, which allows us to

- only erase those when switching presets
- go back to the preset binding when erasing a user binding
- only show user customization if requested
- make bare bind statements in config.fish work (!!!11elf!!!)

Fixes #5191.
Fixes #3699.
2018-09-30 16:54:56 +02:00
ridiculousfish
36a149337b Eliminate / vet and whitelist some more globals 2018-09-29 01:11:15 -04:00
ridiculousfish
0170875ece Add an assert that builtin names are sorted 2018-09-29 00:30:02 -04:00
ridiculousfish
96da62ea87 Revert "Convert list of builtins from sorted array to unordered_set"
This reverts commit d8a1928c24.

It is better to have builtins as static const data to avoid unnecessary
initialization and allocation during startup.
2018-09-29 00:22:24 -04: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
d7b2576fb5 Mark short_options as const everywhere
These were needlessly mutable file-scoped variables.
2018-09-29 00:18:36 -04:00
ridiculousfish
9fd3f35c9a Fix some dead code
Delete some dead code, and migrate some other code under the appropriate
preprocessor check.
2018-09-28 21:26:21 -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
ridiculousfish
a389ca694c Revert "Save history on exec"
This reverts commit 9d0050023c.

This change was not necessary. History is already saved on exec().
2018-09-28 20:20:54 -04:00
ridiculousfish
7a0e72bfa9 env_get_pwd_slash to return L"/" if $PWD is empty or missing
Prior to this change, env_get_pwd_slash() would try to infer the PWD from
getcwd() if $PWD were missing. But this results env_get_pwd_slash() doing
something radically different than $PWD, and also is a lot of code for a
scenario that cannot be reliably reproduced. Just return "/" in this case.
2018-09-28 20:09:45 -04:00
Mahmoud Al-Qudsi
dd8c4cfb33 fixup! Move get_runtime_path() to env.cpp and expose it in env.h 2018-09-28 11:49:06 -05:00
Mahmoud Al-Qudsi
9d0050023c Save history on exec
See https://github.com/fish-shell/fish-shell/issues/907

May not fully resolve the issue, needs to be tested before #907 can be closed.
2018-09-28 11:34:07 -05:00
Mahmoud Al-Qudsi
8c14f0f30f Add vector of cleanup/termination events to be executed before quit 2018-09-28 11:34:07 -05:00
Mahmoud Al-Qudsi
e045b045da Move get_runtime_path() to env.cpp and expose it in env.h
It was previously a file-local static function in env_universal.cpp.
2018-09-28 11:33:11 -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
ridiculousfish
cc99e8d510 Switch tokenizer_error back to just an error code
Rather than having tokenizer_error as pointers to objects, switch it back
to just an error code value. This makes reasoning about it easier since
it's immutable values instead of mutable objects, and it avoids allocation
during startup.
2018-09-27 21:40:51 -04:00
ridiculousfish
f28f9792b3 Remove ENUM_FLAGS
This define added operator overloading via preprocessor macros, which is
more magic than necessary. It was only used in one place.
2018-09-27 21:25:58 -04:00
Mahmoud Al-Qudsi
f5083d7bab Set $status after while depending on whether loop was entered
Closes #4982.
2018-09-27 08:15:45 -05:00
Fabian Homborg
6c1ea03e9c [pager] Do full fuzzy search
Just like the completion code, this now matches e.g. `f-p` to
`format-branch`.

Fixes #5213.
2018-09-27 13:18:26 +02:00
Mahmoud Al-Qudsi
1f440eb063 Fix crash when nodeptr is null and node->get_source() is called
Responsible for the crash during the low-level tests after
9c63ad3209.
2018-09-26 21:03:55 -05:00
Mahmoud Al-Qudsi
a0110d296c Refactor function_get_[desc/definition] to pass-by-reference 2018-09-26 21:03:55 -05:00
Mahmoud Al-Qudsi
a02c54c8c7 Fix completion descriptions for functions
At some point the completion code was refactored and in the event where
no explicit function description was passed into `resolve_description()`
it would attempt to use the `desc_func` parameter but pass in the
_remaining_ part of the completion rather than the full text, which
would obviously fail.

e.g. if completing `foo<TAB>`, for function `foobar` it would attempt to
find the description for a function named `bar` instead of `foobar`.

Closes #5206.
2018-09-26 21:03:55 -05:00
Mahmoud Al-Qudsi
2db759813d Revert "Fix completion descriptions for functions"
This reverts commit 9c63ad3209 until I can
figure out what is causing the assertion and test failures.

It *seems* to be that passing in the correct function name to the
description lookup is causing a previously present error to be realized,
but I can't yet be certain.
2018-09-26 14:10:46 -05:00
Mahmoud Al-Qudsi
9c63ad3209 Fix completion descriptions for functions
At some point the completion code was refactored and in the event where
no explicit function description was passed into `resolve_description()`
it would attempt to use the `desc_func` parameter but pass in the
_remaining_ part of the completion rather than the full text, which
would obviously fail.

e.g. if completing `foo<TAB>`, for function `foobar` it would attempt to
find the description for a function named `bar` instead of `foodbar`.

Closes #5206.
2018-09-26 13:18:29 -05:00
Mahmoud Al-Qudsi
d31cc08fd9 Add basic RAII wrapper for DIR*
At some point we should also fold the wreaddir_* functions into this new
dir_t struct as well.
2018-09-26 12:36:20 -05:00
Amos Bird
a483643626 fix enum warning. 2018-09-22 11:58:55 +02:00
Mahmoud Al-Qudsi
5b59ab3d9c Add workaround to env_get_pwd_slash() for cases where PWD is not set
There's been no reproducible case entered for #5080, but the stack trace
indicates the problem is with env_get_pwd_slash() returning an empty
string, which isn't a string that terminates in `/`.

In addition to making the failure case to return the path `./` (which
has the benefit of having the same meaning as $PWD), trying a little bit
harder to retrieve the real PWD by using getcwd(3). While
get_current_dir(3) is documented as relying on PWD, getcwd(3) does not
mention any such caveats, so it's possible that it will work even if
something is breaking PWD.

Just a thought, but it's possible if due to some recursion PWD surpassed
some predetermined value (maybe PATH_MAX) that PWD (on certain platforms
or under certain enivronments) won't be set (hence the code that deals
with ERANGE errors from the getcwd(3) call).

Closes #5080.
2018-09-19 18:16:54 -05:00
David Adam
fde74d489c Fix build on Linux
Broken in dc250e0c29
2018-09-19 10:55:36 +08:00
Mahmoud Al-Qudsi
dc250e0c29 Fix fish startup behavior in presence of unset $USER
As reported in fish-shell/fish-shell#5180, when the USER environment
variable is not set and fish is started, `get_runtime_path()` returns a
blank string. At some point in the past, this was called after
`setup_user()` in env.cpp, but this is no longer the case.

This commit removes the reliance on the $USER environment variable
entirely, and instead uses `getpwuid(geteuid()).pw_name` to retrieve the
current username.

Closes #5180.
2018-09-18 21:03:04 -05:00
Fabian Homborg
0e82fcd999 Always notify about crashes
And by crash I mean anything that exits with SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGSYS.

Fixes #4962.
2018-09-18 21:22:15 +02:00
ridiculousfish
e6863a90c8 Don't reset the screen after emitting a BEL
Fixes #3693
2018-09-16 16:25:49 -07:00
ridiculousfish
f3da54d99c Convert some iterators to C++-11 range-based loops 2018-09-16 15:49:18 -07:00
Fabian Homborg
3ba74b3195 [string] Match everything with an empty pattern and -e
I.e. `string match --entire "" -- banana` used to match nothing, now
it matches everything.

Fixes #4971.
2018-09-16 13:03:15 +02:00
Fabian Homborg
9be7288fab expansion: Only clamp ranges when not forcing direction
This caused `$var[2..-1]` to still expand to $var[1] if only one
element was given.

Fixup for #4965.

Fixes #5187.
2018-09-15 11:07:29 +02:00
ridiculousfish
ce174afabf Rename my_env_set to more useful env_set_reporting_errors 2018-09-11 09:32:44 -07:00
ridiculousfish
daf520db0a Reformat all files 2018-09-08 22:19:05 -07:00
ridiculousfish
6e6fcda8e2 Get history working in web_config again 2018-09-08 22:13:54 -07: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
8b277e711e Large refactor of exec.cpp
Break up that monster function.
2018-09-03 15:57:11 -07:00
ridiculousfish
eca4d113c6 Factor do_fork into a real function 2018-09-03 14:33:53 -07:00
ridiculousfish
2a62e18635 Remove child_forked and child_spawned
These variables weren't used for anything.
2018-09-03 13:31:03 -07:00
ridiculousfish
f7a020ad33 Rename launch process to exec_process_in_job
This avoids a name collision with another launch_process
2018-09-03 11:18:39 -07:00
ridiculousfish
48c510572b Factor out launch_process from exec.cpp
Makes the monster function slightly more tractable.
2018-09-01 14:54:23 -07:00
ridiculousfish
753639aa9c Reduce the scope of pid in exec_job 2018-09-01 14:39:32 -07:00
ridiculousfish
ec9c592edc Adopt autoclose_fd_t in exec_job 2018-09-01 14:27:58 -07:00
ridiculousfish
274c77cf0c Add autoclose_fd_t for helping to manage file descriptors 2018-09-01 14:27:36 -07:00
ridiculousfish
9269a5e0a8 Clean up abbreviation implementation a bit 2018-09-01 13:18:34 -07:00
ridiculousfish
051605b593 Cleap up owning_lock interface
Use some operator overloading to avoid the weird interface of acquired_lock.
2018-09-01 13:11:42 -07:00
ridiculousfish
1a9e3761ae Add highlighting tests for empty variables 2018-09-01 12:05:52 -07:00
ridiculousfish
7bd26f9ff0 Teach syntax highlighting about variables in commands 2018-09-01 12:00:56 -07:00
ridiculousfish
865a4647ae Allow variables in commands
Syntax highlighting for these coming in next commit.

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

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

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

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

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

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

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

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

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

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

This merges some changes to history that may help to mitigate the crashes seen in #5088 . These SIGBUS crashes occur when reading a memory mapping whose underlying file was truncated. It's not clear why this should occur more often on NFS (or ever). However memory mapping over NFS is sketchy anyways so this is desirable regardless.
2018-07-21 13:51:49 -07:00
ridiculousfish
c636a455a0 Add locking to try_complete_user
This uses the thread-unsafe getpwent(). Add a lock around the whole section
to avoid the crash identified in #5088
2018-07-15 15:50:56 -07:00