Colors and Icons for everyone!

Adding more colors and icons to the ZSH ls command

 

Doctor, I feel like a pair of curtains! Pull yourself together….

I finally got myself some curtains and fit them to my windows.

 

My balcony

I gave my balcony a little upgrade introducing plants.

 

Texas, Cowboys and Tags

Funny story about “texas-style tagging” which happened to me recently.

 

Adding hostname to oh-my-zsh-theme

I really like to use ZSH with the community driven Oh-My-ZSH framework. I tried the different themes that it offers, and since I found one that I like (miloshadzic) I really got used to it. So much so, that I started installing it on all my server instances where I SSH into.

Default miloshadzic theme
Default miloshadzic theme (source)

This is where the inevitable started to happen: I mixed up machines and started losing time by being flabbergasted as to why this or that is not around etc.

For some time I didn’t bother with it and thought that it’s just my lack of concentration. But after I started regularly jumping in and out of containers, SSH sessions and what not every day for every customer, the errors piled up.

I started to use different themes for different environments, but since I am so used and happy with my local setup, this all felt like a bad solution.

So today I tackled the problem (for now only on my machine, but that will help already a lot) by modifying my favourite theme and adding the hostname to the prompt line. I found it quite cool to check how to do it and hence I will write down my findings.

Wrong Approach

Of course the first thing I wanted to see, is how complicated it is to change anything about those themes and was surprised, that the miloshadzic theme is very simple indeed. I learned, that whatever is defined in the PROMPT variable is the thing that is displayed and that there are the fancy definitions for the colors. So I just added my hard-coded hostname in the front, saved, sourced the config again and…. it worked! I was surprised that it was that easy, since I just guessed, copy-pasted and tried out something.

So why is it the wrong approach? Well the themes and the entire oh-my-ZSH are inside of a git repository. So changing things there is bad of course, since they will possibly block getting updates to it (which is done by git pull). Additionally you can’t version them yourself if you make more complicated adaptations.

Correct Approach

So since we did it wrong, let’s do it right now! With all the steps necessary below 🙂

The idea is to put the changed theme in a custom folder which oh-my-zsh knows about and automatically uses to overwrite the defaults if there is a theme named the same. By not changing the name, you don’t have to make any changes to your .zshrc and everything else can also stay the same.

First I checked where my zsh custom directory is: echo $ZSH_CUSTOM (for me it’s here: /Users/alex/.oh-my-zsh/custom

Then I copied the theme which I currently use into a themes directory in the custom directory we just found out about. The built in themes are here: ~/.oh-my-zsh/themes

cp ~/.oh-my-zsh/themes/miloshadzic.zsh-theme ~/.oh-my-zsh/custom/themes

Open the copied file and edit anything about you want, for me it was to add the hostname in blue %{$fg[blue]%}%m and a pipe in red as a separator (for consistency) %{$fg[red]%}| in the beginning of the PROMPT.

The whole thing looked like this in the end:

# Yay! High voltage and arrows!
  
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""

PROMPT='%{$fg[blue]%}%m%{$fg[red]%}|%{$fg[cyan]%}%1~%{$reset_color%}%{$fg[red]%}|%{$reset_color%}$(git_prompt_info)%{$fg[cyan]%}⇒%{$reset_color%} '

After saving and sourcing the .zshrc file again (or of course opening a new Shell) I was greeted with this result:

Resultint output
Hostname and Pipe in the front

I now can see quickly where I am and won’t do silly mistakes as I often did before, while also still using my favourite theme!

For further reading, you can check the customisation part of oh-my-zsh here: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization

 

Disable Chromes Highjacking of Media Keys

Recently I noticed that my media keys didn’t work anymore when I wanted to change or pause a song on Spotify on OSX. What happened instead was that random Youtube videos, which I had opened previously in Chrome, started playing/pausing. Only after closing all websites containing video elements, Spotify would bend to my will again.

This was incredibly annoying.

I didn’t know what to google for since at first I thought that this is some kind of OSX “feature”. I found a lot of random solutions using applescript and what not that were waaaay to hacky in order to be ‘the’ solution.

Just today I figured out that this behaviour can be configured in Chrome. Credit goes to Reddit user @N_P_K and this post of his:

TL;DR: paste this into your Chromes omnibar and set the feature to disabled:

chrome://flags/#hardware-media-key-handling
 

Hello world!

I am happy to announce that I have decided to start my personal blog on all the things I do and plan to do in the future.

The blog will mostly revolve around programming, woodworking and other creations I might come up with. Also from time to time there will be some posts about things that I have experienced or found interesting to blog about 🙂

Right now my main focus is on programming, especially Clojure and Ruby on Rails. Depending on time and fancy, even some Android could come along.