2021-02-21 04:37:27 +00:00
|
|
|
export OZSH_HOME="$HOME/.ozsh"
|
2021-03-08 10:04:11 +00:00
|
|
|
export OZSH_MODULES="$OZSH_HOME/modules"
|
|
|
|
export OZSH_LASTUPDATE_FILE="$OZSH_HOME/last_update"
|
2021-02-21 04:37:27 +00:00
|
|
|
|
2021-03-08 10:04:11 +00:00
|
|
|
#
|
|
|
|
# clone the plugin if not exist
|
|
|
|
# $1 = plugin name
|
|
|
|
# $2 = git URL
|
|
|
|
#
|
|
|
|
function ozsh_clone_plugin {
|
|
|
|
if [ ! -d "$OZSH_MODULES/$1" ]; then
|
|
|
|
echo "Installing plugin $1..."
|
|
|
|
git -C "$OZSH_MODULES" clone "$1" "$2" > /dev/null 2>&1
|
2021-02-21 04:37:27 +00:00
|
|
|
fi
|
2021-03-08 10:04:11 +00:00
|
|
|
}
|
2021-02-21 04:37:27 +00:00
|
|
|
|
2021-03-08 10:04:11 +00:00
|
|
|
#
|
|
|
|
# load plugin
|
|
|
|
# $1 = plugin type
|
|
|
|
# $2 = plugin name
|
|
|
|
# $3 = plugin url <ignored for plugin_omz>
|
|
|
|
#
|
|
|
|
function ozsh_load {
|
2021-02-21 04:37:27 +00:00
|
|
|
if [ "$1" = 'plugin' ]; then
|
2021-03-08 10:04:11 +00:00
|
|
|
ozsh_clone_plugin "$2" "$3"
|
|
|
|
source "$OZSH_MODULES/$2/$2.plugin.zsh"
|
|
|
|
elif [ "$1" = 'theme' ]; then
|
|
|
|
ozsh_clone_plugin "$2" "$3"
|
|
|
|
source "$OZSH_MODULES/$2/$2.zsh-theme"
|
2021-02-21 04:37:27 +00:00
|
|
|
elif [ "$1" = 'plugin_omz' ]; then
|
2021-03-08 10:04:11 +00:00
|
|
|
ozsh_clone_plugin ohmyzsh "https://github.com/ohmyzsh/ohmyzsh"
|
|
|
|
source "$OZSH_MODULES/ohmyzsh/plugins/$2/$2.plugin.zsh"
|
2021-02-21 04:37:27 +00:00
|
|
|
else
|
|
|
|
echo "Invalid ozsh_load arguments: $@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function ozsh_update {
|
|
|
|
git -C $OZSH_HOME stash
|
2021-02-21 05:58:12 +00:00
|
|
|
git -C $OZSH_HOME pull --rebase
|
2021-02-21 04:37:27 +00:00
|
|
|
git -C $OZSH_HOME stash pop
|
2021-03-08 10:04:11 +00:00
|
|
|
|
|
|
|
# check for updates in modules
|
|
|
|
for d in $OZSH_MODULES
|
|
|
|
do
|
|
|
|
git -C $OZSH_HOME/$d pull --rebase > /dev/null 2>&1
|
|
|
|
done
|
|
|
|
|
|
|
|
echo $(date) > "$OZSH_LASTUPDATE_FILE"
|
|
|
|
}
|
|
|
|
|
|
|
|
function ozsh_autoupdate {
|
2021-03-08 10:07:13 +00:00
|
|
|
local timediff=$(( ($(date --date="$(date)" +%s) - $(date --date="$(cat $OZSH_LASTUPDATE_FILE)" +%s) ) / (60*60*24) ))
|
2021-03-08 10:04:11 +00:00
|
|
|
if [ $timediff -ge 7 ]; then
|
|
|
|
vared -p 'Would you like to update ozsh? [y/N]: ' -c answer
|
|
|
|
if [ "$answer" == "y" || "$answer" == "Y" ]; then
|
|
|
|
ozsh_update
|
|
|
|
fi
|
|
|
|
fi
|
2021-02-21 04:37:27 +00:00
|
|
|
}
|
2021-03-08 10:04:11 +00:00
|
|
|
|
|
|
|
function ozsh_init {
|
|
|
|
# check modules directory
|
|
|
|
if [ ! -d $OZSH_MODULES ]; then
|
|
|
|
mkdir -p $OZSH_MODULES
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create lastupdate file if not exist
|
|
|
|
if [ ! -f $OZSH_LASTUPDATE_FILE ]; then
|
|
|
|
echo $(date) > $OZSH_LASTUPDATE_FILE
|
|
|
|
fi
|
|
|
|
|
|
|
|
ozsh_autoupdate
|
|
|
|
}
|
|
|
|
|
|
|
|
# init
|
|
|
|
ozsh_init
|
|
|
|
|
|
|
|
# undefine functions
|
|
|
|
unset -f ozsh_init
|
|
|
|
unset -f ozsh_autoupdate
|