dashwood.net -

Ryan Stefan's Micro Blog

Windows WSL Tips and Solved Issues

Dec 222018

I've completely switched over to Windows 10 with WSL on my main development computer and it's going pretty well. I just cant stand coding in Windows because everything is different and nothing works as well as it does on Linux. My job requires a lot of design work so having my home computers on Linux was not very practical. So when I heard about a native Linux sub-system I jumped at it. I will be putting any issues that I solve in this article. 

Getting Rsub Working with Windows WSL & Ubuntu 18.04

  1. Add rsub to sublime with package control (on Windows)
  2. Install & configure rmate (on Linux)
  3. Install openssh-server (on Linux)
  4. configure ssh (on Linux)
  5. add bashrc script with sudo and -f (on Linux)

Installing & Rmate

pip install rmate
sudo nano /etc/rmate.rc

127.0.0.1
52698

ctrl+o
ctrl+x

Install & Configure Openssh Server

sudo apt install openssh-server

sudo nano /etc/ssh/sshd_config

Port 2222
ListenAddress 0.0.0.0
Protocol 2
PasswordAuthentication yes
StrictModes no

ctrl+o
ctrl+x

sudo nano /etc/ssh/ssh_config

Host *
  RemoteForward 52698 localhost:52698
Port 2222
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes

sudo service ssh --full-restart

Bashrc Configurations

sudo nano ~/.bashrc

Open any file with Sublime Text

I plan on expanding this so that it can open on other windows drives like E:/

function subl {
 CUR_PATH=`readlink -f $1`
 if [[ $CUR_PATH == /mnt/c/* ]]; then
 /mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe "C:${CUR_PATH:6}"
 else
 sudo rmate $CUR_PATH -f
 fi
}

Convert and Open Shell Directory in Explorer

  • $() runs subshell function but leaves quotes around result
  • `` double ticks run the wslpath function in a subshell and strips quotes from result
  • $pwd is in quotes because directory spaces break the wslpath function
  • /$1 is an optional parameter for a subdir path
open() { explorer.exe `wslpath -w "$PWD"/$1`; }

Handy Bash Aliases

alias bashrc='subl ~/.bashrc' # open bashrc config
alias rbash='. ~/.bashrc' # reset bash shell to use changes

alias rbash='. ~/.bashrc' # reset bashrc in terminal
alias startredis='sudo service redis-server start'
alias stopredis='sudo service redis-server stop'

Windows Python Path Conflicting with Pipenv

This one is pretty annoying. I installed python 3.7 on my windows computer so that I could do linting on Sublime Text and it caused my pipenv to start using that path for the --three tag. I suppose I could have specified a different version, but I assumed there would be a way to turn off the windows python path inside WSL. I tried a few different ways, but none of them worked. I gave up and just made a bash function that points to my linux path:

##! Don't install packages with this, it will break dependency matching
pipenv3() { pipenv --python=/usr/bin/python3 install "[email protected]"; }

Note: bash script variables won't work if you use single quotes like this -> '

Other Things

  • ConEmu as bash editor
  • DejaVu Sans Mono font for everything (11pt)
  • Started saving appdata inside Google Drive
  • win+x shows "Power Menu"
  • win+ → or win + ← fits window to half screen
  • display fusion allows shortcuts on secondary taskbar
  • stickies — sticky notes minimize to tray
  • Musicbee — Powerful music player that saves spot

Side Note about Pip

Something that has been bothering me for a while now is whether I should install pipenv with pip or pip3. Turns out that pip is not the python two version of pip, but rather a hybrid of both. So there is pip3, pip, and pip2. So the obvious answer is to install it using plain pip. 

"pip3 always operates on the Python3 environment only, as pip2 does with Python2. pip operates on whichever environment is appropriate to the context."

Use "sudo apt install pip" on Ubuntu — Doesn't work well on Mint

Setting up Postgresql Properly

sudo apt install postgresql
sudo service postgresql start
sudo su - postgres
createuser --superuser ryan
psql # <- command line tool for making queries
\password ryan
\q # <- exit psql to create new users/dbs or import/export db's (psql is for sql)
createdb ryan # or whatever# exit and now you can run psql in your own console with your username.

#start automatically
sudo systemctl enable postgresql

Setting up Redis

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install redis-server

sudo service redis-server start
sudo service redis-server stop
sudo service redis-server restart

# running just redis-server will force you to keep a bash window open
# I usually just create a bashrc alias for this /shrug

# for automatically starting redis enter

sudo systemctl enable redis-server


Comments