Skip to content

Simple way to add to the path #6960

@boxed

Description

@boxed

(This has been discussed in #527 previously)

I can never remember how to set the path persistently in fish, When I google it I end up at issue #527 but the discussion there is a bit confused. I suggest two things:

  1. Add a command add_to_path that is idempotent and validates the path.
  2. Edit the top comment of How to set $PATH persistently? #527 or the title to point out this new way so people who end up there from google get the right information. Google results changes too slowly!

I have written a draft of an implementation of add_to_path:

#!/usr/bin/env fish
if argparse -n 'fish-add-user-path' -N 1 'h/help' -- $argv
    ;
else
    exit
end

function add_to_path_if_not_there
    set exists 0

    # normalize path to end with /
    switch $argv
    case "*/"
        set new_path $argv
    case "*"
        set new_path "$argv/"
    end

    for x in (string split " " $fish_user_paths)
        if test "$x" = "$new_path"
            set exists 1
            break
        end
    end

    if test "$exists" = "0"
        set -Ux fish_user_paths $fish_user_paths $new_path
    end   
end

# validate that paths exists
for x in (string split " " $argv)
    if test -d $x
        ;
    else
        echo "Path '$x' does not exist"
        exit
    end
end


for x in (string split " " $argv)
    add_to_path_if_not_there $x 
end

This is my first fish program so please help me in making it suck less :P

ping @jonlorusso @knightsamar @kegesch @raunyoliveira-hotmart @i-am-the-slime @samhh @brianmhunt @radoslawc @cumulotimbus @AnotherCoolDude and many more that have seemed to think this is a good idea.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions