From 77c36cbca8df38daf8c0c51860f3b778522c84c5 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sat, 4 Dec 2021 13:37:17 +0100 Subject: [PATCH] Refactoring: Use "axzsh_" prefix (instead of "ax_") for all functions & variables New function names: - axzsh_hostname_prompt_root() - axzsh_hostname_prompt_yn() - axzsh_logname_prompt_root() - axzsh_logname_prompt_yn() - axzsh_plugin_fnc() - axzsh_plugin_init() - axzsh_prompt() - axzsh_vcs_prompt() - _axzsh_ssh_prompt() New array names: - axzsh_hostname_prompt_functions - axzsh_logname_prompt_functions - axzsh_vcs_prompt_functions --- ax.zsh | 6 +++--- bin/axzshctl | 8 ++++---- core/50_prompt/50_prompt.zshrc | 24 ++++++++++++------------ core/99_cleanup/99_cleanup.zlogin | 18 +++++++++--------- default_plugins/ssh/ssh.zshrc | 6 +++--- plugins/git/git.zshrc | 2 +- themes/ax.axzshtheme | 6 +++--- themes/axemoji.axzshtheme | 2 +- themes/debian.axzshtheme | 2 +- themes/ohmyzsh.axzshtheme | 2 +- 10 files changed, 38 insertions(+), 38 deletions(-) diff --git a/ax.zsh b/ax.zsh index c88c192..00c242e 100644 --- a/ax.zsh +++ b/ax.zsh @@ -46,7 +46,7 @@ function axzsh_handle_stage { [[ -n "$AXZSH_DEBUG" ]] \ && echo " - Reading cache file \"$cache_file\" ..." source "$cache_file" - unfunction ax_plugin_init + unfunction axzsh_plugin_init else # No cache file available. local new_cache_file="$cache_file.NEW" @@ -189,7 +189,7 @@ function axzsh_load_plugin { if [[ -n "$cache_file" ]]; then # Add plugin data to cache - printf "# BEGIN: %s\nax_plugin_init()\n{\n" "$fname" >>"$cache_file" + printf "# BEGIN: %s\naxzsh_plugin_init()\n{\n" "$fname" >>"$cache_file" case "$fname" in *"/repos/"*) echo "[[ -n \"\$AXZSH_DEBUG\" ]] && echo ' - $plugin ($type): \"$fname\" ...'" >>$cache_file @@ -199,7 +199,7 @@ function axzsh_load_plugin { echo "[[ -n \"\$AXZSH_DEBUG\" ]] && echo ' - $plugin ($type, cached) ...'" >>$cache_file "$cat_cmd" "$fname" >>"$cache_file" esac - printf "}\nax_plugin_init\n# END: %s\n\n" "$fname" >>"$cache_file" + printf "}\naxzsh_plugin_init\n# END: %s\n\n" "$fname" >>"$cache_file" fi fi diff --git a/bin/axzshctl b/bin/axzshctl index 8e1306c..34e22d2 100755 --- a/bin/axzshctl +++ b/bin/axzshctl @@ -362,9 +362,9 @@ function CheckPlugins { fi for p in $AXZSH/core/*/*.zshrc; do [[ "$(basename "$p")" == "01_zprofile.zshrc" ]] && continue - printf "# BEGIN: %s\nax_plugin_init()\n{\n" "$p" >>"$T" + printf "# BEGIN: %s\naxzsh_plugin_init()\n{\n" "$p" >>"$T" cat "$p" >>"$T" - printf "}\nax_plugin_init\n# END: %s\n\n" "$p" >>"$T" + printf "}\naxzsh_plugin_init\n# END: %s\n\n" "$p" >>"$T" done ax_msg - "Checking plugins ..." @@ -387,8 +387,8 @@ function CheckPlugins { ( AXZSH_PLUGIN_CHECK=1 source "$T" - ax_plugin_fnc() { source "$script" } - ax_plugin_fnc + axzsh_plugin_fnc() { source "$script" } + axzsh_plugin_fnc ); r=$? [[ $r -eq 0 ]] && new_plugin=$plugin break diff --git a/core/50_prompt/50_prompt.zshrc b/core/50_prompt/50_prompt.zshrc index 7aaf053..aea921d 100644 --- a/core/50_prompt/50_prompt.zshrc +++ b/core/50_prompt/50_prompt.zshrc @@ -18,21 +18,21 @@ else fi ZSH_THEME_LOGNAME_PROMPT_SUFFIX_SPACING="@" -function ax_logname_prompt_root() { +function axzsh_logname_prompt_root() { (( $UID == 0 )) || return 1 return 0 } -function ax_logname_prompt_yn() { +function axzsh_logname_prompt_yn() { local func - for func ($ax_logname_prompt_functions); do + for func ($axzsh_logname_prompt_functions); do $func || continue echo "${ZSH_THEME_LOGNAME_PROMPT_PREFIX_SPACING}${ZSH_THEME_LOGNAME_PROMPT_PREFIX}${1:-$LOGNAME}${ZSH_THEME_LOGNAME_PROMPT_SUFFIX}${ZSH_THEME_LOGNAME_PROMPT_SUFFIX_SPACING}" return done } -ax_logname_prompt_functions=(ax_logname_prompt_root) +axzsh_logname_prompt_functions=(axzsh_logname_prompt_root) # Hostname @@ -41,21 +41,21 @@ ZSH_THEME_HOSTNAME_PROMPT_PREFIX="" ZSH_THEME_HOSTNAME_PROMPT_SUFFIX="" ZSH_THEME_HOSTNAME_PROMPT_SUFFIX_SPACING=":" -function ax_hostname_prompt_root() { +function axzsh_hostname_prompt_root() { (( $UID == 0 )) || return 1 return 0 } -function ax_hostname_prompt_yn() { +function axzsh_hostname_prompt_yn() { local func - for func ($ax_hostname_prompt_functions); do + for func ($axzsh_hostname_prompt_functions); do $func || continue echo "${ZSH_THEME_HOSTNAME_PROMPT_PREFIX_SPACING}${ZSH_THEME_HOSTNAME_PROMPT_PREFIX}${1:-$SHORT_HOST}${ZSH_THEME_HOSTNAME_PROMPT_SUFFIX}${ZSH_THEME_HOSTNAME_PROMPT_SUFFIX_SPACING}" return done } -ax_hostname_prompt_functions=() +axzsh_hostname_prompt_functions=() # VCS @@ -77,17 +77,17 @@ ZSH_THEME_VCS_PROMPT_BEHIND="%{$fg_no_bold[blue]%}$behind%{$fg[default]%}" unset clean dirty ahead behind -function ax_vcs_prompt() { +function axzsh_vcs_prompt() { local func local p - for func ($ax_vcs_prompt_functions); do + for func ($axzsh_vcs_prompt_functions); do p=$( $func ) || continue echo "${ZSH_THEME_VCS_PROMPT_PREFIX_SPACING}${p}${ZSH_THEME_VCS_PROMPT_SUFFIX_SPACING}" return done } -ax_vcs_prompt_functions=() +axzsh_vcs_prompt_functions=() # Prompt @@ -100,7 +100,7 @@ ZSH_THEME_PROMPT_ROOT_PREFIX="" ZSH_THEME_PROMPT_SUFFIX="" ZSH_THEME_PROMPT_SUFFIX_SPACING="" -function ax_prompt() { +function axzsh_prompt() { local p (( $UID == 0 )) \ && p="${ZSH_THEME_PROMPT_ROOT_PREFIX}${ZSH_THEME_PROMPT_ROOT}" \ diff --git a/core/99_cleanup/99_cleanup.zlogin b/core/99_cleanup/99_cleanup.zlogin index 764466b..1971cd0 100644 --- a/core/99_cleanup/99_cleanup.zlogin +++ b/core/99_cleanup/99_cleanup.zlogin @@ -2,24 +2,24 @@ # 99_cleanup.zlogin: Don't pollute the namespace, remove variables/functions/... for func ( - ax_hostname_prompt_root - ax_hostname_prompt_yn - ax_logname_prompt_root - ax_logname_prompt_yn - ax_prompt + axzsh_hostname_prompt_root + axzsh_hostname_prompt_yn + axzsh_logname_prompt_root + axzsh_logname_prompt_yn + axzsh_prompt ); do unfunction $func 2>/dev/null done -for func ($ax_logname_prompt_functions); do +for func ($axzsh_logname_prompt_functions); do unfunction $func 2>/dev/null done -unset ax_logname_prompt_functions +unset axzsh_logname_prompt_functions -for func ($ax_hostname_prompt_functions); do +for func ($axzsh_hostname_prompt_functions); do unfunction $func 2>/dev/null done -unset ax_hostname_prompt_functions +unset axzsh_hostname_prompt_functions # Try to map OhMyZsh theme Environment ... [[ -n "$ZSH_THEME_GIT_PROMPT_AHEAD" ]] \ diff --git a/default_plugins/ssh/ssh.zshrc b/default_plugins/ssh/ssh.zshrc index 0faab3c..d275b06 100644 --- a/default_plugins/ssh/ssh.zshrc +++ b/default_plugins/ssh/ssh.zshrc @@ -15,13 +15,13 @@ ssh-autoadd() { ssh-add } -_ax_ssh_prompt() { +_axzsh_ssh_prompt() { [[ -n "$SSH_CLIENT" ]] || return 1 return 0 } -ax_logname_prompt_functions=($ax_logname_prompt_functions _ax_ssh_prompt) -ax_hostname_prompt_functions=($ax_hostname_prompt_functions _ax_ssh_prompt) +axzsh_logname_prompt_functions=($axzsh_logname_prompt_functions _axzsh_ssh_prompt) +axzsh_hostname_prompt_functions=($axzsh_hostname_prompt_functions _axzsh_ssh_prompt) # Validate SSH_AUTH_SOCK: Inside of screen(1) sessions for example, the socket # file becomes invalid when the session has been disconnected. diff --git a/plugins/git/git.zshrc b/plugins/git/git.zshrc index 4a4e430..ba71aa4 100644 --- a/plugins/git/git.zshrc +++ b/plugins/git/git.zshrc @@ -57,7 +57,7 @@ git_prompt() { # OhMyZsh compatibility functions alias parse_git_dirty=git_parse_dirty -ax_vcs_prompt_functions=($ax_vcs_prompt_functions git_prompt) +axzsh_vcs_prompt_functions=($axzsh_vcs_prompt_functions git_prompt) alias fix="gd --name-only | uniq | xargs $EDITOR" alias g="git" diff --git a/themes/ax.axzshtheme b/themes/ax.axzshtheme index 0a4eda4..ddb67f0 100644 --- a/themes/ax.axzshtheme +++ b/themes/ax.axzshtheme @@ -9,11 +9,11 @@ ZSH_THEME_PROMPT_ROOT_PREFIX="%{$fg_bold[red]%}" ZSH_THEME_PROMPT_SUFFIX="%b%{$reset_color%}" ZSH_THEME_PROMPT_SUFFIX_SPACING=" " -ax_logname_prompt_functions=($ax_logname_prompt_functions ax_logname_prompt_root) -ax_hostname_prompt_functions=($ax_hostname_prompt_functions ax_hostname_prompt_root) +axzsh_logname_prompt_functions=($axzsh_logname_prompt_functions axzsh_logname_prompt_root) +axzsh_hostname_prompt_functions=($axzsh_hostname_prompt_functions axzsh_hostname_prompt_root) # The primary prompt string, printed before a command is read. -PS1="$(ax_logname_prompt_yn)$(ax_hostname_prompt_yn)%B%2~%b"'$(ax_vcs_prompt)'"$(ax_prompt)" +PS1="$(axzsh_logname_prompt_yn)$(axzsh_hostname_prompt_yn)%B%2~%b"'$(axzsh_vcs_prompt)'"$(axzsh_prompt)" # Primary prompt on the right-hand side. axzsh_is_utf_terminal \ diff --git a/themes/axemoji.axzshtheme b/themes/axemoji.axzshtheme index 331a322..ec12376 100644 --- a/themes/axemoji.axzshtheme +++ b/themes/axemoji.axzshtheme @@ -32,7 +32,7 @@ else fi # The primary prompt string, printed before a command is read. -PS1="${system_emoji}${emoji_spacing} $(ax_logname_prompt_yn)$(ax_hostname_prompt_yn)%B%2~%b"'$(ax_vcs_prompt)'"$(ax_prompt)" +PS1="${system_emoji}${emoji_spacing} $(axzsh_logname_prompt_yn)$(axzsh_hostname_prompt_yn)%B%2~%b"'$(axzsh_vcs_prompt)'"$(axzsh_prompt)" # Default execution trace prompt. PS4="$fg_no_bold[yellow]->$reset_color " diff --git a/themes/debian.axzshtheme b/themes/debian.axzshtheme index b16c497..5f004fb 100644 --- a/themes/debian.axzshtheme +++ b/themes/debian.axzshtheme @@ -3,4 +3,4 @@ ZSH_THEME_PROMPT_SUFFIX_SPACING=" " -PS1="%{$fg_bold[green]%}%n@%m%{$reset_color%}:%{$fg_bold[blue]%}%~%{$reset_color%}"'$(ax_vcs_prompt)'"$(ax_prompt)" +PS1="%{$fg_bold[green]%}%n@%m%{$reset_color%}:%{$fg_bold[blue]%}%~%{$reset_color%}"'$(axzsh_vcs_prompt)'"$(axzsh_prompt)" diff --git a/themes/ohmyzsh.axzshtheme b/themes/ohmyzsh.axzshtheme index c3612c3..f3beed4 100644 --- a/themes/ohmyzsh.axzshtheme +++ b/themes/ohmyzsh.axzshtheme @@ -2,7 +2,7 @@ # ohmyzsh.axzshtheme: OhMyZSH "robbyrussell" theme ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)" -PS1='${ret_status} %{$fg[cyan]%}%c%b $(ax_vcs_prompt)%b ' +PS1='${ret_status} %{$fg[cyan]%}%c%b $(axzsh_vcs_prompt)%b ' ZSH_THEME_VCS_PROMPT_PREFIX_SPACING="%{$fg_bold[blue]%}vcs:(" ZSH_THEME_VCS_PROMPT_PREFIX="%{$fg[red]%}" -- 2.39.2