2021-11-13 01:02:56 +08:00
.. _cmd-fish_add_path:
2021-11-12 20:34:16 +08:00
.. program :: fish_add_path
2020-05-21 19:33:17 +08:00
fish_add_path - add to the path
==============================================================
Synopsis
--------
docs synopsis: add HTML highlighing and automate manpage markup
Recent synopsis changes move from literal code blocks to
[RST line blocks]. This does not translate well to HTML: it's not
rendered in monospace, so aligment is lost. Additionally, we don't
get syntax highlighting in HTML, which adds differences to our code
samples which are highlighted.
We hard-wrap synopsis lines (like code blocks). To align continuation
lines in manpages we need [backslashes in weird places]. Combined with
the **, *, and `` markup, it's a bit hard to get the alignment right.
Fix these by moving synopsis sources back to code blocks and compute
HTML syntax highlighting and manpage markup with a custom Sphinx
extension.
The new Pygments lexer can tokenize a synopsis and assign the various
highlighting roles, which closely matches fish's syntax highlighing:
- command/keyword (dark blue)
- parameter (light blue)
- operator like and/or/not/&&/|| (cyan)
- grammar metacharacter (black)
For manpage output, we don't project the fish syntax highlighting
but follow the markup convention in GNU's man(1):
bold text type exactly as shown.
italic text replace with appropriate argument.
To make it easy to separate these two automatically, formalize that
(italic) placeholders must be uppercase; while all lowercase text is
interpreted literally (so rendered bold).
This makes manpages more consistent, see string-join(1) and and(1).
Implementation notes:
Since we want manpage formatting but Sphinx's Pygments highlighing
plugin does not support manpage output, add our custom "synopsis"
directive. This directive parses differently when manpage output is
specified. This means that the HTML and manpage build processes must
not share a cache, because the parsed doctrees are cached. Work around
this by using separate cache locations for build targets "sphinx-docs"
(which creates HTML) and "sphinx-manpages". A better solution would
be to only override Sphinx's ManualPageBuilder but that would take a
bit more code (ideally we could override ManualPageWriter but Sphinx
4.3.2 doesn't really support that).
---
Alternative solution: stick with line blocks but use roles like
:command: or :option: (or custom ones). While this would make it
possible to produce HTML that is consistent with code blocks (by adding
a bit of CSS), the source would look uglier and is harder to maintain.
(Let's say we want to add custom formatting to the [|] metacharacters
in HTML. This is much easier with the proposed patch.)
---
[RST line blocks]: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#line-blocks
[backslashes in weird places]: https://github.com/fish-shell/fish-shell/pull/8626#discussion_r782837750
2022-01-09 22:09:46 +08:00
.. synopsis ::
fish_add_path path ...
2022-01-17 12:29:49 +08:00
fish_add_path [(-g | --global) | (-U | --universal) | (-P | --path)] [(-m | --move)] [(-a | --append) | (-p | --prepend)] [(-v | --verbose) | (-n | --dry-run)] PATHS ...
2020-05-21 19:33:17 +08:00
Description
-----------
2022-07-19 02:53:37 +08:00
:program: `fish_add_path` is a simple way to add more components to fish's :envvar: `PATH` . It does this by adding the components either to $fish_user_paths or directly to :envvar: `PATH` (if the `` --path `` switch is given).
2020-05-21 19:33:17 +08:00
2021-11-12 20:51:04 +08:00
It is (by default) safe to use :program: `fish_add_path` in config.fish, or it can be used once, interactively, and the paths will stay in future because of :ref: `universal variables <variables-universal>` . This is a "do what I mean" style command, if you need more control, consider modifying the variable yourself.
2020-05-21 19:33:17 +08:00
2022-09-24 01:57:49 +08:00
Components are normalized by :doc: `realpath <realpath>` . Trailing slashes are ignored and relative paths are made absolute (but symlinks are not resolved). If a component already exists, it is not added again and stays in the same place unless the `` --move `` switch is given.
2020-05-21 19:33:17 +08:00
2023-04-04 23:50:01 +08:00
Components are added in the order they are given, and they are prepended to the path unless `` --append `` is given. If $fish_user_paths is used, that means they are last in $fish_user_paths, which is itself prepended to :envvar: `PATH` , so they still stay ahead of the system paths. If the `` --path `` option is used, the paths are appended/prepended to :envvar: `PATH` directly, so this doesn't happen.
With `` --path `` , because :envvar: `PATH` must be a global variable instead of a universal one, the changes won't persist, so those calls need to be stored in :ref: `config.fish <configuration>` .
2020-05-21 19:33:17 +08:00
2022-07-19 02:53:37 +08:00
If no component is new, the variable (:envvar: `fish_user_paths` or :envvar: `PATH` ) is not set again or otherwise modified, so variable handlers are not triggered.
2020-05-21 19:33:17 +08:00
If a component is not an existing directory, `` fish_add_path `` ignores it.
Options
-------
2022-03-11 23:56:20 +08:00
**-a** or **--append**
Add components to the *end* of the variable.
**-p** or **--prepend**
Add components to the *front* of the variable (this is the default).
**-g** or **--global**
Use a global :envvar: `fish_user_paths` .
**-U** or **--universal**
Use a universal :envvar: `fish_user_paths` - this is the default if it doesn't already exist.
**-P** or **--path**
Manipulate :envvar: `PATH` directly.
**-m** or **--move**
Move already-existing components to the place they would be added - by default they would be left in place and not added again.
**-v** or **--verbose**
2022-09-24 01:57:49 +08:00
Print the :doc: `set <set>` command used.
2022-03-11 23:56:20 +08:00
**-n** or **--dry-run**
Print the `` set `` command that would be used without executing it.
2020-05-21 19:33:17 +08:00
2022-03-12 00:18:41 +08:00
**-h** or **--help**
Displays help about using this command.
2020-05-21 19:33:17 +08:00
If `` --move `` is used, it may of course lead to the path swapping order, so you should be careful doing that in config.fish.
Example
-------
::
# I just installed mycoolthing and need to add it to the path to use it.
2020-10-11 03:22:34 +08:00
> fish_add_path /opt/mycoolthing/bin
2020-05-21 19:33:17 +08:00
# I want my ~/.local/bin to be checked first.
2020-10-11 03:22:34 +08:00
> fish_add_path -m ~/.local/bin
2020-05-21 19:33:17 +08:00
# I prefer using a global fish_user_paths
2020-10-11 03:22:34 +08:00
> fish_add_path -g ~/.local/bin ~/.otherbin /usr/local/sbin
2020-05-21 19:33:17 +08:00
# I want to append to the entire $PATH because this directory contains fallbacks
2020-10-11 03:22:34 +08:00
> fish_add_path -aP /opt/fallback/bin
2020-05-21 19:33:17 +08:00
# I want to add the bin/ directory of my current $PWD (say /home/nemo/)
> fish_add_path -v bin/
set fish_user_paths /home/nemo/bin /usr/bin /home/nemo/.local/bin
2020-09-13 01:28:01 +08:00
# I have installed ruby via homebrew
2020-10-11 03:22:34 +08:00
> fish_add_path /usr/local/opt/ruby/bin