]> arthur.barton.de Git - ax-zsh.git/commitdiff
Introduce new "ax-io" stage, which is run before all other stages
authorAlexander Barton <alex@barton.de>
Thu, 11 Jun 2020 12:03:50 +0000 (14:03 +0200)
committerAlexander Barton <alex@barton.de>
Thu, 11 Jun 2020 12:03:50 +0000 (14:03 +0200)
This is in preparation of supporting Powerlevel10k "instant prompt",
which requires all input/output be done before activating it.

ax.zsh
core/11_terminal/11_terminal.ax-io [new file with mode: 0644]
core/11_terminal/11_terminal.zprofile [deleted file]
core/12_locale/12_locale.ax-io [new file with mode: 0644]
core/12_locale/12_locale.zprofile [deleted file]
plugins/icalbuddy/icalbuddy.ax-io [new file with mode: 0644]
plugins/icalbuddy/icalbuddy.zshrc [deleted file]
plugins/remind/remind.ax-io [new file with mode: 0644]
plugins/remind/remind.zshrc [deleted file]

diff --git a/ax.zsh b/ax.zsh
index 197c5f0928a0da84d4aa8ded8a9028f5e78082a2..2d7bd66b6093f705d3cca365871fcb098612285e 100644 (file)
--- a/ax.zsh
+++ b/ax.zsh
@@ -7,7 +7,7 @@ script_type="$script_name[2,-1]"
 # Handle "initialization stage", load all plugins of that stage, either from an
 # existing cache file or individually, optionally creating the cache.
 # - $1: Script name
