Skip to content

Commit 74d0839

Browse files
committed
Use hooks instead of preexec and precmd functions, better newlines
1 parent 050d921 commit 74d0839

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

sobole.zsh-theme

+14-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ _return_status="%(?..%{$fg[red]%}%? ⚠️%{$reset_color%})"
2828

2929
RPROMPT='%{$(echotc UP 1)%} $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'
3030

31-
function __sobole::current_caret {
31+
__sobole::current_caret () {
3232
# This function sets caret color and sign
3333
# based on theme and privileges.
3434
if [[ "$USER" == 'root' ]] || [[ "$(id -u "$USER")" == 0 ]]; then
@@ -47,7 +47,7 @@ function __sobole::current_caret {
4747
echo "%{$fg[$CARET_COLOR]%}$CARET_SIGN%{$reset_color%}"
4848
}
4949

50-
function __sobole::current_dir {
50+
__sobole::current_dir () {
5151
# Settings up current directory and settings max width for it:
5252
local max_pwd_length="${SOBOLE_MAX_DIR_LEN:-65}"
5353
local color
@@ -65,7 +65,7 @@ function __sobole::current_dir {
6565
fi
6666
}
6767

68-
function __sobole::user_info {
68+
__sobole::user_info () {
6969
# Shows user in the PROMPT if needed.
7070
if [[ ! -z "$SOBOLE_DEFAULT_USER" ]] &&
7171
[[ "$USER" != "$SOBOLE_DEFAULT_USER" ]]; then
@@ -85,7 +85,7 @@ function __sobole::user_info {
8585
# Disable the standard prompt:
8686
export VIRTUAL_ENV_DISABLE_PROMPT=1
8787

88-
function __sobole::current_venv {
88+
__sobole::current_venv () {
8989
if [[ ! -z "$VIRTUAL_ENV" ]]; then
9090
# Show this info only if virtualenv is activated:
9191
local dir=$(basename "$VIRTUAL_ENV")
@@ -215,16 +215,22 @@ fi
215215

216216
_SOBOLE_ADD_LINE_SEPARATOR='false'
217217

218-
preexec() {
219-
if [[ "$2" == 'clear' ]]; then
218+
__sobole::preexec () {
219+
if [[ $# -eq 0 ]] || [[ "$2" == 'clear' ]]; then
220220
_SOBOLE_ADD_LINE_SEPARATOR='false'
221221
else
222222
_SOBOLE_ADD_LINE_SEPARATOR='true'
223223
fi
224224
}
225225

226-
precmd() {
227-
if [[ "$_SOBOLE_ADD_LINE_SEPARATOR" == 'true' ]]; then
226+
__sobole::precmd () {
227+
local cmd_result="$?"
228+
if [[ "$_SOBOLE_ADD_LINE_SEPARATOR" == 'true' ]] ||
229+
[[ "$cmd_result" -ne 0 ]]; then
228230
print
229231
fi
230232
}
233+
234+
autoload -Uz add-zsh-hook
235+
add-zsh-hook preexec __sobole::preexec
236+
add-zsh-hook precmd __sobole::precmd

0 commit comments

Comments
 (0)