fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Fabian Boehmfish_add_path: Be more informative in verbose modef59cdfaa8

master
2.3 KiB73 linesraw
1# RUN: %fish %s
2#
3# This deals with $PATH manipulation. We need to be careful not to step on anything.
4
5set -l tmpdir (mktemp -d)
6mkdir $tmpdir/bin
7mkdir $tmpdir/sbin
8mkdir $tmpdir/etc
9ln -s $tmpdir/bin $tmpdir/link
10
11# We set fish_user_paths to an empty global to have a starting point
12set -g fish_user_paths
13fish_add_path -v $tmpdir/bin
14# CHECK: set fish_user_paths {{.*}}/bin
15echo $status
16# CHECK: 0
17
18# Confirm that it actually ends up in $PATH
19contains -- (builtin realpath $tmpdir/bin) $PATH
20and echo Have bin
21# CHECK: Have bin
22
23# Not adding duplicates and not triggering variable handlers
24function checkpath --on-variable PATH --on-variable fish_user_paths; echo CHECKPATH: $argv; end
25set PATH $PATH
26# CHECK: CHECKPATH: VARIABLE SET PATH
27fish_add_path -v $tmpdir/bin
28# CHECK: Skipping already included path: {{.*}}
29# CHECK: No paths to add, not setting anything.
30# Nothing happened, so the status failed.
31echo $status
32# CHECK: 1
33functions --erase checkpath
34
35# Add a link to the same path.
36fish_add_path -v $tmpdir/link
37# CHECK: set fish_user_paths {{.*}}/link {{.*}}/bin
38echo $status
39# CHECK: 0
40
41# Relative paths are made absolute
42set -l oldpwd $PWD
43cd $tmpdir
44fish_add_path -nv sbin .
45# CHECK: set fish_user_paths /{{.*}}/sbin /{{.*}} /{{.*}}/link /{{.*}}/bin
46cd $oldpwd
47
48fish_add_path -a $tmpdir/sbin
49# Not printing anything because it's not verbose, the /sbin should be added at the end.
50string replace -- $tmpdir '' $fish_user_paths | string join ' '
51# CHECK: /link /bin /sbin
52
53fish_add_path -m $tmpdir/sbin
54string replace -- $tmpdir '' $fish_user_paths | string join ' '
55# CHECK: /sbin /link /bin
56
57set -l oldpath "$PATH"
58fish_add_path -nP $tmpdir/etc | string replace -- $tmpdir ''
59# Should print a set command to prepend /etc to $PATH, but not actually do it
60# CHECK: set -g PATH /etc{{.*}}
61
62# Confirm that $PATH didn't change.
63test "$oldpath" = "$PATH"
64or echo "PATH CHANGED!!!" >&2
65
66# See that moving multiple arguments removes the correct ones - #7776
67PATH=$tmpdir/{bin,etc,link,sbin} fish_add_path -nPpm $tmpdir/{link,sbin} | string replace -a $tmpdir ''
68# CHECK: set -g PATH /link /sbin /bin /etc
69
70# See that trying to add a path twice doesn't duplicate it
71PATH=$tmpdir/{bin,etc,link,sbin} fish_add_path -nPpm $tmpdir/sbin{,} | string replace -a $tmpdir ''
72# CHECK: set -g PATH /sbin /bin /etc /link
73exit 0