yazi-1:  CLI file manager , created with Rust.

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

# 前置き：my favorite file manager.

 ここ数年で、GUIからほぼCUI?の環境に移行しました。おかげで、GUIのfilemanger（explore, finder, Thunar etc）を使わなくなりました。マウス面倒だし。ただWEBは仕方ない。。。

#### [lf](https://github.com/gokcehan/lf): ここ数年、最も愛用利しているfile manager. Go言語 
　長所：カスタマイズが容易。速い。複数の **lf** を跨いでコピーができる。vimのpluginあり。
　短所：previewの設定が面倒。

#### [nnn](https://github.com/jarun/nnn): remoteのmount機能が素晴らしい。
　長所：packageの容量は小さいが高性能。sshfsなどでremoteを容易にmount。plugin多数。
　短所：小気味良いが、見た目がすこし味気ないか。pluginの設定が多少面倒。

#### vifm: 上記を利用できない環境で利用。classicなfiler。
　長所：上記よりは利用できる環境が多い気がする。keybindはvimとほぼ同じ。
　短所：機能が少ない。多少設定を弄らなと、使いにくいかも。
以下に良い解説がある。
 
https://pc.oreda.net/software/filer/vifm


 
閑話休題。私がyaziで注目しているのは

**高速、多機能、preview機能（terminal上での）。**

なかでもpreviewが素晴らしい。**特にsshでログインしたremote-PCにあるfileの画像をterminal上で綺麗に表示できまる。** 仕事で多量の画像を扱う私には欲しかった機能です。ただ、この機能を利用するにはterminalを選ぶ必要がある。(以下参照。)

https://yazi-rs.github.io/docs/image-preview

**Yazi shows remote PC's image file(right-side)  cleary on terminal, after ssh log-in.**

![3-2_plugin-pr-remotePC-2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/57f5ae8a-bb8b-4a61-852f-30fad3b75f58.jpeg)

yaziの由来は中国語の「アヒル」のようです。高速な動作がうりなのに、「アヒル」とはjoke？

>Yazi (means "duck") is a terminal file manager written in Rust, based on non-blocking async I/O. 

>The developer chose the name "Yazi" because it means "duck" in Chinese (鸭子). This name reflects the project's origins and adds a unique, memorable touch to the terminal file manager

**今回はthemeを除いた設定を中心に紹介します。**

# 0. Preparation
**!! Attention!!**
- Read carefully following page, which include install, config, tips, etc...
- require yazi version　25.2.26-1 or higher.

https://yazi-rs.github.io/docs/installation

# 1. install (manjaro-linux)

```sh
## full install
sudo pacman -S yazi ffmpeg p7zip jq poppler fd ripgrep fzf zoxide imagemagick

## For a minimal installation, Yazi only.
sudo pacman -S yazi
```

If you like to use yazi on windows, mac etc, read this page.

https://yazi-rs.github.io/docs/installation


**Add follows to  ~/.zshrc**

move to yazi's current-working directory, finishing yazi.

```sh
function y() {
	local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
	yazi "$@" --cwd-file="$tmp"
	if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
		builtin cd -- "$cwd"
	fi
	rm -f -- "$tmp"
}
```

**Add follows to .tmux.conf**, for preview.

https://yazi-rs.github.io/docs/image-preview

```sh
set -g allow-passthrough on
set -ga update-environment TERM
set -ga update-environment TERM_PROGRAM
```

# 2. config files

```
yazi.toml - General configuration.
keymap.toml - Keybindings configuration.
theme.toml - Color scheme configuration.
```

### 2-1. place config file at following directory.

```sh
mkdir -p ~/.config/yazi
```

### 2-2. Default config files on git. And download raw files from below.

https://github.com/sxyazi/yazi/tree/shipped/yazi-config/preset

### 3. Edit cofig files

**!! require yazi version 25.2 or higher !!**

#### 3-1. yazi.toml 
#### A. Reduce column 3 to 2 & show hidden. files

```
## modify manager sction.

 [manager]
  ## Set the value to 0 to hide the corresponding panel, 
  ## but at least one panel must be visible (non-zero).
  
  ratio          = [ 0, 1, 1 ]   ## 2 cols
  #ratio          = [ 1, 4, 3 ]  ## default 3 cols.

  ## show hidden files
  show_hidden    = true

```

default : 3-clos
![3_yazi_col-3.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/130527e0-2ae9-4def-a0cb-2074d32825fb.jpeg)


mine : 2-cols.  why need 3 cols...
![3_yazi_col-2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/e5cf4da0-5aa0-4220-b5c9-e2e17291d434.jpeg)


#### B. customize image opner. 

Because **Yazi takes a few seconds to open images on WSL + Windows Terminal.**
If you use yazi on linux & mac, you do *not* need.

```
## add following at the end of opener section
[opener] 

  my_img = [
      { run = '/usr/bin/viewnior "$1"',     desc = "Open", for = "linux" },
  ]

## modify open section

  [open]
  rules = [
      # Folder
      { name = "*/", use = [ "edit", "open", "reveal" ] },
      # Text
      { mime = "text/*", use = [ "edit", "reveal" ] },
      # Image
  #   { mime = "image/*", use = [ "open", "reveal" ] },   ## default
      { mime = "image/*", use = [ "my_img", "reveal" ] }, ## mine
      # Media
      { mime = "{audio,video}/*", use = [ "play", "reveal" ] },
```

