Created
April 21, 2021 11:54
-
-
Save alicanerdogan/a7f51df5ad77aac180f906489484bfc9 to your computer and use it in GitHub Desktop.
Setup Mac Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'open3' | |
| aliases = | |
| %{git_current_branch() { | |
| git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
| } | |
| gpush() { | |
| git push origin $(git_current_branch) | |
| } | |
| gpushf() { | |
| git push --force origin $(git_current_branch) | |
| } | |
| gpull() { | |
| git pull origin $(git_current_branch) | |
| } | |
| alias gremovebranches="git branch --merged origin/master | grep -v 'master$' | xargs git branch -d" | |
| alias edit-bashrc="vi ~/.bashrc && source ~/.bashrc" | |
| alias edit-zshrc="vi ~/.zshrc && source ~/.zshrc" | |
| alias edit-aliases="vi ~/.aliases && source ~/.aliases"} | |
| post_installation_aliases = | |
| 'alias rm="safe-rm" | |
| export GOPATH=$HOME/repos/go | |
| export PATH=$PATH:$GOPATH/bin | |
| export NVM_DIR="$HOME/.nvm" | |
| [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm | |
| [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion' | |
| zshrc = | |
| 'ZSH_THEME="agnoster" | |
| source ~/.aliases' | |
| bashrc = 'source ~/.aliases' | |
| install_zsh_cmd = | |
| '$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)' | |
| install_brew = | |
| '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)' | |
| brew_pkgs = %w[ | |
| bash-completion | |
| bat | |
| fd | |
| fzf | |
| gh | |
| go | |
| golangci/tap/golangci-lint | |
| htop | |
| jq | |
| mkcert | |
| node | |
| nvm | |
| postgresql | |
| safe-rm | |
| starship | |
| vim | |
| wget | |
| yarn | |
| zsh-you-should-use | |
| git | |
| curl | |
| rust | |
| ruby | |
| docker | |
| ] | |
| brew_taps = %w[homebrew/cask-fonts] | |
| brew_cask_pkgs = %w[ | |
| visual-studio-code | |
| microsoft-edge | |
| spotify | |
| firefox-beta | |
| iterm2 | |
| trailer | |
| font-fira-code | |
| ] | |
| brew_services = %w[postgresql] | |
| npm_pkgs = %w[tldr] | |
| vscode_extensions = %w[ | |
| albert.TabOut | |
| arcsine.chronicler | |
| castwide.solargraph | |
| cssho.vscode-svgviewer | |
| dbaeumer.vscode-eslint | |
| eamodio.gitlens | |
| esbenp.prettier-vscode | |
| GitHub.github-vscode-theme | |
| golang.go | |
| GraphQL.vscode-graphql | |
| joelday.docthis | |
| jpoissonnier.vscode-styled-components | |
| misogi.ruby-rubocop | |
| ms-vscode.hexeditor | |
| mtxr.sqltools | |
| Orta.vscode-jest | |
| rebornix.ruby | |
| redhat.vscode-yaml | |
| rust-lang.rust | |
| ryu1kn.partial-diff | |
| wingrunr21.vscode-ruby | |
| ] | |
| def execute_cmd(args = {}) | |
| shell = args.fetch(:shell, 'zsh') | |
| cmd = args.fetch(:cmd, nil) | |
| raise 'cmd cannot be empty' if cmd == nil | |
| exit_status = nil | |
| Open3.popen2e( | |
| "#{shell} -c \"#{cmd}\"" | |
| ) do |stdin, stdout_and_stderr, wait_thread| | |
| while line = stdout_and_stderr.gets | |
| puts line | |
| end | |
| exit_status = wait_thread.value.exitstatus | |
| end | |
| raise "#{cmd} returned exit status #{exit_status}" if exit_status != 0 | |
| end | |
| execute_cmd(cmd: install_zsh_cmd, shell: 'sh') | |
| File.write('~/.aliases', aliases, mode: 'a') | |
| File.write('~/.bashrc', aliases, mode: 'a') | |
| File.write('~/.zshrc', aliases, mode: 'a') | |
| execute_cmd(cmd: install_brew) | |
| brew_pkgs.each { |pkg| execute_cmd(cmd: "brew install #{pkg}") } | |
| brew_taps.each { |tap| execute_cmd(cmd: "brew tap #{tap}") } | |
| brew_cask_pkgs.each do |cask_pkg| | |
| execute_cmd(cmd: "brew install --cask #{cask_pkg}") | |
| end | |
| brew_services.each do |service| | |
| execute_cmd(cmd: "brew services start #{service}") | |
| end | |
| npm_pkgs.each { |npm_pkg| execute_cmd(cmd: "yarn global add #{npm_pkg}") } | |
| vscode_extensions.each do |ext| | |
| execute_cmd(cmd: "code --install-extension #{ext}") | |
| end | |
| File.write('~/.aliases', post_installation_aliases, mode: 'a') | |
| puts 'Please install manually logitech options for input device support' | |
| puts 'SETUP HAS BEEN SUCCESSFUL' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment