Skip to content

Instantly share code, notes, and snippets.

@criztovyl
Last active June 27, 2016 17:21
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 criztovyl/d8455c5297929579481f to your computer and use it in GitHub Desktop.
Save criztovyl/d8455c5297929579481f to your computer and use it in GitHub Desktop.
Overwrite a command with it's development one.
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