username ➜ current_directory (current_branch) $
I work with a Macbook Pro M1 (M1 Pro) from 2021, it’s the first Mac I’ve ever had beside some family computer ten years earlier.
I looked for a Linux-style terminal to replace the default one and went for Alacritty, because I already had experience with it. I also often use the VSCode terminal, because it’s there. Both Alacritty and VSCode terminals have a Cmd-f shortcut to look for a specific string in the output history.
My day to day shells are bash and fish. Everytime I open a terminal it defaults to bash, I often run fish after bash to have autocomplete and better (in my opinion) line editing. I chose fish over zsh because I don’t want to spend time configuring zsh. I have a habit of not using shell plugins, so my shells are pretty barebones.
The only “extension” I use is autojump, my favorite cd
helper
(brew install autojump). I can type j ow to go to the Downloads folder,
j code for my VSCodeProjects folder, you get the idea. Autojump keeps a data structure of
frequently accessed places, no
configuration is needed. jo to open in Finder.App. It even has a fish script (look for
autojump.fish).
I don’t have a need for tmux at this point. I already have a tiling window manager (Amethyst). Of course in a perfect world it would be nicer to have three shells in one window, but for now I’m happy with opening Alacritty one time and hitting Cmd-N twice.
On the bash side, only a few shortcuts come to mind: Control-l, Control-u, Control-w, Control-k and Control-y. Also Control-a, Control-e. Add Control-r (to fetch a command from history).
I reassigned my caps lock key as an Escape key, to make Esc-f and Esc-b easier to access. Esc-t swaps current word and previous word in place. Can’t wait to have a use case for this one.
A very useful one: after moving up in the command history and modifying a past command, Esc-r will reset the changes in place.
Now let’s run fish and see what changes.
Autocompletion works! If it gives you what you want, do not press tab, press the right arrow instead.
After hitting tab if too many results are shown I’ll press Control-s and type search terms.
Moving wordwise is done with Cmd-arrows instead of whatever Bash developers smoked back in 1776.
At this point I noticed that shell shortcuts that uses the Alt (Option) key do not work out-of-the-box
because Alacritty doesn’t send Option as a “Meta key”.
On the other hand, this behavior of Alacritty is why Option+Shift+L gives me a vertical bar, which is still useful. I decided
to rebind
the
shortcuts to the command key instead.
By running the fish builtin bind I got every default shortcut and I
could easily copy and paste what I needed.
# ~/.config/fish/functions/fish_user_key_bindings.fish function fish_user_key_bindings # input a newline character without executing the command bind super-enter 'commandline -i \\n (commandline --search-field >/dev/null && echo --search-field)' expand-abbr # if a completion is available, get the first word only bind super-right nextd-or-forward-word end
So far we have pretty much everything to move around both shells and edit commands effectively. We may miss terminal shortcuts for increasing and decreasing the font size.
I found that the default shortcut for resetting the font size in Alacritty conflicted with a custom MacOS keybinding for taking screenshots.
# ~/.alacritty.toml
[keyboard]
bindings = [
{ key = "Key0", mods = "Command", action = "None" },
{ key = "R", mods = "Command", action = "ResetFontSize" },
]
Next I noticed that Control-z worked fine in every fish session but Control-Shift-z didn’t in VSCode, I had to modify VSCode shortcuts so that it let Control-Shift-z pass through when the terminal is in focus.
I always wondered if there was a way to sudo commands using TouchID, turns out there is.
# add this to /etc/pam.d/sudo auth sufficient pam_tid.so
In the Apple’s Terminal.App, sudo will display a small key icon that can’t be displayed by any other program. This feature doesn’t exist in Alacritty. Enabling TouchID fixes this and provide a faster way to run commands. If you’re super strict you “should” edit the sudo file using the default Terminal, and only then start using sudo in Alacritty.
I also wanted sudo to ask for my fingerprint everytime:
# add this after Defaults env_reset in /etc/sudoers Defaults timestamp_timeout=0
The holy trinity of jobs management: Control-Z, fb and bg. Also
jobs to list the jobs.
nohup is an alternative way of running a background job, because it creates a process that the
parent shell can’t kill when exiting.
Nohup processes still show up in jobs output.
This setup doesn’t give me the freedom of attaching and deattaching processes between terminal sessions. Multiplexers solve this problem but I don’t really need it that much.
Nohup is basically a wrapper around processes which intercepts SIGHUP, when the OS kills the terminal, the subprocess stays alive because of nohup.
When looking this up I stumbled upon transient services, which are a way to make systemd run arbitrary processes
and access them later using the usual subcommands. Stuff like
systemd-run --scope -u my_job_name my_command
followed by systemctl --user status my_job_name.scope or
journalctl --user -u my_job_name.scope -f.
It may be more complicated than that though. The MacOS equivalent is launchd, managed using launchctl. It also
supports
user level services, which could be super useful.
Honestly? nano, vim, and ed. They all come preinstalled everywhere, they're easy and more than enough to change a thing or two in a config file.