Skip to content

Commit 20107bf

Browse files
committed
Add posts
1 parent 1fdd16d commit 20107bf

File tree

14 files changed

+1011
-339
lines changed

14 files changed

+1011
-339
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
+++
2+
title = 'Colemak - the slowest way I could write a blog post (for now!)'
3+
date = 2016-01-31T12:22:13-05:00
4+
+++
5+
6+
I am in the process of learning Colemak, an alternate keyboard layout. There are lots of great reasons to do something that seems so masochistic, but it would take too long to type them here (literally). I've gone from ~55 WPM, to about ~15-20, but my goal is ~80 COMFORTABLY by the time I'm done. The top of my right hand especially hurts after prolonged QWERTY use.
7+
8+
A couple guys at work use Dvorak, which I tried to learn in 2005. But as a developer, the punctuation moves killed me so I gave up after a couple of months. Plus, Dvorak was designed without the aid of computers and without any concern for the learning curve coming from QWERTY. Colemak has been easier to learn than Dvorak for me because:
9+
10+
- Only two keys changed hands: E and P
11+
- Only three keys moved far from their QWERTY positions: E, P & Y
12+
- The useless CAPSLOCK key becomes backspace, so you have a way to fix mistakes on homerow
13+
- Only 17 keys moved in total, and only one on the bottom row
14+
- WAY more words can be typed without moving from homerow
15+
- L is more accessible with stronger fingers
16+
17+
The biggest problem for me has been relearning frequent letters like E and S. S has been especially brutal.
18+
19+
Here are the resources I used to make the decision to switch:
20+
- [http://colemak.com/](http://colemak.com)
21+
- [https://thetypingcat.com/course/colemak](https://thetypingcat.com/course/colemak)
22+
- [http://patorjk.com/keyboard-layout-analyzer/#/main](http://patorjk.com/keyboard-layout-analyzer/#/main)
23+
24+
All the online resources suggest learning to touch type over QWERTY keys with the new layout. Hogwash. Last time I put stickers on my keys, and I still touch typed, but didn't get stuck or frustrated nearly so much as I would have without labels. This time, I have (and highly recommend), this: [http://kbcovers.com/colemak-keyboard-cover](http://kbcovers.com/colemak-keyboard-cover)
25+
26+
(this post was not easy to type, so when/if I get better, I'll follow up).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
+++
2+
title = 'Two years of Colemak'
3+
date = 2018-02-24T18:03:00-05:00
4+
+++
5+
6+
![Colemak](https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/KB_US-Colemak.svg/800px-KB_US-Colemak.svg.png)
7+
8+
It's been more than 2 years since I learned to type using [Colemak](https://colemak.com/), and I am still happily using it. I have nearly no interaction with QWERTY aside from my phone, the occasional shared machine where I can't use my AutoHotKey mappings, and the meaningless default letters on all the keyboards I use but never look at. I never actually achieved my goal of 70 WPM, but I also never really properly trained for speed. But, I can typically type all day with no back of hand pain, and that was reason numero uno! Although, it should be noted that I also switched to a [trackball](https://www.amazon.com/Logitech-910-001799-Wireless-Trackball-M570/dp/B0043T7FXE/ref=sr_1_3?s=pc&ie=UTF8&qid=1519510748&sr=1-3&keywords=trackball) so I cannot fully attribute my lack of RSI pain to Colemak. I now touch type with all ten fingers, rather than my gimpy QWERTY variant that I self-taught in 2nd grade when my fingers were too small for home row on the keyboard. I'm not really sure why it's taken me two years to blog a follow up about this (more about my poor blogging habits than my typing ability, I can assure). I was pretty solidly proficient in my Colemak adjustment by month 2 of my transition - by March 2016 I was up to a passable 40 WPM. But those were two brutal months. Absolutely brutal.
9+
10+
Some notes about what I learned/now know/struggled with:
11+
12+
- I like that [the transitional Tarmak layouts](https://forum.colemak.com/topic/1858-learn-colemak-in-steps-with-the-tarmak-layouts/https://forum.colemak.com/topic/1858-learn-colemak-in-steps-with-the-tarmak-layouts/) are available for learning, but for me it was all or nothing. I never used this method because getting proper touch typing technique down made the experience different enough from QWERTY that I learned quickly and did not confuse which layout I was in.
13+
14+
- Having [a labeled keyboard cover](http://kbcovers.com/colemak-keyboard-cover/) helped immensely, especially when it came to passwords. Without this, I would not have been able to switch wholesale and learning would have taken much longer. While I no longer need the labels, having the cover is still really nice, and I have bought multiple over the past two years. Plus, sometimes you are lounging on a couch and not wanting to deal with proper form. Labels mean I can be sloppy occasionally if I want to.
15+
16+
- Microsoft Windows is pretty hostile in its lack of Colemak support compared to MacOS. Thankfully my home and work machines are all Macs, but I get around okay in Windows with the help of [AutoHotKey](https://colemak.com/AutoHotKey). My [config is here](https://github.com/mattmc3/keyboard-tools).
17+
18+
- The "r" and "s" placement was **by far** the most difficult part of my transition. Moving the "s" into the QWERTY "d" position meant that I was always hitting "r" accidentally when I meant "s". I was still doing that sometimes for a good 6-8 months into my learning process - well beyond where I was proficient with everything else. I have thought many times about just swapping those two keys.
19+
20+
- At two years, unfortunately I average about ~65 WPM, which isn't too far past my pre-Colemak speed on QWERTY. I peak much higher than I ever did with QWERTY at ~85 WPM bursts, but my average is sill brought down by mistakes and inconsistencies. Also, I was never the best speller. I'm more a numbers guy.
21+
22+
- I did not lose any speed typing on my QWERTY phone, but I did wish I had a good iOS Colemak keyboard in the early days, if for nothing else to give me the exposure to help me memorize Colemak placement. There are a few, and [this was the best one I found](https://itunes.apple.com/us/app/tempest-keyboard/id920849876?mt=8).
23+
24+
- On the rare occasion where I have to type QWERTY on someone else's machine in front of them, I feel gimpy and could never achieve anywhere close to my prior typing speed. The less I use QWERTY, the less I can go back to it.
25+
26+
- I learned that there is a lot of help, blogs, and interesting info [in forums](https://www.reddit.com/r/Colemak/), or even [chat rooms](https://discordapp.com/invite/sMNhBUP). But truthfully, I learned way more by just [practicing](https://thetypingcat.com/typing-courses/basic/lesson-1) and doing what worked for me than from all the advice. Each learner has their own path.
27+
28+
- I do not regret switching at all, but I also do not find myself actively recommending to others that they switch, nor do I find that I push Colemak over other options like Dvorak. In fact, I often find myself talking about <a href="http://mkweb.bcgsc.ca/carpalx/?partial_optimization" target="_blank">smaller swapping options</a> or even <a href="http://www.minimak.org/" target="_blank">Minimak</a> because truly - almost ANYTHING is better than QWERTY. <a href="http://mkweb.bcgsc.ca/carpalx/?worst_layout" target="_blank">QWERTY does manage to beat one purposely awful layout</a>, so I guess it could have been worse. But not much.
29+
30+
- QWERTY is soooo bad. So bad. <a href="https://blogs.msdn.microsoft.com/ashleyf/2013/03/30/colemak/" target="_blank">Check out these heat maps</a>. Or, <a href="http://patorjk.com/keyboard-layout-analyzer/#/main" target="_blank">test for yourself</a>.
31+
32+
- The new layout kept me from using vim/neovim for a really, really long time. Vi, being a modal editor with both mnemonic AND positional keys like HJKL for movement was too much to manage while learning. Had vim been my primary editor, I probably would not have even switched from QWERTY. The switch was painful enough without blowing use of [my favorite editor](https://www.sublimetext.com/) out of the water.
33+
34+
- With Colemak, everyone talks about inward rolls and two-letter combos called _bigrams_ and all these nerdy concepts that are pretty techno-babbley, and that's fine. For me, as a beginner, no argument was as compelling as the simple "Wheel of Fortune" argument - remember RSTLNE? The most common consonants plus a vowel? Well, the 10 most common English letters are actually [e-t-a-o-i-n-s-r-h-l-d](http://letterfrequency.org/). Have a look at the Colemak home row: a-r-s-t-d-h-n-e-i-o. They are all there on home row with Colemak! There are so many words you can make without even leaving home row. Since your fingers will spend most of their time there, it is so comfortable to type.
35+
36+
- [Optimized bigrams](https://geekhack.org/index.php?topic=67604.0) and [inward rolls](https://forum.colemak.com/topic/1645-rolls-vs-hand-alternation/) are super nerdy concepts, and I never understood how awesome they are until I was more fluent in Colemak. Now that I am I appreciate how Colemak handles them so much. The joy and comfort of Colemak typing has not worn off. [And I'm not the only one](https://www.reddit.com/r/Colemak/comments/5957yz/barstool_is_a_really_fun_word_to_type_in_colemak/). Barstool. Barstool. Ahhh.
37+
38+
So... would I switch if I had it to do over again? Absolutely. Would I choose Colemak? Pretty sure I would, though I am jealous of [how much better Dvorak is supported](https://superuser.com/questions/548441/how-do-i-get-dvorak-keyboard-layout-on-windows) and [evangelized](http://www.dvzine.org/). [All](https://arstechnica.com/gadgets/2014/03/my-quest-to-learn-the-dvorak-keyboard-layout-part-1/) the [good](https://arstechnica.com/gadgets/2014/04/readers-react-to-my-quest-to-learn-the-dvorak-keyboard-layout/) [articles](https://arstechnica.com/gadgets/2014/04/my-quest-to-learn-the-dvorak-keyboard-layout-the-grand-finale/) [are](https://arstechnica.com/gadgets/2014/05/storing-two-keyboard-layouts-in-your-brain-at-once-its-possible/) [Dvorak](http://infohost.nmt.edu/~shipman/ergo/parkinson.html) [related](http://www.dvzine.org/). Are you thinking I am absolutely crazy, or are you thinking of switching? Both?
39+
40+
[The best argument I have for you is that if you are a programmer, you are a typist first](https://blog.codinghorror.com/we-are-typists-first-programmers-second/). For me, making myself a better and more efficient typist pays me back in comfort and longevity. Did I get as fast as I thought I would? No, so maybe that's not worth it to you if that's your goal. But as for RSI, anecdotally I can put a big fat check in that box. [Now, off to work on typing speed some more](http://zty.pe/).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
+++
2+
title = 'Better shell aliases in git'
3+
date = 2024-07-01T05:29:58-04:00
4+
+++
5+
6+
# Better shell aliases in git: adding an external shell script
7+
8+
10 years ago, I read [this blog post on GitHub Flow git aliases](https://haacked.com/archive/2014/07/28/github-flow-aliases/) by Phil Haack. From it, I learned a few really clever tricks. Even though I never much cared for using 'GitHub Flow' as a git workflow, I used some of those tricks for my own git aliases. One of those being this basic pattern:
9+
10+
```
11+
[alias]
12+
foo = "!f() { echo foobar; }; f"
13+
```
14+
15+
This lovely little mess of an alias embeds a one-line shell function tersely named "`f`" directly into a git command. [From the git manual](https://git-scm.com/docs/git-config): "if the alias is prefixed with an exclamation point, it will be treated as a shell command". [Other sources around the same time](https://www.atlassian.com/blog/git/advanced-git-aliases) also began promoting that same trick.
16+
17+
That trick opens the door to let you create clever aliases like [`git browse`](https://haacked.com/archive/2017/01/04/git-alias-open-url), which navigates to the remote URL of your repo in a web browser. The one Phil published is very Windows/Git Bash specific, and it doesn't work for repos cloned with the `[email protected]:my/repo` form, so I modified it in my config to become:
18+
19+
```
20+
[alias]
21+
browse = "!f() { REPO_URL=$(git config remote.origin.url | sed -e 's#^.*@#https://#' -e 's#.git$##' -e 's#:#/#2'); git web--browse $REPO_URL; }; f"
22+
```
23+
24+
And now I have this lovely little mess of an alias. Notice that long horizontal scroll? Yeah... that one-liner is about 150 characters long and pretty ugly looking. But it works, so I kept it and moved on. For 10 years I popped useful aliases in and out of my gitconfig, many with this inline shell pattern.
25+
26+
Recently, I stumbled upon an [Oh-My-Zsh](https://github.com/ohmyzsh/ohmyzsh) plugin called [git-commit](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git-commit/git-commit.plugin.zsh) which takes this pattern to a new extreme. It stores the function in a string, and then generates 12 little alias monsters like this:
27+
28+
```
29+
[alias]
30+
build = "!a() { if [ \"$1\" = \"-s\" ] || [ \"$1\" = \"--scope\" ]; then local scope=\"$2\"; shift 2; git commit -m \"build(${scope}): ${@}\"; else git commit -m \"build: ${@}\"; fi }; a"
31+
```
32+
33+
It's really tricky if not impossible to read and understand that. Especially with all the backslash escaping. Now, the authors of `git-commit` aren't intending for that alias to actually be maintained in its `gitconfig` form - it's generated from a string in a script. But even so, forget about changing that easily, customizing it to your needs, or testing it without copy/pasting it into something usable. They even added some extra magic to update the aliases when OMZ updates. I started to wonder why they didn't just include an actual script file (let's call it `omz_git_commit`), and then have the aliases simply call out to that script. If they did that, then most of the craziness goes away, like so:
34+
35+
```
36+
[alias]
37+
build = "!omz_git_commit build"
38+
chore = "!omz_git_commit chore"
39+
ci = "!omz_git_commit ci"
40+
docs = "!omz_git_commit docs"
41+
feat = "!omz_git_commit feat"
42+
fix = "!omz_git_commit fix"
43+
perf = "!omz_git_commit perf"
44+
refactor = "!omz_git_commit refactor"
45+
rev = "!omz_git_commit rev"
46+
style = "!omz_git_commit style"
47+
test = "!omz_git_commit test"
48+
wip = "!omz_git_commit wip"
49+
```
50+
51+
They also wouldn't need to reach out and touch people's gitconfig every time Oh-My-Zsh has a new commit.
52+
53+
## The antipattern
54+
55+
By now you can probably see where this is going - these kinds of complex git aliases become crazy hard to maintain over time. My `gitconfig` became a mess of functions I could no longer read or understand. Add to that the abomination of mixing code and configuration in one file, and I feel like `!f() { echo foobar; }; f` has become a true antipattern. For the occasional one-off, fine. But once I got past a certain number of these aliases at a certain complexity, it was time to refactor. So, what's the better way? Glad you asked.
56+
57+
## My solution
58+
59+
My solution has been to simply create a shell script external to my gitconfig that my git aliases can call. That script needs to be in the shell's `$PATH` for git to find it. With this script I can do more complicated actions without feeling like I have to cram everything into one line. And, it's easy to see what's in that script and read all the code. This git extensions script file can be written as a POSIX script, Bash, Zsh, Fish, Oil, Nushell, Xonsh - whatever shell you want. And, you don't have to convert your git aliases wholesale - you can start just with the ones that reach a certain complexity. Though I do find it easier to have all most of git subcommand handlers in one place.
60+
61+
### Preparing to use your script
62+
63+
For demo purposes, we'll create a simple POSIX script for our "git extensions" called `gitex`. We'll put it in `~/bin/gitex` and make it executable:
64+
65+
```sh
66+
mkdir -p ~/bin && touch ~/bin/gitex
67+
chmod u+x ~/bin/gitex
68+
```
69+
70+
Make sure you have added `~/bin` to your `$PATH`. If you don't know how to do that, consult your preferred shell's documentation.
71+
72+
#### Bash
73+
74+
For Bash, you might need to do something like this:
75+
76+
```bash
77+
echo 'export PATH="~/bin:$PATH"' >> ~/.bashrc
78+
```
79+
80+
#### Zsh
81+
82+
For Zsh, you could add this to your `${ZDOTDIR:-$HOME}/.zshrc`:
83+
84+
```zsh
85+
path+=(~/bin $path)
86+
```
87+
88+
#### Fish
89+
90+
For Fish, you could add this to your `config.fish`:
91+
92+
```fish
93+
fish_add_path --global --prepend ~/bin
94+
```
95+
96+
### Setting up your script
97+
98+
Now that we have our new `~/bin/gitex` script set up, let's make a simple primary function so we can extend our script with subcommands as we add new git aliases.
99+
100+
```sh
101+
#!/bin/sh
102+
##? gitex - git extensions; make git shell aliases that don't suck
103+
gitex() {
104+
# Call the subcommand function if it exists.
105+
if typeset -f "gitex_${1}" > /dev/null; then
106+
local subcmd=$1
107+
shift
108+
"gitex_${subcmd}" "$@"
109+
else
110+
echo >&2 "gitex: subcommand not found '$1'."
111+
return 1
112+
fi
113+
}
114+
gitex "$@"
115+
```
116+
117+
### Extending your script
118+
119+
You can now add new subcommand functions to your `~/bin/gitex` script. Let's add our `git browse` command.
120+
121+
```sh
122+
##? browse: Open web browser to git remote URL
123+
gitex_browse() {
124+
local url=$(
125+
git config remote.${1:-origin}.url |
126+
sed -e 's#^.*@#https://#' -e 's#.git$##' -e 's#:#/#2'
127+
)
128+
git web--browse $url
129+
}
130+
```
131+
132+
And now finally, you can add your new `gitex` aliases to your `gitconfig`:
133+
134+
```
135+
[alias]
136+
browse = "!gitex browse"
137+
```
138+
139+
Hope this was helpful! For people who've been shell scripting for awhile, this is probably all old hat. But for folks who have only just begun to dive into this space and have copy/pasted others' scripts over time, hopefully this is a helpful next step in your shell scripting journey.
140+
141+
### A special note for alternative shell users
142+
143+
If you are a [Fish shell](https://fishshell.com/) user, it can be especially daunting (or at the least, annoying) to deal in POSIX shell syntax. If you want to write your `gitex` script in Fish (or another scripting language), you can easily do that by changing the shebang from `#!/bin/sh` to `#!/usr/bin/env fish` and then writing your script in that language.
144+
145+
For Fish users, there's another alternative. You can, in fact, write Fish functions and assign them to git aliases. POSIX is cross-platform and has a lot of advantages, but if you use Fish you probably know those pros/cons all too well. You can weigh whether any of that really matters to you - that's a whole different article. Let's assume that you, for whatever reason, prefer to write your scripts in a "sensible language" because you want to ["never write esac again"](https://fishshell.com/).
146+
147+
It's as simple as defining your Fish functions (`gitex_foo`, `gitex_bar`, `gitex_baz`, etc), and then add this to your `gitconfig`:
148+
149+
```
150+
[alias]
151+
foo = "!fish -P -c 'gitex_foo $argv'"
152+
bar = "!fish -P -c 'gitex_bar $argv'"
153+
baz = "!fish -P -c 'gitex_baz $argv'"
154+
```
155+
156+
## In conclusion
157+
158+
You can [check out my dotfiles](https://github.com/mattmc3/dotfiles/) if you want to see [my `gitex` implementation](https://github.com/mattmc3/dotfiles/blob/main/bin/gitex). Happy scripting!

content/posts/my-first-post.md

-6
This file was deleted.

0 commit comments

Comments
 (0)