leo-arch / clifm

The shell-like, command line terminal file manager: simple, fast, extensible, and lightweight as hell.
https://github.com/leo-arch/clifm/wiki
GNU General Public License v2.0
1.33k stars 40 forks source link

Tree mode? #191

Open BioBox opened 1 year ago

BioBox commented 1 year ago

Is your feature request related to a problem? Please describe. I want a way to get a quick view of tree's output that can fit on a single screen. I wrote a shell script for it, but I think that this might offer the best solution. I want to give this program a mode that emulates what my script does whilst retaining the extra shortcuts and interactivity of clifm.

Describe the solution you'd like Have a tree mode that will prints a recursive tree instead of the standard ls with the eln numbers. This mode should work with the file filters as well to give the user very powerful scanning capabilities. There should also be bindings to increment or decrement the depth level as well.

Describe alternatives you've considered I wrote a fish shell to view the tree output more comfortably, but I realized that this program has potential to offer a much better solution. Here it is if you wan to see it :stuck_out_tongue_closed_eyes:

function itree --description 'Interactive tree viewer'
    function path_join
    echo (string join / $argv[1] (command realpath --relative-to=$argv[1] $argv[2]))
    end

    set select (tree -nd $argv[1] | sed -e '1d' -e '$d' | fzy | awk '{print $NF}')
    set next (path_join $argv[1] $select)

    # If user selects a deep directory then fill in the missing components
    if [ ! -d $next ]
    set select (fd --prune -t d -g "**/"(basename $next) -1 $argv[1])
    end

    set next (path_join $argv[1] $select)
    set --global tre (realpath $next)

    # Is this the bottom?
    if [ (tree -nd $select | tail -n 1 | cut -d ' ' -f 1) -eq 0 ]
    read -P "It goes no deeper. What do now? (p/l) " response
    switch $response
        case p
        echo (realpath $next)
        case l
        ls $next
    end
    return 0
    end

    read -P "What do? (p/t/l/c) " response
    switch $response
    case p
        echo (realpath $next)
    case t
        tree $next
    case c
        itree $next
    case l
        ls $next
    end
end

If you have fish you can install fd and tree and run it yourself to get a basic idea of what I'm describing.

EDIT: Add command to ensure we're using GNU realpath and not the one supplied by fish.

leo-arch commented 1 year ago

Hi @BioBox. Thanks for your suggestion.

A built-in tree view mode would be a killer feature, for sure, but it's not planned for now (though it is already in my TODO list). The closest we have, much similar to your script, is a flat view provided by the fzfsel.sh plugin (invoked via the * action). To run this plugin in flat view mode issue:

* -f

But yes, implemented this way (externally) we lose all of clifm's interactivity.