Giter Site home page Giter Site logo

git-radar's Introduction

Git Radar

A heads up display for git.

An example of git-radar

Git-radar is a tool you can add to your prompt to provide at-a-glance information on your git repo. It's a labour of love I've been dogfooding for the last few years. Maybe it can help you too.

Table of Contents

Installation

Install from brew:

> brew install michaeldfallen/formula/git-radar

Manually:

> cd ~ && git clone https://github.com/michaeldfallen/git-radar .git-radar
> echo 'export PATH=$PATH:$HOME/.git-radar' >> ~/.bashrc

Then run git-radar to see the docs and prove it's installed.

Usage

To use git-radar you need to add it to your prompt. This is done in different ways depending on your shell.

Bash

Add to your .bashrc

export PS1="$PS1\$(git-radar --bash --fetch)"

(note: the \ escaping the $ is important)

Zsh

Add to your .zshrc

export PROMPT="$PROMPT\$(git-radar --zsh --fetch) "

(note: the \ escaping the $ is important)

Fish

Add to your config.fish

function fish_prompt
    set_color $fish_color_cwd
    echo -n (prompt_pwd)
    echo -n (git-radar --fish --fetch)
    set_color normal
    echo -n ' > '
end

Features

Files status

The prompt lists the file changes and whether they are staged, unstaged or untracked.

Prompt Meaning
git:(master) 3A We have 3 untracked files
git:(master) 2D2M We have 2 modifications and 2 deletions not yet staged to commit
git:(master) 1M1R We have 1 modification and a file renamed staged and ready to commit
git:(master) 1U We have a conflict caused by US that we need to address
git:(master) 1M 1D2M 2A A combination of the above types

Each symbol represents a different change to a file. These are based on what git considers has happened to the file.

Symbol Meaning
A A new Added file
D A file has been Deleted
M A file has been Modified
R A file has been renamed
C A file has been copied
U A conflict caused by Us
T A conflict caused by Them
B A conflict caused by Both us and them

The color tells you what stage the change is at.

Color Meaning
Green Staged and ready to be committed (i.e. you have done a git add)
Red Unstaged, you'll need to git add them before you can commit
Grey Untracked, these are new files git is unaware of
Yellow Conflicted, these need resolved before they can be committed

The use of feature is controlled by the GIT_RADAR_FORMAT environment variable. See Customise your prompt for how to personalise this.

Local commits status

The prompt will show you the difference in commits between your branch and the remote your branch is tracking. The examples below assume you are checked out on master and are tracking origin/master.

Prompt Meaning
git:(master 2↑) We have 2 commits to push up
git:(master 3↓) We have 3 commits to pull down
git:(master 3⇵5) Our version and origins version of master have diverged

The use of feature is controlled by the GIT_RADAR_FORMAT environment variable. See Customise your prompt for how to personalise this.

Remote commits status

The prompt will also show the difference between your branch on origin and what is on origin/master. This a is hard coded branch name which I intend to make configurable in the future.

This is the difference between the commits you've pushed up and origin/master.

Prompt Meaning
git:(m ← 2 my-branch) We have 2 commits on origin/my-branch that aren't on origin/master
git:(m 4 → my-branch) There are 4 commits on origin/master that aren't on origin/my-branch
git:(m 1 ⇄ 2 my-branch) origin/master and origin/my-branch have diverged, we'll need to rebase or merge

The use of feature is controlled by the GIT_RADAR_FORMAT environment variable. See Customise your prompt for how to personalise this.

Stash status

The prompt will show you whether and how many stashes you have stored.

Prompt Meaning
git:(master) 1≡ We have one stash

If you don't rely on this status, you can always hide this part of the prompt by customising your prompt

(Optional) Auto-fetch repos

Ensuring your refs are up to date I found can be a pain. To streamline this git-radar can be configured to auto-fetch your repo. When the --fetch flag is used git-radar will run git fetch asynchronously every 5 minutes.

This will only occur when the prompt is rendered and it will only occur on the repo you are currently in.

To use this feature, when setting your prompt, call git-radar with --fetch:

