From c8764ae224161b4cf7865110aef828ec721ec1f5 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Sat, 21 Sep 2019 17:43:17 -0300 Subject: [PATCH] Warn about fzf if not installed (#27) Fix #13 --- navi | 10 ++-------- scripts/release | 12 +++--------- src/healthcheck.sh | 9 +++++++++ src/main.sh | 9 +++++++++ src/misc.sh | 8 ++++++++ test/core.sh | 3 +-- 6 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 src/healthcheck.sh diff --git a/navi b/navi index 33b6c48..99c8a05 100755 --- a/navi +++ b/navi @@ -3,14 +3,6 @@ set -euo pipefail export SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -source "${SCRIPT_DIR}/src/arg.sh" -source "${SCRIPT_DIR}/src/cheat.sh" -source "${SCRIPT_DIR}/src/docs.sh" -source "${SCRIPT_DIR}/src/misc.sh" -source "${SCRIPT_DIR}/src/selection.sh" -source "${SCRIPT_DIR}/src/str.sh" -source "${SCRIPT_DIR}/src/ui.sh" - source "${SCRIPT_DIR}/src/main.sh" ##? Command cheatsheet tool @@ -24,4 +16,6 @@ source "${SCRIPT_DIR}/src/main.sh" VERSION="0.6.1" docs::eval "$@" + +health::fzf main "$@" diff --git a/scripts/release b/scripts/release index b207590..8a77e0c 100755 --- a/scripts/release +++ b/scripts/release @@ -2,15 +2,7 @@ set -euo pipefail export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" -cd "$SCRIPT_DIR" - -command_exists () { - type "$1" &> /dev/null -} - -echoerr() { - echo "$@" 1>&2 -} +source "${SCRIPT_DIR}/src/main.sh" sha256() { if command_exists sha256sum; then @@ -30,6 +22,8 @@ header() { echo } +cd "$SCRIPT_DIR" + header "git pull" git pull diff --git a/src/healthcheck.sh b/src/healthcheck.sh new file mode 100644 index 0000000..90ed69d --- /dev/null +++ b/src/healthcheck.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +health::fzf() { + if ! command_exists fzf; then + echoerr "You need to install fzf before using navi" + echoerr "Please refer to https://github.com/junegunn/fzf for install instructions" + exit 66 + fi +} \ No newline at end of file diff --git a/src/main.sh b/src/main.sh index dbb8ac1..01cb9b9 100644 --- a/src/main.sh +++ b/src/main.sh @@ -1,6 +1,15 @@ #!/usr/bin/env bash set -euo pipefail +source "${SCRIPT_DIR}/src/arg.sh" +source "${SCRIPT_DIR}/src/cheat.sh" +source "${SCRIPT_DIR}/src/docs.sh" +source "${SCRIPT_DIR}/src/healthcheck.sh" +source "${SCRIPT_DIR}/src/misc.sh" +source "${SCRIPT_DIR}/src/selection.sh" +source "${SCRIPT_DIR}/src/str.sh" +source "${SCRIPT_DIR}/src/ui.sh" + main() { local readonly cheats="$(cheat::find)" local readonly selection="$(ui::select "$cheats")" diff --git a/src/misc.sh b/src/misc.sh index 29e1f7e..34157dd 100644 --- a/src/misc.sh +++ b/src/misc.sh @@ -4,3 +4,11 @@ dep() { : } + +command_exists () { + type "$1" &> /dev/null +} + +echoerr() { + echo "$@" 1>&2 +} diff --git a/test/core.sh b/test/core.sh index 726cdbf..6e9dcdc 100644 --- a/test/core.sh +++ b/test/core.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -source <( -grep -v 'main ' "${SCRIPT_DIR}/navi" | sed -E "s|export.*|export SCRIPT_DIR=\"${SCRIPT_DIR}\"|") +source "${SCRIPT_DIR}/src/main.sh" test::success() { echo "Test passed!"