overhaul prompt management; make it easier to add/remove things to {,r}prompt over time
This commit is contained in:
		
							
								
								
									
										24
									
								
								base/prompt.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								base/prompt.zsh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					typeset -ag prompt_functions
 | 
				
			||||||
 | 
					typeset -ag rprompt_functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function prompt_builder () {
 | 
				
			||||||
 | 
					        result=""
 | 
				
			||||||
 | 
					        for prompt_func in $prompt_functions; do
 | 
				
			||||||
 | 
					                result="${result}$($prompt_func) "
 | 
				
			||||||
 | 
					        done
 | 
				
			||||||
 | 
					        # prompt will always end with "% " (or "# " if we're somehow root)
 | 
				
			||||||
 | 
					        result="${result}%#%{$reset_color%} "
 | 
				
			||||||
 | 
					        print "${result}"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function rprompt_builder () {
 | 
				
			||||||
 | 
					        result=""
 | 
				
			||||||
 | 
					        for rprompt_func in $rprompt_functions; do
 | 
				
			||||||
 | 
					                result="$($rprompt_func) ${result}"
 | 
				
			||||||
 | 
					        done
 | 
				
			||||||
 | 
					        result="${result}%{$reset_color%}"
 | 
				
			||||||
 | 
					        print "${result}"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PROMPT='$(prompt_builder)'
 | 
				
			||||||
 | 
					RPROMPT='$(rprompt_builder)'
 | 
				
			||||||
							
								
								
									
										19
									
								
								modules/base_prompt.zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								modules/base_prompt.zsh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					#    PROMPT="%{$fg_bold[cyan]%}%n%{$fg_bold[white]%}@%{$fg_bold[magenta]%}%m %{$fg_bold[white]%}%~ %# %{$reset_color%}"
 | 
				
			||||||
 | 
					#    RPROMPT="%(?..%{$fg[red]%}%? )$RPROMPT"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function prompt_userathost () {
 | 
				
			||||||
 | 
					    print "%{$fg_bold[cyan]%}%n%{$fg_bold[white]%}@%{$fg_bold[magenta]%}%m %{$fg_bold[white]%}%~"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					prompt_functions+=prompt_userathost
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function rprompt_clock () {
 | 
				
			||||||
 | 
					    print "%{$fg_bold[black]%}%T"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function rprompt_retval () {
 | 
				
			||||||
 | 
					    print "%(?..%{$fg[red]%}%?)"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rprompt_functions+=rprompt_clock
 | 
				
			||||||
 | 
					rprompt_functions+=rprompt_retval
 | 
				
			||||||
@@ -6,16 +6,12 @@
 | 
				
			|||||||
#     auto_assign_base: false
 | 
					#     auto_assign_base: false
 | 
				
			||||||
#     changeps1: false
 | 
					#     changeps1: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local orig_rprompt="${RPROMPT}"
 | 
					function conda_prompt() {
 | 
				
			||||||
 | 
					 | 
				
			||||||
function precmd_conda_prompt() {
 | 
					 | 
				
			||||||
    if [[ -v CONDA_DEFAULT_ENV && "$CONDA_DEFAULT_ENV" != "base" ]]; then
 | 
					    if [[ -v CONDA_DEFAULT_ENV && "$CONDA_DEFAULT_ENV" != "base" ]]; then
 | 
				
			||||||
        RPROMPT="%{$fg[cyan]%}$CONDA_DEFAULT_ENV %{$reset_color%} ${orig_rprompt}"
 | 
					        print "%{$fg[cyan]%}$CONDA_DEFAULT_ENV"
 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
        RPROMPT="${orig_rprompt}"
 | 
					 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (( ${+commands[conda]} )); then
 | 
					if (( ${+commands[conda]} )); then
 | 
				
			||||||
    precmd_functions+=precmd_conda_prompt
 | 
					    rprompt_functions+=conda_prompt
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
@@ -10,9 +10,9 @@ if [[ $cols -lt 80 ]]; then
 | 
				
			|||||||
        hostemoji="🖥"
 | 
					        hostemoji="🖥"
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    PROMPT="👤%{$fg_bold[white]%}@${hostemoji} %~ %# %{$reset_color%}"
 | 
					    PROMPT="👤%{$fg_bold[white]%}@${hostemoji} %~ %# %{$reset_color%}"
 | 
				
			||||||
else
 | 
					#else
 | 
				
			||||||
    PROMPT="%{$fg_bold[cyan]%}%n%{$fg_bold[white]%}@%{$fg_bold[magenta]%}%m %{$fg_bold[white]%}%~ %# %{$reset_color%}"
 | 
					#    PROMPT="%{$fg_bold[cyan]%}%n%{$fg_bold[white]%}@%{$fg_bold[magenta]%}%m %{$fg_bold[white]%}%~ %# %{$reset_color%}"
 | 
				
			||||||
    RPROMPT="%(?..%{$fg[red]%}%? )$RPROMPT"
 | 
					#    RPROMPT="%(?..%{$fg[red]%}%? )$RPROMPT"
 | 
				
			||||||
fi 
 | 
					fi 
 | 
				
			||||||
TMOUT=60
 | 
					TMOUT=60
 | 
				
			||||||
TRAPALRM () {
 | 
					TRAPALRM () {
 | 
				
			||||||
@@ -20,6 +20,7 @@ TRAPALRM () {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
source ~/.local/share/zeesh/base/precmd.zsh
 | 
					source ~/.local/share/zeesh/base/precmd.zsh
 | 
				
			||||||
 | 
					source ~/.local/share/zeesh/base/prompt.zsh
 | 
				
			||||||
source ~/.local/share/zeesh/base/updates.zsh 
 | 
					source ~/.local/share/zeesh/base/updates.zsh 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# TODO: handle whether or not to load given modules]
 | 
					# TODO: handle whether or not to load given modules]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user