diff --git a/README.md b/README.md index 97bc906..492f3e4 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Yes, macOS have optimized battery charging. It will try to find out your chargin > Currently, it is command-line only. Some knowledge of the command-line is recommended. A native GUI is possible but not planned. If you want to build a GUI, you can ask me to put a link here to your project -1. (Optional) If you are lazy, there is an installation script to help you get the first 3 steps done (Internet connection required). Put this in your terminal: `curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh | bash`. You may need to provide your password (to control charging). This will download and install the latest _stable_ version for you, then you can skip to step 5. +1. (Optional) If you are lazy, there is an installation script to help you get the first 3 steps done (Internet connection required). Put this in your terminal: `bash <(curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh)`. You may need to provide your password (to control charging). This will download and install the latest _stable_ version for you, then you can skip to step 5. 2. Get the binary. For _stable_ and _beta_ releases, you can find the download link in the [release page](https://github.com/charlie0129/batt/releases). If you want development versions with the latest features and bug fixes, you can download prebuilt binaries from [GitHub Actions](https://github.com/charlie0129/batt/actions/workflows/build-test-binary.yml) (has a retention period of 3 months and you need to `chmod +x batt` after extracting the archive) or [build it yourself](#building) . 3. Put the binary somewhere safe. You don't want to move it after installation :). It is recommended to save it in your `$PATH`, e.g., `/usr/local/bin`, so you can directly call `batt` on the command-line. In this case, the binary location will be `/usr/local/bin/batt`. 4. Install daemon using `sudo batt install`. If you do not want to use `sudo` every time after installation, add the `--allow-non-root-access` flag: `sudo batt install --allow-non-root-access`. To uninstall: please refer to [How to uninstall?](#how-to-uninstall) @@ -177,7 +177,7 @@ Automatic: > Updates to the latest _stable_ version. If you want to use other versions (_beta_, _development_), please use the manual method. ```bash -curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh | bash +bash <(curl -fsSL https://github.com/charlie0129/batt/raw/master/hack/install.sh) ``` Manual: diff --git a/cmd.go b/cmd.go index 30f1432..4513a3f 100644 --- a/cmd.go +++ b/cmd.go @@ -668,10 +668,13 @@ One thing to note: this option is purely cosmetic. batt will still function even } func bool2Text(b bool) string { + var c string if b { - return color.New(color.Bold, color.FgGreen).Sprint("✔") + c = "✔" + } else { + c = "✘" } - return bold("✘") + return bold(c) } func bold(format string, a ...interface{}) string { diff --git a/hack/install.sh b/hack/install.sh index 99ad964..5cf05e3 100755 --- a/hack/install.sh +++ b/hack/install.sh @@ -14,23 +14,15 @@ confirm() { echo -n "$1 [y/n]: " read -r -n 1 REPLY case $REPLY in - [y]) + [yY]) echo return 0 ;; - [n]) + [nN]) echo return 1 ;; - [Y]) - echo - return 0 - ;; - [N]) - echo - return 1 - ;; - *) printf "invalid input" ;; + *) printf " is invalid. Press 'y' to continue; 'n' to exit. \n" ;; esac done } @@ -43,6 +35,8 @@ launch_daemon="/Library/LaunchDaemons/cc.chlc.batt.plist" # Uninstall old versions (if present) if [[ -f "$launch_daemon" ]]; then + echo "You have old versions of batt installed, which need to be uninstalled before installing the latest version. We will uninstall it for you now." + confirm "Is this OK?" || exit 0 info "Stopping old versions of batt..." sudo launchctl unload "$launch_daemon" sudo rm -f "$launch_daemon" @@ -70,7 +64,7 @@ if [[ -z "$PREFIX" ]]; then fi echo "Will install batt ${version} to $PREFIX (to change install location, set \$PREFIX environment variable)." -confirm "Continue?" || exit 0 +confirm "Ready to install?" || exit 0 info "Downloading batt ${version} from $tarball_url and installing to $PREFIX..." sudo mkdir -p "$PREFIX" curl -fsSL "$tarball_url" | sudo tar -xzC "$PREFIX"