• Stars
    star
    3,632
  • Rank 12,183 (Top 0.3 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An opinionated git prompt for bash and zsh

alt tag alt tag alt tag alt tag alt tag alt tag alt tag alt tag alt tag alt tag alt tag alt tag alt tag alt tag

alt tag

Installation

The Font

oh-my-git is shipped with 3 themes. The one showed above is called oppa-lana-style. It's based on the Awesome-Terminal-Fonts by @gabrielelana. The screenshots above use the font Source Code Pro by Adobe patched to include additional glyphs from Powerline and from Awesome-Terminal-Fonts, but you can choose any other of the Awesome-Terminal-Fonts.

You can freely download the fonts from the original repo.

To install one of the fonts, on macOS just double click on the corresponding ttf file and click on Install font. So far, I didn't find a way to make the fallback strategy work on macOS.

On Linux you can either install the patched font or you can apply the Awesome-Terminal-Fonts fallback strategy.

Then, configure your terminal with the desired font, and restart it.

Bash

One liner for macOS:

git clone https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.profile

One liner for Ubuntu:

git clone https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.bashrc

Then restart your Terminal.

Manual installation

Fork the repo and git clone it in your home directory.

Then add

source $HOME/oh-my-git/prompt.sh

to the bash startup file (~/.profile on Mac, ~/.bashrc on Linux)

If you prefer to keep oh-my-git repository in a different directory, just modify the startup file accordingly to the chosen position

source /wherever-you-want/oh-my-git/prompt.sh

zsh

With antigen installed, just add

antigen use oh-my-zsh
antigen bundle arialdomartini/oh-my-git
antigen theme arialdomartini/oh-my-git-themes oppa-lana-style

to your .zshrc file.

oh-my-git-themes still includes the old 2 themes arialdo-granzestyle (which is inspired to the great Granze theme) by @granze, and arialdo-pathinline. If you want to use them, edit accordingly your .zshrc file.

Fig

Fig adds apps, shortcuts, and autocomplete to your existing terminal.

Install oh-my-git in just one click.

How to install antigen

antigen is a plugin manager for zsh. Installing antigen is straightforward:

cd ~ && git clone https://github.com/zsh-users/antigen.git .antigen 

Then, edit your .zshrc file including

source "$HOME/.antigen/antigen.zsh"

antigen use oh-my-zsh
antigen bundle arialdomartini/oh-my-git
antigen theme arialdomartini/oh-my-git-themes oppa-lana-style

antigen apply

When you restart zsh, antigen will download and install all that's needed.

Customizing symbols

You can easily change any symbols used by the prompt. Take a look to the file prompt.sh (or to oppa-lana-style.zsh-theme if you use zsh). You will find a bunch of variables, each of them with its default value. The variables names should be auto-explanatory. Something like

: ${omg_is_a_git_repo_symbol:='❀'}
: ${omg_has_untracked_files_symbol:='∿'}
: ${omg_has_adds_symbol:='+'}
: ${omg_has_deletions_symbol:='-'}
: ${omg_has_cached_deletions_symbol:='βœ–'}
: ${omg_has_modifications_symbol:='✎'}
: ${omg_has_cached_modifications_symbol:='☲'}
: ${omg_ready_to_commit_symbol:='β†’'}
: ${omg_is_on_a_tag_symbol:='⌫'}

You can override any of those variables in your shell startup file.

For example, just add a

omg_is_on_a_tag_symbol='#'

to your .bashrc file, and oh-my-git will use # when you are on a tag.

Disabling oh-my-git

oh-my-git can be disabled on a per-repository basis. Just add a

[oh-my-git]
enabled = false

in the .git/config file of a repo to revert to the original prompt for that particular repo. This could be handy when working with very huge repository, when the git commands invoked by oh-my-git can slow down the prompt.

Uninstall

Bash

  • Remove the line source ~/.oh-my-git/prompt.sh from the terminal boot script (.profile or .bash_rc)
  • Delete the oh-my-git repo with a rm -fr ~/.oh-my-git

zsh

Remove the lines

antigen use oh-my-zsh
antigen bundle arialdomartini/oh-my-git
antigen theme arialdomartini/oh-my-git-themes oppa-lana-style

from your .zshrc file

Troubleshooting

Help, I installed oh-my-git but this is what I see:

alt tag

A: It's likely that you forgot to install the font.


I don't want to install a new font!

A: "No prob. You may select another theme, or you can customize symbols. Take a look to the prompt.sh file. It contains a list of pre-defined symbols, similar to:

# Symbols
: ${omg_is_a_git_repo_symbol:='❀'}
: ${omg_has_untracked_files_symbol:='∿'}
: ${omg_has_adds_symbol:='+'}
: ${omg_has_deletions_symbol:='-'}
: ${omg_has_modifications_symbol:='✎'}

Those are just default values. If you wish to use another glyph for untracked file, just define a

omg_has_untracked_files_symbol="whatever"

in your shell startup file.


With Bash the last symbol looks very bad, like this

oh-my-git

A: Unfortunately, I haven't find a way to tell bash "print the next symbol using the background color currently used by the terminal" and as far as I know there's no way to achieve this result. Zsh is not affected by this issue, but bash is.

As a consequence, when printing the last symbol, oh-my-git has no choice but setting explicitly the foreground and background colors. Currently, the standard background color is black. This is unfortunate, because if the terminal uses a different background color than black, the result is bad, as showed in the above screenshot.

A smart solution is the one proposed by @Sgiath: in the color palette set the first color (the one in the top-left corner) same as background color, like this

oh-my-git

This in fact sets the "black" color to the same color used as the terminal background.

If for any reasons you cannot change the palette, you can override the colors used to render the last symbol with the variable omg_last_symbol_color.

For example, if the terminal is using a gray background, you can add a

background=240
red='\e[0;31m'
omg_last_symbol_color="${red}\[\033[48;5;${background}m\]"

to your .bashrc and fix the issue by choosing the right value for background.

You can use

foreground=160
background=240
omg_last_symbol_color="\[\033[38;5;${foreground}m\]\[\033[48;5;${background}m\]"

if you want a more detailed control on the colors.

Finding the right value is not trivial. Please, refer to this page for a the 256 colors code table.


On OS X, I configured iTerm2 with the patched font, but the prompt is still broken.

A: iTerm2 preferences have 2 sections for setting the font: one for Regular Font and one for Non-ASCII Font. The font should be set on both the sections, like showed in the following screenshot:

iTerm2 Preferences Page


Help! On Linux I can't install the font!

A: You should refer to the documentation of Awesome-Terminal-Fonts. Anyway, this is how I personally setup the prompt on Ubuntu

# Copy the awesome fonts to ~/.fonts
cd /tmp
git clone http://github.com/gabrielelana/awesome-terminal-fonts
cd awesome-terminal-fonts
git checkout patching-strategy
mkdir -p ~/.fonts
cp patched/*.ttf ~/.fonts

# update the font-info cache
sudo fc-cache -fv ~/.fonts

Then, run gnome-terminal (or whatever terminal you like) and select one of the awesome-fonts

alt tag

Finally, install oh-my-zsh with the one-liner (if you use Bash) or with Antigen if you love zsh, and restart the Terminal.


When I'm not in a git repo, I want to use my old, beloved prompt...

A: Sure! Use the variable omg_ungit_prompt. Store there your old prompt: it will be used when you are not in a git repo.


Help! I used the one-liner for OS X, but the prompt doesn't start!

A: The one-liner for OS X adds the startup command in ~/.profile, which is the startup file for generic login shells. If a ~/.bash_profile is present, this is used in place of .profile, and .profile itself is ignored. To solve your issue, use this alternative one-liner

cd ~ && git clone https://github.com/arialdomartini/oh-my-git.git && echo source $HOME/.oh-my-git/prompt.sh >> .bash_profile

or just move the startup command

echo source $HOME/oh-my-git/prompt.sh

from .profile to .bash_profile


Hey, where's my current virtualenv name? It disappeared from the prompt! Or it appears like this

virtualenv badly rendered

A: Yes, actually the virtualenv's approach with prompts is pretty disappointing (see Virtualenv's bin/activate is Doing It Wrong): in fact, the script activate performs a

PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"

that arrogantly prepends the virtualenv name to the current PS1, leaving you no opportunity to customise the output.

You can solve this problem disabling the standard virtualenv prompt injection and using the callback function omg_prompt_callback.

Add

VIRTUAL_ENV_DISABLE_PROMPT=true
function omg_prompt_callback() {
    if [ -n "${VIRTUAL_ENV}" ]; then
        echo "\e[0;31m(`basename ${VIRTUAL_ENV}`)\e[0m "
    fi
}

to your shell startup script. It should render the prompt inside an active virtualenv like this

a proper virtualenv rendering]

You can use the call back function to inject whatever you want at the beginning of the second line.

Known bugs and limitations

  • git v1.8.4 or newer is required
  • It works weird on brand new repositories, before the first commit
  • It has been tested on Mac and Ubuntu only. I never managed to make it work on Cygwin
  • Depending on the theme selected, you need an unicode font (like Sauce Code Pro, Menlo or Monaco on Mac OS X, or Monospace on Ubuntu; on Windows, with Cygwin, a good choice is Meslo by AndrΓ© Berg, but I didn't tested the ooppa-lana-style theme)
  • If the Terminal uses a clear background color, in Bash you need to change the colors defined in prompt.sh. The zsh version is not affected by this problem.

More Repositories

1

Back-End-Developer-Interview-Questions

A list of back-end related questions you can be inspired from to interview potential candidates, test yourself or completely ignore
15,041
star
2

morris-worm

The decompiled Morris Worm source code
C
571
star
3

git-dashboard

A dead stupid (yet effective) git dashboard in 3 lines of bash
Shell
41
star
4

get-git

Una guida per capire git rapidamente e senza grattacapi
35
star
5

oh-my-git-themes

Themes of the ZSH version of oh-my-git prompt
27
star
6

dotfiles

macOS and Linux configuration files
Shell
11
star
7

arialdomartini.github.io

My personal blog
HTML
11
star
8

is-hive-mind-or-not

My attempt to discover if TJ Holowaychuk is a hive mind or a real programmer
Shell
8
star
9

books

Notes reading IT books
8
star
10

api-design-guidelines

6
star
11

yesbut

An amazing tool that helps you getting rid of the annoying requests by your developers
Python
5
star
12

learn-you-a-haskell-for-the-great-good

Learning Haskell
Haskell
5
star
13

mnemonics

Visualization Mnemonics for Software Principles
C#
4
star
14

primitive-obsession

A dead simple library to deal with the Primitive Obsession smell in C#
C#
3
star
15

lazy

Scripts I use for the housekeeping of my personal stuff
C#
3
star
16

xp-practices-poster

eXtreme Programming Practices and their relationships in a printable A3 poster
3
star
17

category-theory

Notes and exercises reading Category Theory for Programmers
3
star
18

mef-and-autofac

Loading plugins and registering their components with Autofac
C#
3
star
19

functional-programming-in-csharp

Exercises reading Functional Programming in C# by Enrico Buonanno
C#
2
star
20

csharp-bits

Code exercises in C#
C#
2
star
21

grasp-it

Lectures, Practical Exercises and Katas for Pragmatic Programmers
C#
2
star
22

scala-coursera-assignments

Scala
2
star
23

elisp-game-of-life

An implementation of Conway's Game of Life in Emacs Lisp
Emacs Lisp
2
star
24

pie.monads

Monoids, Functors and Monads for C#
C#
2
star
25

neat-coin

A didactic crypto-currency based on blockchain, running on .NET Core and built in TDD.
C#
2
star
26

haskell-in-depth

Exercises reading Haskell in Depth
Haskell
2
star
27

disposable-filesystem

A C# library that ease the creation of temporary files and directories in test projects
C#
2
star
28

private-ethereum

Running an Ethereum private network in a Docker container
Shell
2
star
29

nim-bits

Studying nim
Nim
1
star
30

refactoring

Support exercises for Refactoring classes
Java
1
star
31

oh-no-bash

A collection of bash scripts I use in my daily job
Shell
1
star
32

defunct-c

(Abandoned) A interpreted functional programming language, highly inspired (if not shamelessly plagiarised) by Lisp, written in C
C
1
star
33

elixir-bits

Studying "Γ‰tudes for Elixir"
Elixir
1
star
34

erlang-bits

Code written while studying Erlang
Erlang
1
star
35

Bebox.Toolkit

A simple toolkit I use for my C# projects
C#
1
star
36

fp-course

Exercises with Functional Programming in Haskell
Haskell
1
star
37

without-mediatr

Replacing MediatR with plain OOP
C#
1
star
38

property-based-testing-for-the-rest-of-us

Sample code for the article series Property-based Testing for The Rest of Us
C#
1
star
39

myvps

DevOps tools for my VPS
Shell
1
star
40

refactoring-trivia-csharp

Refactoring exercises in C# based on Trivia Legacy Code Retreat
C#
1
star
41

docker-bits

Playing with Docker
Shell
1
star
42

homebrew-nim

Nim homebrew source release for OS X. Nim's official repository is at https://github.com/Araq/Nim
Ruby
1
star
43

oh-my-git-gh-pages

github-pages files for oh-my-git
CSS
1
star
44

rabbitmq-skeleton

C#
1
star
45

dotnet-eli5

Compatibility between Core, Full Framework and .NET Standard
C#
1
star
46

ace-jump-mode-wiki

Wiki pages for Emacs ace-jump-mode
1
star
47

wait-and-play

Set up a timer and make Android play an ogg file (this will be the base for another less trivial project)
Java
1
star
48

yat

from Sales Traveling Problem to Neuronal Networks + Genetic Algorhithms
C#
1
star
49

bunny

Best practices with RabbitMQ in C#
C#
1
star
50

random-fizz-buzz

An algorithm to find the best random feed to generate a valid fizz-buzz sequence
C#
1
star
51

monkey

Interpreter of Monkey language, written in GoLang
Go
1
star