1# Loads a given theme. 2# 3# Shares the same syntax as antigen-bundle command. 4# 5# Usage 6# antigen-theme zsh/theme[.zsh-theme] 7# 8# Returns 9# 0 if everything was succesfully 10antigen-theme () { 11 local name=$1 result=0 record 12 local match mbegin mend MATCH MBEGIN MEND 13 14 if [[ -z "$1" ]]; then 15 printf "Antigen: Must provide a theme url or name.\n" >&2 16 return 1 17 fi 18 19 -antigen-theme-reset-hooks 20 21 record=$(-antigen-find-record "theme") 22 if [[ "$1" != */* && "$1" != --* ]]; then 23 # The first argument is just a name of the plugin, to be picked up from 24 # the default repo. 25 antigen-bundle --loc=themes/$name --btype=theme 26 27 else 28 antigen-bundle "$@" --btype=theme 29 30 fi 31 result=$? 32 33 # Remove a theme from the record if the following conditions apply: 34 # - there was no error in bundling the given theme 35 # - there is a theme registered 36 # - registered theme is not the same as the current one 37 if [[ $result == 0 && -n $record ]]; then 38 # http://zsh-workers.zsh.narkive.com/QwfCWpW8/what-s-wrong-with-this-expression 39 if [[ "$record" =~ "$@" ]]; then 40 return $result 41 else 42 _ANTIGEN_BUNDLE_RECORD[$_ANTIGEN_BUNDLE_RECORD[(I)$record]]=() 43 fi 44 fi 45 46 return $result 47} 48 49-antigen-theme-reset-hooks () { 50 # This is only needed on interactive mode 51 autoload -U add-zsh-hook is-at-least 52 local hook 53 54 # Clear out prompts 55 PROMPT="" 56 if [[ -n $RPROMPT ]]; then 57 RPROMPT="" 58 fi 59 60 for hook in chpwd precmd preexec periodic; do 61 add-zsh-hook -D "${hook}" "prompt_*" 62 # common in omz themes 63 add-zsh-hook -D "${hook}" "*_${hook}" 64 add-zsh-hook -d "${hook}" "vcs_info" 65 done 66} 67