Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gturi committed Oct 2, 2021
2 parents 976789a + 2291f5c commit 597d050
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# bash-bookmarks
utility to bookmark directories

Utility to bookmark directories, avoiding the hassle of remembering/typing long path names to reach them.

## Usage

First you need to bookmark a directory using the `bookmark` command:

```bash
bookmark /path/to/directory/to/bookmark @bookmark-name
```

Then use `goto` command to quickly `cd` to the bookmarked directory:

```bash
goto @bookmark-name
```

Finally you can use `unbookmark` command to remove a bookmark:

```
unbookmark @bookmark-name
```

Tip: using `@` prefix (or another common prefix) before every bookmark allows you to easily find a bookmark thanks to bash autocompletion.

If anything goes wrong, your bookmarks will be stored inside `$HOME/.bookmarks` directory (they are actually just symbolic links to your directories). And remember to file an issue!

## Install

Run `install.sh` script. The changes will be loaded from the next terminal session you will open.

## Uninstall

Remove the following lines from your `.bashrc`:

```bash
# bash bookmarks
if [ -f "/path/to/bash-bookmarks.sh" ]; then
source "/path/to/bash-bookmarks.sh"
fi
```

Remove `$HOME/.bookmarks` directory.

## License

[GPL-3.0](LICENSE)
38 changes: 38 additions & 0 deletions bash-bookmarks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

BOOKMARK_DIR="$HOME/.bookmarks"

# create bookmark directory if it does not exists
[ -d "$BOOKMARK_DIR" ] || mkdir "$BOOKMARK_DIR"

if [ -d "$BOOKMARK_DIR" ]; then
export CDPATH=".:$BOOKMARK_DIR:/"

alias goto="cd -P"
# goto completion function
_goto() {
local IFS=$'\n'
local cur=${COMP_WORDS[COMP_CWORD]}
local BOOKMARK_LIST="$(/bin/ls $BOOKMARK_DIR)"
COMPREPLY=( $( compgen -W "$BOOKMARK_LIST" -- ${cur}) )
} && complete -F _goto goto

function bookmark {
# $1: directory that will be bookmarked
# $2: bookmark name
ln -s "$1" "$BOOKMARK_DIR/$2"
}

function unbookmark {
# $1: bookmark name
rm "$BOOKMARK_DIR/$1"
}
# unbookmark completion function
_unbookmark() {
local IFS=$'\n'
local cur=${COMP_WORDS[COMP_CWORD]}
local BOOKMARK_LIST="$(/bin/ls $BOOKMARK_DIR)"
COMPREPLY=( $( compgen -W "$BOOKMARK_LIST" -- ${cur}) )
} && complete -F _unbookmark unbookmark

fi
20 changes: 20 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# gets the absolute path to directory containing this script
DIR=$(dirname $(readlink -f $0))

SCRIPT=$DIR/bash-bookmarks.sh

if [ -f "$SCRIPT" ]; then
# adds to .bashrc
# # bash bookmarks
# if [ -f "$SCRIPT" ]; then
# source "$SCRIPT"
# fi
printf '\n%s\n%s\n%s\n%s\n' \
"# bash bookmarks" \
"if [ -f \"$SCRIPT\" ]; then" \
" source \"$SCRIPT\"" \
'fi' \
>> "$HOME/.bashrc"
fi

0 comments on commit 597d050

Please sign in to comment.