-
-
Save hirose31/3489436 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
if type -p readlink >/dev/null; then | |
alias abspath='readlink -f' | |
else | |
abspath() { | |
_CWD=$(pwd) | |
if [ -d "$1" ]; then | |
\cd $1 | |
echo $(pwd -P)/ | |
elif [ -f "$1" ]; then | |
case $1 in | |
*/*) \cd ${1%/*};; | |
esac | |
echo $(pwd -P)/${1##*/} | |
else | |
echo $1 | |
fi | |
\cd $_CWD | |
} | |
fi | |
# append_path ORIGINAL_PATH ADD_DIR1 ADD_DIR2 ... | |
append_path() { | |
path=$1 | |
shift | |
for p in "$@"; do | |
[ -d $p ] || continue | |
case $path in | |
*:${p}:*|*:${p}|${p}:*) ;; | |
*) path=$path:$p ;; | |
esac | |
done | |
path=${path#:} | |
echo $path | |
} | |
_get_kamipo_bin() { | |
bashrc_path=$(abspath ${BASH_SOURCE[0]}) | |
bashrc_dir=${bashrc_path%/*} | |
bin_dir=$(abspath "${bashrc_dir}/../bin") | |
echo $bin_dir | |
} | |
_add_kamipo_path() { | |
local _bin_path=$(_get_kamipo_bin) | |
append_path "$PATH" $_bin_path | |
} | |
export PATH=$(_add_kamipo_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment