#!/usr/bin/env perl use strict; use warnings; use File::HomeDir qw(home); use constant KILL_PATH => '/bin/kill'; use constant CONFIRM => [ "no", "yes" ]; sub confirm { my ($pid, $proc, $color) = @_; my $list; my $choice; for (@{+CONFIRM}) { $list .= $_ . "\n"; } $choice = `printf "%s" "$list" | dmenu -i -p "kill $proc ($pid)?" -sb '$color' -shb '$color'`; chomp $choice; if ($choice eq ${+CONFIRM}[1]) { return (1); } return (0); } sub action { my ($var, $user, $color) = @_; my $pid; my $proc; chomp $var; if (not $var) { return; } if ($var =~ /^\s*(\d+)\s/) { $pid = $1; } if ($var =~ /^\s*\S+\s+\S+\s+(\S+)/) { $proc = $1; } if (confirm($pid, $proc, $color) == 1) { exec(KILL_PATH, '-9', $pid); } return; } sub main { my $choice; my $ps; my $user; my $color; $color = '#cc241d'; if (@ARGV == 1) { $color = $ARGV[0]; } $user = getpwuid($<); $choice = `ps -U "$user" -o pid,user,comm,time,%cpu,%mem | dmenu -i -l 40 -sb '$color' -shb '$color'`; action($choice, $user, $color); return (0); } main(); __END__