# Personnaliser WSL ### PowerShell #### Installer git: ```powershell PS choco install git.install --params "/GitAndUnixToolsOnPath /NoGitLfs /NoAutoCrlf" ``` #### Installer Posh-Git and Oh-My-Posh: https://github.com/JanDeDobbeleer/oh-my-posh?WT.mc_id=-blog-scottha ```powershell PS Install-Module posh-git -Scope CurrentUser PS Install-Module oh-my-posh -Scope CurrentUser ``` Si PowerShell a besoin de NuGet, il propose de l'installer: ```powershell PS Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force ``` ```powershell Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck ``` #### Configuration de PowerShell: Exécuter "notepad $PROFILE" et ajouter à la fin: ```powershell Import-Module posh-git Import-Module oh-my-posh Set-Theme Paradox ``` #### Installer les polices: Depuis WSL (linux) ```bash # clone git clone https://github.com/powerline/fonts.git --depth=1 # install cd fonts ./install.sh # clean-up a bit cd .. rm -rf fonts ``` Depuis PowerShell ```powershell # clone git clone https://github.com/powerline/fonts.git --depth=1 # install cd fonts .\install.ps1 #clean up cd .. rd /S /Q fonts ``` ### WSL #### Installer zsh: ```bash $ sudo apt-get install zsh curl git $ chsh -s $(which zsh) ``` #### Installer antibody: ```bash $ curl -sfL git.io/antibody | sudo sh -s - -b /usr/local/bin [sudo] password for bruno: getantibody/antibody info checking GitHub for latest tag getantibody/antibody info found version: 6.0.1 for v6.0.1/Linux/x86_64 getantibody/antibody info installed /usr/local/bin/antibody ``` On restaure .zshrc .zsh_plugins.txt .dircolors ```bash $ curl https://clicclac.info/backup/zsh_win10.tar.gz | tar -xzv ``` On met à jour les plugins antibody ```bash $ antibody bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.sh ``` #### Installer z plugin: ```bash $ cd /usr/local/etc/profile.d/z/ #Créer les dossiers profile.d et z si ils n'existent pas. #Cloner le répertoire git clone https://github.com/rupa/z.git ``` Ajouter la ligne suivante au .zshrc ```bash . /usr/local/etc/profile.d/z/z.sh ``` ### SSH #### Générer une paire de clé ssh sous Windows: ```powershell PS ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (C:\Users\bruno/.ssh/id_rsa): Created directory 'C:\Users\bruno/.ssh'. ``` #### Copier les clés dans wsl: ```bash $ cp -r /mnt/c/Users//.ssh ~/.ssh # Corriger les autorisations: $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/* ``` #### Installer keychain dans wsl: ```bash $ sudo apt install keychain ``` #### Copier la clé sur le serveur: ```bash cat ~/.ssh/id_rsa.pub | ssh bruno@maboiteverte.fr 'cat>> ~/.ssh/authorized_keys' cat ~/.ssh/id_rsa.pub | ssh sentier@sur-le-sentier.fr 'cat>> ~/.ssh/authorized_keys' cat ~/.ssh/id_rsa.pub | ssh -p42666 bruno@clicclac.synology.me 'cat>> ~/.ssh/authorized_keys' ``` Si il n'y a qu'une seule clé sur le serveur (scp écrase authorized_keys) ```bash scp -P42666 C:\Users\bruno\.ssh\id_rsa.pub bruno@clicclac.synology.me:~/.ssh/authorized_keys ``` #### Ne plus demander la passphrase ssh: https://medium.com/@glsorre/windows-subsystem-for-linux-never-prompt-your-ssh-passphrase-again-353db7c931ab Installer CredentialManager: ```powershell PS Install-Module -Name CredentialManager ``` Copier les 2 fichiers suivants dans `/home/[YOUR_WSL_USERNAME]/wslu/` *keychain.ps1:* ```powershell $credentials = Get-StoredCredential -Target sshpassphrase $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($credentials.Password) $passphrase = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) C:\Windows\System32\wsl.exe -u [YOUR_WSL_USERNAME] -d [YOUR_DISTRIBUTION] /home/[YOUR_WSL_USERNAME]/wslu/keychain.sh $passphrase ``` *keychain.sh:* ```bash #!/bin/bash SSH_ASKPASS_SCRIPT=/tmp/ssh-askpass-script cat > ${SSH_ASKPASS_SCRIPT} <Ouvrir dans le Gestionnaire d'identification: *Panneaux de configuration -> Gestionnaire d'identification -> Information d'identification Windows -> Ajouter des informations d'identification génériques* - Adresse Internet ou réseau: sshpassphrase *(le mot passphrase)* - Nom d'utilisateur: sshpassphrase *(le mot passphrase)* - Mot de passe: *(la passphrase)* Ouvrir le Planificateur de taches: *Panneaux de configuration -> Outils d'administration -> Planificateur de taches -> Créer une tache de base* - Général: - Mettre un nom: Launch Keychain - Configuré pour Windows 10 - Déclencheur: - quand j'ouvre une session - Action: démarrer un programme - Programme/script: powershell - Ajouter des arguments: -File C:\Users\bruno\wslu\keychain.ps1 ### VS Code #### Avoir VisualCode en français: Rechercher 'French language' dans les extensions #### #### VScode et wsl: Afficher la palette de commande (Ctrl+Maj+P) et entrer Remote-WSL: New Window Depuis le terminal, taper `code .` ou `code-insiders .` La commande `code` est dispo depuis le terminal. Si elle ne l'est pas, vérifier que VS Code est dans le `PATH`. Sinon ajouter la ligne suivante au `.zshrc` ```bash # VS Code export PATH="/mnt/c/Program Files/Microsoft VS Code/bin:$PATH" ``` #### ###Changer les couleurs pour **ls**: ``` LS_COLORS="ow=01;36;40" && export LS_COLORS ``` cd utilise les couleurs ls. ```bash zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}" autoload -Uz compinit compinit ``` ### Fin ```bash $ uname --release 4.19.84-microsoft-standard # 08-08-2020 ``` https://devblogs.microsoft.com/commandline/access-linux-filesystems-in-windows-and-wsl-2/