Commit 56063910 authored by Naoki OKAMURA's avatar Naoki OKAMURA

improved: remove zplug dependence from zsh files

parent 40be9359
#!/usr/bin/env zsh
# NixOS and nixpkgs
# -----------------
if type nixos-rebuild 2>&1 >/dev/null ; then
if test -e /etc/nixpkgs ; then
alias nixos-apply="sudo nixos-rebuild -I nixpkgs=/etc/nixpkgs switch"
alias nixos-upgrade="sudo nixos-rebuild -I nixpkgs=/etc/nixpkgs boot"
else
alias nixos-apply="sudo nixos-rebuild switch"
alias nixos-upgrade="sudo nixos-rebuild boot"
fi
fi
if type nix-env 2>&1 >/dev/null ; then
if test -e /etc/nixpkgs ; then
alias nix-build="nix-build -I nixpkgs=/etc/nixpkgs"
alias nix-env="nix-env -I nixpkgs=/etc/nixpkgs"
alias nix-shell="nix-shell -I nixpkgs=/etc/nixpkgs"
alias nix-search="nix search -I nixpkgs=/etc/nixpkgs"
else
alias nix-search="nix search"
fi
fi
function nix-clean() {
nix-store --gc
if test -e /etc/nixos ; then
sudo nix-store --gc
fi
if test -e /etc/nixos ; then
sudo nix-collect-garbage -d
sudo /run/current-system/bin/switch-to-configuration boot
fi
}
# Aliases
# -------
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
linux | *_nt-* )
alias ls="ls --color -F"
;;
darwin)
alias ls="ls -GF"
;;
esac
if type fzy 2>&1 >/dev/null; then
function fzy-history() {
BUFFER="$(fc -l -n 1 | sort | uniq | fzy --query "${LBUFFER}")"
CURSOR=$#BUFFER
zle -R -c
}
zle -N fzy-history
bindkey '^R' fzy-history
fi
#!/usr/bin/env bash
# Prepare Auto-onstall
# --------------------
if test -d /etc/nixos ; then
export DOTFILES=/etc/nixos/dotfiles/nyarla
fi
if test -z "${DOTFILES:-}" ; then
export DOTFILES="$HOME"/local/dotfiles/dotfiles/nyarla
fi
if ! test -d $DOTFILES/../../.git ; then
cd $DOTFILES/../../
git init
git remote add origin git@gitlab.com:nyarla/nixos-configurations.git
git pull origin master
fi
# NPM (Node.js)
# -------------
if type npm 2>&1 >/dev/null ; then
test -d "$HOME"/.config/npm || mkdir -p "$HOME"/.config/npm
if test "$(npm config get prefix)" != "${HOME}/.config/npm" ; then
npm config set prefix "${HOME}/.config/npm"
fi
test -x $HOME/.config/npm/bin/bash-language-server || npm install -g bash-language-server
test -x $HOME/.config/npm/bin/docker-langserver || npm install -g dockerfile-language-server-nodejs
test -x $HOME/.config/npm/bin/typescript-language-server || npm install -g typescript-language-server
test -x $HOME/.config/npm/bin/vscode-css-languageserver || npm install -g vscocde-css-languageserver-bin
test -x $HOME/.config/npm/bin/vscode-json-languageserver || npm install -g vscode-json-languageserver
fi
# Git
# ---
test -e $HOME/.gitconfig || ln -s $DOTFILES/git/gitconfig $HOME/.gitconfig
test -e $HOME/.gitignore || ln -s $DOTFILES/git/gitignore $HOME/.gitignore
# TMUX
# ----
test -e $HOME/.tmux.conf || ln -s $DOTFILES/tmux/tmux.conf $HOME/.tmux.conf
# Vim
# ---
if ! test -d "$HOME"/.vim.d ; then
mkdir -p "$HOME"/.vim.d/{backup,swap}
fi
test -e $HOME/.config/vim-volt || ln -sf $DOTFILES/volt $HOME/.config/vim-volt
### FIXME: auto install for vim plugins
# MLTerm
# ------
test -d $HOME/.mlterm || mkdir -p $HOME/.mlterm
test -e $HOME/.mlterm/color || ln -s $DOTFILES/mlterm/color $HOME/.mlterm/color
test -e $HOME/.mlterm/key || ln -s $DOTFILES/mlterm/key $HOME/.mlterm/key
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
darwin)
test -e $HOME/.mlterm/main || ln -s $DOTFILES/mlterm/main.macOS $HOME/.mlterm/main
test -e $HOME/.mlterm/aafont || ln -s $DOTFILES/mlterm/aafont.macOS $HOME/.mlterm/aafont
;;
*)
test -e $HOME/.mlterm/main || ln -s $DOTFILES/mlterm/main $HOME/.mlterm/main
test -e $HOME/.mlterm/aafont || ln -s $DOTFILES/mlterm/aafont $HOME/.mlterm/aafont
;;
esac
# Post Auto-install
# -----------------
unset DOTFILES
#!/usr/bin/env zsh
# Golang
# ------
export GOPATH="$HOME"/dev
if ! test -d "$GOPATH"/bin ; then
mkdir -p "$GOPATH"/bin
fi
export PATH="$GOPATH"/bin:$PATH
# NPM (Node.js)
# -------------
if ! test -d "$HOME"/.config/npm/bin ; then
mkdir -p "$HOME"/.config/npm/bin
fi
export PATH="$HOME"/.config/npm/bin:$PATH
# Rust
# ----
if test -e "$HOME"/.cargo/env ; then
source "$HOME"/.cargo/env
fi
# Perl
# ----
#if test -d "$HOME"/.config/perl5 ; then
# eval "$(perl -I "$HOME"/.config/perl5/lib/perl5 -Mlocal::lib="$HOME"/.config/perl5)"
# export PATH="$HOME"/.config/perl5/bin:$PATH
#fi
# Keychain
# --------
if type keychain 2>&1 >/dev/null && test -d "$HOME"/.ssh/id_ed25519 ; then
keychain --nogui --quiet $HOME/.ssh/id_ed25519
source "$HOME"/.keychain/$(hostname)-sh
fi
# Vim8 with Volt
# --------------
if type volt 2>&1 >/dev/null ; then
export VOLTPATH=$HOME/.config/vim-volt
fi
# Anyenv
# ------
if test -e $HOME/.anyenv/bin ; then
export PATH="$HOME"/.anyenv/bin:$PATH
eval "$(anyenv init -)"
fi
# Machine-local scripts
# ---------------------
if ! test -d "$HOME"/local/bin ; then
mkdir -p "$HOME"/local/bin
fi
export PATH="$HOME"/local/bin:$PATH
# Cleanup
# -------
path=(${^path}(N-/^W))
#!/usr/bin/env zsh
# ZSH Options
# -----------
setopt autocd
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushd_to_home
setopt hist_ignore_dups
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt hist_reduce_blanks
setopt hist_find_no_dups
setopt share_history
export HISTFILE=$HOME/.zsh_history
export HISTSIZE=1024
export SAVEHIST=1024
#!/usr/bin/env zsh
# Kernel
# ------
case "$(uname -r | tr '[:upper:]' '[:lower:]')" in
*-microsoft )
unsetopt BG_NICE
umask 022
;;
esac
# Platform
# --------
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
*_nt-* )
alias exit="sh -c \"cmd /C 'taskkill /F /T /PID $(cat /proc/$$/winpid)'\""
trap 'sh -c "cmd /C \"taskkill /F /T /PID $(cat /proc/$$/winpid)\""' 1 2 3 15
;;
esac
#!/usr/bin/env zsh
# zprofile (for login)
# ====================
CWD="$(pwd)"
function has() {
type ${1:-} 2>&1 >/dev/null
}
# wcwidth-cjk (for cjk)
# --------------------
if has wcwidth-cjk && has wcwidth; then
if test "$(wcwidth '○' | cut -d' ' -f1)" = "1" ; then
exec wcwidth-cjk $SHELL --login
fi
fi
# keychain (for ssh and mosh)
# ---------------------------
if has keychain ; then
keychain --nogui --quiet "$HOME"/.ssh/id_ed25519
source "$HOME"/.keychain/$(hostname)-sh
fi
# auto install (dotfiles)
# -----------------------
! test -d /etc/nixos || export DOTFILES=/etc/nixos/dotfiles/nyarla
! test -z "${DOTFILES:-}" || export DOTFILES="$HOME"/local/dotfiles/dotfiles/nyarla
if ! test -d $DOTFILES/../../.git ; then
cd $DOTFILES/../../.git
git init
git remote add origin git@gitlab.com:nyarla/nixos-configurations.git
git pull origin master
fi
if has npm; then
if ! test -d "$HOME"/.config/npm ; then
mkdir -p "$HOME"/.config/npm
npm config set prefix "$HOME"/.config/npm
npm install -g \
bash-language-server \
dockerfile-language-server \
typescript-language-server \
vscode-css-languageserver \
vscode-json-languageserver \
;
fi
fi
test -e "$HOME"/.gitignore || ln -sf "$DOTFILES"/git/gitignore "$HOME"/.gitignore
test -e "$HOME"/.gitconfig || ln -sd "$DOTFILES"/git/gitconfig "$HOME"/.gitconfig
test -e "$HOME"/.tmux.conf || ln -sf "$DOTFILES"/ "$HOME"/.tmux.conf
test -d "$HOME"/.vim.d || mkdir -p "$HOME"/.vim.d/{backup,swap}
test -e "$HOME"/.config/vim-volt || ln -sf "$DOTFILES"/volt "$HOME"/.config/vim-volt
# TODO: auto install vim plugins by vim-volt
test -d "$HOME"/.mlterm || mkdir -p "$HOME"/.mlterm
test -e "$HOME"/.mlterm/color || ln -sf "$DOTFILES"/mlterm/color "$HOME"/.mlterm/color
test -e "$HOME"/.mlterm/key || ln -sf "$DOTFILES"/mlterm/key "$HOME"/.mlterm/key
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
darwin)
test -e "$HOME"/.mlterm/main || ln -sf "$DOTFILES"/mlterm/main.macOS "$HOME"/.mlterm/main
test -e "$HOME"/.mlterm/aafont || ln -sf "$DOTFILES"/mlterm/aafont.macOS "$HOME"/.mlterm/aafont
;;
*)
test -e "$HOME"/.mlterm/main || ln -sf "$DOTFILES"/mlterm/main "$HOME"/.mlterm/main
test -e "$HOME"/.mlterm/aafont || ln -sf "$DOTFILES"/mlterm/aafont "$HOME"/.mlterm/aafont
;;
esac
# auto install (zsh plugins)
# --------------------------
test -d "$HOME"/.config/zsh || mkdir -p "$HOME"/.config/zsh
cd "$HOME"/.config/zsh
test -d enhancd || git clone https://github.com/b4b4r07/enhancd
test -d pure || git clone https://github.com/sindresorhus/pure
test -d "$HOME"/local/zfunctions || mkdir -p "$HOME"/local/zfunctions
test -e "$HOME"/local/zfunctions/async || ln -sf "$HOME"/.config/zsh/pure/async.zsh "$HOME"/local/zfunctions/async
test -e "$HOME"/local/zfunctions/prompt_pure_setup || ln -sf "$HOME"/.config/zsh/pure/pure.zsh "$HOME"/local/zfunctions/prompt_pure_setup
cd $CWD
unset CWD
unset DOTFILES
unset -f has
#!/usr/bin/env zsh
# zshenv (for login, interactive or shell script)
# ===========================================
# Go
# --
export GOPATH="$HOME"/dev
! test -d "$GOPATH"/bin || export PATH="$GOPATH"/bin:$PATH
# Node.js (npm)
# -------------
! test -d "$HOME"/.config/npm/bin || export PATH="$HOME"/.config/npm/bin:$PATH
# Rust (cargo)
# ------------
! test -d "$HOME"/.cargo/env || source "$HOME"/.cargo/env
# Volt (vim plugin manager)
# -------------------------
! test -e"$HOME"/.config/vim-volt || export VOLTPATH="$HOME"/.config/vim-volt
# Scripts (on local machine)
# --------------------------
! test -d "$HOME"/local/bin || export PATH="$HOME"/local/bin:$PATH
# cleanup (PATH)
# --------------
path=(${^path}(N-/^W))
#!/usr/bin/env zsh
# Preload
# -------
if type wcwidth-cjk 2>&1 >/dev/null ; then
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
linux)
if ! [[ "${LD_PRELOAD:-}" =~ .*wcwidth-cjk.* ]]; then
exec wcwidth-cjk $SHELL
fi
;;
darwin)
if ! [[ "${DYLD_INSERT_LIBRARIES:-}" =~ .*wcwidth-cjk.* ]]; then
exec wcwidth-cjk $SHELL
fi
;;
esac
fi
function has() {
type ${1:-} 2>&1 >/dev/null
}
# ZPlug
# -----
export ZPLUG_HOME="$HOME"/.config/zplug
if ! test -d $ZPLUG_HOME ; then
test -d "$HOME"/.config || mkdir -p "$HOME"/.config
git clone https://github.com/zplug/zplug $ZPLUG_HOME
fi
# zshrc (for login or interactive)
# ================================
# zsh options
# -----------
setopt autocd
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushd_to_home
if test -e $ZPLUG_HOME/init.zsh ; then
source $ZPLUG_HOME/init.zsh
setopt hist_ignore_dups
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
setopt hist_find_no_dups
setopt share_history
zplug "b4b4r07/enhancd", use:"init.sh"
test "${HISTFILE:-}" != "" || export HISTFILE="$HOME"/.zsh_history
test "${HISTSIZE:-}" != "" || export HISTSIZE=1024
test "${SAVEHIST:-}" != "" || export SAVEHIST=1024
zplug "mafredri/zsh-async"
zplug "sindresorhus/pure"
# nix and nixos
# -------------
if test -e /etc/nixos ; then
export DOTFILES=/etc/nixos/dotfiles/nyarla
if has nix-env ; then
if test -d /etc/nixpkgs ; then
alias nix-build="nix-build -I nixpkgs=/etc/nixpkgs"
alias nix-env="nix-env -I nixpkgs=/etc/nixpkgs"
alias nix-shell="nix-shell -I nixpkgs=/etc/nixpkgs"
alias nix-search="nix search -I nixpkgs=/etc/nixpkgs"
if has nixos-rebuild ; then
alias nixos-apply="sudo nixos-rebuild -I nixpkgs=/etc/nixpkgs switch"
alias nixos-upgrade="sudo nixos-rebuild -I nixpkgs=/etc/nixpkgs boot"
fi
else
export DOTFILES=$HOME/local/dotfiles/dotfiles/nyarla
zplug "zsh-users/zsh-syntax-highlighting", defer:2
zplug "zsh-users/zsh-completions", defer:2
fi
alias nix-search"nix search"
zplug "$DOTFILES"/zsh, from:"local", use:"*.plugin.zsh"
if has nixos-rebuild ; then
alias nixos-apply="sudo nixos-rebuild switch"
alias nixos-upgrade="sudo nixos-rebuild boot"
fi
fi
if ! zplug check ; then
zplug install
if has nixos-rebuild ; then
function nix-clean() {
nix-store --gc
sudo nix-store --gc
sudo nix-collect-garbage -d
sudo /run/current-system/bin/switch-to-configuration boot
}
else
alias nix-clean="nix-store --gc"
fi
zplug load
function nix-prepare() {
cd "$HOME"/local/files \
&& find . -type f '*.*' | xargs -I{} nix-prefetch-url "file://$HOME/local/files/{}"
}
fi
# command-specific
# ----------------
if has fzy ; then
function fzy-history() {
BUFFER="$(fc -l -n 1 | sort | uniq | fzy --query "${LBUFFER}")"
CURSOR=$#BUFFER
zle -R -c
}
zle -N fzy-history
bindkey '^R' fzy-history
fi
# os-specific
# -----------
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
linux)
alias ls="ls --color -F"
;;
darwin)
alias ls="ls -GF"
;;
*_nt-*)
alias ls="ls -GF"
# workaround for WSL1
# unsetopt BG_NICE
# umask 022
# alias exit="sh -c \"cmd /C 'taskkill /F /T /PID $(cat /proc/$$/winpid)'\""
# trap 'sh -c "cmd /C \"taskkill /F /T /PID $(cat /proc/$$/winpid)\""' 1 2 3 15
;;
esac
# init (zsh plugins)
# ------------------
! test -e "$HOME"/.config/zsh/enhancd/init.sh || source "$HOME"/.config/zsh/enhancd/init.sh
if test -e "$HOME"/local/zfunctions ; then
fpath=("$HOME"/local/zfunctions $fpath)
autoload -U promptinit; promptinit
prompt pure
fi
# finalize
# --------
if ! test -z "${__INIT_CWD:-}" ; then
cd $__INIT_CWD
unset __INIT_CWD
fi
unset -f has
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