Skip to content

Zsh completion #59

Merged
merged 7 commits into from Dec 21, 2012

3 participants

@pengwynn

First stab at zsh completion.

@sferik
Owner
sferik commented Jul 14, 2012

This seems like a good first stab. A few questions/suggestions:

  1. Instead of duplicating the names and descriptions of each command, which will require manual updates to two files any time someone wants add or modify a command, what if you generated the zsh completion file with a rake or thor task instead? It seems like you could extract all the commands and descriptions by parsing the source files directly or via t help. I'm worried that if I merge this pull request the way it's written now, it will quickly fall out-of-date, as people add or modify functionality without realizing they also need to update the zsh completion file. If it was a rake task, I could make it a dependency of rake release, which would guarantee it would always be up-to-date.
  2. It looks like you added completion for all the top-level commands but none of the subcommands (delete, list, search, set, and stream). Was this an intentional omission? It seems like there should at least be completion for these keywords, even if all the subcommands aren't supported. If we're going to generate this file programmatically, I can't think of any reason not to include all the subcommands in addition to the top-level commands.
  3. I'm worried that many zsh users who might want to use this script won't discover it unless you add note to the README telling people it exists and explaining how to install it. Could you please make this part of the pull request? I'd also be open to a new t command that installs the script into the correct location. Perhaps the command could switch on ENV['SHELL'].split('/').last to determine which completion file to install and where to install it. For now, this is the only completion file, but I wouldn't be surprised if someone followed your lead and created one for bash and other shells, which leads me to…
  4. The file should have zsh somewhere in its path. If you don't want to change the name of the file (so it can be easily copied into place), I'd suggest putting it in an etc/zsh or completion/zsh directory. git puts its completion files in a completion directory (under contrib).
  5. I already merged 0ab754f in #58. I'm not sure exactly why it's showing up in this pull request as well, but I believe this can be fixed by:
    • pulling the upstream master down to your local master,
    • rebasing your zsh-completion branch from master, and then
    • force-pushing that branch back up to your fork.
@pengwynn

Thanks for the feedback, @sferik. Yeah, definitely a WIP. I ran out of time on the plane, hence the short PR description.

  1. I want to automate this with rake. I just wanted to get something useable before tapping into Thor's tasks.
  2. Subcommands are coming.
  3. README will follow. Honestly, I need to research some bulletproof install instructions. Everybody does zsh completion differently.
  4. Good idea on the name.
  5. My bad. I branched off of my own master that had that commit before starting this one. I'll remove.
@sferik
Owner
sferik commented Aug 14, 2012

Any plans to take another stab at this?

@pengwynn

Still on my list. Moving and travel has limited my output lately. Feel free to take a stab or close this and I can re-open it when I can circle back.

@sferik
Owner
sferik commented Aug 14, 2012

I have no problem with keeping it open. Just wanted to ping you to make sure you hadn't completely forgotten about it.

@danigiri
danigiri commented Sep 4, 2012

Looks great. Please note the popular oh-my-zsh, it could be added or referenced as a plugin as well.

@sferik
Owner
sferik commented Nov 11, 2012

@pengwynn It has been 3 months since I last pinged you about this so I'm pinging you again. It would be great to finish this up and merge it in.

@pengwynn

Sorry this took so long. Here's take 2:

  • Created a rake task to generate the completion function live from T::CLI and subcommand class tasks
  • Moved the output to etc/t-completion.zsh
  • Updated README
@sferik sferik commented on an outdated diff Dec 21, 2012
@@ -242,6 +242,13 @@ used by `t`:
![Timeline](https://github.com/sferik/t/raw/master/screenshots/timeline.png)
![List](https://github.com/sferik/t/raw/master/screenshots/list.png)
+## Shell completion
+If you're running [Zsh][zsh], you can source the [bundled completion file][completion]
+to get shell completion for `t` commands, subcommands, and flags.
+
+Don't run Zsh? Why not [contribute][contribute] completion support for your favorite
@sferik
Owner
sferik added a note Dec 21, 2012

A little Markdown protip: if the linked text is the same as the reference text, you can just say [contribute][].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sferik sferik and 1 other commented on an outdated diff Dec 21, 2012
tasks/zsh.rake
+
+#{subcommand_arguments_functions}
+
+#{subcommand_functions}
+)
+end
+
+def general_options_completions
+%Q(t_general_options=("(-H --host)"{-H,--host=HOST}"[Twitter API server]"
+ "(-N --no-color)"{-N,--no-color}"[Disable colorization in output]"
+ "(-U --no-ssl)"{-U,--no-ssl}"[Disable SSL]"
+ "(-P --profile)"{-P,--profile=FILE}"[Path to RC file]"
+ $nul_arg
+ )
+)
+end
@sferik
Owner
sferik added a note Dec 21, 2012

Is it possible to automatically generate the global options, as you do with the tasks? These don't change very often but I'd prefer if nothing was hardcoded.

@pengwynn
pengwynn added a note Dec 21, 2012

I had this as dynamic, but left it static because I'm tweaking the completion for the --profile and --host options to be of type file and url respectively. I'm almost there.

If they're dynamic, I have no hook to treat them differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sferik
Owner
sferik commented Dec 21, 2012

This is looking much better. I posted a couple comments/questions inline.

Another question: Could you chain the completion:zsh task to be a dependency of the release task? Perhaps it could even git add and git commit itself if there are any changes. This would ensure that the completion file is always up-to-date before pushing a release.

Also, what did you think of my suggestion to add a command to t that installs the completion script into place? I'm not a zsh user but I assume there's a conventional or environmental path into which completion scripts can be copied and automatically sourced? How do other programs handle installation?

@pengwynn

I'll play with the task dependency. I wasn't sure of your release process so I didn't want to get too cute.

I don't think we'll be able to automate the install since everyone's setup is different. I've included a note in the README and a comment at the top of the file on minimal setup. I think that should be fine.

Perhaps @danigiri or an oh-my-zsh user wants to include special setup instructions for that framework? It's changed since I used it.

@pengwynn

OK, this should be good to go.

@sferik sferik merged commit 38e1e3b into sferik:master Dec 21, 2012
@sferik sferik referenced this pull request Feb 8, 2013
Closed

Bash completion #89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.