🚀 LAUNCHING A THING TODAY 🚀
My friend @ellane and I are pleased to launch a new mini-course:
🧑💻 Ellane learns the command line 🧑💻
She mentioned this to me a while ago, so we're going to do it live on Mastodon. Here, in this thread. We're thinking of it like a correspondence course.
You can't fit that much in a post, and formatting here isn't great, so the full posts will be on our mini blog at:
commandline.johnnydecimal.com.
We'd love you to follow along.
Ellane and Johnny have a conversation about the command line.commandline.johnnydecimal.com
01. Introduction & goals
On Mastodon, @ellane mentioned that she'd like to 'learn the command line'. What she told Johnny was that she wants to:
- understand what the command line IS
- learn how not to stuff up your machine
- learn what language it speaks
- understand what commands DO, where things go
- what's Homebrew, and why use it and what does it do, and how does it do it?
02. What is the command line?
A very high-level introduction to the command line. What even is it? Why would we use it?
You can click a button because some designer in Seattle designed the program to have a button.
But what if you want more granular control? What if there isn't a button for the thing you want to do?
Then you crack open the command line.
Over to you, @ellane.
Thanks, Johnny, this is outrageously exciting to my aspiring-geeky heart!
So I've done my assignment re- layers of abstraction. Makes perfect sense.
Just like my car's ignition button, I'm aware there's an organised, predictable series of events that take place once the button is pushed. Each event relies on those that came before it (pistons, oil, petrol, etc), but I don't have to think of any of that when I'm buckling up.
Computers be no different!
04. Let me show you around your new car
@ellane Oh good analogy! That's going to be helpful.
Learning 'the command line' is like learning how to drive. But before we can drive, we need a vehicle.
Let me show you around your new car.
commandline.johnnydecimal.com/…
Computers are like cars. Let's head to the showroom and pick you a nice model.commandline.johnnydecimal.com
@canion Even if the first few lessons are too basic for you (as I'm the noobiest of beginners), hopefully starting from scratch will fill in any holes in your foundation.
The level of assumed knowledge in every.single.tutorial. I've found up to this point has roadblocked me before I could get started. This one is my first experience with a teacher who is patiently explaining things from the very VERY foundational beginnings. Loving it so far!
@johnnydecimal
Homework assignment part 1: Figure out how to make it so that when you type `logout`, the window closes.
I poked around in Settings, and found an option under Shell called `When the shell exits`. The default behaviour was `Don’t close the window`, which was just the clue I needed! As I’d hoped, `Close the window` was also an option in the drop down list.
#LearnCLI (1/3)🧵
Homework assignment part 2: Why doesn’t Johnny like closing the window with the red button?
I couldn’t find a clear answer to this, so here’s my best guess: Using the red button might run the risk of closing the window before a process has completed successfully, leading to problems. Is it like leaving the car in a gear other than Park before turning it off? (2/3)🧵
@Ellane W
My theory was just that it was a GUI (Graphical User Interface) element. Part of the Terminal app, but not actually part of the command line.
I didn't even think about interrupting a running process 😆
@Johnny ‘Decimal’ Noble
06. The structure of a command @ellane
Commands are all structured in the same way. They all follow one of a few patterns. When you learn those patterns, you learn the syntax of _all commands_.
We know that `pie lunch cook` isn't a valid sentence, even if we're not a chef.
And soon you'll immediately recognise that `--food pie &meal lunch cook` couldn't ever be a valid command: it just doesn't _look_ right.
commandline.johnnydecimal.com/…
Our first look at the fundamental structure of a command.commandline.johnnydecimal.com
Okay, this feels like progress! I cd'd myself to the Documents folder on the first go, by typing in `cd Documents`, and used `ls` to see the list of items in that folder. Did the same with the Downloads folder, and was reminded (again) that I really need to clear that one out. I tried a number of things to `cd` to a specific nested folder, with no luck.
One of my attempts had an alarming result:
#LearnCLI (1/2) 🧵
When I could see the folder I wanted to `ls` in the `ls` of its parent folder, I typed `view [name of folder]`.
I should have known better than to experiment with unknown commands!
That gave me a blank page with a `1` at the top, and the word `Insert` at the bottom. Logout didn't work, so I committed the press-the-red-dot-to-close-the-window sin. No more jumping ahead of the teacher for me! (2/2) 🧵
I had no idea what `view` did, by the way. Had to type it to see, at which point I realised it was a synonym for `vim`.
You learn something every day…
And you did the right thing hitting the red button aka the ejector seat. 👍
08. File paths @ellane
File paths are core to this whole experience: many things you do involve a file, or being in a specific folder before you take an action. So let's go a bit deeper.
This lesson introduces ~, ., .., and /. Tiny symbols but they mean so much!
We also talk about relative vs. absolute file paths.
commandline.johnnydecimal.com/…
How do we get around the file system if the folder we want isn't a direct subfolder of where we are?commandline.johnnydecimal.com
I’ve managed to change directory to pretty much everywhere, which is cool! Got a bit carried away trying to see the contents of a folder quite deep in multiple subfolders, and got a **zsh: permission denied** message. This was puzzling until I realised I’d forgotten to preface the path with a command! (1/2)🧵
10. Escape arguments, completely.
By trying to `cd` to a folder with a space in it, you've accidentally given that command two arguments.
So let's talk about **arguments** and what they are. Then I'll show you two ways to get round this problem without renaming_every_folder:
1. Escaping with `\`.
2. Tab autocompletion.
The first is something you need to know. The second is something you'll actually use!
commandline.johnnydecimal.com/…
The CLI doesn't handle spaces in file names very well. We use 'escaping' to work around it.commandline.johnnydecimal.com
Escape Arguments Homework:
I successfully `cd`d to “A_folder_in_quotes” by typing `cd \”A` and then pressing <tab>
Then I navigated to a folder with word spaces inside my Obsidian vault, which is nestled four folders deep (don’t judge), and pressed <tab> to auto complete its name, which is ALL THE NOTES. Terminal completed the string like this: `cd ALL\ THE\ NOTES`. (1/4)🧵
If I was typing it I’d have initially thought to put the backslash close to the next word, but now I can see that it’s immediately preceding the word space, which is the thing we need to escape.
I tried to `cd` to the this/that folder two ways: `cd this\/that` didn't work (and I don't know why), while `cd “this/that” ` did. (2/4)🧵
Look at this one more closely!
It should be `this\that` — the same backslash that you use for the escape character.
The puzzle is: how do you include the escape character in an argument _if it’s the escape character?_
Question: is case important? It doesn’t seem to be. I’ve noticed that `cd Desktop` returns `ellane@macbook-pro Desktop % `, while `cd desktop` returns `ellane@macbook-pro desktop %`. It’s the same location each time, so I’ll assume location names aren’t case sensitive unless you tell me otherwise.
One more question: what’s `ttys000`? And why the % sign? I seem to remember a $ sign being there last time.
`Last login: Mon Jun 3 13:29:54 on ttys000`
`ellane@macbook-pro ~ %` (3/4)🧵
It’s good to learn the why behind things that look different to my GUI-trained eyes.
I used to view things like slashes that went the wrong way and underscores between words as tech-virtue signalling: We’re More Technical and Clever Than You So We Wrap Things In Extra Bits Because We Can. Seems silly now! (4/4)🧵
12. Case-sensitivity, ttys, and the prompt.
There’s a bit of feedback here, so I’ve made one post addressing these questions. And in the next post we’ll continue with the concepts.
Case-sensitivity: is your macOS case-sensitive? (A: kinda.)
ttys000: what is it? (A: 1800s technology.)
% vs. $: why? (A: style. 🕺🏽)
13. Flags and options.
We almost understand the syntax of a command. To recap, we've met the command, and its (often optional) arguments.
Now let's meet flags and options, which are two sides of the same coin. They modify the _behaviour_ of a command.
commandline.johnnydecimal.com/…
The final piece of the command puzzle, we introduce 'flags' and 'options'.commandline.johnnydecimal.com
Interesting podcast excerpt, thanks. It’s good to know about Macs having a different approach to case than other systems. Seems to me if we’re going to err, it should be on the side of precision—so I’ll play it safe by treating everything as case sensitive from now on.
Thanks for explaining the `ttys000`. I figured it wasn’t something I *needed* to know, but having that confirmed saves me from the distraction of wondering what it is every time I see it. (1/3)🧵
Just to check, I opened another window and yep, it said `tys001`.
I played with `ls -la` for different locations on my hard drive, and the `--color=always` one, too. The latter produced mostly one colour, with splashes of another here and there. I suppose we’ll get to the logic behind that later, if it’s important enough to discuss.
When displaying `ls -la` there’s a column on the left with information like `drwxr-xr-x@` that I don’t understand. (2/3)🧵
@natedunnmi I assumed that code would only recognise the US spelling, color, so that's the one I use.
…Just tried it out, and 'colour' is an unrecognized (not unrecognised) option.
@johnnydecimal
As with the colour, we’ll either get to that later or it’ll turn out to be something else I don’t need to worry about.
Referring to the `ls` information at ss64.com/mac/ls.html, I tried `ls-F` as a shorter way of writing `ls -F`, but it returned an error: `zsh: command not found: ls-F`.
Okay. Commands, flags and options, arguments, in that order. Got it. (3/3)🧵
Hi both, just wanted to say thank you for this open and transparent communication about this learning experience!
I work in IT for some time and its not only a great reminder on how things work but also how many things are logical and others are ambiguous and sometimes confusing. 🙏😌
15. Less is more.
Let's learn how to view plain text files. Do you have any of those handy?
Oh wait.
---
Then we'll use this same skill to explore the system's built-in 'manual pages', which are more up-to-date than the web link I sent you last time.
These pages are a treasure-trove of information. They tell you, in great detail, how to use any command.
This one has taken me a while to work through, lots to take in.
Firstly, why *yes*, I do happen to have a plain text file or two handy! And I note that .md seems to fall under the .txt umbrella. Nice.
These exercises began with the frustration of it taking me what felt like an age to navigate to a folder with text files long enough to work with. Autocomplete didn’t seem to be working so I reviewed the lesson on that topic. Great! Clear on that at last. Until… (1/9)🧵
…I mistakenly pressed tab to summon auto complete with one quote mark at the beginning of a word—it’s obvious I should have omitted it, but now I’ve got `[dquote>` and I don’t know what to do with it. None of the commands I’ve learned thus far helped (including `logout`, `q`) so I closed the window with the red corner dot and opened a new one.
Is there a way to create a bookmark, a shortcut, to get to a deeply nested folder? Please say yes! (2/9)🧵
Righteo, that `h` brings up shortcuts in the file viewer. Is this a file viewer, or a File Viewer? In my mind the former would be built-in, a CLI system-wide way of navigating a file, whereas the latter would be one flavour, like an app.
Is Control-E the same as Control-e? When I see an upper case letter in a CLI context it feels like pressing Shift is implied. So would Control-E actually be Control+Shift+E, or is it case insensitive? Like Command-S on the Mac, for Save. (4/9)🧵
OK, here @ellane asks about Control-E vs Control-E, and @johnnydecimal settles on the side of "not case sensitive."
But in the previous lesson, "Less Is More," in learning how to navigate a text file with search, "To find the next instance of the same search, hit `n`. The previous, `N`."
Isn't that an example of case sensitivity? Or is that a rare exception? Seems akin to "`tab` to move forward, `shift-Tab` to move backward" in many forms... 🤔
@natedunnmi Feels like a default that the community has settled on over the years.
Control-[CHARACTER] = not case sensitive, i.e. Ctrl-n doesn't do a different thing to Ctrl-N. Therefore, pick a default, which is to express it as a captial. Maybe that's just clearer?
Whereas 'n' to go forward vs. ‘N' to to back, they're two different commands.
'n' without shift does one thing. 'n' with shift, that is to say ’N’, _does something different_.
Lots of this is just historical decisions…
@natedunnmi Also note how Mac + Windows is explicit about 'Shift'.
Ctrl+E on a Mac, means ‘control and the E key’.
You want a shift in there, you have to say it. 'Ctrl-Shift-E’.
Oh yeah, and look at your menus! Copy = ⌘C. But you don't have to press Shift to get a capital C.
Paste and match style = ⌥⇧⌘V. Needs a Shift, so the Shift is explicit.
Yes, I touch type. 85 wpm on a good day. (It’s such an important skill in my book that I stooped to bribery, offering each of my children a modest cash prize if they could demonstrate it to my satisfaction. All four did, and now as adults they are proficient where many of their peers are not.)
I pressed `/` to search for this string “F..” in my text file by escaping the two periods. So far so good, but… (5/9)🧵
…what I wanted was to be taken to the first instance, and then to the next when I was ready, etc. Searching like this highlighted the right pattern, but I had to scroll through a very long document to find each instance.
I just typed this: “Why doesn’t autocomplete work with the `less` command? Do I really have to type out the full name of the file I want to view?” before realising I’d been pressing `return` after the first part of the name, rather than `tab`. (6/9)🧵
`j` and `k` are much more convenient than searching out the up and down arrow keys. `q` for quit? It was really that simple?? Good to know. I’ve been stuck on pages like this in the past, not knowing how to get out.
If spacebar moves down one full page, is there a command to move back up one full page? EDIT: Forget this one—I found it
I’m seeing character wrapping rather than word wrapping. Is there anything in the Settings to fix this? It disrupts the flow of reading. (3/9)🧵
Until this becomes (new) muscle memory, I can see I’m going to have to slow down and compare what I’ve learned with what my fingers are used to doing.
So. Auto complete worked when searching for a text file to open, but it returned `no such file or directory` until I added the file extension to the name. What’s that all about?
I’m mentally framing this quote: “None of it is difficult; it's just unfamiliar.” (7/9)🧵
The “Convention: indicating flags and arguments” section of this lesson feels like deep water. If you’ve never used any of those options to man, chances are high I never will either.
I’ll leave it here, and spend the next few days playing around with man (oh gosh, the dad jokes around this one must be plentiful!). (9/9)🧵
Lots of feedback! I've done some inline comments and I'll keep the next lesson a separate page for neatness.
Yeah, sorry (not sorry) about that! Sorry you have a lot to go through, not sorry I have questions and comments about it all. This is going to be interesting to go back over and read after it’s all neatly and deeply in my brain.
I’m sure I’ll end up rolling my eyes at the simple things I missed, but there’s an important principle here: Someone can be good at one thing and still need to be in nappies (diapers) for a while in another thing. Thanks for your patience!
Not at all! This is a whole other world here.
In the years running up to 2018 I tried and stalled and tried and failed to start learning some sort of programming language. Started one, stopped. Changed my mind. Started another.
So many times.
The one thing that finally got me was a JavaScript course, sadly now gone*, by a Google engineer. You should have seen how slowly he went.
Pain. Stakingly. Slowly. Like proper baby-steps slowly.
*It was free and now it’s $300/month.
1/5
And that’s what I needed. That was the ah-ha moment.
Now I can do JavaScript, to an okay standard. Nowhere near many people, but good enough for what I need to do.
I still lean on the web. But because I understand the fundamentals, what I find myself needing is the pointer.
I’m in a dark room and you just need to put my hand on the switch. Then I can do the rest myself.
That’s what we’re going for here.
Fundamentals. Deep understanding.
Slowly. Until the light comes on.
2/5
*Also*, it’s my job as the teacher to notice and adapt, but that can be hard as we’re just doing this by text.
So if at any point you think we’re going too quickly, please say so.
If there’s a concept that needs to be reinforced, re-explained, whatever: tell me.
3/5
I just realised something! You have access to Learn Excel with Lucy.
Re-watch ‘Functions & Formulas’, and in pt. 2 pay close attention to the TEXTJOIN function.
_Syntactically_ it’s totally different to the CLI.
_Conceptually_ it’s **identical**.
- What’s the command?
- Does it have flags?
- Does it have options?
- Does it take arguments?
This is the thing about computers, and languages: once you internalise the _idea_, the rest is just translation.
4/5
So the job is to train your brain to think in this really un-human way.
You’re becoming a programmer. The CLI is just a computer to be programmed.
Excel or the CLI. It doesn’t matter.
(For anyone following along, I’ll make that lesson free in the next couple of days and edit this post with a link.)
5/5
We use Homebrew to install and remove some stuff.commandline.johnnydecimal.com
Great. Yeah I was going to write a short summary post to reinforce what’s important to focus on and what’s not. I’ll do it here.
Important:
- The basic <command> <flags/options> <argument> idea.
- This is such a massive leap from clicking a mouse.
- We’ll do a LOT more of this over time.
- Viewing a document; getting around inside there.
Not important:
- Any of the specific flags or arguments to any particular command.
- None of the contents of the man pages! Scary nonsense.
Okay, I've reviewed the Formulas and Functions lesson in the Excel course. I love the foundational nature of it! Even though I already know how to create spreadsheets that reference other cells, it was still enormously helpful to have the structure of the process explained in that kind of detail.
I'm ready to go on!
Okay, terribly late on this one, and I still haven’t written a proper post for our little site. But I figure if I just type this at the kitchen table rather than agonising over perfection, that’s probably better.
(I will update the site later.)
So we’re going to ‘pivot’, as we say in the tech industry. I set out to teach you ‘the CLI’, but that’s a _massive_ undertaking, and your actual goal is to ‘learn plain text accounting, specifically hledger’.
Rather than possibly useless…
1/x
…theory, therefore, we’re going to focus on the goal, and cover topics _as required_ on our way to that goal.
In your latest blog post you mentioned that you can read stuff, but you can’t yet edit. So let’s do that now.
Now, this qualifies as a ‘potentially dangerous’ command. Because if you edit the wrong file, you could mess something up! So just make sure you’re in the right place, and maybe create some test files to start.
The command 🥁 is 🥁
pico
2/x
That’s it. You can just type `pico` and it’ll open.
And I’m going to leave you there. Because if you look around, I think you’ll work it out. The hints are all on-screen: see the bar along the bottom.
This is a pretty rudimentary text editor. It’s not the legendary `vim`. But it’s easy to use, and it’ll do the job.
And think about this: once this is all set up, there’s no reason to use the CLI to edit your plain text files. They’re just plain text files.
3/x
You can use whatever you like to edit them. And just dive down to the CLI as required.
But still, I think this is a valuable exercise. So have a play with pico, create a few files, edit a few files, and let me know how you get on.
Next, we’re going to go straight for the hledger installation page. 😬
4/4
Challenge accepted! You’re right about not needing to use the CLI to edit my files; it’s just a vehicle for learning a skill. A mountain to climb, not to build a house on.
I’m looking forward to the next bit! I messed around with installing hLedger last year, but never understood what I was doing, or how to update to the latest version.
Ahah— a challenge for both of us! I've followed your instructions to the best of my ability, and am stuck.
"You can just type `pico` and it will open".
What will open? I managed to use Terminal to create a new file in the location of my choice, but not to open an existing file. If I type `less` I can read the file, but not edit it.
This is the kind of roadblock that would have made me give up in the past—but not now! I'll keep trying to work it out.
Okay, we have two possibilities here.
Just like with any other text editor, you can either:
1. Open it ‘empty’, and start typing a new document, or
2. Open it with an existing document.
It never hurts to have a look at the first line of the man page, `man pico`:
`pico [ options ] [ file ]`
So:
- `pico`, then
- some optional [options], then
- optionally, a [file].
Ignoring the optional options, this gives us two paths... which might sound familiar?…
I did it! Pico is more familiar with its ⌃T commands, but you've introduced me to j and k for moving around, and so I've been spoiled with single letter commands!
So… I jumped off the cliff into vim land. And I like it! With :q! under my belt I'm having fun learning how to navigate a doc. #LearnCLI
Ha! What! This is excellent.
There are many, many fine vim tutorials out there. And really once you’ve got the hang of it, ten commands gets you by.
Next stop: Homebrew. 🚏 Give me a day or so. We’re heading to the National Library to work today, it’s our happy focus place.
Okay, let's turn in the direction of hledger. We're going to install it.
First, we need to install Homebrew. But first: what is it?
# Package managers
We're all used to installing software, and keeping that software up to date.
How do you install and keep updated applications for your Terminal? There are a bunch of ways, but Homebrew has become the de-facto standard for the Mac. Because it's just really nice.
Done. I was held up briefly because there was no visual feedback when typing my password; got it on the second try.
It seems to have worked, as `brew help` is showing me a list of ways to get started. I'll be (wisely) leaving those alone until you help me learn what they're all about.
So the purpose of Homebrew is just to install hledger. How might we do that?
Homebrew's web site is amazing so we might as well double-check. Head over there and search for hledger using the box at the top. You should find yourself on the formulae page for the app.
In this case, the page tells us exactly what we need to do:
`brew install hledger`
Right, so hledger is now installed—or rather updated, as I'd somehow managed to install it ages ago without understanding what I was doing. Took a look at brew.sh/, and I'm starting to feel a little less intimidated by sites like this, thanks to these lessons.
Using the Help documentation I've created the journal file using `hledger add`, and have completed my first entry (!).
Amazing progress!
So I'm going to throw caution to the wind — because it's Lucy's birthday today and I'm required out back to do chicken-related things — and give you the 'move a file' command.
Be careful with this one, because if you move the wrong file to the wrong place, there's no 'undo' in this world.
The command: `mv`, short for `move`.
And the same command serves as a rename! You just 'move' the file from its old name to its new name.
Check `man mv` but it's pretty obvious.
The equivalent to copy a file is `cp`. Maybe create some dummy stuff on your desktop and mess about there for a bit.
When you're sick of that stuff, `rm` (remove) will delete it.
What happens if you try to remove a whole folder? Can you find the (potentially VERY dangerous) flag that allows you to 'recursively' delete an entire folder?
Okay I must be honest and say I've been spending most of my time trying to get hledger to see and work with my newly moved file of transactions. (Which I moved in the regular way this time. It's good to know how to do it the hard way, but I was eager to get to the meat of it).
I'm frustrated that I can navigate to where my file is, but can't get hledger to *do* anything with it! The help files aren't helping.
What is/isn't hledger doing? Is there an error? Or can you post a screenshot?
The goal of this was to get you using hledger so let's focus our efforts there, and what you learn along the way is what you learn.
This is the error message:
hledger: Error: /Users/ellane/.hledger.journal:1:1:
|
1 | ; journal created 2024-07-08 by hledger
| ^
unexpected end of medium
expecting end of input or transaction or directive
I then used your instructions to install something else. `brew install firefox` seemed safe.
1. Homebrew automatically updated itself (a good thing)
2. I don't know how to use these suggested commands `Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE.`
3. Homebrew detected that Firefox is already installed and stopped installation
If Firefox had been out of date, I assume brew would have detected that and updated it?
Nice one!
As a rule, if something's already installed then brew isn't going to want to mess with it. Brew needs to install it so that brew can control it, because files are in different places and were installed in different ways.
So you could remove Firefox and re-install using brew to bring it under its control?
Those SHOUTY THINGS you can ignore.
And you can `brew update` then `brew upgrade` to do a manual upgrade of your installed apps at any time.
You asked what I'd like to learn next, and the main thing is taking the instructions in the hledger docs and applying them to what I've learned so far. I'm struggling a little with what does what.
Now some of these questions will be best put to the hledger forum, but there are some generalities here too. Like recognising when the manual is giving me an argument or a command, and putting it in the right order.
Also, you mentioned showing me how to set 'bookmarks' to save time.
Okay let’s get back on this #LearnCLI horse!
Bookmarks. How do you move quickly to another folder?
1. Define an alias
You can create an ‘alias’ which is like a shortcut. You define <some short thing> which does <some longer thing>.
`alias m='cd ~/Movies'` creates an alias, m, which issues the command to take you to your Movies folder.
So you can create yourself an 'hl' alias, say, which changes you to your hledger folder.
Typing `alias` shows you your defined aliases.
1/x
That's great, but you'll notice that these aliases aren't persistent: close the window and it's gone.
To make them persistent, we need to add them to a file which is run whenever a new prompt is launched.
This introduces your first 'dotfile'. So called because it starts with a dot.
Dotfiles are very common in CLI world. They're universally used as configuration files.
Because your system – including the macOS Finder – hides them by default. So they don't get in the way.
2/x
This particular dotfile is called .zshrc, and it lives in your home folder. So – and I'm _so proud_ that you're using vim – let's edit that.
vim ~/.zshrc
You might already have one with stuff in it. If not, you'll just see an empty file. Either way, add your alias as a new line.
Hint: lines starting with # are comments. So you might add a section like this:
# Ellane's aliases
alias hl='cd ~/some/deep/path/to/hledger'
to keep things neat.
Save that, open a new window, and test.
3/x
While we're in .zshrc, here's another quality-of-life improver that I always add to mine.
Normally when you press up-arrow to search through your history, it's just a dumb list of previous commands.
It's far more useful if you can type the start of a command you know you've previously typed, and have up-arrow search your history. To do that, add these lines:
# Enable history substring search
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward
4/x
And one last hint: rather than having to open a new window every time, you can 'use' your .zshrc in the current window by typing:
source ~/.zshrc
Okay, this is just a quick one but I promise to stick with it now! And what I'll do is let it play out here for a bit, then summarise to the website.
Which, to remind our viewers, is commandline.johnnydecimal.com.
So! Tell me how you're getting on, and what you'd like to do next.
5/5
Ellane and Johnny have a conversation about the command line.commandline.johnnydecimal.com
Oh yeah, and the point of that history thing is that I often find myself typing
cd ~/path/to
and knowing that this is enough to be able to trigger up-arrow, find what I want in history, and away I go.
Can be quicker day-to-day than defining an alias. Although defining the alias is the better thing to do, long-term.
6/5
How I'm getting on is …rather lost!
I've added the lines you suggested for aliases and history search, but don't know how to make them do their thing. (This reminds me that the intuition I've developed for GUIs doesn't apply here—I need different skills.)
What does zsh stand for? If I just see it as 3 letters, it won't stick as a concept. Looking it up on the internet doesn't help as most explainy people think I already know what it *is*, just not how to use it.
And what's the rc for that comes after zsh?
It looks like the next step is helping my CLI to see the .zshrc file.
There are many different kinds of shells, and most end with "sh" (standing simply for "shell") - like sh, bash, csh, tcsh, ksh, dash, fish etc. As far as I know, the "z" in "zsh" is the initial of someones name.
The "rc" stands for "run commands" (although there are different interpretations) and indicates that it is a configuration file.
mupdf is a viewer ...
To create from markdown, you can use pandoc like this :
$ pandoc file.md -o beautiful.pdf
Yes, PDF from Markdown would be good to know how to do but TBH I'm probably not going to use the CLI for that so maybe another topic would be better tackled first.
Where I'm at right now is saving CSV files from hledger with `-o file-name.csv`, and learning more vim. I'm open to suggestions for other things to learn that have an immediate application to this kind of work.
@hyde
for vim if you have a small budget I recommend this book
pragprog.com/titles/dnvim2/pra…
Quickly learn Vim’s core functionality and tackle your trickiest editing and writing tasks to become a more efficient developer--with more than 120 tips.pragprog.com
The book teach VIM a text editor software who allows write and edit text very fast.Internet Archive
I'm pleased to see a way to do this inside the CLI. Thus far I've been creating Keyboard Maestro shortcuts to save keystrokes and it works well, but I like that there's an integrated option outside of apps like that.
So I'm in the .zschrc document (which said it was a new doc, BTW), and have entered the path following your pattern. Testing it in a new window did nothing, however, so now we need to figure out what I did wrong.
It seems odd that the file was created new rather than having already been there. What do you see with
ls -a .zs*
It seems like there should have already been a .zshrc with something in it.
Also, somewhere in the back of my mind is the need to log off and back on for the change to work. Or you can use the command 'source ~/.zshrc' to make the change work I think.
Note: I know nothing about your OS, so I probably should stay out of this. It's just so puzzling.
IIRC modern macOS doesn't come with a .zshrc.
Hmm I wonder ... Ellane, what do you see if you do:
cd ~/.zsh
ls -la
Edit: just realised I have a test user account on this machine that I don't configure. No .zshrc anywhere to be seen. So a blank file was to be expected, Ellane.
Okay so I've got the blank .zshrc file, and have entered my first alias. I'm unclear as to whether the " or ` were supposed to be entered as well. Tried both, neither worked.
I'm seeing zsh: command not found: hl
Try this.
You can see my current aliases there.
Thanks for the vid, I've watched it a few times but don't know what I was seeing. What's lutetium? You typed quotation marks before the cd...?
Sorry I'm not catching on too quickly this time!
Quelquefois c'est frustrant d'essayer d'apprendre une nouvelle langue !
But once you know the vocab, it comes more easily. One piece at a time.
Not sure if you got your answer:
Yes there are quotation marks before the cd and at the end of it. These are around the command that ellane equals.
And on the next screen after saving this, notice that he typed
source .zshrc
That lets the shell see this change you've made. The other option is to log off and then login again.
lutetium is the name of this laptop, so that's just part of my prompt.
The alias I added was:
alias ellane="cd ~/Movies"
(Confusing things by using "double quotes vs. 'single last time. Sorry! But they both work the same.)
Then we exit vim and I 'source' that file to activate the new alias. Or I could have opened another shell.
Because this .zshrc file is run by every new shell on launch. That's what it's for. Hence putting a command in it will make it available in every new shell.
So you'll want to add something like
alias hl="cd /path/to/your/hledger/directory"
Then save, either 'source' the file or launch a new shell, and then
hl
_should_ jump you there.
You can use the `echo` command to test your .zshrc is being executed. `echo` just types out text. Try it:
echo Help I am stuck in the computer!
So you can put an `echo` in your .zshrc and every time you launch a new shell, you should see what you wrote.
I wish you could do syntax highlighting here. It'd be nice to indicate exactly what's a command.
`Backticks`, being used for inline markdown, are often used to delimit the thing to be typed. In almost all cases you should not include them.
Sometimes people (or code blocks on websites) indicate a command with a $ at the front. That represents your prompt and should also not be typed.
(Sometimes when you copy the code block off a website the $ also gets copied! This is wrong.)
Little CLI hint: `history` shows you stuff you've previously typed.
If you want to repeat one of them, `!xx`, where xx is the number before the command, will do that.
Hitting the up-arrow repeatedly will also call back previous commands. There's a nice way to improve this that I'll tell you about later.
A year or so ago I spent a week interacting with my .md notes exclusively in TextEdit (plain text mode), just for the experience. Those raw visuals were a good introduction for becoming familiar with the command line, I now realise.
Wowza, that’s a lot of reading! I scanned through the man page for man itself, and for less. I can see why it’s built in; that’s a lot to remember. Nothing I’m not used to, though. I’m a big keyboard shortcut user in the apps I spend the most time in. (8/9)
I have a question, which is slightly off-topic:
It looks like you have been less technical person in the past? If yes: How do you look on IT and apps, now that you took the red pill and left the matrix?
Do you think that "apps should just do their magic" or that this will help you achieve more? Do you believe that programming or IT Stuff is much more different that you thought and now want to unlearn about the truth?
Im just curious on your perception. 😌
This is a great question. I always thought I was technical, but realise now just how much I’ve been dancing to someone else’s tune. I don’t yet know if I’ll end up writing my own.
This current foray into the command line was sparked by wanting Terminal to do a specific thing I’d heard it could do and realising I was a digital baby all over again, unable to crawl, never mind walk or run.
Re your question on my general attitude to IT, it may be too early to tell.
Thanks for your reply, I fully agree that it will take some more time to fully identify the impact of this exercise.
Needed to ask it early on, it might sit in the back your head so you can tell me closer to the end. 😉🙏
(I started programming as a hobby again after 12 years and I see for myself how the different the world is or how rusty I have become? 😬😅
jut m'y two cents, when you do :
$ cd a\ dir\ with\ spaces
you can also use double quotes:
$ cd "a dir
[tab]And it will expand it to ;
$ cd "a dir with spaces"
This lesson also brought up one of the frustrations I’ve faced in the past when trying to use Terminal.
I’ve pasted in the string I was given (in this case, `printenv`), pressed `Enter,` and a process completed successfully. I then wanted to do something else, but nothing I typed showed up on the screen, even though there was a blinking cursor.
What am I missing? Surely the answer isn’t to close the window and open a new one, is it, but if so, why? (3/3)🧵
Hmm no, this is not normal.
Here's a little video. I type out `printenv`, hit return, see the result, hit return a few times, do it again. This is what should happen.
You're saying after your first screen of results the window becomes unresponsive?
Try typing vs. pasting, though that shouldn't matter.
It was unresponsive yesterday, but worked today. *shrugs*
I found the same thing when trying to use hledger in the past: got in there, but couldn't figure out how to exit.
There's going to be a logical explanation for this behaviour, no doubt, and I'm looking forward to learning more so I don't feel so lost.
Hmm okay let's just keep an eye on that. If it happens again, let me know.
Preparing my response as we speak! Should be there tomorrow.
I’ve managed to change directory to pretty much everywhere, which is cool! Got a bit carried away trying to see the contents of a folder quite deep in multiple subfolders, and saw a `zsh: permission denied` message. This was puzzling until I realised I’d forgotten to preface the path with a command! (1/2)🧵
Something else I’ve noticed is that the CLI does *not* like word spaces. It returns a **too many arguments** message any time I try to access a folder with a multiple-word name. Is there any way around that, or do I have to rename_everything_to_remove_word_spaces?
Rather than renaming, I looked for paths with locations that were one word only and was able to `ls` the contents of the parent folder of the directory I was looking at. So far so good. (2/2)🧵
use quotes. If you do something like :
$ ls "My
[tab]When you press the tab, it will complete the name like :
My folder
My file
Etc ...
@ajlewis2 @ellane
If you have an alias in your ~/.zshrc file like:
alias hl="cd /path/to/your/directory"
you can call it just by its name:
$ hl