#### 3-2. key.tmol

**!! Attention !!**
- 記載方法にprepend とappendがあり、配置する場所に注意。
概ねprependを使って、defaultの前に配置すれば、dafeultのkey-bindingsを上書きできる?

- pluginはここに記載して、利用するようだ。

>In each layer, there are two attributes: prepend_keymap and append_keymap. Prepend inserts before the default keybindings, while append inserts after them.

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

```
Prepend : inserts before the default keybindings.

append  : inserts after default.
```


#### A. Add bookmark(default bookmark)

*can use 3rd-pary bokmar plugin. Read below secsion C.*
```
## sample.
## "g" as prefix for bookmark.
## g >> y; go to yazi config dir.
  [[manager.prepend_keymap]]
  on   = [ "g", "y" ]
  run  = "cd ~/.config/yazi"
  desc = "cd ~/.config/yazi"
```

#### B. Add plugins and  some useful tools.

https://github.com/yazi-rs/plugins

https://yazi-rs.github.io/docs/tips

#### Install plugins.
**Read following page cafully.**
I git clone plugin page inside ```~/.config/yazi```, but it is not corrcet...


https://yazi-rs.github.io/docs/cli

```sh
## example. install maxpreview.

ya pack -a yazi-rs/plugins:max-preview
```


##### Some of my favorite plugins & useful tools.
```
## T : hide preview window.
 [[manager.prepend_keymap]]
 on   = "T"
 run  = "plugin toggle-pane min-preview"
 desc = "Show or hide the preview pane"

## cont-t :ax-preview window.
 [[manager.prepend_keymap]]
 on   = "<C-t>"
 run  = "plugin toggle-pane max-preview"
 desc = "Maximize or restore the preview pane"

## ! : open shell
 [[manager.prepend_keymap]]
 on   = "!"
 run  = 'shell "$SHELL" --block'
 desc = "Open shell here"

## ecape : use as "close". 
 [[input.prepend_keymap]]
 on   = "<Esc>"
 run  = "close"
 desc = "Cancel input"

## l (エル not 1) : open file.
 [[manager.prepend_keymap]]
 on   = "l"
 run  = "plugin smart-enter"
 desc = "Enter the child directory, or open the file"

## bookamark
## create its own bookmarks; bookmarkcache inside plugin-dir.
## https://gitee.com/DreamMaoMao/bookmarks.yazi
## "u" as prefix
[[manager.prepend_keymap]]
on = [ "u", "a" ]
run = "plugin bookmarks 'save'"
desc = "Save current position as a bookmark"

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

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

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

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

#### C. Some comment about bookmark plugins.

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

- git clone following page.

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

- **should modify original bookmak plugin's setting.**
Maybe the original setting is old, and "--args" option is deprecated now.

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

- contents of bookmarkcache inside plugins.
Seems to be able to modify this file usig editor. 
```
## sample
## u >> y ; go to yazi config dir.
y###/home/wan/.config/yazi/yazi.toml/###yazi###false
c###/home/wan/.config/###config###true
```

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



#### D. Sample of plugin's effects.

default view
![3-2_plugin_hide_pr-0.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/299b4583-a4e0-4987-8ff7-2d968014833c.jpeg)


hida preview
![3-2_plugin_hide_pr-1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/5cf9ccb6-eb31-4373-9578-b8f79cdf023a.jpeg)

max-preview
![3-2_plugin_max_pr-1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/d9e67392-9964-4732-9c10-681b3f4ba847.jpeg)


**Yazi show remote PC's image file(right-side)  cleary on terminal, after ssh log-in.**

![3-2_plugin-pr-remotePC-2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/57f5ae8a-bb8b-4a61-852f-30fad3b75f58.jpeg)

### 4. Some useful functions.

#### 4-1. search using fd, rg.
```
type "s" : fd file or directory search
```
![5-search_fd-2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/5925f6e3-49b2-411a-b7c8-f62e5e24b91c.jpeg)

```
type "S" : rg contents saerch
```
![5-search_rg-2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/82a85a06-c78f-4b42-a419-5e252b5a4737.jpeg)

#### 4-2. task manager

```
type "w" : show up task manager

then,
return : show each task content

or
type "x" : cancel task ## but can not cancel copy on my env.  why?

escape : close window
```

task manager window (hover)

![5-rask_manager.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/c3aa3830-5dc5-4664-a47e-1f9cc22b8247.jpeg)



#### 5. key bindings.

**nice reference page.**
Find keys for copy, pastey, etc on this page.

https://kb.adamsdesk.com/application/yazi-keyboard-shortcuts/?utm_source=pocket_shared


# Reference
- Quick start

https://yazi-rs.github.io/docs/installation

- key bindings

https://kb.adamsdesk.com/application/yazi-keyboard-shortcuts/?utm_source=pocket_shared

- yazi/git

https://github.com/sxyazi/yazi

- yazi/ plugins

https://github.com/yazi-rs/plugins

- lots of 3rd party plugins?, but not official.

https://github.com/AnirudhG07/awesome-yazi

- Qiita articles

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