install: break up files, add nix

This commit is contained in:
Charles Gould 2020-06-01 02:29:09 -05:00
parent c381dc1228
commit 4a00ab548c
13 changed files with 157 additions and 46 deletions

View File

@ -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` 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.
2. Install [Homebrew](https://brew.sh/): `./install-brew.sh`
3. Install tools: `brew bundle install --file=brew/Brewfile` ### Usage
4. Install optional tools: `brew/install-extra.sh [--casks]`
5. Install everything else, including symlinks: `./install.sh` 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).

View File

@ -6,10 +6,6 @@ brew "diff-so-fancy"
brew "fd" brew "fd"
brew "fish" brew "fish"
brew "fzf" brew "fzf"
brew "gawk"
brew "git"
brew "neovim" brew "neovim"
brew "ripgrep" brew "ripgrep"
brew "tldr"
brew "tree" brew "tree"
brew "wget"

View File

@ -12,7 +12,9 @@ dungeon
elvish elvish
fortune fortune
fzy fzy
gawk
gcc gcc
git
gitup gitup
go go
gradle gradle
@ -55,6 +57,7 @@ syncthing
telnet telnet
termtosvg termtosvg
tig tig
tldr
triangle triangle
tmux tmux
ttyd ttyd
@ -63,6 +66,7 @@ unrtf
up up
vitetris vitetris
watch watch
wget
yq yq
zeek zeek
zsxd zsxd

View File

@ -72,6 +72,11 @@ if test -x /home/linuxbrew/.linuxbrew/bin/brew
eval (/home/linuxbrew/.linuxbrew/bin/brew shellenv) eval (/home/linuxbrew/.linuxbrew/bin/brew shellenv)
end 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) # Cheatsheet widget (Ctrl+G)
if command -q navi if command -q navi
navi widget fish | source navi widget fish | source

View File

@ -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

View File

@ -1,22 +1,28 @@
#!/bin/bash #!/bin/bash
DOTFILES="$HOME/dotfiles" DOTFILES=$(cd "$(dirname "$0")" && pwd)
# Install symlinks confirm() {
"$DOTFILES/install-symlinks.sh" local prompt="$1 [Y/n] "
# Install plugin manager for Neovim, if it doesn't exist while true; do
VIM_PLUG_SRC="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" read -e -p "$prompt" yn
VIM_PLUG_DST="$HOME/.local/share/nvim/site/autoload/plug.vim" case "$yn" in
if [ ! -f "$VIM_PLUG_DST" ]; then "" ) return 0;; # default is yes
echo "Downloading plug.vim ..." [Yy]* ) return 0;;
curl -fsSL -o "$VIM_PLUG_DST" --create-dirs "$VIM_PLUG_SRC" [Nn]* ) return 1;;
fi * ) ;; # wait for yes or no
esac
done
}
# Install plugins for Neovim # Install tools
nvim +PlugInstall +qall 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 # Extra steps
BREW_PREFIX=$(brew --prefix) confirm "Set login shell?" && "$DOTFILES/install/install-shell.sh"
grep -q "$BREW_PREFIX/bin/fish" /etc/shells || echo "$BREW_PREFIX/bin/fish" | sudo tee -a /etc/shells confirm "Create symlinks?" && "$DOTFILES/install/install-symlinks.sh"
sudo chsh -s "$BREW_PREFIX/bin/fish" $(whoami) confirm "Install vim plugins?" && "$DOTFILES/install/install-vim-plugins.sh"

View File

@ -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

11
install/install-brew.sh Executable file
View File

@ -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

19
install/install-nix-packages.sh Executable file
View File

@ -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

11
install/install-nix.sh Executable file
View File

@ -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

20
install/install-shell.sh Executable file
View File

@ -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

View File

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
DOTFILES="$HOME/dotfiles" echo "***** INSTALL SYMLINKS *****"
DOTFILES=$(cd "$(dirname "$0")/.." && pwd)
backup_existing() { backup_existing() {
if [ -e "$1" ]; then 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/fish" "$HOME/.config"
ln -fsv "$DOTFILES/nvim" "$HOME/.config" ln -fsv "$DOTFILES/nvim" "$HOME/.config"
ln -fsv "$DOTFILES/git" "$HOME/.config" ln -fsv "$DOTFILES/git" "$HOME/.config"
echo

18
install/install-vim-plugins.sh Executable file
View File

@ -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