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

Add verbose option to search arguments as well as command names #14

Merged
merged 12 commits into from Mar 11, 2017
Merged

Conversation

dnbkr
Copy link
Contributor

@dnbkr dnbkr commented Mar 2, 2017

This feature allows you to run fkill -v and then when searching for processes to kill, it will include the full proc command (including arguments)

This is useful when I have a daemonic process, like a dev web server, that I want to kill, but was launched with python start_web_server.py for example.


Fixes #13
Fixes #18

@dnbkr dnbkr mentioned this pull request Mar 2, 2017
@knownasilya
Copy link

Excellent!

@dnbkr
Copy link
Contributor Author

dnbkr commented Mar 6, 2017

Hi,

Just wondering if you've had a chance to look at this yet?

Daniel

@sindresorhus sindresorhus changed the title Added verbose option to search arguments as well as command names Add verbose option to search arguments as well as command names Mar 7, 2017
cli.js Outdated
@@ -14,6 +14,7 @@ const cli = meow(`

Options
-f, --force Force kill
-v, --verbose Include arguments in process search
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be two spaces between the flag and description, and you need to align the above flag.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better description:

Show process arguments

cli.js Outdated
inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
const verbose = flags.verbose || false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set default values with minimist instead.

cli.js Outdated

return inquirer.prompt([{
name: 'processes',
message: 'Running processes:',
type: 'autocomplete',
source: (answers, input) => Promise.resolve().then(() => filterProcesses(input, processes))
source: (answers, input) => Promise.resolve().then(() => filterProcesses(input, processes, verbose))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would continue passing the flags object down here to make it easier to add more options in the future.

@sindresorhus
Copy link
Owner

Generally looks good :)

You should limit the length though. Chrome has some crazy long process arguments:

/Applications/Google Chrome.app/Contents/Versions/56.0.2924.87/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper --type=renderer --enable-feature
s=AutofillProfileCleanup<AutofillProfileCleanup,BlockSmallPluginContent<PluginPowerSaverTiny,EnableSyncClientToServerCompression<EnableSyncClientToServerCompr
ession,*ExpectCTReporting<ExpectCTReporting,*NegotiateTLS13<TLS13Negotiation,ParseHTMLOnMainThread<ParseHTMLOnMainThread,PersistentHistograms<PersistentHistog
rams,*PointerEvent<PointerEvent,PreferHtmlOverPlugins<Html5ByDefault,SecurityChip<SecurityChip,SecurityWarningIconUpdate<SecurityWarningIconUpdate,Subresource
Filter<SubresourceFilter,*TranslateRankerLogging<TranslateRankerLogging,ViewsSimplifiedFullscreenUI<ViewsSimplifiedFullscreenUI --disable-features=DocumentWri
teEvaluator<DisallowFetchForDocWrittenScriptsInMainFrame,SSLPostQuantumExperiment<SSLPostQuantum --force-fieldtrials=*AppBannerTriggering/LanguageAdd/*Autofil
lProfileCleanup/Enabled/CaptivePortalInterstitial/Enabled/*ChromeChannelStable/Enabled/*ChromeSuggestionsTuning/Default/*ClientSideDetectionModel/Model0/*Data
ReductionProxyUseQuic/Enabled10_NoControl/*DisallowFetchForDocWrittenScriptsInMainFrame/DocumentWriteScriptBlockGroup_20161208_Launch/*EnableSyncClientToServe
rCompression/Enabled/ExpectCTReporting/ExpectCTReportingDisabled/*ExtensionDeveloperModeWarning/Enabled/*ExtensionInstallVerification/Enforce/*Html5ByDefault/
Enabled/*InstanceID/Enabled/*MarkNonSecureAs/show-non-secure-passwords-cc-ui/*OmniboxBundledExperimentV1/StandardR7/*ParseHTMLOnMainThread/Default/PasswordBra
nding/SmartLockBrandingSavePromptOnly/*PasswordGeneration/Disabled/*PasswordManagerSettingsMigration/Enable/*PersistentHistograms/EnabledInMemory/*PluginPower
SaverTiny/Enabled2/*QUIC/EnabledNoId/ReportCertificateErrors/ShowAndPossiblySend/SHA1IdentityUIWarning/Enabled/SHA1ToolbarUIJanuary2016/Warning/SHA1ToolbarUIJ
anuary2017/Error/SSLCommonNameMismatchHandling/Enabled/*SSLPostQuantum/disabled/*SafeBrowsingIncidentReportingService/Default/SafeBrowsingUnverifiedDownloads/
DisableByParameterMostSbTypes2/SafeBrowsingV4LocalDatabaseManagerEnabled/Default/*SecurityChip/Enabled/SecurityWarningIconUpdate/Enabled/SignInPasswordPromo/E
nable3/*SiteIsolationExtensions/Enabled_100/*StrictSecureCookies/Enabled/*SubresourceFilter/EnabledForPhishingSites/*TLS13Negotiation/Default/*TranslateRanker
Logging/TranslateRankerLoggingDefault/*TranslateServerStudy/Default/*UMA-Dynamic-Uniformity-Trial/Group3/*UMA-Population-Restrict/normal/*UMA-Uniformity-Trial
-1-Percent/group_13/*UMA-Uniformity-Trial-10-Percent/group_04/*UMA-Uniformity-Trial-100-Percent/group_01/*UMA-Uniformity-Trial-20-Percent/group_03/*UMA-Unifor
mity-Trial-5-Percent/group_13/*UMA-Uniformity-Trial-50-Percent/group_01/*WebFontsInterventionV2/Default/ --primordial-pipe-token=93C0072AEDA354DB6C67392A6B27A
92F --lang=en-US --metrics-client-id=9f725972-7a9e-4133-b210-03300eef79c1 --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --blink-setti
ngs=disallowFetchForDocWrittenScriptsInMainFrame=false,disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections=true --enable-pinch --num-raster-threads=
4 --enable-gpu-rasterization --enable-zero-copy --enable-gpu-memory-buffer-compositor-resources --enable-main-frame-before-activation --content-image-texture-
target=0,0,3553;0,1,3553;0,2,3553;0,3,3553;0,4,3553;0,5,3553;0,6,3553;0,7,3553;0,8,3553;0,9,3553;0,10,34037;0,11,34037;0,12,34037;0,13,3553;0,14,3553;0,15,355
3;1,0,3553;1,1,3553;1,2,3553;1,3,3553;1,4,3553;1,5,3553;1,6,3553;1,7,3553;1,8,3553;1,9,3553;1,10,34037;1,11,34037;1,12,34037;1,13,3553;1,14,3553;1,15,3553;2,0
,3553;2,1,3553;2,2,3553;2,3,3553;2,4,3553;2,5,34037;2,6,3553;2,7,3553;2,8,3553;2,9,3553;2,10,3553;2,11,3553;2,12,34037;2,13,3553;2,14,34037;2,15,34037;3,0,355
3;3,1,3553;3,2,3553;3,3,3553;3,4,3553;3,5,34037;3,6,3553;3,7,3553;3,8,3553;3,9,3553;3,10,3553;3,11,3553;3,12,34037;3,13,3553;3,14,34037;3,15,34037 --service-r
equest-channel-token=93C0072AEDA354DB6C67392A6B27A92F --renderer-client-id=75

@sindresorhus
Copy link
Owner

I know it's verbose mode, but I think we should simplify the apps in this mode:

/Applications/iTerm.app/Contents/MacOS/iTerm2 => /Applications/iTerm.app

@knownasilya
Copy link

@sindresorhus this comment #13 (comment) regarding the chrome processes might be helpful.

@dnbkr
Copy link
Contributor Author

dnbkr commented Mar 8, 2017

Have updated based on feedback; yet to sort out extracting the process name from the args and truncating the macOS .app insides. Will take a look at that later today hopefully.

Updates address help output, truncating overly verbose procs to one line, passing flags throughout the app

cli.js Outdated
const textLength = lineLength - 3;
const front = Math.ceil(textLength / 2);
const back = Math.floor(textLength / 2);
return `${text.substr(0, front)}...${text.substr(text.length - back)}`;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to use a module for this, like: https://github.com/sindresorhus/cli-truncate

@@ -13,7 +13,8 @@ const cli = meow(`
$ fkill [<pid|name> ...]

Options
-f, --force Force kill
-f, --force Force kill
-v, --verbose Show process arguments
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to update the readme output.

@dnbkr
Copy link
Contributor Author

dnbkr commented Mar 9, 2017

Changes to ps-list to extract args from command will solve issues such as:

/Applications/iTerm.app/Contents/MacOS/iTerm2 => /Applications/iTerm.app

(I was thinking of removing all text after /Contents/MacOS until we hit a space, but this would fail for applications with a space in their name, so waiting for the changes to ps-list would be better overall, i think)

Excluding the integration with future ps-list changes, have I missed anything?

cli.js Outdated
}));
.map(proc => {
const lineLength = process.stdout.columns || 80;
const margins = 4 + proc.pid.toString().length;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is 4? Can you make it a constant with a descriptive name? It seem arbitrary without more context. Also note that cliTruncate accounts for the dots, so you don't have to do that.

cli.js Outdated
const margins = 4 + proc.pid.toString().length;
const length = lineLength - margins;
const name = cliTruncate(flags.verbose ? proc.cmd : proc.name, length, { position: 'middle' });
return { name: `${name} ${chalk.dim(proc.pid)}`, pid: proc.pid };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the properties on separate lines for this, for readability reasons

@sindresorhus
Copy link
Owner

You need to resolve the merge conflict.

@sindresorhus sindresorhus merged commit 117edc7 into sindresorhus:master Mar 11, 2017
@sindresorhus
Copy link
Owner

Yay! Thanks for working on this @coffeedoughnuts. Good stuff.

happy

@sindresorhus
Copy link
Owner

@coffeedoughnuts Would you be interested in being a maintainer on this project? You did such a great job with this PR. No worries if not though :)

@dnbkr
Copy link
Contributor Author

dnbkr commented Mar 12, 2017

@sindresorhus hey - i've not maintained an open source project before; what exactly would it involve? (Just responding to issues and approving PRs?)

Would be interested though; mainly contributed to this one because i'm so sick of ps aux | grep <something> and then copy-pasting the proc id to kill - saw your tool and thought it's exactly what i needed for work!

@SamVerschueren
Copy link
Contributor

Being kind to people is always the first thing to do :). And then yes, helping to triage issues and review PRs. I always let @sindresorhus make the final decision though as it's his project so he's the one to decide on new features etc. Something I forgot to mention?

@dnbkr
Copy link
Contributor Author

dnbkr commented Mar 12, 2017

well - happy to help in any way i can :)

@sindresorhus
Copy link
Owner

@coffeedoughnuts Yes, what Sam said. Just helping out in any way you feel like :)

@pirate
Copy link

pirate commented Mar 13, 2017

Hey guys, just testing this on my local machine and ran into some problems. It seems fkill is having trouble killing some processes when I search for them by argument (the procs are owned by me, and are killable with kill):

➜  ps ax | grep -v grep | grep runserver
90766 s003  S+     0:01.05 python ./manage.py runserver
90769 s003  S+    11:45.73 /Users/squash/.virtualenvs/grater/bin/python ./manage.py runserver
➜  fkill -v
? Running processes: runserv
? Running processes: python ./manage.py runserver 90766

AggregateError:
    Error: Killing process python ./manage.py runserver 90766 failed: No matching processes belonging to you were found
        at Promise.all.then (/Users/squash/.config/yarn/global/node_modules/fkill/index.js:41:10)
    at Promise.all.then (/Users/squash/.config/yarn/global/node_modules/fkill/index.js:41:10)
[1]

@dnbkr
Copy link
Contributor Author

dnbkr commented Mar 14, 2017

@pirate thanks for pointing that out; not sure how i let that one slip through. I've made a bug fix PR to fix this issue ( #25 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants