diff --git a/README.md b/README.md index d88741d..cff9bbb 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,32 @@ -### Dotfiles +## Dotfiles -My personal configuration files. +Developer config files. -##### Usage +| Tool | Description | +| -------- | ----------- | +| Homebrew | Package management | +| Nix | Package management (experimental) | +| Fish | Shell | +| Git | Version control | +| Neovim | Editor | -1. Clone this repository into `~/dotfiles` -2. Install [Homebrew](https://brew.sh/): `./install-brew.sh` -3. Install tools: `brew bundle install --file=brew/Brewfile` -4. Install optional tools: `brew/install-extra.sh [--casks]` -5. Install everything else, including symlinks: `./install.sh` +MacOS is my primary work environment, hence Homebrew. This setup can be deployed on Linux too. I am aware of criticisms with Homebrew on Linux, but it fits my needs. Nix is being considered as an alternative. + +### Usage + +Run the interactive installer for Mac/Linux: `./install.sh` + +If you decline every prompt, it looks like this: + +``` +> ./install.sh +Install Homebrew? [Y/n] n +Install Homebrew packages? [Y/n] n +Install Nix? [Y/n] n +Install Nix packages? [Y/n] n +Set login shell? [Y/n] n +Create symlinks? [Y/n] n +Install vim plugins? [Y/n] n +``` + +These steps _should_ be executed in order. You can safely rerun a step if needed; it tries to be idempotent. Backups are created if you have existing configs that would be overwritten. Definitely do not create symlinks until you have installed the [required](brew/Brewfile) packages (the config files depend on them). diff --git a/brew/Brewfile b/brew/Brewfile index 4f13e1c..9c039c4 100644 --- a/brew/Brewfile +++ b/brew/Brewfile @@ -6,10 +6,6 @@ brew "diff-so-fancy" brew "fd" brew "fish" brew "fzf" -brew "gawk" -brew "git" brew "neovim" brew "ripgrep" -brew "tldr" brew "tree" -brew "wget" diff --git a/brew/brews.txt b/brew/brews.txt index e609c4b..cfb5c5e 100644 --- a/brew/brews.txt +++ b/brew/brews.txt @@ -12,7 +12,9 @@ dungeon elvish fortune fzy +gawk gcc +git gitup go gradle @@ -55,6 +57,7 @@ syncthing telnet termtosvg tig +tldr triangle tmux ttyd @@ -63,6 +66,7 @@ unrtf up vitetris watch +wget yq zeek zsxd diff --git a/fish/config.fish b/fish/config.fish index a9a9e07..93f17f2 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -72,6 +72,11 @@ if test -x /home/linuxbrew/.linuxbrew/bin/brew eval (/home/linuxbrew/.linuxbrew/bin/brew shellenv) end +# Nix package manager +if test -f ~/.nix-profile/etc/profile.d/nix.sh + functions -q fenv && fenv source ~/.nix-profile/etc/profile.d/nix.sh +end + # Cheatsheet widget (Ctrl+G) if command -q navi navi widget fish | source diff --git a/install-brew.sh b/install-brew.sh deleted file mode 100755 index b374783..0000000 --- a/install-brew.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Check if Homebrew is already installed -if [ -x "$(command -v brew)" ]; then - echo "Homebrew is already installed." - exit 0 -fi - -# Install Homebrew -case "$(uname -s)" in - Darwin|Linux) - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" - ;; - *) - echo "Unsupported kernel: $(uname -s)" - ;; -esac diff --git a/install.sh b/install.sh index a95034b..c663888 100755 --- a/install.sh +++ b/install.sh @@ -1,22 +1,28 @@ #!/bin/bash -DOTFILES="$HOME/dotfiles" +DOTFILES=$(cd "$(dirname "$0")" && pwd) -# Install symlinks -"$DOTFILES/install-symlinks.sh" +confirm() { + local prompt="$1 [Y/n] " -# Install plugin manager for Neovim, if it doesn't exist -VIM_PLUG_SRC="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" -VIM_PLUG_DST="$HOME/.local/share/nvim/site/autoload/plug.vim" -if [ ! -f "$VIM_PLUG_DST" ]; then - echo "Downloading plug.vim ..." - curl -fsSL -o "$VIM_PLUG_DST" --create-dirs "$VIM_PLUG_SRC" -fi + while true; do + read -e -p "$prompt" yn + case "$yn" in + "" ) return 0;; # default is yes + [Yy]* ) return 0;; + [Nn]* ) return 1;; + * ) ;; # wait for yes or no + esac + done +} -# Install plugins for Neovim -nvim +PlugInstall +qall +# Install tools +confirm "Install Homebrew?" && "$DOTFILES/install/install-brew.sh" +confirm "Install Homebrew packages?" && "$DOTFILES/install/install-brew-packages.sh" +confirm "Install Nix?" && "$DOTFILES/install/install-nix.sh" +confirm "Install Nix packages?" && "$DOTFILES/install/install-nix-packages.sh" -# Make fish the default shell -BREW_PREFIX=$(brew --prefix) -grep -q "$BREW_PREFIX/bin/fish" /etc/shells || echo "$BREW_PREFIX/bin/fish" | sudo tee -a /etc/shells -sudo chsh -s "$BREW_PREFIX/bin/fish" $(whoami) +# Extra steps +confirm "Set login shell?" && "$DOTFILES/install/install-shell.sh" +confirm "Create symlinks?" && "$DOTFILES/install/install-symlinks.sh" +confirm "Install vim plugins?" && "$DOTFILES/install/install-vim-plugins.sh" diff --git a/install/install-brew-packages.sh b/install/install-brew-packages.sh new file mode 100755 index 0000000..73ab865 --- /dev/null +++ b/install/install-brew-packages.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +echo "***** INSTALL HOMEBREW PACKAGES *****" + +DOTFILES=$(cd "$(dirname "$0")/.." && pwd) + +# Install required tools +brew bundle install --file="$DOTFILES/brew/Brewfile" + +# Install optional tools (prompted by fzf) +"$DOTFILES/brew/install-extra.fish" + +echo diff --git a/install/install-brew.sh b/install/install-brew.sh new file mode 100755 index 0000000..fae9a3a --- /dev/null +++ b/install/install-brew.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "***** INSTALL HOMEBREW *****" + +if [ -x "$(command -v brew)" ]; then + echo "Homebrew is already installed." +else + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" +fi + +echo diff --git a/install/install-nix-packages.sh b/install/install-nix-packages.sh new file mode 100755 index 0000000..402850f --- /dev/null +++ b/install/install-nix-packages.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +echo "***** INSTALL NIX PACKAGES *****" + +NIX_ENV="$HOME/.nix-profile/bin/nix-env" + +if [ -x "$NIX_ENV" ]; then + "$NIX_ENV" -iA nixpkgs.bat + "$NIX_ENV" -iA nixpkgs.fd + "$NIX_ENV" -iA nixpkgs.fish + "$NIX_ENV" -iA nixpkgs.neovim + "$NIX_ENV" -iA nixpkgs.ripgrep + "$NIX_ENV" -iA nixpkgs.tree + "$NIX_ENV" -iA nixpkgs.gitAndTools.diff-so-fancy +else + echo "Cannot install Nix packages! $NIX_ENV is not executable." +fi + +echo diff --git a/install/install-nix.sh b/install/install-nix.sh new file mode 100755 index 0000000..aec2b0b --- /dev/null +++ b/install/install-nix.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "***** INSTALL NIX *****" + +if [ -d /nix ]; then + echo "Nix is already installed." +else + /bin/bash -c "$(curl -fsSL https://nixos.org/nix/install) --no-daemon" +fi + +echo diff --git a/install/install-shell.sh b/install/install-shell.sh new file mode 100755 index 0000000..acf1c11 --- /dev/null +++ b/install/install-shell.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +echo "***** INSTALL SHELL *****" + +SHELL_PATH='/usr/local/bin/fish' + +if [ ! -x "$SHELL_PATH" ]; then + echo "Cannot set login shell! $SHELL_PATH is not executable." + exit 1 +fi + +if [ "$SHELL" = "$SHELL_PATH" ]; then + echo "$SHELL_PATH is already the login shell." +else + echo "Setting the login shell to $SHELL_PATH ..." + grep -q "$SHELL_PATH" /etc/shells || echo "$SHELL_PATH" | sudo tee -a /etc/shells + sudo chsh -s "$SHELL_PATH" $(whoami) +fi + +echo diff --git a/install-symlinks.sh b/install/install-symlinks.sh similarity index 88% rename from install-symlinks.sh rename to install/install-symlinks.sh index e9a14b1..4666383 100755 --- a/install-symlinks.sh +++ b/install/install-symlinks.sh @@ -1,6 +1,8 @@ #!/bin/bash -DOTFILES="$HOME/dotfiles" +echo "***** INSTALL SYMLINKS *****" + +DOTFILES=$(cd "$(dirname "$0")/.." && pwd) backup_existing() { if [ -e "$1" ]; then @@ -24,3 +26,5 @@ ln -fsv "$DOTFILES/bash/.bashrc" "$HOME/.bashrc" # Bash does not support XDG con ln -fsv "$DOTFILES/fish" "$HOME/.config" ln -fsv "$DOTFILES/nvim" "$HOME/.config" ln -fsv "$DOTFILES/git" "$HOME/.config" + +echo diff --git a/install/install-vim-plugins.sh b/install/install-vim-plugins.sh new file mode 100755 index 0000000..b94ce30 --- /dev/null +++ b/install/install-vim-plugins.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +echo "***** INSTALL VIM PLUGINS *****" + +VIM_PLUG="$HOME/.local/share/nvim/site/autoload/plug.vim" + +if [ -f "$VIM_PLUG" ]; then + echo "Updating vim plugin manager..." + echo "Updating vim plugins..." + nvim +PlugUpgrade +PlugUpdate +qall +else + echo "Installing vim plugin manager..." + curl -fsSL -o "$VIM_PLUG" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + echo "Installing vim plugins..." + nvim +PlugInstall +qall +fi + +echo