ChatGPT Conversation

Tags: #zsh

User: Thava Alagu (thavamuni@gmail.com)
Created: 03/03/2025, 15:11:32
Updated: 03/03/2025, 15:12:06
Exported: 03/03/2025, 15:16:58

Prompt:

I am using zsh with oh-my-zsh on my mac machine. I am not using git plugin; Still by default, it is showing the current git branch on the prompt inside any git repo; How can I disable that for all repos or disable selectively for some repos ? or choose another prompt style which does not include git branch on the prompt.

Response:

The Git branch appears in your prompt because of the default oh-my-zsh theme you're using, not the git plugin. Here are ways to disable or modify it:

1. Disable Git Branch for All Repositories

Modify your ~/.zshrc file:

  1. Open ~/.zshrc in a text editor:

    nano ~/.zshrc
    
  2. Look for the ZSH_THEME line. Your current theme is likely one that includes Git info (e.g., robbyrussell, agnoster, etc.).

  3. Change the theme to one that does not show Git branches, such as:

    ZSH_THEME="simple"
    
  4. Save and exit (Ctrl + X, then Y, then Enter).

  5. Apply changes:

    source ~/.zshrc
    

2. Disable Git Branch Display Selectively for Some Repositories

If you want to hide the Git branch only in specific repositories, add this to your ~/.zshrc:

function git_prompt_info() {
  local git_dir
  git_dir=$(git rev-parse --git-dir 2>/dev/null)
  if [[ "$PWD" =~ "/path/to/repo1|/path/to/repo2" ]]; then
    echo ""  # Hide Git branch for specific repos
  else
    git_prompt_short_sha
  fi
}

Replace /path/to/repo1|/path/to/repo2 with actual repo paths.

3. Use a Custom Prompt Without Git Info

Instead of changing themes, you can set a minimal custom prompt:

PROMPT='%n@%m %~ %# '

This will display:

  • Username (%n)
  • Hostname (%m)
  • Current directory (%~)
  • # for root, $ for normal users.

Add this line to your ~/.zshrc and reload:

source ~/.zshrc

Let me know if you need a specific prompt style!


Powered by ChatGPT Exporter