Skip to content

Instantly share code, notes, and snippets.

@elfenlaid
Created April 16, 2021 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elfenlaid/46f7f908d82bed0dd95e29c5ee618284 to your computer and use it in GitHub Desktop.
Save elfenlaid/46f7f908d82bed0dd95e29c5ee618284 to your computer and use it in GitHub Desktop.
Fish $PATH environment variable manager

Fish $PATH environment variable manager

Install

Store file at ~/.config/fish/functions/path.fish path

Usage

$ path --help

Usage: path [options] [path]

Options:
-h, --help	Show this help message and exit
-a, --add	Append path to PATH
-d, --delete	Delete path from PATH
  • echo $PATH with path
  • Add path path -a ~/.gem/ruby/2.6.3/bin
    • path won't add duplicates
  • Remove path path -d ~/.gem/ruby/2.6.3/bin
function path
set options $options (fish_opt -s a -l add --required-val)
set options $options (fish_opt -s d -l delete --required-val)
set options $options (fish_opt -s h -l help)
argparse $options -- $argv
if set -q _flag_help
printf "\n%s\n" "Usage: path [options] [path]"
printf "\n%s\n" "Options:"
printf "%s\t%s\n" "-h, --help" "Show this help message and exit"
printf "%s\t%s\n" "-a, --add" "Append path to PATH"
printf "%s\t%s\n" "-d, --delete" "Delete path from PATH"
return
end
if set -q _flag_add
if not contains $_flag_add $PATH
set -U fish_user_paths $_flag_add $fish_user_paths
echo "Updated PATH: $PATH"
else
echo "$_flag_add is alredy in PATH: $PATH"
end
return
end
if set -q _flag_delete
if set -l index (contains -i $_flag_delete $PATH)
set --erase --universal fish_user_paths[$index]
echo "Updated PATH: $PATH"
else
echo "$_flag_delete not found in PATH: $PATH"
end
return
end
echo "PATH: $PATH"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment