-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add zsh and dash support to prompt (#32)
* restructure prompt repository to allow switching shells between: * sh/dash * bash * zsh * move most scripts that are shell agnostic to sh and update shebang * maintain feature parity between bash / zsh for: * prompt * color support * shell options * tab completion (including case-insensitive secondary match) * update documentation for updated installation * add `use-bash` command to enable changing the default shell to bash * add `use-zsh` command to enable changing the default shell to zsh * add `dark-mode` theme for macOS * add support for installing older versions of prompt through bootstrap and `update-prompt` commands NOTES: Adding support for zsh allows new installations of macOS Catalina to use the default shell, which was switched to zsh for this release. Future builds of macOS are likely to drop built-in support for bash due to the GPLv3 license. When bootstrapping prompt from bash; prompt will update and use bash. When bootstrapping prompt from zsh; prompt will update and use zsh. When bootstrapping from any other shell, prompt will use bash by default. A command line argument can be used to to select the prompt at install time. Switching prompts can be done via new `use-bash` and `use-zsh` commands. BREAKING CHANGE: While this is not an actual breaking change, quite a bit has changed with regard to how prompt actually works. We want to notify users that this may result is some level of bugs as test coverage of scripts like this one is incredibly difficult.
- Loading branch information
1 parent
6e55c54
commit 275f62c
Showing
135 changed files
with
2,013 additions
and
692 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,10 @@ | |
|
||
artifacts/ | ||
node_modules/ | ||
docker/ | ||
|
||
*.md | ||
*.lock | ||
*.json | ||
CODEOWNERS | ||
LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,103 @@ | ||
#!/usr/bin/env bash | ||
#!/usr/bin/env sh | ||
|
||
__am-prompt-bootstrap() | ||
set -e | ||
|
||
__am_prompt_update() | ||
{ | ||
local CURL_OPT='-s' | ||
if [ ! -z "${GH_TOKEN:-}" ]; then | ||
CURL_OPT='$CURL_OPT -H "Authorization: token $GH_TOKEN"' | ||
local CLR_FAIL=${CLR_FAIL:-"\033[1;31m"} # BRIGHT RED | ||
local CLR_SUCCESS=${CLR_SUCCESS:-"\033[1;32m"} # BRIGHT GREEN | ||
local CLR_WARN=${CLR_WARN:-"\033[1;33m"} # BRIGHT YELLOW | ||
local CLR_CLEAR=${CLR_CLEAR:-"\033[0m"} # DEFAULT COLOR | ||
|
||
local GH_TOKEN=${GH_TOKEN:-} | ||
local PROMPT_TOKEN=${PROMPT_TOKEN:-} | ||
local PROMPT_TOKEN=${PROMPT_TOKEN:-$GH_TOKEN} | ||
local PROMPT_CURL_OPT=${PROMPT_CURL_OPT:-'-s'} | ||
local PROMPT_COMMIT_REF=${PROMPT_COMMIT_REF:-"master"} | ||
local PROMPT_SHELL=${PROMPT_SHELL:-"bash"} | ||
local PROMPT_DRY_RUN=${PROMPT_DRY_RUN:-} | ||
|
||
while :; do | ||
case $1 in | ||
-t|--token) | ||
PROMPT_TOKEN=$2 | ||
shift | ||
;; | ||
-v|--version) | ||
PROMPT_COMMIT_REF=$2 | ||
shift | ||
;; | ||
-dr|--dry-run) | ||
PROMPT_DRY_RUN=1 | ||
;; | ||
-f|--force) | ||
rm -rf "$HOME/.am/prompt/.sha" 1>/dev/null 2>&1 | ||
;; | ||
--debug) | ||
set -x | ||
;; | ||
?*) | ||
PROMPT_SHELL=$1 | ||
;; | ||
*) | ||
break | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ ! -z "${PROMPT_TOKEN:-}" ]; then | ||
PROMPT_CURL_OPT='$PROMPT_CURL_OPT -H "Authorization: token $PROMPT_TOKEN"' | ||
fi | ||
|
||
local SHA_URI="https://api.github.com/repos/automotiveMastermind/prompt/commits/master" | ||
local PROMPT_SHA=$(curl $CURL_OPT $SHA_URI | grep sha | head -n 1 | sed 's#.*\:.*"\(.*\).*",#\1#') | ||
local SHA_PATH=$HOME/.am/prompt/$PROMPT_SHA | ||
local PROMPT_SHA_URI="https://api.github.com/repos/automotiveMastermind/prompt/commits/$PROMPT_COMMIT_REF" | ||
local PROMPT_SHA=$(curl $PROMPT_CURL_OPT $PROMPT_SHA_URI | grep sha | head -n 1 | sed 's#.*\:.*"\(.*\).*",#\1#') | ||
|
||
if [ -f $SHA_PATH ]; then | ||
echo "prompt: latest version already installed: $PROMPT_SHA" | ||
exit 0 | ||
# detect if sha could be located | ||
if [ -z ${PROMPT_SHA:-} ]; then | ||
echo "${CLR_FAIL}prompt: cannot retrieve SHA of latest version. Are you connected to the internet?${CLR_CLEAR}" | ||
return 1 | ||
fi | ||
|
||
local INSTALL_URI="https://github.com/automotiveMastermind/prompt/archive/master.tar.gz" | ||
local INTALL_TEMP=$(mktemp -d) | ||
local EXTRACT_TEMP="$INTALL_TEMP/extract" | ||
local PROMPT_SHA_PATH=$HOME/.am/prompt/.sha | ||
|
||
pushd $INTALL_TEMP 1>/dev/null | ||
curl -skL $INSTALL_URI | tar zx | ||
# detect if sha file exists | ||
if [ -f "$PROMPT_SHA_PATH" ]; then | ||
|
||
# get the value of the sha file | ||
PROMPT_CURRENT_SHA=$(cat "$PROMPT_SHA_PATH") | ||
|
||
# print latest version already installed | ||
if [ "${PROMPT_SHA}" = "${PROMPT_CURRENT_SHA}" ]; then | ||
echo "${CLR_SUCCESS}prompt: latest version already installed: ${PROMPT_SHA}.${CLR_CLEAR}" | ||
echo " - run update-prompt with the --force flag to reinstall ${CLR_CLEAR}" | ||
exit 0 | ||
fi | ||
fi | ||
|
||
if [ ! -z "${PROMPT_DRY_RUN:-}" ]; then | ||
echo "${CLR_WARN}prompt: a new version of prompt is available: ${PROMPT_SHA}." | ||
echo " - run the update-prompt command line tool to upgrade${CLR_CLEAR}" | ||
return 0 | ||
fi | ||
|
||
remove-backup | ||
|
||
local PROMPT_CHANGELOG_URI="https://github.com/automotivemastermind/prompt/blob/$PROMPT_COMMIT_REF/CHANGELOG.md" | ||
local PROMPT_INSTALL_URI="https://github.com/automotiveMastermind/prompt/archive/$PROMPT_COMMIT_REF.tar.gz" | ||
local PROMPT_INTALL_TEMP=$(mktemp -d) | ||
local PROMPT_EXTRACT_TEMP="$PROMPT_INTALL_TEMP/extract" | ||
|
||
pushd $PROMPT_INTALL_TEMP 1>/dev/null | ||
curl -skL $PROMPT_INSTALL_URI | tar zx | ||
pushd prompt-master 1>/dev/null | ||
./install.sh | ||
./install.sh $PROMPT_SHELL | ||
popd 1>/dev/null | ||
popd 1>/dev/null | ||
|
||
rm -rf $INTALL_TEMP 1>/dev/null | ||
rm -rf $PROMPT_INTALL_TEMP 1>/dev/null | ||
|
||
open-url $CHANGELOG_URI 1>/dev/null | ||
} | ||
|
||
__am-prompt-bootstrap | ||
__am_prompt_update $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.