custom-hypr - add yazi config
This commit is contained in:
21
.config/yazi/plugins/rich-preview.yazi/LICENSE
Normal file
21
.config/yazi/plugins/rich-preview.yazi/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Anirudh Gupta
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
75
.config/yazi/plugins/rich-preview.yazi/README.md
Normal file
75
.config/yazi/plugins/rich-preview.yazi/README.md
Normal file
@@ -0,0 +1,75 @@
|
||||
# rich-preview.yazi
|
||||
|
||||
Preview file types using `rich` command in Yazi. This plugin allows preview for various filetypes including -
|
||||
|
||||
- Markdown
|
||||
- Jupyter notebook
|
||||
- JSON
|
||||
- CSV
|
||||
- RestructuredText
|
||||
|
||||
## Previews/Screenshots
|
||||
|
||||
[rich-preview1.webm](https://github.com/user-attachments/assets/580e36a8-249f-48a8-95fc-8c3d60e6a7d7)
|
||||
|
||||
## Requirements
|
||||
|
||||
- [Yazi](https://github.com/sxyazi/yazi) v0.4 or higher.
|
||||
- [rich-cli](https://github.com/Textualize/rich) v13.7.1 or higher.
|
||||
|
||||
## Installation
|
||||
|
||||
To install this plugin, simply run-
|
||||
|
||||
```bash
|
||||
ya pack -a AnirudhG07/rich-preview
|
||||
## For linux and MacOS
|
||||
git clone https://github.com/AnirudhG07/rich-preview.yazi.git ~/.config/yazi/plugins/rich-preview.yazi
|
||||
|
||||
## For Windows
|
||||
git clone https://github.com/AnirudhG07/rich-preview.yazi.git %AppData%\yazi\config\plugins\rich-preview.yazi
|
||||
```
|
||||
|
||||
## Usages
|
||||
|
||||
The `rich` commands automatically detects if the file is markdown, csv, json, etc. files and accordingly the preview is viewed.
|
||||
|
||||
Add the below to your `yazi.toml` file to allow the respective file to previewed using `rich`.
|
||||
|
||||
```toml
|
||||
[plugin]
|
||||
|
||||
prepend_previewers = [
|
||||
{ name = "*.csv", run = "rich-preview"}, # for csv files
|
||||
{ name = "*.md", run = "rich-preview" }, # for markdown (.md) files
|
||||
{ name = "*.rst", run = "rich-preview"}, # for restructured text (.rst) files
|
||||
{ name = "*.ipynb", run = "rich-preview"}, # for jupyter notebooks (.ipynb)
|
||||
{ name = "*.json", run = "rich-preview"}, # for json (.json) files
|
||||
# { name = "*.lang_type", run = "rich-preview"} # for particular language files eg. .py, .go., .lua, etc.
|
||||
]
|
||||
```
|
||||
|
||||
## Configurations
|
||||
|
||||
If you would like to use `rich` with more configurations, you can go to `init.lua` and edit the arguments in the code with your preferences. You can view the options using `rich --help`.
|
||||
|
||||
```lua
|
||||
-- init.lua
|
||||
"-j",
|
||||
"--left",
|
||||
"--line-numbers",
|
||||
"--force-terminal",
|
||||
"--panel=rounded",
|
||||
"--guides",
|
||||
"--max-width" -- to area of preview
|
||||
```
|
||||
|
||||
You can add more, remove and choose themes as you wish. You can set styles or Themes(as mentioned in `rich --help`) by `--theme=your_theme` and similarly for style.
|
||||
|
||||
## Notes
|
||||
|
||||
Currently the colors maynot be uniformly present, along with weird lines here and there. This is due to `"--force-terminal"` option. You can disable it if you find it annoying. Work is in progress to possibly fix the issue.
|
||||
|
||||
# Explore Yazi
|
||||
|
||||
Yazi is an amazing, blazing fast terminal file manager, with a variety of plugins, flavors and themes. Check them out at [awesome-yazi](https://github.com/AnirudhG07/awesome-yazi) and the official [yazi webpage](https://yazi-rs.github.io/).
|
||||
53
.config/yazi/plugins/rich-preview.yazi/main.lua
Normal file
53
.config/yazi/plugins/rich-preview.yazi/main.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
local M = {}
|
||||
|
||||
function M:peek(job)
|
||||
local child = Command("rich")
|
||||
:args({
|
||||
"-j",
|
||||
"--left",
|
||||
"--line-numbers",
|
||||
"--force-terminal",
|
||||
"--panel=rounded",
|
||||
"--guides",
|
||||
"--max-width",
|
||||
tostring(job.area.w),
|
||||
tostring(job.file.url),
|
||||
})
|
||||
:stdout(Command.PIPED)
|
||||
:stderr(Command.PIPED)
|
||||
:spawn()
|
||||
|
||||
if not child then
|
||||
return require("code"):peek(job)
|
||||
end
|
||||
|
||||
local limit = job.area.h
|
||||
local i, lines = 0, ""
|
||||
repeat
|
||||
local next, event = child:read_line()
|
||||
if event == 1 then
|
||||
return require("code"):peek(job)
|
||||
elseif event ~= 0 then
|
||||
break
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
if i > job.skip then
|
||||
lines = lines .. next
|
||||
end
|
||||
until i >= job.skip + limit
|
||||
|
||||
child:start_kill()
|
||||
if job.skip > 0 and i < job.skip + limit then
|
||||
ya.manager_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
|
||||
else
|
||||
lines = lines:gsub("\t", string.rep(" ", PREVIEW.tab_size))
|
||||
ya.preview_widgets(job, { ui.Text.parse(lines):area(job.area) })
|
||||
end
|
||||
end
|
||||
|
||||
function M:seek(job)
|
||||
require("code"):seek(job)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user