From b8f6218bf179c04efe0cb0bb1b05735d5c45be41 Mon Sep 17 00:00:00 2001 From: Yuri Pereira Constante Date: Tue, 30 Aug 2022 15:18:25 +0000 Subject: [PATCH] refactor: use `fish_add_path` during fish setup if available (#1317) --- asdf.fish | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/asdf.fish b/asdf.fish index e9d2a3b6..7cef8114 100644 --- a/asdf.fish +++ b/asdf.fish @@ -2,27 +2,36 @@ if not set -q ASDF_DIR set -x ASDF_DIR (dirname (status -f)) end -set -l asdf_user_shims ( - if test -n "$ASDF_DATA_DIR" - printf "%s\n" "$ASDF_DATA_DIR/shims" - else - printf "%s\n" "$HOME/.asdf/shims" - end -) - # Add asdf to PATH -set -l asdf_bin_dirs $ASDF_DIR/bin $asdf_user_shims +# fish_add_path was added in fish 3.2, so we need a fallback for older version +if type -q fish_add_path + if test -n "$ASDF_DATA_DIR" + fish_add_path --global --move "$ASDF_DATA_DIR/shims" "$ASDF_DIR/bin" + else + fish_add_path --global --move "$HOME/.asdf/shims" "$ASDF_DIR/bin" + end +else + set -l asdf_user_shims ( + if test -n "$ASDF_DATA_DIR" + printf "%s\n" "$ASDF_DATA_DIR/shims" + else + printf "%s\n" "$HOME/.asdf/shims" + end + ) -for x in $asdf_bin_dirs - if test -d $x - for i in (seq 1 (count $PATH)) - if test $PATH[$i] = $x - set -e PATH[$i] - break + set -l asdf_bin_dirs $ASDF_DIR/bin $asdf_user_shims + + for x in $asdf_bin_dirs + if test -d $x + for i in (seq 1 (count $PATH)) + if test $PATH[$i] = $x + set -e PATH[$i] + break + end end end + set PATH $x $PATH end - set PATH $x $PATH end # Load the asdf wrapper function