migrating to zsh! finally (or: even while my friends sleep, terminal cat keeps me company)

sneak preview

blah blah background

mac defaults to zsh, but i resisted changing over right away.

i had a nice dotfiles automation set up (with my terminal timers complete with a custom fun sound when the timer went off). using (someone else’s script) I could clone my dotfiles repo, run a single shell command, and have all my nice terminal customizations.

plus, i had a nice cat.

well, i have not used tt in a while anyway (i really miss working in linux — once i make a bit more, we’re going back to linux haha. though it’s neat the some of the LLMs can run on mac silicon) since it works so-so on my current macbook — mostly, on macbook you can’t force the terminal to stay on top so the timer gets buried anyway.

I also was really happy with autojump. but I had seen brief glimpses of my friends using zsh and it seemed to have really nice tab-completion.

so, zsh time it is!

okay i’m too lazy to write a true write up so i’ll just document what i did for my own reference.

install oh-my-zsh

i’m not sure why oh-my-zsh, but it seems nice. i think it includes a lot of powerful plugins (downloads and lets you one-line activate them).

https://ohmyz.sh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

out of the bat — git aliases!

i had that in my bashrc manually, but in oh-my-zsh there’s a one-liner.

alias ga='git add'

and already we can see in ~/.zshrc  that we can do

plugins=(git)

and these aliases are included  in oh-my-zsh with that one line!

other oh-my-zsh plugins i enabled:

plugins=(git gitignore 
magic-enter
colorize
colored-man-pages
python
)

and then let’s overwrite that (rip) — use random stranger’s plugin pack

okay but i was missing my autojump, and i realized that there are still some manual steps to install extra fancy plugins. i didn’t want to do some comprehensive understanding of competion, tab completion, autocompletion of commands vs files vs folders, frequency-based or history, etc. i just wanted someone to pick a few. and all the different themes, wow.

hence then I used

https://github.com/gustavohellwig/gh-zsh

which includes zsh-completions and zsh-autosuggestions which are not in oh-my-zsh. (completions is in oh-my-zsh).

sudo curl -fsSL https://raw.githubusercontent.com/gustavohellwig/gh-zsh/main/gh-zsh.sh | bash

powerlevel10k — no need for other themes

most importantly, it includes a customizable theme called powerlevel10k. This actually walks you through creating a custom prompt  in detail — everything from what information you want on the right or left, do you want a timestamp (if so in what format), do you want minimalist or maximalist (with all the icons! and colored backgrounds!), if you want a two line prompt or not, how many colors you want, etc.

it was really cool actually!

p10k configure

after all that I ended up with

╭─ ~/Documents/projects/python_fun on main ········· at 22:48:40
╰─❯

okay but we need cats: editing the p10k prompt

very importantly, i then spent a while figuring out how to add a cat back into my prompt.

thus

vi ~/.p10k.zsh

it turns out an example of adding to the prompt is given in this line, so lets uncomment it

typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( 
[...]
example # example user-defined segment (see prompt_example function below)

way far down we can define it

 # Example of a user-defined prompt segment. Function prompt_example will be called on every 
# prompt if `example` prompt segment is added to POWERLEVEL9K_LEFT_PROMPT_ELEMENTS or # POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS. It displays an icon and orange text greeting th e user.
#
# Type `p10k help segment` for documentation and a more sophisticated example.
function prompt_example() {
# p10k segment -f 208 -i '⭐' -t 'hello, %n'
p10k segment -f 208 -i '<hi>' -t 'ฅ^•ﻌ•^ฅ'
}

So I put in a cat!  hurray! now on the right hand side my cat friend is back 🙂

this is what the cat looks like

 

╭─ ~/Documents/projects/python_fun on main ········ at 22:58:03
╰─❯ <hi> ฅ^•ﻌ•^ฅ

image: even when my friends are asleep … terminal cat keeps me company

(the <hi>  reminds me of old-school chat logs)

fix the python virtualenvironment display

okay, but what is up with the weird python enviroment display?

╭─ Py py311 ~/Documents/projects/python_fun on main 

There’s a random “Py” and the environment name is sort of just thrown in there, grr.

First off, I moved it from the right to the left prompt. It’s the virtualenv  not pyenv for reasons i don’t know yet.

typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
virtualenv
[...]
)

Then I set delimiters around the environment name

 typeset -g POWERLEVEL9K_VIRTUALENV_LEFT_DELIMITER='('
typeset -g POWERLEVEL9K_VIRTUALENV_RIGHT_DELIMITER=')'

I also think it’s handy to have the actual python version, so I’ll try it out, but instead of the “Py” which is super random I’ll use a snake instead.

typeset -g POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION=true 
typeset -g POWERLEVEL9K_VIRTUALENV_VISUAL_IDENTIFIER_EXPANSION='🐍

hurray!

there we have it — a zsh prompt I enjoy 🙂

At first I missed autojump, but after typing a few commands in manually, the completion has been great. Very pleased. will report more later (and I can always install autocomplete).

add oh-my-zsh plugins back

oh right — p10k overwrites your zsh, so we have to add them back in.

╰─❯ vi ~/.zshrc
export ZSH="$HOME/.oh-my-zsh"

[...]

plugins=(git gitignore
magic-enter
colorize
colored-man-pages
python
)

MAGIC_ENTER_GIT_COMMAND='git status -sb .'
MAGIC_ENTER_OTHER_COMMAND='ls -la .'
source $ZSH/oh-my-zsh.sh

explanation of magic-enter plugin config

so basically when you hit enter on an empty line, zsh will automatically put in this command depending on if you’re in or out of a git directory. (either git status or ls -la)

change git icons to be fancier

okay, this is just because I was really confused to have a ?1 in my prompt and i find it funny that the comment mentions exactly this. in ~/.p10k.sh

 # Branch icon. Set this parameter to '\UE0A0 ' for the popular Powerline branch icon.
# typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON='\UE0A0 '

# Untracked files icon. It's really a question mark, your font isn't broken.
# Change the value of this parameter to show a different icon.
# typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='…'

all together now

this is the final result (for now)

note that there is an alias of “..” to “cd ..”,  which seems nice. Also, the very last line you c an see how nice the autocompletion is — I only have to type sou and i can tab complete the entire line.

random bugfix: locale

 I did change “C” to “en” in the following variables to fix an issue with showing examples for bash commands, where I would get a random text “failed to set default locale”.

here’s what i mean by showing examples, I can just type “tar” and hit tab and get this:

specifically I changed in my ~/.zshrc:

export LANG="en_US.UTF-8" 
export LC_ALL="en_US.UTF-8"

bonus: fancy-looking font: fira-code

someone in my past was very excited about ligatures and fancy fonts for coding. most specifically, this font turns !=  into what looks more like while you are typing !

 brew install font-fira-code

well, i don’t think that worked; in the end i downloaded the zip and unziped and opened the fonts.

then i went into terminal settings and set it to use font-fira 🙂

here are some examples of what it looks like. this is what i actually typed

╰─❯ echo 'Example fira-code ! and = is != , > and = >=, = = == => = and = ==, 0 o O lL1

and it shows up like so
here is a video of how the ligatures are rendered on the fly:

 

 

all together now

for reference:

.zshrc

export ZSH="$HOME/.oh-my-zsh" 

[...]

plugins=(git gitignore
magic-enter
colorize
colored-man-pages
python
)

export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"

MAGIC_ENTER_GIT_COMMAND='git status -sb .'
MAGIC_ENTER_OTHER_COMMAND='ls -la .'
source $ZSH/oh-my-zsh.sh

and  edits to .p10k.zsh

typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
virtualenv
[...]
)

typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( 
[...]
example
)
function prompt_example() {
p10k segment -f 208 -i '<hi>' -t 'ฅ^•ﻌ•^ฅ'
}
typeset -g POWERLEVEL9K_VIRTUALENV_LEFT_DELIMITER='('
typeset -g POWERLEVEL9K_VIRTUALENV_RIGHT_DELIMITER=')'
typeset -g POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION=true 
typeset -g POWERLEVEL9K_VIRTUALENV_VISUAL_IDENTIFIER_EXPANSION='🐍
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON='\UE0A0 '

hurray!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.