Giter VIP home page Giter VIP logo

twf's Introduction

twf - Tree View Find

twf is a standalone tree view explorer inspired by fzf.

Features

  • Standalone, usable from vim, the shell or any other program.
  • Locate files through external programs such as fzf.
  • Customizable previews.
  • Optional inline display in the shell.

Installation

Using Homebrew

brew install --HEAD wvanlint/twf/twf

Using Go

Install Go, and ensure that $GOPATH/bin is added to the $PATH.

export GOPATH="$HOME/go"
export PATH="$PATH:$HOME/bin:$GOPATH/bin"

Install the Go binary.

go get -u github.com/wvanlint/twf/cmd/twf

Integrations

In .zshrc

twf-widget() {
  local selected=$(twf --height=0.5)
  BUFFER="$BUFFER$selected"
  zle reset-prompt
  zle end-of-line
  return $ret
}
zle -N twf-widget
bindkey '^T' twf-widget

In .vimrc

function! Twf()
  let temp = tempname()
  execute 'silent ! twf ' . @% . ' > ' . temp
  redraw!
  try
    let out = filereadable(temp) ? readfile(temp) : []
  finally
    silent! call delete(temp)
  endtry
  if !empty(out)
    execute 'edit! ' . out[0]
  endif
endfunction

nnoremap <silent> <Space>t :call Twf()<CR>

In .config/nvim/init.vim

function! TwfExit(path)
  function! TwfExitClosure(job_id, data, event) closure
    bd!
    try
      let out = filereadable(a:path) ? readfile(a:path) : []
    finally
      silent! call delete(a:path)
    endtry
    if !empty(out)
      execute 'edit! ' . out[0]
    endif
  endfunction
  return funcref('TwfExitClosure')
endfunction

function! Twf()
  let temp = tempname()
  call termopen('twf ' . @% . ' > ' . temp, { 'on_exit': TwfExit(temp) })
  startinsert
endfunction

nnoremap <silent> <Space>t :call Twf()<CR>

Usage

twf [flags...] [path]

The binary twf will output the path that you select in the tree view, so it is usable in scripts and from other programs. For example, you can try the following commands:

cat $(twf)
cat $(twf --height=0.5)
vim $(twf)

It is also possible to locate and highlight a file given as an argument.

twf path/to/subdir/file

Default keybindings

  • j: Move down.
  • k: Move up.
  • ctrl-j: Move preview down.
  • ctrl-k: Move preview up.
  • p: Move to parent.
  • P: Move to parent and collapse.
  • o: Expand/collapse directory.
  • O: Recursively expand/collapse directory.
  • Enter: Select file and exit.
  • /: Use an external program (fzf by default) to find a file and highlight it in the tree.

Flags

  • -autoexpandDepth <depth>: Depth to which directories should be automatically expanded at startup. If -1, depth is unlimited. The default is 1, meaning only the root should be expanded.

  • -autoexpandIgnore <regexp>: Regular expression matching paths to ignore when auto-expanding directories at startup. Each path that's tested against the regex is relative to the twf root and does not begin with / or ./, e.g. foo/bar/qux.

    For example, ^(\.git|internal/filetree/testdata)$ would ignore the .git directory at the root level as well as the internal/filetree/testdata directory.

  • -bind <keybindings>: Keybindings for command sequences.

    This takes the following format:

    <keybindings> = <key>::<commands>[,<keybindings>]
    <key>         = "ctrl-a" | "a" | "esc" | ...
    <commands>    = <command>[;<command>]...
    <command>     = "tree:open" | "quit" | ...
    

    For example: k::tree:prev,j::tree:next,enter::tree:selectPath;quit. See below for the possible keys and commands.

  • -dir <dir>: Root directory to browse.

  • -graphics <graphicMappings>: Graphics per type of text span.

    This takes the following format:

    <graphicMappings> = <graphicMapping>[,<graphicMappings>]
    <graphicsMapping> = <span>::<graphics>
    <span>            = tree:cursor | tree:dir
    <graphics>        = <graphic>[,<graphics>]
    <graphic>         = reverse | bold
    <graphic>         = fg#<color> | bg#<color>
    <color>           = black | red | green | yellow | blue | magenta | cyan | white | brightred | ...
    <color>           = 0-255
    <color>           = <R><G><B>  # In hexadecimal
    
  • -height <float>: Proportion (between 0.0 and 1.0) of the vertical space of the terminal to take up. If equal to 1.0, an alternative buffer will be used.

  • -locateCmd <str>: The command whose output will be interpreted as a path to locate in the file tree, when called via the '/' key binding.

  • -loglevel <level>: Logging priority. Empty disables logging. Follows the notation here.

  • -preview <bool>: Enable/disable previews.

  • -previewCmd <str>: Command to create preview of a file. The sequence {} serves as a placeholder for the path to preview.

