Skip to content

Commit

Permalink
feat: add support for derived platforms (like popos)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccaffery committed Jan 5, 2021
1 parent 19c07ee commit 1ef63d7
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 83 deletions.
60 changes: 35 additions & 25 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 $@
34 changes: 21 additions & 13 deletions src/bash/scripts/eval/source-os
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 21 additions & 13 deletions src/sh/scripts/eval/source-os
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 42 additions & 19 deletions src/sh/scripts/use-shell
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 $@
34 changes: 21 additions & 13 deletions src/zsh/scripts/eval/source-os
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1ef63d7

Please sign in to comment.