mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-22 03:10:11 +08:00
fish_add_path: Don't resolve symlinks
The case for symlinked directories being duplicated a lot isn't there, but there *is* a usecase for adding the symlink rather than the target, and that's homebrew. E.g. homebrew installs ruby into /usr/local/Cellar/ruby/2.7.1_2/bin, and links to it from /usr/local/opt/ruby/bin. If we add the target, we would miss updates. Having path entries that point to the same location isn't a big problem - it's a path lookup, so it takes a teensy bit longer. The canonicalization is mainly so paths don't end up duplicated via weird spelling and so relative paths can be used.
This commit is contained in:
parent
568f9031aa
commit
0072367512
@ -20,7 +20,7 @@ Description
|
||||
|
||||
It is (by default) safe to use ``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.
|
||||
|
||||
Components are normalized by :ref:`realpath <cmd-realpath>`. This means that trailing slashes are ignored and symlinks are resolved, and relative paths are made absolute. If a component already exists, it is not added again and stays in the same place unless the ``--move`` switch is given.
|
||||
Components are normalized by :ref:`realpath <cmd-realpath>`. This means that 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.
|
||||
|
||||
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 $PATH, so they still stay ahead of the system paths).
|
||||
|
||||
@ -64,3 +64,6 @@ Example
|
||||
# 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
|
||||
|
||||
# I have installed ruby via homebrew
|
||||
fish_add_path /usr/local/opt/ruby/bin
|
||||
|
@ -21,4 +21,4 @@ If a ``realpath`` command exists, it will be preferred, so if you want to use th
|
||||
|
||||
The following options are available:
|
||||
|
||||
- ``-s`` or ``--no-symlink``: Don't resolve symlinks, only make paths absolute, squash multiple slashes and remove trailing slashes.
|
||||
- ``-s`` or ``--no-symlinks``: Don't resolve symlinks, only make paths absolute, squash multiple slashes and remove trailing slashes.
|
||||
|
@ -41,7 +41,7 @@ function fish_add_path --description "Add paths to the PATH"
|
||||
# We could add a non-canonical version of the given path if no duplicate exists, but tbh that's a recipe for disaster.
|
||||
|
||||
# realpath complains if a parent directory does not exist, so we silence stderr.
|
||||
set -l p (builtin realpath -- $path 2>/dev/null)
|
||||
set -l p (builtin realpath -s -- $path 2>/dev/null)
|
||||
|
||||
# Ignore non-existing paths
|
||||
test -d "$p"; or continue
|
||||
|
@ -30,19 +30,20 @@ echo $status
|
||||
# CHECK: 1
|
||||
functions --erase checkpath
|
||||
|
||||
# Not adding a link either
|
||||
# Add a link to the same path.
|
||||
fish_add_path -v $tmpdir/link
|
||||
# CHECK: set fish_user_paths {{.*}}/link {{.*}}/bin
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
# CHECK: 0
|
||||
|
||||
fish_add_path -a $tmpdir/sbin
|
||||
# Not printing anything because it's not verbose, the /sbin should be added at the end.
|
||||
string replace -- $tmpdir '' $fish_user_paths | string join ' '
|
||||
# CHECK: /bin /sbin
|
||||
# CHECK: /link /bin /sbin
|
||||
|
||||
fish_add_path -m $tmpdir/sbin
|
||||
string replace -- $tmpdir '' $fish_user_paths | string join ' '
|
||||
# CHECK: /sbin /bin
|
||||
# CHECK: /sbin /link /bin
|
||||
|
||||
set -l oldpath "$PATH"
|
||||
fish_add_path -nP $tmpdir/etc | string replace -- $tmpdir ''
|
||||
|
Loading…
x
Reference in New Issue
Block a user