twf's People

Contributors

b0o avatar wvanlint avatar wwalker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

twf's Issues

Ability to open sub-directory and make it root

Hi! First of all, thank you so much for this app. I looked so hard for something like this and I finally found yours. Great work! I do have a few recommendations and/or issues I found, but this is still a great app that I plan to use a lot! :)

Currently, I am able to make a parent directory root by pressing p. I would appreciate a similar functionality, but instead it opens a highlighted sub-directory and makes it the new root, if it is within scope of this app. Thanks!

I'm unclear on what -locateCmd does

-locateCmd <str>: The command whose output will be interpreted as a path to locate in the file tree.

An example would be helpful.

I created a script aaa ran:

twf -locateCmd aaa

3 times. once each outputting:

/home/wwalker/bin/aaa
/bin/aaa
bin/aaa

in no case did it show the file in the tree.

However, this may be a side effect of #9 .

twf should error on bad argument to -locateDir

Passing -locateCmd a command that doesn't exist should fail with an error.

2020-06-07 21:36:00 - wwalker@plutonium:~ ✓ $ twf -locateCmd juhytgtr
2020-06-07 21:37:35 - wwalker@plutonium:~ ✓ $ 

Panic when previewing nvim

Hello,
I ran with NeoVim it raises a panic.

:!twf
panic: device not configured

goroutine 1 [running]:
main.main()
        /Users/alesshh/.asdf/installs/golang/1.14.2/packages/pkg/mod/github.com/wvanlint/[email protected]/cmd/twf/main.go:67 +0x935

shell returned 2

This issue didn't occur when I ran the inside vim 8.
Any tips to fix or contribute?

left and right actions - feature request

twf is pretty nice. Thanks for a nice tool !

I think it would improve the user experience if these actions existed.

Of course that is my personal cognitive bias :-)

I think that "GoLeft" is just a keymapping, but, GoRight is more complex

l RightArrow (GoRight):

  • on a collapsed directory (oj):
    • expand the directory AND
    • move to the first item in the newly expanded directory
  • on a expanded directory (j):
    • move to the first item in the directory
  • on a file in an expanded directory (j):
    • move to the next item in the directory

h LeftArrow (GoLeft):

  • Always go to the parent directory of the current item ('p')
    • This may jump "up" a hundred rows

Run program on current file/directory?

As the title suggested, it would be nice if we can run commands/ open current file/directory in certain program and keep twf running, similar to fzf.

twf should error

Running:

twf internal/state/does-not-exist

Opens the current directory, but should error because it could not find the path that it was passed.

Error installing via Brew (on Apple Silicon?)

Absolutely love the idea here and I'd be grateful for any help debugging this install.

Thanks,
Kastan

==> Pouring go--1.18.1.arm64_monterey.bottle.tar.gz
🍺  /opt/homebrew/Cellar/go/1.18.1: 11,964 files, 595.3MB
==> Installing wvanlint/twf/twf --HEAD
==> go build -o /opt/homebrew/Cellar/twf/HEAD-8eddca9/bin/twf github.com/wvanlint/twf/cmd/twf
Last 15 lines from /Users/kastanday/Library/Logs/Homebrew/twf/01.go:
go: downloading golang.org/x/text v0.3.0
go: downloading go.uber.org/atomic v1.6.0
go: downloading go.uber.org/multierr v1.5.0
# golang.org/x/sys/unix
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/syscall_darwin.1_13.go:25:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.1_13.go:27:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.1_13.go:40:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:28:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:43:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:59:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:75:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:90:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:105:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:121:3: //go:linkname must refer to declared function or variable
/Users/kastanday/Library/Caches/Homebrew/go_mod_cache/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:121:3: too many errors

If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):
  https://github.com/wvanlint/homebrew-twf/issues

Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels.
❯ twf
zsh: command not found: twf

feature request: support for mouse click event

Hello,

Let's be honest, the mouse it useful sometime ;)

It would be awesome to have mouse even support when clicking on directories and files.
Even more awesome if right click, left click can be configured as normal keybinding.

This allow true IDE experience.

Support for spaces in file names

Currently files with spaces in them will fail to be previewed.

Some support of escaping spaces when passing file names to other programs should help here.

Twf crashes, if the passed path is not a child of the current working directory.

Hello,

thanks for this nice tool. I'm currently trying to use it to replace NERDtree etc. in vim. Unfortunately, twf crashes, when the path passed to it is not a child of the current working directory. This also happens with plain twf without vim:

  • twf build from master on Arch Linux.
  • Reproduction steps without vim:
cd /tmp
twf /home
  • Error:
panic: Path not found: /home

goroutine 1 [running]:
main.main()
	github.com/wvanlint/twf/cmd/twf/main.go:69 +0x7d0

I find this especially important for the vim use case:

cd /tmp
vim /home/foo
# in vim, trying to navigate the directory of the opened buffer
! twf /tmp
# Results in an error:
panic: Path not found: /home

goroutine 1 [running]:
main.main()
	github.com/wvanlint/twf/cmd/twf/main.go:69 +0x7d0

shell returned 2

Press ENTER or type command to continue

Binding shift-down causes hard lock

Running

❯ twf --bind="shift-down::preview:down"

will work and launch the UI, but if you try to invoke the assigned binding ("shift-down"), the terminal will lock up and no longer respond to commands.

Again, great work!

Some files and directories missing

There are 5 .[A-Z]* directories, and 7 .a* directories:

drwxr-xr-x. 4 wwalker wwalker  4096 2016-08-13T14:58:26.000000000 .DataGrip2016.2
drwx------. 2 wwalker wwalker  4096 2017-03-19T19:56:54.000000000 .HipChat
drwx------. 2 wwalker wwalker  4096 2017-03-19T19:56:54.000000000 .QtWebEngineProcess
drwx------. 6 wwalker wwalker  4096 2018-07-31T11:21:23.000000000 .Skype
drwx------. 2 wwalker wwalker  4096 2017-12-03T15:57:11.000000000 .TeamSpeak 3
2020-06-07 21:04:54 - wwalker@plutonium:~ ✓ $ ls -lad .a*
drwx------.  3 wwalker wwalker  4096 2017-01-10T11:36:40.000000000 .adobe
drwx------.  3 wwalker wwalker  4096 2018-07-15T19:27:38.000000000 .ansible
drwxr-xr-x.  2 wwalker wwalker  4096 2019-04-20T15:35:14.634771604 .arduino15
drwxr-xr-x.  3 wwalker wwalker  4096 2018-09-12T11:10:37.000000000 .aspera
drwxr-xr-x.  4 wwalker wwalker  4096 2017-07-18T22:40:49.000000000 .audacity-data
drwxr-xr-x  10 wwalker wwalker  4096 2019-09-15T15:57:03.506460076 .autorandr
drwxr-xr-x.  2 wwalker wwalker  4096 2020-05-31T17:06:37.526831847 .aws

But, twf doesn't show the first 3 directories. There are also 7 directories that start with .a and only 5 are shown.

▼ wwalker
  ▶ ....
  ▶ .....
  ▶ .Skype
  ▶ .TeamSpeak 3
  ▶ .ansible
  ▶ .arduino15
  ▶ .aspera
  ▶ .audacity-data
  ▶ .aws
  ▶ .bashrc.d
  ▶ .bzf
  ▶ .cache
  ▶ .ccache
  ▶ .config
  ▶ .dbus
  ▶ .elm
  ▶ .emacs.d
  ▶ .fltk
  ▶ .frozen-bubble
  ▶ .gem
  ▶ .gimp-2.8
  ▶ .gnome
  ▶ .gnome2
  ▶ .gnupg
  ▶ .gphoto

twf does not highlight the file path passed in

in the twf src dir, running:

$ twf internal/state/state.go

Shows the current directory as open, but not the internal directory.

It Does, however, show the preview of the correct file.

Panic when previewing .zprofile

Hey, wanted to try this out as it looked nice. Ran into an issue looking through my home directory.
Looks like it panicked when I scrolled over my .zprofile

Heres the stacktrace:

panic: Terminal: exit status 1, stacktrace: goroutine 1 [running]:
runtime/debug.Stack(0xc00014f5c0, 0x1332e60, 0xc00000fa00)
	/usr/local/Cellar/go/1.14.3/libexec/src/runtime/debug/stack.go:24 +0x9d
github.com/wvanlint/twf/internal/terminal.(*Terminal).StartLoop.func1(0xc00014fcc8)
	/Users/kylepollina/go/src/github.com/wvanlint/twf/internal/terminal/terminal.go:187 +0x57
panic(0x1332e60, 0xc00000fa00)
	/usr/local/Cellar/go/1.14.3/libexec/src/runtime/panic.go:969 +0x166
github.com/wvanlint/twf/internal/views.(*previewView).Render(0xc000072230, 0x2, 0x34, 0x1b, 0x30, 0xc000358501, 0x51e, 0xa0)
	/Users/kylepollina/go/src/github.com/wvanlint/twf/internal/views/preview_view.go:55 +0x43e
github.com/wvanlint/twf/internal/terminal.(*Terminal).render(0xc000122090, 0xc00014fe40, 0x3, 0x3)
	/Users/kylepollina/go/src/github.com/wvanlint/twf/internal/terminal/terminal.go:147 +0x267
github.com/wvanlint/twf/internal/terminal.(*Terminal).StartLoop(0xc000122090, 0xc00007ef90, 0xc00014fe40, 0x3, 0x3, 0x0, 0x0)
	/Users/kylepollina/go/src/github.com/wvanlint/twf/internal/terminal/terminal.go:239 +0x38b
main.main()
	/Users/kylepollina/go/src/github.com/wvanlint/twf/cmd/twf/main.go:69 +0x599


goroutine 1 [running]:
main.main()
	/Users/kylepollina/go/src/github.com/wvanlint/twf/cmd/twf/main.go:72 +0x925

twf starts showing an open directory that is not open

wvanlint , again, thanks for a very cool ap !

Running

twf

shows only one line:

▼ wwalker

The arrow indicates the directory is "open"; but, it isn't "open" nothing is below.

Hitting o twice works

or

Hitting j works too.

Also, it works right when I start twf with an unused argument comes up correctly:

twf asdfzxcv

shows correctly:

▼ wwalker
  ▶ ....
  ▶ .....
  ▶ .Skype
  ▶ .TeamSpeak 3
  ▶ .ansible
  ▶ .arduino15
  ▶ .aspera
  ▶ .audacity-data
  ▶ .aws
  ▶ .bashrc.d

Unable to bind ctrl-down

Really cool work! Thanks for sharing!

I seem unable to bind "ctrl-down".

❯ twf --bind="ctrl-down::preview:down" 
invalid value "ctrl-down::preview:down" for flag -bind: Can't parse event: ctrl-down

Seems "down" and "ctrl-a" work, but "ctrl-down" (and "up") don't seem to be parsed.

feature request

Enable pageUp and pageDown in /internal/terminal/events.go so that these key events can then be defined and used mapped to twf commands.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.