Commit Graph

1549 Commits

Author SHA1 Message Date
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