Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use command to “protect” further commands #3462

Merged
merged 2 commits into from
Oct 11, 2023

Conversation

calestyo
Copy link
Contributor

@calestyo calestyo commented Oct 5, 2023

Hey.

This would be for #3458.

  • The current commit (hopefully) adds command to all commands that are not built-ins or functions.

    I haven't really tested it yet ;-) ... and guess anyway that it will be rather quite some effort to test all cases where command is now used.

  • A future commit might use builtin to protect further things like printf or echo. But arguably, it's always a trade off how far we go here (code readability vs. actually adding some benefit).
    But I do think, that at least "regular" (non-built-in) commands should all be "protected".

  • Also, I made no effort to do the same for fish or zsh. Since this adds no real new feature, I hope this is okay.

  • But I did notice that all zsh files have:

    'emulate' 'zsh' '-o' 'no_aliases'

    'emulate' 'zsh' '-o' 'no_aliases'

    Not really sure how that works, but shouldn't it anyway make the command superfluous, at least in terms of aliases (probably not in terms of functions)?

This commit causes all simple commands that are not built-ins or functions to be
invoked via `command` in order to protect them from alias substitution or from
accidentally taking functions of the same name.

It was decided to not “protect” `fzf` and `fzf-tmux` for now.
Maybe a better solution should be implemented for that in the future.

Signed-off-by: Christoph Anton Mitterer <[email protected]>
@calestyo
Copy link
Contributor Author

calestyo commented Oct 5, 2023

@junegunn … I did some (very very limited) testing now... and the test suite also runs through.

So once @step- has made his fix of the issue described at #3313 (comment), I'd rebase this branch and we could IMO merge it (after you double and triple checked it ;-) ).

step- added a commit to step-/fzf that referenced this pull request Oct 6, 2023
* Use the all-compatible mawk `-W version` option.
  junegunn#3313 (comment).
* Do not remap the history key if no dependent commands is installed
  (perl, awk or mawk in this order).
* Run the command and not a function consistently with junegunn#3462.

The version check bash code relies on the following mawk source code,
extracted from mawk 1.3.4 20230322.

```
version.c:
18-  #include "init.h"
19-  #include "patchlev.h"
20-
21:  #define	 VERSION_STRING	 \
22-    "mawk %d.%d%s %s\n\
23-  Copyright 2008-2022,2023, Thomas E. Dickey\n\
24-  Copyright 1991-1996,2014, Michael D. Brennan\n\n"
....
30-  void
31-  print_version(FILE *fp)
32-  {
33:      fprintf(fp, VERSION_STRING, PATCH_BASE, PATCH_LEVEL, PATCH_STRING, DATE_STRING);
34-      fflush(fp);
35-
36-  #define SHOW_RANDOM "random-funcs:"

patchlev.h:
13-  /*
14-   * $MawkId: patchlev.h,v 1.128 2023/03/23 00:23:57 tom Exp $
15-   */
16:  #define  PATCH_BASE	1
17-  #define  PATCH_LEVEL	3
18-  #define  PATCH_STRING	".4"
19-  #define  DATE_STRING    "20230322"
```
shell/completion.bash Outdated Show resolved Hide resolved
junegunn added a commit that referenced this pull request Oct 7, 2023
* Use the all-compatible mawk `-W version` option.
  #3313 (comment).
* Run the command and not a function consistently with #3462.

The version check bash code relies on the following mawk source code,
extracted from mawk 1.3.4 20230322.

```
version.c:
18-  #include "init.h"
19-  #include "patchlev.h"
20-
21:  #define	 VERSION_STRING	 \
22-    "mawk %d.%d%s %s\n\
23-  Copyright 2008-2022,2023, Thomas E. Dickey\n\
24-  Copyright 1991-1996,2014, Michael D. Brennan\n\n"
....
30-  void
31-  print_version(FILE *fp)
32-  {
33:      fprintf(fp, VERSION_STRING, PATCH_BASE, PATCH_LEVEL, PATCH_STRING, DATE_STRING);
34-      fflush(fp);
35-
36-  #define SHOW_RANDOM "random-funcs:"

patchlev.h:
13-  /*
14-   * $MawkId: patchlev.h,v 1.128 2023/03/23 00:23:57 tom Exp $
15-   */
16:  #define  PATCH_BASE	1
17-  #define  PATCH_LEVEL	3
18-  #define  PATCH_STRING	".4"
19-  #define  DATE_STRING    "20230322"
```

Co-authored-by: Junegunn Choi <[email protected]>
shell/completion.bash Outdated Show resolved Hide resolved
@calestyo calestyo force-pushed the protect-commands-in-shell-scripts branch from 98b6dfd to 08948ac Compare October 8, 2023 08:48
@calestyo
Copy link
Contributor Author

calestyo commented Oct 8, 2023

Rebased the commit on current master, though it still has the command on fzf/fzf-tmux until we come to a decision above.

@calestyo calestyo force-pushed the protect-commands-in-shell-scripts branch from 08948ac to 2c35c19 Compare October 9, 2023 01:13
@calestyo calestyo marked this pull request as ready for review October 10, 2023 14:10
shell/key-bindings.bash Outdated Show resolved Hide resolved
@junegunn junegunn merged commit 561e0b0 into junegunn:master Oct 11, 2023
5 checks passed
@junegunn
Copy link
Owner

Merged, thanks!

@calestyo calestyo deleted the protect-commands-in-shell-scripts branch October 11, 2023 19:13
kugel- added a commit to kugel-/fzf that referenced this pull request Oct 1, 2024
With the current code, I get this
  command cat: command not found

when using any keybinding that does _fzf_complete.
Seen on Ubuntu 24.04.1 (GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu))

Fixes: 561e0b0 ("[bash] Use `command` to “protect” further commands (junegunn#3462)")
Signed-off-by: Thomas Martitz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants