Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,24 @@ Have a look at our [bash-it-docker repository](https://github.com/Bash-it/bash-i

### Updating

To update Bash-it to the latest version, simply run:
To update Bash-it to the latest stable version, simply run:

```bash
bash-it update
bash-it update stable
```

that's all.
If you want to update to the latest dev version (directly from master), run:

```bash
bash-it update dev
```

If you want to update automatically and unattended, you can add the optional
`-s/--silent` flag, for example:

```bash
bash-it update dev --silent
```

If you are using an older version of Bash-it, it's possible that some functionality has changed, or that the internal structure of how Bash-it organizes its functionality has been updated.
For these cases, we provide a `migrate` command:
Expand Down
11 changes: 10 additions & 1 deletion completion/available/bash-it.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ _bash-it-comp()
COMPREPLY=( $(compgen -W "${doctor_args}" -- ${cur}) )
return 0
;;
migrate | reload | search | update | version)
update)
if [[ ${cur} == -* ]];then
local update_args="-s --silent"
else
local update_args="stable dev"
fi
COMPREPLY=( $(compgen -W "${update_args}" -- ${cur}) )
return 0
;;
migrate | reload | search | version)
return 0
;;
enable | disable)
Expand Down
129 changes: 98 additions & 31 deletions lib/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bash-it ()
_bash-it-search $component "$@"
return;;
update)
func=_bash-it_update;;
func=_bash-it_update-$component;;
migrate)
func=_bash-it-migrate;;
version)
Expand Down Expand Up @@ -155,60 +155,127 @@ _bash-it-plugins ()
_bash-it-describe "plugins" "a" "plugin" "Plugin"
}

_bash-it_update() {
_bash-it_update-dev() {
_about 'updates Bash-it to the latest master'
_group 'lib'

_bash-it_update- dev "$@"
}

_bash-it_update-stable() {
_about 'updates Bash-it to the latest tag'
_group 'lib'

_bash-it_update- stable "$@"
}

_bash-it_pull_and_update_inner() {
git checkout "$1" &> /dev/null
if [[ $? -eq 0 ]]; then
echo "Bash-it successfully updated."
echo ""
echo "Migrating your installation to the latest $2 version now..."
_bash-it-migrate
echo ""
echo "All done, enjoy!"
bash-it reload
else
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
fi
}

_bash-it_update-() {
_about 'updates Bash-it'
_param '1: What kind of update to do (stable|dev)'
_group 'lib'

declare silent
for word in $@; do
if [[ ${word} == "--silent" || ${word} == "-s" ]]; then
silent=true
fi
done
local old_pwd="${PWD}"

cd "${BASH_IT}" || return

if [ -z $BASH_IT_REMOTE ]; then
if [ -z "$BASH_IT_REMOTE" ]; then
BASH_IT_REMOTE="origin"
fi

git fetch &> /dev/null
git fetch $BASH_IT_REMOTE --tags &> /dev/null

if [ -z "$BASH_IT_DEVELOPMENT_BRANCH" ]; then
BASH_IT_DEVELOPMENT_BRANCH="master"
fi
# Defaults to stable update
if [ -z "$1" ] || [ "$1" == "stable" ]; then
version="stable"
TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2> /dev/null)

if [[ -z "$TARGET" ]]; then
echo "Can not find tags, so can not update to latest stable version..."
return
fi
else
version="dev"
TARGET=${BASH_IT_REMOTE}/${BASH_IT_DEVELOPMENT_BRANCH}
fi

declare revision
revision="HEAD..${TARGET}"
declare status
status="$(git rev-list master..${BASH_IT_REMOTE}/master 2> /dev/null)"
status="$(git rev-list ${revision} 2> /dev/null)"
declare revert

if [[ -z "${status}" && ${version} == "stable" ]]; then
revision="${TARGET}..HEAD"
status="$(git rev-list ${revision} 2> /dev/null)"
revert=true
fi

if [[ -n "${status}" ]]; then
if [[ $revert ]]; then
echo "Your version is a more recent development version ($(git log -1 --format=%h HEAD))"
echo "You can continue in order to revert and update to the latest stable version"
echo ""
log_color="%Cred"
fi

for i in $(git rev-list --merges --first-parent master..${BASH_IT_REMOTE}); do
for i in $(git rev-list --merges --first-parent ${revision}); do
num_of_lines=$(git log -1 --format=%B $i | awk 'NF' | wc -l)
if [ $num_of_lines -eq 1 ]; then
description="%s"
else
description="%b"
fi
git log --format="%h: $description (%an)" -1 $i
git log --format="${log_color}%h: $description (%an)" -1 $i
done
echo ""
read -e -n 1 -p "Would you like to update to $(git log -1 --format=%h origin/master)? [Y/n] " RESP
case $RESP in
[yY]|"")
git pull --rebase &> /dev/null
if [[ $? -eq 0 ]]; then
echo "Bash-it successfully updated."
echo ""
echo "Migrating your installation to the latest version now..."
_bash-it-migrate
echo ""
echo "All done, enjoy!"
bash-it reload
else
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
fi
;;
[nN])
echo "Not upgrading…"
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac

if [[ $silent ]]; then
echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..."
_bash-it_pull_and_update_inner $TARGET $version
else
read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP
case $RESP in
[yY]|"")
_bash-it_pull_and_update_inner $TARGET $version
;;
[nN])
echo "Not updating…"
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
fi
else
echo "Bash-it is up to date, nothing to do!"
if [[ ${version} == "stable" ]]; then
echo "You're on the latest stable version. If you want to check out the latest 'dev' version, please run \"bash-it update dev\""
else
echo "Bash-it is up to date, nothing to do!"
fi
fi
cd "${old_pwd}" &> /dev/null || return
}
Expand Down
4 changes: 4 additions & 0 deletions template/bash_profile.template.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export BASH_IT_THEME='bobby'
# cloned bash-it with a remote other than origin such as `bash-it`.
# export BASH_IT_REMOTE='bash-it'

# (Advanced): Change this to the name of the main development branch if
# you renamed it or if it was changed for some reason
# export BASH_IT_DEVELOPMENT_BRANCH='master'

# Your place for hosting Git repos. I use this for private repos.
export GIT_HOSTING='[email protected]'

Expand Down
9 changes: 7 additions & 2 deletions test/completion/bash-it.completion.bats
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ function __check_completion () {
assert_line -n 0 "vagrant vault vim"
}

@test "completion bash-it: update - show no options" {
@test "completion bash-it: update - show options" {
run __check_completion 'bash-it update '
assert_line -n 0 ""
assert_line -n 0 "stable dev"
}

@test "completion bash-it: update - show optional flags" {
run __check_completion 'bash-it update -'
assert_line -n 0 "-s --silent"
}

@test "completion bash-it: search - show no options" {
Expand Down