Making with Code

Terminal Adventure #

This lab will explore one of the most important tools we’ll use all year: the Terminal. The Terminal is what we’ll use to navigate our file system, run code files, install software, and do all kinds of other tasks.

๐Ÿ‘พ ๐Ÿ’ฌ Windows Users

Windows users should use Powershell wherever it says Terminal.

You may see more information output than your Mac peers, but all commands should work the same.


[0] Setup #

First, we want to make some folders to store our work. Do this we’ll be using these three commands:

CommandWhat it does
lsList what’s in the current directory (folder).
mkdirMake a new directory (folder)
cd folderGo to folder
cd ..Go up one to the previous folder

๐Ÿ’ป Open Terminal and use ls to list out all the files at your current location.

ls

๐Ÿ‘€ You should see something like this.

Applications         Downloads            Pictures
Creative Cloud       Library              Public
Desktop              Movies
Documents            Music

๐Ÿ’ป Then, use cd to change directories to your Desktop. A directory is just a fancy word for a folder.

cd Desktop

๐Ÿ’ป Use the mkdir command to make a directory called making_with_code.

mkdir stands for make directory.

mkdir making_with_code

๐Ÿ’ป Use ls to check the folder was created.

ls

๐Ÿ’ป Use cd to enter your new making_with_code directory.

cd making_with_code

๐Ÿ’ป Make a unit00_drawing directory. This will store your files for our first unit.

mkdir unit00_drawing

๐Ÿ’ป Go into the unit00_drawing folder

cd unit00_drawing

๐Ÿ’ป Run the following command in your terminal to clone today's lab. This will make a copy of the code on your own computer. This uses something called git and Github, you will learn more about this later this unit.

git clone https://github.com/the-isf-academy/lab_terminal_adventure.git
๐Ÿ’ป Go into the lab_terminal_adventure folder
cd lab_terminal_adventure

๐Ÿ’ป Next, we enter the Poetry shell. This will ensure all of the correct packages and versions of those packages are being used.

You will use poetry shell, everytime you want to work on a lab or project.

poetry shell

You should see the following output:

Creating virtualenv lab-00-terminal-adventure-shGU1wL6-py3.10 in /Users/eqbrown/Library/Caches/pypoetry/virtualenvs
Spawning shell within /Users/eqbrown/Library/Caches/pypoetry/virtualenvs/lab-00-terminal-adventure-shGU1wL6-py3.10
bash-5.1$ . /Users/eqbrown/Library/Caches/pypoetry/virtualenvs/lab-00-terminal-adventure-shGU1wL6-py3.10/bin/activate
(lab-00-terminal-adventure-shGU1wL6-py3.10) bash-5.1$
๐Ÿ‘พ ๐Ÿ’ฌ Exiting the poetry shell

When you want to exit the shell, you can type exit or ^D

๐Ÿ“ Your folders are now all properly setup for cs!


[1] Starting your Adventure #

๐Ÿ’ป If you left the poetry shell, make sure you enter it again.

poetry shell

๐Ÿ’ป Let’s have a look at what’s in the lab_terminal_adventure repository with ls. A repository is just a fancy word for a folder that is stored in the cloud using a version control software.

ls

You should see the following output:

adventure	    returnToShip.py  poetry.lock	pyproject.toml

returnToShip.py is a runnable Python file (you can tell by the .py at the end).

๐Ÿ’ป Run it to see what happens:
python returnToShip.py

You should see the following output:

Your adventure has only just begun. You are not yet ready to return
to the ship. More secrets await you in the ocean's depths.
๐Ÿ‘พ ๐Ÿ’ฌ Your challenge is to see if you can get the treasure, using just the Terminal

Use Terminal to explore the contents of the adventure directory.

๐Ÿ’ป Begin by going into into the adventure directory:

cd adventure
ls

You should see the following output:

seafloor	sinking.txt

sinking.txt is a text file, so we can read it.

๐Ÿ’ป Try using the cat command:

cat sinking.txt

๐Ÿ’ป Continue exploring into the depths of the sea to find the treasure! Return to the lab_00_terminal_adventure directory and run the returnToShip.py file to see if you were successful. If you were unable to escape the monster, try again!


Terminal Commands #

Below are some Terminal commands which might come in handy on your adventure.

ย  ย  ย  ย  Command ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย What it does
lsList what’s in the current directory.
cd ~Go to your home directory
cd folderGo to folder
cd ..Go up a level in your directory system.
open file.txtOpens file.txt with its default program
cat file.txtPrints out the contents of file.txt
python x.pyRuns the Python program x.py
mv old.txt new.txtRenames a file from old.txt to new.txt. Also works for directories.
mv file.txt dirMoves a file to directory dir.
mv dir1 dir2Moves dir1 to dir2 or renames if dir2 doesn’t exist.
mv dir1 ..Moves dir1 up a level in your directory system.
cp old.txt new.txtCopy a file from old.txt to new.txt.
mkdir bagCreates a new directory called bag
pwdPrints the path to where you are in the filesystem
rm file.txtremoves (deletes) the file file.txt
rm -d dirremoves (deletes) the directory dir
rm -r dirrecursively removes (deletes) the directory dir and all subdirectories and files within that directory. Be careful, this is a powerful tool!

[2] Deliverables #

โšกโœจ You will end this lab by collecting the treasure!

โœ” Once you’ve successfully completed the adventure be sure to fill out this Google form.

๐Ÿ‘พ ๐Ÿ’ฌ Exiting the poetry shell

Remember, when you want to exit the shell, you can type exit or ^D


[3] Extension #

๐Ÿ’ป Once you finish the Terminal Adventure, you may either explore Vim OR continue exploring drawing with the Python Turtle library.

Vim #

Vim is text-editor that you can use to write code directly inside your Terminal. Ms. Brown or Ms. Genzlinger may have used vim to activate Poetry on your computer.

๐Ÿ’ป To learn vim, in your Terminal type:

You can create a new tab in your terminal with โŒ˜+t

vimtutor

Vimtutor is a built in tutorial for learning vim.

Python Turtle #

๐Ÿ’ป Go to bit.ly/day1_cs9 and continue experiementing with Python code. Can you figure out how to: