Commit Graph

14638 Commits

Author SHA1 Message Date
Fabian Homborg
6c1ec98e92 prompt_pwd: full-dirs set to 0 means not even last component is safe
Alternative is to print an error.
2021-08-09 17:42:00 +02:00
Fabian Homborg
af2952dd2f Allow passing directories to prompt_pwd
This allows us to test it without cd-ing about the place.
2021-08-09 17:42:00 +02:00
Fabian Homborg
7a8feb4656 prompt_pwd: Allow keeping components full length
And allow passing the parameters as options.
2021-08-09 17:42:00 +02:00
Andrew Schulman
afef67b4e8 Fix dirs returns false when $dirstack is empty 2021-08-09 12:43:03 +02:00
exploide
60a9dcbf05 updated ping completions
support for ping from iputils (version 20210202)
support for ping from inetutils (version 2.1)
support for ping from busybox (version 1.33.1)
support for ping from FreeBSD and macOS (by @juntuu)
2021-08-06 17:08:50 +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
5e46ad645a CHANGELOG string width stuff 2021-08-04 21:12:42 +02:00
Fabian Homborg
3ed49304f2 Completions 2021-08-04 21:09:47 +02:00
Fabian Homborg
b2764ad4b1 docs 2021-08-04 21:09:47 +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
fcbf303e05 Only do the macOS apropos thing if makewhatis is available
This won't work without it, and happens to be broken on jailbroken
iOS.

Fixes #8205.
2021-08-04 18:55:01 +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
Kid
c7c67755d3
Add --function to set completion (#8202)
* Add `--function` to `set` completion

* Resolve review

* Revert other changes
2021-08-04 08:49:51 +02:00
Fabian Homborg
b97a75ff83 CHANGELOG set --function 2021-08-01 20:10:07 +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
1b20e75f19 Run fish_indent on share/**.fish 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
2c420ef728 docs: Document that commands with space will be kept until the next 2021-08-01 14:01:49 +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
Fabian Homborg
0157ac35a4 Autoload: Ignore empty and effectively empty commands
Fixes #8195.
2021-08-01 12:16:46 +02:00
Mahmoud Al-Qudsi
97e514d7ff Use more consistent names for event_t function impls
The names in the implementation differed from those in the header, but
the header names were definitely better (because they correlated across
function calls).
2021-07-31 15:26:09 -05:00
Branch Vincent
bb10cdbd77 add missing git commit completions 2021-07-30 19:39:53 -07:00
Fabian Homborg
0ddf09254d Try to convince Github harder to not count pcre2
We're 44% "shell" because it's counting all of pcre2's autocruft!
2021-07-30 18:36:12 +02:00
Fabian Homborg
0d054f16c4 docs: Remove background from pygments
For some reason I've seen one version of firefox use this over the one
we set in pydoctheme.css. Since we set it there in both light and dark
mode, this one should not be used.
2021-07-30 18:36:12 +02:00
Sam Yu
ac6507776f
Add zypper subcommands completion (#8183)
* Add zypper subcommands completion

rename functions to avoid confusion

* Revert partial changes
2021-07-30 18:24:32 +02:00
exploide
ac81d370cd completion nmap: suppress warning when local scripts folder exists 2021-07-30 17:41:55 +02:00
Fabian Homborg
80888eed57 Remove read_only stuff from env_var_t
This doesn't work.

The real thing that tells if something is read-only is
electric_var_t::readonly().

This wasn't used, and we provide no way to make a variable read-only,
which makes this an unnecessary footgun.
2021-07-30 15:33:08 +02:00
Fabian Homborg
dd3cdbcfc9 Fix crash if $PWD is used as for-loop variable
for PWD in foo; true; end

prints:

>..src/parse_execution.cpp:461: end_execution_reason_t parse_execution_context_t::run_for_statement(const ast::for_header_t&, const ast::job_list_t&): Assertion `retval == ENV_OK' failed.

because this used the wrong way to see if something is read-only.
2021-07-30 15:33:04 +02:00
Fabian Homborg
55732f445a set: Use env_var_t::flags_for() to see if it's read-only
env_var_t::read_only() is basically broken.

It doesn't work for $PWD, as best as I can tell no variable is
read-only except for a hardcoded list of some of the electric ones.

So we should probably remove the entire read_only and
setting_read_only mechanism.
2021-07-30 15:32:58 +02:00
Fabian Homborg
09b8471f5c Test numeric locale
This allows us to test that `test` takes numbers with decimal point even in comma-using locales,
to stop those pesky americans from breaking everything again.

(and yes, we use french to keep myself honest)
2021-07-29 17:20:20 +02:00
Fabian Homborg
4c90ed0e0d Generate french locale
To keep myself honest, we're not gonna choose german
2021-07-29 17:20:20 +02:00
Fabian Homborg
bf1fd733d0 Revert "Extend the fast path of fish_wcstod"
This breaks in comma-using locales (like my own de_DE.UTF-8), because
it still uses the locale-dependent strtod, which will then refuse to
read

   1234.567

Using strtod_l (not in POSIX, I think?) might help, but might also be
a lot slower. Let's revert this for now and figure out if that is
workable.

This reverts commit fba86fb821.
2021-07-29 16:29:12 +02:00
ridiculousfish
fba86fb821 Extend the fast path of fish_wcstod
fish_wcstod had a "fast path" which looked for all digits, otherwise
falling back to wcstod_l. However we now pass the C locale to wcstod_l,
so it is safe to extend the fast path to all ASCII characters.

In practice math parsing would pass strings here like "123 + 456" and
the space and + were knocking us off the fast path. benchmarks/math.fish
goes from 2.3 to 1.4 seconds with this change.
2021-07-28 16:14:55 -07:00
ridiculousfish
32e23c84f4 Clean up parser_t::push_block
Fix some unnecessary copying and unused variables.
2021-07-28 15:37:34 -07:00
ridiculousfish
789261a40c Stop storing is_breakpoint inside the parser
This can also be trivially computed from the block list.
2021-07-28 13:56:33 -07:00
ridiculousfish
b914c94cc1 Stop storing 'is_block' inside the parser
is_block is a field which supports 'status is-block', and also controls
whether notifications get posted. However there is no reason to store
this as a distinct field since it is trivially computed from the block
list. Stop storing it. No functional changes in this commit.
2021-07-28 13:56:33 -07:00
Fabian Homborg
b3cdf4afe1 Hardcode $PWD as read-only for set --show
Through a mechanism I don't entirely understand, $PWD is sometimes
writable (so that `cd` can change it) and sometimes not.

In this case we ended up with it writable, which is wrong.

See #8179.
2021-07-28 22:13:22 +02:00
Fabian Homborg
3db78232c6 Show if a var is read-only with set --show
Fixes #8179.
2021-07-28 21:13:03 +02:00
Kevin Konrad
413fd2fc03 extract argcomplete completion mechanism into its own function 2021-07-28 18:10:59 +02:00
Kevin Konrad
577a273228 add changelog entry for qmk completion 2021-07-28 18:10:59 +02:00
Kevin Konrad
336de2d9fa add completion for qmk 2021-07-28 18:10:59 +02:00
YAKSH BARIYA
0b8b535187
Add completions for gping (#8181) 2021-07-28 17:53:44 +02:00
Branch Vincent
d8465e0a86 document --no-config 2021-07-27 23:00:23 +02:00
Fabian Homborg
8939a71ec6 An empty string means we're on the first line
Oops, this broke up-or-search!
2021-07-27 20:11:32 +02:00
Fabian Homborg
48e696bbb4 Update commandline state before completion
Fixes #8175.
2021-07-27 19:03:35 +02:00