-# - $2: Stage name (zprofile, zshrc, zlogin, zlogout)
+# - $2: Stage name (ax-io, zprofile, zshrc, zlogin, zlogout)
 function axzsh_handle_stage {
        name="$1"
        type="$2"
@@ -101,7 +101,7 @@ function axzsh_load_plugin {
 
        if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
                zsh_themes=("$dname/"*.zsh-theme(NY1))
-               if [[ -r "$dname/$plugin.zprofile" || -r "$dname/$plugin.zlogout" ]]; then
+               if [[ -r "$dname/$plugin.ax-io" || -r "$dname/$plugin.zprofile" || -r "$dname/$plugin.zlogout" ]]; then
                        # Native AX-ZSH plugin, but for different stage. Skip it!
                        :
                elif [[ -r "$dname/${plugin_short}.plugin.zsh" ]]; then
@@ -201,6 +201,11 @@ if [[ -z "$AXZSH" ]]; then
        fi
 fi
 
+if [[ "$script_type" = "zprofile" ]]; then
+       # Load all "output" plugins first, that is, before the "zprofile stage":
+       axzsh_handle_stage "$script_name" "ax-io"
+fi
+
 axzsh_handle_stage "$script_name" "$script_type"
 
 # Clean up ...
diff --git a/core/11_terminal/11_terminal.ax-io b/core/11_terminal/11_terminal.ax-io
new file mode 100644 (file)
index 0000000..1ddb802
--- /dev/null
@@ -0,0 +1,12 @@
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 10_terminal.zprofile: Initialize terminal settings
+
+# Use tset(1) to validate TERM when stdin as a tty. Explicitly set SHELL to
+# /bin/sh to force tset to output sh-compliant commands even when SHELL was not
+# set correctly or for an other shell.
+[[ -t 0 ]] && eval `SHELL=/bin/sh tset -Is -m "dec-vt52:vt52"`
+
+# Is TERM still unset?
+[[ -z "$TERM" ]] && TERM="dumb"
+
+export TERM
diff --git a/core/11_terminal/11_terminal.zprofile b/core/11_terminal/11_terminal.zprofile
deleted file mode 100644 (file)
index 1ddb802..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 10_terminal.zprofile: Initialize terminal settings
-
-# Use tset(1) to validate TERM when stdin as a tty. Explicitly set SHELL to
-# /bin/sh to force tset to output sh-compliant commands even when SHELL was not
-# set correctly or for an other shell.
-[[ -t 0 ]] && eval `SHELL=/bin/sh tset -Is -m "dec-vt52:vt52"`
-
-# Is TERM still unset?
-[[ -z "$TERM" ]] && TERM="dumb"
-
-export TERM
diff --git a/core/12_locale/12_locale.ax-io b/core/12_locale/12_locale.ax-io
new file mode 100644 (file)
index 0000000..689b674
--- /dev/null
@@ -0,0 +1,71 @@
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 12_locale.zprofile: Initialize locale settings
+
+# This is only relevant for interactive shells (because the user has to
+# manually enter data when the validation fails):
+[[ -z "$PS1" ]] && return 0
+
+# Make sure that LANG and LC_MESSAGES are either unset or set to something sane,
+# that is, follow the "xx_ZZ.*" syntax.
+fix_locale() {
+       local encoding locale
+
+       locale="$1:r"
+       encoding="$1:e"
+
+       if [[ -z "$1" || "$locale" =~ '.*_.*' || ${#locale%%_*} -ne 2 ]]; then
+               echo "$1"
+       else
+               locale="${locale:0:2}_${locale:0:2:u}"
+               [[ -n "$encoding" ]] && locale="$locale.$encoding"
+               echo "$locale"
+       fi
+}
+[[ -n "$LANG" ]] && LANG=$(fix_locale "$LANG")
+[[ -n "$LC_MESSAGES" ]] && LANG=$(fix_locale "$LC_MESSAGES")
+unfunction fix_locale
+
+# Validate the locale(7) settings in interactive shells and try to mimic the
+# tset(1) behaviour.
+while true; do
+       lc_messages=$(locale 2>/dev/null | fgrep LC_MESSAGES | cut -d'=' -f2)
+       [[ "$lc_messages" = '"C"' && "$LANG" != 'C' && "$LC_ALL" != 'C' ]] && lc_messages=$LANG
+       lc_messages=$lc_messages:gs/\"//
+       locale=$lc_messages:r
+       [[ ( "$OSTYPE" =~ '^linux-gnu' || "$OSTYPE" = 'cygwin') && $locale != 'C' ]] \
+               && encoding=$lc_messages:e:l:gs/-// \
+               || encoding=$lc_messages:e
+       [[ -n "$encoding" ]] && locale="$locale.$encoding"
+       [[ -z "$LANG$LANGUAGE$LC_ALL$LC_MESSAGES" ]] && unset lc_messages
+
+       if [[ -n "$LANG$LANGUAGE$LC_ALL$LC_MESSAGES" ]] && locale -a 2>/dev/null | grep "^$locale\$" >/dev/null; then
+               # The locale setting seems to be valid: one of the LANG,
+               # LANGUAGE, LC_ALL and/or LC_MESSAGES is set and the locale is
+               # included in "locale -a" output. Good!
+               break
+       fi
+
+       echo "ax-zsh: unknown/unsupported locale ${lc_messages:-unknown}" >&2
+       unset locale
+       while [[ -z "$locale" ]]; do
+               if ! read "locale?Locale? "; then
+                       echo >&2
+                       break 2
+               fi
+       done
+       if [[ -n "$locale" ]]; then
+               export LANG=$locale
+               unset LANGUAGE LC_ALL LC_MESSAGES
+       fi
+done
+unset lc_messages locale encoding
+
+case "$LANG" in
+       *_*)
+               # LANG contains at least one "_" ("aa_BB" form).
+               if [[ -z "$LANGUAGE" ]]; then
+                       # But LANGUAGE isn't set, so set it automatically to
+                       # "aa_BB:aa" form.
+                       export LANGUAGE=${LANG%.*}:${${LANG%.*}%_*}
+               fi
+esac
diff --git a/core/12_locale/12_locale.zprofile b/core/12_locale/12_locale.zprofile
deleted file mode 100644 (file)
index 689b674..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 12_locale.zprofile: Initialize locale settings
-
-# This is only relevant for interactive shells (because the user has to
-# manually enter data when the validation fails):
-[[ -z "$PS1" ]] && return 0
-
-# Make sure that LANG and LC_MESSAGES are either unset or set to something sane,
-# that is, follow the "xx_ZZ.*" syntax.
-fix_locale() {
-       local encoding locale
-
-       locale="$1:r"
-       encoding="$1:e"
-
-       if [[ -z "$1" || "$locale" =~ '.*_.*' || ${#locale%%_*} -ne 2 ]]; then
-               echo "$1"
-       else
-               locale="${locale:0:2}_${locale:0:2:u}"
-               [[ -n "$encoding" ]] && locale="$locale.$encoding"
-               echo "$locale"
-       fi
-}
-[[ -n "$LANG" ]] && LANG=$(fix_locale "$LANG")
-[[ -n "$LC_MESSAGES" ]] && LANG=$(fix_locale "$LC_MESSAGES")
-unfunction fix_locale
-
-# Validate the locale(7) settings in interactive shells and try to mimic the
-# tset(1) behaviour.
-while true; do
-       lc_messages=$(locale 2>/dev/null | fgrep LC_MESSAGES | cut -d'=' -f2)
-       [[ "$lc_messages" = '"C"' && "$LANG" != 'C' && "$LC_ALL" != 'C' ]] && lc_messages=$LANG
-       lc_messages=$lc_messages:gs/\"//
-       locale=$lc_messages:r
-       [[ ( "$OSTYPE" =~ '^linux-gnu' || "$OSTYPE" = 'cygwin') && $locale != 'C' ]] \
-               && encoding=$lc_messages:e:l:gs/-// \
-               || encoding=$lc_messages:e
-       [[ -n "$encoding" ]] && locale="$locale.$encoding"
-       [[ -z "$LANG$LANGUAGE$LC_ALL$LC_MESSAGES" ]] && unset lc_messages
-
-       if [[ -n "$LANG$LANGUAGE$LC_ALL$LC_MESSAGES" ]] && locale -a 2>/dev/null | grep "^$locale\$" >/dev/null; then
-               # The locale setting seems to be valid: one of the LANG,
-               # LANGUAGE, LC_ALL and/or LC_MESSAGES is set and the locale is
-               # included in "locale -a" output. Good!
-               break
-       fi
-
-       echo "ax-zsh: unknown/unsupported locale ${lc_messages:-unknown}" >&2
-       unset locale
-       while [[ -z "$locale" ]]; do
-               if ! read "locale?Locale? "; then
-                       echo >&2
-                       break 2
-               fi
-       done
-       if [[ -n "$locale" ]]; then
-               export LANG=$locale
-               unset LANGUAGE LC_ALL LC_MESSAGES
-       fi
-done
-unset lc_messages locale encoding
-
-case "$LANG" in
-       *_*)
-               # LANG contains at least one "_" ("aa_BB" form).
-               if [[ -z "$LANGUAGE" ]]; then
-                       # But LANGUAGE isn't set, so set it automatically to
-                       # "aa_BB:aa" form.
-                       export LANGUAGE=${LANG%.*}:${${LANG%.*}%_*}
-               fi
-esac
diff --git a/plugins/icalbuddy/icalbuddy.ax-io b/plugins/icalbuddy/icalbuddy.ax-io
new file mode 100644 (file)
index 0000000..52849bc
--- /dev/null
@@ -0,0 +1,41 @@
+# AX-ZSH: Alex' Modular ZSH Configuration
+# icalbuddy.zshrc: Show reminders using icalBuddy(1).
+
+# Make sure that "icalBuddy(1)" is installed.
+(( $+commands[icalBuddy] )) || return 1
+
+# Don't run this plugin on "check-plugins"!
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 0
+
+# Don't show reminders when ~/.hushlogin exists ...
+[[ -r ~/.hushlogin ]] && return 0
+
+# Check if reminders have been shown during last 60 minutes, and if so,
+# don't show them now but return.
+[[ -z `find ~/.last_reminder -mmin -60 2>/dev/null` ]] || return 0
+
+tmpfile=$(mktemp ${TMPDIR:-/tmp}/icalbuddy.XXXXXX) || return 1
+
+if [[ "$LANG" =~ "\.UTF" ]]; then
+       bul="•"; bul_imp="!"; sep="»"
+else
+       bul="*"; bul_imp="!"; sep=">"
+fi
+
+# Show reminders now.
+icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
+       -nc -npn -iep "title,due" -stda \
+       tasksDueBefore:today 2>/dev/null >>"$tmpfile"
+icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
+       -nc -npn -iep "title,datetime" \
+       eventsToday+1 2>/dev/null  >>"$tmpfile"
+
+if [[ -s "$tmpfile" ]]; then
+       echo; cat "$tmpfile"; echo
+fi
+
+rm -f "$tmpfile"
+unset bul bul_imp sep tmpfile
+
+# Wtite "stamp" file.
+[[ -w ~/ ]] && touch ~/.last_reminder
diff --git a/plugins/icalbuddy/icalbuddy.zshrc b/plugins/icalbuddy/icalbuddy.zshrc
deleted file mode 100644 (file)
index 390d90f..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-# AX-ZSH: Alex' Modular ZSH Configuration
-# icalbuddy.zshrc: Show reminders using icalBuddy(1).
-
-# Make sure that "icalBuddy(1)" is installed.
-(( $+commands[icalBuddy] )) || return 1
-
-# Don't run this plugin on "check-plugins"!
-[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 0
-
-# Don't show reminders when ~/.hushlogin exists ...
-[[ -r ~/.hushlogin ]] && return 0
-
-# Check if reminders have been shown during last 60 minutes, and if so,
-# don't show them now but return.
-[[ -z `find ~/.last_reminder -mmin -60 2>/dev/null` ]] || return 0
-
-tmpfile=$(mktemp ${TMPDIR:-/tmp}/icalbuddy.XXXXXX) || return 1
-
-if axzsh_is_utf_terminal; then
-       bul="•"; bul_imp="!"; sep="»"
-else
-       bul="*"; bul_imp="!"; sep=">"
-fi
-
-# Show reminders now.
-icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
-       -nc -npn -iep "title,due" -stda \
-       tasksDueBefore:today 2>/dev/null >>"$tmpfile"
-icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
-       -nc -npn -iep "title,datetime" \
-       eventsToday+1 2>/dev/null  >>"$tmpfile"
-
-if [[ -s "$tmpfile" ]]; then
-       echo; cat "$tmpfile"; echo
-fi
-
-rm -f "$tmpfile"
-unset bul bul_imp sep tmpfile
-
-# Wtite "stamp" file.
-[[ -w ~/ ]] && touch ~/.last_reminder
diff --git a/plugins/remind/remind.ax-io b/plugins/remind/remind.ax-io
new file mode 100644 (file)
index 0000000..05ee676
--- /dev/null
@@ -0,0 +1,27 @@
+# AX-ZSH: Alex' Modular ZSH Configuration
+# remind.zshrc: Show reminders of remind(1).
+
+# Make sure that "remind(1)" is installed.
+(( $+commands[remind] )) || return 1
+
+# Don't run this plugin on "check-plugins"!
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 0
+
+# Some handy alias.
+alias remindcal='remind -ccu+3 -m -w$COLUMNS,4,0 $HOME/.remind'
+
+# Don't show reminders when ~/.hushlogin exists ...
+[[ -r ~/.hushlogin ]] && return 0
+
+# Is there a file with reminders?
+[[ -r ~/.remind ]] || return 0
+
+# Check if reminders have been shown during last 60 minutes, and if so,
+# don't show them now but return.
+[[ -z `find ~/.last_reminder -mmin -60 2>/dev/null` ]] || return 0
+
+# Show reminders now.
+remind -h -g -t5 ~/.remind && echo
+
+# Wtite "stamp" file.
+[[ -w ~/ ]] && touch ~/.last_reminder
diff --git a/plugins/remind/remind.zshrc b/plugins/remind/remind.zshrc
deleted file mode 100644 (file)
index 05ee676..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-# AX-ZSH: Alex' Modular ZSH Configuration
-# remind.zshrc: Show reminders of remind(1).
-
-# Make sure that "remind(1)" is installed.
-(( $+commands[remind] )) || return 1
-
-# Don't run this plugin on "check-plugins"!
-[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 0
-
-# Some handy alias.
-alias remindcal='remind -ccu+3 -m -w$COLUMNS,4,0 $HOME/.remind'
-
-# Don't show reminders when ~/.hushlogin exists ...
-[[ -r ~/.hushlogin ]] && return 0
-
-# Is there a file with reminders?
-[[ -r ~/.remind ]] || return 0
-
-# Check if reminders have been shown during last 60 minutes, and if so,
-# don't show them now but return.
-[[ -z `find ~/.last_reminder -mmin -60 2>/dev/null` ]] || return 0
-
-# Show reminders now.
-remind -h -g -t5 ~/.remind && echo
-
-# Wtite "stamp" file.
-[[ -w ~/ ]] && touch ~/.last_reminder