Commit Graph

3988 Commits

Author SHA1 Message Date
Mahmoud Al-Qudsi
72e50d1ab2 Revert "wcsfilecmp: Don't use iswdigit"
This reverts commit 1ab81ab90d.
2021-10-04 18:08:18 -05:00
Aaron Gyes
f9def20180 Update ConfigureChecks, only do the mtime hack for Linux.. on Linux
- Only check for HAVE_CLOCK_GETTIME and HAVE_FUTIMENS on Linux, since
they are only used to implement a Linux-specific workaround related
to mtime precision.
- Make sure that hack is limited to Linux builds
- HAVE_SYS_SYSCTL_H was unused, but we should have been using it
- HAVE_TERMIOS_H was unused, remove it

The only functional change is that unix machines with clock_gettime
and futimens will not bother with a Linux-specific hack, and won't
waste time checking for either during cmake configuration either.
2021-10-02 17:02:53 -07:00
Fabian Homborg
1ab81ab90d wcsfilecmp: Don't use iswdigit
For some godforsaken reason it's slow on glibc

Like, actually, this manages to somehow make "echo **" 10% faster now?

The spec says this matches 0 through 9 always, so this is safe. We
also use this logic in a variety of other places already.
2021-10-01 19:14:27 +02:00
Fabian Homborg
71a0d839a7 wildcard: Use fstatat
This allows us to skip re-wcs2stringing the base_dir again and again
by simply using the fd. It's about 10% faster in my testing.

fstatat is defined by POSIX, so it should be available everywhere.
2021-10-01 19:14:27 +02:00
Aaron Gyes
2f29bb5b51 remove unused macros 2021-10-01 09:07:08 -07:00
Aaron Gyes
dcaa9c7959 fix incorrect error message for 'end --foo' 2021-10-01 04:54:02 -07:00
Aaron Gyes
55ab2f6e6d Remove some unsued macros and a template 2021-10-01 04:50:19 -07:00
Aaron Gyes
d2f47e0523 add missing header 2021-10-01 03:40:32 -07:00
Aaron Gyes
831e9082d7 enum_map stuff to enum_map.h 2021-10-01 03:39:43 -07:00
ridiculousfish
15cee66df1 Wrap even more stuff in anonymous namespaces 2021-09-30 11:33:03 -07:00
ridiculousfish
89c02cfe81 Put lots of things in anonymous namespaces
This is an attempt to help prevent ODR violations by making stuff local
to a file, instead of emitting weak symbols.
2021-09-30 11:33:03 -07:00
ridiculousfish
accba09709 Remove entry_was_evicted from LRU
This was no longer used. This allows us to remove the CRTP bits as well.
2021-09-30 11:33:03 -07:00
ridiculousfish
a6010519df Put ast_t::populator_t into an anonymous namespace
This is part of an effort to reduce the number of weak symbols, so we
can help prevent ODR errors. No functional change here.
2021-09-30 11:33:03 -07:00
Fabian Homborg
78fcbed6f2 wcsfilecmp: Skip towlower/upper if unnecessary
Also for the glob version, because this is just a performance thing.

Makes `echo **` 20% faster - 100ms to 80ms for the fish repo.

This also applies to the future `path` builtin.

Still not a speed demon, but this is a very very easy win.

Now we probably gotta do globbing all in string instead of wcs2stringing ourselves to death.
2021-09-30 18:09:58 +02:00
Fabian Homborg
4ffabd44be Don't add expansion error offset twice
Like the $status commit, this would add the offset to already existing
errors, so

```fish
(foo)
(bar)

something
```

would see the "(foo)" error, store the correct error location, then
see the "(bar)" error, and *add the offset of (bar)* to the "(foo)"
error location.

Solve this by making a new error list and appending it to the existing
ones.

There's a few other ways to solve this, including:

- Stopping after the first error (we only display the first anyway, I
think?)
- Making it so the source location has an "absolute" flag that shows
the offset has already been added (but do we ever need to add two offsets?)

I went with the simpler fix.
2021-09-30 18:09:58 +02:00
Fabian Homborg
6774a514fa Don't set error offset for $status
This would break the location of any prior errors without doing
anything of value.

E.g.

