Menu
This post explains how to have posh-git prompt style in Oh My Zsh theme on Mac.
Zsh, or z shell, is a popular shell alternative to bash and tcsh, complete with many improvements and customization options offered through the Oh-My-ZSH project. If you’d like to use zsh as the default shell in Terminal for Mac OS rather than bash, you can do so rather easily with taking the following steps. This video will help developers/enthusiasts to set up and install 'oh-my-zsh' on a MacBook.This is my first technical cast/vlog. This recording is intended to show you how the setup and nothing to. Guys at work use Mac's with oh-my-zsh and boy that made me pretty jealous. It was not that straightforward to make it all work though. So hopefully, this post will help me and others in the future. Here's what we are going to do: Enable WSL on Windows 10; Install zsh + oh-my-zsh; Configure zsh and oh-my-zsh; Change Themes and colors. Step 1: Ditch Bash and Use ZSH + Oh-My-ZSH. First, some terminalogy — bwhahaha get it TERMINALogy!!.wipes tear from eye. ? Ok, maybe thats it for the terrible puns. So you have your terminal application. This is the default terminal app on mac/linux/windows or iTerm2 or powershell etc. (You should definitely be using iTerm2 though).
After 4 years of using Windows, I am coming back to using a Mac. And there are so many things in Windows I am missing already. One of these things is posh-git; I loved how in one glance to your prompt you know the status of your git repo: how many files changed, how many added, how many deleted, how many indexed… just love it!
Once I moved to Mac, I changed my shell to use zsh using Oh My Zsh due to the rich experience it brings to the terminal. I was delighted to see all these themes and plugins, and then started looking for a theme that provided the same information posh-git prompt provided. To my surprise, there was none! So I started my quest to see how I can change zsh, the theme, or the plugin to have such prompt.
Being lazy, I wanted change an existing theme I like with the least amount of investment. I looked in the documentation to see how I could do that, and found the customisation wiki page:
Oh My Zsh For MacShould I override the theme?Install Oh My Zsh Mac
Overriding the theme seemed to be the perfect solution, however, there were couple of drawbacks:
Zsh Profile Mac
Remember I wanted to put the least amount of effort, and I surely didn’t want to learn the whole thing! But while looking into avit theme, one thing grasped my attention: there was a clear reference to what seemed to be like a function git_prompt_info. And I thought this should be it, if I could find where this function is and how to override it.
To my luck, it was mentioned as an example in the customisation wiki page as an example!
Override the internals it is!
Laplace to z transform. Ok great, now I know that I can customise git_prompt_info, all what I need is to mimic whatever posh-git does in that function!
So I hit
Initially I mistakenly called the __posh_git_ps1 function, but I soon realised that I need to print (echo) the git info just like prompt_git_info did rather than changing any variables, for that I should use the __posh_git_echo.
And thus I ended up with a file called emad-git-prompt.zsh under the path ~/.oh-my-zsh/custom with the content of posh-git-bash here, and at the end of the file I wrote the following code:
Oh My Zsh Mac Install
I hope this helps you 🙂
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |