From 08b50ad31bdbd747bcbf2ab8a4f883f4fa602728 Mon Sep 17 00:00:00 2001 From: Tim Triemstra Date: Wed, 22 Nov 2023 18:42:12 -0800 Subject: [PATCH] Mostly renames but starting to get ready for setting up via PATH (basically a reset) or a local Dotfiles repo --- .../com.apple.Terminal.plist | Bin .../com.googlecode.iterm2.plist | Bin Mac/{ => Root}/dot-aliases.sh | 0 Mac/{ => Root}/dot-functions.sh | 0 Mac/{ => Root}/dot-gitconfig | 0 Mac/{ => Root}/dot-gitignore | 0 Mac/{ => Root}/dot-vimrc | 0 Mac/{ => Root}/dot-zshenv.sh | 0 Mac/{ => Root}/dot-zshrc.sh | 6 +- Mac/Scripts/install-ruby.sh | 18 ----- Mac/Scripts/update-ruby.sh | 64 ------------------ .../install-brew.sh => setup-brew.sh} | 4 +- Mac/{setup-macos.sh => setup-dotfiles.sh} | 55 ++++++++------- Mac/setup-ruby.sh | 47 +++++++++++++ readme.md | 37 ++++------ setup.sh | 14 +++- todo.md | 12 ++-- 17 files changed, 113 insertions(+), 144 deletions(-) rename Mac/{Settings => Preferences}/com.apple.Terminal.plist (100%) rename Mac/{Settings => Preferences}/com.googlecode.iterm2.plist (100%) rename Mac/{ => Root}/dot-aliases.sh (100%) rename Mac/{ => Root}/dot-functions.sh (100%) rename Mac/{ => Root}/dot-gitconfig (100%) rename Mac/{ => Root}/dot-gitignore (100%) rename Mac/{ => Root}/dot-vimrc (100%) rename Mac/{ => Root}/dot-zshenv.sh (100%) rename Mac/{ => Root}/dot-zshrc.sh (94%) delete mode 100755 Mac/Scripts/install-ruby.sh delete mode 100755 Mac/Scripts/update-ruby.sh rename Mac/{Scripts/install-brew.sh => setup-brew.sh} (86%) rename Mac/{setup-macos.sh => setup-dotfiles.sh} (84%) create mode 100755 Mac/setup-ruby.sh diff --git a/Mac/Settings/com.apple.Terminal.plist b/Mac/Preferences/com.apple.Terminal.plist similarity index 100% rename from Mac/Settings/com.apple.Terminal.plist rename to Mac/Preferences/com.apple.Terminal.plist diff --git a/Mac/Settings/com.googlecode.iterm2.plist b/Mac/Preferences/com.googlecode.iterm2.plist similarity index 100% rename from Mac/Settings/com.googlecode.iterm2.plist rename to Mac/Preferences/com.googlecode.iterm2.plist diff --git a/Mac/dot-aliases.sh b/Mac/Root/dot-aliases.sh similarity index 100% rename from Mac/dot-aliases.sh rename to Mac/Root/dot-aliases.sh diff --git a/Mac/dot-functions.sh b/Mac/Root/dot-functions.sh similarity index 100% rename from Mac/dot-functions.sh rename to Mac/Root/dot-functions.sh diff --git a/Mac/dot-gitconfig b/Mac/Root/dot-gitconfig similarity index 100% rename from Mac/dot-gitconfig rename to Mac/Root/dot-gitconfig diff --git a/Mac/dot-gitignore b/Mac/Root/dot-gitignore similarity index 100% rename from Mac/dot-gitignore rename to Mac/Root/dot-gitignore diff --git a/Mac/dot-vimrc b/Mac/Root/dot-vimrc similarity index 100% rename from Mac/dot-vimrc rename to Mac/Root/dot-vimrc diff --git a/Mac/dot-zshenv.sh b/Mac/Root/dot-zshenv.sh similarity index 100% rename from Mac/dot-zshenv.sh rename to Mac/Root/dot-zshenv.sh diff --git a/Mac/dot-zshrc.sh b/Mac/Root/dot-zshrc.sh similarity index 94% rename from Mac/dot-zshrc.sh rename to Mac/Root/dot-zshrc.sh index bdfe2ab..39f6205 100755 --- a/Mac/dot-zshrc.sh +++ b/Mac/Root/dot-zshrc.sh @@ -19,7 +19,7 @@ message ".zshrc" "Launched $SHELL' at ${TIMENOW}." # Warn about installing Homebrew if it is not yet present which -s brew &> /dev/null if [[ $? != 0 ]] ; then - error "Missing Homebrew" "Run install-brew.sh" + error "Missing Homebrew" "Run setup-brew.sh" else message "Found Homebrew" "Installed brew tools supercede system tools (e.g. Ruby)" fi @@ -52,13 +52,13 @@ source $HOME/local.sh # *** NOTE: Removing rbenv - switched to simple `brew install ruby` # # This `rbenv` setting needs to be hard-coded into .zshrc by default -# If you get a "command not found" for rbenv, run `install-ruby` +# If you get a "command not found" for rbenv, run `setup-ruby` # # To read more about installing rbenv see: https://github.com/rbenv/rbenv # eval "$(rbenv init - zsh)" # which -s rbenv &> /dev/null # if [[ $? != 0 ]] ; then -# error "Missing rbenv" "Run install-ruby.sh" +# error "Missing rbenv" "Run setup-ruby.sh" # else # eval "$(rbenv init -)" # export PATH="${HOME}/.rbenv/bin:$PATH" diff --git a/Mac/Scripts/install-ruby.sh b/Mac/Scripts/install-ruby.sh deleted file mode 100755 index 282fb61..0000000 --- a/Mac/Scripts/install-ruby.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/zsh -# -# install-ruby.sh -- macOS version (simple version, installs latest) - -source ${HOME}/.functions -message "install-ruby.sh" "Running [brew install ruby] instead of [rbenv]" -bullet "The latest Ruby is installed via this script and put first in PATH" - -which -s brew -if [[ $? != 0 ]] ; then - error "Missing Homebrew" "Must first install Homebrew before installing Ruby" - exit 0 -fi - -brew install ruby - -# ============================================================================== -exit 0 diff --git a/Mac/Scripts/update-ruby.sh b/Mac/Scripts/update-ruby.sh deleted file mode 100755 index d458e52..0000000 --- a/Mac/Scripts/update-ruby.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/zsh -# -# update-ruby.sh -# -# Import the default functions used in these scripts -source ${HOME}/.functions -message "update-ruby.sh" "Checking current installs of \"brew\" and \"rbenv\"" - -# If rbenv isn't already installed, add following to the .zshrc file -# if [[ -v RBENV_INSTALLED ]]; then -# bullet "RBENV_INSTALLED = $RBENV_INSTALLED - already installed" -# else -# bullet "RBENV_INSTALLED = $RBENV_INSTALLED - not installed, adding to .zshrc" -# fi - - -# ============================================================================== -CURRENT_RUBY=$(ruby -v 2> /dev/null) -bullet "Ruby Version = ${CURRENT_RUBY}" - - -# ============================================================================== -# Make sure Homebrew and rbenv are properly installed, or this will all fail -which -s brew &> /dev/null -if [[ $? != 0 ]] ; then - error "Missing Homebrew" "Re-run install-brew" - exit 0 -fi - -which -s rbenv &> /dev/null -if [[ $? != 0 ]] ; then - error "Missing rbenv" "Re-run install-ruby" - exit 0 -fi - - - -# ============================================================================== -# Install some gems (Jekyll and Bundler to start) -# rbenv and a custom Ruby is required for users to install their own gems -# because the system Ruby is read-only (no new gems installs) -which -s bundler &> /dev/null -if [[ $? != 0 ]] ; then - bullet "Installing Bundler" "Installing the Bundler gem for the first time" - sudo gem install bundler -else - message "Updating Bundler" "Updating the Bundler gem to latest version" - sudo gem update bundler -fi - -which -s jekyll &> /dev/null -if [[ $? != 0 ]] ; then - bullet "Installing Jekyll" "Installing the Jekyll gem for the first time" - sudo gem install jekyll -else - bullet "Updating Jekyll" "Updating the Jekyll gem to latest version" - sudo gem update jekyll -fi - - -# ============================================================================== -exit 0 - - diff --git a/Mac/Scripts/install-brew.sh b/Mac/setup-brew.sh similarity index 86% rename from Mac/Scripts/install-brew.sh rename to Mac/setup-brew.sh index 4f7e71f..03de5ca 100755 --- a/Mac/Scripts/install-brew.sh +++ b/Mac/setup-brew.sh @@ -1,6 +1,6 @@ #!/bin/zsh # -# install-brew.sh -- macOS version +# setup-brew.sh -- macOS version # # ============================================================================== @@ -8,7 +8,7 @@ source ~/.functions -message "install-brew.sh" "Installing Homebrew using default script" +message "setup-brew.sh" "Installing Homebrew using default script" which -s brew &> /dev/null if [[ $? != 0 ]] ; then diff --git a/Mac/setup-macos.sh b/Mac/setup-dotfiles.sh similarity index 84% rename from Mac/setup-macos.sh rename to Mac/setup-dotfiles.sh index 3f11d4b..e2e43ed 100755 --- a/Mac/setup-macos.sh +++ b/Mac/setup-dotfiles.sh @@ -1,7 +1,9 @@ #!/bin/zsh # # setup-macos.sh - the macOS version -source "$DOTFILES_ROOT/Mac/dot-functions.sh" + +# TODO: This needs to adapt to whether this is a FRESH install or re-run from PATH +source "$DOTFILES_ROOT/Mac/Root/dot-functions.sh" echo message "setup-macos.sh -- setting up for macOS via ${DOTFILES_ROOT}" @@ -48,47 +50,44 @@ sudo chmod 766 $HOME/Developer sudo chmod 777 /opt/homebrew/bin sudo chmod 777 /usr/local/bin + +# ============================================================================== +message "Copying scripts into ~/Developer" "These scripts are now in PATH" # Put some files in these directories just to validate cp ${DOTFILES_ROOT}/readme.md $HOME/Developer -# ============================================================================== -message "Copying dotfiles" "Overwriting existing versions of these files" -cp $DOTFILES_ROOT/Mac/dot-zshrc.sh $HOME/.zshrc -cp $DOTFILES_ROOT/Mac/dot-zshenv.sh $HOME/.zshenv -cp $DOTFILES_ROOT/Mac/dot-aliases.sh $HOME/.aliases -cp $DOTFILES_ROOT/Mac/dot-functions.sh $HOME/.functions +# Don't copy with -R for the primary PATH files +cp -R $DOTFILES_ROOT/Mac/* $HOME/Developer/ + -# Copy app preferences -cp $DOTFILES_ROOT/Mac/Preferences/* $HOME/Library/Preferences/ + +# TODO: FEATURE - Install from ~/Developer if run from PATH, or DOTFILES if fresh install + +# ============================================================================== +message "Installing root dotfiles" "Overwriting existing versions of these files" +cp $DOTFILES_ROOT/Mac/Root/dot-zshrc.sh $HOME/.zshrc +cp $DOTFILES_ROOT/Mac/Root/dot-zshenv.sh $HOME/.zshenv +cp $DOTFILES_ROOT/Mac/Root/dot-aliases.sh $HOME/.aliases +cp $DOTFILES_ROOT/Mac/Root/dot-functions.sh $HOME/.functions # Copy Git and other config files -cp $DOTFILES_ROOT/Mac/dot-gitconfig $HOME/.gitconfig -cp $DOTFILES_ROOT/Mac/dot-gitignore $HOME/.gitignore -cp $DOTFILES_ROOT/Mac/dot-vimrc $HOME/.vimrc +cp $DOTFILES_ROOT/Mac/Root/dot-gitconfig $HOME/.gitconfig +cp $DOTFILES_ROOT/Mac/Root/dot-gitignore $HOME/.gitignore +cp $DOTFILES_ROOT/Mac/Root/dot-vimrc $HOME/.vimrc # Register gitignore and other git stuff git config --global core.excludesfile ~/.gitignore +message "Installing app preferences" "Overwriting Terminal, Xcode, and other settings" +# Copy app settings +cp $DOTFILES_ROOT/Mac/Preferences/* $HOME/Library/Preferences/ + # Copy Xcode preferences mkdir -p $HOME/Library/Developer/Xcode/UserData/FontAndColorThemes cp -R $DOTFILES_ROOT/Mac/Xcode/* $HOME/Library/Developer/Xcode/UserData/FontAndColorThemes/ -# ============================================================================== -message "Copying scripts into ~/Developer" "These scripts are now in PATH" -cp -R $DOTFILES_ROOT/Mac/Demos/* $HOME/Developer/ -cp -R $DOTFILES_ROOT/Mac/Scripts/* $HOME/Developer/ -# Don't copy with -R for the root files, to avoid copyin -cp $DOTFILES_ROOT/Mac/* $HOME/Developer/ - -# These files are copied into Developer subfolders, not into the PATH -mkdir -p $HOME/Developer/Settings -cp -R $DOTFILES_ROOT/Mac/Settings/* $HOME/Developer/Settings/ - -mkdir -p $HOME/Developer/Xcode -cp -R $DOTFILES_ROOT/Mac/Xcode/* $HOME/Developer/Xcode/ - # ============================================================================== @@ -156,8 +155,8 @@ echo message "Restart terminal" "After restart, you can run the following commands:" bullet "git config --global user.name \"Your Name\"" bullet "git config --global user.email \"youremail@yourdomain.com\"" -bullet "install-brew.sh <-- install and setup Homebrew" -bullet "install-ruby.sh <-- install a newer version of Ruby via Homebrew" +bullet "setup-brew.sh <-- install or update Homebrew" +bullet "setup-ruby.sh <-- setup a newer version (or update) of Ruby via Homebrew" echo exit 0 diff --git a/Mac/setup-ruby.sh b/Mac/setup-ruby.sh new file mode 100755 index 0000000..9062d45 --- /dev/null +++ b/Mac/setup-ruby.sh @@ -0,0 +1,47 @@ +#!/bin/zsh +# +# setup-ruby.sh -- macOS version (simple version, installs latest) + +source ${HOME}/.functions +message "setup-ruby.sh" "Running [brew install ruby] instead of [rbenv]" +bullet "The latest Ruby is installed via this script and put first in PATH" + +which -s brew +if [[ $? != 0 ]] ; then + error "Missing Homebrew" "Must first install Homebrew before installing Ruby" + exit 0 +fi + +brew install ruby + +# Update to the latest version of Ruby Gems installers +sudo gem update + + + +# TODO: the below may require Terminal is restarted one before it succeeds? + +# ============================================================================== +# Install some gems (Jekyll and Bundler to start) +which -s bundler &> /dev/null +if [[ $? != 0 ]] ; then + bullet "Installing Bundler" "Installing the Bundler gem for the first time" + sudo gem install bundler +else + message "Updating Bundler" "Updating the Bundler gem to latest version" + sudo gem update bundler +fi + +which -s jekyll &> /dev/null +if [[ $? != 0 ]] ; then + bullet "Installing Jekyll" "Installing the Jekyll gem for the first time" + sudo gem install jekyll +else + bullet "Updating Jekyll" "Updating the Jekyll gem to latest version" + sudo gem update jekyll +fi + + + +# ============================================================================== +exit 0 diff --git a/readme.md b/readme.md index da3176b..be9b111 100755 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ Documentation for these `dotfiles` can be [found here](https://timtr.github.io/Dotfiles/Docs/). -On a Mac, first install Xcode or the command line tools package. Then run: +On a Mac, first install Xcode or the command line tools, then run: ``` git clone https://github.com/timtr/Dotfiles.git @@ -10,30 +10,31 @@ On a Mac, first install Xcode or the command line tools package. Then run: ./setup.sh ``` -Alternately, type `./setup.sh reset` to override custom files like `./local.sh` and to blow-away settings for tools like Xcode that you may otherwise not want to modify. +You can also type `./setup.sh reset` to override custom files like `./local.sh` and to blow-away settings for tools like Xcode that you may otherwise not want to modify. -Run `setup.sh` from within a local `Dotfiles` folder instance. Once installed, quit Terminal and relaunch. Finish install by typing: +The first install requires that you run `setup.sh` from within the local `Dotfiles` folder. Once installed, quit Terminal and relaunch. Finish install by typing: ``` git config --global user.name "Your Name" git config --global user.email "youremail@yourdomain.com" - install-brew.sh - install-ruby.sh + setup-brew.sh + setup-ruby.sh ``` -A tool called `help.sh` is runable from the shell for additional help. +Once installed, a tool called `help.sh` is runable from the PATH for additional help. ## Features -Files ending in .sh are often renamed to be prefix by a `"."` with the `.sh` extension removed. This makes these files easier to edit during creation of this project, and also makes it clear which are "source" versions of these files, versus the installed versions. +**local.sh** - Installs a file called `~/local.sh` (if doesn't exist) that you can customize with settings that do not belong checked into GitHub, for instance set certain keys, or environment variables. This is also the file to add things like feature flags during development, add a Swift toolchain, or to enable secret build settings. **ZSH settings** - sets up the prompt, `PATH`, and other basic settings. Note that `.zshenv` sets up the PATH so it works even when there is no interactive terminal session, and `.zshrc` will source this file for a consistent PATH for terminal windows. -**local.sh** - Installs a file called `~/local.sh` (if doesn't exist) that you can customize with settings that do not belong checked into GitHub, for instance set certain keys, or environment variables. This is also the file to add things like feature flags during development, add a Swift toolchain, or to enable secret build settings. +Files ending in `.sh` are often renamed to have a "dot" prefix and no extension (`.sh` removed). The the `.sh` extension hints to text editors to highlight like a shell script, and also makes it clear which are "source" versions of these files, versus the installed no-extension versions. + -### Other smaller features +### Other small features - Creates a symlink from ~/Dropbox to the new ~/Library/CloudStorage directory if it exists @@ -48,20 +49,10 @@ For reference, `zsh` config files are loaded in the following order: .zprofile -- if login (not using this file in current setup) ``` -### Known Issues and ToDo items - -- TODO: report the current `git config --global user.name "your name"` info, or if not set then report how to set it. Same for the setting for `git config --global user.email \"email@domain.com\"` - - ## Setup a custom Swift toolchain -You can download new Swift toolchains from [Swift.org](https://swift.org/download/#snapshots) and set them up to be used by default. There is a new alias installed by these dotfiles called `swift-alt` that will run the `swift` command line interface using the alternate toolchain, once installed. - -This dotfiles install will install a file called `.swift-settings.sh` at the user's root, enabling feature flags and adding the `swift-alt` alias. You will likely need to edit this file to enter the bundle ID of the installed toolchain you would like to use. As a result, the dotfiles `setup.sh` script will not overwrite this file once installed, so as to not blow away your customizations. If you want to re-install this file, simply delete it and re-run the dotfiles `setup.sh` to install a fresh version. - -To get the correct toolchain bundle ID, in the format `org.swift.cXXXXXXX` you will need to go to the folder `/Library/Something/Toolchains` after installed, show package contents of one of the toolchains, and open the `Info.plist` file. From there, you should see a Bundle ID entry, matching the format. - +You can download new Swift toolchains from [Swift.org](https://swift.org/download/#snapshots) and set them up to be used by default. The `~/local.sh` file is perfect to place to configure these settings rather than make the changes to the main Dotfile repo since it is likely to be a per-machine configuration. ## Overview @@ -72,14 +63,14 @@ The scripts are designed to work in `zsh`, although they rarely use advanced fea The setup will create a custom folder `$HOME/bin/` that is added to the PATH variable and useful for putting random stuff in the path. For Homebrew and related tools support, it also adds `/usr/local/bin` (for Intel) and `/opt/homebrew/bin` (for Apple) to the PATH. -There are a few aliases added that make it easy to install Homebrew and other tools, rather than trying to do the installs directly from `setup.sh`. Mostly this is because the install is a multi-step process, and it is just a lot easier to run the full setup, then manually type `install-brew` when everything else looks to be working. +There are a few aliases added that make it easy to install Homebrew and other tools, rather than trying to do the installs directly from `setup.sh`. Mostly this is because the install is a multi-step process, and it is just a lot easier to run the full setup, then manually type `setup-brew.sh` when everything else looks to be working. ## Demos -Once installed, you can install Homebrew and run demos. For example, run `demo-homebrew.sh` from the PATH to show a Terminal screen of software being downloaded, built, installed, and erased (in a repeating loop). Hit `CONTROL-Z` to quit that demo. +Once installed, you can install Homebrew and run demos. For example, run `demo-homebrew.sh` from the PATH to show a Terminal screen of software being downloaded, built, installed, and erased (in a repeating loop). Hit `CONTROL-Z` to quit that demo. -You can also open the `./Developer/demo-safari-cycle.html` file to launch Safari and begin cycling through many web pages, implying a sort of automated web test harness. +You can also open the `~/Developer/demo-safari-cycle.html` file to launch Safari and begin cycling through many web pages, implying a sort of automated web test harness. ## License diff --git a/setup.sh b/setup.sh index 68aa555..8d89ef6 100755 --- a/setup.sh +++ b/setup.sh @@ -18,6 +18,7 @@ fi DOTFILES_ROOT=${0:a:h} DOTFILES_SETUP=${0:a} export DOTFILES_RESET=0 +export DOTFILES_FRESH=1 # Display usage information if no commands are entered @@ -34,13 +35,22 @@ if [[ "$1" = "reset" ]]; then export DOTFILES_RESET=1 fi +# Handle the "reset" command if entered +if [[ "$1" = "fresh" ]]; then + echo "\n \033[1mFresh install\033[0m: Type setup-dotfiles.sh to re-run setup from PATH" + read -s -k + export DOTFILES_FRESH=1 +fi + + + # This script will run either the Linux or macOS installer # (yes, one day may need more options than this, but for now...) if [[ $OSTYPE == darwin* ]]; then - source $DOTFILES_ROOT/Mac/setup-macos.sh + source $DOTFILES_ROOT/Mac/setup-dotfiles.sh else - source $DOTFILES_ROOT/Linux/setup-linux.sh + source $DOTFILES_ROOT/Linux/setup-dotfiles.sh fi diff --git a/todo.md b/todo.md index 6dc7741..6035035 100755 --- a/todo.md +++ b/todo.md @@ -1,17 +1,21 @@ # TODO Items -- Rename the dot files to `dot-name.sh` to be more clear (Almost done) -- Add all `update-ruby.sh` functionality into `install-ruby.sh` script -- Copy all scripts and settings into `~/Developer` - Use a new variable for $HOME/Developer, e.g. $DEVELOPER - Drive full setup from $DEVELOPER to enable re-run from PATH, not from Dotfiles -- Move the actual dotfiles (e.g. `zshenv`) into subfolder `Root` + - Using `export DOTFILES_FRESH=1` to indicate a fresh install +- Report current `git config --global user.name "your name"` info (and email) - or instruct how to set it + + ## Done - Move all script files into main `Mac` folder to go into the $PATH - Put root `~/Developer` in the PATH (remove `./Bin` sub-folder) +- Rename the dot files to `dot-name.sh` to be more clear (Almost done) +- Copy all scripts and settings into `~/Developer` +- Add all `update-ruby.sh` functionality into `setup-ruby.sh` script +- Move the actual dotfiles (e.g. `zshenv`) into subfolder `Root`