mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
fish_add_path: Automatically enable verbose mode for interactive use
fish_add_path can be used either interactively, in the commandline, or in config.fish. That's its greatest strength, it's a very DWIM-style command. One of the compromises that entails, however, is that it can't really be very loud about what it does. If it skips a path, it can't write a warning because it might be used in config.fish. But it *can* if it's used interactively. So we try to detect that case and enable verbose mode automatically. That means if you do ```fish fish_add_path /opt/mytool/bin/mytool ``` it may tell you "Skipping path because it is a file instead of a directory:". The check isn't perfect, it goes through status current-command and isatty, but it should be good for most cases (and be false in config.fish).
This commit is contained in:
parent
3411b72a6d
commit
6706b15fbc
2 changed files with 7 additions and 1 deletions
|
@ -52,7 +52,8 @@ Options
|
||||||
Move already-included directories to the place they would be added - by default they would be left in place and not added again.
|
Move already-included directories to the place they would be added - by default they would be left in place and not added again.
|
||||||
|
|
||||||
**-v** or **--verbose**
|
**-v** or **--verbose**
|
||||||
Print the :doc:`set <set>` command used.
|
Print the :doc:`set <set>` command used, and some more warnings, like when a path is skipped because it doesn't exist or is not a directory.
|
||||||
|
Verbose mode is automatically enabled when fish_add_path is used interactively and the output goes to the terminal.
|
||||||
|
|
||||||
**-n** or **--dry-run**
|
**-n** or **--dry-run**
|
||||||
Print the ``set`` command that would be used without executing it.
|
Print the ``set`` command that would be used without executing it.
|
||||||
|
|
|
@ -36,6 +36,11 @@ function fish_add_path --description "Add paths to the PATH"
|
||||||
set -l mode $_flag_prepend $_flag_append
|
set -l mode $_flag_prepend $_flag_append
|
||||||
set -q mode[1]; or set mode -p
|
set -q mode[1]; or set mode -p
|
||||||
|
|
||||||
|
# Enable verbose mode if we're interactively used
|
||||||
|
status current-command | string match -rq '^fish_add_path$'
|
||||||
|
and isatty stdout
|
||||||
|
and set -l _flag_verbose yes
|
||||||
|
|
||||||
# To keep the order of our arguments, go through and save the ones we want to keep.
|
# To keep the order of our arguments, go through and save the ones we want to keep.
|
||||||
set -l newpaths
|
set -l newpaths
|
||||||
set -l indexes
|
set -l indexes
|
||||||
|
|
Loading…
Reference in a new issue