81 lines
1.8 KiB
Bash
81 lines
1.8 KiB
Bash
export OZSH_HOME="$HOME/.ozsh"
|
|
export OZSH_MODULES="$OZSH_HOME/modules"
|
|
export OZSH_LASTUPDATE_FILE="$OZSH_HOME/last_update"
|
|
|
|
#
|
|
# 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 "$2" "$1" > /dev/null 2>&1
|
|
fi
|
|
}
|
|
|
|
#
|
|
# load plugin
|
|
# $1 = plugin type
|
|
# $2 = plugin name
|
|
# $3 = plugin url <ignored for plugin_omz>
|
|
#
|
|
function ozsh_load {
|
|
if [ "$1" = 'plugin' ]; then
|
|
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"
|
|
elif [ "$1" = 'plugin_omz' ]; then
|
|
ozsh_clone_plugin ohmyzsh "https://github.com/ohmyzsh/ohmyzsh"
|
|
source "$OZSH_MODULES/ohmyzsh/plugins/$2/$2.plugin.zsh"
|
|
else
|
|
echo "Invalid ozsh_load arguments: $@"
|
|
fi
|
|
}
|
|
|
|
function ozsh_update {
|
|
git -C $OZSH_HOME stash
|
|
git -C $OZSH_HOME pull
|
|
git -C $OZSH_HOME stash pop
|
|
|
|
# check for updates in modules
|
|
for d in $OZSH_MODULES
|
|
do
|
|
git -C $d pull > /dev/null 2>&1
|
|
done
|
|
|
|
echo $(date) > "$OZSH_LASTUPDATE_FILE"
|
|
}
|
|
|
|
function ozsh_autoupdate {
|
|
local timediff=$(( ($(date --date="$(date)" +%s) - $(date --date="$(cat $OZSH_LASTUPDATE_FILE)" +%s) ) / (60*60*24) ))
|
|
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
|
|
}
|
|
|
|
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 |