```fish
echo foo | exec grep # this exec is not allowed!

$status

somethingelse # The error might be found here!
```

Would apply the offset of `$status` to the offset of `exec`, locating
the error for `exec` somewhere after $status!
2021-09-30 18:09:58 +02:00
Aaron Gyes
fb32872f6b don't use __has_builtin
GCC doesn't have this until GCC 10. Just assume it exists, as
our compiler requirements mean it should exist.
2021-09-28 23:54:17 -07:00
Aaron Gyes
97bb53e32d Add likely() and unlikely() for our assertions
Allows the compiler to know our bespoke assert functions
are cold paths. This would normally occur somehow for real assert().
Assembly does appear it will save some branches.

Also don't worry about NDEBUG

(This doesn't matter because we rolled our own assert functions.
Thanks @zanchey.)
2021-09-28 23:39:54 -07:00
Aaron Gyes
3fd2da951e remove unused futimes check 2021-09-28 22:02:14 -07:00
ridiculousfish
0c06ca3c3f Mark parser_t::principal as const 2021-09-24 21:09:28 -07:00
Aaron Gyes
5fc9a3c31e exec.h: remove unused declaration 2021-09-24 09:30:25 -07:00
ridiculousfish
13fd3f7a76 Pass in variables directly to screen_t::update
This fixes a TODO. No functional change.
2021-09-23 10:32:55 -07:00
ridiculousfish
8878672014 Switch screen.h free functions to member functions on screen_t
Refactoring only, no functional change here.
2021-09-23 10:32:54 -07:00
ridiculousfish
26f3cee86c History variable expansion to use passed-in vars
This eliminates a call to principal_parser.
2021-09-23 10:29:34 -07:00
Fabian Homborg
45714eb29d Add function scope to read as well
Fixes #8295.
2021-09-23 17:12:37 +02:00
Fabian Homborg
8b093e2651 Remove guessed_emoji_width
Just guess anew when it's not set.

(this still uses the value of $fish_emoji_width, but clamped to 1 or 2
- we could also guess if it's an unusable value, but that's a
different issue and tbh this variable is becoming less and less useful
as time moves on and things move to the new widths by default)

Fixes #8274.
2021-09-23 15:31:05 +02:00
Fabian Homborg
bb115c847e Handle backspaces for visible width
This makes it so we treat backspaces as width -1, but never go below a
0 total width when talking about *lines*, like in screen or string
length --visible.

Fixes #8277.
2021-09-23 12:58:35 +02:00
Fabian Homborg
82a809e2db Check for tputs type via cmake
Instead of testing for ncurses and netbsd.

Fixes #8087.
2021-09-23 10:41:54 +02:00
Aaron Gyes
5a685c16c5 Fix build 2021-09-21 18:33:14 -07:00
Aaron Gyes
933bb96983 remove accidental change 2021-09-21 18:26:44 -07:00
Aaron Gyes
db72a05e89 Tighten up includes, some typedefs -> using
clangd was unable to resolve some symbols
2021-09-21 18:05:53 -07:00
Aaron Gyes
b4b84f6847 builtin.cpp: don't check exit code if not a normal exit
Fixes #8308
2021-09-21 17:49:08 -07:00
Aaron Gyes
cedf9c4d90 builtin_read.cpp: include <termios.h> not "termios.h" 2021-09-21 17:49:08 -07:00
ridiculousfish
971073d429 Disable posix_spawn on OpenBSD
OpenBSD has a posix_spawn implementation which fails to return ENOEXEC
on a shebangless script, causing us to fail the shebangless tests.
Disable posix_spawn on OpenBSD.
2021-09-18 14:08:18 -07:00
ridiculousfish
3ed8a57bc5 Don't use mmap for history files on OpenBSD
OpenBSD's mmap is famously unsychronized with file IO. In theory fsync
and msync can be used to synchronize but I was unable to get it to work.
Just don't use mmap for history on OpenBSD. This fixes the history merge
tests.
2021-09-18 14:08:08 -07:00
ridiculousfish
881b987934 Explicitly error when reading directories
FreeBSD will allow read() on arbitrary directories, causing fish to
produce a nonsense error. Use fstat() to check for directories before
reading.
2021-09-17 20:48:58 -07:00
ridiculousfish
9a2482557d get_hostname_identifier to not return empty hostnames
When getting the hostname to construct the legacy uvar path, if the
hostname is empty, we will create a path pointing at a directory. On
BSDs this path can be successfully open'd and we will produce errors
about invalid uvar files.
2021-09-17 11:18:39 -07:00
ridiculousfish
5a6b966bfe Fix acidentally quadratic wildcard_match
The "linear" wildcard_match actually contained a bug that compared two
strings on every iteration, causing this to be much slower than
necessary. Fix this.
2021-09-16 17:38:03 -07:00
ridiculousfish
d6075885ef Reduce named pipe uvar notifier poll time from 100 msec to 10 msec
To broadcast a uvar change on Linux, we write to a named pipe, wait a bit,
and then read it back. While the pipe is readable, fish will enter a "polling
mode" where it will check for uvar changes every N msec, until the pipe is no
longer readable. If the pipe stays readable for too long (5 seconds), fish
will try to drain it; this may happen if broadcasting instance of fish is
killed before it can read back its data.

