remove submodules and add autoupdate
This commit is contained in:
parent
fff65677dd
commit
9ddbe49b60
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
modules
|
15
.gitmodules
vendored
15
.gitmodules
vendored
@ -1,15 +0,0 @@
|
||||
[submodule "modules/powerlevel10k"]
|
||||
path = modules/powerlevel10k
|
||||
url = https://github.com/romkatv/powerlevel10k
|
||||
[submodule "modules/zsh-autosuggestions"]
|
||||
path = modules/zsh-autosuggestions
|
||||
url = https://github.com/zsh-users/zsh-autosuggestions
|
||||
[submodule "modules/zsh-syntax-highlighting"]
|
||||
path = modules/zsh-syntax-highlighting
|
||||
url = https://github.com/zsh-users/zsh-syntax-highlighting
|
||||
[submodule "modules/ohmyzsh"]
|
||||
path = modules/ohmyzsh
|
||||
url = https://github.com/ohmyzsh/ohmyzsh
|
||||
[submodule "modules/zsh-completions"]
|
||||
path = modules/zsh-completions
|
||||
url = https://github.com/zsh-users/zsh-completions
|
43
.zshrc
43
.zshrc
@ -1,5 +1,3 @@
|
||||
export OZSH_HOME="$HOME/.ozsh"
|
||||
|
||||
source $OZSH_HOME/libozsh.zsh
|
||||
|
||||
# link the p10k.zsh file
|
||||
@ -14,25 +12,32 @@ if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]
|
||||
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
|
||||
fi
|
||||
|
||||
# load theme
|
||||
ozsh_load theme powerlevel10k "https://github.com/romkatv/powerlevel10k"
|
||||
|
||||
# load plugins
|
||||
ozsh_load plugin zsh-autosuggestions "https://github.com/zsh-users/zsh-autosuggestions"
|
||||
ozsh_load plugin zsh-syntax-highlighting "https://github.com/zsh-users/zsh-syntax-highlighting"
|
||||
ozsh_load plugin zsh-completions "https://github.com/zsh-users/zsh-completions"
|
||||
autoload -U compinit && compinit
|
||||
ozsh_load plugin_omz gpg-agent
|
||||
|
||||
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
|
||||
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
|
||||
|
||||
#
|
||||
# User-specific settings
|
||||
#
|
||||
set -o emacs
|
||||
|
||||
# optional settings
|
||||
export PATH="$PATH:/usr/local/bin"
|
||||
|
||||
#
|
||||
|
||||
|
||||
# persist history
|
||||
HISTFILE=$HOME/.zsh_history
|
||||
HISTSIZE=10000
|
||||
SAVEHIST=10000
|
||||
setopt appendhistory
|
||||
|
||||
|
||||
# load theme
|
||||
ozsh_load theme powerlevel10k
|
||||
|
||||
# load plugins
|
||||
ozsh_load plugin zsh-autosuggestions
|
||||
ozsh_load plugin zsh-syntax-highlighting
|
||||
ozsh_load plugin zsh-completions
|
||||
autoload -U compinit && compinit
|
||||
ozsh_load plugin_omz gpg-agent
|
||||
|
||||
# optional settings
|
||||
export PATH="$PATH:/usr/local/bin"
|
||||
|
||||
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
|
||||
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
|
||||
|
72
libozsh.zsh
72
libozsh.zsh
@ -1,17 +1,35 @@
|
||||
export OZSH_HOME="$HOME/.ozsh"
|
||||
export OZSH_MODULES="$OZSH_HOME/modules"
|
||||
export OZSH_LASTUPDATE_FILE="$OZSH_HOME/last_update"
|
||||
|
||||
function ozsh_load {
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Invalid ozsh_load number of arguments: $#"
|
||||
return
|
||||
#
|
||||
# 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
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# load plugin
|
||||
# $1 = plugin type
|
||||
# $2 = plugin name
|
||||
# $3 = plugin url <ignored for plugin_omz>
|
||||
#
|
||||
function ozsh_load {
|
||||
if [ "$1" = 'plugin' ]; then
|
||||
source "$OZSH_HOME/modules/$2/$2.plugin.zsh"
|
||||
ozsh_clone_plugin "$2" "$3"
|
||||
source "$OZSH_MODULES/$2/$2.plugin.zsh"
|
||||
elif [ "$1" = 'theme' ]; then
|
||||
source "$OZSH_HOME/modules/$2/$2.zsh-theme"
|
||||
ozsh_clone_plugin "$2" "$3"
|
||||
source "$OZSH_MODULES/$2/$2.zsh-theme"
|
||||
elif [ "$1" = 'plugin_omz' ]; then
|
||||
source "$OZSH_HOME/modules/ohmyzsh/plugins/$2/$2.plugin.zsh"
|
||||
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
|
||||
@ -21,5 +39,43 @@ function ozsh_update {
|
||||
git -C $OZSH_HOME stash
|
||||
git -C $OZSH_HOME pull --rebase
|
||||
git -C $OZSH_HOME stash pop
|
||||
git -C $OZSH_HOME submodule update --recursive --remote
|
||||
|
||||
# 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 {
|
||||
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
|
@ -1 +0,0 @@
|
||||
Subproject commit f21e646ce6c09198f7f625c597f08af49551fdb0
|
@ -1 +0,0 @@
|
||||
Subproject commit b816abfed0e8785d8bc2e47987cc40f6bcd4bc29
|
@ -1 +0,0 @@
|
||||
Subproject commit ae315ded4dba10685dbbafbfa2ff3c1aefeb490d
|
@ -1 +0,0 @@
|
||||
Subproject commit c7baec49d3e044121f7a37b65a84461ef8dac2de
|
@ -1 +0,0 @@
|
||||
Subproject commit 5eb494852ebb99cf5c2c2bffee6b74e6f1bf38d0
|
Loading…
Reference in New Issue
Block a user