Skip to content

Commit 0907e55

Browse files
committed
Add Show A File Preview When Searching With FZF as a unix til
1 parent c8cdbdc commit 0907e55

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
1010
For a steady stream of TILs from a variety of rocketeers, checkout
1111
[til.hashrocket.com](https://til.hashrocket.com/).
1212

13-
_799 TILs and counting..._
13+
_800 TILs and counting..._
1414

1515
---
1616

@@ -747,6 +747,7 @@ _799 TILs and counting..._
747747
- [Search History](unix/search-history.md)
748748
- [Search Man Page Descriptions](unix/search-man-page-descriptions.md)
749749
- [Securely Remove Files](unix/securely-remove-files.md)
750+
- [Show A File Preview When Searching With FZF](unix/show-a-file-preview-when-searching-with-fzf.md)
750751
- [Show Disk Usage For The Current Directory](unix/show-disk-usage-for-the-current-directory.md)
751752
- [Show The Size Of Everything In A Directory](unix/show-the-size-of-everything-in-a-directory.md)
752753
- [SSH Escape Sequences](unix/ssh-escape-sequences.md)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Show A File Preview When Searching With FZF
2+
3+
[FZF](https://github.com/junegunn/fzf) by itself is a great way to fuzzy
4+
find files. It gets even better when you can view a preview of a file before
5+
opening it up. The `--preview` flag lets you do just this.
6+
7+
Add a basic file preview with `cat`:
8+
9+
```bash
10+
$ fzf --preview 'cat {}'
11+
```
12+
13+
The `{}` will get replaced a single-quoted string of the highlighted file.
14+
15+
You can spice up the preview a bit with color and line numbers using
16+
[`bat`](https://github.com/sharkdp/bat):
17+
18+
```bash
19+
$ fzf --preview 'bat --color "always" {}'
20+
```
21+
22+
The `--color` flag tells `bat` to produce syntax highlighted output even
23+
though it isn't in interactive mode.
24+
25+
Lastly, you can keep it performant by only showing the first 100 lines:
26+
27+
```bash
28+
$ fzf --preview 'bat --color "always" --line-range 0:100 {}'
29+
```
30+
31+
See `man fzf` for more details.
32+
33+
[source](https://github.com/dkarter/dotfiles/blob/master/vimrc#L362)

0 commit comments

Comments
 (0)