mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-11 07:34:32 +00:00
Revamp the jobs builtin
darcs-hash:20051211233001-ac50b-24547ca41d4db05f87d59dd3e396c3190a66ef89.gz
This commit is contained in:
parent
28dd48a76a
commit
5262f3ce99
5 changed files with 180 additions and 87 deletions
244
builtin.c
244
builtin.c
|
@ -73,6 +73,18 @@
|
|||
/**
|
||||
Table of all builtins
|
||||
*/
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
JOBS_DEFAULT,
|
||||
JOBS_PRINT_PID,
|
||||
JOBS_PRINT_COMMAND,
|
||||
JOBS_PRINT_GROUP,
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
static hash_table_t builtin;
|
||||
|
||||
int builtin_out_redirect;
|
||||
|
@ -2400,25 +2412,103 @@ static int cpu_use( job_t *j )
|
|||
}
|
||||
#endif
|
||||
|
||||
static void builtin_jobs_print( job_t *j, int mode, int header )
|
||||
{
|
||||
process_t *p;
|
||||
switch( mode )
|
||||
{
|
||||
case JOBS_DEFAULT:
|
||||
{
|
||||
|
||||
if( header )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, L"Job\tGroup\t");
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
sb_append( sb_out, L"CPU\t" );
|
||||
#endif
|
||||
sb_append( sb_out, L"State\tCommand\n" );
|
||||
}
|
||||
|
||||
sb_printf( sb_out, L"%d\t%d\t", j->job_id, j->pgid );
|
||||
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
|
||||
#endif
|
||||
sb_append2( sb_out, job_is_stopped(j)?L"stopped\t":L"running\t",
|
||||
// job_is_completed(j)?L"completed\t":L"unfinished\t",
|
||||
j->command, L"\n", (void *)0 );
|
||||
}
|
||||
|
||||
case JOBS_PRINT_GROUP:
|
||||
{
|
||||
if( header )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, L"Group\n");
|
||||
}
|
||||
sb_printf( sb_out, L"%d\n", j->pgid );
|
||||
break;
|
||||
}
|
||||
|
||||
case JOBS_PRINT_PID:
|
||||
{
|
||||
if( header )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, L"Procces\n");
|
||||
}
|
||||
|
||||
for( p=j->first_process; p; p=p->next )
|
||||
{
|
||||
sb_printf( sb_out, L"%d\n", p->pid );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case JOBS_PRINT_COMMAND:
|
||||
{
|
||||
if( header )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, L"Command\n");
|
||||
}
|
||||
|
||||
for( p=j->first_process; p; p=p->next )
|
||||
{
|
||||
sb_printf( sb_out, L"%ls\n", p->argv[0] );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Builtin for printing running jobs
|
||||
*/
|
||||
static int builtin_jobs( wchar_t **argv )
|
||||
{
|
||||
|
||||
enum
|
||||
{
|
||||
DEFAULT,
|
||||
PRINT_PID,
|
||||
PRINT_COMMAND
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
int argc=0;
|
||||
job_t *j;
|
||||
int found=0;
|
||||
int mode=DEFAULT;
|
||||
int mode=JOBS_DEFAULT;
|
||||
|
||||
job_t *print_me=0;
|
||||
|
||||
|
||||
argc = builtin_count_args( argv );
|
||||
|
||||
woptind=0;
|
||||
|
@ -2436,6 +2526,14 @@ static int builtin_jobs( wchar_t **argv )
|
|||
L"command", no_argument, 0, 'c'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"group", no_argument, 0, 'g'
|
||||
}
|
||||
,
|
||||
{
|
||||
L"last", no_argument, 0, 'l'
|
||||
}
|
||||
,
|
||||
{
|
||||
0, 0, 0, 0
|
||||
}
|
||||
|
@ -2446,7 +2544,7 @@ static int builtin_jobs( wchar_t **argv )
|
|||
|
||||
int opt = wgetopt_long( argc,
|
||||
argv,
|
||||
L"pc",
|
||||
L"pclg",
|
||||
long_options,
|
||||
&opt_index );
|
||||
if( opt == -1 )
|
||||
|
@ -2472,13 +2570,33 @@ static int builtin_jobs( wchar_t **argv )
|
|||
|
||||
|
||||
case 'p':
|
||||
mode=PRINT_PID;
|
||||
mode=JOBS_PRINT_PID;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
mode=PRINT_COMMAND;
|
||||
mode=JOBS_PRINT_COMMAND;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
mode=JOBS_PRINT_GROUP;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
{
|
||||
job_t *j;
|
||||
for( j=first_job; j; j=j->next )
|
||||
{
|
||||
if( j->constructed )
|
||||
{
|
||||
print_me = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
case '?':
|
||||
// builtin_print_help( argv[0], sb_err );
|
||||
|
||||
|
@ -2487,58 +2605,16 @@ static int builtin_jobs( wchar_t **argv )
|
|||
}
|
||||
}
|
||||
|
||||
if( mode==DEFAULT )
|
||||
if( woptind < argc-1 )
|
||||
{
|
||||
|
||||
for( j= first_job; j; j=j->next )
|
||||
{
|
||||
/*
|
||||
Ignore unconstructed jobs, i.e. ourself.
|
||||
*/
|
||||
if( j->constructed /*&& j->skip_notification*/ )
|
||||
{
|
||||
if( !found )
|
||||
{
|
||||
/*
|
||||
Print table header before first job
|
||||
*/
|
||||
sb_append( sb_out, L"Job\tGroup\t");
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
sb_append( sb_out, L"CPU\t" );
|
||||
#endif
|
||||
sb_append( sb_out, L"State\tCommand\n" );
|
||||
}
|
||||
|
||||
found = 1;
|
||||
|
||||
sb_printf( sb_out, L"%d\t%d\t", j->job_id, j->pgid );
|
||||
|
||||
#ifdef HAVE__PROC_SELF_STAT
|
||||
sb_printf( sb_out, L"%d%%\t", cpu_use(j) );
|
||||
#endif
|
||||
sb_append2( sb_out, job_is_stopped(j)?L"stopped\t":L"running\t",
|
||||
// job_is_completed(j)?L"completed\t":L"unfinished\t",
|
||||
j->command, L"\n", (void *)0 );
|
||||
|
||||
}
|
||||
}
|
||||
if( !found )
|
||||
{
|
||||
sb_append2( sb_out, argv[0], L": There are no running jobs\n", (void *)0 );
|
||||
}
|
||||
sb_append2( sb_err, argv[0], L": zero or one arguments\n", (void *)0 );
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
||||
if( woptind == argc-1 )
|
||||
{
|
||||
long pid;
|
||||
wchar_t *end;
|
||||
job_t *j;
|
||||
|
||||
if( woptind != argc-1 )
|
||||
{
|
||||
sb_append2( sb_err, argv[0], L": Expected exactly one argument\n", (void *)0 );
|
||||
}
|
||||
|
||||
|
||||
errno=0;
|
||||
pid=wcstol( argv[woptind], &end, 10 );
|
||||
if( errno || *end )
|
||||
|
@ -2548,30 +2624,44 @@ static int builtin_jobs( wchar_t **argv )
|
|||
|
||||
}
|
||||
|
||||
j = job_get_from_pid( pid );
|
||||
if( !j )
|
||||
print_me = job_get_from_pid( pid );
|
||||
if( !print_me )
|
||||
{
|
||||
sb_printf( sb_err, L"%ls: No suitable job: %d\n", argv[0], pid );
|
||||
return 1;
|
||||
}
|
||||
process_t *p;
|
||||
for( p=j->first_process; p; p=p->next )
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Do not babble if not interactive
|
||||
*/
|
||||
if( builtin_out_redirect )
|
||||
found=1;
|
||||
|
||||
if( !print_me )
|
||||
{
|
||||
job_t *j;
|
||||
|
||||
for( j= first_job; j; j=j->next )
|
||||
{
|
||||
switch( mode )
|
||||
/*
|
||||
Ignore unconstructed jobs, i.e. ourself.
|
||||
*/
|
||||
if( j->constructed /*&& j->skip_notification*/ )
|
||||
{
|
||||
case PRINT_PID:
|
||||
{
|
||||
sb_printf( sb_out, L"%d\n", p->pid );
|
||||
break;
|
||||
}
|
||||
|
||||
case PRINT_COMMAND:
|
||||
{
|
||||
sb_printf( sb_out, L"%ls\n", p->argv[0] );
|
||||
break;
|
||||
}
|
||||
builtin_jobs_print( j, mode, !found );
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( !found )
|
||||
{
|
||||
sb_append2( sb_out, argv[0], L": There are no running jobs\n", (void *)0 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_jobs_print( print_me, mode, !found );
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -997,7 +997,6 @@ g++, javac, java, gcj, lpr, doxygen, whois, find)
|
|||
- The jobs builtin should be able to give information on a specific job, such as the pids of the processes in the job
|
||||
- Syntax highlighting should mark cd to non-existing directories as an error
|
||||
- the code for printing the prompt should know about the most common escape sequences
|
||||
- block builtin
|
||||
- redo the jobs command
|
||||
- wait shellscript
|
||||
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
\section jobs jobs - print currently running jobs
|
||||
|
||||
\subsection jobs-synopsis
|
||||
<tt>jobs</tt>
|
||||
<tt>jobs [OPTIONS] [PID]</tt>
|
||||
|
||||
\subsection jobs-description Description
|
||||
The <tt>jobs</tt> builtin causes fish to print a list of the currently
|
||||
running jobs and their status.
|
||||
|
||||
On systems that supports this feature, jobs will also print the CPU
|
||||
usage of each job since the last command was executed. The CPU usage
|
||||
is expressed as a percentage of full CPU activity. Note that on
|
||||
jobs accepts the following switches:
|
||||
|
||||
- <tt>-l</tt> or <tt>--last</tt> only the last job to be started is printed
|
||||
- <tt>-g</tt> or <tt>--group</tt> only print the group id of each job
|
||||
- <tt>-c</tt> or <tt>--command</tt> print the commandname for each process in all jobs
|
||||
- <tt>-p</tt> or <tt>--process</tt> print the procces id for each process in all jobs
|
||||
|
||||
On systems that supports this feature, jobs will print the CPU usage
|
||||
of each job since the last command was executed. The CPU usage is
|
||||
expressed as a percentage of full CPU activity. Note that on
|
||||
multiprocessor systems, the total activity may be more than 100\%.
|
||||
|
|
5
event.c
5
event.c
|
@ -462,8 +462,6 @@ static void event_fire_delayed()
|
|||
free( blocked );
|
||||
blocked = new_blocked;
|
||||
}
|
||||
|
||||
|
||||
|
||||
while( sig_list[active_list].count > 0 )
|
||||
{
|
||||
|
@ -518,7 +516,6 @@ static void event_fire_delayed()
|
|||
|
||||
void event_fire( event_t *event )
|
||||
{
|
||||
//int is_event_old = is_event;
|
||||
is_event++;
|
||||
|
||||
if( event && (event->type == EVENT_SIGNAL) )
|
||||
|
@ -556,7 +553,7 @@ void event_fire( event_t *event )
|
|||
}
|
||||
|
||||
}
|
||||
is_event--;// = is_event_old;
|
||||
is_event--;
|
||||
}
|
||||
|
||||
|
||||
|
|
2
input.c
2
input.c
|
@ -698,7 +698,7 @@ static wchar_t *input_expand_sequence( const wchar_t *in )
|
|||
}
|
||||
debug( 1, L"Invalid sequence - Control-nothing?\n" );
|
||||
error = 1;
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue