2 个版本
0.1.2 | 2022 年 11 月 9 日 |
---|---|
0.1.1 | 2022 年 11 月 6 日 |
0.1.0 |
|
#2881 in 命令行工具
245KB
1K SLoC
shinydir - 强制目录整洁!
停止随意将垃圾文件扔到处,设置规则并让工具来提醒你。
shinydir 是一个 CLI 工具,它根据设置的规则检查目录是否填充了允许的文件或子目录,并报告任何异常。它还可以根据配置的规则自动移动错位的文件。
安装
从 crates.io 安装
推荐通过使用 cargo install
在 crates.io 上安装 shinydir。
确保您已安装最新的 Rust 工具链。
要构建并安装最新发布的版本,请运行 crate install shinydir
。
从 GitHub 发布版安装
如果您没有安装 Rust 工具链或者在本机构建不方便,您可以直接从 Github 上的最新发布版下载编译后的二进制文件。
从源代码安装
确保您已安装最新的 Rust 工具链。
- 克隆此仓库:
git clone https://github.com/Unoqwy/shinydir
- 进入克隆的目录:
cd shinydir
- 构建和安装:
cargo install --path .
用法
您可以通过环境变量 SHINYDIR_CONFIG_FILE
设置配置文件路径(建议使用绝对路径)。否则,默认路径取决于您的操作系统。
- Linux:
$XDG_CONFIG_HOME/shinydir/shinydir.toml
($XDG_CONFIG_HOME
如果未设置,默认为$HOME/.config
) - MacOS:
$HOME/Library/Application Support/Shiny-Dir/shinydir.toml
- Windows:
C:\Users\User\AppData\Roaming\Shiny Dir\config\shinydir.toml
默认配置在首次运行时复制,如果配置文件不存在。您可以在 这里 查看默认设置。
shinydir 的力量源于您的自定义配置,在继续之前,请确保将配置文件修改成您喜欢的样子。
shd [-c <custom-config>] check [--list]
- 检查配置的目录并报告位置错误的文件。使用 --list
获取未格式化的绝对文件名列表,这对于管道很有用。
shd [-c <custom-config>] auto-move [--dry] [--list]
- 根据设定的规则移动位置错误的文件。使用 --dry
来查看不实际移动文件的结果。使用 --list
获取“移动操作”的原始列表,每行将包含用空格分隔的旧文件路径和新文件路径。您可以通过调用外部脚本在配置中获取文件的目的地(见高级规则),从而发挥创意。
配置
通用设置
[settings]
color = true # Use colors in terminal output
use-unicode = true # Use fancy unicode chars in terminal output
hide-ok-directories = true # Hide directories (and auto-move rules) from output
# when there are no misplaced files/nothing to move
目录规则
设置您想要的规则,以便 check
命令可以相应地提醒您。
[dir."$HOME/Shared"] # Create a rule for the 'Shared' directory is user home
allowed-dirs = [
# Allow only two sub-directories: 'Movies', and 'FileTransfer'
# Any other directory will be reported as misplaced
{ name = "Movies" },
{ name = "FileTransfer" },
]
allowed-files = [
# Allow files prefixed with `backup-`
# Any other file will be reported as misplaced
{ pattern = "^backup-" },
]
[dir."$HOME/Shared/Movies"]
recursive = true # Apply rules recursively on child directories
recursive-ignore-children = [
# Recursive rules will not apply in the directory '.thumbnails'
{ name = ".thumbnails" },
]
# Omitting 'allow-dirs' means any directory is allowed
allow-files = [
# Allow files with extension 'mp4' or 'mov'
# Any other file will be reported as misplaced
{ ext = "mp4" },
{ ext = "mov" },
]
自动移动通用设置
[automove]
force-dry-run = true # This is a security feature for new users.
# It prevents auto-move from actually working!
# Make sure to turn this off (set to false) when you are ready to use auto-move
自动移动规则
设置您想要的规则,以便 auto-move
命令可以为您整理混乱。
[[automove.rules]]
name = "Home Movies" # Give a custom name to the rule. If unset, it will fallback to the absolute path of `parent`
parent = "$HOME/Shared" # Handle files under in the 'Shared' directory
match = [
# Look for files with extension 'mp4' or 'mov'
{ ext = "mp4" },
{ ext = "mov" },
]
to = "$HOME/Shared/Movies" # These files belong to our 'Movies' sub-directory, move them there
您可以使用脚本处理更复杂的场景。在以下示例中,截图会自动按月分类。您可以查看相关的脚本此处。
[[automove.rules]]
name = "Screenshots"
parent = "$HOME/Screenshots"
match = [
{ ext = "png" },
{ ext = "jpg" },
]
to = "$HOME/Screenshots" # Stay within the same directory with this setting,
# the script below returns a relative filename that includes a directory
to-script = "examples/dated-monthly.sh" # This script will be called for each matching file,
# to get a new filename to move the file to.
# In this example, a file created in November 2022 will be moved to
# `$HOME/Screenshots/Nov-2022/<original filename>`
# Note: `to` is still required when `to-script` is set! It will be the base path of any relative filename the script returns.
# However, the script is free to return absolute paths, in which case `to` will be ignored
依赖关系
~4–16MB
~157K SLoC