-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
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
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) |
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
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 |
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
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 |