2024-04-12 18:19:32 +08:00
|
|
|
# RUN: %fish %s
|
2020-05-21 19:33:17 +08:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
fish_add_path -v $tmpdir/bin
|
|
|
|
# CHECK: set fish_user_paths {{.*}}/bin
|
|
|
|
echo $status
|
|
|
|
# CHECK: 0
|
|
|
|
|
|
|
|
# Confirm that it actually ends up in $PATH
|
|
|
|
contains -- (builtin realpath $tmpdir/bin) $PATH
|
|
|
|
and echo Have bin
|
|
|
|
# CHECK: Have bin
|
|
|
|
|
|
|
|
# Not adding duplicates and not triggering variable handlers
|
|
|
|
function checkpath --on-variable PATH --on-variable fish_user_paths; echo CHECKPATH: $argv; end
|
|
|
|
set PATH $PATH
|
|
|
|
# CHECK: CHECKPATH: VARIABLE SET PATH
|
|
|
|
fish_add_path -v $tmpdir/bin
|
2024-05-27 14:38:36 +08:00
|
|
|
# CHECK: Skipping already included path: {{.*}}
|
|
|
|
# CHECK: No paths to add, not setting anything.
|
2020-05-21 19:33:17 +08:00
|
|
|
# Nothing happened, so the status failed.
|
|
|
|
echo $status
|
|
|
|
# CHECK: 1
|
|
|
|
functions --erase checkpath
|
|
|
|
|
2020-09-13 01:28:01 +08:00
|
|
|
# Add a link to the same path.
|
2020-05-21 19:33:17 +08:00
|
|
|
fish_add_path -v $tmpdir/link
|
2020-09-13 01:28:01 +08:00
|
|
|
# CHECK: set fish_user_paths {{.*}}/link {{.*}}/bin
|
2020-05-21 19:33:17 +08:00
|
|
|
echo $status
|
2020-09-13 01:28:01 +08:00
|
|
|
# CHECK: 0
|
2020-05-21 19:33:17 +08:00
|
|
|
|
2023-09-29 22:52:50 +08:00
|
|
|
# Relative paths are made absolute
|
|
|
|
set -l oldpwd $PWD
|
|
|
|
cd $tmpdir
|
|
|
|
fish_add_path -nv sbin .
|
|
|
|
# CHECK: set fish_user_paths /{{.*}}/sbin /{{.*}} /{{.*}}/link /{{.*}}/bin
|
|
|
|
cd $oldpwd
|
|
|
|
|
2020-05-21 19:33:17 +08:00
|
|
|
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 ' '
|
2020-09-13 01:28:01 +08:00
|
|
|
# CHECK: /link /bin /sbin
|
2020-05-21 19:33:17 +08:00
|
|
|
|
|
|
|
fish_add_path -m $tmpdir/sbin
|
|
|
|
string replace -- $tmpdir '' $fish_user_paths | string join ' '
|
2020-09-13 01:28:01 +08:00
|
|
|
# CHECK: /sbin /link /bin
|
2020-05-21 19:33:17 +08:00
|
|
|
|
|
|
|
set -l oldpath "$PATH"
|
|
|
|
fish_add_path -nP $tmpdir/etc | string replace -- $tmpdir ''
|
|
|
|
# Should print a set command to prepend /etc to $PATH, but not actually do it
|
2021-06-24 03:29:27 +08:00
|
|
|
# CHECK: set -g PATH /etc{{.*}}
|
2020-05-21 19:33:17 +08:00
|
|
|
|
|
|
|
# Confirm that $PATH didn't change.
|
|
|
|
test "$oldpath" = "$PATH"
|
|
|
|
or echo "PATH CHANGED!!!" >&2
|
|
|
|
|
2021-03-04 23:10:27 +08:00
|
|
|
# See that moving multiple arguments removes the correct ones - #7776
|
|
|
|
PATH=$tmpdir/{bin,etc,link,sbin} fish_add_path -nPpm $tmpdir/{link,sbin} | string replace -a $tmpdir ''
|
2021-06-24 03:29:27 +08:00
|
|
|
# CHECK: set -g PATH /link /sbin /bin /etc
|
2021-03-04 23:10:27 +08:00
|
|
|
|
2022-05-17 23:02:46 +08:00
|
|
|
# See that trying to add a path twice doesn't duplicate it
|
|
|
|
PATH=$tmpdir/{bin,etc,link,sbin} fish_add_path -nPpm $tmpdir/sbin{,} | string replace -a $tmpdir ''
|
2022-05-17 23:21:42 +08:00
|
|
|
# CHECK: set -g PATH /sbin /bin /etc /link
|
2020-05-21 19:33:17 +08:00
|
|
|
exit 0
|