Bash

export PS1="$PS1\$(git-radar --bash --fetch)"

(note: the \ escaping the $ is important)

Zsh

export PROMPT="$PROMPT\$(git-radar --zsh --fetch) "

(note: the \ escaping the $ is important)

You may also choose to fetch at a customized interval of time. To do so, add this to your .bashrc, .zshrc:

export GIT_RADAR_FETCH_TIME=<seconds>

For example, to fetch every 30 seconds (instead of the default 5 minutes):

export GIT_RADAR_FETCH_TIME=30

You can also do this in the gitradarrc file:

GIT_RADAR_FETCH_TIME=30

Customise your prompt

Git Radar is highly customisable using a prompt format string. The 4 features above: remote commits, local commits, branch and file changes; are controlled by the prompt format string.

Feature Control string
Remote commits %{remote}
Local commits %{local}
Branch %{branch}
File changes %{changes}
Stashes %{stash}

You can create any prompt shape you prefer by exporting GIT_RADAR_FORMAT with your preferred shape. The control strings above will be replaced with the output of the corresponding feature.

Examples

GIT_RADAR_FORMAT Result
%{branch}%{local}%{changes} master1↑1M
[%{branch}] - %{local} - %{changes} [master] - 1↑ - 1M

Prefixing and Suffixing the features

Often you will want certain parts of the prompt to only appear when there is content to render. For example, when in a repo you want [branch] but when out of a repo you don't want the [] appearing.

To do this the control strings support prefixes and suffixes. Prefixes and Suffixes are separated from the feature name by : and will only render if the feature would render:

Format: prompt > %{prefix - :changes: - suffix}

In a repo: prompt > prefix - 1M - suffix

Outside a repo: prompt >

The default prompt format uses this to add spaces only if the feature would render. In that way the prompt always looks well spaced out no matter how many features are rendering.

Support

Ensuring prompt execution

When setting your prompt variable, PROMPT in Zsh and PS1 in Bash, it's important that the function executes each time the prompt renders. That way the prompt will respond to changes in your git repo. To ensure this you will need to escape the execution of the function. There are two ways to do this:

1. Use $' to render raw characters

export PROMPT=$'$(git-radar --zsh)'
export PS1=$'$(git-radar --bash)'

2. Use \ to escape execution of the subshell

export PROMPT="\$(git-radar --zsh)"
export PS1="\$(git-radar --bash)"

Configuring colours

You can configure the colour scheme in two ways: export Environment Variables or use an rc file.

Exporting Environment Variables

To configure the prompt this way just add to your ~/.bashrc or ~/.zshrc an export directive with the value you want to change.

Example: Change the branch colour in Zsh

In ~/.zshrc:

export GIT_RADAR_COLOR_BRANCH='$fg[yellow]'

Example: Change the branch colour in Bash

In ~/.bashrc:

export GIT_RADAR_COLOR_BRANCH='\\033[0;33m'

Setting an RC file

Git radar supports multiple rc files. One of these will be sourced when the prompt renders.

Example: Change the branch colour in Zsh

In ~/.gitradarrc:

GIT_RADAR_COLOR_BRANCH='$fg[yellow]'

Basic RC file

Create a file at ~/.gitradarrc which sets the Environment variables listed in Configuration values using colour codes listed in either Zsh Colour Codes or Bash Colour Codes depending on your shell.

Shell specific RC file

If you use both Bash and Zsh you can set RC files that are specific for those shells.

For Bash: Create a file at ~/.gitradarrc.bash

For Zsh: Create a file at ~/.gitradarrc.zsh

Bash Colour Codes

Bash colour codes make use of the colours your terminal app claims to be red or green. Using one of these codes will only produce the colour your terminal claims, so you should customise your colour scheme on your terminal as well as customising git-radar.

Note the "Bright" colours can be shown as bold instead, it depends on your terminal. By default, for example, the Mac OSX Terminal.app uses the "Bright" colours to provide 8 new lighter colours but some terminals only support 8 and will show the text as bold instead.

Colour Code for Text Code for Background
Black \\033[0;30m \\033[0;40m
Red \\033[0;31m \\033[0;41m
Green \\033[0;32m \\033[0;42m
Yellow \\033[0;33m \\033[0;43m
Blue \\033[0;34m \\033[0;44m
Magenta \\033[0;35m \\033[0;45m
Cyan \\033[0;36m \\033[0;46m
White \\033[0;37m \\033[0;47m
Bright Black \\033[1;30m \\033[1;40m
Bright Red \\033[1;31m \\033[1;41m
Bright Green \\033[1;32m \\033[1;42m
Bright Yellow \\033[1;33m \\033[1;43m
Bright Blue \\033[1;34m \\033[1;44m
Bright Magenta \\033[1;35m \\033[1;45m
Bright Cyan \\033[1;36m \\033[1;46m
Bright White \\033[1;37m \\033[1;47m
Reset \\033[0m \\033[0m

Note the Reset will set back to what your terminal claims as standard text and background.

Zsh Colour Codes

Zsh also provides a way to access the colours that your terminal claims as red or green, etc.

Note the "Bright" colours can be shown as bold instead, it depends on your terminal. By default, for example, the Mac OSX Terminal.app uses the "Bright" colours to provide 8 new lighter colours but some terminals only support 8 and will show the text as bold instead.

Colour Code for Text Code for Background
Black $fg[black] $bg[black]
Red $fg[red] $bg[red]
Green $fg[green] $bg[green]
Yellow $fg[yellow] $bg[yellow]
Blue $fg[blue] $bg[blue]
Magenta $fg[magenta] $bg[magenta]
Cyan $fg[cyan] $bg[cyan]
White $fg[white] $bg[white]
Bright Black $fg_bold[black] $bg_bold[black]
Bright Red $fg_bold[red] $bg_bold[red]
Bright Green $fg_bold[green] $bg_bold[green]
Bright Yellow $fg_bold[yellow] $bg_bold[yellow]
Bright Blue $fg_bold[blue] $bg_bold[blue]
Bright Magenta $fg_bold[magenta] $bg_bold[magenta]
Bright Cyan $fg_bold[cyan] $bg_bold[cyan]
Bright White $fg_bold[white] $bg_bold[white]
Reset $reset_color $reset_color

Configuration values

All these values should be set using a the correct colour code for your terminal. You should also choose the colour code based on what shell you are using. There is a way to support colouring multiple shells using rc files.

Colouring the Branch part

GIT_RADAR_COLOR_BRANCH='[colour code]'

git:(my-branch)
     ^^^^^^^^^

The colour to use for the Branch or git reference.

It is unset by GIT_RADAR_COLOR_BRANCH_RESET which you can set if you want a different background colour to return to.

Colouring the local commits status

GIT_RADAR_COLOR_LOCAL_AHEAD='[colour code]'

git:(my-branch 1↑)
                ^

The colour to use for the arrow that indicates how many commits you have to push up.

It is unset by GIT_RADAR_COLOR_LOCAL_RESET which you can set if you want a different background colour to return to.

GIT_RADAR_COLOR_LOCAL_BEHIND='[colour code]'

git:(my-branch 1↓)
                ^

The colour to use for the arrow that indicates how many commits you have to pull down.

It is unset by GIT_RADAR_COLOR_LOCAL_RESET which you can set if you want a different background colour to return to.

GIT_RADAR_COLOR_LOCAL_DIVERGED='[colour code]'

git:(my-branch 1⇵1)
                ^

The colour to use for the arrow that indicates how many commits your branch has diverged by.

It is unset by GIT_RADAR_COLOR_LOCAL_RESET which you can set if you want a different background colour to return to.

Colouring the remote commits status

GIT_RADAR_COLOR_REMOTE_AHEAD='[colour code]'

git:(m ← 1 my-branch)
       ^

The colour to use for the arrow that indicates how many commits your branch has to merge on to master.

It is unset by GIT_RADAR_COLOR_REMOTE_RESET which you can set if you want a different background colour to return to.

GIT_RADAR_COLOR_REMOTE_BEHIND='[colour code]'

git:(m 1 → my-branch)
         ^

The colour to use for the arrow that indicates how many commits your branch is behind master.

It is unset by GIT_RADAR_COLOR_REMOTE_RESET which you can set if you want a different background colour to return to.

GIT_RADAR_COLOR_REMOTE_DIVERGED='[colour code]'

git:(m 1 ⇄ 1 my-branch)
         ^

The colour to use for the arrow that indicates how many commits your branch has diverged from master.

It is unset by GIT_RADAR_COLOR_REMOTE_RESET which you can set if you want a different background colour to return to.

GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM='[colour code]'

git:(upstream ⚡ my-branch)
              ^

The colour to use for the lightning bolt which indicates that your branch is not tracking an upstream branch.

It is unset by GIT_RADAR_COLOR_REMOTE_RESET which you can set if you want a different background colour to return to.

Colouring the file changes status

GIT_RADAR_COLOR_CHANGES_STAGED='[colour code]'

git:(my-branch) 1M
                 ^

The colour to use for the letters that indicate changes that have been staged to commit.

It is unset by GIT_RADAR_COLOR_CHANGES_RESET which you can set if you want a different background colour to return to.

GIT_RADAR_COLOR_CHANGES_UNSTAGED='[colour code]'

git:(my-branch) 1M
                 ^

The colour to use for the letters that indicate changes that have not yet been staged to commit.

It is unset by GIT_RADAR_COLOR_CHANGES_RESET which you can set if you want a different background colour to return to.

GIT_RADAR_COLOR_CHANGES_CONFLICTED='[colour code]'

git:(my-branch) 1B
                 ^

The colour to use for the letters that indicate changes that have conflicts that need resolved.

It is unset by GIT_RADAR_COLOR_CHANGES_RESET which you can set if you want a different background colour to return to.

GIT_RADAR_COLOR_CHANGES_UNTRACKED='[colour code]'

git:(my-branch) 1A
                 ^

The colour to use for the letters that indicate files that are currently not tracked by git.

It is unset by GIT_RADAR_COLOR_CHANGES_RESET which you can set if you want a different background colour to return to.

Colouring the stash status

GIT_RADAR_COLOR_STASH='[colour code]'

git:(my-branch) 1≡
                 ^

The colour to use for the lines that indicates how many stashes you have stored.

It is unset by GIT_RADAR_COLOR_STASH_RESET which you can set if you want a different background colour to return to.

License

Git Radar is licensed under the MIT license.

See LICENSE for the full license text.

Links

  • mini-git-radar - lightweight version of git-radar. Only for macOS and bash/fish.

git-radar's People

Contributors

btabibian avatar crflynn avatar grigoryvp avatar hallzy avatar inakiabt avatar joaoschaab avatar justinas avatar kain88-de avatar matthillmanbt avatar michaeldfallen avatar n10v avatar reicolina avatar slackorama avatar srstevenson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-radar's Issues

Unittests not working in linux

As sargas pointed out in Issue #10 : The unittests are not passing through when called in a ubuntu bash shell.
This should be fixed before continuing development on new features.

I have tried fixing the tests, so that they would work on my ubuntu terminal. Could someone test them out on OSX?

Here is the link to the fixed tests.

Optionally hide "git:"

Thanks for git-radar!

The "git:" label is useful for like a day, then it becomes visual noise. Can it be suppressed?

Bugs in new version

2015-10-15 16 14 07

  1. Prompt starts with new line
  2. Colors don't display correct

Shell: fish 2.2.0

Unhandled git error when a tracked upstream branch is removed

git checkout -b some-feature
git push -u some-remote some-feature
git push some-remote :some-feature

yields the following output whenever git-radar is called on the branch with the missing upstream:

fatal: ambiguous argument 'some-remote/some-feature...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Fatal: ambiguous argument 'some-remote/some-feature...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

The example is a silly chain of three commands to elicit this behavior, but I don't think having tracked branches deleted from remotes is an uncommon occurrence.

Any modifications required for Mac OS?

Hello and thanks for amazing work!

All works fine except line length: since you don't escape color codes via additional pair of "[" and "]", macos thinks that prompt has much greater length than actually is and wraps text being entered early.

What else do I need to add into my ~/.bashrc to fix this issue? Maybe some flag or general setting is required?

illustration

`grep -o` not available in git bash for Windows

The grep in git bash for Windows does not support the -o option. grep -o plays a pretty big part in the (staged|conflicted|unstaged|untracked)_status, which means that, on Windows, using git-radar results in the following message repeated about 20 times.

grep: invalid option -- o
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.

weird characters show up with git-radar on mac os x

This only happens in 1 of my repositories, the other ones work just fine.
It used to work, but I don't know what has changed since then.
Let me know how I can help figure this out, thanks!

$ git-radar --bash --fetch
 git:(master) 1��

Here is a screenshot:

http://i.imgur.com/oKpSY06.png

Remove the space before the output

This is a request to remove the space prefix of the output of git-radar. This would give more flexibility to theme builders over where the output can be placed. It would also be more consistent, because there's no padding at the end of the output.

no-remote-status being ignored?

I am trying to ignore the remote status section (as checking my current branch against origin/master isn't helpful for me). I can't seem to get the flag to work:

export PS1='[$NC]\u@\h:[$Red]\w[$NC]$(git-radar --bash --fetch --no-remote-status) $ '

Still gives me this output:
mike@compy:~/Development/project git:(𝘮 7 ⇄ 4 develop)

Thanks!

Possible to change character for untracked files?

There's one discrepancy from git status --short that annoys me, and that is that untracked files are marked with ?? in the status, but with a grey A in git-radar. I understand that that is because there's a relation between untracked and added files, but I'd rather have the output resemble what I see in git status --short, which matches my mental model better. Is there a way to change the individual symbols?

How to adjust coloring of "git:"

Hi,

first: thank you very much for the great tool.

second: I'm quite a newbie regarding shell prompt customization, so ...

now: I'm using OS X terminal app with dark solarized color theme, see https://github.com/tomislav/osx-terminal.app-colors-solarized. Within this theme, the "git(...)" part of git-radar ist colored black with bad contrast to the dark backround. I haven't found a way to customize that. Can it be customized?

This may be related to issue #40 and #57 .

Again thanks for the great work!

Regards
Stefan

0.6 upgrade issue

Upgrade issue:

==> Upgrading michaeldfallen/formula/git-radar
==> Downloading https://github.com/michaeldfallen/git-radar/releases/download/v0.6/git-radar-0.6.tar.gz
==> Downloading from https://github-cloud.s3.amazonaws.com/releases/30383524/479733a6-8a17-11e5-9757-048ccc020cf6.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20151113%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-D

################################################################## 100.0%

Error: SHA1 mismatch
Expected: 8a2ba434134413e16d83a6dd8d98ba5e1d3ac782a0719abc27fc6feef6ca5a82
Actual: 27c9ebfe8470851099d3f4efe65370cf00c9b58d
Archive: /Library/Caches/Homebrew/git-radar-0.6.tar.gz
To retry an incomplete download, remove the file above.
Winnetou-iMac:~ mati$

Some arrow characters are not showing up

Hi, Linux user here.

Some of the characters are now showing up correctly. Particularly the "Remote commits status" arrow icons:

screenshot from 2015-09-01 12-03-12

My font is currently "Adobe Source Pro for Powerline", although I already tried a couple others, including non-Powerline fonts.

I'm not sure if this is some issue with git-radar, or with my own system, but maybe someone here has had this problem before?

Problems zsh ubuntu

Had trouble in using the zsh in ubuntu, the command that includes the PROMPT does not work does not seem to boot

Use hooks to speed up prompt

The radar's local and remote commits can be slow, on heavy repos it can be very slow. We could use git hooks to only calculate the local and remote commits each time push, fetch, pull, commit etc events occur.

The precalculated strings could then be read from files in the .git folder quite quickly on each render.

Show whether anything is stashed

Sometimes I forget that I have something stashed, and later come back to the problem and wind up rewriting things. Would be nice to see that I have something stashed. Maybe just a single character, or a number 1-9+ of how many things are stashed.

Identify a branch that isn't set upstream

If a branch isn't set upstream (i.e. isn't tracking a remote branch) then the remote_branch_name returns ``and so all theremote_ahead../`remote_behind..` calls return nothing.

That isn't particularly informative. Would be useful to have a function that tells you if a local branch is tracking and can be used in the prompt to identify a branch that is local only.

have to pull twice to update a work branch

Hi,

I'm using bash in my terminals and I face very often a weird issue that happens when I change to another work branch and make a pull. The first time the pull fails showing the error message below. The second time works fine.

  • First pull
$ git checkout devel

$ (𝘮 ← 272 devel) 2A git pull
Ubuntu 13.10 ssh-pty

error: Ref refs/remotes/origin/devel is at 8d5945183d93bb831fc58f71b0801b97fbb2076f but expected 91981363fc49ccc92b7519695f08e7c9e41ec181
From xxxxxx:proyect/app
 ! 9198136..8d59451  devel -> origin/devel  (unable to update local ref)
  • Second pull
$ (𝘮 ← 274 devel 2↓) 2A git pull
Ubuntu 13.10 ssh-pty

Updating 9198136..8d59451
Fast-forward
...

Can anybody point me out in the right direction about what the problem is? Thanks.

Fetches not every 5 minutes?

Hi, I have come across something... it seems that (for me at least) it does not fetch every 5 minutes, but rather, almost immediately.

I notice in the code that there is a record timestamp function that creates a file in the .git directory of a repo, but mine is empty, and with a quick scan of the code I could not find a place that put anything in that file, and thus the timestamp is possible just nothing so the script thinks it needs to fetch always.

Has anyone else seen this?

Not that I am complaining, because I think I like it this way anyways, but just something I observed.

Prompt not loading in zsh

export PROMPT="$PROMPT$(git-radar --zsh) "

export PROMPT="%1/%$(git-radar --zsh --fetch) "

export PROMPT="$(git-radar --zsh)"

Tried all three of the above at the top of my .zshrc
Each one just places the text in the parentheses in my prompt but doesn't apply the prompt settings. What configuration am I missing here?

Brew install is successful
Disabled oh-my-zsh framework.
restarted terminal after each attempt with the different settings above.

It's like it's not actually running the code. A couple times (not every time) actually running $git-radar --zsh returned the the prompt color code that should be applied in the prompt.

brackets showing up instead of normal prompt representation

Hi,

When I add export PS1="\W\$(~/git-radar/git-radar --bash) " to my .bashrc I get the following:

py_ \[\]git:(\[\]\[\]master\[\]\[\])\[\] 3\[\]M\[\] 59\[\]A\[\]

Where py_ is my current direcotry.

When I add export PS1="\W$(~/git-radar/git-radar --bash) " it shows the correct format but no longer updates. I suppose this has to do with static executation and lazy evaluation of bash for PS1 and thus not the correct way of using your script.

I will appreciate if you could help.

P.s the package is fantastic. Cannot wait to use it and possibly contribute back.

escaping `$` prevents subexpression evaluation

I'm using zsh on El Capitan (sorry).

export PROMPT="$(git-radar --zsh --fetch) " renders the prompt once and then doesn't update. The suggested way to get the subexpression to re-evaluate on each prompt render (export PROMPT="\$(git-radar --zsh --fetch)") renders the raw characters $(git-radar --zsh --fetch) for me.

I've tried using backticks and $'$(…)' to evaluate the sub-expression but none have worked so far.

Thanks for making radar and for responding to the issues so well! This one is not urgent at all, so a point in the right direction whenever you've got time would be great 😄

Prompt not updating - OSX - zsh

The prompt doesn't update when I change branches, make changes, or anything else. However, it does work when using bash. The only way I can get it to change is by opening a new shell window or running exec $SHELL.

Does git-radar set background colors?

I'm trying to replace my home grown version with git-radar but I'm having problems with background colors. Here's what my old theme looks like:

And here's what I see using git-radar:

screen shot 2015-08-26 at 17 53 45

Here's how I set the background and the text from git-radar:

echo "%{$BG[019]%}$(git-radar --zsh --fetch) "

So, it looks like the background is set on the branch name? Is this correct?

Make it faster using builtins

Nice PS1 hack. This is definitely the fanciest one I've seen for git. So I want to help you improve it.

My question is this: do blank lines appear in the terminal if you hold down the enter key? That means the time to optimize is now. The name of the game is to drive down latency so that never happens.

Here's some code I wrote for mine own .bashrc file that you can use. It uses bash builtins to determine the git root and the current branch. This way you only need like 5 or so system calls, rather than the 182 you'd need to run the git command: strace -f git symbolic-ref --short HEAD |& wc -l

I've found that this is really helpful not only from the user experience standpoint (fast is better than slow) but also in situations where IO gets pwnd or you run out of processes. git might not run at all and you need builtins to save the system.

The only tradeoff with these functions is that it leaves garbage files behind in /tmp. It's assumed that a cron job exists to purge those occasionally. /etc/cron.daily/tmpreaper comes standard on Debian systems.

# Caches last directory for which `jartps1_gitdir_find` failed.
export JARTPS1_GITDIR_TMP="$(mktemp --suffix=-jartps1-gitdir)"

################################################################################
# Swiftly determine name of current Git branch.
#
# Arguments:
#   None
# Returns:
#   0 on success, storing result to ${jartps1_gitbranch}.
#   1 if ${PWD} isn't inside a Git repo.
# Globals:
#   jartps1_gitbranch      - Used to store result.
################################################################################
jartps1_gitbranch_find() {
  if jartps1_gitdir_find; then
    local head
    if read head <"${jartps1_gitdir}/.git/HEAD" &>/dev/null; then
      if [[ "${head}" =~ refs/heads/(.+) ]]; then
        jartps1_gitbranch="${BASH_REMATCH[1]}"
      else
        jartps1_gitbranch="${head##*/}"
      fi
      if [[ "${jartps1_gitbranch}" != "" ]]; then
        return 0
      fi
    fi
  fi
  return 1
}

################################################################################
# Swiftly locate root of current Git repository.
#
# This is the fastest possible solution. Rather than the naïve approach of
# executing the git command (which could take hundreds of milliseconds), this
# routine launches no processes and only requires a few stat() system calls. In
# some cases it can avoid lookup or cache the result.
#
# Arguments:
#   dir                 - Optional, defaults to ${PWD}
# Returns:
#   0 on success, storing result to ${jartps1_gitdir}.
#   1 if dir isn't inside a Git repo.
# Globals:
#   jartps1_gitdir      - Used to store result.
#   JARTPS1_GITDIR_TMP  - Temp file used to cache last failed search.
################################################################################
jartps1_gitdir_find() {
  local dir="$1"
  if [[ -z "${dir}" ]]; then
    dir="${PWD}"
    case "${dir}" in
      /)                              return 1 ;;
      /home/${USER})                  return 1 ;;
    esac
    if [[ -f "${JARTPS1_GITDIR_TMP}" ]]; then
      local notgit
      if read notgit <"${JARTPS1_GITDIR_TMP}" &>/dev/null; then
        if [[ "${dir}" == "${notgit}" ]]; then
          return 1
        fi
      fi
    fi
  fi
  if [[ -d "${dir}/.git" ]]; then
    jartps1_gitdir="${dir}"
  else
    local parent="${dir%/*}"
    if [[ -z "${parent}" ]]; then
      printf "%s" "$PWD" >"${JARTPS1_GITDIR_TMP}"
      return 1
    fi
    jartps1_gitdir_find "${parent}"
  fi
}

OSX Bash: White space being added before branch-name

Hey thanks for git-radar — It feels it's going to really boost my productivity here scanning through changes.

I have tried to install it and somehow and getting some white space before the branch name, any ideas?

Thanks in advance

PS1="(\$(git-radar --bash))$"

screen shot 2015-09-03 at 09 30 20

odd sed error on branches named with multiple / characters

I am receiving this error:

sed: 1: "s/%{\(\([^%^{^}]*\)\:\) ...": bad flag in substitute command: 't'

This is my PS1:

export PS1="\[\033[01;32m\]\j\[\033[00m\]|\[\033[01;34m\]\W\[\033[00m\] \$(git-radar --bash --fetch) 🍉 ";

This error occurs sporadically in and out of tmux, and I fully acknowledge that some other utility may be causing it. Any help is appreciated.

Cheers 🍻

Installation with ohmyzsh

Documentation says export PROMPT="$PROMPT$(git-radar --zsh --fetch) "
but $git-radar says export PROMPT="%1/%\$(git-radar --zsh --fetch) "

Is one of these not right?

Haven't been able to get either to work. Have tried sourcing .zshrc, reseting, restarting terminal and machine. Not recieving errors though.

Cheers!

Easier install

Why go to the trouble of installing a package through homebrew in order to customize PS1? What about Linux users?

Consider instead maintaining a "binary" release file in your repository. You could just have a makefile cat everything together, so long as you remember to run it before each commit.

Then your install instructions could be simple and transparent:

wget -O ~/.git-radar.bashrc https://raw.githubusercontent.com/michaeldfallen/git-radar/master/.git-radar.bashrc
sed -i -e '/.git-radar.bashrc/d' ~/.bashrc
echo source ~/.git-radar.bashrc >>~/.bashrc
source ~/.git-radar.bashrc

Duplicate branches pointing to same upstream

When you have two branches point to the same upstream branch you get the following message:

fatal: ambiguous argument 'origin/branch                                                                                               
origin/branch...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: ambiguous argument 'origin/branch
origin/branch...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

due to the remote_branch_name function having trouble finding which branch to follow

fatal error messages with git-radar on local untracked branches

$ git-radar --bash
fatal: ambiguous argument './master...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: ambiguous argument './master...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
 git:(some-branch)

pushing the branch remotely fixes the issue

$ git push -u origin some-branch
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:PagerDuty/web.git
 * [new branch]      some-branch -> some-branch
Branch some-branch set up to track remote branch some-branch from origin.
$ git-radar --bash
 git:(some-branch)

Some info about my system stats:
os x el capitan version 10.11.1
git version 2.6.2

Extraneous characters displayed in zsh output

I'm brand new to zsh, so this may be my mistake. The zsh examples given in the README and the usage message don't work for me, so I experimented and ended up using this:

%$(git-radar --zsh --fetch)

which results in this:

%{ git:(𝘮 34 ⇄ 65 feature/AUD-1140) 2A

note the '%{' at the beginning, which seems to be caused by the git-radar command, not by some other part of the prompt variable (this is a minimal working example). For what it's worth, within a longer PROMPT variable, the %{ is colored according to the preceding color escape codes.

This is on OS X Yosemite, in iTerm.

Add an argument to make the prompt more minimalistic (shorter)

First of all, git-radar is brilliant! 😃 Great Work!

I do notice that the prompt could get quite long, depending of the status of your git project. For example: git:(upstream ⚡long-named-branch xx) 1A 1D1M 1A1 could be a little long.

I wonder if people would be interested in adding an optional --minimal arg to the git-radar command, so when present, both the git: and the remote commits status (i.e: upstream ⚡) will not be shown. The reason i'm suggesting to hide the remote commits status is because i don't rely on it 100% of the time, but again, I'm curious to see what others think.

The other option could be for this --minimal arg to only hide the git: part, and then have another arg --no-remote-status that, if present, will hide the remote commits status part of the prompt.

I will be more than happy to help implementing this feature. Let me know what you think.

Cheers!

redirecting on OSX

Hey,

I installed via Homebrew and added the export path and got the following error when running source ~/.zshrc

nohup: redirecting stderr to stdout

Colors

A better color palette (or a collection of) to support existing terminal color themes would be very much appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.