Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt format string #65

Merged
merged 20 commits into from
Oct 15, 2015
Merged

Prompt format string #65

merged 20 commits into from
Oct 15, 2015

Conversation

michaeldfallen
Copy link
Owner

In response issues #62, #57, #54, #17 (so quite a lot of people) and pull request #40, which was an attempt to address some of these points, I have added the ability to describe the shape of the prompt fully through a format string.

You export this as GIT_RADAR_FORMAT or set it in your .gitradarrc file.

%{remote} - Output the remote status part
%{branch} - Output the branch name, or sha reference if detached
%{local} - Output the local commit diff
%{changes} - Output the file changes

With this you can create very flexible and unique prompt, for example:

${branch}%{local}%{changes} = master1↑1M
[${branch}] - %{local} - %{changes} = [master] - 1↑ - 1M

It also supports prefixes and suffixes that only output if there is something to output:

%{[prefix] :local: [suffix]} with no local commits would produce nothing

with local commits would produce [prefix] 1↑ [suffix]

It also supports both zsh colours and bash colour codes so you can colour the parts you add to the prompt really easily.

@michaeldfallen
Copy link
Owner Author

I haven't done any documentation yet but the basic functionality is working. I've also switched the basic prompt in prompt.zsh and prompt.bash to use the new render_prompt function and a default GIT_RADAR_FORMAT setting that mimics the original prompt shape.

@n10v
Copy link
Contributor

n10v commented Sep 17, 2015

Wow
Good idea
👍

@reicolina
Copy link
Contributor

👍 It looks good @michaeldfallen ! Thanks for taking the time to address these. 💪

@mcphailtom
Copy link

Looks great

@michaeldfallen
Copy link
Owner Author

Thanks guys. I want to run a few performance tests to make sure the extra subshells and sed command don't slow down too much.

@slackorama
Copy link
Contributor

This fails for me on Ubuntu:

render_prompt:12: failed to compile regex: Invalid content of \{\}                                                                                                                             
render_prompt:20: failed to compile regex: Invalid content of \{\}
render_prompt:28: failed to compile regex: Invalid content of \{\}
render_prompt:36: failed to compile regex: Invalid content of \{\}

This fixes it:

diff --git a/radar-base.sh b/radar-base.sh
index d5456d0..464ac45 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -494,8 +494,8 @@ render_prompt() {
   local_sed=""
   changes_sed=""

-  if_pre="%{([^%{}]{1,}:){0,1}"
-  if_post="(:[^%{}]{1,}){0,1}}"
+  if_pre="%\{([^%{}]{1,}:){0,1}"
+  if_post="(:[^%{}]{1,}){0,1}\}"
   sed_pre="%{\(\([^%^{^}]*\)\:\)\{0,1\}"
   sed_post="\(\:\([^%^{^}]*\)\)\{0,1\}}"

@n10v
Copy link
Contributor

n10v commented Oct 7, 2015

And when will be git-radar update with this feature?

@michaeldfallen
Copy link
Owner Author

@BoGeM sorry, I've been away on honeymoon and my new wife wouldn't much like it if I spent the time coding. Back now and I'm going to look in to this and merge soon. Just looking in to the performance and the bug @slackorama mentioned above.

@slackorama
Copy link
Contributor

Congrats on the marriage! Tell your wife I said thanks for git-radar. It's a huge time saver.

I found another issue in this branch. If your branch has a slash in it (if you use git-flow branches are named "feature/some_cool_fix"), it will break the sed commands:

This works as a fix for me:

@@ -508,7 +508,7 @@ render_prompt() {
     fi
   fi
   if [[ $PROMPT_FORMAT =~ ${if_pre}branch${if_post} ]]; then
-    branch_result="$(readable_branch_name)"
+    branch_result="$(readable_branch_name | sed -e 's/\//\\\//')"
     if [[ -n "$branch_result" ]]; then
       branch_sed="s/${sed_pre}branch${sed_post}/\2${branch_result}\4/"
     else

Let me know if you want me to put together a PR or not.

@michaeldfallen
Copy link
Owner Author

@slackorama thanks :-) and good catch. This was a major change so thanks for flushing out the bugs. I've created performance tests in master and run them on this, doesn't seem to slow down much, 10ms at most. The real slow down is git status --porcelain which I think I need to async at some point but that's out of scope for this.

@michaeldfallen
Copy link
Owner Author

I've added the fixes by @slackorama so I think this is good to go.

@michaeldfallen
Copy link
Owner Author

Readme looks good enough for now -> merging :shipit:

michaeldfallen added a commit that referenced this pull request Oct 15, 2015
@michaeldfallen michaeldfallen merged commit 5640131 into master Oct 15, 2015
@michaeldfallen michaeldfallen deleted the format-string branch October 15, 2015 11:26
@n10v
Copy link
Contributor

n10v commented Oct 15, 2015

Supeer

@michaeldfallen
Copy link
Owner Author

inakiabt added a commit to inakiabt/git-radar that referenced this pull request Oct 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants