Bash ubuntu on windows

De Banane Atomic
Révision datée du 10 juillet 2018 à 14:51 par Nicolas (discussion | contributions) (→‎git)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à la navigationAller à la recherche

Usage

Bash.svg
# acces à C:\
cd /mnt/c

# log as root
sudo su

# lancer une commande bash depuis un autre shell (powershell)
wsl ls -al

Installation

Pour Windows 10 64 bits
Powershell.svg
# en mode Administrateur
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Microsoft Store → Ubuntu 18.04
L'installation se fait dans C:\Users\%username%\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs

Autre méthode:

  1. Settings → Update & security → For developers → Developer mode
  2. Control panel → Uninstall a program → Turn Windows features on or off → Windows Subsystem for Linux

Changer le thème des couleurs

Télécharger Windows Console Colortool

Dos.svg
colortool.exe -b schemes\OneHalfDark.itermcolors
REM -b change la console actuelle et le schéma par défaut

Introducing the Windows Console Colortool

Changer la couleur des dossiers other-writable (o+w) and not sticky

Par défaut, ils sont bleus sur fond vert.

Bash.svg
# création de la configuration des couleurs
dircolors -p > ~/.dircolors
~/.dircolors
#OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
OTHER_WRITABLE 34;40 # bleu sur fond noir
~/.zshrc
# read ~/.dircolors
d=.dircolors
test -r $d && eval "$(dircolors $d)"
# apply to completion
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}

list-colors

Lancer bash depuis le menu contextuel d'explorer

regedit → HKEY_CLASSES_ROOT\Directory\Background\shell

  • new Key → bash
    • (Default) → Data = Open a bash shell here
    • new String Value → Icon → Data = C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2018.427.0_x64__79rhkp1fndgsc\ubuntu1804.exe
    • new Key → command
      • (Default) → Data = C:\Users\llobera\AppData\Local\Microsoft\WindowsApps\ubuntu1804.exe run zsh
      • (Default) → Data = cmd.exe /c pushd "%V" && bash.exe -c zsh

La flèche ne s'affiche pas avec le thème zsh robbyrussell

Changer le font du terminal: clique-droit sur la barre de titre → Properties → Font : DejaVu Sans Mono N’accepte que les font ttf, pas les otf.
Ou changer les flèches dans le thème robbyrussell.

~/.oh-my-zsh/custom/robbyrussell.zsh-theme
# replace arrow with good one for the font
if [[ $ZSH_THEME == "robbyrussell" ]]; then
        local ret_status="%(?:%{$fg_bold[green]%}→ :%{$fg_bold[red]%}→ )"
        PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'

        ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
        ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
        ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}→"
        ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
fi

Utiliser des applications graphiques

  1. installer un X Server pour Windows (Xming, Cygwin X, vcXsrv)
    1. Cygwin X: xorg-server xinit xhost
Bash.svg
# dans le terminal cygwin
startxwin -- -listen tcp
export DISPLAY=:0
xhost +localhost

# dans wsl
ai x11-apps
export DISPLAY=:0
xeye

Thème

/etc/gtk-3.0/settings.ini
[Settings]
gtk-theme-name = Adwaita-dark
gtk-icon-theme-name = ubuntu-mono-dark
gtk-sound-theme-name = ubuntu
gtk-icon-sizes = panel-menu-bar=24,24

Failed to execute child process “dbus-launch” (No such file or directory)

Installer ubuntu-desktop fixe le problème
/usr/share/dbus-1/session.conf
<!-- <listen>unix:tmpdir=/tmp</listen> -->
<listen>tcp:host=localhost,bind=0.0.0.0,port=0</listen>

<!-- <auth>EXTERNAL</auth> -->
<!-- fallback to DBUS_COOKIE_SHA1 -->
Bash.svg
sudo service dbus restart

insufficient privileges to access the ebtables rulesets

Erreur durant la màj de ebtables

Bash.svg
# désactiver les màj pour ebtables
sudo apt-mark hold ebtables

npm

Solution: installer npm sur wsl
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

Le fichier C:\Program Files\nodejs\npm à des fin de ligne CRLF, ce que wsl ne sait pas interpréter.

Bash.svg
ai dos2unix
# remplace tous les CRLF en LF
dos2unix npm
net.js:200
    this._handle.open(options.fd);
                 ^

Error: EINVAL: invalid argument, uv_pipe_open
    at new Socket (net.js:200:18)
    at createWritableStdioStream (internal/process/stdio.js:164:16)
    at process.getStdout [as stdout] (internal/process/stdio.js:14:14)
    at console.js:243:38
    at NativeModule.compile (bootstrap_node.js:596:7)
    at Function.NativeModule.require (bootstrap_node.js:541:18)
    at setupGlobalConsole (bootstrap_node.js:310:41)
    at startup (bootstrap_node.js:70:7)
    at bootstrap_node.js:608:3

git

L'utilisation de git clone télécharge les fichiers avec LF comme caractère de fin de ligne.
Modifier la Configuration si certain programme ont besoin de CRLF