213 lines
4.8 KiB
Markdown
213 lines
4.8 KiB
Markdown
# fzf
|
|
|
|
|
|
|
|
https://github.com/junegunn/fzf
|
|
|
|
https://github.com/junegunn/fzf/wiki
|
|
|
|
https://sim590.github.io/fr/outils/fzf/#extension-de-la-complétion
|
|
|
|
https://github.com/junegunn/fzf/wiki/examples
|
|
|
|
https://github.com/junegunn/fzf/blob/master/ADVANCED.md
|
|
|
|
|
|
|
|
##### Installation:
|
|
|
|
```bash
|
|
$ brew install fzf
|
|
|
|
# To install useful key bindings and fuzzy completion:
|
|
$ $(brew --prefix)/opt/fzf/install
|
|
```
|
|
|
|
##### Syntaxe:
|
|
|
|
| Token | Match type | Description |
|
|
| --------- | -------------------------- | ------------------------------------ |
|
|
| `sbtrkt` | fuzzy-match | Items that match `sbtrkt` |
|
|
| `'wild` | exact-match (quoted) | Items that include `wild` |
|
|
| `^music` | prefix-exact-match | Items that start with `music` |
|
|
| `.mp3$` | suffix-exact-match | Items that end with `.mp3` |
|
|
| `!fire` | inverse-exact-match | Items that do not include `fire` |
|
|
| `!^music` | inverse-prefix-exact-match | Items that do not start with `music` |
|
|
| `!.mp3$` | inverse-suffix-exact-match | Items that do not end with `.mp3` |
|
|
|
|
Options
|
|
|
|
Search mode
|
|
-e, --exact
|
|
Enable exact-match
|
|
|
|
-i Case-insensitive match (default: smart-case match)
|
|
|
|
+i Case-sensitive match
|
|
|
|
|
|
|
|
##### Utilisation 1:
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master* 19s 17:46:16
|
|
$ find . | fzf
|
|
```
|
|
|
|
puis on entre des mots-clé pour affiner la recherche.
|
|
|
|
<img src="/Users/bruno/Documents/docs/docs/Linux/fzf2.png" alt="fzf2" style="zoom:50%;" />
|
|
|
|
##### Utilisation 2:
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master*
|
|
$ nano $(fzf)
|
|
```
|
|
|
|
On filtre: 'led
|
|
|
|
<img src="/Users/bruno/Documents/docs/docs/Linux/fzf.png" alt="fzf" style="zoom:50%;" />
|
|
|
|
|
|
|
|
**Return** ouvre le fichier dans nano.
|
|
|
|
On peut ouvrir plusieurs fichiers dans nano:
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master*
|
|
$ nano $(fzf -m)
|
|
```
|
|
|
|
puis **Tab** pour sélectionner plusieurs fichiers et **Return** pour les ouvrir.
|
|
|
|
|
|
|
|
#### Fuzzy completion
|
|
|
|
Déclencheur: ** puis <Tab>
|
|
|
|
|
|
|
|
##### Utilisation 3 (complétion de cd):
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master* 18:00:32
|
|
$ cd **
|
|
```
|
|
|
|
Puis **Tab**
|
|
|
|
<img src="/Users/bruno/Documents/docs/docs/Linux/fzf3.png" alt="fzf3" style="zoom:50%;" />
|
|
|
|
Puis **Return**
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master*
|
|
$ cd SiriControl/
|
|
|
|
~/Documents/Scripts_Raspberry/SiriControl master*
|
|
$
|
|
```
|
|
|
|
La complétion marche aussi avec la <u>commande ssh</u>: les serveurs sont tirés de /etc/hosts et de ssh/config.
|
|
|
|
##### Utilisation 4 (kill):
|
|
|
|
Taper **kill** puis **Espace** puis **Tab**
|
|
|
|
```bash
|
|
$ kill<espace>
|
|
```
|
|
|
|
<img src="/Users/bruno/Documents/docs/docs/Linux/fzf4.png" alt="fzf4" style="zoom:50%;" />
|
|
|
|
**Tab** pour sélectionner les process à tuer puis **Return**:
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry/SiriControl master*
|
|
$ kill 266 311
|
|
```
|
|
|
|
|
|
|
|
##### Utilisation 5 (complétion de cat):
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master*
|
|
$ cat **
|
|
```
|
|
|
|
Puis **Tab**
|
|
|
|

|
|
|
|
Puis **Return**
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master*
|
|
$ cat pir/pir2.py
|
|
```
|
|
|
|
La complétion marche aussi avec les variables d'environnement.
|
|
|
|
```bash
|
|
$ unset **<Tab>
|
|
$ unalias **<Tab>
|
|
$ export **<Tab>
|
|
```
|
|
|
|
|
|
|
|
##### Utilisation 6 (complétion de nano):
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master*
|
|
$ nano /opt/**
|
|
```
|
|
|
|
Puis **Tab**
|
|
|
|

|
|
|
|
Puis **Return**
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master*
|
|
$ nano /opt/homebrew/etc/httpd/httpd.conf
|
|
```
|
|
|
|
|
|
|
|
Lancer la fuzzy recherche dans le répertoire parent:
|
|
|
|
```bash
|
|
~/Documents/Scripts_Raspberry master*
|
|
$ nano ../**
|
|
```
|
|
|
|
|
|
|
|
##### Options:
|
|
|
|
```bash
|
|
fzf --height 40% --layout reverse --info inline --border \
|
|
--preview 'bat --style=numbers --color=always --line-range :500 {}' --preview-window right \
|
|
--color 'fg:#bbccdd,fg+:#ddeeff,bg:#334455,preview-bg:#223344,border:#778899'
|
|
```
|
|
|
|
```bash
|
|
# .zshrc
|
|
|
|
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
|
|
#export FZF_DEFAULT_COMMAND="find ."
|
|
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow'
|
|
# --preview "bat --style=numbers --color=always --line-range :500 {}" --preview="head -$LINES {}"
|
|
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
|
|
|
|
```
|
|
|
|
|
|
|
|
### |