Skip to content

Instantly share code, notes, and snippets.

@filviu
Last active March 31, 2023 05:17
Show Gist options
  • Save filviu/caaa5cfeab8a5362c13bb1bc461cfeb1 to your computer and use it in GitHub Desktop.
Save filviu/caaa5cfeab8a5362c13bb1bc461cfeb1 to your computer and use it in GitHub Desktop.
Shell bookmarks in bash
#!/bin/bash
if [ -d "$HOME/.bookmarks" ]; then
export CDPATH=".:$HOME/.bookmarks:/"
alias {g,go,goto}="cd -P"
_goto()
{
local IFS=$'\n'
COMPREPLY=( $( compgen -W "$(/bin/ls ~/.bookmarks)" -- ${COMP_WORDS[COMP_CWORD]}))
} && complete -F _goto goto go g
fi

Simple BASH bookmarks

# pg-up/down autocompletion
# https://superuser.com/questions/171999/smart-tab-completion-for-directories
bind '"\e[6~": menu-complete'
bind '"\e[5~": menu-complete-backward'

Create ~/.bookmarks and symlink folders inside it. I name mine starting with @ e.g. ln -s /usr/local/src @src

Then you can g and go to the folder.

Inspired from:

Another similar idea here https://medium.com/@marko.luksa/linux-osx-shell-trick-create-bookmarks-so-you-can-cd-directly-into-the-dirs-you-use-regularly-64003051211f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment