mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-27 11:43:37 +08:00
e013422143
In the variable handler, we just go through the entire thing and keep every element once. If there's a duplicate, we set it again, which calls the handler again. This takes a bit of time, to be paid on each startup. On my system, with 100 already deduplicated elements, that's about 4ms (compared to ~17ms for adding them to $PATH). It's also semantically more complicated - now this variable specifically is deduplicated? Do we just want "unique" variables that can't have duplicates? However: This entirely removes the pathological case of appending to $fish_user_paths in config.fish (which should be an FAQ entry!), and the implementation is quite simple.
37 lines
819 B
Fish
37 lines
819 B
Fish
# RUN: %fish %s
|
|
#
|
|
# This deals with $PATH manipulation. We need to be careful not to step on anything.
|
|
|
|
set -l tmpdir (mktemp -d)
|
|
mkdir $tmpdir/bin
|
|
mkdir $tmpdir/sbin
|
|
mkdir $tmpdir/etc
|
|
ln -s $tmpdir/bin $tmpdir/link
|
|
|
|
# We set fish_user_paths to an empty global to have a starting point
|
|
set -g fish_user_paths
|
|
set fish_user_paths $tmpdir/bin
|
|
|
|
# Confirm that it actually ends up in $PATH
|
|
contains -- (builtin realpath $tmpdir/bin) $PATH
|
|
and echo Have bin
|
|
# CHECK: Have bin
|
|
|
|
# Not adding duplicates
|
|
set PATH $PATH
|
|
set -l --path oldpath $PATH
|
|
set -a fish_user_paths $tmpdir/bin
|
|
test "$oldpath" = "$PATH"
|
|
or begin
|
|
echo OH NO A DUPLICATE
|
|
echo NEW: $PATH
|
|
echo OLD: $oldpath
|
|
end
|
|
|
|
|
|
# Add a link to the same path.
|
|
set -a fish_user_paths $tmpdir/link
|
|
contains -- $tmpdir/link $PATH
|
|
and echo Have bin
|
|
# CHECK: Have bin
|