I did some tweaking of this myself, and implemented command line wrapping, and cleaned it up a bit. Here's my version of the code.

Update:  Ok, I did some more tweaking, and now it actually works the way that I intended it to.  There are still some changes that I would like to make to it before too much longer.

#!/usr/bin/perl use Term::Size; $psl=`ps auxfw`; @psla=split("\n", $psl); chomp @psla; ($screen_width, undef) = Term::Size::chars; die "Screen to skinny, can't run, please make your screen at least 40 +columns wide\n" if ($screen_width<40); $Iam=getpwuid($<); foreach $l (@psla) { ( $user, $pid, $pcpu, $pmem, undef, undef, $tty, undef, undef, undef, @cmd ) = split / +/, $l; if ( $user =~ /root/ ) { $usercolor = "^[[0;31m"; } elsif ( $user =~ /$Iam/ ) { $usercolor = "^[[0;34m"; } else { $usercolor = "^[[0;36m"; } &printline( $user, $tty, $pid, $pcpu, $pmem, join( " ", @cmd ), $u +sercolor ); } sub printline { my ( $user, $tty, $pid, $pcpu, $pmem, $cmd, $usercolor ) = @_; my $ttycolor = "^[[0;33m"; my $pidcolor = "^[[1;30m"; my $pcpucolor = "^[[0;37m"; my $pmemcolor = "^[[1;37m"; my $cmdcolor = "^[[1m"; my $line_prestuff = 36; my $cmd_width = $screen_width-$line_prestuff-1; my $cont_start = $line_prestuff+2; my $cmd_cont = $cmd_width-2; $cmd =~ s/^\\/ \\/; $cmd =~ s/^\|/ |/; printf( "$usercolor%-8s $ttycolor%-5s $pidcolor%5s " . "$pcpucolor%4s $pmemcolor%4s $cmdcolor%-${cmd_width}s\n" +, $user, $tty, $pid, $pcpu, $pmem, substr($cmd, 0, $cmd_wid +th) ); $cmd = substr( $cmd, $cmd_width ); do { next unless length($cmd); printf( "%${cont_start}s$cmdcolor%-${cmd_cont}s\n", " ", subst +r($cmd, 0, $cmd_cont) ); } while ( $cmd = substr( $cmd, $cmd_const ) ); }

In reply to RE: psall (color ps) by qi3ber
in thread psall (color ps) by jettero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.