From fdcabaf507ba1dd41fe1345f15989623c941ba31 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Thu, 18 Aug 2011 02:23:31 +0000 Subject: Use preexec hook to replace "fg" et al. with the jobtext of the resumed job. --- Functions/Prompts/prompt_bart_setup | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'Functions/Prompts/prompt_bart_setup') diff --git a/Functions/Prompts/prompt_bart_setup b/Functions/Prompts/prompt_bart_setup index 1cc7b6f08..a264cdce1 100644 --- a/Functions/Prompts/prompt_bart_setup +++ b/Functions/Prompts/prompt_bart_setup @@ -67,15 +67,38 @@ prompt_bart_help () { } integer PSCOL=1 +typeset PSCMD= + +prompt_bart_preexec () { + setopt localoptions noxtrace noksharrays unset + local -a cmd; cmd=( ${(z)3} ) + if [[ $cmd[1] = fg ]] + then + shift cmd + cmd[1]=${cmd[1]:-%+} + fi + if [[ $#cmd -eq 1 && $cmd[1] = %* ]] + then + PSCMD=$jobtexts[$cmd[1]] + elif [[ -o autoresume && -n $jobtexts[%?$2] ]] + then + PSCMD=$jobtexts[%?$2] + else + PSCMD=$2 + fi + return 0 +} prompt_bart_precmd () { setopt localoptions noxtrace noksharrays unset local zero='%([BSUbfksu]|[FB]{*})' escape colno lineno + : "${PSCMD:=$history[$[HISTCMD-1]]}" # Default to history text + # Using psvar here protects against unwanted promptsubst expansions. - psvar[7]="$history[$[HISTCMD-1]]" # Use history text, not just number - psvar[8]='' # No padding until we compute it + psvar[7]="$PSCMD" + psvar[8]='' # No padding until we compute it psvar[9]=() typeset -g PSCOL @@ -153,6 +176,7 @@ prompt_bart_setup () { repeat 1 case "$1:l" in (off|disable) add-zsh-hook -D precmd "prompt_*_precmd" + add-zsh-hook -D preexec "prompt_*_preexec" functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch}" [[ $prompt_theme[1] = bart ]] && PS1=${${(f)PS1}[-1]} return 1 @@ -182,6 +206,7 @@ prompt_bart_setup () { # Paste our special commands into precmd and TRAPWINCH add-zsh-hook precmd prompt_bart_precmd + add-zsh-hook preexec prompt_bart_preexec functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch} prompt_bart_winch" -- cgit v1.2.3 From 557baa173c6be93e475d6e25d3fb0c80164d6e87 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Mon, 29 Aug 2011 16:08:28 +0000 Subject: users/16291: prompt_bart_preexec uses history text in the non-"fg" case to avoid alias expansion. --- ChangeLog | 7 ++++++- Functions/Prompts/prompt_bart_setup | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'Functions/Prompts/prompt_bart_setup') diff --git a/ChangeLog b/ChangeLog index 0bd63d991..5c800d16b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-29 Barton E. Schaefer + + * users/16291: Functions/Prompts/prompt_bart_setup: revert to + using history text in non-"fg" case to avoid alias expansion. + 2011-08-29 Mikael Magnusson * 29722: Completion/X/Command/_mplayer: escape colon. @@ -15344,5 +15349,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5448 $ +* $Revision: 1.5449 $ ***************************************************** diff --git a/Functions/Prompts/prompt_bart_setup b/Functions/Prompts/prompt_bart_setup index a264cdce1..6cbbb71c7 100644 --- a/Functions/Prompts/prompt_bart_setup +++ b/Functions/Prompts/prompt_bart_setup @@ -70,7 +70,7 @@ integer PSCOL=1 typeset PSCMD= prompt_bart_preexec () { - setopt localoptions noxtrace noksharrays unset + setopt localoptions noxtrace noshwordsplit noksharrays unset local -a cmd; cmd=( ${(z)3} ) if [[ $cmd[1] = fg ]] then @@ -84,7 +84,8 @@ prompt_bart_preexec () { then PSCMD=$jobtexts[%?$2] else - PSCMD=$2 + # Use history text to avoid alias expansion + PSCMD=$history[$HISTCMD] fi return 0 } -- cgit v1.2.3