make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / taslis
blobfbf02b3ad3334c61ef7040471be4fafa349132e4
1 #!/usr/bin/env perl
2 ###################
4 $me=$0;
5 $0="taslis";
6 sub heply { system "pod2text", $me; }
7 exit heply if $ARGV[0] eq '--help';
8 use Term::ReadKey;
9 ReadMode 4;
10 sub bye { exit ReadMode 0 }
11 sub getkey { while(not defined ($k = ReadKey(-1))){} return $k }
12 $SIG{INT}=$SIG{STOP}=$SIG{STOP}=$SIG{TSTP}=$SIG{QUIT}='bye';
14 # active window id
15 $awid = hex((`xprop -root -f _NET_ACTIVE_WINDOW 0x " \\\$0" _NET_ACTIVE_WINDOW` =~ /(\S+)$/)[0]);
17 while(1){
18 @tl=();
19 for(split/[\r\n]+/,`wmctrl -lp`){
20 ($wid, $wrksp, $pid, $host, $title)=split/\s+/;
21 if(open(P,"/proc/$pid/stat")) { ($state)=(<P>=~/\)\s+(\S+)/); close P }
22 push @tl,[$wid, $wrksp, $pid, $_, $state];
23 $L = 2+length$_ if length$_ > $L; # set longest line
26 bye unless @tl;
28 # sort order by workspace
29 @tl = sort { $$a[1] <=> $$b[1] } @tl;
30 # set selection if active window id match
31 if(tell STDERR == 0) {
32 for(0..$#tl) {
33 $in = $_ and last if hex $tl[$_][0] == $awid;
37 # clear screen region
38 print STDERR "\033[s\033[1;0H", ( ((" " x $L) . "\n") x ($#tl+2) ), "\033[u";
40 $in=$#tl if $in>$#tl;
41 $pos = tell STDERR;
43 print STDERR "\033[s\033[1;0H";
44 for(0..$#tl) {
45 printf STDERR "%s%s\033[m\n",($_==$in?"\033[44;1;36m":"\033[1;36m"),$tl[$_][3];
47 print STDERR "\033[u";
49 $k=getkey;
50 if($k =~ /q/i) { bye }
51 elsif($k eq chr(27)) {
52 $k=getkey;
53 if($k eq '[') {
54 $k=getkey;
55 if($k =~ /[DA]/) { # arrow left/up
56 $in-- if $in > 0
58 elsif($k =~ /[CB]/) { # arrow right/down
59 $in++ if $in < $#tl
61 elsif($k =~ /[H5]/) { # home/pg up
62 $in=0
64 elsif($k =~ /[F6]/) { # end/pg down
65 $in=$#tl
67 elsif($k eq chr(27)) { bye }
69 elsif($k eq chr(27)) { bye }
71 elsif($k =~ /c/i) {
72 system("wmctrl -ic ".$tl[$in][0]);
74 elsif($k =~ /[ts ]/i) {
75 kill ${$tl[$in]}[4] eq 'T' ? 18 : ${$tl[$in]}[4] eq 'S' ? 19 : 0, $$tl[$in][2] if $$tl[$in][2]; # CONT,TSTP
77 elsif($k =~ /k/i) {
78 kill 9, $$tl[$in][2] if $$tl[$in][2]; # KILL
80 elsif($k =~ /h/i) {
81 kill 1, $$tl[$in][2] if $$tl[$in][2]; # HUP
83 elsif($k =~ /i/i) {
84 kill 2, $$tl[$in][2] if $$tl[$in][2]; # INT
86 elsif($k =~ /d/i) {
87 $/=undef;
88 print STDERR "Commandline:\t";
89 open A,"/proc/".${$tl[$in]}[2]."/cmdline";
90 print STDERR join(" ",split/\x0/,<A>)."\n";
91 close A;
92 print STDERR "Directory:\t";
93 print STDERR readlink "/proc/".${$tl[$in]}[2]."/cwd","\n";
94 $/="\n";
95 open A,"/proc/".${$tl[$in]}[2]."/status";
96 /^(ppid|uid|gid):/i and print STDERR $_ while<A>;
97 close A;
99 elsif($k eq '?') {
100 heply
102 elsif($k =~ /[\r\n]/) {
103 ReadMode 0;
104 system("wmctrl -ia ".$tl[$in][0]);
105 exit 0;
109 __END__
111 =pod
113 =head1 NAME
115 taslis - WM's Window List
117 =head1 DESCRIPTION
119 B<Taslis> stands for I<tas>kI<lis>t. List X11 clients provided by wmctrl(1) in ANSI-compatible terminal.
121 =head1 KEYS
123 =over 8
125 =item Left,Right
127 Select item
129 =item Enter
131 Switch to workspace and raise window
133 =item C
135 Close window gracefully
137 =item H
139 Hangup selected process
141 =item I
143 Interrupt process
145 =item S,T,Space
147 Suspend, Resume process
149 =item K
151 Kill process
153 =item D
155 Process's details
157 =item Q
159 Dismiss
161 =item ?
163 Help
165 =back
167 =cut