$ find . -[TAB]
-a -and (Result is only true if both previous and next action are true)
-amin (File last accessed specified number of minutes ago)
-anewer (File last accessed more recently than file was modified)
-atime (File last accessed specified number of days ago)
…and 67 more rows
但它不是凭空来的,而是有人做了先期的工作:
$ cat /opt/local/share/fish/completions/find.fish
# Completions for the 'find' command
# Switches for how to handle symlinks
complete -c find -s P -d "Never follow symlinks"
complete -c find -s L -o follow -d "Follow symlinks"
complete -c find -s H -d "Don't follow symlinks (except for command line arguments)"
...
所以我的方式只是额外加了一层包装。如果有人喜欢直接用原有命令行,或者在程序脚本中用命令。就不需要这层包装,直接用原有的命令。有git也有ui-git。在ui下面也不需要找。这个记熟了和直接记熟了命令行参数是一样的。记住了cmd -opt 和记住了ui-cmd o 这个序列是一样的。界面可以不用看直接连续按下去。
do --:Rg
local function root_default()
local project = require("infra.project")
return project.git_root() or project.working_root()
end
local sort_comp = cmds.FlagComp.constant("sort", { "none", "path", "modified", "accessed", "created" })
-- see: rg --type-list
local type_comp = cmds.FlagComp.constant("type", { "c", "go", "h", "lua", "py", "sh", "systemd", "vim", "zig" })
local function is_extra_flag(flag) return flag ~= "root" and flag ~= "pattern" end
local spell = cmds.Spell("Rg", function(args)
local extra = {}
local iter = fn.filtern(is_extra_flag, fn.items(args))
for key, val in iter do
if val == true then table.insert(extra, string.format("--%s", key)) end
table.insert(extra, string.format("--%s=%s", key, val))
end
require("grep").rg(args.root, args.pattern, extra)
end)
-- stylua: ignore
do
spell:add_flag("root", "string", false, root_default, common_root_comp)
spell:add_flag("fixed-strings", "true", false)
spell:add_flag("hidden", "true", false)
spell:add_flag("max-depth", "number", false)
spell:add_flag("multiline", "true", false)
spell:add_flag("no-ignore", "true", false)
spell:add_flag("sort", "string", false, nil, sort_comp)
spell:add_flag("sortr", "string", false, nil, sort_comp)
spell:add_flag("type", "string", false, nil, type_comp)
end
spell:add_arg("pattern", "string", true)
cmds.cast(spell)
end