@@ -1,9 +1,9 @@ #!/bin/sh # # An example hook script to verify if you are on battery, in case you-# are running Linux. Called by git-gc --auto with no arguments. The hook-# should exit with non-zero status after issuing an appropriate message-# if it wants to stop the auto repacking.+# are running Linux or OS X. Called by git-gc --auto with no arguments.+# The hook should exit with non-zero status after issuing an appropriate+# message if it wants to stop the auto repacking. # # This hook is stored in the contrib/hooks directory. Your distribution # may have put this somewhere else. If you want to use this hook, you
@@ -30,6 +30,9 @@ then elif grep -q '0x01$' /proc/apm 2>/dev/null then exit 0+elif test -x /usr/bin/pmset && (! /usr/bin/pmset -g batt | grep -q 'Battery Power' )+then+ exit 0 fi echo "Auto packing deferred; not on AC"
From: Jonathan del Strother <hidden> Date: 2016-06-15 22:45:24
On Fri, Sep 26, 2008 at 12:20 AM, Miklos Vajna [off-list ref] wrote:
On Tue, Sep 23, 2008 at 11:43:23PM +0100, Jonathan del Strother [off-list ref] wrote:
quoted
Shell scripting isn't my fortĂŠ, suggestions for improvements would be
welcome.
+elif test -x /usr/bin/pmset && (! /usr/bin/pmset -g batt | grep -q 'Battery Power' )
What about
+elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt | grep -q 'AC Power'
?
I was trying to handle pmset reporting anything other than Battery
Power (currently it reports either Battery, UPS, or AC), but thinking
about it, if you're on UPS, you probably don't want git gc eating into
your remaining power...
I'll post an updated version on Monday.
From: Jonathan del Strother <hidden> Date: 2016-06-15 22:45:25
Signed-off-by: Jonathan del Strother <redacted>
---
Second attempt - this simplifies the test while making it more specific (it will only pack when on AC power, rather than, say, UPS).
contrib/hooks/pre-auto-gc-battery | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
@@ -1,9 +1,9 @@ #!/bin/sh # # An example hook script to verify if you are on battery, in case you-# are running Linux. Called by git-gc --auto with no arguments. The hook-# should exit with non-zero status after issuing an appropriate message-# if it wants to stop the auto repacking.+# are running Linux or OS X. Called by git-gc --auto with no arguments.+# The hook should exit with non-zero status after issuing an appropriate+# message if it wants to stop the auto repacking. # # This hook is stored in the contrib/hooks directory. Your distribution # may have put this somewhere else. If you want to use this hook, you
@@ -30,6 +30,10 @@ then elif grep -q '0x01$' /proc/apm 2>/dev/null then exit 0+elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt |+ grep -q "Currently drawing from 'AC Power'"+then+ exit 0 fi echo "Auto packing deferred; not on AC"