From bc65fc853433558c15db0f29ed84e62b20114d82 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Sun, 8 Mar 2020 00:13:45 +0530 Subject: [PATCH] Added install script to install zoxide with cross-compatibility in a one-liner format. --- install.sh | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..5d7f1cf --- /dev/null +++ b/install.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +set -u + +usage() { + cat 1>&2 <&1 +} + +info() { + printf "%s\n" "$1" >&1 +} + +warning() { + printf "\033[33m%s\033[0m\n" "$1" >&2 +} + +error() { + printf "\033[31;1m%s\033[0m\n" "$1" >&2 + exit 1 +} + +cmd_chk() { + command -v "$1" >/dev/null 2>&1 +} + +## Ensures that the command executes without error +ensure() { + if ! "$@"; then error "command failed: $*"; fi +} + +need_cmd() { + if ! cmd_chk "$1"; then + error "need $1 (command not found)" + fi +} + +prompt_confirm() { + if [ ! -t 1 ]; then + error "Unable to run interactively. Please execute this script using interactive shell" + fi + + while true; do + read -rp "Is this okay? (y/N): " _choice + _choice=$(echo "$_choice" | tr '[:upper:]' '[:lower:]') + + case "$_choice" in + y | yes) break ;; + n | no) error "Operation aborted" ;; + esac + done +} + +cargo_build() { + success "Compiling from source..." + + if ! cmd_chk "cargo"; then + success "Cargo will be installed." + prompt_confirm + + ensure curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + + # shellcheck source=/dev/null + source "$HOME/.cargo/env" + fi + + RUSTFLAGS="-C target-cpu=native" ensure cargo install zoxide +} + +main "$@" || exit 1