mirror of
https://github.com/Ascyii/dotfiles.git
synced 2026-01-01 06:54:24 -05:00
Modular stow folders. Replaced kitty with alacritty
This commit is contained in:
21
cli/.config/yazi/plugins/what-size.yazi/LICENSE
Normal file
21
cli/.config/yazi/plugins/what-size.yazi/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Francesco Pira
|
||||
|
||||
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.
|
||||
83
cli/.config/yazi/plugins/what-size.yazi/README.md
Normal file
83
cli/.config/yazi/plugins/what-size.yazi/README.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# what-size.yazi
|
||||
|
||||
A plugin for [yazi](https://github.com/sxyazi/yazi) to calculate the size of the current selection or the current working directory (if no selection is made).
|
||||
|
||||
## Compatibility
|
||||
|
||||
what-size supports Yazi on Linux, macOS, and Windows.
|
||||
|
||||
### OS
|
||||
|
||||
- Linux since first commit
|
||||
- macOS since commit `42c6a0efb7245badb16781da5380be1a1705f3f2` ([link](https://github.com/pirafrank/what-size.yazi/commit/42c6a0efb7245badb16781da5380be1a1705f3f2))
|
||||
- Windows since commit `4a56ead2a84c5969791fb17416e0b451ab906c5d` ([link](https://github.com/pirafrank/what-size.yazi/commit/4a56ead2a84c5969791fb17416e0b451ab906c5d))
|
||||
|
||||
### Yazi
|
||||
|
||||
- yazi `25.x` since commit `fce1778d911621dc57796cdfdf11dcda3c2e28de` ([link](https://github.com/pirafrank/what-size.yazi/commit/fce1778d911621dc57796cdfdf11dcda3c2e28de)).
|
||||
- yazi `0.4.x` since commit `2780de5aeef1ed16d1973dd6e0cd4d630c900d56` ([link](https://github.com/pirafrank/what-size.yazi/commit/2780de5aeef1ed16d1973dd6e0cd4d630c900d56)).
|
||||
- yazi `0.3.x` up to commit `f08f7f2d5c94958ac4cb66c51a7c24b4319c6c93` ([link](https://github.com/pirafrank/what-size.yazi/commit/f08f7f2d5c94958ac4cb66c51a7c24b4319c6c93)).
|
||||
|
||||
## Requirements
|
||||
|
||||
- `du` on Linux and macOS
|
||||
- PowerShell on Windows
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
ya pack -a 'pirafrank/what-size'
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Add this to your `~/.config/yazi/keymap.toml`:
|
||||
|
||||
```toml
|
||||
[manager]
|
||||
prepend_keymap = [
|
||||
{ on = [ ".", "s" ], run = "plugin what-size", desc = "Calc size of selection or cwd" },
|
||||
]
|
||||
```
|
||||
|
||||
If you want to copy the result to clipboard, you can add `--clipboard` or `-c` as 2nd positional argument:
|
||||
|
||||
```toml
|
||||
[manager]
|
||||
prepend_keymap = [
|
||||
{ on = [ ".", "s" ], run = "plugin what-size -- '--clipboard'", desc = "Calc size of selection or cwd" },
|
||||
]
|
||||
```
|
||||
|
||||
```toml
|
||||
[manager]
|
||||
prepend_keymap = [
|
||||
{ on = [ ".", "s" ], run = "plugin what-size -- '-c'", desc = "Calc size of selection or cwd" },
|
||||
]
|
||||
```
|
||||
|
||||
Change to whatever keybinding you like.
|
||||
|
||||
## Feedback
|
||||
|
||||
If you have any feedback, suggestions, or ideas please let me know by opening an issue.
|
||||
|
||||
## Dev setup
|
||||
|
||||
Check the debug config [here](https://yazi-rs.github.io/docs/plugins/overview/#debugging).
|
||||
|
||||
To get debug logs while develoing use `ya.dbg()` in your code, then set the `YAZI_LOG` environment variable to `debug` before running Yazi.
|
||||
|
||||
```sh
|
||||
YAZI_LOG=debug yazi
|
||||
```
|
||||
|
||||
Logs will be saved to `~.local/state/yazi/yazi.log` file.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome. Please fork the repository and submit a PR.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
96
cli/.config/yazi/plugins/what-size.yazi/main.lua
Normal file
96
cli/.config/yazi/plugins/what-size.yazi/main.lua
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
-- function to get paths of selected elements or current directory
|
||||
-- if no elements are selected
|
||||
local get_paths = ya.sync(function()
|
||||
local paths = {}
|
||||
-- get selected files
|
||||
for _, u in pairs(cx.active.selected) do
|
||||
paths[#paths + 1] = tostring(u)
|
||||
end
|
||||
-- if no files are selected, get current directory
|
||||
if #paths == 0 then
|
||||
if cx.active.current.cwd then
|
||||
paths[1] = tostring(cx.active.current.cwd)
|
||||
else
|
||||
ya.err("what-size would return nil paths")
|
||||
end
|
||||
end
|
||||
return paths
|
||||
end)
|
||||
|
||||
-- Function to get total size from output
|
||||
-- Unix use `du`, Windows use PowerShell
|
||||
local function get_total_size(items)
|
||||
local is_windows = package.config:sub(1,1) == '\\'
|
||||
|
||||
if is_windows then
|
||||
local total = 0
|
||||
for _, path in ipairs(items) do
|
||||
path = path:gsub('"', '\\"')
|
||||
local ps_cmd = string.format(
|
||||
[[powershell -Command "& { $p = '%s'; if (Test-Path $p) { if ((Get-ChildItem -Path $p -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum) { (Get-ChildItem -Path $p -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum } else { (Get-Item $p).Length } } }"]],
|
||||
path
|
||||
)
|
||||
local pipe = io.popen(ps_cmd)
|
||||
local result = pipe:read("*a")
|
||||
-- Debug
|
||||
-- ya.notify {
|
||||
-- title = "Debug Output",
|
||||
-- content = result,
|
||||
-- timeout = 5,
|
||||
-- }
|
||||
pipe:close()
|
||||
local num = tonumber(result)
|
||||
if num then total = total + num end
|
||||
end
|
||||
return total
|
||||
else
|
||||
local arg = ya.target_os() == "macos" and "-scA" or "-scb"
|
||||
local output, err = Command("du"):arg(arg):args(items):output()
|
||||
if not output then
|
||||
ya.err("Failed to run du: " .. err)
|
||||
end
|
||||
local lines = {}
|
||||
for line in output.stdout:gmatch("[^\n]+") do
|
||||
lines[#lines + 1] = line
|
||||
end
|
||||
local last_line = lines[#lines]
|
||||
local size = tonumber(last_line:match("^(%d+)"))
|
||||
return ya.target_os() == "macos" and size * 512 or size
|
||||
end
|
||||
end
|
||||
|
||||
-- Function to format file size
|
||||
local function format_size(size)
|
||||
local units = { "B", "KB", "MB", "GB", "TB" }
|
||||
local unit_index = 1
|
||||
while size > 1024 and unit_index < #units do
|
||||
size = size / 1024
|
||||
unit_index = unit_index + 1
|
||||
end
|
||||
return string.format("%.2f %s", size, units[unit_index])
|
||||
end
|
||||
|
||||
return {
|
||||
-- as per doc: https://yazi-rs.github.io/docs/plugins/overview#functional-plugin
|
||||
entry = function(_, job)
|
||||
-- defaults not to use clipboard, use it only if required by the user
|
||||
local clipboard = job.args.clipboard == true or job.args[1] == "--clipboard" or job.args[1] == "-c"
|
||||
local items = get_paths()
|
||||
|
||||
local total_size = get_total_size(items)
|
||||
local formatted_size = format_size(total_size)
|
||||
|
||||
local notification_content = "Total size: " .. formatted_size
|
||||
if clipboard then
|
||||
ya.clipboard(formatted_size)
|
||||
notification_content = notification_content .. "\nCopied to clipboard."
|
||||
end
|
||||
|
||||
ya.notify {
|
||||
title = "What size",
|
||||
content = notification_content,
|
||||
timeout = 4,
|
||||
}
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user