- cross-posted to:
- linux@lemmy.ml
- linux@lemmy.ml
- cross-posted to:
- linux@lemmy.ml
- linux@lemmy.ml
A week ago I started a little script to format the output of file and path listings from other programs. It got a little bit out of hand and I implemented lot of advanced features into the fmt commands; kind of a sub language to define how the output should be formatted and structured. Entire idea is to give it paths, process the stream (not the file content itself, but the path representing a file) and output them again.
fpath accepts two type of input: a) either as arguments like fpath *.txt
or b) from stdin like ls -1 | fpath
. With additional options and commands the output can be colored and reformatted to something entirely different. In example with -F
option the advanced formatting is possible, such as fpath -F '{.size} {name}'
as a simple example.
There is lot of functionality (based on Python, yes this is a Python script), such as {reverse}{name}{/reverse}
to reverse font color and background of the segment that is enclosed by the command, a slice to get a subset as a range from the entire path {-1:}
, or {center:80}text{/center}
to add spaces to get centered text, or just {ext}
to output the extension, {mime}
to output the file mime type, or even execute arbitrary programs {!grep:a}{path}{/!}
to reduce output that has an a
in the path.
Did I over engineer it again? Or just ignore most stuff and use it with the most simple options, should be enough anyway: fpath -t -s red *.txt
I like this as an idea, but there’d need to be some sort of automatic hooking for me to want to use it. eza/lsd are good enough for ls output for me.
Doing stuff like this is much more cozy in nushell, since piping is a lot less messy
I find myself writing way less stuff like this since making the switch…partially because they output of a lot of builtins is already pretty.
fpath is not a replacement for a
ls
like command, but to change its output (I am an eza user myself). fpath takes output of eza to transform it into whatever I want. And its not just usable with an list program such ls or eza, but also operates on stdin like grep, even non existent files to maybe form something on a different place with same name in example. I still use ls (which is eza for me as an alias) for regular day operation.fpath is useful for output from
find
command orbaloosearch6
(KDE’s file indexer, that only outputs full path of matching search). In this case eza does not help me. Sometimes it can get messy with usingsed
andgrep
mulitple times and Bash substitution to get file extension and so on. Or I usebaloosearch6 "Super Mario World" | fpath -F{name} -x*.pcm
to just show filename, excluding all paths matching *.pcm glob (not regex) for whatever reason I want to use. The thing is, this is just a moment to be in. Next moment I can easily adjust the output to output it with or without other information.