Skip to content

Commit

Permalink
Add customization instructions in README
Browse files Browse the repository at this point in the history
  • Loading branch information
urbainvaes committed Mar 30, 2018
1 parent 23de3ea commit f9a54a6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# fzf-marks
This thin plugin can be used to create, delete, and navigate marks in Bash and Zsh.
This plugin can be used to create, delete, and navigate marks in *bash* and *zsh*.
It depends on Junegunn Choi's fuzzy-finder [fzf](https://github.com/junegunn/fzf).

![](https://raw.github.com/uvaes/fuzzy-zsh-marks/demo/demo.gif)

## Installation
# Installation

If you use zsh, I recommend installing with a plugin manager.
If you use *zsh*, I recommend installing with a plugin manager.
With [zgen](https://github.com/tarjoilija/zgen),
this can be done by adding the following line to the plugin list.
this can be done by adding the following line to the plugin list:
```zsh
zgen load urbainvaes/fzf-marks
```

If you use bash,
or if you use zsh without without a plugin manager,
If you use *bash*,
or if you use *zsh* without without a plugin manager,
the plugin can be enabled by sourcing the file
`fzf-marks.plugin.bash` or `fzf-marks.plugin.zsh` from your shell startup file.

Expand All @@ -30,20 +30,28 @@ echo "source $PWD/fzf-marks/fzf-marks.plugin.bash" >> ~/.bashrc
source fzf-marks/fzf-marks.plugin.bash
```

## Usage
Most of the key bindings in the search window are the default fzf ones.
The most relevant ones are:
# Usage
Most of the keybindings in the search window are the default fzf ones.
The only additions are

- **ctrl-n** / **ctrl-p** to go to the next/previous match.
- **ctrl-y** or **Enter** to accept a match.
- **ctrl-t** to toggle a match for deletion.
- **ctrl-y**, to accept a match;
- **ctrl-t**, to toggle a match for deletion.

In Zsh or Bash, the script creates three commands:
Both in *bash* and *zsh*, the script creates three commands:

- **mark** to create a new bookmark. For example, `mark work` creates a bookmark labeled work.
- **jump** to jump to a given bookmark using fzf. By default, the script binds this function to **ctrl-g**.
- **dmark** to delete marks toggled for deletion.
- **mark**, to create a new mark;
- **jump**, to jump to a mark;
- **dmark**, to delete the marks toggled for deletion.

## License
# Customization

| Config | Default | Description |
| ------ | ------- | ----------- |
| `FZF_MARKS_FILE` | `${HOME}/.fzf-marks` | File containing the marks data |
| `FZF_MARKS_COMMAND` | `fzf --height 40% --reverse` | Command used to call `fzf` |
| `FZF_MARKS_JUMP` | `\C-g` (*bash*) or `^g` (*zsh*) | Keybinding to `jump` |
| `FZF_MARKS_DMARK` | None | Keybinding to `dmark` |

# License

MIT
24 changes: 12 additions & 12 deletions fzf-marks.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if [[ -z "${BOOKMARKS_FILE}" ]] ; then
export BOOKMARKS_FILE="${HOME}/.bookmarks"
if [[ -z "${FZF_MARKS_FILE}" ]] ; then
export FZF_MARKS_FILE="${HOME}/.fzf-marks"
fi

if [[ ! -f "${BOOKMARKS_FILE}" ]]; then
touch "${BOOKMARKS_FILE}"
if [[ ! -f "${FZF_MARKS_FILE}" ]]; then
touch "${FZF_MARKS_FILE}"
fi

if [[ -z "${FZF_MARKS_COMMAND}" ]] ; then
Expand All @@ -26,39 +26,39 @@ function mark() {
local mark_to_add
mark_to_add="$* : $(pwd)"

if grep -qxFe "${mark_to_add}" "${BOOKMARKS_FILE}"; then
if grep -qxFe "${mark_to_add}" "${FZF_MARKS_FILE}"; then
echo "** The following mark already exists **"
else
echo "${mark_to_add}" >> "${BOOKMARKS_FILE}"
echo "${mark_to_add}" >> "${FZF_MARKS_FILE}"
echo "** The following mark has been added **"
fi
echo "${mark_to_add}"
}

function handle_symlinks() {
local fname
if [ -L "${BOOKMARKS_FILE}" ]; then
fname=$(readlink "${BOOKMARKS_FILE}")
if [ -L "${FZF_MARKS_FILE}" ]; then
fname=$(readlink "${FZF_MARKS_FILE}")
else
fname=${BOOKMARKS_FILE}
fname=${FZF_MARKS_FILE}
fi
echo "${fname}"
}

function jump() {
local jumpline jumpdir bookmarks
jumpline=$($(echo ${FZF_MARKS_COMMAND}) --bind=ctrl-y:accept --query="$*" --select-1 --tac < "${BOOKMARKS_FILE}")
jumpline=$($(echo ${FZF_MARKS_COMMAND}) --bind=ctrl-y:accept --query="$*" --select-1 --tac < "${FZF_MARKS_FILE}")
if [[ -n ${jumpline} ]]; then
jumpdir=$(echo "${jumpline}" | sed -n 's/.* : \(.*\)$/\1/p' | sed "s#~#${HOME}#")
bookmarks=$(handle_symlinks)
perl -n -i -e "print unless /^${jumpline//\//\\/}\$/" "${bookmarks}"
cd "${jumpdir}" && echo "${jumpline}" >> "${BOOKMARKS_FILE}"
cd "${jumpdir}" && echo "${jumpline}" >> "${FZF_MARKS_FILE}"
fi
}

function dmark() {
local marks_to_delete line bookmarks
marks_to_delete=$($(echo ${FZF_MARKS_COMMAND}) -m --bind=ctrl-y:accept,ctrl-t:toggle --query="$*" --tac < "${BOOKMARKS_FILE}")
marks_to_delete=$($(echo ${FZF_MARKS_COMMAND}) -m --bind=ctrl-y:accept,ctrl-t:toggle --query="$*" --tac < "${FZF_MARKS_FILE}")
bookmarks=$(handle_symlinks)

if [[ -n ${marks_to_delete} ]]; then
Expand Down
24 changes: 12 additions & 12 deletions fzf-marks.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if [[ -z "${BOOKMARKS_FILE}" ]] ; then
export BOOKMARKS_FILE="${HOME}/.bookmarks"
if [[ -z "${FZF_MARKS_FILE}" ]] ; then
export FZF_MARKS_FILE="${HOME}/.fzf-marks"
fi

if [[ ! -f "${BOOKMARKS_FILE}" ]]; then
touch "${BOOKMARKS_FILE}"
if [[ ! -f "${FZF_MARKS_FILE}" ]]; then
touch "${FZF_MARKS_FILE}"
fi

if [[ -z "${FZF_MARKS_COMMAND}" ]] ; then
Expand All @@ -26,21 +26,21 @@ function mark() {
local mark_to_add
mark_to_add="$* : $(pwd)"

if grep -qxFe "${mark_to_add}" "${BOOKMARKS_FILE}"; then
if grep -qxFe "${mark_to_add}" "${FZF_MARKS_FILE}"; then
echo "** The following mark already exists **"
else
echo "${mark_to_add}" >> "${BOOKMARKS_FILE}"
echo "${mark_to_add}" >> "${FZF_MARKS_FILE}"
echo "** The following mark has been added **"
fi
echo "${mark_to_add}"
}

function handle_symlinks() {
local fname
if [ -L "${BOOKMARKS_FILE}" ]; then
fname=$(readlink "${BOOKMARKS_FILE}")
if [ -L "${FZF_MARKS_FILE}" ]; then
fname=$(readlink "${FZF_MARKS_FILE}")
else
fname=${BOOKMARKS_FILE}
fname=${FZF_MARKS_FILE}
fi
echo "${fname}"
}
Expand All @@ -57,19 +57,19 @@ zle -N redraw-prompt

function jump() {
local jumpline jumpdir bookmarks
jumpline=$($(echo ${FZF_MARKS_COMMAND}) --bind=ctrl-y:accept --query="$*" --select-1 --tac < "${BOOKMARKS_FILE}")
jumpline=$($(echo ${FZF_MARKS_COMMAND}) --bind=ctrl-y:accept --query="$*" --select-1 --tac < "${FZF_MARKS_FILE}")
if [[ -n ${jumpline} ]]; then
jumpdir=$(echo "${jumpline}" | sed -n 's/.* : \(.*\)$/\1/p' | sed "s#~#${HOME}#")
bookmarks=$(handle_symlinks)
perl -n -i -e "print unless /^${jumpline//\//\\/}\$/" "${bookmarks}"
cd "${jumpdir}" && echo "${jumpline}" >> "${BOOKMARKS_FILE}"
cd "${jumpdir}" && echo "${jumpline}" >> "${FZF_MARKS_FILE}"
fi
zle && zle redraw-prompt
}

function dmark() {
local marks_to_delete line bookmarks
marks_to_delete=$($(echo ${FZF_MARKS_COMMAND}) -m --bind=ctrl-y:accept,ctrl-t:toggle --query="$*" --tac < "${BOOKMARKS_FILE}")
marks_to_delete=$($(echo ${FZF_MARKS_COMMAND}) -m --bind=ctrl-y:accept,ctrl-t:toggle --query="$*" --tac < "${FZF_MARKS_FILE}")
bookmarks=$(handle_symlinks)

if [[ -n ${marks_to_delete} ]]; then
Expand Down

0 comments on commit f9a54a6

Please sign in to comment.