项目作者: zahav

项目描述 :
WSL 2 Ubuntu + Windows Terminal + Docker + VS Code
高级语言: Shell
项目地址: git://github.com/zahav/wsl-dotfiles.git
创建时间: 2020-10-20T09:30:21Z
项目社区:https://github.com/zahav/wsl-dotfiles

开源协议:MIT License

下载


My Windows Subsystem for Linux Setup & Dotfiles

Install

On Windows

1. Enable WSL2

Run in PowerShell, as admin (elevated):

  1. Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  2. Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
  3. wsl --set-default-version 2

On WSL 2

2. Install dependencies

  1. # Use apt over HTTPS
  2. sudo apt update && sudo apt install -y \
  3. apt-transport-https \
  4. ca-certificates \
  5. curl \
  6. gnupg-agent \
  7. software-properties-common
  8. # Add AzureCLI to sources.list
  9. curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
  10. AZ_REPO=$(lsb_release -cs)
  11. echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
  12. sudo tee /etc/apt/sources.list.d/azure-cli.list
  13. # Add Docker to sources.list
  14. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  15. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  16. # Add Node.js to sources.list
  17. curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
  18. # Add Yarn to sources.list
  19. curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
  20. echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  21. # Install development tools
  22. sudo apt update && sudo apt upgrade
  23. sudo apt install -y \
  24. azure-cli \
  25. containerd.io \
  26. docker-ce \
  27. docker-ce-cli \
  28. fontconfig \
  29. git \
  30. gnupg \
  31. nodejs \
  32. unzip \
  33. yarn \
  34. zsh
  35. # Add user to docker group
  36. sudo usermod -aG docker $USER
  37. # Test the installation
  38. docker run --rm hello-world

3. Restore (or generate) the GPG key

  • On old system, create a backup of a GPG key
    • gpg --list-secret-keys
    • gpg --export-secret-keys {{KEY_ID}} > /tmp/private.key
  • On new system, import the key:
    • gpg --import /tmp/private.key
  • Delete the /tmp/private.key on both sides

4. Setup Git

  1. # Set the git author email and username
  2. email="EMAIL"
  3. username="USERNAME"
  4. gpgkeyid="KEY_ID"
  5. # Configure Git
  6. git config --global user.email "${email}"
  7. git config --global user.name "${username}"
  8. git config --global user.signingkey "${gpgkeyid}"
  9. git config --global commit.gpgsign true
  10. git config --global core.excludesfile $HOME/.gitignore
  11. # Create a Code directory for all our work
  12. mkdir $HOME/Code
  13. # Generate a new key
  14. ssh-keygen -t rsa -b 4096 -C "${email}" -f github_rsa
  15. # Start ssh-agent and add the key to it
  16. eval $(ssh-agent -s)
  17. ssh-add $HOME/.ssh/github_rsa
  18. # Display the public key ready to be copy pasted to GitHub
  19. cat $HOME/.ssh/github_rsa.pub

5. Setup ZSH and Oh My Zsh

  1. # Change the default shell to ZSH
  2. chsh -s $(which zsh)
  3. # Install Oh My Zsh
  4. sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  5. # Finally clone the repository
  6. mkdir -p $HOME/.dotfiles
  7. git clone git@github.com:zahav/wsl-dotfiles.git $HOME/.dotfiles
  8. # Removes .zshrc from $HOME (if it exists) and symlinks the .zshrc file from the .dotfiles
  9. rm $HOME/.zshrc
  10. ln -s $HOME/.dotfiles/.zshrc $HOME/.zshrc
  11. # Link custom dotfiles
  12. ln -s $HOME/.dotfiles/.aliases.zsh $HOME/.aliases.zsh
  13. ln -s $HOME/.dotfiles/.gitignore_global $HOME/.gitignore

6. Customise our fonts

  1. # Install JetBrains Mono typeface
  2. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/install_manual.sh)"
Alternate fonts to try
  • Cascadia Code
  • DejaVu Sans
  • FuraMono
  • FiraCode
  • Hack
  • Menlo

7. Copy useful files to Windows

  1. windowsUserProfile=/mnt/c/Users/$(cmd.exe /c "echo %USERNAME%" 2>/dev/null | tr -d '\r')
  2. # Windows Terminal settings
  3. cp $HOME/.dotfiles/terminal-settings.json ${windowsUserProfile}/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json
  4. # Avoid too much RAM consumption
  5. cp $HOME/.dotfiles/.wslconfig ${windowsUserProfile}/.wslconfig