mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-13 01:31:18 +02:00
16198: add %j prompt expansion and j test character for no. of jobs in prompt
This commit is contained in:
parent
f3f81f0837
commit
19d2273cb7
4 changed files with 50 additions and 19 deletions
|
@ -1,5 +1,11 @@
|
||||||
2001-11-02 Oliver Kiddle <opk@zsh.org>
|
2001-11-02 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
|
* unposted: Functions/Prompts/prompt_oliver_setup,
|
||||||
|
Doc/Zsh/prompt.yo: documentation and example for 16198
|
||||||
|
|
||||||
|
* 16198: Src/prompt.c: add %j prompt expansion and j test
|
||||||
|
character for putting the number of jobs in the prompt
|
||||||
|
|
||||||
* 16177: Completion/Unix/Type/_time_zone: also look in
|
* 16177: Completion/Unix/Type/_time_zone: also look in
|
||||||
/usr/lib/locale/TZ for time zones
|
/usr/lib/locale/TZ for time zones
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,9 @@ The line number currently being executed in the script, sourced file, or
|
||||||
shell function given by tt(%N). This is most useful for debugging as part
|
shell function given by tt(%N). This is most useful for debugging as part
|
||||||
of tt($PS4).
|
of tt($PS4).
|
||||||
)
|
)
|
||||||
|
item(tt(%j))(
|
||||||
|
The number of jobs.
|
||||||
|
)
|
||||||
item(tt(%L))(
|
item(tt(%L))(
|
||||||
The current value of tt($SHLVL).
|
The current value of tt($SHLVL).
|
||||||
)
|
)
|
||||||
|
@ -222,6 +225,7 @@ least var(n) elements.)
|
||||||
sitem(tt(D))(True if the month is equal to var(n) (January = 0).)
|
sitem(tt(D))(True if the month is equal to var(n) (January = 0).)
|
||||||
sitem(tt(d))(True if the day of the month is equal to var(n).)
|
sitem(tt(d))(True if the day of the month is equal to var(n).)
|
||||||
sitem(tt(g))(True if the effective gid of the current process is var(n).)
|
sitem(tt(g))(True if the effective gid of the current process is var(n).)
|
||||||
|
sitem(tt(j))(True if the number of jobs is at least var(n).)
|
||||||
sitem(tt(L))(True if the tt(SHLVL) parameter is at least var(n).)
|
sitem(tt(L))(True if the tt(SHLVL) parameter is at least var(n).)
|
||||||
sitem(tt(l))(True if at least var(n) characters have already been
|
sitem(tt(l))(True if at least var(n) characters have already been
|
||||||
printed on the current line.)
|
printed on the current line.)
|
||||||
|
|
|
@ -1,35 +1,41 @@
|
||||||
# oliver prompt theme
|
# oliver prompt theme
|
||||||
|
|
||||||
prompt_oliver_help() {
|
prompt_oliver_help() {
|
||||||
cat - <<ENDHELP
|
cat <<'ENDHELP'
|
||||||
With this prompt theme, the prompt contains the current directory,
|
With this prompt theme, the prompt contains the current directory,
|
||||||
history number and the previous command\'s exit code (if non-zero)
|
history number, number of jobs (if non-zero) and the previous
|
||||||
and a final character which depends on priviledges.
|
command's exit code (if non-zero) and a final character which
|
||||||
|
depends on priviledges.
|
||||||
|
|
||||||
The colour of the prompt depends on two associative arrays -
|
The colour of the prompt depends on two associative arrays -
|
||||||
\$pcolour and $\tcolour. Each array is indexed by the name of the
|
$pcolour and $tcolour. Each array is indexed by the name of the
|
||||||
local host. Alternatively, the colour can be set with parameters
|
local host. Alternatively, the colour can be set with parameters
|
||||||
to prompt.
|
to prompt. To specify colours, use English words like 'yellow',
|
||||||
|
optionally preceded by 'bold'.
|
||||||
|
|
||||||
The hostname and username are also included unless they are in the
|
The hostname and username are also included unless they are in the
|
||||||
\$normal_hosts or \$normal_users array.
|
$normal_hosts or $normal_users array.
|
||||||
ENDHELP
|
ENDHELP
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_oliver_setup() {
|
prompt_oliver_setup() {
|
||||||
prompt_opts=( percent set )
|
prompt_opts=( cr subst percent )
|
||||||
|
|
||||||
local pcol=$'\e['${1:-${pcolour[${HOST:=`hostname`}]:-33}}m
|
[[ "${(t)pcolour}" != assoc* ]] && typeset -Ag pcolour
|
||||||
local tcol=$'\e['${2:-${tcolour[$HOST]:-37}}m
|
[[ "${(t)tcolour}" != assoc* ]] && typeset -Ag tcolour
|
||||||
local a host="%M:" user="%n "
|
local pcol=${1:-${pcolour[${HOST:=`hostname`}]:-yellow}}
|
||||||
for a in $normal_hosts; do
|
local pcolr=$fg[${pcol#bold}]
|
||||||
[[ $HOST == $a ]] && host=""
|
[[ $pcol = bold* ]] && pcolr=$bold_color$pcolr
|
||||||
done
|
|
||||||
for a in root $normal_users; do
|
|
||||||
[[ ${USER:-`whoami`} == $a ]] && user=""
|
|
||||||
done
|
|
||||||
|
|
||||||
PS1="%{$pcol%}$user$host%~ [%h%0(?..:%?)]%# %{$tcol%}"
|
local tcol=${2:-${tcolour[$HOST]:-white}}
|
||||||
|
local tcolr=$reset_color$fg[${tcol#bold}]
|
||||||
|
[[ $tcol = bold* ]] && tcolr=$tcolr$bold_color
|
||||||
|
|
||||||
|
local a host="%m:" user="%n "
|
||||||
|
[[ $HOST == (${(j(|))~normal_hosts}) ]] && host=""
|
||||||
|
[[ ${USER:-`whoami`} == (root|${(j(|))~normal_users}) ]] && user=""
|
||||||
|
|
||||||
|
PS1="%{$pcolr%}$user$host%~%"'$((COLUMNS-12))'"(l.$prompt_newline. )[%h%1(j.%%%j.)%0(?..:%?)]%# %{$tcolr%}"
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_oliver_setup "$@"
|
prompt_oliver_setup "$@"
|
||||||
|
|
17
Src/prompt.c
17
Src/prompt.c
|
@ -202,7 +202,7 @@ static int
|
||||||
putpromptchar(int doprint, int endchar)
|
putpromptchar(int doprint, int endchar)
|
||||||
{
|
{
|
||||||
char *ss, *tmbuf = NULL, *hostnam;
|
char *ss, *tmbuf = NULL, *hostnam;
|
||||||
int t0, arg, test, sep;
|
int t0, arg, test, sep, j, numjobs;
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
time_t timet;
|
time_t timet;
|
||||||
Nameddir nd;
|
Nameddir nd;
|
||||||
|
@ -286,6 +286,13 @@ putpromptchar(int doprint, int endchar)
|
||||||
if (getegid() == arg)
|
if (getegid() == arg)
|
||||||
test = 1;
|
test = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'j':
|
||||||
|
for (numjobs = 0, j = 1; j < MAXJOB; j++)
|
||||||
|
if (jobtab[j].stat && jobtab[j].procs &&
|
||||||
|
!(jobtab[j].stat & STAT_NOPRINT)) numjobs++;
|
||||||
|
if (numjobs >= arg)
|
||||||
|
test = 1;
|
||||||
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
*bp = '\0';
|
*bp = '\0';
|
||||||
countprompt(bufline, &t0, 0, 0);
|
countprompt(bufline, &t0, 0, 0);
|
||||||
|
@ -371,6 +378,14 @@ putpromptchar(int doprint, int endchar)
|
||||||
sprintf(bp, "%d", curhist);
|
sprintf(bp, "%d", curhist);
|
||||||
bp += strlen(bp);
|
bp += strlen(bp);
|
||||||
break;
|
break;
|
||||||
|
case 'j':
|
||||||
|
for (numjobs = 0, j = 1; j < MAXJOB; j++)
|
||||||
|
if (jobtab[j].stat && jobtab[j].procs &&
|
||||||
|
!(jobtab[j].stat & STAT_NOPRINT)) numjobs++;
|
||||||
|
addbufspc(DIGBUFSIZE);
|
||||||
|
sprintf(bp, "%d", numjobs);
|
||||||
|
bp += strlen(bp);
|
||||||
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
queue_signals();
|
queue_signals();
|
||||||
if ((hostnam = getsparam("HOST")))
|
if ((hostnam = getsparam("HOST")))
|
||||||
|
|
Loading…
Reference in a new issue