Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pawelduda/fzf-live-repl
Turn your fzf into a live REPL
https://github.com/pawelduda/fzf-live-repl
Last synced: about 1 month ago
JSON representation
Turn your fzf into a live REPL
- Host: GitHub
- URL: https://github.com/pawelduda/fzf-live-repl
- Owner: pawelduda
- License: unlicense
- Created: 2019-07-17T00:11:47.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-12T23:03:01.000Z (almost 4 years ago)
- Last Synced: 2024-08-03T01:39:22.535Z (4 months ago)
- Language: Shell
- Size: 352 KB
- Stars: 253
- Watchers: 5
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🚀 fzf-live-repl 🚀
This hacky one-liner turns your [fzf](https://github.com/junegunn/fzf) into a live REPL. There is not much to explain,
see it for yourself. Please note that I will be adding more examples as I come up with them. You are also welcome to
contribute them yourself by creating an issue or a pull request.[Featured in my blog post](https://paweldu.dev/posts/fzf-live-repl/)
[See also: fzf-launch - open any file directly from command line with a command of your choice](https://paweldu.dev/posts/fzf-launch/)
## How?
By abusing the `--preview` flag of `fzf`. It allows an arbitrary command to be executed as the query changes. The `{q}`
is then being substituted by your typed query. After exiting `fzf` by pressing `enter`, the `--print-query` flag ensures that the typed
query will be printed to stdout.## WARNING!
Always be careful what you set the `--preview` flag to! **Imagine setting `rm -rf` and then typing `*` as the query
string!**. I take no responsibility if you break anything!**ONLY USE THIS FOR COMMANDS WHICH ARE READ-ONLY!**
**ALWAYS KNOW WHAT YOU'RE TYPING/PASTING!**
## Examples
### Live awk preview
```bash
$ echo '' | fzf --print-query --preview 'echo "a\nb\nc\nd" | awk {q}'
```
![live-awk-preview](gifs/fzf_awk.gif?raw=True)### Peek into contents of a directory
```bash
$ echo '' | fzf --preview 'ls {q}'
```
![fzf-ls](gifs/fzf_ls.gif?raw=True)### Execute a Ruby script
```bash
$ echo '' | fzf --print-query --preview 'ruby -e {q}'
```
![fzf-ruby](gifs/fzf_ruby.gif?raw=True)### Instantly browse manpages (and find the relevant flag as you type the command - TODO)
```bash
$ echo '' | fzf --preview 'man {q}'
```### Execute a Python script
```bash
$ echo '' | fzf --print-query --preview 'python -c {q}'
```