mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-26 11:14:08 +00:00
shell: have, path_(append|prepend|remove)
- have: command -v shorthand - path_append: appends dir to PATH - path_prepend: prepends dir to PATH - path_remove: removes dir from PATH
This commit is contained in:
@@ -171,3 +171,33 @@ function menu_usage()
|
||||
menu_item "$CMD" "$DESC"
|
||||
done
|
||||
}
|
||||
|
||||
# shorthand for checking if the system has the bin in path.
|
||||
# usage: have php && php -v
|
||||
function have
|
||||
{
|
||||
command -v "$1" >&/dev/null;
|
||||
}
|
||||
|
||||
# Remove directory from the PATH variable
|
||||
# usage: path_remove ~/.local/bin
|
||||
function path_remove
|
||||
{
|
||||
PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$1\"" | sed 's/:$//')
|
||||
}
|
||||
|
||||
# Append directory to the PATH
|
||||
# usage: path_append ~/.local/bin
|
||||
function path_append
|
||||
{
|
||||
path_remove "$1"
|
||||
PATH="${PATH:+"$PATH:"}$1"
|
||||
}
|
||||
|
||||
# Prepend directory to the PATH
|
||||
# usage: path_prepend ~/.local/bin
|
||||
function path_prepend
|
||||
{
|
||||
path_remove "$1"
|
||||
PATH="$1${PATH:+":$PATH"}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user