In #8209 we have a case where fish is launched in the background to set a
uvar, and then immediately exits, leaving data on the pipe. This means that
we are perpetually in a polling mode until we hit that timeout. Reduce the
timeout to 1 second and the polling interval to 10 msec.

This improves #8209; it doesn't fix it fully but I think it's the best we can
do absent some other IPC mechanism.
2021-09-16 15:25:31 -07:00
Johannes Altmanninger
7f71df0905 builtin cd: recognize EPERM, as it's returned by MacOS
Now that we removed EROTTEN which had the same error code as EPERM,
we can give a less confusing error in case a user has not allowed
their terminal access to a directory.

See #8264
2021-09-17 00:43:12 +02:00
Johannes Altmanninger
eae9ee7f35 builtin cd: print error about broken symlinks
When cd is passed a broken symlink, this changes the error message from
"no such directory" to "broken symbolic link".  This scenario probably
won't happen very often since completion won't suggest broken symlinks
but it can't hurt to give a good error.

Fish used to do this until 7ac5932.  This logic used to be in
path_get_cdpath, however, that is only used for highlighting, so we
don't need error messages there. Changing cd is enough.

Reword from "rotten" to "broken" since that's what file(1) uses.
Clean-up leftovers from old "rotten" code (nomen est omen).

See #8264
2021-09-17 00:43:12 +02:00
Fabian Homborg
41d6a5b9c4 screen: If prompt ends in newline, last line width is 0
This makes us start drawing the commandline at the beginning of the
line again.

See https://github.com/kovidgoyal/kitty/issues/4032#issuecomment-920094245
2021-09-15 17:49:58 +02:00
Fabian Homborg
600dd3bd0f range-for! range-for! range-for! 2021-09-15 17:49:58 +02:00
Fabian Homborg
0e8beab7bf lru: Make parameter const-ref
This has no effect here, but it's used in the tests, where the
override is constref.
2021-09-15 17:49:58 +02:00
Fabian Homborg
4c5d586249 tinyexpr: Check for null-pointer 2021-09-15 17:49:58 +02:00
Fabian Homborg
e38de3df64 iothread: Stop casting intptr_t to void*
This works without, and clang-tidy tells me there's "optimisation
opportunities" that may be concealed.
2021-09-15 17:49:58 +02:00
ridiculousfish
29413665c5 Treat Fitzpatrick emoji modifiers as width 0
Fixes #8275
2021-09-09 18:06:59 -07:00
Fabian Homborg
4046b4cedf Remove redundant variable
normalize_path returns a wcstring, so the check can't fail.

Just pass it directly.
2021-09-09 18:41:38 +02:00
Fabian Homborg
a78d9d8e9a normalize_path: Squash leading slashes even without allow_leading
This currently changes builtin realpath with the "-s" option:

    builtin realpath -s ///tmp

previously would print "///tmp", now it prints "/tmp".

The only thing "allow_leading_double_slashes" does is allow *two*
slashes.

This is important for `path match`, to be introduced in #8265.
2021-09-09 18:41:11 +02:00
ridiculousfish
9aac663bb0 Remove operator< from builtin_data_t
It was unused.
2021-09-06 18:13:47 -07:00
Fabian Homborg
ac7e3a53c1 screen: Allow for doubled escapes in the tmux sequence
See
https://github.com/tmux/tmux/wiki/FAQ#what-is-the-passthrough-escape-sequence-and-how-do-i-use-it.
2021-08-30 18:11:34 +02:00
Fabian Homborg
c02cc110e0 screen: Support tmux escape sequences
Tmux has support for wrapping arbitrary escape sequences inside

```
\ePtmux;\e%s\e\\
```

Since this ends like the screen title escape, we just reuse that.

Characteristically, this is basically undocumented, but we already use
it in e.g. fish_vi_cursor.
2021-08-30 16:55:14 +02:00
Mahmoud Al-Qudsi
069d396ebc Merge branch 'ctest' 2021-08-29 13:03:16 -05:00
Rosen Penev
e62e6c35f7 add constexpr
This was not const before.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-29 19:14:27 +02:00
Mahmoud Al-Qudsi
c82d1980bf Prevent same history test from running multiple times at once
The default matching logic for fish_tests was prefix based, so when we
were running `history` we were also running all history tests. This
causes the test to fail for an unknown reason.
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
aaac759d9a Make test a custom target again and add top-level test targets
Even though we are using CMake's ctest for testing, we still define our
own `make test` target rather than use its default for many reasons:

 * CMake doesn't run tests in-proc or even add each tests as an
   individual node in the ninja dependency tree, instead it just bundles
   all tests into a target called `test` that always just shells out to
   `ctest`, so there are no build-related benefits to not doing that
   ourselves.
 * CMake devs insist that it is appropriate for `make test` to never
   depend on `make all`, i.e. running `make test` does not require any
   of the binaries to be built before testing.
 * The only way to have a test depend on a binary is to add a fake test
   with a name like "build_fish" that executes CMake recursively to
   build the `fish` target.
 * It is not possible to set top-level CTest options/settings such as
   CTEST_PARALLEL_LEVEL from within the CMake configuration file.
 * Circling back to the point about individual tests not being actual
   Makefile targets, CMake does not offer any way to execute a named
   test via the `make`/`ninja`/whatever interface; the only way to
   manually invoke test `foo` is to to manually run `ctest` and specify
   a regex matching `foo` as an argument, e.g. `ctest -R ^foo$`... which
   is really crazy.

With this patch, it is now possible to execute any single test by name,
by invoking the build directly, e.g. to run the `universal.fish` check:
`cmake --build build --target universal.fish` or
`ninja -C build universal.fish`. Unfortunately, this is not integrated
into the Makefile wrapper, so `make universal.fish` won't work (although
this can potentially be hacked around).
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
26092456d4 Add CMake enumeration of low-level fish_tests.cpp tests
Instead of compiling `fish_tests.cpp` dynamically with weakly-linked
symbols and asking it to print the list of all available tests, we
use a magic string `#define`'d as a no-op to allow CMake to regex search
for matching test groups. This speeds up configuration somewhat (by not
compiling anything), but more importantly, it's much less brittle and
doesn't involve and linker dark magic.

There's of course still no getting around the fact that it's really ugly.
2021-08-29 08:56:12 +02:00
Fabian Homborg
4c3cb119fc Actually return when reading file failed
Fixes #8258.
2021-08-29 08:36:54 +02:00
ridiculousfish
7a1c005b42 Switch to using timef instead of gettimeofday
This encapsulates the tricky arithmetic inside timef(), which uses
gettimeofday.
2021-08-27 16:25:33 -07:00
ridiculousfish
7d537eefbb proc_get_jiffies to accept pid directly
No need to accept the mutable proc here.
2021-08-27 13:05:27 -07:00
ridiculousfish
f577c221eb Introduce get_by_sorted_name
Given that we have several lists of things sorted by name, replace a
bunch of ad-hoc lower_bound calls with a single function.
2021-08-26 13:40:37 -07:00
Fabian Homborg
ee2d2caeaa escape_code_length: Test colors last
We have a *lot* of color sequences to try and tparm is slow (on the
whole, when you do this thousands of times).

So let's just check colors last, which makes everything else (which is
comparatively nothing) faster, while barely impacting
colors (benchmarking confirms no measurable difference).

