Last active
June 27, 2016 17:21
-
-
Save criztovyl/d8455c5297929579481f to your computer and use it in GitHub Desktop.
Overwrite a command with it's development one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devpath() | |
{ | |
DEVPATH_DIR=$HOME/.local/share/devpath | |
DEVPATH_RE='.*devpath/.' | |
if [[ "$1" =~ ^-{0,2}h(elp)?$ ]] || [[ -z "$1" ]]; then | |
echo "Usage: devpath scriptName" >&2 | |
echo "or : devpath -l|--list" >&2 | |
return 0 | |
elif [[ "$1" =~ ^-{0,2}l(ist)?$ ]]; then | |
IFS=":" read -ra path <<< "$PATH" | |
for path_element in ${path[@]}; do | |
[[ "$path_element" =~ $DEVPATH_RE ]] && ls $path_element | |
done | |
else | |
script=$1 | |
scriptName=$(basename $script) | |
scriptName=${scriptName//.${scriptName##*.}/} | |
bin=$DEVPATH_DIR/$scriptName | |
[ -d "$bin" ] || mkdir -p "$bin" | |
[ ! -f $bin/$scriptName ] && ln -s `realpath "$script"` $bin/$scriptName || echo "Already linked :)" >&2 | |
[[ $PATH =~ $bin ]] || export PATH=$bin":"$PATH | |
echo "Done." >&2 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment