Skip to content
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

Fix: Plugin knife: Add relative local path for commands which upload files #4240

Merged
merged 3 commits into from
Jun 8, 2016

Conversation

kierandoonan
Copy link
Contributor

Currently any of the knife * from file commands autocomplete by the knife plugin only look in the current directory for the relevant files. This fix searches upwards for a .chef folder and then looks in the folder relative to that folder (this is similar to the way knife itself functions). This should affect the following subcommands:

  • knife node from file
  • knife environment from file
  • knife role from file
  • knife data bag from file

It also adds an option (KNIFE_RELATIVE_PATH) that lets knife cookbook upload work in the same way. This is useful when you have multiple local Chef orgs and can't set a path to a single cookbooks folder.

for (( n=${#slashes}; n>0; --n ))
do
test -e "$directory/.chef" && echo "$directory" && return
directory="$directory/.."
Copy link
Member

Choose a reason for hiding this comment

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

You can use ${directory:h} to get the parent folder. Then you only need to check if $directory = / in your loop condition, and you don't need the slashes and the for.

@kierandoonan
Copy link
Contributor Author

Updated to use directory:h

@mcornella
Copy link
Member

Better 👍

I haven't tested the rest, it would be nice to have some more people test this.
/cc contributors @loxley @marcparadise @maplebed @mugenken @cwjohnston @moutten @franklouwers

@robbyrussell robbyrussell added Status: testers needed Pull Requests that are waiting for testers to merge Area: plugin Issue or PR related to a plugin labels Sep 27, 2015
@njsnx
Copy link

njsnx commented Jun 8, 2016

Will this be merged? Very useful!

@petrhecko
Copy link

Works fine for me, would be great to be merged!

@mcornella mcornella merged commit 80cac85 into ohmyzsh:master Jun 8, 2016
@mcornella
Copy link
Member

mcornella commented Jun 8, 2016

Merged. It would be better if those documenting comments where put in a README file.

@maxmanders
Copy link

Thanks folks, and nice work @kierandoonan :-D

neiljdo added a commit to neiljdo/oh-my-zsh that referenced this pull request Jun 8, 2016
* 'master' of https://github.com/robbyrussell/oh-my-zsh: (69 commits)
  Fix: Plugin knife: Add relative local path for commands which upload files (ohmyzsh#4240)
  Add list-timers to systemd user commands (ohmyzsh#5099)
  Adds ReactNative plugin 📱 (ohmyzsh#5018)
  Fix arcanist aliases (ohmyzsh#5110)
  add plugin react-native (ohmyzsh#4606)
  installer: fix ordering of cygwin msys git check (ohmyzsh#4557)
  Use default branch on recently created Mercurial repository. (ohmyzsh#4985)
  Add zsh completion plugin for rustc (ohmyzsh#3159)
  Changd `alias gsta='git stash'` to `alias gsta='git stash save'`.
  added assembly alias (ohmyzsh#5107)
  Fix styling in cakephp3 completion
  Better cake3 completion
  Change vim command to $EDITOR for consistency (ohmyzsh#5063)
  fixed bower completion error from issue ohmyzsh#2694 (ohmyzsh#5056)
  vagrant snapshot (ohmyzsh#5032)
  Arcanist plugin (ohmyzsh#5106)
  completion: zsh: improve main function selection
  gitfast: fix the prompt colour
  gitfast: update to upstream v2.8
  Add alias for oneline git tree with --all option
  ...
ShadowStar pushed a commit to ShadowStar/oh-my-zsh that referenced this pull request Jun 12, 2016
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
foobacca pushed a commit to foobacca/oh-my-zsh that referenced this pull request Jun 12, 2016
* upstream/master:
  Mod: use new debug namespace to avoid deprecation warning (ohmyzsh#4799)
  Fix: Plugin knife: Add relative local path for commands which upload files (ohmyzsh#4240)
  Add list-timers to systemd user commands (ohmyzsh#5099)
  Adds ReactNative plugin 📱 (ohmyzsh#5018)
  Fix arcanist aliases (ohmyzsh#5110)
  add plugin react-native (ohmyzsh#4606)
  installer: fix ordering of cygwin msys git check (ohmyzsh#4557)
  Use default branch on recently created Mercurial repository. (ohmyzsh#4985)
  Support bundler
sprig added a commit to sprig/oh-my-zsh that referenced this pull request Jun 20, 2016
…to robbyrussell-master

* 'master' of https://github.com/robbyrussell/oh-my-zsh: (454 commits)
  znt: update to v2.2.1 (ohmyzsh#5174)
  emacs plugin tweak to open buffer from stdin (ohmyzsh#5126)
  Update taskwarrior completion to 2.5.1 (ohmyzsh#5171)
  Remove undesirable hardcoding of PATH into zshrc (ohmyzsh#4925)
  Add README for OSX plugin and refactor plugin file
  Open finder to PWD - part 2 (ohmyzsh#5165)
  Add ofd() to OSX plugin to open finder on current directory (ohmyzsh#5164)
  add 'mvn clean install -DskipTests --offline' alias to speed up maven compile (ohmyzsh#5153)
  Peepcode theme: Don't try to use RVM if it's not available (ohmyzsh#5154)
  Replace _kitchen completion with the version from zsh-users (ohmyzsh#5011)
  Mod: use new debug namespace to avoid deprecation warning (ohmyzsh#4799)
  Fix: Plugin knife: Add relative local path for commands which upload files (ohmyzsh#4240)
  Add list-timers to systemd user commands (ohmyzsh#5099)
  Adds ReactNative plugin 📱 (ohmyzsh#5018)
  Fix arcanist aliases (ohmyzsh#5110)
  add plugin react-native (ohmyzsh#4606)
  installer: fix ordering of cygwin msys git check (ohmyzsh#4557)
  Use default branch on recently created Mercurial repository. (ohmyzsh#4985)
  Add zsh completion plugin for rustc (ohmyzsh#3159)
  Changd `alias gsta='git stash'` to `alias gsta='git stash save'`.
  ...
zhangweifang pushed a commit to zhangweifang/oh-my-zsh that referenced this pull request Jun 21, 2016
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
freecastle added a commit to freecastle/oh-my-zsh that referenced this pull request Jun 21, 2016
* 'master' of https://github.com/robbyrussell/oh-my-zsh:
  bundler plugin: Simplify retrieval of cpu count on OSX (ohmyzsh#5180)
  Fix gfg function completion definition
  Fix man-preview completion definition
  Fix issue with `dash` as the default `/bin/sh` script executing program. (ohmyzsh#5177)
  znt: update to v2.2.1 (ohmyzsh#5174)
  emacs plugin tweak to open buffer from stdin (ohmyzsh#5126)
  Update taskwarrior completion to 2.5.1 (ohmyzsh#5171)
  Remove undesirable hardcoding of PATH into zshrc (ohmyzsh#4925)
  Add README for OSX plugin and refactor plugin file
  Open finder to PWD - part 2 (ohmyzsh#5165)
  Add ofd() to OSX plugin to open finder on current directory (ohmyzsh#5164)
  add 'mvn clean install -DskipTests --offline' alias to speed up maven compile (ohmyzsh#5153)
  Peepcode theme: Don't try to use RVM if it's not available (ohmyzsh#5154)
  Replace _kitchen completion with the version from zsh-users (ohmyzsh#5011)
  Mod: use new debug namespace to avoid deprecation warning (ohmyzsh#4799)
  Fix: Plugin knife: Add relative local path for commands which upload files (ohmyzsh#4240)
sirech pushed a commit to sirech/oh-my-zsh that referenced this pull request Jun 21, 2016
* source/master: (61 commits)
  bundler plugin: Simplify retrieval of cpu count on OSX (ohmyzsh#5180)
  Fix gfg function completion definition
  Fix man-preview completion definition
  Fix issue with `dash` as the default `/bin/sh` script executing program. (ohmyzsh#5177)
  znt: update to v2.2.1 (ohmyzsh#5174)
  emacs plugin tweak to open buffer from stdin (ohmyzsh#5126)
  Update taskwarrior completion to 2.5.1 (ohmyzsh#5171)
  Remove undesirable hardcoding of PATH into zshrc (ohmyzsh#4925)
  Add README for OSX plugin and refactor plugin file
  Open finder to PWD - part 2 (ohmyzsh#5165)
  Add ofd() to OSX plugin to open finder on current directory (ohmyzsh#5164)
  add 'mvn clean install -DskipTests --offline' alias to speed up maven compile (ohmyzsh#5153)
  Peepcode theme: Don't try to use RVM if it's not available (ohmyzsh#5154)
  Replace _kitchen completion with the version from zsh-users (ohmyzsh#5011)
  Mod: use new debug namespace to avoid deprecation warning (ohmyzsh#4799)
  Fix: Plugin knife: Add relative local path for commands which upload files (ohmyzsh#4240)
  Add list-timers to systemd user commands (ohmyzsh#5099)
  Adds ReactNative plugin 📱 (ohmyzsh#5018)
  Fix arcanist aliases (ohmyzsh#5110)
  add plugin react-native (ohmyzsh#4606)
  ...
tedbundyjr pushed a commit to tedbundyjr/oh-my-zsh that referenced this pull request Jun 23, 2016
* 'master' of https://github.com/robbyrussell/oh-my-zsh: (201 commits)
  bundler plugin: Simplify retrieval of cpu count on OSX (ohmyzsh#5180)
  Fix gfg function completion definition
  Fix man-preview completion definition
  Fix issue with `dash` as the default `/bin/sh` script executing program. (ohmyzsh#5177)
  znt: update to v2.2.1 (ohmyzsh#5174)
  emacs plugin tweak to open buffer from stdin (ohmyzsh#5126)
  Update taskwarrior completion to 2.5.1 (ohmyzsh#5171)
  Remove undesirable hardcoding of PATH into zshrc (ohmyzsh#4925)
  Add README for OSX plugin and refactor plugin file
  Open finder to PWD - part 2 (ohmyzsh#5165)
  Add ofd() to OSX plugin to open finder on current directory (ohmyzsh#5164)
  add 'mvn clean install -DskipTests --offline' alias to speed up maven compile (ohmyzsh#5153)
  Peepcode theme: Don't try to use RVM if it's not available (ohmyzsh#5154)
  Replace _kitchen completion with the version from zsh-users (ohmyzsh#5011)
  Mod: use new debug namespace to avoid deprecation warning (ohmyzsh#4799)
  Fix: Plugin knife: Add relative local path for commands which upload files (ohmyzsh#4240)
  Add list-timers to systemd user commands (ohmyzsh#5099)
  Adds ReactNative plugin 📱 (ohmyzsh#5018)
  Fix arcanist aliases (ohmyzsh#5110)
  add plugin react-native (ohmyzsh#4606)
  ...

# Conflicts:
#	README.md
#	lib/git.zsh
#	plugins/branch/branch.plugin.zsh
#	plugins/ember-cli/README.md
#	plugins/github/README.md
#	plugins/github/github.plugin.zsh
#	plugins/history-substring-search/README.md
#	plugins/history-substring-search/update-from-upstream.zsh
#	plugins/zsh-navigation-tools/.config/znt/n-aliases.conf
#	plugins/zsh-navigation-tools/.config/znt/n-cd.conf
#	plugins/zsh-navigation-tools/.config/znt/n-env.conf
#	plugins/zsh-navigation-tools/.config/znt/n-functions.conf
#	plugins/zsh-navigation-tools/.config/znt/n-history.conf
#	plugins/zsh-navigation-tools/.config/znt/n-kill.conf
#	plugins/zsh-navigation-tools/.config/znt/n-list.conf
#	plugins/zsh-navigation-tools/.config/znt/n-options.conf
#	plugins/zsh-navigation-tools/.config/znt/n-panelize.conf
#	plugins/zsh-navigation-tools/README.md
#	plugins/zsh-navigation-tools/n-aliases
#	plugins/zsh-navigation-tools/n-cd
#	plugins/zsh-navigation-tools/n-env
#	plugins/zsh-navigation-tools/n-functions
#	plugins/zsh-navigation-tools/n-history
#	plugins/zsh-navigation-tools/n-kill
#	plugins/zsh-navigation-tools/n-list
#	plugins/zsh-navigation-tools/n-list-draw
#	plugins/zsh-navigation-tools/n-list-input
#	plugins/zsh-navigation-tools/n-options
#	plugins/zsh-navigation-tools/n-panelize
#	plugins/zsh-navigation-tools/znt-history-widget
#	plugins/zsh-navigation-tools/zsh-navigation-tools.plugin.zsh
sprig added a commit to sprig/oh-my-zsh that referenced this pull request Jun 25, 2016
* 'master' of github.com:sprig/oh-my-zsh: (455 commits)
  quoted a string
  znt: update to v2.2.1 (ohmyzsh#5174)
  emacs plugin tweak to open buffer from stdin (ohmyzsh#5126)
  Update taskwarrior completion to 2.5.1 (ohmyzsh#5171)
  Remove undesirable hardcoding of PATH into zshrc (ohmyzsh#4925)
  Add README for OSX plugin and refactor plugin file
  Open finder to PWD - part 2 (ohmyzsh#5165)
  Add ofd() to OSX plugin to open finder on current directory (ohmyzsh#5164)
  add 'mvn clean install -DskipTests --offline' alias to speed up maven compile (ohmyzsh#5153)
  Peepcode theme: Don't try to use RVM if it's not available (ohmyzsh#5154)
  Replace _kitchen completion with the version from zsh-users (ohmyzsh#5011)
  Mod: use new debug namespace to avoid deprecation warning (ohmyzsh#4799)
  Fix: Plugin knife: Add relative local path for commands which upload files (ohmyzsh#4240)
  Add list-timers to systemd user commands (ohmyzsh#5099)
  Adds ReactNative plugin 📱 (ohmyzsh#5018)
  Fix arcanist aliases (ohmyzsh#5110)
  add plugin react-native (ohmyzsh#4606)
  installer: fix ordering of cygwin msys git check (ohmyzsh#4557)
  Use default branch on recently created Mercurial repository. (ohmyzsh#4985)
  Add zsh completion plugin for rustc (ohmyzsh#3159)
  ...
atsuya pushed a commit to atsuya/oh-my-zsh that referenced this pull request Jul 23, 2016
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
bwkeller pushed a commit to bwkeller/oh-my-zsh that referenced this pull request Aug 6, 2016
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
DennisDenuto pushed a commit to DennisDenuto/oh-my-zsh that referenced this pull request Oct 29, 2016
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
avleen pushed a commit to avleen/oh-my-zsh that referenced this pull request Dec 23, 2016
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
seth-cohen pushed a commit to seth-cohen/oh-my-zsh that referenced this pull request Oct 29, 2018
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
jmartindf pushed a commit to jmartindf/oh-my-zsh that referenced this pull request Nov 10, 2018
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
@mcornella mcornella removed the Status: testers needed Pull Requests that are waiting for testers to merge label Oct 24, 2019
spiliopoulos pushed a commit to spiliopoulos/zsh-config that referenced this pull request Jun 17, 2020
…files (ohmyzsh#4240)

* Added autocomplete support for local knife file uploads

* Added option to allow for relative path resolution for cookbooks

* Updated _chef_root function to use directory:h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: plugin Issue or PR related to a plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants