DEV Community

Cover image for Beautify your bash within in minutes
mikelogaciuk
mikelogaciuk

Posted on

Beautify your bash within in minutes

Purpose

Sometimes, classic bash stops being sufficient for every developer and I mean not it's utility but details that it can show to us.

For this purpose, comes Oh-My-Posh, which as author states is:

Oh My Posh is a custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable.

Preparation

First things first, in order to install it. We can install it manually, or with homebrew which every developer that works on Linux, should have.

Homebrew

We install it with this tiny snippet:

sudo apt-get install build-essential procps curl file git

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Then we pass it to our .profile:

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/ubuntu/.profile
Enter fullscreen mode Exit fullscreen mode

Or:

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Enter fullscreen mode Exit fullscreen mode

Then we need to restart our shell:

exec "$SHELL"
Enter fullscreen mode Exit fullscreen mode

And update our new brew:

brew update
Enter fullscreen mode Exit fullscreen mode

And that's it, now we can use e.g.:

brew install minikube
Enter fullscreen mode Exit fullscreen mode

But that is not a purpose of this topic.

Oh-My-Posh

Manual installation looks like this:

sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
sudo chmod +x /usr/local/bin/oh-my-posh
Enter fullscreen mode Exit fullscreen mode

With brew:

brew install jandedobbeleer/oh-my-posh/oh-my-posh

brew update && brew upgrade oh-my-posh
Enter fullscreen mode Exit fullscreen mode

We are going to need special font for it:

cd ~
mkdir .fonts
unzip ~/Downloads/Meslo.zip -d ~/.fonts/Meslo
fc-cache -fv
Enter fullscreen mode Exit fullscreen mode

Then we download official theme pack from author:

mkdir ~/.poshthemes
wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip
unzip ~/.poshthemes/themes.zip -d ~/.poshthemes
chmod u+rw ~/.poshthemes/*.json
rm ~/.poshthemes/themes.zip
Enter fullscreen mode Exit fullscreen mode

Then we go to this website and look for theme and add it to ~/.profile:

echo 'eval "$(oh-my-posh init bash --config ~/.poshthemes/theme_name.omp.json)"' >> ~/.profile

exec SHELL
Enter fullscreen mode Exit fullscreen mode

Installing on Windows

For Windows users installation looks like this:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force;

Install-Module oh-my-posh -Scope CurrentUser
Add-Content $PROFILE "`nSet-PoshPrompt -Theme tonybaloney"
Enter fullscreen mode Exit fullscreen mode

Than in order to set theme use snippet below:

Add-Content $PROFILE "`nSet-PoshPrompt -Theme YOURTHEME"
Enter fullscreen mode Exit fullscreen mode

Note that you will need any font from here: link.

Top comments (2)

Collapse
 
silverdes profile image
OUAIJI ABDELAZIZ

Hi!
Thanks for the tutorial.
Is that applicable on windows?

Collapse
 
mikelogaciuk profile image
mikelogaciuk

Hi!

Yes of course, you can install it for 'Powershell' & 'Terminal' :)

Link:
ohmyposh.dev/docs/installation/win...