Skip to content

Commit

Permalink
refactor & update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pombadev committed Feb 20, 2022
1 parent dbab3ce commit b7e75cc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ ikill [![Crates.io](https://img.shields.io/crates/v/ikill)](https://crates.io/cr
> Interactively kill running processes, inspired by [fkill-cli](https://github.com/sindresorhus/fkill-cli).
### Features

- List and fuzzy find running processes.
- Multi select processes (by pressing <kbd>⭾</kbd>)
- Multi select processes by pressing <kbd>⭾</kbd>.
- Clear all queries by pressing <kbd>Ctrl</kbd>+<kbd>l</kbd>.

### Usage

Run `ikill` on terminal, search and press <kbd>↵</kbd>.

### Screenshot

[![A screenshot](./screencast.gif)](./screencast.gif)

### Installation

If you have rust toolchain installed, you can just do:
```
cargo install ikill
Expand All @@ -23,6 +27,7 @@ cargo install ikill
Alternatively, you can download pre-build binaries from the [release page](https://github.com/pjmp/ikill/releases).

### Usage

```
ikill - Interactively kill processes
Expand All @@ -35,6 +40,7 @@ FLAGS:
```

# Alternatives

```bash
# using `fzf`
pgrep . -l | fzf --reverse -m | awk '{ print $2 }' | xargs -I% -r kill -9 '%'
Expand All @@ -44,5 +50,6 @@ pgrep . -l | dmenu -l 20 | awk '{ print $2 }' | xargs -I% -r kill -9 '%'
```

### TODO
- [ ] Kill process by PID/name (without fuzzy finder).

- [ ] Preview pane with process id?
- [ ] allow users to customize `skim`?
Binary file modified screencast.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions src/ikill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub async fn run() -> Result<(), Box<dyn std::error::Error>> {
.multi(true)
.case(CaseMatching::Smart)
.header(Some("PID NAME COMMAND"))
.bind(vec!["ctrl-l:unix-line-discard"])
.build()?;

let all_processes = processes()
Expand All @@ -53,23 +54,22 @@ pub async fn run() -> Result<(), Box<dyn std::error::Error>> {

drop(tx);

let selected_items = Skim::run_with(&skim_options, Some(rx))
// skip items where `esc` key were pressed
.filter(|out| !out.is_abort)
.map(|out| out.selected_items)
.unwrap_or_else(Vec::new);
if let Some(out) = Skim::run_with(&skim_options, Some(rx)) {
// exit when `esc` key were pressed
if out.is_abort {
return Ok(());
}

#[allow(clippy::needless_collect)]
let selected_items = selected_items
.iter()
.map(|item| item.output().to_string())
.collect::<Vec<_>>();
for item in out.selected_items {
let pid = item.output();

for process in all_processes {
let selected_process = selected_items.contains(&process.pid().to_string());
let selected = all_processes.iter().find(|ps|
// unwraping this because this was converted from i32
ps.pid() == pid.parse::<i32>().unwrap());

if selected_process {
process.kill().await?;
if let Some(selected) = selected {
selected.kill().await?;
}
}
}

Expand Down

0 comments on commit b7e75cc

Please sign in to comment.