Commit Graph

372 Commits

Author SHA1 Message Date
oliver 0faf67ce9a
feat(main): highlight invalid apt subcommands distinctly
Detect apt subcommands after runnable apt invocations and mark known
subcommands as commands while styling unknown ones as unknown tokens.

Load apt subcommands lazily from apt help with a built-in fallback list so
highlighting works across apt versions. Add tests for valid and invalid apt
subcommand handling.feat(main): highlight invalid apt subcommands distinctly

Detect apt subcommands after runnable apt invocations and mark known
subcommands as commands while styling unknown ones as unknown tokens.

Load apt subcommands lazily from apt help with a built-in fallback list so
highlighting works across apt versions. Add tests for valid and invalid apt
subcommand handling.
2026-06-06 22:18:09 +08:00
Daniel Shahaf 5eb677bb0f 'main' tests: Don't assume ps(1) is available.
It's actually unavailable in the minimal chroots Debian builds our
package on.  That's allowed by POSIX, which specifies ps(1) to be
optional, whereas id(1) —

- is not optional in POSIX
- should exist on every system anyone might run the testsuite on
- has the same length name, so test expectations don't have to be updated
- doesn't take a filename argument (ditto)

That does make the pipeline as a whole somewhat nonsensical
semantically, but it remains just as valid syntactically.
2024-11-21 15:09:26 +00:00
Matthew Martin e0165eaa73 main: Refactor __is_redirection
Fixes #942.
2024-01-06 12:36:52 -06:00
m0viefreak 0b5b3dcc0c tests: parameter-to-global-alias: Use alias name less likely to clash 2023-10-27 22:05:00 -05:00
Daniel Shahaf c10808ad5f main: New test for issue #854 2022-01-31 09:54:57 +00:00
Matthew Martin f0e6a8ef5c main: Honor shwordsplit when expanding parameters
Closes #687, #818.
2021-06-28 23:02:31 -05:00
Nikola Knezevic e8517244f7 main: Allow for "]" in shell aliases
PR #776 fixed an issue with complex aliases and expansion. However, this change
also introduced a problem with aliases which contain `]` (for example, commonly
seen on macOS: `alias ]=open`), due to using an associative array `seen_alias`,
indexed by the alias name. Due to `"$seen_alias[$arg]"`, it would fail when
`$arg` is expanded to anything containing `]`'. Thus, typing `] /` would result
in:

```
> ] /
(anon):unset:3: seen_alias[]]: invalid parameter name
```

This change fixes the issue by ensuring we properly access keys in the
associative array `seen_alias`.

Older versions of zsh have issues with map keys having special
characters, especially lacking ways to remove such keys. The
issue is described in detail in
https://unix.stackexchange.com/questions/626393/in-zsh-how-do-i-unset-an-arbitrary-associative-array-element.

This fix uses proposal from
[zsh-workers/43269](https://www.zsh.org/mla/workers/2018/msg01073.html),
discovered by Stephane Chazelas, that boils down to avoid removing keys
from the map, and reconstruct the map anew with some keys omitted.

Co-authored-by: @phy1729
2021-03-04 20:29:43 -06:00
Daniel Shahaf 205bc7ea19 'main': Disable a lint warning when env(1) was followed by a pipe.
Fixes #797.
2021-03-01 20:21:39 +00:00
Matthew Martin 75c0eb0717 main: Remember nest level an alias was seen in for seen_alias
Fixes #775.
2020-12-25 16:39:07 -06:00
Matthew Martin 2ebfa6a598 main: Forget seen aliases when starting a new command
Fixes #769
2020-10-12 19:29:53 -05:00
Matthew Martin aac09942b8 Revert "tests: Add a test that 'rehash' isn't run."
This reverts commit 62c5575848.

The test fails when zsh/parameter is available.
2020-10-12 19:28:53 -05:00
Roman Perepelitsa 62c5575848 tests: Add a test that 'rehash' isn't run.
See comments within for the rationale.

This is a regression test for a regression that was only present in development
versions of PR #764 and was never present in master.
2020-08-26 08:47:06 +00:00
Daniel Shahaf 6d5372a937 tests: parameter-to-global-alias: Fix a false positive failure when 'x' happens to be a valid external command name.
Reported on issue #757 along with other issues.
2020-08-11 09:21:21 +00:00
m0viefreak 79b6e7e05f tests: precommand-killing1: Use a dummy path that always exists
E.g., on Cygwin /etc/passwd does not necessarily exist.
2020-08-11 08:13:17 +00:00
Daniel Shahaf f6471dbec3 tests: Fix a wrong value of $PREBUFFER in a test, and add checks to prevent this from recurring.
Discussed: https://github.com/zsh-users/zsh-syntax-highlighting/pull/706#issuecomment-642072978
2020-06-11 08:14:07 +00:00
Daniel Shahaf 6fd92e1bbd 'main': Don't progress the $in_redirection staller while $in_param.
Fixes #712.
2020-06-08 14:38:59 +00:00
Daniel Shahaf 792c065acb tests: Add an XFail test for issue #712.
The second test point passes on 0.7.1, but the third does not.
2020-06-08 14:38:43 +00:00
Daniel Shahaf 0f11d80968 'main': Highlight the parentheses of array assignments as reserved words.
Fixes #585.
2020-06-08 14:23:43 +00:00
Matthew Martin 870bccf8ff main: Add tests for arithmetic expansion 2020-05-23 20:29:09 -05:00
Matthew Martin a238647df9 main: Add arithmetic substitution highlighting
Closes #607 #649 #704
2020-05-23 20:29:00 -05:00
Daniel Shahaf ade4b28d2d 'main': Fix issue #677, concerning multiline aliases.
The fix is to exempt such aliases from the empty commands sanity check.
2020-05-22 04:54:10 +00:00
Daniel Shahaf ea3ae74164 'main': Fix the last commit's bug concerning parameter elision not happening in redirects in command position. 2020-05-13 12:51:52 +00:00
Daniel Shahaf 41b8a74692 'main': Add a test for parameter elision not happening in redirects in command position.
Will be fixed in the next commit.
2020-05-13 12:51:40 +00:00
Daniel Shahaf 291634ecfe tests: Add a test for the infinite loop fixed by each of the last two commits.
Accidentally lost during a rebase.
2020-04-03 01:04:31 +00:00
Matthew Martin d1802e388e main: Add test for issue #713 2020-03-22 15:01:53 -05:00
Daniel Shahaf aecfd61bbd 'main': Support the 'env' precommand. 2020-03-21 01:45:34 +00:00
Daniel Shahaf e4f24f8901
Merge pull request #669 from danielshahaf/cdpath-and-nonexecutable-in-command-position-v1
Command position: non-executable files, non-cdable directories, CDPATH false positives
2020-03-19 21:22:52 +00:00
Daniel Shahaf 1000da306a 'main': Correctly highlight '&&' and '||' inside '[[ … ]]' conditions. 2020-03-19 20:16:43 +00:00
Daniel Shahaf b44964c545 'main': Highlight reserved words following assignments as errors.
Fixes #461.
2020-03-19 19:48:44 +00:00
Daniel Shahaf f54d829f03 tests: Add tests for issue #461. 2020-03-19 19:43:12 +00:00
Daniel Shahaf b0af27f25f tests: Add a unit test for a path specified with mixed quoting.
Fixes #475.
2020-03-19 06:49:40 +00:00
Daniel Shahaf bd9094cc61 tests: Add a test for issue #498, which has already been fixed. 2020-03-19 06:44:12 +00:00
Daniel Shahaf c7229a000a tests: Test that global qualifiers and command substitutions aren't evaluated.
Fixes #504.
2020-03-19 06:41:38 +00:00
Daniel Shahaf f2726d0464 'main': Don't consider path_prefix in alias expansions. 2020-03-19 06:06:30 +00:00
Daniel Shahaf 8184266338 'main': Add a test for aliases to AUTO_CD directories. 2020-03-19 06:06:30 +00:00
Daniel Shahaf 83ac855ceb 'main': Let AUTO_CD directories be highlighted with their own style. 2020-03-19 06:06:30 +00:00
Daniel Shahaf 5545fb9ab2 'main': In command position, do not highlight directories (unless AUTO_CD is set) and non-executable files.
Fixes #202.

Test expectations are updated.  For example, BUFFER='/bin' is now
highlighted as path_prefix because it's a prefix of '/bin/sh' which
would be valid.  However, BUFFER='/bin;' is now properly highlighted
as an error (unless AUTO_CD is set).
2020-03-19 06:06:30 +00:00
Daniel Shahaf a6eb966d96 'main': Extend tests to capture the current behaviour.
The next commits will change this behaviour.
2020-03-19 06:05:23 +00:00
Daniel Shahaf c67372e96c 'main': Add an XFail test for issue #202. 2020-03-19 06:05:23 +00:00
Daniel Shahaf 29ca0bc6c8 'main': Highlight errors from the EQUALS option.
Fixes #430.
2020-03-19 05:59:04 +00:00
Daniel Shahaf 08839bbd87 'main': Let the type determination ignore global aliases when it ignores regular ones. 2020-03-19 05:28:17 +00:00
Daniel Shahaf e2dddb91c6 'main': Add a regression test for parameters that expand to global aliases.
Will be fixed in the next commit.
2020-03-19 05:27:31 +00:00
Daniel Shahaf 3c5f63d959 'main': Highlight global aliases 2020-03-19 05:05:37 +00:00
Daniel Shahaf 5a44d9f32a tests: Record current behaviour on global aliases. 2020-03-19 05:04:15 +00:00
Daniel Shahaf fdf23e06c7 'main': Support the "close file descriptor" and "coproc" redirection syntaxes
Part of issue #645.
2020-03-19 03:15:37 +00:00
Daniel Shahaf 10171731f3 tests: Add a test for the "close file descriptor" and "coproc" redirection syntaxes
Part of issue #645.
2020-03-19 03:14:15 +00:00
Daniel Shahaf dfc41123d7 tests: Fix the test added in the last commit. 2020-03-19 02:30:58 +00:00
Daniel Shahaf d6defe715a tests: Add a test for issue #705, concerning continuation lines. 2020-03-19 01:39:33 +00:00
Daniel Shahaf d237a60c9b 'main': Don't highlight arithmetic expansions as command substitutions.
This is not perfect: we don't try to detect cases such as «$((ls); (ls))»,
which look like arithmetic expansions but are in fact command substitutions.

Fixes part of #607.

Introduces #704.
2020-03-17 15:05:32 +00:00
Daniel Shahaf 2e65bb6d7d tests: Add a test documenting the current state, prior to introducing #704. 2020-03-17 15:05:32 +00:00