Skip to content

Commit

Permalink
feat(prompt): enable user-defined marker
Browse files Browse the repository at this point in the history
  • Loading branch information
Deavon M. McCaffery committed Apr 11, 2017
1 parent a3c0e21 commit 2c63a54
Show file tree
Hide file tree
Showing 25 changed files with 344 additions and 258 deletions.
213 changes: 109 additions & 104 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,136 +3,141 @@
CLR_SUCCESS="\033[1;32m" # BRIGHT GREEN
CLR_CLEAR="\033[0m" # DEFAULT COLOR

AM_PATH="$HOME/.am"
AM_PROMPT="$AM_PATH/prompt"

PB_PATH="$HOME/.pulsebridge"
PB_PROMPT="$PB_PATH/prompt"

success() {
echo -e "${CLR_SUCCESS}$1${CLR_CLEAR}"
__prompt-success() {
echo -e "${CLR_SUCCESS}prompt-install: $1${CLR_CLEAR}"
}

if [ -d $PB_PROMPT ]; then
if [ -d $AM_PROMPT ]; then
cp -R $PB_PROMPT/* $AM_PROMPT/ 1>/dev/null
rm -rf $PB_PROMPT
else
mkdir -p $AM_PROMPT 1>/dev/null
mv $PB_PROMPT $AM_PROMPT 1>/dev/null
fi
fi
__prompt-install() {
local AM_HOME="$HOME/.am"
local AM_PROMPT="$AM_HOME/prompt"

now=$(date +"%Y%m%d_%H%M%S")
backup_path="$AM_PATH/backup/prompt/$now"
local NOW=$(date +"%Y%m%d_%H%M%S")
local BACKUP_PATH="$AM_HOME/backup/prompt/$NOW"

success "Creating backup path : $backup_path..."
mkdir -p "$backup_path" 1>/dev/null
__prompt-success "creating backup path: $BACKUP_PATH"
mkdir -p "$BACKUP_PATH" 1>/dev/null

if [ -d $AM_PROMPT ]; then
success "Backing up $AM_PROMPT..."
cp -R $AM_PROMPT/* "$backup_path" 1>/dev/null
for template in template/*; do
local name=$(basename "$template")
local path="$HOME/.${name}"

success "Removing $AM_PROMPT..."
rm -rf $AM_PROMPT 1>/dev/null
fi
if [ -f "$path" ]; then
__prompt-success "backing up ${name}"
cp "$path" "$BACKUP_PATH/$name"
fi

success "Creating $AM_PROMPT..."
mkdir -p $AM_PROMPT/bin 1>/dev/null
cat "$template" > "$path"
done

success "Installing promptMastermind to $AM_PROMPT..."
cp -Rf src/* $AM_PROMPT 1>/dev/null
if [ -d $AM_PROMPT ]; then
__prompt-success "backing up $AM_PROMPT"
cp -R $AM_PROMPT/* "$BACKUP_PATH" 1>/dev/null

__prompt-success "removing $AM_PROMPT"
rm -rf "$AM_PROMPT/git" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/scripts" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/themes" 1>/dev/null 2>&1
rm -f "$AM_PROMPT/bashrc" 1>/dev/null 2>&1
fi

if [ -f $backup_path/scripts/bookmarks.sh ]; then
success "Restoring bookmarks..."
cp -R $backup_path/scripts/bookmarks.sh $AM_PROMPT/scripts 1>/dev/null
fi
__prompt-success "creating $AM_PROMPT"
mkdir -p "$AM_PROMPT/user" 1>/dev/null 2>&1

__prompt-success "installing promptMastermind to $AM_PROMPT"
cp -Rf src/git "$AM_PROMPT" 1>/dev/null
cp -Rf src/scripts "$AM_PROMPT" 1>/dev/null
cp -Rf src/themes "$AM_PROMPT" 1>/dev/null
cp -f src/bashrc "$AM_PROMPT" 1>/dev/null

for useritem in src/user/*; do
local name=$(basename "$useritem")
local path="$AM_PROMPT/user/$name"

if [ ! -f "$path" ]; then
__prompt-success "initializing user profile: $name at $path"
cp "$useritem" "$path"
fi
done

if type brew 1>/dev/null 2>&1; then
local LOCAL_PREFIX=$(brew --prefix)
elif [ -d $LOCALAPPDATA/git ]; then
local LOCAL_PREFIX=$(echo "/$LOCALAPPDATA/git" | sed -e 's/\\/\//g' -e 's/://')
else
local LOCAL_PREFIX=/usr/local
fi

if [ -f $backup_path/scripts/variables.sh ]; then
success "Restoring variables..."
cp -R $backup_path/scripts/variables.sh $AM_PROMPT/scripts 1>/dev/null
fi
local BASH_COMPLETION="$LOCAL_PREFIX/etc/bash_completion.d"
local UNAME=$(uname)
local UNAME_INSTALL="./uname/install-$UNAME.sh"

for template in template/*; do
name=$(basename "$template")
path=$HOME/.${name}
if [ -e /etc/os-release ]; then
source /etc/os-release

if [ -f $path ]; then
success "Backing up ${name}..."
cp $path $backup_path/$name
local UNAME_INSTALL="./uname/install-$ID.sh"
fi

cat $template > $path
done

LOCAL_PREFIX=/usr/local
BASH_COMPLETION=$LOCAL_PREFIX/etc/bash_completion.d
UNAME=$(uname)
UNAME_INSTALL="./uname/install-$UNAME.sh"

if [ -e /etc/os-release ]; then
source /etc/os-release
if [ -f "$UNAME_INSTALL" ]; then
source "$UNAME_INSTALL"
fi

UNAME_INSTALL="./uname/install-$ID.sh"
fi
local GIT_PROMPT_NAME=git-prompt.sh
local GIT_COMPLETE_NAME=git-flow-completion.bash
local GIT_PROMPT_URI=https://raw.githubusercontent.com/lyze/posh-git-sh/master/$GIT_PROMPT_NAME
local GIT_COMPLETE_URI=https://raw.githubusercontent.com/petervanderdoes/git-flow-completion/develop/$GIT_COMPLETE_NAME
local PROMPT_COMPLETION="$AM_PROMPT/completions"

if [ -f $UNAME_INSTALL ]; then
source $UNAME_INSTALL
fi
if [ -f "$BASH_COMPLETION/$GIT_COMPLETE_NAME" ]; then
__prompt-success 'removing git flow bash completion'
rm -rf "$BASH_COMPLETION/$GIT_COMPLETE_NAME" 1>/dev/null
fi

GIT_PROMPT_NAME=git-prompt.sh
GIT_COMPLETE_NAME=git-flow-completion.bash
GIT_PROMPT_URI=https://raw.githubusercontent.com/lyze/posh-git-sh/master/$GIT_PROMPT_NAME
GIT_COMPLETE_URI=https://raw.githubusercontent.com/petervanderdoes/git-flow-completion/develop/$GIT_COMPLETE_NAME
PROMPT_COMPLETION=$AM_PROMPT/completions
if [ -f "$BASH_COMPLETION/$GIT_PROMPT_NAME" ]; then
__prompt-success 'removing crappy git-prompt'
rm -rf "$BASH_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null
fi

if [ -f "$BASH_COMPLETION/$GIT_COMPLETE_NAME" ]; then
success "Removing git flow bash completion..."
rm -rf "$BASH_COMPLETION/$GIT_COMPLETE_NAME" 1>/dev/null
fi
if [ ! -d "$PROMPT_COMPLETION" ]; then
mkdir -p "$PROMPT_COMPLETION" 1>/dev/null
fi

if [ -f "$BASH_COMPLETION/$GIT_PROMPT_NAME" ]; then
success "Removing crappy git-prompt..."
rm -rf "$BASH_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null
fi
__prompt-success 'downloading better git-prompt'
local result=$(curl -sLD- "$GIT_PROMPT_URI" -o "$PROMPT_COMPLETION/$GIT_PROMPT_NAME" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")

if [ ! -d "$PROMPT_COMPLETION" ]; then
mkdir -p "$PROMPT_COMPLETION" 1>/dev/null
fi
if [ "$result" = "200" ]; then
__prompt-success 'successfully installed git-prompt'
chmod +x "PROMPT_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null 2>&1
fi

success "Downloading better git-prompt..."
result=$(curl -sLD- "$GIT_PROMPT_URI" -o "$PROMPT_COMPLETION/$GIT_PROMPT_NAME" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
__prompt-success 'downloading git-flow completion'
local result=$(curl -sLD- "$GIT_COMPLETE_URI" -o "$PROMPT_COMPLETION/$GIT_COMPLETE_NAME" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")

if [ "$result" = "200" ]; then
success "Successfully installed git-prompt..."
chmod +x "PROMPT_COMPLETION/$GIT_PROMPT_NAME" 1>/dev/null 2>&1
fi
if [ "$result" = "200" ]; then
__prompt-success 'successfully installed git-flow completion'
chmod +x "$PROMPT_COMPLETION/$GIT_COMPLETE_NAME" 1>/dev/null 2>&1
fi

success "Downloading git-flow completion..."
result=$(curl -sLD- "$GIT_COMPLETE_URI" -o "$PROMPT_COMPLETION/$GIT_COMPLETE_NAME" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
local CURL_OPT='-s'

if [ "$result" = "200" ]; then
success "Successfully installed git-flow completion..."
chmod +x "$PROMPT_COMPLETION/$GIT_COMPLETE_NAME" 1>/dev/null 2>&1
fi
if [ ! -z "${GH_TOKEN:-}" ]; then
local CURL_OPT="$CURL_OPT -H 'Authorization: token $GH_TOKEN'"
fi

CURL_OPT='-s'
if [ ! -z "${GH_TOKEN:-}" ]; then
CURL_OPT="$CURL_OPT -H 'Authorization: token $GH_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 PROMPT_SHA_PATH=$HOME/.am/prompt/$PROMPT_SHA

SHA_URI="https://api.github.com/repos/automotivemastermind/prompt/commits/master"
PROMPT_SHA=$(curl $CURL_OPT $SHA_URI | grep sha | head -n 1 | sed 's#.*\:.*"\(.*\).*",#\1#')
PROMPT_SHA_PATH=$HOME/.am/prompt/$PROMPT_SHA
touch "$PROMPT_SHA_PATH"

touch $PROMPT_SHA_PATH
echo -e "${CLR_SUCCESS}"
echo "#######################################"
echo "#######################################"
echo " PLEASE OPEN A NEW TERMINAL WINDOW"
echo "#######################################"
echo "#######################################"
echo -e "${CLR_CLEAR}"

echo -e "${CLR_SUCCESS}"
echo "#######################################"
echo "#######################################"
echo " PLEASE OPEN A NEW TERMINAL WINDOW"
echo "#######################################"
echo "#######################################"
echo -e "${CLR_CLEAR}"
source "$AM_PROMPT/bashrc"
}

source $HOME/.am/prompt/bashrc
__prompt-install
19 changes: 15 additions & 4 deletions src/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,28 @@ if [ -t 1 ]; then
bind "set show-all-if-ambiguous on" # show completion with double tap
fi

AM_PROMPT=$HOME/.am/prompt
export AM_HOME="$HOME/.am"
export AM_PROMPT="$AM_HOME/prompt"

# determine if a user variables exist
if [ -f "$AM_PROMPT/user/bashrc" ]; then
source "$AM_PROMPT/user/variables.sh"
fi

# source scripts
for script in $AM_PROMPT/scripts/*.sh; do
source $script
source "$script"
done

# test for prompt bin
if [ -d $AM_PROMPT/bin ]; then
if [ -d "$AM_PROMPT/user/bin" ]; then
# append prompt to path
export PATH=$PATH:$AM_PROMPT/bin
export PATH=$PATH:"$AM_PROMPT/user/bin"
fi

# determine if a user bashrc exists
if [ -f "$AM_PROMPT/user/bashrc" ]; then
source "$AM_PROMPT/user/bashrc"
fi

# set the prompt
Expand Down
30 changes: 14 additions & 16 deletions src/scripts/add-bookmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ if [ ! -z "${PROMPT_DEBUG:-}" ]; then
echo 'add-bookmark'
fi

add-bookmark-usage() {
echo 'add-bookmark <name>'
echo ' name : a name for your bookmark'
}

add-bookmark() {
# make sure that a bookmark was specified.
if [ -z "${1:-}" ]; then
echo USAGE: add-bookmark NAME
echo ' NAME : a title for your bookmark'
else
# make sure we remove any existing bookmark before defining another one.
remove-bookmark $1 silent
local b="$1"=\"$(pwd)\"

echo Adding bookmark: $b
echo $b >> $HOME/.am/prompt/scripts/bookmarks.sh
source $HOME/.am/prompt/scripts/bookmarks.sh
echo 'add-bookmark: missing <name>'
add-bookmark-usage
return
fi
}

mbm() {
add-bookmark $@
}
# make sure we remove any existing bookmark before defining another one.
remove-bookmark $1 silent
local b="$1"=\"$(pwd)\"

mb() {
add-bookmark $@
echo "add-bookmark: adding bookmark $b"
echo $b >> $HOME/.am/prompt/scripts/bookmarks.sh
source $HOME/.am/prompt/scripts/bookmarks.sh
}
15 changes: 10 additions & 5 deletions src/scripts/add-var.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ if [ ! -z "${PROMPT_DEBUG:-}" ]; then
fi

add-var-usage() {
echo "add-var <name> <value>"
echo ' name : a name for your variable'
echo ' value : a value for your variable'
echo '[add-var|set-var] <name> <value>'
echo ' name : a name for your variable'
echo ' value : a value for your variable'
}

add-var() {
Expand All @@ -27,8 +27,13 @@ add-var() {
# make sure we remove any existing variable before defining another one
remove-var $1 silent
local v="$1"=\"$2\"
local varpath="$AM_PROMPT/user/variables.sh"

echo Adding varable: $v
echo $v >> $HOME/.am/prompt/scripts/variables.sh
source $HOME/.am/prompt/scripts/variables.sh
echo $v >> "$varpath"
source "$varpath"
}

set-var() {
add-var $@
}
22 changes: 11 additions & 11 deletions src/scripts/dotnet-install.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

if [ ! -z "${PROMPT_DEBUG:-}" ]; then
echo "dotnet-install"
echo 'dotnet-install'
fi

safe-exec() {
__prompt-safe-exec() {
local CMD=$1
shift

Expand Down Expand Up @@ -61,24 +61,24 @@ dotnet-install() {
fi

local DOTNET_INSTALL_SH="$DOTNET_INSTALL_DIR/dotnet-install.sh"
local DOTNET_PROJECTJSON_URI="https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2.1/scripts/obtain/dotnet-install.sh"
local DOTNET_MSBUILD_URI="https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.sh"
local DOTNET_MSBUILD_CHANNELS=("rel-1.0.1")
local DOTNET_MSBUILD_VERSIONS=("1.0.1")
local DOTNET_PROJECTJSON_URI='https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2.1/scripts/obtain/dotnet-install.sh'
local DOTNET_MSBUILD_URI='https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.sh'
local DOTNET_MSBUILD_CHANNELS=('rel-1.0.1')
local DOTNET_MSBUILD_VERSIONS=('1.0.1')

curl -fSsL $DOTNET_PROJECTJSON_URI -o $DOTNET_INSTALL_SH 1>/dev/null 2>&1
safe-exec chmod +x $DOTNET_INSTALL_SH
safe-exec $DOTNET_INSTALL_SH
__prompt-safe-exec chmod +x $DOTNET_INSTALL_SH
__prompt-safe-exec $DOTNET_INSTALL_SH

curl -fSsL $DOTNET_MSBUILD_URI -o $DOTNET_INSTALL_SH 1>/dev/null 2>&1
safe-exec chmod +x $DOTNET_INSTALL_SH
__prompt-safe-exec chmod +x $DOTNET_INSTALL_SH

for DOTNET_MSBUILD_CHANNEL in ${DOTNET_MSBUILD_CHANNELS[@]}; do
safe-exec $DOTNET_INSTALL_SH --channel $DOTNET_MSBUILD_CHANNEL
__prompt-safe-exec $DOTNET_INSTALL_SH --channel $DOTNET_MSBUILD_CHANNEL
done

for DOTNET_MSBUILD_VERSION in ${DOTNET_MSBUILD_VERSIONS[@]}; do
safe-exec $DOTNET_INSTALL_SH --version $DOTNET_MSBUILD_VERSION
__prompt-safe-exec $DOTNET_INSTALL_SH --version $DOTNET_MSBUILD_VERSION
done

mkdir -p /usr/local/share 1>/dev/null 2>&1
Expand Down
Loading

0 comments on commit 2c63a54

Please sign in to comment.