From c360f95111c23374490acbec30c22b85e1e3542b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 27 Dec 2016 01:55:03 +1300 Subject: Add another issue --- ISSUES.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ISSUES.markdown b/ISSUES.markdown index 0434d54e..60558e80 100644 --- a/ISSUES.markdown +++ b/ISSUES.markdown @@ -18,3 +18,5 @@ Known issues they succeed? Did I do that or is it Bash? * Wouldn't be too hard to add some HTTP BASIC auth to ix(1df) to make pastes manageable +* On non-OBSD pdksh and mksh, !! comes out as literal !! after subshell + expansion; a version switch might be necessary -- cgit v1.2.3 From 90dcadfb2e6e82b7d5e9bdbac2c109433f70caf7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 27 Dec 2016 02:26:00 +1300 Subject: Realised easy win avoiding subshells And also the PROMPT_RETURN fudge in Bash/Zsh --- bash/bashrc.d/prompt.bash | 11 ++++------- ksh/kshrc.d/prompt.ksh | 6 +----- zsh/zshrc.d/prompt.zsh | 13 ++----------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 776ac8a6..d923ef20 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -6,11 +6,8 @@ prompt() { # Turn complex, colored PS1 and debugging PS4 prompts on on) - # Declare the PROMPT_RETURN variable as an integer - declare -i PROMPT_RETURN - # Set up pre-prompt command - PROMPT_COMMAND='PROMPT_RETURN=$? ; history -a' + PROMPT_COMMAND='history -a' # If Bash 4.0 is available, trim very long paths in prompt ((BASH_VERSINFO[0] >= 4)) && PROMPT_DIRTRIM=4 @@ -23,7 +20,7 @@ prompt() { PS1=$PS1'\w' # Add sub-commands; VCS, job, and return status checks - PS1=$PS1'$(prompt vcs)$(prompt job)$(prompt ret)' + PS1=$PS1'$(ret=$?;prompt vcs;prompt job;prompt ret)' # Add prefix and suffix PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}' @@ -83,7 +80,7 @@ prompt() { # Revert to simple inexpensive prompts off) - unset -v PROMPT_COMMAND PROMPT_DIRTRIM PROMPT_RETURN + unset -v PROMPT_COMMAND PROMPT_DIRTRIM PS1='\$ ' PS2='> ' PS3='? ' @@ -218,7 +215,7 @@ prompt() { # Show return status of previous command in angle brackets, if not zero ret) - ((PROMPT_RETURN)) && printf '<%u>' "$PROMPT_RETURN" + ((ret)) && printf '<%u>' "$ret" ;; # Show the count of background jobs in curly brackets, if not zero diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh index 99e193b2..4a58f46d 100644 --- a/ksh/kshrc.d/prompt.ksh +++ b/ksh/kshrc.d/prompt.ksh @@ -20,15 +20,11 @@ function prompt { # Add sub-commands; working directory with ~ abbreviation, VCS, job # count, and previous command return value - PS1=$PS1'$(prompt pwd)$(prompt vcs)$(prompt job)$(prompt ret)' + PS1=$PS1'$(ret=$?;prompt pwd;prompt vcs;prompt job;prompt ret)' # Add prefix and suffix PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}' - # Add a wrapper around the prompt as determined so far so that the - # return value from the previous command doesn't get lost - PS1='$(ret=$?;printf %s "'"$PS1"'")' - # Add terminating "$" or "#" sign PS1=$PS1'\$' diff --git a/zsh/zshrc.d/prompt.zsh b/zsh/zshrc.d/prompt.zsh index 5dc00fd3..27db61cb 100644 --- a/zsh/zshrc.d/prompt.zsh +++ b/zsh/zshrc.d/prompt.zsh @@ -8,14 +8,6 @@ prompt() { on) setopt promptsubst promptpercent - # Declare the PROMPT_RETURN variable as an integer - declare -i PROMPT_RETURN - - # Set up pre-prompt command - precmd() { - PROMPT_RETURN=$? - } - # Basic prompt shape depends on whether we're in SSH or not PS1= if [[ -n $SSH_CLIENT ]] || [[ -n $SSH_CONNECTION ]] ; then @@ -24,7 +16,7 @@ prompt() { PS1=$PS1'%~' # Add sub-commands; VCS, job, and return status checks - PS1=$PS1'$(prompt vcs)$(prompt job)$(prompt ret)' + PS1=$PS1'$(ret=$?;prompt vcs;prompt job;prompt ret)' # Add prefix and suffix PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}' @@ -52,7 +44,6 @@ prompt() { # Revert to simple inexpensive prompts off) - unset -v precmd PROMPT_RETURN PS1='\$ ' PS2='> ' PS3='? ' @@ -187,7 +178,7 @@ prompt() { # Show return status of previous command in angle brackets, if not zero ret) - ((PROMPT_RETURN)) && printf '<%u>' "$PROMPT_RETURN" + ((ret)) && printf '<%u>' "$ret" ;; # Show the count of background jobs in curly brackets, if not zero -- cgit v1.2.3 From 3828a1ff720dd08823d91ef0fb237540f1754bea Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 27 Dec 2016 02:29:18 +1300 Subject: Tell ShellCheck to ignore an error ret actually is assigned, just not in any place ShellCheck could reasonably be expected to find --- bash/bashrc.d/prompt.bash | 1 + ksh/kshrc.d/prompt.ksh | 1 + zsh/zshrc.d/prompt.zsh | 1 + 3 files changed, 3 insertions(+) diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index d923ef20..aa96cdda 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -215,6 +215,7 @@ prompt() { # Show return status of previous command in angle brackets, if not zero ret) + # shellcheck disable=SC2154 ((ret)) && printf '<%u>' "$ret" ;; diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh index 4a58f46d..063f5210 100644 --- a/ksh/kshrc.d/prompt.ksh +++ b/ksh/kshrc.d/prompt.ksh @@ -186,6 +186,7 @@ function prompt { # Show return status of previous command in angle brackets, if not zero ret) + # shellcheck disable=SC2154 ((ret)) && printf '<%u>' "$ret" ;; diff --git a/zsh/zshrc.d/prompt.zsh b/zsh/zshrc.d/prompt.zsh index 27db61cb..898031ea 100644 --- a/zsh/zshrc.d/prompt.zsh +++ b/zsh/zshrc.d/prompt.zsh @@ -178,6 +178,7 @@ prompt() { # Show return status of previous command in angle brackets, if not zero ret) + # shellcheck disable=SC2154 ((ret)) && printf '<%u>' "$ret" ;; -- cgit v1.2.3 From d71d8492a373306333711da74c3318f9c2c67d53 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 27 Dec 2016 02:41:56 +1300 Subject: Add workaround to what looks like a bug to me --- ISSUES.markdown | 4 ++++ bash/bashrc.d/prompt.bash | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/ISSUES.markdown b/ISSUES.markdown index 60558e80..5d9d43d3 100644 --- a/ISSUES.markdown +++ b/ISSUES.markdown @@ -20,3 +20,7 @@ Known issues manageable * On non-OBSD pdksh and mksh, !! comes out as literal !! after subshell expansion; a version switch might be necessary +* Running the block of git(1) commands in the prompt leaves five "stale" + jobspecs around that flee after a jobs builtin run; only saw this manifest + after 90dcadf; either I understand job specs really poorly or this may be a + bug in bash diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index aa96cdda..123c4146 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -156,6 +156,11 @@ prompt() { } >/dev/null 2>&1 + # For some reason, five commands in the above block seem to stick + # around as jobs after this command is over; I don't know why, but + # this clears it; might be a bug + jobs >/dev/null + # Print the status in brackets; add a git: prefix only if there # might be another VCS prompt (because PROMPT_VCS is set) printf '(%s%s%s%s)' \ -- cgit v1.2.3