mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Show A File Preview When Searching With FZF as a unix til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_799 TILs and counting..._
|
_800 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -747,6 +747,7 @@ _799 TILs and counting..._
|
|||||||
- [Search History](unix/search-history.md)
|
- [Search History](unix/search-history.md)
|
||||||
- [Search Man Page Descriptions](unix/search-man-page-descriptions.md)
|
- [Search Man Page Descriptions](unix/search-man-page-descriptions.md)
|
||||||
- [Securely Remove Files](unix/securely-remove-files.md)
|
- [Securely Remove Files](unix/securely-remove-files.md)
|
||||||
|
- [Show A File Preview When Searching With FZF](unix/show-a-file-preview-when-searching-with-fzf.md)
|
||||||
- [Show Disk Usage For The Current Directory](unix/show-disk-usage-for-the-current-directory.md)
|
- [Show Disk Usage For The Current Directory](unix/show-disk-usage-for-the-current-directory.md)
|
||||||
- [Show The Size Of Everything In A Directory](unix/show-the-size-of-everything-in-a-directory.md)
|
- [Show The Size Of Everything In A Directory](unix/show-the-size-of-everything-in-a-directory.md)
|
||||||
- [SSH Escape Sequences](unix/ssh-escape-sequences.md)
|
- [SSH Escape Sequences](unix/ssh-escape-sequences.md)
|
||||||
|
|||||||
33
unix/show-a-file-preview-when-searching-with-fzf.md
Normal file
33
unix/show-a-file-preview-when-searching-with-fzf.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Show A File Preview When Searching With FZF
|
||||||
|
|
||||||
|
[FZF](https://github.com/junegunn/fzf) by itself is a great way to fuzzy
|
||||||
|
find files. It gets even better when you can view a preview of a file before
|
||||||
|
opening it up. The `--preview` flag lets you do just this.
|
||||||
|
|
||||||
|
Add a basic file preview with `cat`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ fzf --preview 'cat {}'
|
||||||
|
```
|
||||||
|
|
||||||
|
The `{}` will get replaced a single-quoted string of the highlighted file.
|
||||||
|
|
||||||
|
You can spice up the preview a bit with color and line numbers using
|
||||||
|
[`bat`](https://github.com/sharkdp/bat):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ fzf --preview 'bat --color "always" {}'
|
||||||
|
```
|
||||||
|
|
||||||
|
The `--color` flag tells `bat` to produce syntax highlighted output even
|
||||||
|
though it isn't in interactive mode.
|
||||||
|
|
||||||
|
Lastly, you can keep it performant by only showing the first 100 lines:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ fzf --preview 'bat --color "always" --line-range 0:100 {}'
|
||||||
|
```
|
||||||
|
|
||||||
|
See `man fzf` for more details.
|
||||||
|
|
||||||
|
[source](https://github.com/dkarter/dotfiles/blob/master/vimrc#L362)
|
||||||
Reference in New Issue
Block a user