Skip to content

Commit

Permalink
feat: include 'repositories' in samples
Browse files Browse the repository at this point in the history
Also rename 'playground' to samples.
  • Loading branch information
dwmkerr authored Jun 19, 2021
1 parent 864c580 commit 8aa34cf
Show file tree
Hide file tree
Showing 57 changed files with 173 additions and 97 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# The 'website/public' directory is an artifact created during the build process.
website/public

# The 'artifacts' directory is where we keep any build artifacts. As they are
# built from the repo code we don't need to track them.
artifacts/

# Folders which might be created by IDEs or other editing tools.
.idea/
.DS_Store
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ curl effective.sh | sh

Or can also manually download them using from any of these locations:

- [https://effective-shell.com/downloads/effective-shell-playground.zip](https://effective-shell.com/downloads/effective-shell-playground.zip)
- [https://effective-shell.com/downloads/effective-shell-playground.tar.gz](https://effective-shell.com/downloads/effective-shell-playground.tar.gz)
- [https://effective-shell.com/downloads/effective-shell-samples.zip](https://effective-shell.com/downloads/effective-shell-samples.zip)
- [https://effective-shell.com/downloads/effective-shell-samples.tar.gz](https://effective-shell.com/downloads/effective-shell-samples.tar.gz)

## The Website

Expand Down Expand Up @@ -67,10 +67,11 @@ make build

The built site is generated at `./website/public`.

Note that the [`effective-shell-playground`](./effective-shell-playground) folder is automatically zipped up and added to the website, meaning it can be downloaded directly from:
Note that the [`samples`](./samples) folder is automatically zipped up and added to the website, meaning it can be downloaded directly from:

```
https://effective-shell.com/downloads/effective-shell-playground.zip
https://effective-shell.com/downloads/effective-shell-samples.zip
https://effective-shell.com/downloads/effective-shell-samples.tar.gz
```

### Updating the Theme
Expand Down
16 changes: 9 additions & 7 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ setup:
serve:
cd website && hugo server --baseURL "http://localhost/" --buildDrafts -v --debug

# Build the site.
# We also create a zip and tar.gz of the playground/samples folder for quick
# downloads for the user. We put the current version in the playground folder
# as well for reference.
# Build the site, including the downloads directory. This requires that we also
# run the 'build-samples.sh' script to zip and tar the effective shell samples.
# The build recipe also tests that the samples files are created in the downloads
# folder as if we don't have them we should definitely not deploy.
.PHONY: build
build:
mkdir -p website/static/downloads
cp version.txt ./effective-shell-playground/.version.txt
zip -r website/static/downloads/effective-shell-playground.zip ./effective-shell-playground
tar czf website/static/downloads/effective-shell-playground.tar.gz -C ./effective-shell-playground .
./scripts/build-samples.sh
cp ./artifacts/samples.zip ./website/static/downloads/effective-shell-samples.zip
cp ./artifacts/samples.tar.gz ./website/static/downloads/effective-shell-samples.tar.gz
cd website && hugo --minify
test -e ./website/static/downloads/effective-shell-samples.zip
test -e ./website/static/downloads/effective-shell-samples.tar.gz

# Create the summary structure in word format, easier to share.
.PHONY: structure
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ stringData:
EOF
```

The first line is using a 'heredoc' to write multiple lines of text to a file. We see heredocs in detail in a later chapter. The file is also in the playground at `templates/secret.template.yaml`.
The first line is using a 'heredoc' to write multiple lines of text to a file. We see heredocs in detail in a later chapter. The file is also in the samples at `~/effective-shell/templates/secret.template.yaml`.

Now let's apply our substitution:

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions scripts/build-samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env sh

# build-samples.sh
#
# This file builds the 'samples' folder. Means it will:
#
# 1. Copy all of the files from 'samples'
# 2. Add the .version.txt file to the samples
# 3. Clone the sample repositories, which are hosted at github.com/effective-shell
# 4. Create a zip archive and tar.gz archive
#
# The samples will be created in the './artifacts' folder.

# Fail on errors.
set -e

# Uncomment the line below to trace the script.
set -x

# First, trash the samples folder if it exists in the artifacts folder. Then
# create a new folder based on the current samples.
[ -d ./artifacts/samples ] && rm -rf ./artifacts/samples
mkdir -p ./artifacts
cp -r ./samples ./artifacts

# Copy over the version identifier.
cp version.txt ./artifacts/samples/.version.txt

# Clone our sample repositories. If we have repositories that should not have
# remotes (i.e. for the chapter on getting started with git, where we work with
# a local repository only) we just remove the remote.
mkdir -p ./artifacts/samples/repositories
( cd ./artifacts/samples/repositories \
&& git clone git://github.com/effective-shell/chapter-27-dotfiles \
&& cd chapter-27-dotfiles \
&& git remote remove origin \
)
( cd ./artifacts/samples/repositories \
&& git clone git://github.com/effective-shell/chapter-28-dotfiles \
&& cd chapter-28-dotfiles \
&& git remote remove origin \
)

# Zip up and tar up the samples
zip -r ./artifacts/samples.zip ./artifacts/samples
tar czf ./artifacts/samples.tar.gz -C ./artifacts/samples .

# mkdir -p website/static/downloads
# cd website && hugo --minify
2 changes: 1 addition & 1 deletion structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ This section contains the things which have been pulled out of chapters as they
- `df` to find out free space, or also how to find out how much space a folder takes up
- `open` and similar commands which are used to interface with the host _graphical_ shell
- **Error Codes** and **set -e** are tacitly referred to in the `stderr` sections of the 'thinking in pipelines' chapter, we will need to have a reference
- chapter 4: instead of creating the aliases directly, we should have a `setup-copy-and-paste.sh` script in the playground which sets up these commands as a one liner, then the user can just call the script.
- chapter 4: instead of creating the aliases directly, we should have a `setup-copy-and-paste.sh` script in the `sample` which sets up these commands as a one liner, then the user can just call the script.
- streams: Introduce the concept of streams
- streams: when I pipe from dev/random how do I not run out of memory?
- streams: why are some things linewise (compare `cat` to `sort` to `uniq`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ And we'll see something like this:

![Screenshot: pbpaste in action](./images/pbpaste.png)

Copying is just as straightforward. If you have downloaded the Effective Shell 'playground' folder you can see we have a list of characters from "The Simpsons" in the file `playground/text/simpsons-characters.txt`. Now we _could_ use the `cat` command to show the contents of the file, and then manually select the text and copy it. Even easier though is to just _pipe_ the contents of the file to the `pbcopy` command:
Copying is just as straightforward. If you have downloaded the Effective Shell 'samples' folder you can see we have a list of characters from "The Simpsons" in the file `effective-shell/text/simpsons-characters.txt`. Now we _could_ use the `cat` command to show the contents of the file, and then manually select the text and copy it. Even easier though is to just _pipe_ the contents of the file to the `pbcopy` command:

```sh
cat ~/playground/text/simpsons-characters.txt | pbcopy
cat ~/effective-shell/text/simpsons-characters.txt | pbcopy
```

The output will look similar to the below (I've included the output of `cat` for reference as well):
Expand Down Expand Up @@ -162,7 +162,7 @@ Because we can _pipe_ the contents of the clipboard to other programs, that mean
Let's take another look at the list of characters we have in the `~/plaground/text/simpsons-characters.txt` file:

```sh
$ cat ~/playground/text/simpsons-characters.txt
$ cat ~/effective-shell/text/simpsons-characters.txt
Artie Ziff
Kirk Van Houten
Timothy Lovejoy
Expand All @@ -182,7 +182,7 @@ Helen Lovejoy
We can easily take this text, sort it and then directly copy the results:

```sh
$ cat ~/playground/text/simpsons-characters.txt | sort | pbcopy
$ cat ~/effective-shell/text/simpsons-characters.txt | sort | pbcopy
```

The contents of the clipboard will now contain:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ This chapter will introduce the `wget`, `unzip`, `cp`, `mv`, `rm`, `mkdir`, `rmd

Before we start copying, deleting, moving and renaming files, we should create a 'playground' area we can work in. We don't want to test all of this on our own personal files until we know exactly what we're doing!

To help with this, I've created a zipped up folder which has a lot of files in it which we can use to play with. Now the file itself is available on the [effective-shell.com](https://effective-shell.com) website, right here:
To help with this, I've created a zipped up 'samples' which has a lot of files in it which we can use to play with. Now the file itself is available on the [effective-shell.com](https://effective-shell.com) website, right here:

[effective-shell.com/downloads/effective-shell-playground.zip](https://effective-shell.com/downloads/effective-shell-playground.zip)
[effective-shell.com/downloads/effective-shell-samples.zip](https://effective-shell.com/downloads/effective-shell-samples.zip)

We *could* open up a web browser, download the file, unzip it and then start from there, but this book is all about how to deal with every day tasks in your shell, so let's skip the browser and do it in the shell instead!

Expand All @@ -30,7 +30,7 @@ First, we'll move to our home directory, then download the file.

```sh
cd
wget https://effective-shell.com/downloads/effective-shell-playground.zip
wget https://effective-shell.com/downloads/effective-shell-samples.zip
```

You'll see something like this:
Expand All @@ -45,7 +45,7 @@ As an example, if were not in the home folder, but wanted to download there, we'

```sh
cd
wget -O ~/playground.zip https://effective-shell.com/downloads/effective-shell-playground.zip
wget -O ~/playground.zip https://effective-shell.com/downloads/effective-shell-samples.zip
```

Now that we've downloaded the file, let's look at our home directory now, with a quick call to `ls ~`:
Expand All @@ -59,7 +59,7 @@ Cool - we have the zip file downloaded! Now we need to work out how to unzip it
One of the interesting things you can do in a shell is ask it to tell you more about a file. This can be useful if we've got a file, and we're not sure what it might be. Let's try it out now:

```sh
file ~/effective-shell-playground.zip
file ~/effective-shell-samples.zip
```

<img alt="Screenshot: file" src="images/file.png" width="800px" />
Expand All @@ -73,7 +73,7 @@ Right now we have a zip file. We need to extract it, unpack the files so that we
Run the command:

```sh
unzip ~/effective-shell-playground.zip
unzip ~/effective-shell-samples.zip
```

Now let's look at what we've got with the `ls` command:
Expand All @@ -89,8 +89,8 @@ Now that we've downloaded and unzipped the file, we don't need the zipped versio
The `rm` (_Remove_) command can be used to delete a file. If we run:

```sh
rm ~/effective-shell-playground.zip
ls | grep playground
rm ~/effective-shell-samples.zip
ls | grep samples
```

Then we'll see the following:
Expand All @@ -106,7 +106,7 @@ However one thing it _will_ do to try and help you not make mistakes is let you
Run the following command to try and delete the unzipped folder:

```sh
rm ~/effective-shell-playground
rm ~/effective-shell-samples
```

<img alt="Screenshot: rm error directory" src="images/rm-error-directory.png" width="800px" />
Expand All @@ -117,7 +117,7 @@ Now we can get around this by adding the `-r` flag, which means 'recursive' - i.

# Examining the Contents of a Folder

Let's take a look at what is in the playground. By the way, the output you see on your computer might have a few more files in it as I might have added some after writing this article!
Let's take a look at what is in the samples. By the way, the output you see on your computer might have a few more files in it as I might have added some after writing this article!

In a graphical user interface, we'd open the folders and look at the files. In the shell, we can use the `tree` command to show the contents of a folder.

Expand All @@ -134,15 +134,15 @@ Using a non-universal command is generally _not_ our goal in this book, but in t
Try it out with:

```sh
tree ~/effective-shell-playground
tree ~/effective-shell-samples
```

<img alt="Screenshot: tree" src="images/tree.png" width="800px" />

The `tree` command shows you all of the folders and files in a location. If we are unsure what one of the files is, we can ask the shell to give us more info. For example, I could find out more about the `loas-gch.JPG` file by running:

```sh
file ~/effective-shell-playground/pictures/loas-gch.JPG
file ~/effective-shell-samples/pictures/loas-gch.JPG
```

<img alt="Screenshot: file info for JPEG file" src="images/file-jpeg-info.png" width="800px" />
Expand All @@ -154,13 +154,13 @@ Note that the `file` command is already showing it is a bit more clever. It know
Let's say we really love that photo, and we want to make a copy of it. We can do that easily by using the `cp` (_Copy) command:

```sh
cp ~/effective-shell-playground/pictures/laos-gch.JPG ~/effective-shell-playground/pictures/laos-gch-copy.JPG
cp ~/effective-shell-samples/pictures/laos-gch.JPG ~/effective-shell-playground/pictures/laos-gch-copy.JPG
```

This makes a copy of the file - if you are not sure if it has worked, just run:

```sh
tree ~/effective-shell-playground
tree ~/effective-shell-samples
```

<img alt="Screenshot: cp command" src="images/cp.png" width="800px" />
Expand All @@ -169,10 +169,10 @@ We can see we've made a copy.

# Saving Some Keystrokes

Wow, it's painful putting `~/effective-shell-playground` before everything! From [Chapter 2- Navigating Your System]({{< relref "/docs/part-1-transitioning-to-the-shell/navigating-your-system" >}}) we already know how to change directory, so let's do that now:
Wow, it's painful putting `~/effective-shell-samples` before everything! From [Chapter 2- Navigating Your System]({{< relref "/docs/part-1-transitioning-to-the-shell/navigating-your-system" >}}) we already know how to change directory, so let's do that now:

```sh
cd ~/effective-shell-playground
cd ~/effective-shell-samples
```

Remember - `cd` is _change directory_. Excellent - until we tell our shell otherwise, this our new working directory.
Expand Down
12 changes: 4 additions & 8 deletions website/content/docs/part-2-core-skills/finding-files/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ Searching through a system to find files or folders can be complex and time cons
The `find` (search for files) command is used to search for files and folders and to perform operations on the results. Let's see it in action by running it in the `~/effective-shell` folder.

{{< hint info >}}
**Running the Samples**
**Downloading the Samples**

Each of these samples assumes you are in the `effective-shell` samples folder. If you don't have this folder, just run:
Run the following command in your shell to download the samples:

```sh
curl effective.sh | sh
```
mkdir -p ~/effective-shell
curl -s -L https://effective-shell.com/downloads/effective-shell-playground.tar.gz | tar -xzf - -C ~/effective-shell
cd ~/effective-shell
```

This command will download and extract the samples folder in your home directory and then set it as your working directory.
{{< /hint >}}

Let's set the current working directory to the `effective-shell` folder and run the `find` command:
Expand Down
14 changes: 13 additions & 1 deletion website/content/docs/part-2-core-skills/job-control/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ python -m SimpleHTTPServer 3000

In fact, this is so useful that I normally _alias_ this command, so that I can just type `serve`. We'll see aliases in a later chapter.

Make sure you have the playground folder downloaded, then run the following commands to open the webpage:
Make sure you have the samples folder downloaded.

{{< hint info >}}
**Downloading the Samples**

Run the following command in your shell to download the samples:

```sh
curl effective.sh | sh
```
{{< /hint >}}

Now run the following commands to open the webpage:

```
$ cd ~/effective-shell/websites/simple
Expand Down
Loading

0 comments on commit 8aa34cf

Please sign in to comment.