-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 of apm completions #2390
Conversation
Have you tested with the power management thing? |
Fixed the switch/case usage. Hopefully it looks better!
Which part is this point referencing?
Similar to above, any options written before the first command (except for
I'm downloading a Debian image at the moment with which I'll check in a VM to see if it breaks it for that, although it's a daemon I've never encountered! |
Ah okay, I assumed "--help" was the same as "help". |
Whoops! |
Ah nice. I was afraid old-apm would print something to stdout or similar. I've just managed to install atom (after about an hour of downloading/building, which seems a bit excessive), and the You might want to use something like
|
complete -x -c apm -n '__fish_apm_config_args 2' -a delete -d 'Delete config item' | ||
complete -x -c apm -n '__fish_apm_config_args 2' -a list -d 'List config items' | ||
complete -x -c apm -n '__fish_apm_config_args 2' -a edit -d 'Edit config items' | ||
complete -x -c apm -n '__fish_apm_config_args 3; and test (commandline -opc)[3] != "edit"; and test (commandline -opc)[3] != "list"' -a '(__fish_apm_config_items)' |
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.
Is there a more efficient way of doing this?
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 would have probably split ...config_args into two functions - _fish_apm_config{needs_command,_using_command_from}.
What you could do is contains -- (commandline -opc)[3] edit list
instead of the tests. That'd be a tiny bit shorter and more easily extensible. (Of course this is all assuming that config has no options that can appear before the subcommand - if there are and you missed them or if it ever changes, this code will stop being correct)
Hold off on a merge, it's still missing the case |
Don't worry, I almost merged something broken a few days ago, so I'm still paying attention 😆.
Ah yes, that's the tough stuff. What I've recently done for git (not pushed yet as I want to test it thoroughly) is: function __fish_git_needs_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 ]
return 0
else
set -l skip_next 1
# Skip first word because it's "git" or a wrapper
for c in $cmd[2..-1]
test $skip_next -eq 0; and set skip_next 1; and continue
# git can only take a few options before a command, these are the ones mentioned in the "git" man page
# e.g. `git --follow log` is wrong, `git --help log` is okay (and `git --help log $branch` is superfluous but works)
# In case any other option is used before a command, we'll fail, but that's okay since it's invalid anyway
switch $c
# General options that can still take a command
case "--help" "-p" "--paginate" "--no-pager" "--bare" "--no-replace-objects" --{literal,glob,noglob,icase}-pathspecs --{exec-path,git-dir,work-tree,namespace}"=*"
continue
# General options with an argument we need to skip. The option=value versions have already been handled above
case --{exec-path,git-dir,work-tree,namespace}
set skip_next 0
continue
# General options that cause git to do something and exit - these behave like commands and everything after them is ignored
case "--version" --{html,man,info}-path
return 1
# We assume that any other token that's not an argument to a general option is a command
case "*"
return 1
end
end
return 0
end
return 1
end (Yes, it's a bit long, but I hope it actually catches all the edgecases - maybe this could be generalized) |
Thanks for that! I've been trying to figure out a way to filter out |
Quick update, I've managed to squish the ability to repeat subcommands (i.e. preventing However I'm currently struggling to prevent duplication of the initial command (i.e. typing $ apm config config
delete (Delete config item) get (Get config item) set (Set config item)
edit (Edit config items) list (List config items) As you can't get to this via following the completions, is this something that's essential to avoid? I've tried to filter it out by checking to see whether the command ( This is the function at the moment: function __fish_apm_using_command
set cmd (commandline -opc)
if test (count $cmd) -gt 1
set -l command_seen 0
for c in $cmd[2..-1]
switch $c
case '--color' '--no-color'
continue
case $argv
if test command_seen -eq 0
set command_seen 1
else
return 1
end
case '*'
return 1
end
end
if test command_seen -eq 1
return 0
end
end
return 1
end Can you see anything there that seems unreasonable or incorrect? |
That function seems okay. What you would probably need to do is only offer sub-subcommands to config if "__fish_apm_using_command config" is true (and no sub-subcommand is there yet) - in the double-config case that would be false. Or are you doing that already and the function doesn't work? I can't see anything on a cursory glance (you could skip a test or two if you inverted command_seen to be 0 when true and 1 when false - then you could return it directly - also "command_seen_once" would be clearer, but neither of those are important). Though...
I've just mentioned this an hour ago:
If you can easily fix it, do it. If not, it's not necessary. Is there something more pressing left to do here? |
It looks like it never enters the case $argv
if test command_seen_once -eq 1
breakpoint
set command_seen_once 0
else
return 1
end The The function is being called as:
|
Uhm.... there's a "$" missing. ( |
That would explain a lot! |
After that you're done if I see this correctly. Could you squash this (make a new branch and do (I'd also like to have a slightly more informative first line in the commit message: "Complete atom package manager or apmd" or so) |
Yep that's fine, I'll comment the functions up a bit more in case they're useful for other completions in the future and then get that done. |
Completions for `apm` now support both the Advanced Power Management client and the Atom text editor.
6a34c5c
to
18a1163
Compare
First time doing a |
Merged, thanks for the nice work and quick replies! |
Thanks for your help!
|
Completions for
apm
now support both the Advanced Power Management client and the Atom text editor package manager.This addresses #2354