-
Notifications
You must be signed in to change notification settings - Fork 36
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 option to select default choices #42
Conversation
src/index.js
Outdated
|
||
if (promptType.type === 'checkbox') { | ||
return options.default | ||
.split(' ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- .split(' ')
+ .split(options['default-separator'] || options.separator)
I'd much rather have a default-separator
option for people to be able to customize and default to separator
it would also remove the need for the extra | xargs
from your example 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: it would also mean we would need to enforce a default value for options.separator
in src/cli.js
right now it can be undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I'll make some changes and add this extra option :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make more sense if the default value of the separator is similar to this line using os.EOL
(e.g. \n
in Unix).
This way you can easily pass file contents, separated by new lines and won't require you to always specify default-separator
in such occasions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do you think it is necessary with an alias? There's no letters that matches with the naming default-separator
. I tried using P
, but it seemed too unclear.
hi @fnky many thanks for taking the time! Really impressive contribution! I didn't knew how much I want to have a default option until I saw this 😂 One consideration, I actually checked out the code to try it out locally and for me the first example wasn't working at first since -$ git branch -a | ipt -D "$(git rev-parse --abbrev-ref HEAD)"
+$ git branch -a | ipt -D "* $(git rev-parse --abbrev-ref HEAD)" |
I couldn't get the multiple options example to work though 😞 I wonder if we have mismatching git versions 🤔 I have:
here, what about you? |
Ah, I thought it was something to do with my git config. But you can use This is what I tested with originally: Select a single choice: git branch -a --format "%(refname:short)" | ipt -m -D "master" Select multiple choices: git branch -a --format "%(refname:short)" | ipt -m -D "$(git branch -a --merged ${1-master} --format "%(refname:short)" | xargs)" I am also using git
|
I have added the $ echo "foo\nbar\nbaz" | ipt -m -D "$(echo "foo\nbaz")" Note that if you pass newlines directly, it won't work: $ echo "foo\nbar\nbaz" | ipt -m -D "foo\nbaz" To use newline separator directly, use $ echo "foo\nbar\nbaz" | ipt -m --default-separator="\n" -D "foo\nbaz" |
@@ -31,6 +31,13 @@ const { argv } = yargs | |||
.describe("c", "Copy selected item(s) to clipboard") | |||
.alias("d", "debug") | |||
.describe("d", "Prints to stderr any internal error") | |||
.alias("D", "default") | |||
.describe("D", "Select a default choices by their name") | |||
.alias("P", "default-separator") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know whether it makes sense to have an alias for default-separator
.
|
||
if (promptType.type === "checkbox") { | ||
return options.default.split( | ||
options["default-separator"] || options.separator || os.EOL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This falls back to separator
, otherwise os.EOL
, similar to this line.
oh yeah!!! works like a charm now 😍 MANY MANY THANKS! this is the best contribution I ever received in an OSS project 😊 |
@fnky I would also suggest you to share reusable workflows as npm packages for easy-sharing across the community 😊 Here are some simple examples I put together, feel free to use them as templates: |
My pleasure, love to help out! Thanks for the workflow suggestions, I’ll take a look when I have the time! Cheers 🍺 |
This PR adds a
default
option to allow certain items in a list to be selected by default.For a single-choice list, it will select the given item defined in
) within quotations.
default
. For a multi-choice list, it will select the given choices separated by space (This is especially helpful in for example selecting the current branch in a list of branches:
or for example auto-selecting already merged branches: