All Projects → lyze → Posh Git Sh

lyze / Posh Git Sh

Bash/ZSH version of the posh-git command prompt

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Posh Git Sh

Org Roam
Rudimentary Roam replica with Org-mode
Stars: ✭ 4,067 (+1224.76%)
Mutual labels:  hacktoberfest
Laravel Starter
A CMS like modular starter application project built with Laravel 8.x.
Stars: ✭ 299 (-2.61%)
Mutual labels:  hacktoberfest
Curriculum
The open curriculum for learning web development
Stars: ✭ 4,240 (+1281.11%)
Mutual labels:  hacktoberfest
Datascience Anthology Pydata
PyData, The Complete Works of
Stars: ✭ 301 (-1.95%)
Mutual labels:  hacktoberfest
Social
🎉 Social can be used for work, or to connect to the fediverse!
Stars: ✭ 302 (-1.63%)
Mutual labels:  hacktoberfest
Minecolonies
Minecolonies minecraft mod
Stars: ✭ 303 (-1.3%)
Mutual labels:  hacktoberfest
Ant Design Blazor
🌈A set of enterprise-class UI components based on Ant Design and Blazor WebAssembly.
Stars: ✭ 3,890 (+1167.1%)
Mutual labels:  hacktoberfest
Por Onde Comecar
União de materiais totalmente gratuitos para ajudar quem desejar entrar em alguma área, aprender uma nova tecnologia ou aprimorar suas skills.
Stars: ✭ 307 (+0%)
Mutual labels:  hacktoberfest
Noteless
A Markdown-based note-taking app for mobile devices.
Stars: ✭ 302 (-1.63%)
Mutual labels:  hacktoberfest
Reddit Enhancement Suite
Reddit Enhancement Suite
Stars: ✭ 3,326 (+983.39%)
Mutual labels:  hacktoberfest
Cryptocmd
Cryptocurrency historical price data library in Python. Data from https://coinmarketcap.com.
Stars: ✭ 299 (-2.61%)
Mutual labels:  hacktoberfest
Awesome Graal
A curated list of awesome resources for Graal, GraalVM, Truffle and related topics
Stars: ✭ 302 (-1.63%)
Mutual labels:  hacktoberfest
Wipe Modules
🗑️ Easily remove the node_modules folder of non-active projects
Stars: ✭ 304 (-0.98%)
Mutual labels:  hacktoberfest
Hashids.js
A small JavaScript library to generate YouTube-like ids from numbers.
Stars: ✭ 3,525 (+1048.21%)
Mutual labels:  hacktoberfest
Cordova Android
Apache Cordova Android
Stars: ✭ 3,285 (+970.03%)
Mutual labels:  hacktoberfest
Browsershot
Convert HTML to an image, PDF or string
Stars: ✭ 3,526 (+1048.53%)
Mutual labels:  hacktoberfest
Devise Security
A security extension for devise, meeting industrial standard security demands for web applications.
Stars: ✭ 302 (-1.63%)
Mutual labels:  hacktoberfest
Airform
Functional HTML forms for Front-End Developers.
Stars: ✭ 307 (+0%)
Mutual labels:  hacktoberfest
Augur
Python library and web service for Open Source Software Health and Sustainability metrics & data collection.
Stars: ✭ 304 (-0.98%)
Mutual labels:  hacktoberfest
Swiftweekly.github.io
A community-driven weekly newsletter about Swift.org
Stars: ✭ 305 (-0.65%)
Mutual labels:  hacktoberfest

posh-git-bash

Build Status

This script allows you to see the status of the current git repository in your prompt. It replicates the prompt status from the Windows PowerShell module dahlbyk/posh-git.

Installation Instructions

  1. Optional. Install bash-completion.

  2. Copy this file to somewhere (e.g., ~/git-prompt.sh).

  3. Add the following line to your ~/.bashrc. (You may need to update your ~/.bash_profile to source your ~/.bashrc, or you can just modify ~/.bash_profile directly.)

    source ~/git-prompt.sh
    
  4. If you are using bash, you should call __posh_git_ps1 in your PROMPT_COMMAND variable. The function __posh_git_ps1 takes two parameters (__posh_git_ps1 <prefix> <suffix>), and sets PS1 to <prefix><status><suffix>. You can also use __posh_git_echo to echo only the status.

    • Bash example:
    PROMPT_COMMAND='__posh_git_ps1 "\[email protected]\h:\w " "\\\$ ";'$PROMPT_COMMAND
    

    This shows username, at-sign, host, colon, cwd, then various status strings, followed by dollar and space, as your prompt. This invocation prepends this instruction to the existing value of PROMPT_COMMAND.

    • For zsh, you need to set the PROMPT variable or the precmd hook.
    precmd() {
      __posh_git_ps1 '%[email protected]%m:%~ ' '$ '
    }
    

    For some additional hints for integrating with oh-my-zsh, take a look at issue #14.

The Prompt

By default, the status summary has the following format:

[{HEAD-name} x +A ~B -C !D | +E ~F -G !H W]
  • {HEAD-name} is the current branch, or the SHA of a detached HEAD. The color of {HEAD-name} represents the divergence from upstream. {HEAD-name} also changes to indicate progress if you are in the middle of a cherry-pick, a merge, a rebase, etc.
    • cyan the branch matches its remote
    • green the branch is ahead of its remote (green light to push)
    • red the branch is behind its remote
    • yellow the branch is both ahead of and behind its remote
  • x is a symbol that represents the divergence from upstream.
    • the branch matches its remote
    • the branch is ahead of its remote
    • the branch is behind its remote
    • the branch is both ahead of and behind its remote
  • Status changes are indicated by prefixes to A through H, where A through D represent counts for the index and E through H represent counts for the working directory. As in git status, index status is dark green and working directory status is dark red.
    • + added
    • ~ modified
    • - removed
    • ! conflicting
  • W represents the overall status of the working directory.
    • ! there are unstaged changes in the working tree
    • ~ there are uncommitted changes, i.e. staged changes, in the working tree waiting to be committed
    • None: there are no unstaged or uncommitted changes to the working tree

For example, a status of [master ≡ +0 ~2 -1 | +1 ~1 -0 !] corresponds to the following git status:

# On branch master
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#        modified:   this-changed.txt
#        modified:   this-too.txt
#        deleted:    gone.txt
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#        modified:   not-staged.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#        new.txt

Example setup

Example usage

To get the above prompt display, I have the following in my .bashrc:

export PROMPT_COMMAND='__posh_git_ps1 "\\[\[\e[0;32m\]\[email protected]\h \[\e[0;33m\]\w" " \[\e[1;34m\]\n\$\[\e[0m\] ";'$PROMPT_COMMAND

Try it out and let me know what you think!

Configuration Options

This script should work out of the box. You can set options controlling the output of the script by using git config. This allows you to control the prompt display on a per-repository basis.

For example, if computing file changes is taking too long in a large repository, you can turn off this behavior (for that repository only):

cd my-git-repo/
git config bash.enableFileStatus false

To restore the default behavior, you can remove the configuration setting:

cd my-git-repo/
git config --unset bash.enableFileStatus

You can also manually edit your git configuration files. These files are most likely ~/.gitconfig or .git/config. An example illustrating the syntax of these files can be found at http://git-scm.com/docs/git-config#_example.

bash.branchBehindAndAheadDisplay

This option controls whether and how to display the number of commits by which the current branch is behind or ahead of its remote.

  • full: Default. Display count alongside the appropriate up/down arrow. If both behind and ahead, use two separate arrows.
  • compact: Display count alongside the appropriate up/down arrow. If both behind and ahead, display the behind count, then a double arrow, then the ahead count.
  • minimal: Display the up/down or double arrow as appropriate, with no counts.

bash.describeStyle

This option controls if you would like to see more information about the identity of commits checked out as a detached HEAD. This is also controlled by the legacy environment variable GIT_PS1_DESCRIBESTYLE.

  • contains: relative to newer annotated tag (v1.6.3.2~35)
  • branch: relative to newer tag or branch (master~4)
  • describe: relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
  • default: exactly matching tag

bash.enableFileStatus

  • true: Default. The script will query for all file indicators every time.
  • false: No file indicators will be displayed. The script will not query upstream for differences. Branch color-coding information is still displayed.

bash.enableGitStatus

  • true: Default. Color coding and indicators will be shown.
  • false: The script will not run.

bash.enableStashStatus

  • true: Default. An indicator will display if the stash is not empty.
  • false: An indicator will not display the stash status.

bash.showStatusWhenZero

  • true: Indicators will be shown even if there are no updates to the index or working tree.
  • false: Default. No file change indicators will be shown if there are no changes to the index or working tree.

bash.showUpstream

By default, __posh_git_ps1 will compare HEAD to your SVN upstream if it can find one, or @{upstream} otherwise. This is also controlled by the legacy environment variable GIT_PS1_SHOWUPSTREAM.

  • legacy: Does not use the --count option available in recent versions of git-rev-list
  • git: Default. Always compares HEAD to @{upstream}
  • svn: Always compares HEAD to SVN upstream

bash.enableStatusSymbol

  • true: Default. Status symbols ( ) will be shown.
  • false: No status symbol will be shown, saving some prompt length.

Known issues

Terminal.app

When using Terminal.app, when the prompt is longer than the terminal window width, the prompt line may not wrap correctly to the next line. This is suspected to be caused by incorrect handling of ANSI color codes by Terminal.app. See issue #18.

Background

This was my first venture into bash scripting, so I decided to make a clone of posh-git, which is a set of PowerShell scripts for git integration. In my humble opinion, I think it is fantastic.

I based my work off of https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh

Please do not hesitate to contact me about any issues or requests. I hope that you may find some use for this script.

License

This is distributed under the GNU GPL v2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].