From 1ef63d7ad8c7200aa6d07b86ac5f4d321e18c186 Mon Sep 17 00:00:00 2001 From: "Deavon M. McCaffery" Date: Wed, 30 Dec 2020 03:28:14 +0000 Subject: [PATCH] feat: add support for derived platforms (like popos) --- install.sh | 60 ++++++++++++++++++-------------- src/bash/scripts/eval/source-os | 34 +++++++++++------- src/sh/scripts/eval/source-os | 34 +++++++++++------- src/sh/scripts/use-shell | 61 +++++++++++++++++++++++---------- src/zsh/scripts/eval/source-os | 34 +++++++++++------- 5 files changed, 140 insertions(+), 83 deletions(-) diff --git a/install.sh b/install.sh index 671313d..b6bbaf8 100755 --- a/install.sh +++ b/install.sh @@ -4,23 +4,23 @@ set -e SCRIPT_DIR=${2:-$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)} -CLR_SUCCESS="\033[1;32m" # BRIGHT GREEN -CLR_WARN="\033[1;33m" # BRIGHT YELLOW -CLR_CLEAR="\033[0m" # DEFAULT COLOR -ECHO='echo' +export CLR_SUCCESS="\033[1;32m" # BRIGHT GREEN +export CLR_WARN="\033[1;33m" # BRIGHT YELLOW +export CLR_CLEAR="\033[0m" # DEFAULT COLOR +export ECHO='echo' -HOMEBREW_NO_AUTO_UPDATE=1 +export HOMEBREW_NO_AUTO_UPDATE=1 # when not outputing to a tty, add spacing instead of colors if [ ! -t 1 ]; then - CLR_SUCCESS="\n------------------------------------------------------------------------------------------------------------------------\n" - CLR_WARN=$CLR_SUCCESS - CLR_CLEAR=$CLR_SUCCESS - ECHO='printf' + export CLR_SUCCESS="\n------------------------------------------------------------------------------------------------------------------------\n" + export CLR_WARN=$CLR_SUCCESS + export CLR_CLEAR=$CLR_SUCCESS + export ECHO='printf' fi -AM_HOME="$HOME/.am" -AM_PROMPT="$AM_HOME/prompt" +export AM_HOME="$HOME/.am" +export AM_PROMPT="$AM_HOME/prompt" __am_prompt_success() { $ECHO "${CLR_SUCCESS}prompt-install: $1${CLR_CLEAR}" @@ -80,19 +80,29 @@ __am_prompt_install() { fi done - local UNAME=$(uname | tr '[:upper:]' '[:lower:]') - local UNAME_INSTALL="$UNAME.sh" - if [ -f /etc/os-release ]; then . /etc/os-release - - local UNAME_INSTALL="$ID.sh" + local UNAMES="$ID $ID_LIKE" + else + local UNAMES=$(uname | tr '[:upper:]' '[:lower:]') fi - if [ -f "$AM_PROMPT/sh/install/$UNAME_INSTALL" ]; then - __am_prompt_success "installing platform prerequisites ($UNAME_INSTALL)" - . "$AM_PROMPT/sh/install/$UNAME_INSTALL" - fi + local UNAME= + until [ "$UNAME" = "$UNAMES" ]; do + local UNAME=${UNAMES%%' '*} + local UNAMES=${UNAMES#*' '} + + local UNAME_PATH="$AM_PROMPT/sh/install/$UNAME.sh" + + if [ ! -f "$UNAME_PATH" ]; then + continue + fi + + __am_prompt_success "installing platform prerequisites ($UNAME)" + . "$UNAME_PATH" + + break + done if [ ! -d "$AM_PROMPT/zsh/completions" ]; then mkdir -p "$AM_PROMPT/zsh/completions" 1>/dev/null @@ -128,16 +138,16 @@ __am_prompt_install() { local PROMPT_SHELL=$(echo $PROMPT_SHELL | tr '[:upper:]' '[:lower:]') # use the correct shell - . "$AM_PROMPT/sh/scripts/use-shell" $PROMPT_SHELL + "$AM_PROMPT/sh/scripts/use-shell" $PROMPT_SHELL # open the changelog url - . "$AM_PROMPT/sh/scripts/open-url" "https://github.com/automotivemastermind/prompt/blob/$PROMPT_SHA/CHANGELOG.md" + "$AM_PROMPT/sh/scripts/open-url" "https://github.com/automotivemastermind/prompt/blob/$PROMPT_SHA/CHANGELOG.md" } -echo -echo "${CLR_WARN}prompt: establishing sudo (you may be prompted for credentials)...${CLR_CLEAR}" +$ECHO +$ECHO "${CLR_WARN}prompt: establishing sudo (you may be prompted for credentials)...${CLR_CLEAR}" sudo echo -trap 'echo; echo; echo "${CLR_WARN}prompt: terminating install...${CLR_CLEAR}"; exit -1;' INT +trap '$ECHO; $ECHO; $ECHO "${CLR_WARN}prompt: terminating install...${CLR_CLEAR}"; exit 1;' INT __am_prompt_install $@ diff --git a/src/bash/scripts/eval/source-os b/src/bash/scripts/eval/source-os index 3b9d360..3477a48 100755 --- a/src/bash/scripts/eval/source-os +++ b/src/bash/scripts/eval/source-os @@ -2,27 +2,35 @@ __am_prompt_source_os() { - local UNAME=$(uname | tr '[:upper:]' '[:lower:]') - local UNAME_PATH="$HOME/.am/prompt/bash/scripts/$UNAME" - if [ -f /etc/os-release ]; then . /etc/os-release + local UNAMES="$ID $ID_LIKE" + else + local UNAMES=$(uname | tr '[:upper:]' '[:lower:]') + fi + + local UNAME= + until [ "$UNAME" = "$UNAMES" ]; do + local UNAME=${UNAMES%%' '*} + local UNAMES=${UNAMES#*' '} - local UNAME="$ID" local UNAME_PATH="$HOME/.am/prompt/bash/scripts/$UNAME" - fi - if [ -d "$UNAME_PATH" ]; then + if [ ! -d "$UNAME_PATH" ]; then + continue + fi + + export AM_PROMPT_OS=$UNAME export PATH="$UNAME_PATH:$PATH" - fi - if [ -d "$UNAME_PATH/eval" ]; then - for EVAL_SCRIPT in $UNAME_PATH/eval/*; do - . "$EVAL_SCRIPT" - done - fi + if [ -d "$UNAME_PATH/eval" ]; then + for EVAL_SCRIPT in $UNAME_PATH/eval/*; do + . "$EVAL_SCRIPT" + done + fi - export AM_PROMPT_OS=$UNAME + break + done } __am_prompt_source_os diff --git a/src/sh/scripts/eval/source-os b/src/sh/scripts/eval/source-os index 7380024..92211d4 100755 --- a/src/sh/scripts/eval/source-os +++ b/src/sh/scripts/eval/source-os @@ -2,27 +2,35 @@ __am_prompt_source_os() { - local UNAME=$(uname | tr '[:upper:]' '[:lower:]') - local UNAME_PATH="$HOME/.am/prompt/sh/scripts/$UNAME" - if [ -f /etc/os-release ]; then . /etc/os-release + local UNAMES="$ID $ID_LIKE" + else + local UNAMES=$(uname | tr '[:upper:]' '[:lower:]') + fi + + local UNAME= + until [ "$UNAME" = "$UNAMES" ]; do + local UNAME=${UNAMES%%' '*} + local UNAMES=${UNAMES#*' '} - local UNAME="$ID" local UNAME_PATH="$HOME/.am/prompt/sh/scripts/$UNAME" - fi - if [ -d "$UNAME_PATH" ]; then + if [ ! -d "$UNAME_PATH" ]; then + continue + fi + + export AM_PROMPT_OS=$UNAME export PATH="$UNAME_PATH:$PATH" - fi - if [ -d "$UNAME_PATH/eval" ]; then - for EVAL_SCRIPT in $UNAME_PATH/eval/*; do - . "$EVAL_SCRIPT" - done - fi + if [ -d "$UNAME_PATH/eval" ]; then + for EVAL_SCRIPT in $UNAME_PATH/eval/*; do + . "$EVAL_SCRIPT" + done + fi - export AM_PROMPT_OS=$UNAME + break + done } __am_prompt_source_os diff --git a/src/sh/scripts/use-shell b/src/sh/scripts/use-shell index df422ac..044a6f4 100755 --- a/src/sh/scripts/use-shell +++ b/src/sh/scripts/use-shell @@ -3,11 +3,11 @@ __am_prompt_use_shell() { local PROMPT_SHELL=$1 - local ECHO=${ECHO:-"echo"} + ECHO=${ECHO:-"echo"} if [ -z "${PROMPT_SHELL:-}" ]; then - echo "${CLR_FAIL}You must specify a shell to use, either bash or zsh.${CLR_CLEAR}" - exit 1 + $ECHO "${CLR_FAIL}You must specify a shell to use, either bash or zsh.${CLR_CLEAR}" + return 1 fi if [ -f /opt/homebrew/bin/brew ]; then @@ -21,40 +21,63 @@ __am_prompt_use_shell() { fi local PROMPT_SHELL_PATH="$LOCAL_PREFIX/bin/$PROMPT_SHELL" - local UNAME=$(uname | tr '[:upper:]' '[:lower:]') - local UNAME_INSTALL="$UNAME.sh" + local INSTALL_PATH="$AM_PROMPT/$PROMPT_SHELL/install" if [ -f /etc/os-release ]; then . /etc/os-release - - local UNAME_INSTALL="$ID.sh" + local UNAMES="$ID $ID_LIKE" + else + local UNAMES=$(uname | tr '[:upper:]' '[:lower:]') fi - if [ -f "$AM_PROMPT/$PROMPT_SHELL/install/$UNAME_INSTALL" ]; then - . "$AM_PROMPT/$PROMPT_SHELL/install/$UNAME_INSTALL" + local UNAME= + until [ "$UNAME" = "$UNAMES" ]; do + local UNAME=${UNAMES%%' '*} + local UNAMES=${UNAMES#*' '} + + local UNAME_PATH="$INSTALL_PATH/$UNAME.sh" + + if [ ! -f "$UNAME_PATH" ]; then + continue + fi + done + + if [ ! -f "$UNAME_PATH" ]; then + $ECHO "${CLR_WARN}prompt: shell cannot be installed on this platform." + $ECHO "Please open an issue to request support for this distribution.${CLR_CLR}" + return 1 fi + . "$UNAME_PATH" + if ! grep "$PROMPT_SHELL_PATH" /etc/shells 1>/dev/null 2>&1; then - echo "${CLR_SUCCESS}adding updated $PROMPT_SHELL to shells...${CLR_CLEAR}" + $ECHO "${CLR_SUCCESS}adding updated $PROMPT_SHELL to shells...${CLR_CLEAR}" sudo sh -c "echo $PROMPT_SHELL_PATH >> /etc/shells" fi if [ "$SHELL" != "$PROMPT_SHELL_PATH" ]; then - echo "${CLR_SUCCESS}setting updated $PROMPT_SHELL to default shell for user...${CLR_CLEAR}" + $ECHO "${CLR_SUCCESS}setting updated $PROMPT_SHELL to default shell for user...${CLR_CLEAR}" sudo chsh -s $PROMPT_SHELL_PATH $(whoami) # set the default shell for the current session export SHELL="$PROMPT_SHELL_PATH" fi - echo "${CLR_SUCCESS}" - echo "##############################################################################" - echo "##############################################################################" - echo " # \$SHELL will be $SHELL" - echo " PLEASE RUN: exec -l \$SHELL" - echo "##############################################################################" - echo "##############################################################################" - echo "${CLR_CLEAR}" + $ECHO "${CLR_SUCCESS}" + $ECHO "##############################################################################" + $ECHO "##############################################################################" + $ECHO " NOTE: to take advantage of the symbols used by the shell, please set" + $ECHO " the terminal font to 'FiraCode Nerd Font Mono'. If you are using" + $ECHO " either macOS terminal or gnome terminal, you can do this" + $ECHO " automatically by loading a `theme`." + $ECHO + $ECHO " \$SHELL will be $SHELL" + $ECHO " PLEASE RUN THE FOLLOWING TO START USING THE NEW SHELL:" + $ECHO + $ECHO " exec \$SHELL -l" + $ECHO "##############################################################################" + $ECHO "##############################################################################" + $ECHO "${CLR_CLEAR}" } __am_prompt_use_shell $@ diff --git a/src/zsh/scripts/eval/source-os b/src/zsh/scripts/eval/source-os index 1e0d9c9..3b94465 100755 --- a/src/zsh/scripts/eval/source-os +++ b/src/zsh/scripts/eval/source-os @@ -2,27 +2,35 @@ __am_prompt_source_os() { - local UNAME=$(uname | tr '[:upper:]' '[:lower:]') - local UNAME_PATH="$HOME/.am/prompt/zsh/scripts/$UNAME" - if [ -f /etc/os-release ]; then . /etc/os-release + local UNAMES="$ID $ID_LIKE" + else + local UNAMES=$(uname | tr '[:upper:]' '[:lower:]') + fi + + local UNAME= + until [ "$UNAME" = "$UNAMES" ]; do + local UNAME=${UNAMES%%' '*} + local UNAMES=${UNAMES#*' '} - local UNAME="$ID" local UNAME_PATH="$HOME/.am/prompt/zsh/scripts/$UNAME" - fi - if [ -d "$UNAME_PATH" ]; then + if [ ! -d "$UNAME_PATH" ]; then + continue + fi + + export AM_PROMPT_OS=$UNAME export PATH="$UNAME_PATH:$PATH" - fi - if [ -d "$UNAME_PATH/eval" ]; then - for EVAL_SCRIPT in $UNAME_PATH/eval/*; do - . "$EVAL_SCRIPT" - done - fi + if [ -d "$UNAME_PATH/eval" ]; then + for EVAL_SCRIPT in $UNAME_PATH/eval/*; do + . "$EVAL_SCRIPT" + done + fi - export AM_PROMPT_OS=$UNAME + break + done } __am_prompt_source_os