Skip to content

Instantly share code, notes, and snippets.

@davehowell
Last active June 3, 2024 05:22
Show Gist options
  • Select an option

  • Save davehowell/bb1c3790ae02008429bbd985deed308d to your computer and use it in GitHub Desktop.

Select an option

Save davehowell/bb1c3790ae02008429bbd985deed308d to your computer and use it in GitHub Desktop.
wsl
# THE WSL2 with Ubuntu 20.04 and bash 5.0 edition. Mainly for VSCode usage
# This is just the customized parts
# if you can only use /usr/bin/python3 because public apt repo is blocked
alias python='python3'
#create a python venv within project dir using current python
# python -m venv .venv
alias vnv='source ./.venv/bin/activate'
#prompt looks like this with green, blue, cyan, purple colors:
# user@host:~/somedir Mon Jun 01 22:38:25
# (current_branch)∫
PS1='\[\033[00;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00;36m\] \d \t
\[\033[01;35m\]$(__git_ps1)\[\033[1;36m\]∫\[\033[00m\] '
#### How to use apt-get to download and install a package manually
## Create directory within home (if you can't write anywhere else, because no sudo for you)
# mkdir ~/apps
## 2) Download "keychain" package from e.g. artifactory - it uses whatever repos are specified in /etc/apt/sources.list
# apt-get download keychain
## 3) extract the package
#dpkg -x keychain_2.8.5-1_all.deb ~/apps/
## 4) Make sure the custom install location is in your PATH
export PATH="~/apps/usr/bin:$PATH"
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
bindkey -e
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/home/dhowell/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
#pyenv
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# change colours and default for ls
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -Fhla'
function mkvenv() {
if [[ -z "$1" ]]; then
echo "usage: mkvenv [--force] [--path VENV_PATH] [PYTHON_VERSION]"
return 1
fi
local cyan='\033[0;36m'
local red='\033[0;31m'
local nocolor='\033[0m'
local grey='\033[0;90m'
local force=""
local venvdir=".venv"
local version=""
if [[ -f .python-version ]]; then
version="$(cat .python-version)"
fi
while [[ -n "$1" ]]; do case $1 in
-p | --path )
shift; venvdir=$1
;;
-f | --force )
force=1
;;
*)
version="$1"
;;
esac; shift; done
hash pyenv 2>/dev/null || { echo -e "${red}pyenv not found; try 'brew install pyenv'${nocolor}"; return 1; }
hash direnv 2>/dev/null || { echo -e "${red}direnv not found; try 'brew install direnv'${nocolor}"; return 1; }
if [[ -f .python-version ]]; then
local existing="$(cat .python-version)"
if [[ -z "$force" && "$existing" != "$version" ]]; then
echo -e "${red}${version} does not match .python-version (${existing})${nocolor}"
return 1
fi
fi
pyenv local "$version" || return 1
if [[ -d "$venvdir" ]]; then
if [[ -z "$force" ]]; then
echo -e "${red}${venvdir} already exists! use -f to overwrite it${nocolor}"
return 1
elif [[ -n "$venvdir" && "$venvdir" != "/" && "$venvdir" != "" ]]; then
rm -r "$venvdir"
fi
fi
printf "$grey"
python -m venv "$venvdir" || return 1
printf "$nocolor"
touch .envrc
sed -i '/^source ".*bin\/activate"$/d' .envrc \
&& echo "source \"$venvdir/bin/activate\"" >> .envrc
sed -i '/^unset PS1$/d' .envrc \
&& echo "unset PS1" >> .envrc
direnv allow
echo -e "${cyan}Created Python virtual environment in $(cd "$venvdir" 2> /dev/null ; pwd) ${nocolor}"
}
# git & right prompt
autoload -Uz compinit && compinit
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
PROMPT=\$vcs_info_msg_0_'%B%F{6}%~%f%b% %* %(?.%F{green}√.%F{red}?%?)%f
%B%F{13}∫%f%b '
zstyle ':vcs_info:git:*' formats '%F{3}(%b)%r%f'
zstyle ':vcs_info:*' enable git
show_virtual_env() {
if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
echo "($(basename $VIRTUAL_ENV))"
fi
}
# bash only
# export -f show_virtual_env
PS1='$(show_virtual_env)'$PS1
# terraform autocomplete
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /usr/local/bin/terraform terraform
# direnv - needs to be last
eval "$(direnv hook zsh)"

Add net tools

sudo apt-get install net-tools

install and switch to zsh

# which shell am I using?
echo $0

# install & switch
sudo apt install zsh
chsh -s $(which zsh)

podman

sudo apt -y install podman

add global config for wsl

sudo nano /etc/wsl.conf

fix DNS

# e.g. add Google's nameserver: 8.8.8.8 
sudo nano /etc/resolv.conf

fix sources list for apt libraries and packages

sudo nano /etc/apt/sources.list
# note that the security subdomain doesn't work for these URLs, just use the archive one for all
# optionally use an AU mirror here

direnv

sudo apt-get install direnv

pyenv

# dependencies according to https://ericsysmin.com/2024/01/11/how-to-install-pyenv-on-ubuntu-22-04/
# Lots of build tools.
sudo apt-get update && sudo apt-get install -y make build-essential libssl-dev \
    zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
    libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev


curl https://pyenv.run | bash

epic list of WSL related things

https://github.com/mikeroyal/WSL-Guide

restart wsl

8 second rule

wsl --list --running
wsl --shutdown #(from powershell or cmd, NOT ubuntu shell)

mounts

WSL2 file system can be accessed from Windows using network drive \wsl$
Windows file system can be accessed from WSL2 using /mnt/c/

This is not endless reflection sadly, you can't go to \wsl$\mnt\c\

enterprise certs

# copy certificates to dir where they get picked up
sudo cp /mnt/c/tmp/proxy_chain.pem /usr/local/share/ca-certificates/extra

# convert pem to crt if it is multiple certificates (i.e. certificate chain)
sudo openssl x509 -outform der -in /usr/local/share/ca-certificates/extra/proxy_chain.pem -out /usr/local/share/ca-certificates/extra/proxy_chain.crt



# Import certs


# show certs
ls /etc/ssl/certs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment