1.8 KiB
created:: 2024-01-25T16:49:34 (UTC -05:00) tags:: nixos source:: https://jeffkreeftmeijer.com/nix-home-manager-git-prompt/ author:: Jeff Kreeftmeijer
-
Git status in shell prompt with Nix Home Manager
Excerpt
By on 2023-03-19 (originally published on 2023-03-13)
By on 2023-03-19 (originally published on 2023-03-13)
Git comes with a script named
git-prompt.shthat exposes information about the current directory’s repository to use in your shell’s prompt. The script is in thecontribdirectory, but I used to extract it to not have to download the git source to set my prompt.Using Nix, the prompt is available in the
~/.nix-profiledirectory, meaning setting up the prompt doesn’t require remembering to download an extra file. Instead, it’s three lines inprograms.zsh.initExtrato source the script and set the prompt1:programs.zsh.initExtra = '' source ~/.nix-profile/share/git/contrib/completion/git-prompt.sh setopt PROMPT_SUBST export PS1='%~ $(__git_ps1 "(%s) ")%# ' '';This produces prompts like
~/repository (main) %inside a git repository, and~/not/a/repository %elsewhere.
- This example is for zsh, omit the
setoptand alter thePS1for bash:
``` programs.bash.initExtra = '' source ~/.nix-profile/share/git/contrib/completion/git-prompt.sh export PS1='\w $(__git_ps1 "(%s) ")$ ' ''; ``` [↩︎](https://jeffkreeftmeijer.com/nix-home-manager-git-prompt/#fnr.1) - This example is for zsh, omit the