Fixes #8253.
2021-08-26 21:01:55 +02:00
Rosen Penev
a36a26c28b clang-tidy: replace NULL with nullptr
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-25 16:10:17 -07:00
Rosen Penev
ffd5716e70 clang-tidy: replace push_back with emplace_back
clang-tidy marks these as needing emplace_back as the types to not
match.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-25 03:19:46 +02:00
Rosen Penev
a9b4127f68 clang-tidy: run through normal checks
There's a .clang-tidy file in here.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-21 21:59:05 +02:00
Fabian Homborg
70e3e0beac Also remove ephemeral item if command is effectively empty
Fixes #8232.

Note that this needed to have expect_prompt used in the pexpect test -
we might want to add a "catchup" there so you can just ignore the
prompt counter for a bit and pick it back up later.
2021-08-20 19:38:16 +02:00
Rosen Penev
b748417af7 clang-tidy: replace size comparisons with empty
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 18:32:45 +02:00
Rosen Penev
1af9e5d21e clang-tidy: simplify two bool returns
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 18:32:15 +02:00
Fabian Homborg
d4f7e25584
Replace strerror/sys_errlist after fork with our own errors (#8234)
* Remove safe_strerror, safe_perror and safe_append

This no longer works on new glibcs because they removed sys_errlist.

So just hardcode the relevant errno messages (and phrase them better).

Fixes #4183.

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
2021-08-20 17:17:01 +02:00
Rosen Penev
90f006b1cd clang-tidy: use delete
The clang warning for pending_signals_t was about the operator=
return type being wrong (misc-unconventional-assign-operator).

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:33:33 +02:00
Johannes Altmanninger
5de05a810c Tell clang-tidy that expander_t::stage_variables intentionally takes values
We don't want to convert the input to a "wcstring &" because
"stage_variables" needs to have the same type as other stages, so we
can use it in a loop. Communicate that to clang-tidy.

We also don't want to take "wcstring &&". As the Google style guide
states, it's not really beneficial here, and it potentially hurts
readability because it's a relatively obscure feature.
The rest of our code contains a bunch of && parameters.  We might
want to get rid of some of them.

Closes #8227
2021-08-20 01:21:21 +02:00
Rosen Penev
ffa3e0b4f4 convert const ref to value
clang-tidy wrongly sees an std::move to a const ref parameter and
believes it to be pointless. The copy constructor however is deleted.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:16:24 +02:00
Rosen Penev
4ea5189c4f clang-tidy: const reference conversions
These are only read from.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:15:48 +02:00
Rosen Penev
f9af33f223 clang-tidy: remove pointless virtual
override is already used.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:15:23 +02:00
Rosen Penev
faf51e0693 clang-tidy: use for range loops
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-20 01:14:25 +02:00
ridiculousfish
2ca66cff53 Disable job control inside command substitutions
This disables job control inside command substitutions. Prior to this
change, a cmdsub might get its own process group. This caused it to fail
to cancel loops properly. For example:

    while true ; echo (sleep 5) ; end

could not be control-C cancelled, because the signal would go to sleep,
and so the loop would continue on. The simplest way to fix this is to
match other shells and not use job control in cmdsubs.

Related is #1362
2021-08-18 22:20:03 +08:00
Mahmoud Al-Qudsi
3291102045 Refactor deferred_process handling to be more clearly safe
The previous layout confused me for a minute as it suggested it was
possible for `pipe_next_read` to be moved twice (once in the first
conditional block, then again when the deferred process conditional
called `continue` - if and only if the deferred process *was* the last
process in the job. This patch clarifies that can't be the case.
2021-08-17 20:10:19 -05:00
Mahmoud Al-Qudsi
c014c23662 Fix undefined behavior in closing a moved pipe
`pipe_next_read` is moved in the body of the loop, and not
re-initialized the last go around. However, we call
`pipe_next_read.close()` after the loop, which is undefined behavior (as
it's been moved).

Best case scenario, the compiler passed the address of our copy of the
struct to `exec_process_in_job` and beyond, it went out of scope there,
the value of `fd` was set to closed (minus one), and we explicitly call
`.close()` again, in which case it does nothing.

Worst case scenario, the compiler re-uses the storage for the now-moved
struct for something else and our call to `.close()` ends up closing
some other value of `fd` (valid or invalid) and things break.

Aside from the fact that we obviously don't need to close it since it's
not assigned for the last process in the job, it's a RAII object so we
don't have to worry about manually closing it in the first place.
2021-08-17 19:52:15 -05:00
Mahmoud Al-Qudsi
57615504d0 Eliminate variable unused after refactor of wcstringutil.cpp 2021-08-17 19:23:13 -05:00
Mahmoud Al-Qudsi
426fa82f8f Fix recently broken escape_code_length() result
`escape_code_length()` was converted from returning a `size_t` to
returning a `maybe_t<size_t>` but that subtly broke all existing call
sites by forcing all input to go through the slow path of assuming a
zero-length escape sequence was found.

This is because all callers predicated their next action on what amounts
to `if (escape_code_length(...))` which would correctly skip the slow
path when `escape_code_length` returned zero, but after the conversion
to `maybe_t` contained not `maybe_t::none()` but rather
`maybe_t::some(0)` due to coercion of the result from the `size_t` local
`esc_seq_len` to the `maybe_t<size_t>` return value - which, when
coerced to a boolean returns *true* for `maybe_t::some(0)` rather than
false.

The regression was introduced in 7ad855a844
and did not ship in any released versions so no harm, no foul.
2021-08-17 19:04:10 -05:00
Mahmoud Al-Qudsi
daa366eb5a maybe.h: reference header new
This is required for the usage of placement new. Not an issue for fish
as it gets picked up from elsewhere, but it lets one use it in a C++
test directly this way.
2021-08-17 18:57:16 -05:00
Rosen Penev
ba91b39715 replace push_back with emplate_back
The latter forwards the arguments directly.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-17 18:56:19 -05:00
Fabian Homborg
e9ee1820d6 Default emoji width to 2 for iTerm
Hallelujah, they switched to Unicode 9.

See #8220.
2021-08-17 13:30:34 +02:00
Mahmoud Al-Qudsi
5326462116 Catch more zero-index expressions
This expands the sanity check for literal zero indexes that was not
updated when range expansions was introduced.

Closes #8213
2021-08-15 13:48:41 -05:00
Fabian Homborg
c4593828f4
commandline: Add --is-valid option (#8142)
* commandline: Add --is-valid option to query whether it's syntactically complete

This means querying when the commandline is in a state that it could
be executed. Because our `execute` bind function also inserts a
newline if it isn't.

One case that's not handled right now: `execute` also expands
abbreviations, those can technically make the commandline invalid
again.

Unfortunately we have no real way to *check* without doing the
replacement.

Also since abbreviations are only available in command position when
you _execute_ them the commandline will most likely be valid.

This is enough to make transient prompts work:

```fish
function reset-transient --on-event fish_postexec
    set -g TRANSIENT 0
end

function maybe_execute
    if commandline --is-valid
        set -g TRANSIENT 1
        commandline -f repaint
    else
        set -g TRANSIENT 0
    end
    commandline -f execute
end

bind \r maybe_execute
```

and then in `fish_prompt` react to $TRANSIENT being set to 1.
2021-08-14 11:29:22 +02:00
Fabian Homborg
eee38836cf set -q: Return 255 if no variable name was passed
Previously this strictly returned the number of unset variables. So if
no variable was given, it would return *true*, which is highly
suspect.
2021-08-14 10:55:21 +02:00
Fabian Homborg
b5e5732be1 Point wildcard error at a more specific help section
"Expansion" covers *all* the expansions, that's a bit of a handful.

Directly point people towards globbing.
2021-08-11 18:40:37 +02:00
ridiculousfish
fdf8f17397 Stop using thread local vectors
These don't build on macOS 10.9, and are unnecessary anyways.
Thread local variables should only be simple primitives.
2021-08-10 13:07:13 -07:00
Johannes Altmanninger
6bd25ff63a Reword comment 2021-08-10 21:01:39 +02:00
Rosen Penev
a00ebc65af remove make_pair
There are better alternatives with C++11.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-08-05 12:12:28 +02:00
Fabian Homborg
2087a3ca63 Let visible length work with CR and LF
Because we are, ultimately, interested in how many cells a string
occupies, we *have* to handle carriage return (`\r`) and line
feed (`\n`).

A carriage return sets the current tally to 0, and only the longest
tally is kept. The idea here is that the last position is the same as
the last position of the longest string. So:

abcdef\r123

ends up looking like

123def

which is the same width as abcdef, 6.

A line feed meanwhile means we flush the current tally and start a new
one. Every line is printed separately, even if it's given as one.

That's because, well, counting the width over multiple lines
doesn't *help*.

As a sidenote: This is necessarily imperfect, because, while we may
know the width of the terminal ($COLUMNS), we don't know the current
cursor position. So we can only give the width, and the user can then
figure something out on their own.

But for the common case of figuring out how wide the prompt is, this
should do.
2021-08-04 21:09:47 +02:00
Fabian Homborg
a05fc52fc8 Ignore second escape inside an escape code 2021-08-04 21:09:47 +02:00
Fabian Homborg
ca551fdeb9 string: Add length --visible for visible length
Without escapes.

The new option is a bit cheesy, but "width" isn't as expressive and
requires an argument.

Maybe we want "pad" to also require --visible?
2021-08-04 21:09:47 +02:00
Fabian Homborg
a4756ce561 string: Make pad pad to terminal width
This just changes it so it subtracts escape sequences, according to
the current terminal.
2021-08-04 21:09:47 +02:00
Fabian Homborg
7ad855a844 screen: Make escape_code_length public
Uncached, but we don't want to keep this globally, I think?

This is useful for doing string pad/length without escapes.
2021-08-04 21:09:47 +02:00
Fabian Homborg
0059192f61 Allow erasing vars via function-scope
This triggered an assert because the remove code had no idea how to
find the function scope.

Oops!
2021-08-04 17:55:41 +02:00
Fabian Homborg
733114fefb
Add set --function (#8145)
* Add `set --function`

This makes the function's scope available, even inside of blocks. Outside of blocks it's the toplevel local scope.

This removes the need to declare variables locally before use, and will probably end up being the main way variables get set.

E.g.:

```fish
set -l thing
if condition
    set thing one
else
    set thing two
end
```

could be written as

```fish
if condition
    set -f thing one
else
    set -f thing two
end
```

Note: Many scripts shipped with fish use workarounds like `and`/`or`
instead of `if`, so it isn't easy to find good examples.

Also, if there isn't an else-branch in that above, just with

```fish
if condition
    set -f thing one
end
```

that means something different from setting it before! Now, if
`condition` isn't true, it would use a global (or universal) variable of
te same name!

Some more interesting parts:

Because it *is* a local scope, setting a variable `-f` and
`-l` in the toplevel of a function ends up the same:

```fish
function foo2
    set -l foo bar
    set -f foo baz # modifies the *same* variable!
end
```

but setting it locally inside a block creates a new local variable
that shadows the function-scoped variable:

```fish
function foo3
    set -f foo bar
    begin
        set -l foo banana
        # $foo is banana
    end
    # $foo is bar again
end
```

This is how local variables already work. "Local" is actually "block-scoped".

Also `set --show` will only show the closest local scope, so it won't
show a shadowed function-level variable. Again, this is how local
variables already work, and could be done as a separate change.

As a fun tidbit, functions with --no-scope-shadowing can now use this to set variables in the calling function. That's probably okay given that it's already an escape hatch (but to be clear: if it turns out to problematic I reserve the right to remove it).

Fixes #565
2021-08-01 20:08:12 +02:00
Johannes Altmanninger
66709571ed fish_indent: handle tokens with trailing escaped newlines
Fixes #8197
2021-08-01 18:59:45 +02:00
Johannes Altmanninger
3a375c2399 reader: fix regressions when moving between lines
Fixes some regressions from 35ca42413 ("Simplify some parse_util functions").
The tmux tests are not beautiful but I find them easy to write.
Probably a pexpect test would also be enough here?
2021-08-01 17:50:44 +02:00
Fabian Homborg
06acc201f4 Disallow NULLs in function names and paths
These aren't compatible with unix semantics.

Fixes #8195 harder.
2021-08-01 12:23:31 +02:00