31-08-2021

This commit is contained in:
2021-08-31 09:29:05 +02:00
parent 7d89fb0224
commit bb890cba15
28 changed files with 1888 additions and 47 deletions

View File

@@ -217,3 +217,4 @@ Ajouter ce fichier au fichier de configuration `.nanorc`
include "~/.nanosyntax/yml.nanorc"
```
https://github.com/scopatz/nanorc

205
docs/Linux/alternatives.md Normal file
View File

@@ -0,0 +1,205 @@
# alternatives
- [bat](bat.md)
- [exa](exa.md)
- [fd](fd.md)
- [fzf](fzf.md)
- ripgrep
- zoxide
### bat
https://github.com/sharkdp/bat
### exa
https://the.exa.website
### fd
https://github.com/sharkdp/fd
### fzf
https://github.com/junegunn/fzf
### ripgrep (rg)
https://github.com/BurntSushi/ripgrep
##### Installation:
```bash
$ brew install ripgrep
```
##### Utilisation:
```bash
$ rg PATH ~/.zshrc
```
![rg](/Users/bruno/Documents/docs/docs/Linux/rg.png)
```bash
# regex ('core' plus 1 ou plusiers lettres)
$ rg 'core\w+' ~/.zshrc
22:PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH
25:coreutils=false
# regex ('core' plus 0 ou plusiers lettres)
$ rg 'core\w*' ~/.zshrc
22:PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH
25:coreutils=false
# string
$ rg -F 'eval "$(' ~/.zshrc
83:eval "$(zoxide init --cmd j zsh)"
107:eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"
```
[https://docs.rs/regex/*/regex/#syntax](https://docs.rs/regex/*/regex/#syntax)
rg dans tout un répertoire:
```bash
$ rg '#!'
handbrake-batchconvert.sh
1:#!/bin/sh
composer.sh
1:#!/bin/bash
tmutil.sh
1:#!/bin/bash
```
```bash
$ rg '#!' Scripts
Scripts/kymsu2/kymsu2.sh
1:#!/usr/bin/env bash
Scripts/sonos/test.sh
1:#!/usr/bin/env bash
```
En l'absence de chemin, rg cherche dans le répertoire courant.
##### Filtre manuel:
```bash
# Rechercher uniquement dans les fichiers .sh
rg echo -g '*.sh'
# Rechercher partout sauf dans les fichiers .sh
rg echo -g '!*.sh'
```
##### File types
```bash
$ rg --type-list
...
config: *.cfg, *.conf, *.config, *.ini
md: *.markdown, *.md, *.mdown, *.mkdn
php: *.php, *.php3, *.php4, *.php5, *.phtml
sh: *.bash, *.bashrc, *.csh, *.cshrc, *.ksh, *.kshrc, *.sh, *.tcsh, *.zsh, .bash_login, .bash_logout, .bash_profile, .bashrc, .cshrc, .kshrc, .login, .logout, .profile, .tcshrc, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, bash_login, bash_logout, bash_profile, bashrc, profile, zlogin, zlogout, zprofile, zshenv, zshrc
...
```
```bash
# Recherche dans les fichiers shell .bashrc, .zshrc...
$ rg 'eval' --type sh ~/
# ou
$ rg 'eval' -tsh ~/
/Users/bruno/.bash_profile
72:eval "$(thefuck --alias)"
/Users/bruno/.zprofile
1:eval "$(/opt/homebrew/bin/brew shellenv)"
...
# Recherche partout sauf dans les fichiers shell .bashrc, .zshrc...
$ rg 'eval' --type-not sh ~/
# ou
$ rg 'eval' -Tsh ~/
```
##### Remplacement:
```bash
# recherche / remplacement mot pour mot
$ rg fast README.md --replace FAST
$ rg fast README.md -r FAST
# remplacer toute une ligne
$ rg '^.*fast.*$' README.md -r FAST
```
##### Fichier de configuration:
```bash
$ cat $HOME/.ripgreprc
```
### zoxide (z-zi)(j-ji)
https://github.com/ajeetdsouza/zoxide
##### Installation:
```bash
$ brew install zoxide
```
##### Ajout au shell:
```bash
# zsh
eval "$(zoxide init zsh)"
# bash
eval "$(zoxide init bash)"
```
##### Installer fzf:
```bash
$ brew install fzf
# To install useful key bindings and fuzzy completion:
$(brew --prefix)/opt/fzf/install
```
##### Configuration:
```bash
# changer les alias prédéfinis (j au lieu de z):
eval "$(zoxide init --cmd j zsh)"
```
##### Utilisation:
```bash
z foo # cd into highest ranked directory matching foo
z foo bar # cd into highest ranked directory matching foo and bar
z ~/foo # z also works like a regular cd command
z foo/ # cd into relative path
z .. # cd one level up
z - # cd into previous directory
zi foo # cd with interactive selection (using fzf)
```

View File

@@ -6,32 +6,32 @@ https://github.com/sharkdp/bat
Installation:
##### Installation:
```bash
$ brew install bat
$ brew install fzf
```
Créer le fichier de configuration:
##### Créer le fichier de configuration:
```bash
$ bat --generate-config-file
```
Editer la configuration:
##### Editer la configuration:
```bash
$ nano /Users/bruno/.config/bat/config
```
Prévisualiser les thèmes:
##### Prévisualiser les thèmes:
```bash
$ bat --list-themes | fzf --preview="bat --theme={} --color=always /Users/bruno/Documents/Scripts/bash/zsh_tools.sh"
```
Tail et bat:
##### Tail et bat:
```bash
$ tail -f /usr/local/var/log/httpd/error_log | bat --paging=never -l log
@@ -43,7 +43,7 @@ $ tail -f /usr/local/var/log/httpd/error_log | bat --paging=never -l log
4 [Fri Nov 27 16:22:54.278819 2020] [core:notice] [pid 10014] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd -D FOREGROUND'
```
Find et bat:
##### Find et bat:
```bash
$ find /usr -name error_log -exec bat {} +
@@ -56,13 +56,64 @@ $ find /usr -name error_log -exec bat {} +
```
Man pages:
##### Man pages:
```bash
$ export MANPAGER="sh -c 'col -bx | bat -l man -p'"
man 2 select
```
##### Afficher les caractères non-imprimables:
```bash
bat -A /etc/hosts
File: /etc/hosts
1 ##␊
2 #·Host·Database␊
3 #␊
4 #·localhost·is·used·to·configure·the·loopback·interface␊
5 #·when·the·system·is·booting.··Do·not·change·this·entry.␊
6 ##␊
7 127.0.0.1├──┤localhost␊
8 255.255.255.255├──┤broadcasthost␊
9 ::1·············localhost␊
10 #·Added·by·Docker·Desktop␊
11 #·To·allow·the·same·kube·context·to·work·on·the·host·and·the·container:␊
12 127.0.0.1·kubernetes.docker.internal␊
13 #·End·of·section␊
```
##### Voir plusieurs fichiers en même temps:
```bash
$ bat plugins.d/*.sh
File: plugins.d/00-kymsu.sh
1 #!/usr/bin/env bash
2 echo "🦄 KYMSU self update"
3 pushd "$(cat ~/.kymsu/path)" > /dev/null
4 git pull
5 popd > /dev/null
6 echo ""
File: plugins.d/antibody.sh
1 #!/usr/bin/env bash
2
3 # Antibody plugin for KYMSU
4 # https://github.com/welcoMattic/kymsu
5 # https://github.com/getantibody/antibody
6
File: plugins.d/conda.sh
1 #!/usr/bin/env bash
2
3 # conda plugin for KYMSU
4 # https://github.com/welcoMattic/kymsu
5
```
## bat-extras

View File

@@ -12,7 +12,7 @@ choco install fd
Recherche un fichier dans le répertoire courant (et sous-dossiers):
##### Recherche un fichier dans le répertoire courant (et sous-dossiers):
```bash
~ master* ⇡
@@ -25,41 +25,42 @@ pip/pip.conf
```
Recherche dans un répertoire particulier:
##### Recherche dans un répertoire particulier:
```bash
~ master* ⇡
fd -HI 'id_*' .ssh
$ fd -HI 'id_*' .ssh
.ssh/id_ed25519
.ssh/id_ed25519.pub
.ssh/id_rsa
.ssh/id_rsa.pub
.ssh/id_rsa.zip
fd -HI 'id_*' $HOME/.ssh
/Users/bruno/.ssh/id_ed25519
/Users/bruno/.ssh/id_ed25519.pub
/Users/bruno/.ssh/id_rsa
/Users/bruno/.ssh/id_rsa.pub
```
Recherche par regex:
##### Recherche par regex:
```bash
~ master* ⇡ 4m 27s
fd -HI '^h.*.conf$' /etc
/etc/apache2/extra/httpd-autoindex.conf
/etc/apache2/extra/httpd-dav.conf
/etc/apache2/extra/httpd-default.conf
/etc/apache2/extra/httpd-info.conf
/etc/apache2/extra/httpd-languages.conf
/etc/apache2/extra/httpd-manual.conf
/etc/apache2/extra/httpd-mpm.conf
/etc/apache2/extra/httpd-multilang-errordoc.conf
/etc/apache2/extra/httpd-ssl.conf
/etc/apache2/extra/httpd-userdir.conf
/etc/apache2/extra/httpd-vhosts.conf
/etc/apache2/httpd.conf
$ fd -I '^.*.conf$' /opt
/opt/homebrew/share/autoconf
/opt/homebrew/share/user_map.conf
/opt/homebrew/Cellar/mariadb/10.6.4/share/user_map.conf
/opt/homebrew/Cellar/groonga/11.0.5/etc/groonga/groonga.conf
/opt/homebrew/Cellar/groonga/11.0.5/etc/groonga/httpd/fastcgi.conf
...
$ fd -H '^.*.conf$' /opt
$
```
https://docs.rs/regex/1.0.0/regex/#syntax
Fichiers se terminant par *'[0-9].jpg'*:
##### Fichiers se terminant par *'[0-9].jpg'*:
```bash
$ fd -HI '.*[0-9]\.jpg$' ~
@@ -67,17 +68,74 @@ $ fd -HI '.*[0-9]\.jpg$' ~
$ find ~ -iname '*[0-9].jpg'
```
Sans arguments:
##### Sans arguments:
```bash
# afficher tous les entrées du répertoire courant
$ fd
# afficher tous les entrées d'un répertoire
$ fd . $HOME/.ssh
/Users/bruno/.ssh/config
/Users/bruno/.ssh/id_ed25519
/Users/bruno/.ssh/id_ed25519.pub
/Users/bruno/.ssh/id_rsa
/Users/bruno/.ssh/id_rsa.pub
/Users/bruno/.ssh/known_hosts
```
##### Chercher un fichier précis:
```bash
$ fd -I -g php.ini /opt
/opt/homebrew/etc/php/7.4/php.ini
/opt/homebrew/etc/php/8.0/php.ini
```
#### Option:
- **-H, --hidden**: cherche dans les fichiers et dossiers cachés
- **-I, --no-ignore**: cherche dans les fichiers et dossiers ignorés par '.gitignore', '.ignore', '.fdignore'
- **-x, --exec <cmd>**: exécute une commande pour chaque résultat
- **-X, --exec-batch <cmd>**: exécute une commande pour tous les résultats en même temps
- **-s, --case-sensitive**:
- **-i, --ignore-case**: (défaut)
- **-l, --list-details**
- **-L, --follow**: suit les liens symboliques (pas par défaut)
- **-d, --max-depth <depth>**: limite le nombre de répertoires traversés (pas de limite par défaut)
- **-t, --type <filetype>...**: filtre par type de fichiers
- 'f' or 'file': fichiers réguliers
- 'd' or 'directory': répertoires
- 'l' or 'symlink': liens symboliques
- 'x' or 'executable': executables
- 'e' or 'empty': fichiers vides ou répertoires
- 's' or 'socket': socket
- 'p' or 'pipe': named pipe (FIFO)
- **-e, --extension <ext>...**: filtre par extension (plusieurs autorisées)
- **-E, --exclude <pattern>...**: exclure des fichiers/répertoires des résultats (--exclude '*.pyc', --exclude node_modules)
- **-c, --color <when>**: colorie chaque chaine trouvée ('auto', 'never', 'always')
- **-S, --size <size>...**: filtre par la taille des fichiers (+3k, -500, +1g, 300)
- **--changed-within <date|dur>**: filtre par la date de modification
- --changed-within 2 weeks (10h, 1d, 35min)
- --change-newer-than '2018-10-27 10:00:00'
- **--changed-before <date|dur>**: filtre par la date de modification
- --changed-before '2018-10-27 10:00:00'
- --change-older-than 2weeks (10h, 1d, 35min)
- **-o, --owner <user:group>**: filtre par utilisateur/groupe (--owner bruno, --owner :staff, --owner '!john:students')
- **--max-results <count>**: limite le nombre de résultats à 'count' et quitte
Option:
- --hidden: cherche dans les dossiers cachés
- --no-ignore:
- -x / --exec:
```bash
# -l, --list-details
$ fd -Il '^.*.conf$' /opt/homebrew/etc
-rw-r--r-- 1 bruno admin 696 jul 24 07:46 /opt/homebrew/etc/fonts/conf.d/10-hinting-slight.conf
-rw-r--r-- 1 bruno admin 2,2K jul 24 07:46 /opt/homebrew/etc/fonts/conf.d/10-scale-bitmap-fonts.conf
-rw-r--r-- 1 bruno admin 1,6K jul 24 07:46 /opt/homebrew/etc/fonts/conf.d/20-unhint-small-vera.conf
```

213
docs/Linux/fzf.md Normal file
View File

@@ -0,0 +1,213 @@
# 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**
![fzf5](/Users/bruno/Documents/docs/docs/Linux/fzf5.png)
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**
![fzf6](/Users/bruno/Documents/docs/docs/Linux/fzf6.png)
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'
```
###

BIN
docs/Linux/fzf.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
docs/Linux/fzf2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

BIN
docs/Linux/fzf3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

BIN
docs/Linux/fzf4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 KiB

BIN
docs/Linux/fzf5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
docs/Linux/fzf6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
docs/Linux/rg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB