2017-03-20 19:51:00 +07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-03-19 15:40:25 +07:00
|
|
|
# Check for updates on initial load...
|
|
|
|
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
|
2017-03-20 19:51:00 +07:00
|
|
|
env OSH=$OSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT bash -f $OSH/tools/check_for_upgrade.sh
|
2017-03-19 15:40:25 +07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Initializes Oh My Bash
|
|
|
|
|
|
|
|
# add a function path
|
|
|
|
fpath=($OSH/functions $OSH/completions $fpath)
|
|
|
|
|
|
|
|
# Set OSH_CUSTOM to the path where your custom config files
|
|
|
|
# and plugins exists, or else we will use the default custom/
|
|
|
|
if [[ -z "$OSH_CUSTOM" ]]; then
|
|
|
|
OSH_CUSTOM="$OSH/custom"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set OSH_CACHE_DIR to the path where cache files should be created
|
|
|
|
# or else we will use the default cache/
|
|
|
|
if [[ -z "$OSH_CACHE_DIR" ]]; then
|
|
|
|
OSH_CACHE_DIR="$OSH/cache"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Load all of the config files in ~/.oh-my-bash/lib that end in .sh
|
|
|
|
# TIP: Add files you don't want in git to .gitignore
|
|
|
|
for config_file in $OSH/lib/*.sh; do
|
|
|
|
custom_config_file="${OSH_CUSTOM}/lib/${config_file:t}"
|
|
|
|
[ -f "${custom_config_file}" ] && config_file=${custom_config_file}
|
|
|
|
source $config_file
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
is_plugin() {
|
|
|
|
local base_dir=$1
|
|
|
|
local name=$2
|
|
|
|
test -f $base_dir/plugins/$name/$name.plugin.sh \
|
|
|
|
|| test -f $base_dir/plugins/$name/_$name
|
|
|
|
}
|
|
|
|
# Add all defined plugins to fpath. This must be done
|
|
|
|
# before running compinit.
|
2017-03-19 16:39:54 +07:00
|
|
|
for plugin in ${plugins[@]}; do
|
2017-03-19 15:40:25 +07:00
|
|
|
if is_plugin $OSH_CUSTOM $plugin; then
|
|
|
|
fpath=($OSH_CUSTOM/plugins/$plugin $fpath)
|
|
|
|
elif is_plugin $OSH $plugin; then
|
|
|
|
fpath=($OSH/plugins/$plugin $fpath)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Figure out the SHORT hostname
|
|
|
|
if [[ "$OSTYPE" = darwin* ]]; then
|
|
|
|
# macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
|
|
|
|
SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
|
|
|
|
else
|
|
|
|
SHORT_HOST=${HOST/.*/}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Load all of the plugins that were defined in ~/.bashrc
|
2017-03-19 16:39:54 +07:00
|
|
|
for plugin in ${plugins[@]}; do
|
2017-03-19 15:40:25 +07:00
|
|
|
if [ -f $OSH_CUSTOM/plugins/$plugin/$plugin.plugin.sh ]; then
|
|
|
|
source $OSH_CUSTOM/plugins/$plugin/$plugin.plugin.sh
|
|
|
|
elif [ -f $OSH/plugins/$plugin/$plugin.plugin.sh ]; then
|
|
|
|
source $OSH/plugins/$plugin/$plugin.plugin.sh
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2017-10-10 18:07:01 +07:00
|
|
|
# Load all of the completion & aliases files in ~/.oh-my-bash/{completion,aliases}
|
|
|
|
# that end in .completion.sh & .aliases.sh
|
|
|
|
# TIP: Add files you don't want in git to .gitignore
|
|
|
|
for alias_file in $OSH/aliases/*.sh; do
|
|
|
|
custom_alias_file="${OSH_CUSTOM}/aliases/${alias_file:t}"
|
|
|
|
[ -f "${custom_alias_file}" ] && alias_file=${custom_alias_file}
|
|
|
|
source $alias_file
|
|
|
|
done
|
|
|
|
for completion_file in $OSH/completion/*.sh; do
|
|
|
|
custom_completion_file="${OSH_CUSTOM}/completion/${completion_file:t}"
|
|
|
|
[ -f "${custom_completion_file}" ] && completion_file=${custom_completion_file}
|
|
|
|
source $completion_file
|
|
|
|
done
|
|
|
|
|
2017-03-19 15:40:25 +07:00
|
|
|
# Load all of your custom configurations from custom/
|
|
|
|
for config_file in $OSH_CUSTOM/*.sh; do
|
2017-03-19 16:17:21 +07:00
|
|
|
if [ -f config_file ]; then
|
|
|
|
source $config_file
|
|
|
|
fi
|
2017-03-19 15:40:25 +07:00
|
|
|
done
|
|
|
|
unset config_file
|
2017-10-10 18:07:01 +07:00
|
|
|
# Load all of your custom aliases from custom/
|
|
|
|
for alias_file in $OSH_CUSTOM/*.sh; do
|
|
|
|
if [ -f alias_file ]; then
|
|
|
|
source $alias_file
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset alias_file
|
|
|
|
# Load all of your custom completions from custom/
|
|
|
|
for completion_file in $OSH_CUSTOM/*.sh; do
|
|
|
|
if [ -f completion_file ]; then
|
|
|
|
source $completion_file
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset completion_file
|
|
|
|
|
|
|
|
# Load colors first so they can be use in base theme
|
|
|
|
source "${OSH}/themes/colours.theme.sh"
|
|
|
|
source "${OSH}/themes/base.theme.sh"
|
2017-03-19 15:40:25 +07:00
|
|
|
|
|
|
|
# Load the theme
|
|
|
|
if [ "$OSH_THEME" = "random" ]; then
|
2017-10-10 18:07:01 +07:00
|
|
|
themes=($OSH/themes/*/*theme.sh)
|
2017-03-19 15:40:25 +07:00
|
|
|
N=${#themes[@]}
|
2017-10-10 18:07:01 +07:00
|
|
|
((N=(RANDOM%N)))
|
2017-03-19 15:40:25 +07:00
|
|
|
RANDOM_THEME=${themes[$N]}
|
|
|
|
source "$RANDOM_THEME"
|
|
|
|
echo "[oh-my-bash] Random theme '$RANDOM_THEME' loaded..."
|
|
|
|
else
|
|
|
|
if [ ! "$OSH_THEME" = "" ]; then
|
2017-10-10 18:07:01 +07:00
|
|
|
if [ -f "$OSH_CUSTOM/$OSH_THEME/$OSH_THEME.theme.sh" ]; then
|
|
|
|
source "$OSH_CUSTOM/$OSH_THEME/$OSH_THEME.theme.sh"
|
|
|
|
elif [ -f "$OSH_CUSTOM/themes/$OSH_THEME/$OSH_THEME.theme.sh" ]; then
|
|
|
|
source "$OSH_CUSTOM/themes/$OSH_THEME/$OSH_THEME.theme.sh"
|
2017-03-19 15:40:25 +07:00
|
|
|
else
|
2017-10-10 18:07:01 +07:00
|
|
|
source "$OSH/themes/$OSH_THEME/$OSH_THEME.theme.sh"
|
2017-03-19 15:40:25 +07:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2017-10-10 18:07:01 +07:00
|
|
|
|
|
|
|
if [[ $PROMPT ]]; then
|
|
|
|
export PS1="\["$PROMPT"\]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! type_exists '__git_ps1' ; then
|
|
|
|
source "$OSH/tools/git-prompt.sh"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Adding Support for other OSes
|
|
|
|
PREVIEW="less"
|
|
|
|
[ -s /usr/bin/gloobus-preview ] && PREVIEW="gloobus-preview"
|
|
|
|
[ -s /Applications/Preview.app ] && PREVIEW="/Applications/Preview.app"
|