Commit 3bf4925c authored by Naoki OKAMURA's avatar Naoki OKAMURA

improved: simplefied bootstrap script for zsh environment.

parent 56063910
#!/usr/bin/env bash
set -e -u -o pipefail
has() {
type $1 2>&1 >/dev/null
}
link() {
local from=$1 dest=$2
test -d "$(dirname "$dest")" || mkdir -p "$(dirname "$dest")"
test -e $dest || ln -s $from $dest
}
fetch() {
local url=$1 dest=$2
test -d "$(dirname "$dest")" || mkdir -p "$(dirname "$dest")"
test -e $dest || curl -o $dest -L $url
}
clone() {
local repo=$1 dest=$2
test -d "$(dirname "$dest")" || mkdir -p "$(dirname "$dest")"
test -e $dest || git clone $repo $dest
}
# tap
( brew tap | grep caskroom/cask ) || brew tap caskroom/cask
( brew tap | grep caskroom/versions ) || brew tap caskroom/versions
( brew tap | grep waltarix/customs ) || brew tap waltarix/customs
# pkgs
test -e /usr/local/bin/zsh || brew install zsh zsh-completions zsh-syntax-highlighting
test -e /usr/local/bin/tmux || brew install waltarix/customs/tmux
test -e /usr/local/bin/wcwidth-cjk || brew install waltarix/customs/wcwidth-cjk
test -e /usr/local/bin/gsed || brew install gnu-sed
test -e /usr/local/bin/gawk || brew install gawk
test -e /usr/local/bin/gmake || brew install make
test -e /usr/local/bin/keychain || brew install keychain
test -e /usr/local/bin/fzy || brew install fzy
test -e /usr/local/bin/restic || brew install restic
test -e /usr/local/bin/git || brew install git
test -e /usr/local/bin/hg || brew install mercurial
test -e /usr/local/bin/bzr || brew install bazaar
test -e /usr/local/bin/svn || brew install subversion
test -e /usr/local/bin/editorconfig || brew install editorconfig
test -e /usr/local/bin/go || brew install go
test -e /usr/local/bin/sassc || brew install sassc
test -e /usr/local/bin/node || brew install nodejs
test -e /usr/local/bin/yarn || brew install yarn
java -version || brew cask install java
test -e /usr/local/bin/scala || brew install scala
test -e /usr/local/bin/ocaml || brew install ocaml
test -e /usr/local/bin/opam || brew install opam
test -e /usr/local/bin/nim || brew install nim
test -e /usr/local/bin/syncthing || brew install syncthing syncthing-inotify
test -e /Applications/Firefox.app || brew cask install firefox
test -e /Applications/Dropbox.app || brew cask install dropbox
test -e /Applications/KeePassXC.app || brew cask install keepassxc
test -e /Applications/MacVim.app || brew cask install macvim
test -e /Applications/"IntelliJ IDEA CE".app || brew cask install intellij-idea-ce
# dotfiles
clone https://github.com/nyarla/nixos-configurations $HOME/local/dotfiles
cd $HOME/local/dotfiles/dotfiles/nyarla
# git
link `pwd`/git/gitconfig $HOME/.gitconfig
link `pwd`/git/gitignore $HOME/.gitignore
# Vim
link `pwd`/vim/init.vim $HOME/.vimrc
link `pwd`/vim/init.gvim $HOME/.gvimrc
link `pwd`/vim/init $HOME/.vim/userautoload/init
link `pwd`/vim/plugins $HOME/.vim/userautoload/plugins
test -d $HOME/.vim.d || (mkdir -p $HOME/.vim.d/swap; mkdir -p $HOME/.vim.d/backup )
fetch https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim $HOME/.vim/autoload/plug.vim
fetch https://raw.githubusercontent.com/hukl/Smyck-Color-Scheme/master/smyck.vim $HOME/.vim/colors/smyck.vim
# zsh
link `pwd`/zsh/init.zsh $HOME/.zshrc
fetch https://raw.githubusercontent.com/miekg/lean/master/prompt_lean_setup $HOME/.zfunctions/prompt_lean_setup
clone https://github.com/b4b4r07/enhancd $HOME/.enhancd
clone https://github.com/riywo/anyenv $HOME/.anyenv
# tmux
link `pwd`/tmux/tmux.conf $HOME/.tmux.conf
#!/usr/bin/env bash
# Functions
# =========
has() {
type "${1:-}" 2>&1 >/dev/null
}
pkg() {
pacman -S "${1:-}"
}
# Packages
# ========
has gcc || pkg msys2-devel
has make || pkg make
has git || pkg git
has curl || pkg curl
# Dotfiles
# ========
if test ! -d $HOME/local/dotfiles ; then
test -d $HOME/local || mkdir -p $HOME/local
git clone https://github.com/nyarla/nixos-configurations.git $HOME/local/dotfiles
fi
DOTFILES=$HOME/local/dotfiles/dotfiles/nyarla
# git
ln -sf $DOTFILES/git/gitconfig $HOME/.gitconfig
ln -sf $DOTFILES/git/gitignore $HOME/.gitignore
# vim
ln -sf $DOTFILES/vim/init.vim $HOME/.vimrc
ln -sf $DOTFILES/vim/init.gvim $HOME/.gvimrc
test -d $HOME/.vim/autoload || mkdir -p $HOME/.vim/autoload/
test -d $HOME/.vim/colors || mkdir -p $HOME/.vim/colors/
test -d $HOME/.vim/userautoload || mkdir -p $HOME/.vim/userautoload/
test -d $HOME/.vim.d/swap || mkdir -p $HOME/.vim.d/swap
test -d $HOME/.vim.d/backup || mkdir -p $HOME/.vim.d/backup
ln -sf $DOTFILES/vim/init $HOME/.vim/userautoload/init
ln -sf $DOTFILES/vim/plugins $HOME/.vim/userautoload/plugins
curl -L https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -o $HOME/.vim/autoload/plug.vim
curl -L https://raw.githubusercontent.com/hukl/Smyck-Color-Scheme/master/smyck.vim -o $HOME/.vim/colors/smyck.vim
# zsh
ln -sf $DOTFILES/zsh/bootstrap.zsh $HOME/.zshrc
test -d $HOME/.anyenv || git clone https://github.com/riywo/anyenv $HOME/.anyenv
# tmux
ln -sf $DOTFILES/tmux/tmux.conf $HOME/.tmux.conf
#!/usr/bin/env bash
# Functions
# =========
has() {
type "${1:-}" 2>&1 >/dev/null
}
# Toolchains
# ==========
if has npm ; then
test -d $HOME/.config/npm || mkdir -p $HOME/.config/npm
npm config set prefix $HOME/.config/npm
npm install -g \
bash-language-server \
dockerfile-language-server-nodejs \
purescript-language-server \
typescript-language-server \
vscode-css-languageserver-bin \
vscode-json-languageserver
fi
# Dotfiles
# ========
DOTFILES=/etc/nixos/dotfiles/nyarla
# git
ln -sf $DOTFILES/git/gitconfig $HOME/.gitconfig
ln -sf $DOTFILES/git/gitignore $HOME/.gitignore
# vim
if has go ; then
go get -u github.com/vim-volt/volt
cd $GOPATH/src/github.com/vim-volt/volt
make
mkdir -p $GOPATH/bin
cp bin/volt $GOPATH/bin/volt
fi
if has volt ; then
ln -sf $DOTFILES/volt $HOME/.config/vim-volt
volt get -u -l
volt build
fi
# zsh
ln -sf $DOTFILES/zsh/zshrc.zsh $HOME/.zshrc
# mlterm
test -d $HOME/.mlterm || mkdir -p $HOME/.mlterm
ln -sf $DOTFILES/mlterm/main $HOME/.mlterm/main
ln -sf $DOTFILES/mlterm/aafont $HOME/.mlterm/aafont
ln -sf $DOTFILES/mlterm/color $HOME/.mlterm/color
ln -sf $DOTFILES/mlterm/key $HOME/.mlterm/key
#!/usr/bin/env bash
has() {
type $1 2>&1 >/dev/null
}
pkg() {
local name=$1
sudo pacman -S $name
}
link() {
local from=$1 dest=$2
test -d "$(dirname "$dest")" || mkdir -p "$(dirname "$dest")"
test -e $dest || ln -s $from $dest
}
fetch() {
local url=$1 dest=$2
test -d "$(dirname "$dest")" || mkdir -p "$(dirname "$dest")"
test -e $dest || curl -o $dest -L $url
}
clone() {
local repo=$1 dest=$2
test -d "$(dirname "$dest")" || mkdir -p "$(dirname "$dest")"
test -e $dest || git clone $repo $dest
}
# pkgs
has git || pkg git
has zsh || pkg zsh
has fzy || pkg fzy
# dotfiles
clone https://github.com/nyarla/nixos-configurations $HOME/local/dotfiles
cd $HOME/local/dotfiles/dotfiles/nyarla
# git
link `pwd`/git/gitconfig $HOME/.gitconfig
link `pwd`/git/gitignore $HOME/.gitignore
# Vim
link `pwd`/vim/init.vim $HOME/.vimrc
link `pwd`/vim/init.gvim $HOME/.gvimrc
link `pwd`/vim/init $HOME/.vim/userautoload/init
link `pwd`/vim/plugins $HOME/.vim/userautoload/plugins
test -d $HOME/.vim.d || (mkdir -p $HOME/.vim.d/swap; mkdir -p $HOME/.vim.d/backup )
fetch https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim $HOME/.vim/autoload/plug.vim
fetch https://raw.githubusercontent.com/hukl/Smyck-Color-Scheme/master/smyck.vim $HOME/.vim/colors/smyck.vim
# ZSH
link `pwd`/zsh/init.zsh $HOME/.zshrc
fetch https://raw.githubusercontent.com/miekg/lean/master/prompt_lean_setup $HOME/.zfunctions/prompt_lean_setup
clone https://github.com/b4b4r07/enhancd $HOME/.enhancd
clone https://github.com/riywo/anyenv $HOME/.anyenv
# tmux
link `pwd`/tmux/tmux.conf $HOME/.tmux.conf
#!/usr/bin/env bash
set -e -u -o pipefail
cd $HOME
# Functions
# =========
has() {
type "${1:-}" 2>&1 >/dev/null
}
# WSL Host
# ========
sudo sed -i.bak -e "s%http://[^ ]\+%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g" /etc/apt/sources.list
sudo apt update
sudo apt upgrade -y
sudo apt install -y mlterm mlterm-im-fcitx fcitx fcitx-skk skkdic-cdb skkdic-extra skktools language-pack-ja dbus-x11
sudo update-locale LANG=ja_JP.UTF-8
if ! test -e $HOME/.nix-profile ; then
test -d /etc/nix || sudo mkdir -p /etc/nix
echo "use-sqlite-wal = false" | sudo tee /etc/nix/nix.conf
echo "sandbox = false" | sudo tee -a /etc/nix/nix.conf
has nix-env || curl https://nixos.org/nix/install | sh
fi
if ! test -e /etc/nixpkgs ; then
sudo mkdir -p /etc/nixpkgs
sudo chown nyarla:users /etc/nixpkgs
cd /etc/nixpkgs
git init
git remote add upstream https://github.com/NixOS/nixpkgs.git
git pull upstream master
cd $HOME
fi
if ! test -e /usr/share/fonts/nix-fonts ; then
ln -sf ~/.nix-profile/share/fonts /usr/share/fonts/nix-fonts
fi
cat <<... | sudo tee /etc/wsl.conf
[automount]
enabled = true
root = /
mountFsTab = true
options = "metadata,umask=22,fmask=11"
[network]
generateHosts = true
generateResolveConf = true
[interop]
enabled = true
appendWindowsPath = false
...
# Toolchains
# ==========
if has npm ; then
test -d $HOME/.config/npm || mkdir -p $HOME/.config/npm
npm config set prefix $HOME/.config/npm
npm install -g \
bash-language-server \
dockerfile-language-server-nodejs \
purescript-language-server \
typescript-language-server \
vscode-css-languageserver-bin \
vscode-json-languageserver \
js-beautify \
typescript-formatter \
fixjson
fi
if ! test -e $HOME/.cargo/env ; then
curl https://sh.rustup.rs -sSf | sh
fi
# Dotfiles
# ========
DOTFILES=$HOME/local/dotfiles/dotfiles/nyarla
# git
ln -sf $DOTFILES/git/gitconfig $HOME/.gitconfig
ln -sf $DOTFILES/git/gitignore $HOME/.gitignore
# vim
ln -sf $DOTFILES/vim/init.vim $HOME/.vimrc
ln -sf $DOTFILES/vim/init.gvim $HOME/.gvimrc
test -d $HOME/.config/nvim/autoload || mkdir -p $HOME/.config/nvim/autoload/
test -d $HOME/.config/nvim/colors || mkdir -p $HOME/.config/nvim/colors/
test -d $HOME/.nvim.d/swap || mkdir -p $HOME/.vim.d/swap
test -d $HOME/.vim.d/backup || mkdir -p $HOME/.vim.d/backup
ln -sf $DOTFILES/vim/init.vim $HOME/.config/nvim/init.vim
curl -L https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -o $HOME/.config/nvim/autoload/plug.vim
curl -L https://raw.githubusercontent.com/hukl/Smyck-Color-Scheme/master/smyck.vim -o $HOME/.config/nvim/colors/smyck.vim
# zsh
ln -sf $DOTFILES/zsh/bootstrap.zsh $HOME/.zshrc
# mlterm
test -d $HOME/.mlterm || mkdir -p $HOME/.mlterm
ln -sf $DOTFILES/mlterm/main $HOME/.mlterm/main
ln -sf $DOTFILES/mlterm/aafont $HOME/.mlterm/aafont
ln -sf $DOTFILES/mlterm/color $HOME/.mlterm/color
ln -sf $DOTFILES/mlterm/key $HOME/.mlterm/key
#!/usr/bin/env bash
# bootstrap zsh environment
# =========================
CWD=$(pwd)
! test -d /etc/nixos || export ROOTDIR=/etc/nixos
! test -z "${DOTFILES:-}" || export ROOTDIR="$HOME"/local/dotfiles
export DOTFILES="$ROOTDIR"/dotfiles/nyarla
if ! test -d "$ROOTDIR"/.git ; then
cd $ROOTDIR
git init
git remote add origin https://gitlab.com/nyarla/nixos-configurations.git
git pull origin master
cd $CWD
fi
cd "$HOME"
test -e "$HOME"/.zshrc || ln -sf "$DOTFILES"/zsh/zshrc.zsh "$HOME"/.zshrc
test -e "$HOME"/.zshenv || ln -sf "$DOTFILES"/zsh/zshenv.zsh "$HOME"/.zshenv
test -e "$HOME"/.zprofile || ln -sf "$DOTFILES"/zsh/zprofile.zsh "$HOME"/.zprofile
cd $CWD
unset CWD
unset ROOTDIR
unset DOTFILES
exec $SHELL -l
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment