Skip to content

Instantly share code, notes, and snippets.

@mloskot
Last active September 26, 2018 09:33
Show Gist options
  • Select an option

  • Save mloskot/aa24d374590d001c9fc8548fcf8c25e6 to your computer and use it in GitHub Desktop.

Select an option

Save mloskot/aa24d374590d001c9fc8548fcf8c25e6 to your computer and use it in GitHub Desktop.
BashOnWindows for C/C++ development

Basics

Force legacy distribution

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LxssManager]
"DistributionFlags"=dword:fffffffd

Disable appending Windows PATH:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss]
"AppendNtPath"=dword:00000000
sudo vi /etc/hosts

# add hostname
127.0.0.1 localhost MYHOSTNAME
sudo vi /etc/inputrc

#add or uncomment line
set bell-style none

Git

  • ~/.gitconfig

C/C++

sudo add-apt-repository ppa:ubuntu-toolchain-r/test               # latest GCC
sudo apt-get update
sudo apt-get install build-essential git gcc-7 g++-7 gcc-6 g++-6
sudo apt-get install libboost-dev

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0.0 60 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-5.0.0
sudo update-alternatives --config gcc
gcc --version

CMake 3.11+

wget https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.sh
sudo sh cmake-3.11.0-Linux-x86_64.sh -- --skip-license --prefix=/usr/local

Set up SSH for remote development (VS2017, CLion, VSCode)

Run wsl_ssh_setup.sh (source code below):

wget https://gist.githubusercontent.com/mloskot/aa24d374590d001c9fc8548fcf8c25e6/raw/ecb80e971130a8c8b3a7cd1fdde31b004751bdf0/wsl_ssh_setup.sh && sudo bash wsl_ssh_setup.sh

Powerline

WARNING Powerline is bloody slow in large git trees eg. Boost repository

  • Install Powerline fonts on Windows
git clone https://github.com/powerline/fonts.git  
cd fonts  
./install.ps1

Go to WSL Bash command prompt, Properties and change font to "DejaVu Sans Mono for Powerline".

  • Install Powerline in WSL
sudo apt-get install build-essential git python-pip

cd ~  
mkdir src  
cd src  
git clone https://github.com/banga/powerline-shell.git

cd ~/src/powerline-shell  
cat config.py.dist > config.py  
./install.py
  • Configure Powerline in WSL
vim .bashrc
# Copy & paste this at the end of the .bashrc
function _update_ps1() {  
    PS1="$(~/src/powerline-shell/powerline-shell.py $? 2> /dev/null)"
}

if [ "$TERM" != "linux" ]; then  
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi  

Clion

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000214944-Looking-for-Monokai-color-scheme-for-CLion

  • Colours: Monokai
  • Font: Consolas or Fira Code
[user]
name = Mateusz Loskot
email = [email protected]
[alias]
br = branch
bv = branch -vv
ci = commit --verbose
co = checkout
lg = log
rt = remote
rv = remote -v
st = status
#!/bin/bash
#
# Copy of https://github.com/JetBrains/clion-wsl/blob/master/ubuntu_setup_env.sh
# modified to NOT to install GCC/clang, etc.
#
SSHD_PORT=22
SSHD_FILE=/etc/ssh/sshd_config
SUDOERS_FILE=/etc/sudoers
# 0. update package lists
sudo apt-get update
# 0.1. reinstall sshd (workaround for initial version of WSL)
sudo apt remove -y --purge openssh-server
sudo apt install -y openssh-server
# 1.2. configure sshd
sudo cp $SSHD_FILE ${SSHD_FILE}.`date '+%Y-%m-%d_%H-%M-%S'`.back
sudo sed -i '/^Port/ d' $SSHD_FILE
sudo sed -i '/^UsePrivilegeSeparation/ d' $SSHD_FILE
sudo sed -i '/^PasswordAuthentication/ d' $SSHD_FILE
echo "# configured by CLion" | sudo tee -a $SSHD_FILE
echo "Port ${SSHD_PORT}" | sudo tee -a $SSHD_FILE
echo "UsePrivilegeSeparation no" | sudo tee -a $SSHD_FILE
echo "PasswordAuthentication yes" | sudo tee -a $SSHD_FILE
# 1.3. apply new settings
sudo service ssh --full-restart
# 2. autostart: run sshd
sed -i '/^sudo service ssh --full-restart/ d' ~/.bashrc
echo "%sudo ALL=(ALL) NOPASSWD: /usr/sbin/service ssh --full-restart" | sudo tee -a $SUDOERS_FILE
cat << 'EOF' >> ~/.bashrc
sshd_status=$(service ssh status)
if [[ $sshd_status = *"is not running"* ]]; then
sudo service ssh --full-restart
fi
EOF
# summary: SSHD config info
echo
echo "SSH server parameters ($SSHD_FILE):"
echo "Port ${SSHD_PORT}"
echo "UsePrivilegeSeparation no"
echo "PasswordAuthentication yes"
make --version
cmake --version
gcc --version
clang --version
gdb --version
valgrind --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment