-
Notifications
You must be signed in to change notification settings - Fork 1
/
path.fish.inc
26 lines (26 loc) · 1.18 KB
/
path.fish.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/fish
# The begin/end block limits the scope of all variables except $PATH
begin
# This script aims to be a direct mapping of our path.bash.inc shell, rather
# than idiomatic fish. Why? I don't really understand fish.
set script_link (readlink (status -f)); or set script_link (status -f)
# This sed expression is the equivalent of "${script_link%/*}" in bash, which
# chops off "/*" (with * as a wildcard) from the end of script_link.
set apparent_sdk_dir (echo $script_link | sed 's/\(.*\)\/.*/\1/')
if [ "$apparent_sdk_dir" = "$script_link" ]
set apparent_sdk_dir .
end
set old_dir (pwd)
# No "cd -P" in fish. It always resolves symlinks to their canonical location,
# though, when you "cd" in.
# Also, cd is cd is *both* a shell builtin and shell wrapper function (to
# implement "cd -") in fish, so "command cd" won't work. "builtin cd" will.
set sdk_dir (builtin cd "$apparent_sdk_dir" > /dev/null; and pwd)
builtin cd "$old_dir"
set bin_path "$sdk_dir/bin"
# -gx for global (not limited to this begin/end block) and exportable (part of
# the environment for child processes)
if not contains "$bin_path" $PATH
set -gx PATH "$bin_path" $PATH
end
end