]> arthur.barton.de Git - ax-zsh.git/commitdiff
Refactor prompt functions
authorAlexander Barton <alex@barton.de>
Sun, 27 Sep 2015 17:34:18 +0000 (19:34 +0200)
committerAlexander Barton <alex@barton.de>
Sun, 27 Sep 2015 17:34:18 +0000 (19:34 +0200)
- Initialize ax_*_prompt_functions arrays.
- ax_logname_prompt -> ax_logname_prompt_yn, return boolean.
- ax_hostname_prompt -> ax_hostname_prompt_yn, return boolean.
- ssh_logname_prompt -> _ax_ssh_logname_prompt, return boolean.

core/50_prompt/50_prompt.zshrc
default_plugins/prompt/prompt.zlogin
default_plugins/ssh/ssh.zshrc

index 5dc89d93c37f8460e3543fe4657d908b846266d8..6f8da72b3c11e2a086cd3ed2f2cd02e505ada5d6 100644 (file)
@@ -14,18 +14,18 @@ function ax_logname_prompt_root() {
        return 0
 }
 
-ax_logname_prompt_functions=($ax_logname_prompt_functions ax_logname_prompt_root)
-
-function ax_logname_prompt() {
+function ax_logname_prompt_yn() {
        local func
        local p
        for func ($ax_logname_prompt_functions); do
-               p=$( $func ) || continue
-               echo "${ZSH_THEME_LOGNAME_PROMPT_PREFIX}${p}${ZSH_THEME_LOGNAME_PROMPT_SUFFIX}"
+               $func || continue
+               echo "${ZSH_THEME_LOGNAME_PROMPT_PREFIX}${1:-$LOGNAME}${ZSH_THEME_LOGNAME_PROMPT_SUFFIX}"
                return
        done
 }
 
+ax_logname_prompt_functions=()
+
 # Hostname
 
 ZSH_THEME_HOSTNAME_PROMPT_PREFIX=""
@@ -33,22 +33,21 @@ ZSH_THEME_HOSTNAME_PROMPT_SUFFIX="%{$reset_color%}:"
 
 function ax_hostname_prompt_root() {
        (( $UID == 0 )) || return 1
-       echo "$SHORT_HOST"
        return 0
 }
 
-ax_hostname_prompt_functions=($ax_hostname_prompt_functions ax_hostname_prompt_root)
-
-function ax_hostname_prompt() {
+function ax_hostname_prompt_yn() {
        local func
        local p
        for func ($ax_hostname_prompt_functions); do
-               p=$( $func ) || continue
-               echo "${ZSH_THEME_HOSTNAME_PROMPT_PREFIX}${p}${ZSH_THEME_HOSTNAME_PROMPT_SUFFIX}"
+               $func || continue
+               echo "${ZSH_THEME_HOSTNAME_PROMPT_PREFIX}${1:-$SHORT_HOST}${ZSH_THEME_HOSTNAME_PROMPT_SUFFIX}"
                return
        done
 }
 
+ax_hostname_prompt_functions=()
+
 # VCS
 
 ZSH_THEME_VCS_PROMPT_PREFIX="(%{$fg_no_bold[yellow]%}"
@@ -69,6 +68,8 @@ function ax_vcs_prompt() {
        done
 }
 
+ax_vcs_prompt_functions=()
+
 # Options and defaults
 
 setopt PROMPT_SUBST
index eeda754d7c75894547257e0d6af4c12afa6f2727..7514fc468e5801ef839ca6e8f0cebc1849499c77 100644 (file)
@@ -2,7 +2,7 @@
 # prompt.zlogin: Setup default prompts
 
 # Default prompt
-PS1='$(ax_logname_prompt)$(ax_hostname_prompt)%B%2~%b $(ax_vcs_prompt)%{$fg_no_bold[green]%}%B$%b%{$reset_color%} '
+PS1='$(ax_logname_prompt_yn)$(ax_hostname_prompt_yn)%B%2~%b $(ax_vcs_prompt)%{$fg_no_bold[green]%}%B\$%b%{$reset_color%} '
 
 # Prompt on right side
 RPS1="%(?..%{$fg_no_bold[red]%}%? ↵%{$reset_color%})"
index c63985b514dc1dfc6f697be02ecd160e3f42d5fc..8d22ae2a074fdf762c1bb1b666e4132d01ce0cc3 100644 (file)
@@ -4,18 +4,10 @@
 # Make sure that "ssh(1)" is installed
 (( $+commands[ssh] )) || return
 
-ssh_logname_prompt() {
+_ax_ssh_prompt() {
        [[ -n "$SSH_CLIENT" ]] || return 1
-       echo "$LOGNAME"
        return 0
 }
 
-ax_logname_prompt_functions=($ax_logname_prompt_functions ssh_logname_prompt)
-
-ssh_hostname_prompt() {
-       [[ -n "$SSH_CLIENT" ]] || return 1
-       echo "$SHORT_HOST"
-       return 0
-}
-
-ax_hostname_prompt_functions=($ax_hostname_prompt_functions ssh_hostname_prompt)
+ax_logname_prompt_functions=($ax_logname_prompt_functions _ax_ssh_prompt)
+ax_hostname_prompt_functions=($ax_hostname_prompt_functions _ax_ssh_prompt)