65

I'm looking for theme to display a full path + git (branch name + uncommitted changes + added files). Didn't find any. something like this:

/full/path/to/repo (master *+)

would love a recommendation of one / a tip of how to edit an existing one (I am currently using Godzilla).

mcls
  • 9,071
  • 2
  • 29
  • 28
Ohad Perry
  • 1,315
  • 2
  • 15
  • 26
  • 1
    Zsh itself does not have themes. Perhaps you meant `oh-my-zsh`? Correctly tagging the question would help bringing the right people to look at your question. – Francisco Jan 13 '15 at 09:13

4 Answers4

127

You can modify the second line of this file:

~/.oh-my-zsh/themes/robbyrussell.zsh-theme

Which looks like this:

PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
#                       ^ replace c with ~

Then source theme again:

source ~/.zshrc

It will now show the path relative to your home directory (~). For example:

# BEFORE
➜  sqlboiler git:(master)
# AFTER
➜  ~/open-source/sqlboiler git:(master)
ikhvjs
  • 5,316
  • 2
  • 13
  • 36
Jim Chen
  • 3,262
  • 3
  • 21
  • 35
  • 14
    Instead of changing the default theme file, I would recommend copying the `PROMT=` lines to the end of `~/.zshrc` before customizing them – dtech Jan 05 '21 at 10:06
  • 2
    good point, I was satisfied with `cp ~/.oh-my-zsh/themes/robbyrussell.zsh-theme ~/.oh-my-zsh/themes/robbyrussell.zsh-theme.orig` – ecoologic Dec 13 '21 at 23:22
  • This didn't work for me at all. https://i.imgur.com/3otsfsa.png – Raleigh L. Aug 11 '22 at 09:09
  • 3
    If your theme is not `robbyrussell` you will need to edit different theme file. You can find your current active theme in `~/.zshrc` file under `ZSH_THEME` variable – Yashashvi Jan 05 '23 at 17:57
71

Run man zshmisc and search for the SIMPLE PROMPT ESCAPES section. This documents escapes which can be used to theme your prompt.

To get the full path path of your current working directory use %d.

I'm assuming you're using oh-my-zsh. In order to accomplish what you want, you can create a modified version of the Godzilla theme and replace the %c (which just shows the current folder) with %d in the PROMPT.

See here: https://github.com/robbyrussell/oh-my-zsh/blob/c78277fd8bda5fec87504469afdf121355876006/themes/gozilla.zsh-theme#L1

mcls
  • 9,071
  • 2
  • 29
  • 28
  • 6
    Is there a way to make "/Users/myuser/Desktop" become "~/Desktop" when using %d instead of %c? Thankss! – FelipeKunzler Aug 06 '16 at 01:42
  • 43
    You can use `%~` (instead of `%d`) to show `~/Desktop/path/` instead of `/Users/myuser/Desktop/path/`. http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html – Himmel Mar 01 '17 at 17:50
15

Besides other answers,

If you also want to add the username and/or hostname, add the three lines below in the end of ~/.zshrc to overwrite the PROMPT:

PROMPT="%{$fg_bold[white]%}%n %{$fg[blue]%}@ %{$fg_bold[yellow]%}%m"

PROMPT+=" %(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"

PROMPT+=' %{$fg[cyan]%}%d%{$reset_color%} $(git_prompt_info)'

Explanation:

%n is the username

%m is the hostname

%d is the directory (you can replace it with %~)

Note: Space between username and hostname is added in the example above is for clarity, you can remove them if you want.

ikhvjs
  • 5,316
  • 2
  • 13
  • 36
7

Locate your current theme in ~/.zshrc file defined under variable named ZSH_THEME. You are supposed to edit the file according to the theme(current zsh theme) defined here. Default one is robbyrussell.

For default theme edit this file: ~/.oh-my-zsh/themes/robbyrussell.zsh-theme Find PROMPT variable definition in file(Note: You can find multiple variable declaration with concatenation, find the one that matches structure mentioned below). It should have something like below:

PROMPT+='%{$fg[blue]%}%~%{$reset_color%}

Modify the middle part of PROMPT variable as your preference from following to change prompt path. Example how path would look like for each setting is shown below:

  1. %~% -> shows: ~/example_dir/temp/hello_world
  2. %d% -> shows: /User/ydave/Desktop/example_dir/temp/hello_world
  3. %2d -> shows: temp/hello_world
  4. %3d -> shows: example_dir/temp/hello_world
  5. %c% -> shows: hello_world
Yashashvi
  • 340
  • 3
  • 12