T34: review round 1: PowerShell reads a native program's code only when one ran in the command, by the new object each run stores, and 1 for any other failure; bash 3.2 runs the user's own DEBUG trap after its own and keeps $_, and a line that is only a subshell sends its D from the prompt by the command number; zsh marks the first prompt under a theme that sets PS1 in its own hook, through sched; each shell run gets its own folder
This commit is contained in:
6 files changed
+103
-28
No files matched your search
@@ -13,28 +13,37 @@ else
|
||||
[ -r ~/.bashrc ] && builtin source ~/.bashrc
|
||||
fi
|
||||
_ely_ran=
|
||||
_ely_sent=
|
||||
_ely_n=0
|
||||
_ely_armed=
|
||||
_ely_ps0=
|
||||
if (( BASH_VERSINFO[0] * 100 + BASH_VERSINFO[1] >= 404 )); then
|
||||
# PS0 runs in the shell, so its subscript can note that a command ran.
|
||||
_ely_ps0='${_ely_note[_ely_ran=1]-}\e]133;C\a'
|
||||
elif [ -z "$(builtin trap -p DEBUG)" ]; then
|
||||
else
|
||||
# bash 3.2 has no PS0: the DEBUG trap sends C, then runs the user's own trap with $? and $_ kept.
|
||||
_ely_debug() {
|
||||
[ -n "$_ely_armed" ] || builtin return 0
|
||||
case $BASH_COMMAND in _ely_*) builtin return 0 ;; esac
|
||||
_ely_armed=
|
||||
_ely_ran=1
|
||||
builtin printf '\e]133;C\a'
|
||||
builtin local status=$?
|
||||
if [ -n "$_ely_armed" ] && [[ $BASH_COMMAND != _ely_* ]]; then
|
||||
_ely_armed=
|
||||
_ely_ran=1
|
||||
builtin printf '\e]133;C\a'
|
||||
fi
|
||||
builtin return $status
|
||||
}
|
||||
builtin trap '_ely_debug' DEBUG
|
||||
builtin eval "_ely_trap=($(builtin trap -p DEBUG))"
|
||||
builtin trap "_ely_debug \"\$_\"${_ely_trap[2]:+; ${_ely_trap[2]}}" DEBUG
|
||||
builtin unset _ely_trap
|
||||
fi
|
||||
_ely_prompt() {
|
||||
builtin local ret=$? LC_ALL=C char url= i title
|
||||
_ely_armed=
|
||||
_ely_sent=$_ely_ran
|
||||
if [ -n "$_ely_ran" ]; then
|
||||
builtin printf '\e]133;D;%s\a' "$ret"
|
||||
_ely_ran=
|
||||
fi
|
||||
_ely_d=([1]=$'\e]133;D;'"$ret"$'\a')
|
||||
for (( i = 0; i < ${#PWD}; i++ )); do
|
||||
char=${PWD:i:1}
|
||||
case $char in
|
||||
@@ -48,7 +57,14 @@ _ely_prompt() {
|
||||
}
|
||||
# Last, after anything that sets PS1 or PS0.
|
||||
_ely_mark() {
|
||||
[[ $PS1 == *'\e]133;A'* ]] || PS1='\[\e]133;A\a\]'"$PS1"'\[\e]133;B\a\]'
|
||||
if [[ $PS1 != *'\e]133;A'* ]]; then
|
||||
if builtin shopt -q promptvars; then
|
||||
# bash 3.2 traps no line that is only a subshell; \# counts it, so the prompt sends its D.
|
||||
PS1='\[${_ely_d[!_ely_sent && _ely_n && \# != _ely_n]-}${_ely_note[_ely_n = \#]-}\e]133;A\a\]'"$PS1"'\[\e]133;B\a\]'
|
||||
else
|
||||
PS1='\[\e]133;A\a\]'"$PS1"'\[\e]133;B\a\]'
|
||||
fi
|
||||
fi
|
||||
if [ -n "$_ely_ps0" ] && builtin shopt -q promptvars && [[ ${PS0-} != *"$_ely_ps0"* ]]; then
|
||||
PS0=$_ely_ps0${PS0-}
|
||||
fi
|
||||
|
||||
@@ -6,11 +6,12 @@ function global:prompt {
|
||||
$ok = $?
|
||||
$esc, $bel = [char]27, [char]7
|
||||
if ($global:ElyRan) {
|
||||
$code = 1
|
||||
if ($ok) { $code = 0 }
|
||||
elseif ($Error.Count -eq 0 -or [object]::ReferenceEquals($Error[0], $global:ElyError)) {
|
||||
# No new error: a native program failed. Strict mode refuses an unset variable.
|
||||
$code = Get-Variable LASTEXITCODE -Scope Global -ValueOnly -ErrorAction Ignore
|
||||
$code = 0
|
||||
if (-not $ok) {
|
||||
# Each native run sets a new $LASTEXITCODE, equal or not; strict mode refuses an unset one.
|
||||
$exit = Get-Variable LASTEXITCODE -Scope Global -ValueOnly -ErrorAction Ignore
|
||||
$ran = $null -ne $exit -and -not [object]::ReferenceEquals($exit, $global:ElyExit)
|
||||
$code = if ($ran -and $exit -ne 0) { $exit } else { 1 }
|
||||
}
|
||||
[Console]::Write("$esc]133;D;$code$bel")
|
||||
$global:ElyRan = $false
|
||||
@@ -36,7 +37,7 @@ if (Test-Path Function:\PSConsoleHostReadLine) {
|
||||
$line = & $global:ElyReadLine
|
||||
if (-not [string]::IsNullOrWhiteSpace($line)) {
|
||||
$global:ElyRan = $true
|
||||
$global:ElyError = if ($Error.Count) { $Error[0] }
|
||||
$global:ElyExit = Get-Variable LASTEXITCODE -Scope Global -ValueOnly -ErrorAction Ignore
|
||||
[Console]::Write("$([char]27)]133;C$([char]7)")
|
||||
}
|
||||
$line
|
||||
|
||||
@@ -8,6 +8,7 @@ fi
|
||||
[[ -r "${ZDOTDIR:-$HOME}/.zshenv" ]] && builtin source "${ZDOTDIR:-$HOME}/.zshenv"
|
||||
if [[ -o interactive ]]; then
|
||||
_ely_ran=
|
||||
_ely_first=1
|
||||
_ely_precmd() {
|
||||
builtin local ret=$? LC_ALL=C char url=
|
||||
if [[ -n $_ely_ran ]]; then
|
||||
@@ -21,14 +22,20 @@ if [[ -o interactive ]]; then
|
||||
url+=$char
|
||||
done
|
||||
builtin printf '\e]7;file://%s\a\e]2;%s\a' "$url" "${${${PWD:t}:-/}//[[:cntrl:]]/}"
|
||||
# Themes set PS1 in later hooks; from the next prompt the marks go on after them.
|
||||
# Themes set PS1 in later hooks: the marks go on after them, at the first prompt through sched.
|
||||
precmd_functions=(${precmd_functions:#_ely_mark} _ely_mark)
|
||||
if (( _ely_first )); then
|
||||
_ely_first=0
|
||||
builtin zmodload zsh/sched && builtin sched +0 _ely_mark $ret
|
||||
fi
|
||||
builtin return ret
|
||||
}
|
||||
_ely_mark() {
|
||||
if [[ -o prompt_percent && $PS1 != *$'\e]133;A'* ]]; then
|
||||
PS1=$'%{\e]133;A\a%}'$PS1$'%{\e]133;B\a%}'
|
||||
fi
|
||||
# sched's command leaves its status for the prompt.
|
||||
builtin return ${1:-0}
|
||||
}
|
||||
_ely_preexec() {
|
||||
_ely_ran=1
|
||||
|
||||
Reference in new issue
Block a user