diff options
| -rw-r--r-- | mac/.config/yazi/plugins/office.yazi/LICENSE | 21 | ||||
| -rw-r--r-- | mac/.config/yazi/plugins/office.yazi/README.md | 76 | ||||
| -rw-r--r-- | mac/.config/yazi/plugins/office.yazi/main.lua | 121 | ||||
| -rw-r--r-- | mac/.config/yazi/yazi.toml | 167 | ||||
| -rw-r--r-- | mac/.config/zsh/.zshrc | 13 |
5 files changed, 269 insertions, 129 deletions
diff --git a/mac/.config/yazi/plugins/office.yazi/LICENSE b/mac/.config/yazi/plugins/office.yazi/LICENSE new file mode 100644 index 0000000..fb5b1d6 --- /dev/null +++ b/mac/.config/yazi/plugins/office.yazi/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 yazi-rs + +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. diff --git a/mac/.config/yazi/plugins/office.yazi/README.md b/mac/.config/yazi/plugins/office.yazi/README.md new file mode 100644 index 0000000..c6fdf37 --- /dev/null +++ b/mac/.config/yazi/plugins/office.yazi/README.md @@ -0,0 +1,76 @@ +<div align="center"> + +# office.yazi +### A plugin to preview office documents in <a href="https://github.com/sxyazi/yazi">Yazi <img src="https://github.com/sxyazi/yazi/blob/main/assets/logo.png?raw=true" alt="a duck" width="24px" height="24px"></a> + +<img src="https://github.com/macydnah/office.yazi/blob/assets/preview_test.gif" alt="preview test" width="88%"> + +## + +</div> + +## Installation +> [!TIP] +> Installing this plugin with `ya` will conveniently clone the plugin from GitHub, +> copy it to your plugins directory, and update the `package.toml` to lock its version [^1]. +> +> To install it with `ya` run: +> ```sh +> ya pkg add macydnah/office +> ``` + +> Or if you prefer a manual approach: +> ```sh +> ## For linux and MacOS +> git clone https://github.com/macydnah/office.yazi.git ~/.config/yazi/plugins/office.yazi +> +> ## For Windows +> git clone https://github.com/macydnah/office.yazi.git %AppData%\yazi\config\plugins\office.yazi +> ``` + +## Usage +In your `yazi.toml` add rules to preloaders[^2] and previewers[^3] to run `office` plugin with office documents. + +> [!NOTE] +> Your config may be different depending if you're *appending*, *prepending* or *overriding* default rules. +> If unsure, take a look at [Configuration](https://yazi-rs.github.io/docs/configuration/overview)[^4] +> and [Configuration mixing](https://yazi-rs.github.io/docs/configuration/overview#mixing)[^5] + +For a general usecase, you may use the following rules +```toml +[plugin] + +prepend_preloaders = [ + # Office Documents + { mime = "application/openxmlformats-officedocument.*", run = "office" }, + { mime = "application/oasis.opendocument.*", run = "office" }, + { mime = "application/ms-*", run = "office" }, + { mime = "application/msword", run = "office" }, + { name = "*.docx", run = "office" }, +] + +prepend_previewers = [ + # Office Documents + { mime = "application/openxmlformats-officedocument.*", run = "office" }, + { mime = "application/oasis.opendocument.*", run = "office" }, + { mime = "application/ms-*", run = "office" }, + { mime = "application/msword", run = "office" }, + { name = "*.docx", run = "office" }, +] +``` + +## Dependencies +> [!IMPORTANT] +> Make sure that these commands are installed in your system and can be found in `PATH`: +> +> - `libreoffice` +> - `pdftoppm` + +## License +office.yazi is licensed under the terms of the [MIT License](LICENSE) + +[^1]: [The official package manager for Yazi](https://yazi-rs.github.io/docs/cli) +[^2]: [Preloaders rules](https://yazi-rs.github.io/docs/configuration/yazi#plugin.preloaders) +[^3]: [Previewers rules](https://yazi-rs.github.io/docs/configuration/yazi#plugin.previewers) +[^4]: [Configuration](https://yazi-rs.github.io/docs/configuration/overview) +[^5]: [Configuration mixing](https://yazi-rs.github.io/docs/configuration/overview#mixing) diff --git a/mac/.config/yazi/plugins/office.yazi/main.lua b/mac/.config/yazi/plugins/office.yazi/main.lua new file mode 100644 index 0000000..3ec7385 --- /dev/null +++ b/mac/.config/yazi/plugins/office.yazi/main.lua @@ -0,0 +1,121 @@ +--- @since 25.2.7 + +local M = {} + +function M:peek(job) + local start, cache = os.clock(), ya.file_cache(job) + if not cache then + return + end + + local ok, err = self:preload(job) + if not ok or err then + return + end + + ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock())) + ya.image_show(cache, job.area) + ya.preview_widgets(job, {}) +end + +function M:seek(job) + local h = cx.active.current.hovered + if h and h.url == job.file.url then + local step = ya.clamp(-1, job.units, 1) + ya.manager_emit("peek", { math.max(0, cx.active.preview.skip + step), only_if = job.file.url }) + end +end + +function M:doc2pdf(job) + local tmp = "/tmp/yazi-" .. ya.uid() .. "/" .. ya.hash("office.yazi") .. "/" + + --[[ For Future Reference: Regarding `libreoffice` as preconverter + 1. It prints errors to stdout (always, doesn't matter if it succeeded or it failed) + 2. Always writes the converted files to the filesystem, so no "Mario|Bros|Piping|Magic" for the data stream (https://ask.libreoffice.org/t/using-convert-to-output-to-stdout/38753) + 3. The `pdf:draw_pdf_Export` filter needs literal double quotes when defining its options (https://help.libreoffice.org/latest/en-US/text/shared/guide/pdf_params.html?&DbPAR=SHARED&System=UNIX#generaltext/shared/guide/pdf_params.xhp) + 3.1 Regarding double quotes and Lua strings, see https://www.lua.org/manual/5.1/manual.html#2.1 --]] + local libreoffice = Command("libreoffice") + :arg({ + "--headless", + "--convert-to", + "pdf:draw_pdf_Export:{" + .. '"PageRange":{' + .. '"type":"string",' + .. '"value":' + .. '"' + .. job.skip + 1 + .. '"' + .. "}" + .. "}", + "--outdir", + tmp, + tostring(job.file.url), + }) + :stdin(Command.NULL) + :stdout(Command.PIPED) + :stderr(Command.NULL) + :output() + + if not libreoffice.status.success then + ya.err( + libreoffice.stdout:match("LibreOffice .+"):gsub("%\n.*", "") + .. " " + .. libreoffice.stdout:match("Error .+"):gsub("%\n.*", "") + ) + return nil, Err("Failed to preconvert `%s` to a temporary PDF", job.file.name) + end + + local tmp = tmp .. job.file.name:gsub("%.[^%.]+$", ".pdf") + local read_permission = io.open(tmp, "r") + if not read_permission then + return nil, Err("Failed to read `%s`: make sure file exists and have read access", tmp) + end + read_permission:close() + + return tmp +end + +function M:preload(job) + local cache = ya.file_cache(job) + if not cache or fs.cha(cache) then + return true + end + + local tmp_pdf, err = self:doc2pdf(job) + if not tmp_pdf then + return true, Err(" " .. "%s", err) + end + + local output, err = Command("pdftoppm") + :arg({ + "-singlefile", + "-jpeg", + "-jpegopt", + "quality=" .. rt.preview.image_quality, + "-f", + 1, + tostring(tmp_pdf), + }) + :stdout(Command.PIPED) + :stderr(Command.PIPED) + :output() + + local rm_tmp_pdf, rm_err = fs.remove("file", Url(tmp_pdf)) + if not rm_tmp_pdf then + return true, Err("Failed to remove %s, error: %s", tmp_pdf, rm_err) + end + + if not output then + return true, Err("Failed to start `pdftoppm`, error: %s", err) + elseif not output.status.success then + local pages = tonumber(output.stderr:match("the last page %((%d+)%)")) or 0 + if job.skip > 0 and pages > 0 then + ya.mgr_emit("peek", { math.max(0, pages - 1), only_if = job.file.url, upper_bound = true }) + end + return true, Err("Failed to convert %s to image, stderr: %s", tmp_pdf, output.stderr) + end + + return fs.write(cache, output.stdout) +end + +return M diff --git a/mac/.config/yazi/yazi.toml b/mac/.config/yazi/yazi.toml index 205ee50..043ce96 100644 --- a/mac/.config/yazi/yazi.toml +++ b/mac/.config/yazi/yazi.toml @@ -6,7 +6,7 @@ ratio = [ 1, 2, 4 ] sort_by = "alphabetical" sort_sensitive = false -sort_reverse = false +sort_reverse = false sort_dir_first = true sort_translit = false linemode = "none" @@ -101,6 +101,11 @@ suppress_preload = false fetchers = [ # Mimetype { id = "mime", name = "*", run = "mime", prio = "high" }, + { id = "git", name = "*", run = "git" }, + { id = "git", name = "*/", run = "git" }, + { id = "mactag", name = "*", run = "mactag" }, + { id = "mactag", name = "*/", run = "mactag" }, + { id = "mime", name = "*", run = "mime-ext", prio = "high" }, ] spotters = [ { name = "*/", run = "folder" }, @@ -160,6 +165,43 @@ previewers = [ # Fallback { name = "*", run = "file" }, ] +prepend_preloaders = [ + { mime = "application/openxmlformats-officedocument.*", run = "office" }, + { mime = "application/oasis.opendocument.*", run = "office" }, + { mime = "application/ms-*", run = "office" }, + { mime = "application/msword", run = "office" }, + { name = "*.docx", run = "office" }, +] +prepend_previewers = [ + { mime = "*/xml", run = 'piper -- bat -p --theme ansi --terminal-width "$w" -f "$1"' }, + { mime = "application/*zip", run = 'piper -- atool --list -- "$1"' }, + { mime = "application/epub+zip", run = 'piper -- pandoc "$1" -t plain' }, + { mime = "application/json", run = 'piper -- bat -p --theme ansi --terminal-width "$w" -f "$1"' }, + { mime = "application/ms-*", run = "office" }, + { mime = "application/msword", run = "office" }, + { mime = "application/oasis.opendocument.*", run = "office" }, + { mime = "application/octet-stream", run = 'piper -- mediainfo "$1"' }, + { mime = "application/openxmlformats-officedocument.*", run = "office" }, + { mime = "application/pgp-encrypted", run = 'piper -- gpg -d -- "$1"' }, + { mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", run = 'piper -- pandoc "$1" -t plain' }, + { mime = "application/vnd.rn-realmedia", run = 'piper -- mediainfo "$1"' }, + { mime = "application/x-mobipocket-ebook", run = 'piper -- pandoc "$1" -t plain' }, + { mime = "application/x-ndjson", run = 'piper -- bat -p --theme ansi --terminal-width "$w" -f "$1"' }, + { mime = "application/x-{tar,bzip*,7z-compressed,xz,rar}", run = "lsar" }, + { mime = "application/{,g}zip", run = "lsar" }, + { mime = "audio/*", run = 'piper -- mediainfo "$1"' }, + # { mime = "image/{jpeg,png,webp}", run = "zoom 5" }, + { mime = "text/*", run = 'piper -- bat -p --theme ansi --terminal-width "$w" -f "$1"' }, + { mime = "text/html", run = 'piper -- lynx -width="$w" -display_charset=utf-8 -dump "$1"' }, + { mime = "text/troff", run = 'piper -- man ./ "$1" | col -b' }, + { mime = "video/*", run = 'piper -- mediainfo "$1"' }, + { name = "*.csv", run = 'piper -- bat -p --color=always "$1"' }, + { name = "*.docx", run = "office" }, + { name = "*.md", run = 'piper -- env CLICOLOR_FORCE=1 glow -w=$w -s=dark "$1"' }, + { name = "*.{odt,ods,odp,odg,ott,ots,otp}", run = 'piper -- odt2txt "$1"' }, + { name = "*.{tar,tar.gz,tar.bz2,tar.xz,zip,7z,rar,iso}", run = 'piper --format=url -- 7z l "$1"' }, + { name = "*/", run = 'piper -- eza -TL=3 --color=always --icons=always --group-directories-first --no-quotes "$1"' }, +] [input] cursor_blink = false @@ -232,126 +274,3 @@ sort_by = "none" sort_sensitive = false sort_reverse = false sort_translit = false - -# plugins -[[plugin.prepend_fetchers]] -id = "git" -name = "*" -run = "git" - -[[plugin.prepend_fetchers]] -id = "git" -name = "*/" -run = "git" - -[[plugin.prepend_previewers]] -mime = "application/{,g}zip" -run = "lsar" - -[[plugin.prepend_previewers]] -mime = "application/x-{tar,bzip*,7z-compressed,xz,rar}" -run = "lsar" - -[[plugin.prepend_fetchers]] -id = "mactag" -name = "*" -run = "mactag" - -[[plugin.prepend_fetchers]] -id = "mactag" -name = "*/" -run = "mactag" - -[[plugin.prepend_fetchers]] -id = "mime" -name = "*" -run = "mime-ext" -prio = "high" - -[[plugin.prepend_previewers]] -name = "*.{tar,tar.gz,tar.bz2,tar.xz,zip,7z,rar,iso}" -run = 'piper --format=url -- 7z l "$1"' - -[[plugin.prepend_previewers]] -name = "*.csv" -run = 'piper -- bat -p --color=always "$1"' - -[[plugin.prepend_previewers]] -name = "*.md" -run = 'piper -- env CLICOLOR_FORCE=1 glow -w=$w -s=dark "$1"' - -[[plugin.prepend_previewers]] -mime = "text/html" -run = 'piper -- lynx -width="$w" -display_charset=utf-8 -dump "$1"' - -[[plugin.prepend_previewers]] -name = "*.{xls,xlsx}" -run = 'piper -- in2csv "$1" | head -n 200' - -[[plugin.prepend_previewers]] -mime = "text/troff" -run = 'piper -- man ./ "$1" | col -b' - -[[plugin.prepend_previewers]] -mime = "text/*" -run = 'piper -- bat -p --theme ansi --terminal-width "$w" -f "$1"' - -[[plugin.prepend_previewers]] -mime = "*/xml" -run = 'piper -- bat -p --theme ansi --terminal-width "$w" -f "$1"' - -[[plugin.prepend_previewers]] -mime = "application/json" -run = 'piper -- bat -p --theme ansi --terminal-width "$w" -f "$1"' - -[[plugin.prepend_previewers]] -mime = "application/x-ndjson" -run = 'piper -- bat -p --theme ansi --terminal-width "$w" -f "$1"' - -[[plugin.prepend_previewers]] -mime = "audio/*" -run = 'piper -- mediainfo "$1"' - -[[plugin.prepend_previewers]] -mime = "video/*" -run = 'piper -- mediainfo "$1"' - -[[plugin.prepend_previewers]] -mime = "application/octet-stream" -run = 'piper -- mediainfo "$1"' - -[[plugin.prepend_previewers]] -mime = "application/vnd.rn-realmedia" -run = 'piper -- mediainfo "$1"' - -[[plugin.prepend_previewers]] -mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" -run = 'piper -- pandoc "$1" -t plain' - -[[plugin.prepend_previewers]] -name = "*.{odt,ods,odp,odg,ott,ots,otp}" -run = 'piper -- odt2txt "$1"' - -[[plugin.prepend_previewers]] -mime = "application/pgp-encrypted" -run = 'piper -- gpg -d -- "$1"' - -[[plugin.prepend_previewers]] -mime = "application/epub+zip" -run = 'piper -- pandoc "$1" -t plain' - -[[plugin.prepend_previewers]] -mime = "application/x-mobipocket-ebook" -run = 'piper -- pandoc "$1" -t plain' - -[[plugin.prepend_previewers]] -mime = "application/*zip" -run = 'piper -- atool --list -- "$1"' - -[[plugin.prepend_previewers]] -name = "*/" -run = 'piper -- eza -TL=3 --color=always --icons=always --group-directories-first --no-quotes "$1"' - -# [[plugin.prepend_previewers]] -# mime = "image/{jpeg,png,webp}" -# run = "zoom 5" diff --git a/mac/.config/zsh/.zshrc b/mac/.config/zsh/.zshrc index 6d13d29..a90fe52 100644 --- a/mac/.config/zsh/.zshrc +++ b/mac/.config/zsh/.zshrc @@ -116,8 +116,11 @@ zstyle ':fzf-tab:*' switch-group ',' '.' # switch group using `,` and `.` ### --- AVANTE --- ### export AVANTE_ANTHROPIC_API_KEY="$(pass show api/claude/nvim | head -n1)" export AVANTE_OPENAI_API_KEY="$(pass show api/chatGPT/nvim | head -n1)" -# export AVANTE_AZURE_OPENAI_API_KEY=your-azure-api-key -# export AVANTE_GEMINI_API_KEY=your-gemini-api-key -# export AVANTE_CO_API_KEY=your-cohere-api-key -# export AVANTE_AIHUBMIX_API_KEY=your-aihubmix-api-key -# export AVANTE_MOONSHOT_API_KEY=your-moonshot-api-key +# export AVANTE_AZURE_OPENAI_API_KEY="$(pass show api/azure/nvim | head -n1)" +# export AVANTE_GEMINI_API_KEY="$(pass show api/gemini/nvim | head -n1)" +# export AVANTE_CO_API_KEY="$(pass show api/cohere/nvim | head -n1)" +# export AVANTE_AIHUBMIX_API_KEY="$(pass show api/aihubmix/nvim | head -n1)" +# export AVANTE_MOONSHOT_API_KEY="$(pass show api/moonshot/nvim | head -n1)" + +### --- OPENAI --- ### +export OPENAI_API_KEY="$(pass show api/chatGPT/nvim | head -n1)" |
