yazi-3 :  Add some shell script

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


# 前置き: 簡単なshell-scriptを設置してみる。
Read previous articles, if needed. 

https://qiita.com/mjr_55/items/f027da4ebba3f36dd926

https://qiita.com/mjr_55/items/3416c5e17ce7120bdd08

# 1. Call shell from yazi & variables(変数).

- Read following page to call & run shell command.

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


#### 1-2. Outline.

- Find "shell" secsion like below.

```
Run a shell command.

Argument/Option	Description

[template]	Optional, command template to be run.

--block:	Open in a blocking manner. After setting this, Yazi will hide into a secondary screen and display the program on the main screen until it exits. During this time, it can receive I/O signals, which is useful for interactive programs.

--orphan:	Keep the process running even if Yazi has exited, once specified, the process will be detached from the task scheduling system.

--interactive:	Request the user to input the command to be run interactively

--cursor:	Set the initial position of the cursor in the interactive command input box. 
For example, shell 'zip -r .zip "$0"' --cursor=7 --interactive places the cursor before .zip.
```

- Some Variables.
```
You can use the following shell variables in [run]:

$n (Unix) / %n (Windows): The N-th selected file, starting from 1. e.g. $2 represents the second selected file.
$@ (Unix) / %* (Windows): All selected files, i.e. $1, $2, ..., $n.
$0 (Unix) / %0 (Windows): The hovered file.
```

- ささやかな補足。（上の英語がわかる人は不要。）
次の章を読めば、わかりますが、例えば、以下のように使います。

```
 'shell  "command $0" --block'
```

- optionに注意。
```
--block # file managerの画面が切り替わり、terminalの画面に。exitでfile managerに戻ります。

--interactive #  file manager 上で floatの　sehllが現れ、そこに直接入力するようです。
                 BGで動くのか？ 動作は未確認。
```

以下の画面が --ineractive？

![7-yazi-shell-iteractive.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/8fd0a629-71be-443c-8d87-59a933e9a266.jpeg)


#### 1-2. Variables


```
$n (Unix) : The N-th selected file, starting from 1. e.g. $2 represents the second selected file.
$@ (Unix) : All selected files, i.e. $1, $2, ..., $n.

## 以下がわかりにくいが、カーソルがあるfile？

$0 (Unix) : The hovered file.
```

```
white area:  $0    カーソル下の白い部分のfileが $0 のようだ。
head yelow : $@    黄色になっている部分が $@ ?
```

![7-yazi-shell-hover_files.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/332398fa-751f-4f6d-90d0-8abe56e50082.jpeg)

##### 以下に興味深い記事がある。

#### Next Tab macros

https://github.com/sxyazi/yazi/issues/1318

以下のような変数が今も使えるのか、どうか不明？


>Yazi has a set of equivalents like **$0** for **%c** , **$PWD** for **%d*, **$@** and **"$*"** for **%p**. For **%f** and **%s**, you can get them using basename, like **$(basename "$0")**. I'm not sure what **%t** means in the context of "tagged files"


上の引用から推測。

間違っていたら、ごめんなさいね。
Sorry, if I missunderstand about blow vriables. 
```
    $PWD : current directory.  
    $(basename "$0")   : the highlighted file basename
    $(basename "$0")   : the selected files basename in the current directory
    %0   : the full paths of the currently copied/cut files
    %@   : the full paths of selected files
```




# 2. Some examples of my script.

### use prefix "x"

## 2-1. Display file using "less" or "bat".

Sometimes, I use **less, lv** to read a file.
Rust's **bat** has a nice way to display a file.

Display file under the cursor: $0 (white)

![7-yazi-shell-hover_files.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/332398fa-751f-4f6d-90d0-8abe56e50082.jpeg)

```
[[manager.prepend_keymap]]
on   = [ "x", "i" ]
run  = 'shell  "/usr/bin/less $0" --block'
desc = show file, less "

[[manager.prepend_keymap]]
on   = [ "x", "I" ]
run  = 'shell  "/usr/bin/bat $0" --block'
desc = "show file, bat "
```

## 2-2. Backup, copy etc a file or directory under the cursor.
Copy etc file or directory under the cursor: $0 (white)

![7-yazi-shell-hover_files.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/332398fa-751f-4f6d-90d0-8abe56e50082.jpeg)


You had better create a shell-script and place it in your PATH.
I place mine under "$HOME/bin/" .

```
[[manager.prepend_keymap]]
on   = [ "x", "b" ]
run  = 'shell  "$HOME/bin/backup-file.sh $0" '
desc = "backup file"
```

## 2-3. Show "diff" between files, or open multiple files, using vim.

Select files using yazi's visual mode before run.: $@ (yellow)

![7-yazi-shell-hover_files.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786524/332398fa-751f-4f6d-90d0-8abe56e50082.jpeg)


```
## vim -d
[[manager.prepend_keymap]]
on   = [ "x", "d" ]
run  = 'shell  "/usr/bin/vim -d $@" --block'
desc = "vim -d files"

## vim -o
[[manager.prepend_keymap]]
on   = [ "x", "o" ]
run  = 'shell  "/usr/bin/vim -O $@" --block'
desc = "vim -O files"
```

# Reference

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

#### Curious exmpales, but not sure they work or not...
https://github.com/sxyazi/yazi/issues/1318