From 4e729b80c6844fa09b52db8a22768474fc69fe1a Mon Sep 17 00:00:00 2001 From: Bruno 21 Date: Fri, 3 Apr 2020 08:23:52 +0200 Subject: [PATCH] 03-04-2020 --- docs/Divers/bash/programmation.md | 99 ++++++-------------- docs/Divers/bash/strings.md | 150 ++++++++++++++++++++++++++++++ docs/Divers/bash/tableaux.md | 17 +++- docs/Divers/zsh/antibody.md | 52 +++++++++++ docs/macos/Divers/Hackintosh.md | 40 ++++++++ docs/macos/ssh/ssh.md | 6 ++ 6 files changed, 286 insertions(+), 78 deletions(-) create mode 100644 docs/Divers/bash/strings.md create mode 100644 docs/macos/Divers/Hackintosh.md diff --git a/docs/Divers/bash/programmation.md b/docs/Divers/bash/programmation.md index bc5d878..091e39a 100644 --- a/docs/Divers/bash/programmation.md +++ b/docs/Divers/bash/programmation.md @@ -24,96 +24,47 @@ declare -i i; i+=1 user 0m0.492s i=0; i=$(expr $i + 1) user 0m5.464s ``` + + +#### [Chaine de caractères:](strings.md) + ##### Concaténer une chaine: ```bash upd+="$name " ``` -#### Trim une chaine: -##### 1. sed + +#### Chemins: + +Répertoire courant (pwd) , nom du script (basename), répertoire du script (dirname) ```bash -$ var=" Une chaine entourée d'espaces " +~/Documents/go $ nano chemins.sh -$ echo "Fluctuat nec $var mergitur" -Fluctuat nec Une chaine entourée d'espaces mergitur +#!/usr/local/bin/bash +echo "Le script exécuté a comme basename `basename "$0"`, dirname `dirname "$0"`" +echo "Le répertoire courant est `pwd`" -# supprimer les espaces en fin de chaine: sed 's/ *$//g'` -$ var=`echo $var | sed 's/ *$//g'` +~/Documents/go $ ./chemins.sh +Le script exécuté a comme basename chemins.sh, dirname . +Le répertoire courant est /Users/bruno/Documents/go -$ echo "Fluctuat nec $var mergitur" -Fluctuat nec Une chaine entourée d'espaces mergitur +cd .. +~/Documentsr $ go/chemins.sh +Le script exécuté a comme basename chemins.sh, dirname go +Le répertoire courant est /Users/bruno/Documents -# supprimer les espaces en début de chaine: sed 's/^ *//g'` -$ var=`echo $var | sed 's/^ *//g'` - -$ echo "Fluctuat nec $var mergitur" -Fluctuat nec Une chaine entourée d'espaces mergitur - -# supprimer les espaces en début et fin de chaine: - -$ var=" Une chaine entourée d'espaces " -$ echo "$var" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//' -Une chaine entourée d'espaces -``` - -##### 2. awk - -```bash -$ echo "${var}" - Une chaine entourée d'espaces - -$ echo "${var}" | awk '{gsub(/^[ \t]+/,""); print $0, " fin" }' -Une chaine entourée d'espaces fin - -$ echo "${var}" | awk '{gsub(/[ \t]+$/,""); print $0, " fin" }' - Une chaine entourée d'espaces fin - -$ echo "${var}" | awk '{gsub(/^[ \t]+| [ \t]+$/,""); print $0, " fin" }' -Une chaine entourée d'espaces fin -``` - -##### 3. xargs - -```bash -$ var=" Une chaine entourée d espaces " - -$ echo "$var" | xargs -Une chaine entourée d espaces - -$ echo " Une chaine entourée d espaces " | xargs -Une chaine entourée d espaces - -# erreur si la chaine contient un apostrophe -$ echo " Une chaine entourée d'espaces " | xargs -xargs: unterminated quote - -# dans ce cas, on utilise xargs -0 -$ echo " Une chaine entourée d'espaces " | xargs -0 - Une chaine entourée d'espaces +cd ~ +~ $ /Users/bruno/Documents/go/chemins.sh +Le script exécuté a comme basename chemins.sh, dirname /Users/bruno/Documents/go +Le répertoire courant est /Users/bruno ``` -#### Longueur d'une chaine: - -```bash -$ echo -n "Longueur de la chaine:" | wc -c - 22 - -$ echo "Longueur de la chaine:" | awk '{print length}' -22 - -$ var="Longueur de la chaine:" -$ echo ${#var} -22 -``` - - - - +#### [Tableaux:](tableaux.md) Déclarer un tableau associatif: @@ -123,6 +74,8 @@ declare -a do_not_update=('') +#### Commandes: + ##### Test si une commande existe: ```bash diff --git a/docs/Divers/bash/strings.md b/docs/Divers/bash/strings.md new file mode 100644 index 0000000..9a65f53 --- /dev/null +++ b/docs/Divers/bash/strings.md @@ -0,0 +1,150 @@ +# Chaine de caractères: + + + +##### Concaténer une chaine: + +```bash +upd+="$name " +``` + + + +##### Trim une chaine: + +1. sed + +```bash +$ var=" Une chaine entourée d'espaces " + +$ echo "Fluctuat nec $var mergitur" +Fluctuat nec Une chaine entourée d'espaces mergitur + +# supprimer les espaces en fin de chaine: sed 's/ *$//g'` +$ var=`echo $var | sed 's/ *$//g'` + +$ echo "Fluctuat nec $var mergitur" +Fluctuat nec Une chaine entourée d'espaces mergitur + +# supprimer les espaces en début de chaine: sed 's/^ *//g'` +$ var=`echo $var | sed 's/^ *//g'` + +$ echo "Fluctuat nec $var mergitur" +Fluctuat nec Une chaine entourée d'espaces mergitur + +# supprimer les espaces en début et fin de chaine: + +$ var=" Une chaine entourée d'espaces " +$ echo "$var" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//' +Une chaine entourée d'espaces +``` + +2. awk + +```bash +$ echo "${var}" + Une chaine entourée d'espaces + +$ echo "${var}" | awk '{gsub(/^[ \t]+/,""); print $0, " fin" }' +Une chaine entourée d'espaces fin + +$ echo "${var}" | awk '{gsub(/[ \t]+$/,""); print $0, " fin" }' + Une chaine entourée d'espaces fin + +$ echo "${var}" | awk '{gsub(/^[ \t]+| [ \t]+$/,""); print $0, " fin" }' +Une chaine entourée d'espaces fin +``` + +3. xargs + +```bash +$ var=" Une chaine entourée d espaces " + +$ echo "$var" | xargs +Une chaine entourée d espaces + +$ echo " Une chaine entourée d espaces " | xargs +Une chaine entourée d espaces + +# erreur si la chaine contient un apostrophe +$ echo " Une chaine entourée d'espaces " | xargs +xargs: unterminated quote + +# dans ce cas, on utilise xargs -0 +$ echo " Une chaine entourée d'espaces " | xargs -0 + Une chaine entourée d'espaces +``` + + + +##### Longueur d'une chaine: + +```bash +$ echo -n "Longueur de la chaine:" | wc -c + 22 + +$ echo "Longueur de la chaine:" | awk '{print length}' +22 + +$ var="Longueur de la chaine:" +$ echo ${#var} +22 +``` + + + +##### Sous-chaine: + +```bash +$ string=abcABC123ABCabc + +$ echo ${string:0} +abcABC123ABCabc + +$ echo ${string:1} +bcABC123ABCabc + +$ echo ${string:7} +23ABCabc + +$ echo ${string:7:3} +23A + +$ echo ${stringZ: -4} # Notez l'espace +Cabc + +$ echo ${string:(-4)} +Cabc +``` + + + +Remplacement de sous-chaine: + +```bash +$ string=abcABC123ABCabc + +$ echo ${string/abc/xyz} # Remplace la 1ere sous-chaine 'abc' par 'xyz'. +xyzABC123ABCabc + +$ echo ${string//abc/xyz} # Remplace toutes les sous-chaine 'abc' par 'xyz'. +xyzABC123ABCxyz + +match=abc +repl=000 +echo ${string/$match/$repl} +000ABC123ABCabc + +echo ${string//$match/$repl} +000ABC123ABC000 + + +echo ${stringZ/abc} # Supprime la 1ere sous-chaine 'abc' +ABC123ABCabc +echo ${stringZ//abc} # Supprime toutes les sous-chaine 'abc' +ABC123ABC + +``` + +http://tldp.org/LDP/abs/html/string-manipulation.html + diff --git a/docs/Divers/bash/tableaux.md b/docs/Divers/bash/tableaux.md index 9f0bdcc..b4ab7c0 100644 --- a/docs/Divers/bash/tableaux.md +++ b/docs/Divers/bash/tableaux.md @@ -59,10 +59,15 @@ L’affichage de l’ensemble d’un tableau se fait avec la syntaxe `${montable $ declare -a tableau_indi=( "un" "deux" "trois" "quatre" ) $ echo ${tableau_indi[@]} un deux trois quatre +$ echo ${tableau_indi[2]} +deux + $ declare -A tableau_asso=( ['chene']="gland" ['erable']="sirop" ['hetre']="faine" ) $ echo ${tableau_asso[@]} gland faine sirop +$ echo ${tableau_asso[erable]} +sirop ``` @@ -80,11 +85,13 @@ un deux trois quatre # !!! normalement 'un' $ declare -A tableau_asso=( ['chene']="gland" ['erable']="sirop" ['hetre']="faine" ) $ echo ${tableau_asso["erable"]} # !!!! rien sur zsh !!!! +$ echo ${tableau_asso[erable]} +sirop ``` -Ajouter un élément: +#### Ajouter un élément: ```bash ARRAY=() @@ -109,7 +116,7 @@ Il n’est pas possible de créer un tableau associatif en lui assignant un él -Afficher la liste des clés: +#### Afficher la liste des clés: ```bash $ declare -a tableau_indi=( "un" "deux" "trois" "quatre" ) @@ -125,7 +132,7 @@ zsh: event not found: tableau_asso[@] # !!! -Obtenir la taille d'un tableau: +#### Obtenir la taille d'un tableau: ```bash $ declare -a tableau_indi=( "un" "deux" "trois" "quatre" ) @@ -139,7 +146,7 @@ $ echo ${#tableau_asso[@]} -Supprimer un élément: +#### Supprimer un élément: ```bash $ declare -a tableau_indi=( "un" "deux" "trois" "quatre" ) @@ -174,7 +181,7 @@ gland faine sirop -Supprimer un tableau entier: +#### Supprimer un tableau entier: ```bash $ declare -a tableau_indi=( "un" "deux" "trois" "quatre" ) diff --git a/docs/Divers/zsh/antibody.md b/docs/Divers/zsh/antibody.md index 215fa4f..e3ed251 100644 --- a/docs/Divers/zsh/antibody.md +++ b/docs/Divers/zsh/antibody.md @@ -51,6 +51,45 @@ updating: https://github.com/zdharma/fast-syntax-highlighting updating: https://github.com/zsh-users/zsh-autosuggestions ``` +Si erreur pendant la mise-à-jour: + +```bash +$ antibody update +Updating all bundles in /Users/bruno/Library/Caches/antibody... +antibody: updating: https://github.com/zsh-users/zsh-history-substring-search +antibody: updating: https://github.com/sindresorhus/pure +antibody: updating: https://github.com/mafredri/zsh-async +antibody: updating: https://github.com/zsh-users/zsh-autosuggestions +antibody: updating: https://github.com/zsh-users/zsh-completions +antibody: updating: https://github.com/marzocchi/zsh-notify +antibody: updating: https://github.com/zdharma/fast-syntax-highlighting +antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zdharma-SLASH-fast-syntax-highlighting +antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-marzocchi-SLASH-zsh-notify +antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions +antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-sindresorhus-SLASH-pure +antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-completions +antibody: error: failed to update: object not found +``` + +il faut vider le cache: + +```bash +~/Library/Caches/antibody +❯ rm -rf https-COLON* + +# ou + +rm -rf "$(antibody home)" +``` + +puis les recharger: + +```bash +$ antibody bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.sh +``` + + + ##### Liste des plugins/thèmes installés: @@ -86,3 +125,16 @@ drwxr-xr-x 12 bruno staff 384 7 jui 18:08 https-COLON--SLASH--SLASH-github drwxr-xr-x 7 bruno staff 224 7 jui 18:01 https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-history-substring-search ``` + + + + +# Z plugin (jump around) + + + +https://github.com/rupa/z + +Copier le script `z.sh` dans `/usr/local/etc/profile.d/` + +puis ajouter `. /usr/local/etc/profile.d/z.sh` au fichier .zshrc \ No newline at end of file diff --git a/docs/macos/Divers/Hackintosh.md b/docs/macos/Divers/Hackintosh.md new file mode 100644 index 0000000..2ea2635 --- /dev/null +++ b/docs/macos/Divers/Hackintosh.md @@ -0,0 +1,40 @@ +# Hackintosh + + + +[Darkwake - Powernap - Power Management - Sleep & wake (Catalina)](https://www.insanelymac.com/forum/topic/342002-darkwake-on-macos-catalina-boot-args-darkwake8-darkwake10-are-obsolete/) + +#### Darkwake: + +Par défaut Catalina 10.5.1: `Darkwake = 3` + + + +#### Power Management: + +Réglages courants: + +```bash +pmset -g +``` + +Réglages recommandés: + +```bash +sudo pmset -a hibernatemode 0 +sudo pmset -a proximitywake 0 +sudo pmset -a powernap 0 +``` + +Voir ce qui empêche la mise en veille: + +```bash +pmset -g assertions +``` + +Historique: + +```bash +pmset -g log|grep -e " Sleep " -e " Wake " +``` + diff --git a/docs/macos/ssh/ssh.md b/docs/macos/ssh/ssh.md index 1cfe71d..1c3181b 100644 --- a/docs/macos/ssh/ssh.md +++ b/docs/macos/ssh/ssh.md @@ -30,6 +30,12 @@ Changer le port ssh (22 par défaut) sur macOS: +#### SeKey + +https://github.com/sekey/sekey + + + **12.6.1 HTTPS vs SSH** If you think you have SSH set up correctly and yet you are still challenged for credentials, consider this: for the repo in question, have you possibly set up GitHub, probably called origin, as an HTTPS remote, instead of SSH?