From 513742f17ac90c57d138b537c6c959b64684bbee Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Fri, 19 May 2023 18:17:07 +0300 Subject: [PATCH] Fix support for autoloaded prompt themes in $fpath Fixes #247. --- functions/.znap.prompt | 18 ++++++++---------- functions/.znap.prompt.load | 8 +++++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/functions/.znap.prompt b/functions/.znap.prompt index 936ebb2..026d9c0 100644 --- a/functions/.znap.prompt +++ b/functions/.znap.prompt @@ -6,18 +6,16 @@ zmodload -F zsh/zleparameter p:widgets autoload -Uz add-zsh-hook add-zle-hook-widget promptinit .znap.prompt() { - if (( # )); then - local gitdir='' - ..znap.repos-dir + local theme= + if (( # )); then if [[ $1 == */* ]]; then .znap.clone $1 || return fi - private _P__repo=~[$1] - private _P__theme=${2:-${${_P__repo##*/((oh-my-|)zsh-|)}%%((-zsh|)-(prompt|theme)|.zsh)}} - .znap.prompt.load $_P__repo $_P__theme + local theme= + .znap.prompt.load "$1" fi ..znap.tput civis # Make cursor invisible. @@ -32,12 +30,12 @@ autoload -Uz add-zsh-hook add-zle-hook-widget promptinit exec 2> $_znap_prompt_tmp # Redirect std err to tmp file. promptinit - if [[ -n $_P__theme ]]; then - prompt_themes+=( $_P__theme ) - prompt $_P__theme + if [[ -n $theme ]]; then + prompt_themes+=( $theme ) + prompt $theme ..znap.tput sc # Save cursor position (overwriting the previous save). - private _P__precmd=prompt_${_P__theme}_precmd + private _P__precmd=prompt_${theme}_precmd if [[ -n $functions[$_P__precmd] ]]; then $_P__precmd diff --git a/functions/.znap.prompt.load b/functions/.znap.prompt.load index a257034..a99711c 100644 --- a/functions/.znap.prompt.load +++ b/functions/.znap.prompt.load @@ -4,7 +4,6 @@ zmodload -F zsh/parameter p:functions .znap.prompt.load() { emulate -L zsh; setopt $_znap_opts - private dir=$1 theme=$2 private setup=prompt_${theme}_setup [[ -v functions[$setup] ]] && @@ -15,6 +14,13 @@ zmodload -F zsh/parameter p:functions unfunction $setup + local repos=() + local gitdir= + ..znap.repos prompt $theme + private dir=$gitdir/$repos[1] + + theme=${2:-${${dir##*/((oh-my-|)zsh-|)}%%((-zsh|)-(prompt|theme)|.zsh)}} + private -a file=( $dir/**/$setup(-.Y1) ) if [[ -n $file ]]; then