Last active
September 18, 2022 07:50
-
-
Save harith/8340924 to your computer and use it in GitHub Desktop.
Utilities to let you easily reach frequently visited but deeply nested directories.
This file contains 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 -ivns "$(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 | |
test -L $symlink && 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 -L $symlink && ( test -e $(readlink $symlink) || rm $symlink ) # remove symlinks if source does not exist | |
done |
There's a utility called autojump
which has completely replaced cd
for me:
https://github.com/joelthelion/autojump
No need to mark folders. As soon as you've visited one it's in the database and can be jumped to (including tab completion from anywhere).
There is also a utility called z
which replaced both cd
and autojump
for me:
DESCRIPTION
Tracks your most used directories, based on 'frecency'.
After a short learning phase, z will take you to the most 'frecent'
directory that matches ALL of the regexes given on the command line.
There's a utility called fasd
that provides a superset of both z
and autojump
functionality:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome!