1. Run Scripts from Command Line
Mac¶
Mac's Terminal app is ideal for this because Mac has a Linux based OS and most apps are deployed to Linux machines in Production due to their cost effectiveness.
Windows¶
Since Window's is not a Linux based OS, you can set up a Linux virtual environment with WSL.
Set Up a WSL Environment¶
NOTE: If you already have a legacy version of WSL installed (i.e. WSL1 instead of WSL2), uninstall it so you can follow the install steps below
- Enable Virtual Machine Platform Windows Feature (if not already done)
- Ensure virtualization is enabled in the Bios: https://support.microsoft.com/en-us/windows/enable-virtualization-on-windows-11-pcs-c5578302-6e43-4b4b-a449-8ced115f58e1
- Run Windows PowerShell as an administrator and select yes to the prompt asking if you want to allow the app to make changes to your device
- Run the command
wsl --install
- This will take a few minutes, but on successful complete, you should see the below output
- Restart your computer
- If you see an Ubunutu terminal loaded when you log back in
- Close out of the Ubuntu window, and open PowerShell
- Run the command
wsl -l -v
to list your installed Linux Distributions and you should see something like the following - NOTE: The star next to the Ubuntu-20.40 distribution means this is the default distribution that will be used when launching WSL
- To launch your default Linux distribution from PowerShell, simply run the command
wsl
- If you don't see an Ubuntu shell, you likely don't have any distributions installed.
- Install an Ubuntu distribution with the command
wsl --install -d ubuntu
- Create a username and password when prompted.
- NOTE: Be sure to save the username and password you use for this linux distribution - each distro has a dif one and this is what has sudo access
- When the install completes you will see
Format Your Terminal¶
No matter the command line interface (CLI) used, it helps to format your CLI to work well with Git so that you know what branch you are working on and don't accidentally commit code to the wrong branch.
.bashrc
vs. .bash_profile
¶
The code below accounts for proper formatting using both the .bashrc
and .bash_profile
. This is important because .bashrc
is used for inactive logins (i.e. task run in the background like a cron job or VSCode logging into your terminal), and .bash_profile
is used when you are actively logging in.
NOTE: Code below found in this Medium article
- Open your terminal of choice (i.e. Mac users default terminal/ Windows users WSL)
- Cd to your home directory
cd ~
- Create
.bash_profile
file if it doesn't already existtouch .bash_profile
- Open
.bash_profile
- Mac:
open .bash_profile
- WSL:
notepad .bash_profile
- Linux:
vim .bash_profile
- Mac:
- Add this line to the bottom of the file
source ~/.bashrc
- NOTE: In vim, type
i
to enter INSERT mode and then right click to paster the copied text. Pressesc
to exit INSERT mode. Type:wq
and press enter to save and close the file.
- Create
.bashrc
file if it doesn't already exist - Open
.bashrc
- Add this line to the bottom of the file
source ~/.bash_prompt
- Create
.bash_prompt file
- Open
.bash_prompt
file - Add these lines to your file
#!/usr/bin/env bash # GIT FUNCTIONS git_branch() { git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*$ \\(.*\\)/ (\\1)/' } # TERMINAL PROMPT PS1="\[\e[0;93m\]\u\[\e[m\]" # username PS1+=" " # space PS1+="\[\e[0;95m\]\W\[\e[m\]" # current directory PS1+=" " # space PS1+="\[\e[0;92m\]\$(git_branch)\[\e[m\]" # current branch PS1+=" " # space PS1+=">> " # end prompt export PS1; export CLICOLOR=1 export LSCOLORS=ExFxBxDxCxegedabagacad
- Relaunch you terminal and navigate to a git repo (i.e. this python-dev-setup repo). You will now see your terminal prompt formatted with your username, current folder and repo branch
- Mac:
- WSL:
- Mac: