Open alanbork opened 2 years ago
On Sun, Mar 13, 2022 at 06:58:14PM -0700, alanbork wrote:
I like to use the -q argument as an optional argument to scripts like this:
function killpick { ps ax | pick -q $1 | awk '{print $1}' | xargs kill -9; }
this way I can either pass the name of what I want to kill (and confirm it matched a running program before killing) or run it with no arguments and type in the name interactively. But -q causes pick to error out if there's no actual argument passed, making this kind of thing unnecessarily hard.
Options accepting an argument that's silently ignored if absent is a construct I have never encountered before. I think you approaching this from the wrong angle, this is what you want?
function killpick { ps ax | pick ${1:+-q $1} | awk '{print $1}' | xargs kill -9; }
Yes, that solves it at the "cost" of a significantly more complicated usage pattern for the end user.
perhaps a solution that would appease both of us: pick takes no arguments other than options. Perhaps the un-named optional argument could be the query.
eg
... | pick -q hello ... | pick hello
would produce the same effect.
On Mon, Mar 14, 2022, 12:06 AM Anton Lindqvist @.***> wrote:
On Sun, Mar 13, 2022 at 06:58:14PM -0700, alanbork wrote:
I like to use the -q argument as an optional argument to scripts like this:
function killpick { ps ax | pick -q $1 | awk '{print $1}' | xargs kill -9; }
this way I can either pass the name of what I want to kill (and confirm it matched a running program before killing) or run it with no arguments and type in the name interactively. But -q causes pick to error out if there's no actual argument passed, making this kind of thing unnecessarily hard.
Options accepting an argument that's silently ignored if absent is a construct I have never encountered before. I think you approaching this from the wrong angle, this is what you want?
function killpick { ps ax | pick ${1:+-q $1} | awk '{print $1}' | xargs kill -9; }
— Reply to this email directly, view it on GitHub https://github.com/mptre/pick/issues/315#issuecomment-1066445509, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANPGZ5KLWXPN5DJ55DA5F73U73QNXANCNFSM5QUFY23Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
On Mon, Mar 14, 2022 at 09:07:39AM -0700, alanbork wrote:
Yes, that solves it at the "cost" of a significantly more complicated usage pattern for the end user.
perhaps a solution that would appease both of us: pick takes no arguments other than options. Perhaps the un-named optional argument could be the query.
eg
... | pick -q hello ... | pick hello
would produce the same effect.
Sorry, no interest in such behavior.
I like to use the -q argument as an optional argument to scripts like this:
function killpick { ps ax | pick -q $1 | awk '{print $1}' | xargs kill -9; }
this way I can either pass the name of what I want to kill (and confirm it matched a running program before killing) or run it with no arguments and type in the name interactively. But -q causes pick to error out if there's no actual argument passed, making this kind of thing unnecessarily hard.