diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc428f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +modules \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index f21aea3..0000000 --- a/.gitmodules +++ /dev/null @@ -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 diff --git a/.zshrc b/.zshrc index 0323a2e..2d3dbea 100644 --- a/.zshrc +++ b/.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 -# persist history -HISTFILE=$HOME/.zsh_history -HISTSIZE=10000 -SAVEHIST=10000 -setopt appendhistory - - # load theme -ozsh_load theme powerlevel10k +ozsh_load theme powerlevel10k "https://github.com/romkatv/powerlevel10k" # load plugins -ozsh_load plugin zsh-autosuggestions -ozsh_load plugin zsh-syntax-highlighting -ozsh_load plugin zsh-completions +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" -# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. -[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh +# + + +# persist history +HISTFILE=$HOME/.zsh_history +HISTSIZE=10000 +SAVEHIST=10000 +setopt appendhistory \ No newline at end of file diff --git a/libozsh.zsh b/libozsh.zsh index d385f5e..db13a46 100644 --- a/libozsh.zsh +++ b/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 +# +function ozsh_load { if [ "$1" = 'plugin' ]; then - source "$OZSH_HOME/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.plugin.zsh" + elif [ "$1" = 'theme' ]; then + 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 \ No newline at end of file diff --git a/modules/ohmyzsh b/modules/ohmyzsh deleted file mode 160000 index f21e646..0000000 --- a/modules/ohmyzsh +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f21e646ce6c09198f7f625c597f08af49551fdb0 diff --git a/modules/powerlevel10k b/modules/powerlevel10k deleted file mode 160000 index b816abf..0000000 --- a/modules/powerlevel10k +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b816abfed0e8785d8bc2e47987cc40f6bcd4bc29 diff --git a/modules/zsh-autosuggestions b/modules/zsh-autosuggestions deleted file mode 160000 index ae315de..0000000 --- a/modules/zsh-autosuggestions +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ae315ded4dba10685dbbafbfa2ff3c1aefeb490d diff --git a/modules/zsh-completions b/modules/zsh-completions deleted file mode 160000 index c7baec4..0000000 --- a/modules/zsh-completions +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c7baec49d3e044121f7a37b65a84461ef8dac2de diff --git a/modules/zsh-syntax-highlighting b/modules/zsh-syntax-highlighting deleted file mode 160000 index 5eb4948..0000000 --- a/modules/zsh-syntax-highlighting +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5eb494852ebb99cf5c2c2bffee6b74e6f1bf38d0