# CS202 Review Session 02 ## The Shell and IDEs Notes from Sam Frank, TA Spring 2024 Inspiration from [MIT Missing Semester](https://missing.csail.mit.edu/2020/) and [Fireship VSCode Tips](https://www.youtube.com/watch?v=ifTF3ags0XI) _Try viewing this in markdown!_ 1. Introduction 2. Motivation 3. The Shell 4. IDEs ------------------------------------------------- 1. Introduction 2. Motivation - Learning these tools will help *immensely* in class and outside it - You will program faster - You will understand your machine better - You will get closer to the OS 3. The Shell What is it? - def: a textual interface to the kernel (OS) - in practice: a program that takes keyboard inputs, and tells the OS to do something History: - Thompson shell (sh) -> Bourne shell (also sh) - today: Bourne Again Shell (bash), Z shell (zsh), etc. How to Use? - Open a terminal app - Enter commands into the prompt ("Command Line Interface") Basic Commands: - `date` --> prints date - `echo [arg]` -> prints [arg] - `ls` - you will implement in lab 2 - "commands" are really just programs! - how does shell know where to find programs? - `echo $PATH` - $PATH contains list of places for shell to look for programs - `which ls` - prints absolute path to `ls` executable - or specify path when command isn't in $PATH - e.g. ./cs202-run-docker - `pwd`: print working directory - `cd`: change directory Flags and Pipe Building: - `ls -l`, `ls -a`, `ls -al` - what are these flags? -> `man ls` (*run this in docker to get linux manual*) - `ls -al` -> `ls -al | head -n3` -> `ls -al | head -n3 | tail -n2` - pipes (`|`) are one of the most important features of the shell! - this is where you really unlock the full powers of the shell - `curl --head --silent www.google.com | grep --ignore-case content-type | cut -d ' ' -f2` Other Output Redirection: - Redirect to a file with `>` - or take input from file with `<` - ex: `echo hello > hello.txt` - `cat hello.txt` - more fun ex: `curl --silent -L www.google.com > google.html` Productivity Tips! - autocomplete !!!!! (tab) - ex: when you are running `./cs202-run-docker`, press tab after typing the first few characters - Clear last command: Cmd + L - Clear whole screen: Cmd + K - Jump to beginning of line: Ctrl + A - Jump to end of line: Ctrl + E - Delete rest of line after cursor: Ctrl + K (combine with Ctrl + A!) - rerun last command: `!!` (especially helpful with sudo) - can also toggle through previous commands with up/down arrow When to Use the Shell: - All the time! (okay, maybe not ALL the time) - It is most helpful when you are running programs or browsing files - Can also edit (quick plug for Vim) - Other cool stuff!: - see where your CPU is going: `top` - look at processes: `ps -ef` - [query Wikipedia over DNS](https://www.commandlinefu.com/commands/view/2829/query-wikipedia-via-console-over-dns): `dig +short txt unix.wp.dg.cx` - combine this with some pipes and file redirection! - `curl -L _ $(dig +short txt unix.wp.dg.cx | awk '{ sub(/.*http/,"https"); sub("\"", "?action=raw"); print}') | more` - `say` (bonus points if you connect to a remote machine via ssh) 4. IDEs (VSCode) What is an IDE? - IDE = Integrated Development Environment - All the things you need for development processs in one place - text editor - compiler(s) - debugger - syntax highlighting - etc. - Ex: Eclipse, JetBrains (IntelliJ, PyCharm, etc.), Visual Studio Code Why VSCode? - fairly minimal => not too complicated, easy to learn - many productivity enhancements - I use it (so I can teach it) - I also recommend it Open VSCode normally, or through terminal (`code [directory]`) Use keyboard to do things! - faster than mouse - learning shortcuts is an investment: take the time to learn 5-10 now, and you will save HOURS in this course alone - [mac](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-mac.pdf) - [windows](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf) - [linux](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf) Cmd + P to open Command Palette - start typing a file name to open that file (much easier than file explorer!) - search for a function with `@` - ... or go to a specific line with `:` (can also use Ctrl + G outside of cmd palette) - Run a command with `>` - ex: `> Shell Command: install 'code' in PATH` - this is how I can open VSCode from my shell! Other Productivity Tips: - No autosave => use Cmd + S - Open up a terminal in VSCode with Ctrl + Shift + ` - Comment out a block of code by highlighting it and typing Cmd + / - exploring function calls: - hover over function with your mouse to see definition, documentation (if it exists) - F12 or Cmd + click to go to definition - Shift + F12 or right click to go to all references - don't ever use Ctrl + F again! - rename symbol (all instances) with F2 Version Control: - You should definitely familiarize yourself with git cli - BUT: VSCode can be nice too - Source control panel will display: - status of remote (i.e. are there changes you need to fetch?) - any modified/staged/untracked files (not included in .gitignore) - click on one to display a side-by-side comparison of your commited version and your working copy - You can easily stage or unstage files - Or undo unstaged changes (this is clutch, and much easier than working with the cli) - You can even commit with a message and push, although I recommend doing this from the cli - Anything more advanced will probably have to be through the cli - Can download git graph plugin - but it is similar to `git lola` My setup (for these labs): - VSCode - With terminal open - two tabs: 1. Docker (to make, run, test, and grade my code) 2. normal shell (to `git add`, `commit`, `push`) Give this a shot, but find what works best for you!