Skip to content

Instantly share code, notes, and snippets.

@mfdj
Last active August 26, 2015 03:08
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 mfdj/5771a769606e7c2e6bb3 to your computer and use it in GitHub Desktop.
Save mfdj/5771a769606e7c2e6bb3 to your computer and use it in GitHub Desktop.
cdp function - dead simple approach to creating and visiting directory aliases
# directory where aliases are stored
export CDP_PATH=~/dotfiles/cdp_symlinks
# cdp --add <-- creates an alias of the current direcotry path, named for the current folder name
# cdp --add custom-name <-- same as above with custom-name
# cdp another-name <-- change into alias
# cdp --list <-- see all aliases available to cdp
# cdp --remove some-name <-- remove an alias
# cd `cdp --path` <-- change into the directory where aliases are stored
function cdp {
if [[ $1 == "--path" || $1 == '-p' ]]; then
if [[ $2 ]]; then
export CDP_PATH=$2
else
[[ $CDP_PATH ]] && echo $CDP_PATH || echo '$CDP_PATH not pointing at a directory.'
fi
return
fi
if [[ ! $CDP_PATH || ! -d $CDP_PATH ]]; then
[[ ! $CDP_PATH ]] \
&& echo '$CDP_PATH not set — example: mkdir ~/.cdp_symlinks; export CDP_PATH=~/.cdp_symlinks' \
|| echo '$CDP_PATH not pointing at a directory.'
return
fi
if [[ $1 == '--add' || $1 == '-a' ]]; then
local dir=`pwd`
[[ $dir == $CDP_PATH ]] && return
cd $CDP_PATH > /dev/null
[[ $2 ]] && ln -s $dir $2 > /dev/null || ln -s $dir > /dev/null
cd - > /dev/null
elif [[ $1 == '--remove' || $1 == '-r' ]]; then
[[ $2 ]] \
&& rm $CDP_PATH/$2 \
|| echo 'missing arugment for remove'
elif [[ $1 == "--list" || $1 == '-l' ]]; then
ls -lG $CDP_PATH
else
CDPATH=$CDP_PATH
cd -P $1 > /dev/null
CDPATH=''
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment