Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies to latest version #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 61 additions & 60 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,86 @@ const psList = require('ps-list');
const pidFromPort = require('pid-from-port');
const util = require('./lib/util');

const loadProcesses = () => {
const loadProcesses = async () => {
if (alfy.input.startsWith(':')) {
const search = alfy.input.slice(1);

return Promise.all([
const result = await Promise.all([
pidFromPort.list(),
psList({all: false})
]).then(result => {
const ports = result[0];
const processList = result[1];
]);

// Swap port and pid
const pidMap = new Map();
for (const entry of ports.entries()) {
const port = String(entry[0]);
const ports = result[0];
const processList = result[1];

if (!port.includes(search)) {
// Filter out results which don't match the search term
continue;
}
// Swap port and pid
const pidMap = new Map();
for (const entry of ports.entries()) {
const port = String(entry[0]);

pidMap.set(entry[1], String(entry[0]));
if (!port.includes(search)) {
// Filter out results which don't match the search term
continue;
}

return processList
.map(process => Object.assign({}, process, {port: pidMap.get(process.pid)}))
.filter(process => Boolean(process.port));
});
pidMap.set(entry[1], String(entry[0]));
}

return processList
.map(process => ({...process, ...{port: pidMap.get(process.pid)}}))
.filter(process => Boolean(process.port));
}

return psList().then(data => alfy.inputMatches(data, 'name'));
const processList = await psList();
return alfy.inputMatches(processList, 'name');
};

loadProcesses()
.then(processes => {
const items = processes
.filter(process => !process.name.endsWith(' Helper'))
.map(process => {
const cleanedPath = process.cmd.replace(/\.app\/Contents\/.*$/, '.app');
(async () => {
const processes = await loadProcesses();
const items = processes
.filter(process => !process.name.endsWith(' Helper'))
.map(process => {
const cleanedPath = process.cmd.replace(/\.app\/Contents\/.*$/, '.app');

// TODO: Use the `process.path` property in `ps-list` when implemented there
// The below can be removed then
const pathForIcon = cleanedPath.replace(/ -.*/, ''); // Removes arguments
// TODO: Use the `process.path` property in `ps-list` when implemented there
// The below can be removed then
const pathForIcon = cleanedPath.replace(/ -.*/, ''); // Removes arguments

let subtitle = cleanedPath;
let subtitle = cleanedPath;

if (process.port) {
// TODO; Use `process.path` property
subtitle = `${process.port} - ${subtitle}`;
}
if (process.port) {
// TODO; Use `process.path` property
subtitle = `${process.port} - ${subtitle}`;
}

return {
title: process.name,
autocomplete: process.name,
subtitle,
arg: process.pid,
icon: {
type: 'fileicon',
path: pathForIcon
return {
title: process.name,
autocomplete: process.name,
subtitle,
arg: process.pid,
icon: {
type: 'fileicon',
path: pathForIcon
},
mods: {
shift: {
subtitle: `CPU ${process.cpu}%`
},
mods: {
shift: {
subtitle: `CPU ${process.cpu}%`
},
alt: {
subtitle: 'Force kill',
arg: JSON.stringify({
alfredworkflow: {
arg: process.pid,
variables: {
force: true
}
alt: {
subtitle: 'Force kill',
arg: JSON.stringify({
alfredworkflow: {
arg: process.pid,
variables: {
force: true
}
})
}
}
})
}
};
})
.sort(util.sorter);
}
};
})
.sort(util.sorter);

alfy.output(items);
});
alfy.output(items);
})();
2 changes: 1 addition & 1 deletion kill.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const fkill = require('fkill');

fkill(parseInt(process.argv[2], 10), {
fkill(Number.parseInt(process.argv[2], 10), {
force: Boolean(process.env.force)
});
8 changes: 4 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';
const process = [
const process = new Set([
'node',
'python'
];
]);

const processCompare = (a, b) => {
const aTitle = a.title.toLowerCase();
const bTitle = b.title.toLowerCase();

if (process.indexOf(aTitle) !== -1) {
if (process.has(aTitle)) {
return -1;
}

if (process.indexOf(bTitle) !== -1) {
if (process.has(bTitle)) {
return 1;
}

Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "github.com/SamVerschueren"
},
"engines": {
"node": ">=6"
"node": ">=10"
},
"scripts": {
"test": "xo && ava",
Expand Down Expand Up @@ -38,15 +38,15 @@
"force"
],
"dependencies": {
"alfy": "^0.8.0",
"fkill": "^5.3.0",
"pid-from-port": "^1.1.2",
"ps-list": "^4.0.0"
"alfy": "^0.10.0",
"fkill": "^7.1.0",
"pid-from-port": "^1.1.3",
"ps-list": "^7.2.0"
},
"devDependencies": {
"alfy-test": "^0.3.0",
"alfy-test": "^0.4.0",
"ava": "*",
"get-port": "^3.2.0",
"get-port": "^5.1.1",
"xo": "*"
}
}
12 changes: 4 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# alfred-fkill [![Build Status](https://travis-ci.org/SamVerschueren/alfred-fkill.svg?branch=master)](https://travis-ci.org/SamVerschueren/alfred-fkill)

> [Alfred 3](https://www.alfredapp.com) workflow to fabulously search and kill processes
> [Alfred 3/4](https://www.alfredapp.com) workflow to fabulously search and kill processes

<img src="screenshot.png" width="694">


## Install

```bash
npm install --global alfred-fkill
```
$ npm install --global alfred-fkill
```

*Requires [Node.js](https://nodejs.org) 4+ and the Alfred [Powerpack](https://www.alfredapp.com/powerpack/).*

*Requires [Node.js](https://nodejs.org) 10+ and the [Alfred Powerpack](https://www.alfredapp.com/powerpack/).*

## Usage

Expand All @@ -24,13 +22,11 @@ Select an item and press <kbd>Enter</kbd> to kill the process.<br>
Hold <kbd>Shift</kbd> to show the used CPU percentage.<br>
Hold <kbd>Alt</kbd> and press <kbd>Enter</kbd> to force kill the process.


## Related

- [fkill](https://github.com/sindresorhus/fkill) - API for this workflow
- [fkill-cli](https://github.com/sindresorhus/fkill-cli) - CLI version of this workflow


## License

MIT © [Sam Verschueren](https://github.com/SamVerschueren)
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import childProcess from 'child_process';
import test from 'ava';
import alfyTest from 'alfy-test';
import getPort from 'get-port';
const test = require('ava');
const alfyTest = require('alfy-test');
const childProcess = require('child_process');
const getPort = require('get-port');

test('search by name', async t => {
const alfy = alfyTest();
Expand Down