From f59cdfaa8d480d5241c521091b44bd5065019342 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Mon, 27 May 2024 08:38:36 +0200 Subject: [PATCH] fish_add_path: Be more informative in verbose mode One issue with fish_add_path at the moment is that it is sometimes a bit too intransparent. You'll try to add a path, but it won't appear - was that because it wasn't a directory, or because it doesn't exist, or because it was already included? If it isn't usable after, did fish_add_path not add it because of something or did something *else* remove it? So we give more explanations - "skipping this because it's a file", "not setting anything because no paths are left to add", ... --- share/functions/fish_add_path.fish | 6 ++++++ tests/checks/fish_add_path.fish | 2 ++ 2 files changed, 8 insertions(+) diff --git a/share/functions/fish_add_path.fish b/share/functions/fish_add_path.fish index 6e2316dd8..1a7b2387f 100644 --- a/share/functions/fish_add_path.fish +++ b/share/functions/fish_add_path.fish @@ -70,6 +70,8 @@ function fish_add_path --description "Add paths to the PATH" if set -q _flag_move; and not contains -- $p $newpaths set -a indexes $ind set -a newpaths $p + else if set -q _flag_verbose + printf (_ "Skipping already included path: %s\n") "$p" end else if not contains -- $p $newpaths # Without move, we only add it if it's not in. @@ -99,6 +101,10 @@ function fish_add_path --description "Add paths to the PATH" and set $scope $var $newvar return 0 else + if set -q _flag_verbose + # print a message in verbose mode + printf (_ "No paths to add, not setting anything.\n") "$p" + end return 1 end end diff --git a/tests/checks/fish_add_path.fish b/tests/checks/fish_add_path.fish index d47fef959..745bbc648 100644 --- a/tests/checks/fish_add_path.fish +++ b/tests/checks/fish_add_path.fish @@ -25,6 +25,8 @@ function checkpath --on-variable PATH --on-variable fish_user_paths; echo CHECKP set PATH $PATH # CHECK: CHECKPATH: VARIABLE SET PATH fish_add_path -v $tmpdir/bin +# CHECK: Skipping already included path: {{.*}} +# CHECK: No paths to add, not setting anything. # Nothing happened, so the status failed. echo $status # CHECK: 1