Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Adding bash completion and helper scripts #1993

Merged
merged 1 commit into from
Oct 22, 2015

Conversation

leedm777
Copy link
Contributor

This patch adds some bash helper scripts.

  • docker-machine.bash - command completion for docker-machine
  • docker-machine-prompt.bash - function for putting the active machine
    name in PS1
  • docker-machine-wrapper.bash - function wrapper adding an eval
    command that runs eval $(docker-machine env whatever) in the
    current shell.

@thaJeztah
Copy link
Member

Thank you!

/cc @albers

@chadxz
Copy link

chadxz commented Oct 20, 2015

+1 for docker-machine eval <env>!

@sruffell
Copy link

I'll add my +1 as well....

@thaJeztah
Copy link
Member

I wonder if the helper scripts (prompt, eval) should be in the "completions" directory or moved somewhere else inside "contrib"; I can imagine some people wanting the completions installed, but not those helpers

@leedm777
Copy link
Contributor Author

@thaJeztah I debated that. The prompt function is harmless if you don't put it in your PS1. The eval wrapper can be disabled by setting DOCKER_MACHINE_WRAPPED to false prior to sourcing the script. That feels "good enough" to me, but I would not object strongly to reorganizing.

The advantage of keeping them together is that if someone wants completion, they probably want the other shell stuff as well. Similarly, if they disable completion then the probably don't want the other shell bloat.

FWIW, Git put its prompt script in its completion directory, which made me feel better about doing it this way.

@dmp42
Copy link
Contributor

dmp42 commented Oct 21, 2015

@nathanleclaire wdyt?

@dmp42
Copy link
Contributor

dmp42 commented Oct 21, 2015

Also, #1309 was attempted before. Anything to merge from there?

@thaJeztah
Copy link
Member

@leedm777 thanks, I'm not a maintainer in this repository, and no strong opinion, apart from trying to keep consistency between the various docker repositories. Just thought I'd mention it.

Thanks so much though, for creating this!

@nathanleclaire
Copy link
Contributor

I'm interested (and thanks for putting this together @leedm777 !), need a chance to review a bit more thoroughly, but two things stand out as needing improvement:

  1. I'd prefer docker-machine use to docker-machine eval
  2. It needs documentation, however, I'm not sure the right place (Installation?) so I'm open to suggestions there.

@leedm777
Copy link
Contributor Author

@nathanleclaire I've added docs, and changed eval to use. Any further thoughts?

@@ -57,6 +57,21 @@ to your PATH.
$ docker-machine -v
machine version 0.5.0 (3e06852)

## Installing bash completion scripts

There are a [number of scripts](../contrib/completion/bash) which add command
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this link is correct - @moxiegirl can you comment? It's meant to link to source code in the docker machine repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, would be good to get your input on this doc in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nathanleclaire The link work when viewed on my fork. I'll gladly take recommendations if there's a better way to link to the scripts.

Choose a reason for hiding this comment

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

@leedm777 When you run make docs to validate your changes --- you are doing this right? :-D --- it reports an error on your link.

...
ERROR: 2015/10/22 LinkResolver: No page found for "../contrib/completion/bash" on page "machine/install-machine.md".
...

Soon our own @SvenDowideit will add this to the CI and such things will be caught when you submit your PR. For now, you have to run make docs. In this case, you wanted to link to the contrib directory in the repository. So you would need to actually put this link in https://github.com/docker/machine/tree/master/contrib/completion/bash as a direct link.

@nathanleclaire I'm checking the added content. Thanks for the ping.

@nathanleclaire
Copy link
Contributor

Putting docker-machine status in PS1 is going to make the terminal pretty slow (talking 100ms-1s extra per command invocation), so I'm hesitant to recommend it directly.

@albers
Copy link
Contributor

albers commented Oct 22, 2015

@thaJeztah Thanks for pointing me to this, and sorry for the delay.
I'm not familiar with docker-machine because I could not get it working in several previous attempts. I'll go for it next weekend.
@leedm777 Thanks for your work. On first sight it looks very impressive!

@thaJeztah
Copy link
Member

@albers thanks for looking; I am happy already with you just giving it a quick look to see if there are possible issues or inconsistencies with the other projects 👍

@@ -57,6 +57,21 @@ to your PATH.
$ docker-machine -v
machine version 0.5.0 (3e06852)

## Installing bash completion scripts

Choose a reason for hiding this comment

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

@leedm777 Nicely done. I would do a few things to sort this. Put your link OUT last --- no sense inducing them to switch channels before you've explained yourself. Break out the functionality into a scannable list.

---> https://gist.github.com/moxiegirl/9b2dba37dc8e75f5654e

Installing bash completion scripts

The Machine repository supplies several bash scripts] that add features such as:

  • command completion
  • a function that displays the active machine in your shell prompt
  • a function wrapper that adds a docker-machine use subcommand

The docker-machine function executes eval "$(docker-machine env X)" in the current shell.

To install the scripts, copy or link them into your /etc/bash_completion.d or
/usr/local/etc/bash_completion.d file. To enable the docker-machine shell prompt, add $(__docker-machine-ps1) to your PS1 setting in ~/.bashrc.

PS1='[\u@\h \W$(__docker-machine-ps1)]\$ '

You can find additional documentation in the comments at the top of each script.

@leedm777
Copy link
Contributor Author

@moxiegirl Is that better :-)

@moxiegirl
Copy link

@leedm777 thank you. Very glad to help your really helpful contribution! LGTM

@@ -57,6 +57,27 @@ to your PATH.
$ docker-machine -v
machine version 0.5.0 (3e06852)

## Installing bash completion scripts

The Machine repository supplies several `bash` scripts that add features such
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move the link to the contrib/completion/bash section of the repository to this line, i.e. "supplies several bash scripts" should be the link to there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see it's the opposite of what @moxiegirl recommended. No need to change it then.

@nathanleclaire
Copy link
Contributor

OK looks pretty good, I have a few docs nits, and just one more suggestion for the UX: If you type docker-machine use by itself, it should spit back the help text just like docker-machine use --help does.

This patch adds some bash helper scripts.

 * docker-machine.bash - command completion for docker-machine
 * docker-machine-prompt.bash - function for putting the active machine
   name in PS1
 * docker-machine-wrapper.bash - function wrapper adding an `use`
   command that runs `eval $(docker-machine env whatever)` in the
   current shell.

Signed-off-by: David M. Lee <dlee@respoke.io>
@leedm777
Copy link
Contributor Author

I think I've addressed all the feedback. This history was getting ugly, so I rebased on master and squashed to a single commit.

Thanks to everyone for all the feedback!

@thaJeztah
Copy link
Member

Great work @leedm777 !

@nathanleclaire nathanleclaire added this to the 0.5.0 milestone Oct 22, 2015
@nathanleclaire
Copy link
Contributor

LGTM

nathanleclaire added a commit that referenced this pull request Oct 22, 2015
Adding bash completion and helper scripts
@nathanleclaire nathanleclaire merged commit 9911019 into docker:master Oct 22, 2015
@leedm777 leedm777 deleted the completion branch October 23, 2015 01:46
@albers
Copy link
Contributor

albers commented Oct 23, 2015

OK, so there won' be any more need for my feedback.

@thaJeztah
Copy link
Member

Sorry for that @albers, I wasn't aware @nathanleclaire was gonna merge before you had the chance to give feedback 😊

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

Successfully merging this pull request may close these issues.

9 participants