vapniks / fzf-tool-launcher

Browse & preview contents of files, and launch tools/pipelines to process a selected file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fzf-tool-launcher

Browse & preview contents of files, and launch tools/pipelines to process a selected file.

Bitcoin donations gratefully accepted: 1AmWPmshr6i9gajMi1yqHgx7BYzpPKuzMz

Installation & requirements

This file needs to be sourced into your zsh shell (e.g. in your init file), and tmux needs to be running before you can use it.

Usage & description

> fzf-tool-launcher [FILE..]

This function allows you to browse files (passed as args) using fzf, and then launch a tool (e.g. fzfrepl) to process the data in the file. As you navigate the files menu, the preview window will display the file contents using a predefined command to format the output. A different command is used for each different file-ending, and large files are truncated before displaying unformatted (so it’s fast). At the top of the preview window the file size, ownership & permissions are displayed.

When you select a file by pressing enter, you will be presented with a menu of tool names. At the bottom of this menu the command line corresponding to the tool is displayed. Pressing enter in the menu will open a new tmux window to run the tool on the file. The old window will stay open; press Ctrl+g to return to the file menu.

Configuration

Preview commands and other options are stored as zstyles, and the tools menu items are stored in a config file. To set a preview command for a particular file-ending, use the file-ending as the style name, and ‘:fzf-tool-launcher:previewcmd:’ as the context, e.g:

zstyle ‘:fzf-tool-launcher:previewcmd:’ csv ‘mlr –icsv –opprint cat {}’

{} is a placeholder for the filename. Note: uppercase & capitalized versions of file-endings are also matched by default so there is no need to add another entry for CSV or Csv in the above example.

By default the tools menu is defined in ~/.fzfrepl/tools_menu, but you can change this location by setting the tools_menu_file style, like this:

zstyle ‘:fzf-tool-launcher:’ tools_menu_file “~/.fzfrepl/tools_menu”

Each line of that file can either be a comment line starting with #, or a tool definition; a word naming the tool, followed by the command, e.g:

mlr_repl fzfrepl.sh -o -c “mlr {q}” -q “cat” {}

(again {} is a placeholder for the filename). See the tools_menu file included in this directory.

As mentioned earlier, large files are truncated before displaying in the preview window unformatted. The default threshold for what counts as a large file is 10485760 bytes (10MiB), but you can change it like this:

zstyle ‘:fzf-tool-launcher:’ max_preview_size 5242880

Keybindings

File menu

Alt+vview entire formatted file with $PAGER (unless its larger than max_preview_size)
Ctrl+vview entire raw file with $PAGER
Ctrl+jexit and print the selected file

Tools menu

Enterrun the selected tool on the selected file

Tips

  • When you launch a tool it will open in new tmux window which will disappear when the tool is exited. If the tool is wrapped by fzfrepl you can save the output by pressing Alt-v to view it in the pager (e.g. less), and using the pagers facility to save its input to a file.

Copyright notice

Copyright (C) 2021 Joe Bloggs vapniks@yahoo.com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

About

Browse & preview contents of files, and launch tools/pipelines to process a selected file.

License:GNU General Public License v3.0


Languages

Language:Shell 100.0%