-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify patch to omz_termsupport_preexec
- Loading branch information
Showing
1 changed file
with
2 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,2 @@ | ||
function omz_termsupport_preexec { | ||
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return | ||
|
||
emulate -L zsh | ||
setopt extended_glob | ||
|
||
# split command into array of arguments | ||
local -a cmdargs | ||
cmdargs=("${(z)2}") | ||
# if running fg, extract the command from the job description | ||
if [[ "${cmdargs[1]}" = fg ]]; then | ||
# get the job id from the first argument passed to the fg command | ||
local job_id jobspec="${cmdargs[2]#%}" | ||
# logic based on jobs arguments: | ||
# http://zsh.sourceforge.net/Doc/Release/Jobs-_0026-Signals.html#Jobs | ||
# https://www.zsh.org/mla/users/2007/msg00704.html | ||
case "$jobspec" in | ||
<->) # %number argument: | ||
# use the same <number> passed as an argument | ||
job_id=${jobspec} ;; | ||
""|%|+) # empty, %% or %+ argument: | ||
# use the current job, which appears with a + in $jobstates: | ||
# suspended:+:5071=suspended (tty output) | ||
job_id=${(k)jobstates[(r)*:+:*]} ;; | ||
-) # %- argument: | ||
# use the previous job, which appears with a - in $jobstates: | ||
# suspended:-:6493=suspended (signal) | ||
job_id=${(k)jobstates[(r)*:-:*]} ;; | ||
[?]*) # %?string argument: | ||
# use $jobtexts to match for a job whose command *contains* <string> | ||
job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;; | ||
*) # %string argument: | ||
# use $jobtexts to match for a job whose command *starts with* <string> | ||
job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;; | ||
esac | ||
|
||
# override preexec function arguments with job command | ||
if [[ -n "${jobtexts[$job_id]}" ]]; then | ||
1="${jobtexts[$job_id]}" | ||
2="${jobtexts[$job_id]}" | ||
fi | ||
fi | ||
|
||
# cmd name only, or if this is sudo or ssh, the next cmd | ||
local CMD="${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}" | ||
local LINE="${1:gs/%/%%}" | ||
|
||
title "$CMD" "%100>...>${LINE}%<<" | ||
} | ||
(( $+functions[omz_termsupport_preexec] )) || return | ||
functions[omz_termsupport_preexec]="${functions[omz_termsupport_preexec]//LINE=\"\${2/LINE=\"\${1}" |