Skip to content

Instantly share code, notes, and snippets.

@OrsosAdam
Last active June 4, 2020 15:18
Show Gist options
  • Save OrsosAdam/f90f5f401e6464e7fb8c20cbf0fc14f5 to your computer and use it in GitHub Desktop.
Save OrsosAdam/f90f5f401e6464e7fb8c20cbf0fc14f5 to your computer and use it in GitHub Desktop.
WSL2 Setup
alias pa="php artisan"
alias pas="php artisan serve"
alias pat="php artisan tinker"
alias par="php artisan routes"
alias pam="php artisan migrate"
alias pam:r="php artisan migrate:refresh"
alias pam:roll="php artisan migrate:rollback"
alias pam:rs="php artisan migrate:refresh --seed"
alias pda="php artisan dumpautoload"
alias cu="composer update"
alias ci="composer install"
alias cda="composer dump-autoload -o"
# Windows leaks some of the commands to wsl somehow
# function path_remove {
# # Delete path by parts so we can never accidentally remove sub paths
# PATH=${PATH//":$1:"/":"} # delete any instances in the middle
# PATH=${PATH/#"$1:"/} # delete any instance at the beginning
# PATH=${PATH/%":$1"/} # delete any instance in the at the end
# }
# path_remove '/mnt/c/Users/me/AppData/Roaming/npm'
# path_remove '/mnt/c/Users/me/AppData/Local/Yarn/bin'
# path_remove '/mnt/c/Program Files (x86)/Yarn/bin'
# path_remove '/mnt/c/Program Files/Git'
# path_remove '/mnt/c/Program Files/Git/cmd'
# path_remove '/mnt/c/Program Files/nodejs'
# path_remove '/mnt/c/OpenSSL-Win32/bin'
# path_remove '/mnt/c/Program Files (x86)/Python27'
# So this is not the best way to solve this. Also, VS Code doesnt read .profile file, so you have to put in the same function here if you want to read it there.
# I solved the path leaking by removing from Windows by hand. I suggest to setup this on a freshly installed computer.
## you can also add this to your .bashrc because vscode integrated terminal has a bug
function color_my_prompt {
local __time="\t"
local __user="\u"
local __cur_location="\w"
local __git_branch_color=""
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\/`'
local __prompt_tail="\[\033[37m\]>"
local __last_color="\[\033[37m\]"
export PS1="|\[\033[35m\]$__time\[\033[37m\]|\[\033[36m\]$__user@${HOSTNAME,,}\[\033[37m\]:\[\033[32m\][$__cur_location]\[\033[31m\]$__git_branch_color$__git_branch$__prompt_tail$__last_color"
}
color_my_prompt

After installing WSL 2 and Windows Terminal respectively, go into the distro of your choice, preferably Ubuntu, without ZSH, only bash.

type sudo apt update && sudo apt dist-upgrade

after the prompt install composer sudo apt install composer

run composer to check if it works

but before that install php-zip also php-mbstring and php-xml which is not included in the composer default packages sudo apt install php-zip php-mbstring php-xml

after that install global laravel composer global require laravel/installer

run laravel to check if it works

if the command is not found use this export PATH="$HOME/.config/composer/vendor/bin:$PATH"

// windows terminal conf
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"fontFace": "Operator Mono",
"colorScheme": "Material",
"commandline": "wsl.exe ~"
scheme:
{
"name": "Material",
"background": "#263238",
"foreground": "#eeffff",
"black": "#000000",
"blue": "#82aaff",
"brightBlack": "#546e7a",
"brightBlue": "#82aaff",
"brightCyan": "#89ddff",
"brightGreen": "#c3e88d",
"brightPurple": "#c792ea",
"brightRed": "#ff5370",
"brightWhite": "#ffffff",
"brightYellow": "#ffcb6b",
"cyan": "#89ddff",
"green": "#c3e88d",
"purple": "#c792ea",
"red": "#ff5370",
"white": "#ffffff",
"yellow": "#ffcb6b"
}

It is discouraged to turn off passwd for root, but we are inside wsl, and i am too lazy for typing the password of mine, so There is a clever oneliner for it, but its too much of a hassle, so here are the prompts

sudo visudo

end of the file:

%sudo ALL=(ALL) NOPASSWD: ALL

so it wont ask for the passwd ever again, but you still have to type sudo...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment