git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #96136 from bdesham/fix-gitstatus-on-zsh

gitstatus: fix zsh integration

commit2be541ff7ce6bca74ddf7cbb54bbc9863011925b authorMartin Weinelt <mweinelt@users.noreply.github.com> dateThu 24 Sep 2020, 07:22 (6 years ago) parent028e05dc278c6f
1 file changed+52−2
pkgs/applications/version-management/git-and-tools/gitstatus/default.nix+52−2
pkgs/applications/version-management/git-and-tools/gitstatus/default.nix+52−2
@@ -1,4 +1,4 @@
1−{ callPackage, stdenv, fetchFromGitHub, ...}:
1+{ callPackage, stdenv, fetchFromGitHub, git, zsh, ...}:
22
33stdenv.mkDerivation rec {
44 pname = "gitstatus";
@@ -13,11 +13,61 @@ stdenv.mkDerivation rec {
1313
1414 buildInputs = [ (callPackage ./romkatv_libgit2.nix {}) ];
1515 patchPhase = ''
16− sed -i "1i GITSTATUS_DAEMON=$out/bin/gitstatusd" gitstatus.plugin.zsh
16+ sed -i '1i GITSTATUS_AUTO_INSTALL=''${GITSTATUS_AUTO_INSTALL-0}' gitstatus.plugin.zsh
17+ sed -i "1a GITSTATUS_DAEMON=$out/bin/gitstatusd" install
1718 '';
1819 installPhase = ''
1920 install -Dm755 usrbin/gitstatusd $out/bin/gitstatusd
2021 install -Dm444 gitstatus.plugin.zsh $out
22+ install -Dm555 install $out
23+ install -Dm444 build.info $out
24+ '';
25+ # Don't install the "install" and "build.info" files, which the end user
26+ # should not need to worry about.
27+ pathsToLink = [
28+ "/bin/gitstatusd"
29+ "/gitstatus.plugin.zsh"
30+ ];
31+
32+ # The install check sets up an empty Git repository and a minimal zshrc that
33+ # invokes gitstatus.plugin.zsh. It runs zsh against this zshrc and verifies
34+ # that the script was sourced successfully and that the "gitstatus_query"
35+ # command ran successfully. This tests the binary itself and the zsh
36+ # integration.
37+ installCheckInputs = [ git zsh ];
38+ doInstallCheck = true;
39+ installCheckPhase = ''
40+ TEMP=$(mktemp -d)
41+ cd "$TEMP"
42+
43+ git init
44+
45+ echo '
46+ GITSTATUS_LOG_LEVEL=DEBUG
47+ . $out/gitstatus.plugin.zsh || exit 1
48+
49+ gitstatus_stop NIX_TEST && gitstatus_start NIX_TEST
50+ gitstatus_query NIX_TEST
51+ if [[ $? -ne 0 ]]; then
52+ print -- "Something went wrong with gitstatus"
53+ exit 1
54+ elif [[ $VCS_STATUS_RESULT != "ok-sync" ]]; then
55+ print -- "Not in a Git repo"
56+ exit 1
57+ else
58+ print -- "OK"
59+ exit 0
60+ fi
61+ ' > .zshrc
62+
63+ # If we try to run zsh like "zsh -i -c true" or "zsh -i > output" then job
64+ # control will be disabled in the shell and the gitstatus plugin script
65+ # will fail when it tries to set the MONITOR option. As a workaround, we
66+ # run zsh as a full-fledged independent process and then wait for it to
67+ # exit. (The "exit" statements in the zshrc ensure that zsh will exit
68+ # almost immediately after starting.)
69+ ZDOTDIR=. zsh -i &
70+ wait $!
2171 '';
2272
2373 meta = with stdenv.lib; {