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

    • thingsiplay@beehaw.orgOP
      link
      fedilink
      arrow-up
      2
      ·
      1 month ago

      It’s a bit hard to show examples that justifies such a tool. But it’s not about making things possible, as there are other tools like ls, grep and sed and awk and Bash commands to do all the formatting and output. But its a little bit easier and more flexible to have fpath, which understands paths and has dedicated functionality to support that. It’s more about being flexible and doing it in place easily. At least for me, because I know the tool.

      Let’s say I want to output some information about files that come as a result from my file indexer baloosearch6 (from KDE). It only outputs full paths. Let’s say I want to show only its names and the file type information (or any other) next to it:

      baloosearch6 "Super Mario" | grep /snes/ | fpath -F'{name}\n\t{file}\n'
      
  • NuclearDolphin@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 month ago

    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.

    • thingsiplay@beehaw.orgOP
      link
      fedilink
      arrow-up
      2
      ·
      1 month ago

      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 or baloosearch6 (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 using sed and grep mulitple times and Bash substitution to get file extension and so on. Or I use baloosearch6 "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.