diff --git a/.gitignore b/.gitignore index 9df3bb19..6971a961 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,10 @@ /config/.config/karabiner/* !/config/.config/karabiner/karabiner.json +# zsh +/config/.config/zsh/.chpwd-recent-dirs +/config/.config/zsh/.zcompdump +/config/.config/zsh/.zsh_history + # Nix /result diff --git a/bin/deploy-config-files b/bin/deploy-config-files index f9363c27..5fa84e22 100755 --- a/bin/deploy-config-files +++ b/bin/deploy-config-files @@ -13,8 +13,8 @@ mkdir -p ~/.config ./bin/ln-idempotently ./config/.config/gh ~/.config/gh # zsh -mkdir -p ~/.config/zsh -./bin/ln-idempotently ./config/.config/zsh/legacy ~/.config/zsh/legacy +./bin/ln-idempotently ./config/.zshenv ~/.zshenv +./bin/ln-idempotently ./config/.config/zsh ~/.config/zsh ./bin/ln-idempotently ./config/.config/starship.toml ~/.config/starship.toml # vim @@ -32,9 +32,3 @@ mkdir -p ~/.config/tmux # ripgrep ./bin/ln-idempotently ./config/.ripgreprc ~/.ripgreprc - -if [ "${CODESPACES:-"false"}" = "true" ]; then - # overwrite default zsh configurations - cp ./codespaces/config/.zshrc ~/.zshrc - cp ./codespaces/config/.zshenv ~/.zshenv -fi diff --git a/codespaces/config/.zshenv b/codespaces/config/.zshenv deleted file mode 100644 index 0e1b788f..00000000 --- a/codespaces/config/.zshenv +++ /dev/null @@ -1 +0,0 @@ -source $HOME/.config/zsh/legacy/.zshenv diff --git a/codespaces/config/.zshrc b/codespaces/config/.zshrc deleted file mode 100644 index 50a31bbd..00000000 --- a/codespaces/config/.zshrc +++ /dev/null @@ -1 +0,0 @@ -source $HOME/.config/zsh/legacy/.zshrc diff --git a/config/.config/zsh/.zshrc b/config/.config/zsh/.zshrc new file mode 100644 index 00000000..e749bb89 --- /dev/null +++ b/config/.config/zsh/.zshrc @@ -0,0 +1,89 @@ +source $HOME/.config/zsh/legacy/exports.zsh +source $HOME/.config/zsh/legacy/aliases.zsh + +bindkey -e # emacs emulation +autoload -Uz add-zsh-hook + +ulimit -u 2048 +ulimit -n 16384 + +# Zsh options +# ================================================================ +REPORTTIME=3 + +setopt correct +setopt interactive_comments +setopt extended_glob + +# ---- Histroy ---- +HISTFILE="${ZDOTDIR}/.zsh_history" +HISTSIZE=10000 # メモリに保存される履歴の件数 +SAVEHIST=1000000 # 保存される履歴の件数 +# https://github.com/rothgar/mastering-zsh/blob/921766e642bcf02d0f1be8fc57d0159a867299b0/docs/config/history.md +setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format. +setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. +setopt SHARE_HISTORY # Share history between all sessions. +setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history. +setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again. +setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate. +setopt HIST_FIND_NO_DUPS # Do not display a previously found event. +setopt HIST_IGNORE_SPACE # Do not record an event starting with a space. +setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file. +setopt HIST_VERIFY # Do not execute immediately upon history expansion. +setopt APPEND_HISTORY # append to history file +setopt HIST_NO_STORE # Don't store history commands + +autoload -Uz chpwd_recent_dirs cdr add-zsh-hook +add-zsh-hook chpwd chpwd_recent_dirs +zstyle ':chpwd:*' recent-dirs-max 5000 +zstyle ':chpwd:*' recent-dirs-default yes +zstyle ':chpwd:*' recent-dirs-prune 'parent' +zstyle ':completion:*' recent-dirs-insert both + +# cdしたあとで、自動的に ls する +function chpwd() { ls } + +# ---- Directory stack ---- +setopt auto_cd # ディレクトリ名を入力したら自動でcd +setopt auto_pushd # ディレクトリスタックに追加(`cd +`で履歴表示) +setopt pushd_ignore_dups # pushd時にすでにスタックに含まれてた場合は追加しない +DIRSTACKSIZE=100 # ディレクトリスタック保存件数 + +# ---- Completion ---- +if [ -d "$HOME/.nix-profile/share/zsh/site-functions" ]; then + fpath=($HOME/.nix-profile/share/zsh/site-functions $fpath) +fi + +setopt auto_menu # 補完候補が複数あるときに自動的に一覧表示 +bindkey "^[[Z" reverse-menu-complete # Shift-Tabで補完候補を逆順する("\e[Z"でも動作する) +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # 補完時に大文字小文字を区別しない + +autoload -Uz compinit; compinit -C + +# Load plugins +# ================================================================ +source $HOME/.config/zsh/legacy/functions.zsh +source $HOME/.config/zsh/legacy/fzf.zsh + +# direnv +if type direnv > /dev/null 2>&1; then + eval "$(direnv hook zsh)" +fi + +# fnm (Node.js) +if type fnm >/dev/null 2>&1; then + eval "$(fnm env --use-on-cd --log-level error)" +fi + +# 1Password +if [ -d "${HOME}/.config/op/plugins.sh" ]; then + source "${HOME}/.config/op/plugins.sh" +fi + +# Orbstack +if [ -f "${HOME}/.orbstack/shell/init.zsh" ]; then + source "${HOME}/.orbstack/shell/init.zsh" +fi + +# Starship +eval "$(starship init zsh)" diff --git a/config/.config/zsh/legacy/.zshenv b/config/.config/zsh/legacy/.zshenv deleted file mode 100644 index c0c7530b..00000000 --- a/config/.config/zsh/legacy/.zshenv +++ /dev/null @@ -1,60 +0,0 @@ -setopt no_global_rcs - -# homebrew -brewPrefix="" - -case "$(uname)" in - "Darwin") - if [ -d "/opt/homebrew" ]; then - brewPrefix="/opt/homebrew" - else - brewPrefix="/usr/local" - fi - ;; - "Linux") - brewPrefix="/home/linuxbrew/.linuxbrew" - if [ ! -d "$brewPrefix" ]; then - brewPrefix="/home/$USER/.linuxbrew" - fi -esac - -if [ -f "$brewPrefix/bin/brew" ]; then - eval $($brewPrefix/bin/brew shellenv) -fi - -source $HOME/.config/zsh/legacy/exports.zsh -source $HOME/.config/zsh/legacy/aliases.zsh - -# rbenv -if [ -d "${HOME}/.rbenv" ]; then - eval "$(rbenv init -)" -fi - -# pyenv -if [ -d "${HOME}/.pyenv" ]; then - eval "$(pyenv init -)" -fi - -if type fnm >/dev/null 2>&1; then - eval "$(fnm env --use-on-cd --log-level error)" -fi - -# jenv -if [ -d "${HOME}/.jenv" ]; then - eval "$(jenv init -)" -fi - -# direnv -if type direnv > /dev/null 2>&1; then - eval "$(direnv hook zsh)" -fi - -# rust -if [ -d "${HOME}/.cargo" ]; then - source $HOME/.cargo/env -fi - -# 1password -if [ -d "$HOME/.config/op/plugins.sh" ]; then - source $HOME/.config/op/plugins.sh -fi diff --git a/config/.config/zsh/legacy/.zshrc b/config/.config/zsh/legacy/.zshrc deleted file mode 100644 index 8ea0b1ba..00000000 --- a/config/.config/zsh/legacy/.zshrc +++ /dev/null @@ -1,81 +0,0 @@ -bindkey -e -autoload -Uz add-zsh-hook -source $HOME/.config/zsh/legacy/functions.zsh -source $HOME/.config/zsh/legacy/fzf.zsh - - -# ================================================================ -# オプション -# ================================================================ - -REPORTTIME=3 - -#### complement #### -fpath=($HOMEBREW_PREFIX/share/zsh/site-functions $fpath) # gitのbranch名補完 -autoload -Uz compinit; compinit -C # 補完機能を有効にする -setopt auto_menu # 補完候補が複数あるときに自動的に一覧表示 -bindkey "^[[Z" reverse-menu-complete # Shift-Tabで補完候補を逆順する("\e[Z"でも動作する) -zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # 補完時に大文字小文字を区別しない -zstyle ':completion:*:sudo:*' command-path $DEFAULT_PREFIX/sbin $DEFAULT_PREFIX/bin \ - /usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin # sudo の後ろでコマンド名を補完 -if [ -e $DEFAULT_PREFIX/share/zsh-completions ]; then - fpath=($DEFAULT_PREFIX/share/zsh-completions $fpath) # zsh-completions有効化 -fi - - -#### history #### -HISTFILE=~/.zsh_history # 履歴の保存先 -HISTSIZE=1000000 # メモリに保存される履歴の件数 -SAVEHIST=1000000 # 保存される履歴の件数 -setopt hist_ignore_all_dups # コマンド履歴がダブってたら古い方を消す -setopt hist_ignore_space # スペースから始まるコマンドを履歴に追加しない -setopt hist_reduce_blanks # 履歴追加時に余分なスペースを削除 -setopt share_history # 同時に起動したzshの間で履歴共有 - -#### directory stack #### -setopt auto_pushd # ディレクトリスタックに追加(`cd +`で履歴表示) -setopt pushd_ignore_dups # pushd時にすでにスタックに含まれてた場合は追加しない -DIRSTACKSIZE=100 # ディレクトリスタック保存件数 - -#### cdr #### -autoload -Uz chpwd_recent_dirs cdr add-zsh-hook -add-zsh-hook chpwd chpwd_recent_dirs -zstyle ':chpwd:*' recent-dirs-max 5000 -zstyle ':chpwd:*' recent-dirs-default yes -zstyle ':completion:*' recent-dirs-insert both - -# 拡張globを有効化 -setopt extended_glob - -# ディレクトリ名を入力したら自動でcd -setopt auto_cd -# cdしたあとで、自動的に ls する -function chpwd() { ls } - -# コマンドが間違ってるときのサジェスト -setopt correct - -# '#' 以降をコメントとして扱う -setopt interactive_comments - -# ^R で履歴検索をするときに * でワイルドカードを使用出来るようにする -# bindkey '^R' history-incremental-pattern-search-backward - -ulimit -u 2048 -ulimit -n 16384 - -# ================================================================ -# プロファイリング結果出力 -# ================================================================ - -# if (which zprof > /dev/null) ;then - # zprof | less -# fi - -# added by travis gem -if [ -f /Users/izumin/.travis/travis.sh ]; then - source /Users/izumin/.travis/travis.sh -fi - -export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" -eval "$(starship init zsh)" diff --git a/config/.config/zsh/legacy/aliases.zsh b/config/.config/zsh/legacy/aliases.zsh index b5b1c542..f5e4aba5 100644 --- a/config/.config/zsh/legacy/aliases.zsh +++ b/config/.config/zsh/legacy/aliases.zsh @@ -7,19 +7,13 @@ fi alias history='history -E' alias mkdir='mkdir -p' -alias be='bundle exec' alias gsed=sed -# `hub` has implemented `pr` and `sync` subcommands. they are conflicted with self-defined commands. -# alias git='hub' - if [[ -x `which colordiff` ]]; then alias diff='colordiff -u' else alias diff='diff -u' fi -alias ew='envchain wtd' - alias mw="docker compose -f /Users/izumin/.bin/compose.mw.yaml" diff --git a/config/.config/zsh/legacy/exports.zsh b/config/.config/zsh/legacy/exports.zsh index 0d4ff3ba..779953e5 100644 --- a/config/.config/zsh/legacy/exports.zsh +++ b/config/.config/zsh/legacy/exports.zsh @@ -11,52 +11,23 @@ export TERM=xterm-256color # path # ================================================================ -export DEFAULT_PREFIX="${HOMEBREW_PREFIX:-"${HOME}/.local"}" - -if [ -n "$HOMEBREW_PREFIX" ]; then - export PATH=$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:${PATH} - export MANPATH=$HOMEBREW_PREFIX/opt/coreutils/libexec/gnuman:${MANPATH} -fi - -export PATH="${HOMEBREW_PREFIX}/bin:${PATH}" export PATH="${HOME}/.local/bin:${PATH}" export PATH="/usr/local/bin:${PATH}" +export PATH=$HOME/bin:$PATH +export PATH=$HOME/.bin:$PATH -# yarn -export PATH="$HOME/.config/yarn/global/node_modules/.bin:$PATH" -export PATH="$HOME/.yarn/bin:$PATH" - -# golang +# Go export GOPATH=$HOME export GOBIN=$GOPATH/gobin - -# rust -export PATH=$HOME/.cargo/bin:$PATH - -# android -export ANDROID_SDK_ROOT=$HOMEBREW_PREFIX/share/android-sdk -export ANDROID_SDK_TOOLS=$ANDROID_SDK_ROOT/tools -export ANDROID_SDK_PLATFORM_TOOLS=$ANDROID_SDK_ROOT/platform-tools -export ANDROID_HOME=$ANDROID_SDK_ROOT +export PATH=$GOBIN:$PATH # Rancher Desktop export PATH=$HOME/.rd/bin:$PATH -# path -export PATH=$HOME/bin:$PATH -export PATH=$HOME/.bin:$PATH -export PATH=$RBENV_ROOT/bin:$PATH -export PATH=$PYENV_ROOT/bin:$PATH -export PATH=$GOBIN:$PATH -export PATH=$ANDROID_SDK_TOOLS:$ANDROID_SDK_PLATFORM_TOOLS:$PATH -export PATH=$POSTGRESAPP_ROOT/bin:$PATH -# nix +# Nix export PATH=/nix/var/nix/profiles/default/bin:$PATH export PATH=$HOME/.nix-profile/bin:$PATH -# Tools in wantedly -export PATH=$HOME/.wantedly/bin:$PATH - # fzf export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border' export FZF_DEFAULT_OPTS=$FZF_DEFAULT_OPTS' @@ -79,4 +50,9 @@ case "$(uname)" in ;; esac +if [ -d "$HOME/.nix-profile/share/git/contrib/diff-highlight" ];then + export PATH="$HOME/.nix-profile/share/git/contrib/diff-highlight:$PATH" +fi + +# LayerX export GOPRIVATE=github.com/LayerXcom/ diff --git a/config/.zshenv b/config/.zshenv new file mode 100644 index 00000000..8a07740e --- /dev/null +++ b/config/.zshenv @@ -0,0 +1,3 @@ +setopt no_global_rcs # disable path helper + +export ZDOTDIR="${HOME}/.config/zsh" diff --git a/home.nix b/home.nix index 10dd6564..58e74e5d 100644 --- a/home.nix +++ b/home.nix @@ -35,8 +35,8 @@ pkgs.fnm # other langs - pkgs.ruby pkgs.php + pkgs.ruby # git pkgs.git @@ -48,6 +48,7 @@ pkgs.neovim # zsh + pkgs.zsh pkgs.sheldon # tmux @@ -119,18 +120,6 @@ }; programs= { - zsh = { - enable = true; - enableCompletion = true; - dotDir = ".config/zsh"; - initExtra = '' - source $HOME/.config/zsh/legacy/.zshrc - ''; - envExtra = '' - source $HOME/.config/zsh/legacy/.zshenv - PATH=${pkgs.git}/share/git/contrib/diff-highlight:$PATH - ''; - }; tmux = { enable = true; extraConfig = ''