├── LICENSE ├── README.md ├── gifs ├── fzf_awk.gif ├── fzf_ls.gif └── fzf_ruby.gif └── scripts ├── fzf_awk.sh ├── fzf_ls.sh ├── fzf_man.sh ├── fzf_python.sh └── fzf_ruby.sh /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🚀 fzf-live-repl 🚀 2 | 3 | This hacky one-liner turns your [fzf](https://github.com/junegunn/fzf) into a live REPL. There is not much to explain, 4 | see it for yourself. Please note that I will be adding more examples as I come up with them. You are also welcome to 5 | contribute them yourself by creating an issue or a pull request. 6 | 7 | [Featured in my blog post](https://paweldu.dev/posts/fzf-live-repl/) 8 | 9 | [See also: fzf-launch - open any file directly from command line with a command of your choice](https://paweldu.dev/posts/fzf-launch/) 10 | 11 | ## How? 12 | By abusing the `--preview` flag of `fzf`. It allows an arbitrary command to be executed as the query changes. The `{q}` 13 | is then being substituted by your typed query. After exiting `fzf` by pressing `enter`, the `--print-query` flag ensures that the typed 14 | query will be printed to stdout. 15 | 16 | ## WARNING! 17 | Always be careful what you set the `--preview` flag to! **Imagine setting `rm -rf` and then typing `*` as the query 18 | string!**. I take no responsibility if you break anything! 19 | 20 | **ONLY USE THIS FOR COMMANDS WHICH ARE READ-ONLY!** 21 | 22 | **ALWAYS KNOW WHAT YOU'RE TYPING/PASTING!** 23 | 24 | ## Examples 25 | 26 | ### Live awk preview 27 | ```bash 28 | $ echo '' | fzf --print-query --preview 'echo "a\nb\nc\nd" | awk {q}' 29 | ``` 30 | ![live-awk-preview](gifs/fzf_awk.gif?raw=True) 31 | 32 | ### Peek into contents of a directory 33 | ```bash 34 | $ echo '' | fzf --preview 'ls {q}' 35 | ``` 36 | ![fzf-ls](gifs/fzf_ls.gif?raw=True) 37 | 38 | ### Execute a Ruby script 39 | ```bash 40 | $ echo '' | fzf --print-query --preview 'ruby -e {q}' 41 | ``` 42 | ![fzf-ruby](gifs/fzf_ruby.gif?raw=True) 43 | 44 | ### Instantly browse manpages (and find the relevant flag as you type the command - TODO) 45 | ```bash 46 | $ echo '' | fzf --preview 'man {q}' 47 | ``` 48 | 49 | ### Execute a Python script 50 | ```bash 51 | $ echo '' | fzf --print-query --preview 'python -c {q}' 52 | ``` 53 | -------------------------------------------------------------------------------- /gifs/fzf_awk.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawelduda/fzf-live-repl/6a56a15861c03328a90414b8fcf41dcf4b1fd2ad/gifs/fzf_awk.gif -------------------------------------------------------------------------------- /gifs/fzf_ls.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawelduda/fzf-live-repl/6a56a15861c03328a90414b8fcf41dcf4b1fd2ad/gifs/fzf_ls.gif -------------------------------------------------------------------------------- /gifs/fzf_ruby.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pawelduda/fzf-live-repl/6a56a15861c03328a90414b8fcf41dcf4b1fd2ad/gifs/fzf_ruby.gif -------------------------------------------------------------------------------- /scripts/fzf_awk.sh: -------------------------------------------------------------------------------- 1 | echo '' | fzf --print-query --preview 'echo "a\nb\nc\nd" | awk {q}' 2 | -------------------------------------------------------------------------------- /scripts/fzf_ls.sh: -------------------------------------------------------------------------------- 1 | echo '' | fzf --preview 'ls {q}' 2 | -------------------------------------------------------------------------------- /scripts/fzf_man.sh: -------------------------------------------------------------------------------- 1 | echo '' | fzf --preview 'man {q}' 2 | -------------------------------------------------------------------------------- /scripts/fzf_python.sh: -------------------------------------------------------------------------------- 1 | echo '' | fzf --print-query --preview 'python -c {q}' 2 | -------------------------------------------------------------------------------- /scripts/fzf_ruby.sh: -------------------------------------------------------------------------------- 1 | echo '' | fzf --print-query --preview 'ruby -e {q}' 2 | --------------------------------------------------------------------------------