Commit Graph

59 Commits

Author SHA1 Message Date
Fabian Boehm
33c5cd5808 git prompt: Remove a useless use of math 2024-05-06 19:15:42 +02:00
Fabian Boehm
78c9482822 Reformat share/**.fish with newlines collapsed 2024-02-27 16:25:01 +01:00
Fabian Boehm
8667ed5c17 fish_git_prompt: Count type changes as dirty too
Fixes #10305
2024-02-17 08:37:22 +01:00
Fabian Boehm
4c1e25b141 fish_git_prompt: Add separator even if state is empty
This would leave off the separator if the repo was just bare or had
upstream difference, but no status (e.g. dirty) applied.

Fixes #10175
2023-12-30 19:38:22 +01:00
Fabian Boehm
5aaa1e69bc fish_git_prompt: Allow counting stash without full informative
Fixes #9572
2023-02-15 19:28:18 +01:00
matt wartell
904839dcce fix 3 instances of old command substitution $() 2023-02-12 16:49:40 +01:00
ridiculousfish
5e0f9521a5 fish_git_prompt: only do macOS workarounds for /usr/bin/git
On macOS, fish_git_prompt was failing to correctly handle the case where
another git was installed, e.g. /usr/local/bin/git from Homebrew.
Disable the workarounds in that case.
2023-01-02 12:26:56 -08:00
Johannes Altmanninger
a0840637fa fish_git_prompt: silence xcrun error when XCode is not installed
Our macOS workarounds involve running "xcrun" to check if Git is installed.
On a freshly upgraded Ventura system that does not have XCode or
CommandLineTools installed, "xcrun" will print this error:

    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

on every prompt. Let's silence this error.
2023-01-01 14:37:40 +01:00
Fabian Boehm
c844b974b3 fish_git_prompt: Silence disown
The `git` can already have finished here, leading to "disown: There
are no suitable jobs". This has caused a failure on Github Actions.

So we do $last_pid and silence all output, like we do in other spots
2022-12-28 14:21:24 +01:00
ridiculousfish
a77bc70def fish_git_prompt: be careful about invoking git on macOS
git on macOS has two hazards:

1. It comes "preinstalled" as a stub which pops a dialog to install
   command line developer tools.

2. It may populate the xcrun cache when run for the first time, which
   may take several seconds.

We fix these as follows, both fixes limited to Darwin:

1. If git is `/usr/bin/git` and `xcode-select --print-path` fails,
   then do not run git automatically.

2. Second, if there is no file at `xcrun --show-cache-path`, we take it
   as an indication that the cache is not yet populated. In this case we
   run `git` in the background to populate the cache.

Credit to @floam for the idea.

Fixes #9343. Fixes #6625.
2022-12-27 11:48:58 -08:00
Fabian Boehm
8d5198b9b4 fish_git_prompt: Fish show_upstream
This isn't a boolean option

Fixes #9301
2022-10-24 19:13:08 +02:00
Fabian Boehm
8c362c89b5
git prompt: Interpret values of "1", "yes" or "true" as true for bools instead of relying on defined-or-not (#9274)
This allows explicitly turning these settings off by setting the variable to e.g. 0.

See #7120
2022-10-21 20:22:20 +02:00
Fabian Boehm
d5db260375 Use string shorten for git
This checked the locale, but did so in a way that's fundamentally
broken:

1. $LANG isn't the only variable ($LC_ALL and $LC_CTYPE)
2. Even if $LANG is set that doesn't mean it's actually working

We could add a `status is-multibyte` here to figure out if we have a
multibyte locale?

But instead, since this is dealing with adding an ellipsis, let's just
add it to `string ellipsize`.

One slight difference is that shortening the branch now counts the ellipsis width.

I.e. assuming the branch is "long-branch-name"

```fish
set -g __fish_git_prompt_shorten_branch_len 8
```

might now print "long-br…" instead of "long-bra…". This is nicer because we can now give the actual maximum width.

The alternative is to add a "--exclusive" option to "string ellipsize" that doesn't count the ellipsis width. So `string ellipsize --char "..." --max 8" long-branch-name` might result in "long-bra...", which is 11 wide.
2022-09-09 18:49:57 +02:00
Fabian Boehm
a004a10a80 fish_git_prompt: Remove variables we don't care from event handler
This was called e.g. when showdirtystate was changed, but then checked
if it was called for the informative statusses only. Simply remove
them.
2022-06-21 20:22:27 +02:00
Fabian Homborg
3552a11afa fish_git_prompt: Print cleanstate character whenever it's defined
And then only define it in informative mode.
2022-06-08 21:23:43 +02:00
Fabian Homborg
ca9910edb7 fish_git_prompt: Add colors for dirty/staged branches
This is a neat feature of the terlar git prompt
2022-06-08 21:23:43 +02:00
Fabian Homborg
f9a170e5f2 git_prompt: Only show untracked files in informative mode if asked
This makes it so

1. The informative status can work without showing untracked
files (previously it was disabled if bash.showUntrackedFiles was
false)
2. If untrackedfiles isn't explicitly enabled, we use -uno, so git
doesn't have to scan all the files.

In a large repository (like the FreeBSD ports repo), this can improve
performance by a factor of 5 or up.
2022-06-07 13:30:03 +02:00
David Adam
a4749356ae fish_git_prompt: drop --ignored flag in git status
Arguments to --ignored were introduced in Git 2.16, from January 2018.

The git completions specifically work around this, allowing older
versions to be used; match this in the git prompt.

Fixes the tests on CentOS 7.
2022-06-02 15:50:43 +08:00
Fabian Homborg
661ea41861 fish_git_prompt: Use "dirty"/"staged" regex like informative
When switching this to use `git status`, I neglected to use the
correct definition of what a "dirty" and a "staged" change is.

So this now showed already staged files still as "dirty".

Fixes #8986
2022-06-01 17:24:08 +02:00
Fabian Homborg
542a78a4c3 fish_git_prompt: Use git status when showDirtystate is enabled
It's faster
2022-05-30 17:22:35 +02:00
ridiculousfish
37625053d4 fish_git_prompt: be careful about git config
fish_git_prompt may run certain git commands which may invoke certain
external programs as specified `.git/config`. Prevent this by suppressing
certain git config options.
2021-12-30 13:11:04 -08:00
Ilan Cosman
30400f3ced Use test command instead of bracket command 2021-11-26 16:55:50 -08:00
Ilan Cosman
566a673e4f Run fish_indent on all non-test .fish files 2021-11-23 09:49:45 +01:00
Aaron Gyes
f817dc7a76 fixup or/and typo 2021-10-22 12:55:43 -07:00
Aaron Gyes
374d580474 Combine 3 git config forks into one
fish_git_prompt duration improved from 76ms to 45ms here.
2021-10-22 12:45:39 -07:00
Aaron Gyes
46278d7137 remove for loops from git prompt event handlers 2021-10-22 09:05:18 -07:00
Fabian Homborg
56af5d0702 Revert "git prompt: Show stagedstate without dirtystate"
After further thinking, showing this now, by default, without a nice way to turn it off isn't great.

This reverts commit 573fed7798.
2021-04-13 19:10:04 +02:00
Fabian Homborg
4fa17bd512 git prompt: Don't compute bits we don't need 2021-04-13 16:44:46 +02:00
Fabian Homborg
573fed7798 git prompt: Show stagedstate without dirtystate
I have *no idea* why this was coupled, especially since dirtystate can
be expensive, staged state should not be.
2021-04-13 16:44:46 +02:00
Fabian Homborg
71166274a2 git prompt: Respect status_order even without informative status
Fixes #7926.

Also switches the default status order for non-informative to the informative one:

stagedstate invalidstate dirtystate untrackedfiles stashstate

instead of

dirty staged stash untracked
2021-04-13 16:44:46 +02:00
Fabian Homborg
a65933551d git prompt: Allow setting __fish_git_prompt_status_order
See #7926
2021-04-13 16:44:46 +02:00
Fabian Homborg
db7278bac6 git prompt: Remove that massive documentation block 2021-04-13 16:44:46 +02:00
Fabian Homborg
f75cf5c16b git prompt: Use status --porcelain for informative status
This allows us to stop descending into untracked directories, which
can be faster.

It's still not *good* - git can still be quite slow here, but if
there's an untracked directory you probably don't care about the
number of files in that.

Fixes #7871.
2021-03-30 17:51:34 +02:00
Fabian Homborg
76457bdc4e fish_git_prompt: Remove repaint from variable handlers
Because we removed repaint coalescing, currently setting any of the
git prompt variables in fish_prompt leads to a repaint loop (that
presumably aborts once it reaches the recursion limit).

Since repainting on these variables isn't really useful (when you
`set` them interactively you already get a new prompt), just remove
it.

There's two cases this "breaks":

- When you set a variable *after* the call to fish_git_prompt
- When you set a variable via a binding

In both of these it's not too much to expect an explicit "commandline
-f repaint", especially since for bindings that's already needed in
most cases, and setting a variable after using it isn't normal.

Fixes #7775.
2021-03-04 15:58:20 +01:00
Fabian Homborg
bc6414aaa8
!fixup fish_git_prompt: Fix variable name
This missed one use of $user_variable
2021-01-18 12:37:30 +01:00
Fabian Homborg
dbfd3b5c39 fish_git_prompt: Remove a few unneeded variables 2021-01-17 21:04:16 +01:00
Shawn LeMaster
e4b64448fa Don't assume $__fish_git_prompt_char_cleanstate is non-empty
This fixes the case where an empty "clean state" character
can cause a spurious space character at the end of the git prompt.
2020-11-10 18:55:15 +01:00
Johannes Altmanninger
eb59d4eb14 Run fish_indent on share/**.fish 2020-08-17 17:40:28 +02:00
Fabian Homborg
63f7f1925e git prompt: Simplify "staged" logic
This had this weird "pass along the sha, then check" logic to it which
is entirely unnecessary.

This function just says when something is staged, nothing more. Why
that is you can figure out for yourself.

This makes it easier to call this function, and it no longer prints an
empty line if nothing is staged.
2020-06-20 21:47:19 +02:00
Fabian Homborg
197d615cc8 git prompt: Minor cleanup 2020-06-20 19:01:27 +02:00
Fabian Homborg
4186d840db git prompt: Simplify some helper functions 2020-06-20 19:01:27 +02:00
Fabian Homborg
73c0fa03b8 git prompt: Also repaint correctly if use_informative_chars is set 2020-06-20 19:01:27 +02:00
Fabian Homborg
894ec3dfd4 fish_git_prompt: Always allow for displaying stashstate
This wasn't added to the prompt status order, so it was computed and
then not used for the informative prompt.

We still check later if we should compute it, so this is harmless if
showstashstate is unset.

Fixes #7136.
2020-06-20 09:33:04 +02:00
Fabian Homborg
ba116f1d3b fish_git_prompt: Count untracked files from the repository root
We already do this for the non-informative (non-counting) version.

Fixes #6086.
2020-05-28 20:49:48 +02:00
Charles Gould
8029f15f1f git prompt: better check for git stashes
When you run "git gc":

 - .git/refs/stash is deleted
 - .git/logs/refs/stash is kept intact
2020-04-10 00:22:16 +02:00
Fabian Homborg
9367d4ff71 Reindent functions to remove useless quotes
This does not include checks/function.fish because that currently
includes a "; end" in a message that indent would remove, breaking the test.
2020-03-09 19:46:43 +01:00
Fabian Homborg
427a18c1ea fish_git_prompt: Add a way to use the informative chars
$__fish_git_prompt_use_informative_chars will use the informative
chars without requiring informative mode (which is really frickin'
slow!).

See #5726.

[ci skip]
2019-06-25 16:11:18 +02:00
Fabian Homborg
d0921489ee fish_git_prompt: Fix changing show_informative_status
If you changed $__fish_git_prompt_show_informative_status, it
triggered a variable handler, which erased the chars, but neglected to
unset $___fish_git_prompt_init, so we just kept chugging along with
empty characters.

What's the hardest thing in CS again? Cache something something?

[ci skip]
2019-05-29 10:36:14 +02:00
Fabian Homborg
bcce6d691f Keep "; and" and "; or" on fish files
This reformats *.fish files from before commit
c2970f9618 with the changes to fish_indent.

[ci skip]
2019-05-05 13:34:38 +02:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00