Last active
January 4, 2016 08:19
-
-
Save gskielian/8594725 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
# Utilities for quickly accessing frequently used directories in bash. | |
# Usage: | |
# $ cd /path/to/project/src/ | |
# $ mark code # Will create a new shortcut. | |
# # Becomes interactive if a shortcut already exists | |
# # m is an alias for mark. You can also `m code` | |
# | |
# $ code # From now on, running this anywhere in the shell | |
# # will put you in /path/to/project/src/code | |
# | |
# $ unmark code # Will remove the symlink and is interactive | |
# # u is an alias for unmark. You can also `u code` | |
SHELLMARKSDIR="$HOME/.shellmarks" | |
mkdir -p $SHELLMARKSDIR | |
function mark_alias { alias $(basename $1)="cd -P $1"; } | |
function mark { # Mark a directory | |
symlink=$SHELLMARKSDIR/$1 | |
ln -ivs "$(pwd)" $symlink && mark_alias $symlink | |
} | |
alias m=mark | |
function unmark { # Remove a mark | |
symlink=$SHELLMARKSDIR/$1 | |
rm -iv $symlink | |
if [ ! -f $symlink ]; then | |
unalias $1 | |
fi | |
} | |
alias u=unmark | |
function shellmarks { # List all existing marks | |
LINK_COLOR=$'\e[1;35m' | |
RESET_COLOR=$'\e[0m' | |
for symlink in $SHELLMARKSDIR/*; do | |
echo "${LINK_COLOR} $(basename $symlink) ${RESET_COLOR} -> $(readlink $symlink)" | |
done | |
} | |
for symlink in $SHELLMARKSDIR/*; do # load all existing symlinks as aliases | |
mark_alias $symlink | |
test -e $symlink || rm $symlink # remove symlinks if source does not exist | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had to remove the h option from
ln -ivhs "$(pwd)" $symlink && mark_alias $symlink
and changing it to:
ln -ivs "$(pwd)" $symlink && mark_alias $symlink
In order to get rid of errors when sourcing my .bashrc file from ubuntu linux