mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-26 19:03:38 +08:00
f6fb347d98
This adds a "path" builtin that can handle paths. Implemented so far: - "path filter PATHS", filters paths according to existence and optionally type and permissions - "path base" and "path dir", run basename and dirname, respectively - "path extension PATHS", prints the extension, if any - "path strip-extension", prints the path without the extension - "path normalize PATHS", normalizes paths - removing "/./" components - and such. - "path real", does realpath - i.e. normalizing *and* link resolution. Some of these - base, dir, {strip-,}extension and normalize operate on the paths only as strings, so they handle nonexistent paths. filter and real ignore any nonexistent paths. All output is split explicitly, so paths with newlines in them are handled correctly. Alternatively, all subcommands have a "--null-input"/"-z" and "--null-output"/"-Z" option to handle null-terminated input and create null-terminated output. So find . -print0 | path base -z prints the basename of all files in the current directory, recursively. With "-Z" it also prints it null-separated. (if stdout is going to a command substitution, we probably want to skip this) All subcommands also have a "-q"/"--quiet" flag that tells them to skip output. They return true "when something happened". For match/filter that's when a file passed, for "base"/"dir"/"extension"/"strip-extension" that's when something about the path *changed*. Filtering --------- `filter` supports all the file*types* `test` has - "dir", "file", "link", "block"..., as well as the permissions - "read", "write", "exec" and things like "suid". It is missing the tty check and the check for the file being non-empty. The former is best done via `isatty`, the latter I don't think I've ever seen used. There currently is no way to only get "real" files, i.e. ignore links pointing to files. Examples -------- > path real /bin///sh /usr/bin/bash > path extension foo.mp4 mp4 > path extension ~/.config (nothing, because ".config" isn't an extension.) |
||
---|---|---|
.. | ||
cmds | ||
python_docs_theme | ||
commands.rst | ||
completions.rst | ||
conf.py | ||
design.rst | ||
faq.rst | ||
fish_for_bash_users.rst | ||
fish_indent_lexer.py | ||
fish_synopsis.py | ||
index.rst | ||
interactive.rst | ||
language.rst | ||
license.rst | ||
relnotes.rst | ||
tutorial.rst |