yazi-2 : plugin, DreamMaoMoa/bookmarks & zoxide

- 注意：以下の記事を参考にされ、問題が生じた場合、責任は負えません。
- 基本的には私の忘備録です。
- 使用環境は **manjaro-linux** と時々macです。
- windowsでは利用できない設定があります。
- 本文を英語で記載してますが、中学生レベルですので、容易に理解できると思います。
- 英語で書くと、わかりにくいと思われる部分は、日本語にしてます。
- link先に了解なく引用している部分がありますので、問題があればご連絡ください。
- 質門に回答できるのかは不明です。

# 前置き：

設定などは[前回参照。](https://qiita.com/mjr_55/items/f027da4ebba3f36dd926)

# 1. About DreamMaoMao/bookmarks plugins.

I use this plugin to manage bookmarks. This tool is convinient and easy to use, comapring to origainal bookmark. I like it. 

https://gitee.com/DreamMaoMao/bookmarks.yazi



# 2. Install.

- git clone following page.

```sh
git clone https://github.com/DreamMaoMao/bookmarks.yazi.git ~/.config/yazi/plugins/bookmarks.yazi
```



# 3. Add its setting to keymap.toml & modify original settings. 

- **should modify original setting.**
The original setting may be old, and **delete "--args".** It is deprecated now.

```
vim  keymap.toml

[[manager.prepend_keymap]]
on = [ "u", "a" ]
- run = "plugin bookmarks --args='save'"  ## del --args
+  run = "plugin bookmarks 'save'"
desc = "Save current position as a bookmark"
```


### !! Place the following setting above the default keymap. !!
>In each layer, there are two attributes: prepend_keymap and append_keymap. Prepend inserts before the default keybindings, while append inserts after them.

>Since Yazi selects the first matching key to run, prepend always has a higher priority than default, and append always has a lower priority than default:

- my keymap.toml

I use "g" & "b" to override original "u".

```
##====== bookamark ==========================
## create its own bookmarks; bookmarkcache inside plugin-dir
## https://gitee.com/DreamMaoMao/bookmarks.yazi

## show bookmark. 
[[manager.prepend_keymap]]
on = [ "g" ]
run = "plugin bookmarks  'jump'"
desc = "Jump to a bookmark"

## call add, edit, del bokmark.
##  prefix b

## use cd.
[[manager.prepend_keymap]]
on = [ "b", "<Space>" ]
run = "cd --interactive"
desc = "Jump interactively"

[[manager.prepend_keymap]]
on = [ "b", "a" ]
run = "plugin bookmarks 'save'"
desc = "Save current position as a bookmark"

[[manager.prepend_keymap]]
on = [ "b", "d" ]
run = "plugin bookmarks 'delete'"
desc = "Delete a bookmark"

[[manager.prepend_keymap]]
on = [ "b", "D" ]
run = "plugin bookmarks 'delete_all'"
desc = "Delete all bookmarks"

[[manager.prepend_keymap]]
on = [ "b", "m" ]
run = "plugin bookmarks 'modify'"
desc = "modify key bind to hoverd path"
```

- I override keys of zoxide (dir. search) & fzf (file search).
 
```
[[manager.prepend_keymap]]
on = ";"
#on = "z"              #default
run = "plugin zoxide"
desc = "Jump to a directory via zoxide"

[[manager.prepend_keymap]]
on = ":"
#on = "Z"              #default
run = "plugin fzf"
desc = "Jump to a file/directory via fzf"
```


# 4. Edit bookmark using editor, if needed. 

- This plugin creates bookmark as bookmarkcache inside plugin directory.

```
$HOME/.config/yazi/plugins/bookmarks.yazi/bookmarkcache
```

-  Seems to modify this file usig editor. 
- contents of bookmarkcache.
```
vim bookmarkcache  

## sample
c###$HOME/.config/###config###true
y###$HOME/.config/yazi/yazi.toml/###yazi###false
```
- Quiz: What does "false" mean? :thermometer_face:



# 5. Bookmark menu

- type g : show bookmark

![4-bookmark-hovor_type-g.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/8189f4a6-01b4-41af-afc2-011edb3eef5a.jpeg)


- type b : bookmark menu
![4-bookmark-hovor.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/6c9f0541-2b5f-4e9b-a25c-10e8754c1990.jpeg)




# 6. zoxide ; override "cd" with zoxide command.

### 6-1. Install
```
yay -S zoxide
```

### 6-2. Set up
"z" , "zi" seems to be aliased as default, but I used ```z: facd, zi: zinit.```

So, use other characters...
I like to replace **cd** to **zoxide command**.

[git explanation](https://github.com/ajeetdsouza/zoxide#configuration)


#### 6-2-A. Confirm the setting to override "cd" with zoxide command.

```
zoxide init --cmd cd zsh

# shellcheck shell=bash

# =============================================================================
#
# Utility functions for zoxide.
#

# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function __zoxide_pwd() {
    \builtin pwd -L
}

# cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd() {
    # shellcheck disable=SC2164
    \builtin cd -- "$@"
}

.....
```

#### 6-2-B. Output above setting and create file.
```
zoxide init --cmd cd zsh > add_to_zsh_cd
```

#### 6-2-C. Confirm, Before adding above to .zshrc.

- backup .zshrc. 
```cp -a ~/.zshrc ~/.zshrc_bk```

- add  ```####zoxide``` to .zshrc as a marker for adding zoxide setting.

```
sed '/####zoxide/r add_to_zsh_cd' ~/.zshrc| tail -n250

##////////////////////////
## zoxide
##
## https://github.com/ajeetdsouza/zoxide#configuration
## https://qiita.com/darallium/items/ed36c8e008dfd0fb5acf
##
####zoxide ////////////////////////
# shellcheck shell=bash
# =============================================================================
# Utility functions for zoxide.
#
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function __zoxide_pwd() {
    \builtin pwd -L
}

# cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd() {
    # shellcheck disable=SC2164
    \builtin cd -- "$@"
}
...
```

#### 6-2-D. Add & overwrite .zshrc

```
## backup .zshrc
cp -a ~/.zshrc ~/.zshrc_bk

## add file contents
sed -i '/####zoxide/r add_to_zsh_cd' ~/.zshrc
```

### 6-3. restart SHELL

```
exec $SHELL
```

#### 6-4. Some examples. 

- cdi : zoxide menu shows up.

![6-zoxide-cdi-2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/e603fa33-3b4b-4a10-af40-1bff753ad3fc.jpeg)


- cd : change directories using key words without specifying the correct path.
 > zoxide, which allows you to jump to directories based on partial matches of directory names. 

```
cd yazi

~/.config/yazi master*
```


# Reference

https://gitee.com/DreamMaoMao/bookmarks.yazi

https://yazi-rs.github.io/docs/configuration/keymap


### about zoxide.

https://github.com/ajeetdsouza/zoxide

https://qiita.com/darallium/items/ed36c8e008dfd0fb5acf

https://wonderwall.hatenablog.com/entry/rust-zoxide

https://qiita.com/P-man_Brown/items/cf8d568390a46e189f5c