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

Maintain idempotency in ~/.laptop.local when using Homebrew #279

Closed
AlJohri opened this issue Aug 29, 2014 · 5 comments
Closed

Maintain idempotency in ~/.laptop.local when using Homebrew #279

AlJohri opened this issue Aug 29, 2014 · 5 comments

Comments

@AlJohri
Copy link
Contributor

AlJohri commented Aug 29, 2014

I understand a lot of emphasis has been given to keep laptop idempotent (https://github.com/thoughtbot/laptop/search?q=idempotency&type=Issues). I was wondering if you have any ideas on how to maintain idempotency in one's personal ~/.laptop.local script.

Particularly, I would like to be able to use the functions written here, https://github.com/thoughtbot/laptop/blob/master/mac-components/mac-functions, within my local script.

My main issue is that when my script attempts to install homebrew packages I get warnings that they are already installed as opposed to simply upgrading them.

In addition, it would lovely if brew_install_or_upgrade could be accompanied with a brew_cask_install_or_upgrade. I understand considerable thought has been given to the implications of supporting brew cask:

but at the very least, supporting it as a function usable via ~/.laptop.local would allow for an extremely clean and readable configuration file.

Do you know any easy ways of accessing the mac-functions within ~/.laptop.local?
What are your thoughts on supporting brew-cask in this non-invasive / easy-to-maintain manner?

@djcp
Copy link
Contributor

djcp commented Aug 29, 2014

~/.laptop.local is sourced at the end, so it runs context of the greater laptop script and has access to the functions it contains.

To the more osx-y questions, I'll let others help you out.

@croaky
Copy link
Contributor

croaky commented Sep 1, 2014

@AlJohri There's not a lot of great, built-in support for brew cask upgrade or brew cask outdated but it is a high priority for the Homebrew Cask team:

Homebrew/homebrew-cask#4678
Homebrew/homebrew-cask#309

I've subscribed to those issues. If they get merged, I'll try to add a brew_cask_install_or_upgrade function at that time. In the meantime, as @djcp mentioned, brew_install_or_upgrade, fancy_echo and other functions defined in https://github.com/thoughtbot/laptop/blob/master/mac are available for use in ~/.laptop.local.

@croaky croaky closed this as completed Sep 1, 2014
@croaky croaky reopened this Sep 1, 2014
@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 7, 2014

Thanks for the responses! I didn't realize I could use the functions in ~/.laptop.local.

@croaky, it seems brew cask upgrade is far off from being completed - perhaps until then you could support a brew_cask_install_or_noop

The regular output of "Cask is already installed" is quite jarring.

@AlJohri
Copy link
Contributor Author

AlJohri commented Sep 21, 2014

This is kind of what I meant:

https://github.com/AlJohri/dotfiles/blob/master/setup-homebrew.sh#L12

brew_cask_expand_alias() {
  brew cask info "$1" 2>/dev/null | head -1 | awk '{gsub(/:/, ""); print $1}'
}

brew_cask_is_installed() {
  local NAME=$(brew_cask_expand_alias "$1")
  brew cask list -1 | grep -Fqx "$NAME"
}

brew_cask_install_or_upgrade() {
  if brew_cask_is_installed "$1"; then
    echo "$1 is already installed, brew cask upgrade is not yet implemented"
  else
    brew cask install "$@"
  fi
}

I know you currently don't echo within the commands (and fancy_echo outside) but at least supporting brew_cask_expand_alias and brew_cask_is_installedwould be a nice syntactical sugar.

@croaky
Copy link
Contributor

croaky commented Oct 1, 2014

Thanks for the code, @AlJohri. Others have been circling around similar ideas in other pull requests. We just created a wiki page that contains a few community extensions:

https://github.com/thoughtbot/laptop/wiki

Feel free to add further customizations you think might be valuable to others.

@croaky croaky closed this as completed Oct 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants