Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/wvanlint/twf

Standalone tree view file explorer, inspired by fzf.
https://github.com/wvanlint/twf

bash cli fzf go neovim nvim unix vim zsh

Last synced: 25 days ago
JSON representation

Standalone tree view file explorer, inspired by fzf.

Lists

README

        

twf - Tree View Find
===

twf is a standalone tree view explorer inspired by [fzf](https://github.com/junegunn/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](https://brew.sh/)

```sh
brew install --HEAD wvanlint/twf/twf
```

### Using Go

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

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

Install the Go binary.

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

Integrations
------------

### In .zshrc

```sh
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

```vim
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 t :call Twf()
```

### In .config/nvim/init.vim

```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 t :call Twf()
```

Usage
-----

```sh
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:

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

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

```sh
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](https://github.com/junegunn/fzf) by default) to find a file and highlight it in the tree.

### Flags

- `-autoexpandDepth `: 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 `: 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 for command sequences.

This takes the following format:
```
= ::[,]
= "ctrl-a" | "a" | "esc" | ...
= [;]...
= "tree:open" | "quit" | ...
```
For example: `k::tree:prev,j::tree:next,enter::tree:selectPath;quit`.
See below for the possible keys and commands.

- `-dir `: Root directory to browse.
- `-graphics `: Graphics per type of text span.

This takes the following format:
```
= [,]
= ::
= tree:cursor | tree:dir
= [,]
= reverse | bold
= fg# | bg#
= black | red | green | yellow | blue | magenta | cyan | white | brightred | ...
= 0-255
= # In hexadecimal
```
- `-height `: 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 `: The command whose output will be interpreted as a path to locate in the file tree, when called via the '/' key binding.
- `-loglevel `: Logging priority. Empty disables logging. Follows the notation [here](https://godoc.org/go.uber.org/zap/zapcore#Level.UnmarshalText).
- `-preview `: Enable/disable previews.
- `-previewCmd `: Command to create preview of a file. The sequence `{}` serves as a placeholder for the path to preview.