From 87225864d38c103d2c1dbe9abe0cb05313f6057e Mon Sep 17 00:00:00 2001 From: ucpr Date: Sat, 9 Mar 2024 14:07:45 +0900 Subject: [PATCH] feat: use sheldon --- .gitignore | 1 + brew/Brewfile | 3 +- cli/lib/linkMap.ts | 6 ++ sheldon/plugins.toml | 44 ++++++++++++++ zsh/.zshrc | 74 ++++++++++------------- zsh/plugins/alias_lazy.zsh | 20 ++++++ zsh/plugins/env_lazy.zsh | 9 +++ zsh/plugins/func_lazy.zsh | 7 +++ zsh/{plugin.zsh => plugins/fzf_lazy.zsh} | 77 ------------------------ zsh/plugins/mise_lazy.zsh | 1 + zsh/plugins/op_lazy.zsh | 1 + zsh/plugins/zsh_lazy.zsh | 37 ++++++++++++ 12 files changed, 159 insertions(+), 121 deletions(-) create mode 100644 sheldon/plugins.toml create mode 100644 zsh/plugins/alias_lazy.zsh create mode 100644 zsh/plugins/env_lazy.zsh create mode 100644 zsh/plugins/func_lazy.zsh rename zsh/{plugin.zsh => plugins/fzf_lazy.zsh} (74%) create mode 100644 zsh/plugins/mise_lazy.zsh create mode 100644 zsh/plugins/op_lazy.zsh create mode 100644 zsh/plugins/zsh_lazy.zsh diff --git a/.gitignore b/.gitignore index 62b90da..70e35ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ brew/Brewfile.lock.json nvim/plugin/packer_compiled.lua zsh/.zcompdump +zsh/plugins/*.zsh.zwc .luarc.json diff --git a/brew/Brewfile b/brew/Brewfile index 0302184..083bfc1 100644 --- a/brew/Brewfile +++ b/brew/Brewfile @@ -53,6 +53,7 @@ brew "kustomize" brew "neofetch" brew "tailscale" brew "cue" +brew "sheldon" cask "google-cloud-sdk" cask "1password" @@ -78,8 +79,6 @@ cask "notion-calendar" cask "spectacle" cask "karabiner-elements" cask "google-drive" -cask "todoist" -cask "xbar" cask "font-hack-nerd-font" diff --git a/cli/lib/linkMap.ts b/cli/lib/linkMap.ts index 1930f00..7696a5c 100644 --- a/cli/lib/linkMap.ts +++ b/cli/lib/linkMap.ts @@ -51,6 +51,7 @@ const linkMap: LinkMap = new Map([ ["mise", { target: join(dotfilesDir, "mise"), symlink: join(home, ".config", "mise"), + platform: "common", }], ["k9s", { target: join(dotfilesDir, "k9s"), @@ -67,6 +68,11 @@ const linkMap: LinkMap = new Map([ symlink: join(home, ".gitmessage"), platform: "common", }], + ["sheldon", { + target: join(dotfilesDir, "sheldon"), + symlink: join(home, ".config", "sheldon"), + platform: "common", + }], ]); export { dotfilesDir, home, linkMap }; diff --git a/sheldon/plugins.toml b/sheldon/plugins.toml new file mode 100644 index 0000000..01d6153 --- /dev/null +++ b/sheldon/plugins.toml @@ -0,0 +1,44 @@ +# `sheldon` configuration file +# ---------------------------- +shell = "zsh" + +apply = ["defer"] + +[templates] +defer = "{{ hooks?.pre | nl }}{% for file in files %}zsh-defer source \"{{ file }}\"\n{% endfor %}{{ hooks?.post | nl }}" + +[plugins.zsh-defer] +github = "romkatv/zsh-defer" +apply = ["source"] + +[plugins.compinit] +inline = 'autoload -Uz compinit && zsh-defer compinit' + +[plugins.pure] +github = "sindresorhus/pure" +use = ["async.zsh", "pure.zsh"] +apply = ["source"] + +[plugins.fast-syntax-highlighting] +github = "zdharma-continuum/fast-syntax-highlighting" + +[plugins.zsh-completions] +github = "zsh-users/zsh-completions" + +[plugins.zsh-autosuggestions] +github = "zsh-users/zsh-autosuggestions" + +[plugins.autopair] +github = "hlissner/zsh-autopair" + +[plugins.zsh-z] +github = "agkozak/zsh-z" + +[plugins.dotfiles-defers] +local = "~/.config/zsh/plugins" +use = ["*_lazy.zsh"] + +#[plugins.dotfiles-sync] +#local = "~/.config/zsh/plugins" +#use = ["*_sync.zsh"] +#apply = ["source"] diff --git a/zsh/.zshrc b/zsh/.zshrc index 1221202..53a77e4 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -1,46 +1,36 @@ -# use compiled zshrc -if [ ~/.zshrc -nt ~/.zshrc.zwc ]; then - zcompile ~/.zshrc -fi - +# history settings HISTFILE=~/.zsh_history HISTSIZE=1000000 SAVEHIST=1000000 -zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' -zstyle ':completion:*:default' menu select=2 -zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" -zstyle ':completion:*:default' menu select=2 -zstyle ':completion:*' ignore-parents parent pwd .. -zstyle ':completion:*' use-cache true -zstyle ':completion:*:default' menu select=2 - -autoload colors -if [ -n "$LS_COLORS" ]; then - zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} -fi - -setopt hist_ignore_dups # 直前と同じコマンドラインはヒストリに追加しない -setopt hist_ignore_all_dups # 重複したヒストリは追加しない -setopt hist_ignore_space # スペースから始まるコマンド行はヒストリに残さない -setopt magic_equal_subst -setopt auto_list # 補完候補が複数ある時に、一覧表示 -setopt ignore_eof # Ctrl+Dでzshを終了しない - -bindkey "^[[3~" delete-char -bindkey -v - -# zinit -ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git" -source "${ZINIT_HOME}/zinit.zsh" -autoload -Uz _zinit -(( ${+_comps} )) && _comps[zinit]=_zinit - -# set theme -zinit ice pick"async.zsh" src"pure.zsh" -zinit light sindresorhus/pure - -zinit wait lucid light-mode as'null' \ - atinit'. "$HOME/.config/zsh/plugin.zsh"' \ - for 'zdharma-continuum/null' -### End of Zinit's installer chunk +# use compiled zshrc +ZSHRC_DIR=${${(%):-%N}:A:h} +function source { # override source command + ensure_zcompiled $1 + builtin source $1 +} +function ensure_zcompiled { + local compiled="$1.zwc" + if [[ ! -r "$compiled" || "$1" -nt "$compiled" ]]; then + echo "\033[1;36mCompiling\033[m $1" + zcompile $1 + fi +} +ensure_zcompiled ~/.zshrc + +# common settings +export XDG_CACHE_HOME="$HOME/.cache" +export XDG_CONFIG_HOME="$HOME/.config" + +# sheldon settings +eval "$(sheldon source)" + +#cache_dir=${XDG_CACHE_HOME:-$HOME/.cache} +#sheldon_cache="$cache_dir/sheldon.zsh" +#sheldon_toml="$HOME/.config/sheldon/plugins.toml" +#if [[ ! -r "$sheldon_cache" || "$sheldon_toml" -nt "$sheldon_cache" ]]; then +# mkdir -p $cache_dir +# sheldon source > $sheldon_cache +#fi +#source "$sheldon_cache" +#unset cache_dir sheldon_cache sheldon_toml diff --git a/zsh/plugins/alias_lazy.zsh b/zsh/plugins/alias_lazy.zsh new file mode 100644 index 0000000..06f00bd --- /dev/null +++ b/zsh/plugins/alias_lazy.zsh @@ -0,0 +1,20 @@ +alias g="git" +alias k="kubectl" +alias kctx="kubectx" +alias kns="kubens" +alias tf="terraform" +alias vim="nvim" +alias v="nvim" + +alias ls='ls --color=auto' +alias la="ls -a" +alias ll="ls -l" +alias sl='ls' +alias grep='grep --color=auto' +alias fgrep='fgrep --color=auto' +alias egrep='egrep --color=auto' + +alias python='python3' + +alias propen='gh pr view --web' +alias prcreate='gh pr create -a @me -f -d && gh pr view --web' diff --git a/zsh/plugins/env_lazy.zsh b/zsh/plugins/env_lazy.zsh new file mode 100644 index 0000000..4aba642 --- /dev/null +++ b/zsh/plugins/env_lazy.zsh @@ -0,0 +1,9 @@ +export GOPATH=~/.go +export PATH=~/.go/bin:$PATH + +export PATH="/opt/homebrew/bin:$PATH" +export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" +export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH" + +export VISUAL=nvim +export EDITOR=nvim diff --git a/zsh/plugins/func_lazy.zsh b/zsh/plugins/func_lazy.zsh new file mode 100644 index 0000000..a7a00f1 --- /dev/null +++ b/zsh/plugins/func_lazy.zsh @@ -0,0 +1,7 @@ +ggl() { + open "https://google.com/search?q=${*// /%20}" +} + +gignore() { + curl -L -s "https://www.gitignore.io/api/$@" +} diff --git a/zsh/plugin.zsh b/zsh/plugins/fzf_lazy.zsh similarity index 74% rename from zsh/plugin.zsh rename to zsh/plugins/fzf_lazy.zsh index 7a5c67c..2dd0542 100644 --- a/zsh/plugin.zsh +++ b/zsh/plugins/fzf_lazy.zsh @@ -1,71 +1,3 @@ -### Zinit -# ref: https://github.com/zdharma/zinit#loading-and-unloading -zinit ice wait'!1'; zinit load zdharma-continuum/fast-syntax-highlighting -zinit ice wait'!0'; zinit load zsh-users/zsh-autosuggestions -zinit ice wait'!0'; zinit load zsh-users/zsh-completions -zinit ice wait'!1'; plugins=(… zsh-completions) -zinit ice wait'!1'; autoload -U compinit && compinit - -zmodload zsh/zpty -autoload -Uz edit-command-line -zle -N edit-command-line -bindkey "^O" edit-command-line - -### Aliases -alias g="git" -alias k="kubectl" -alias kctx="kubectx" -alias kns="kubens" -alias tf="terraform" -alias vim="nvim" -alias v="nvim" - -alias ls='ls --color=auto' -alias la="ls -a" -alias ll="ls -l" -alias sl='ls' -alias grep='grep --color=auto' -alias fgrep='fgrep --color=auto' -alias egrep='egrep --color=auto' - -alias python='python3' - -alias propen='gh pr view --web' -alias prcreate='gh pr create -a @me -f -d && gh pr view --web' - -### Export -export XDG_CACHE_HOME="$HOME/.cache" -export XDG_CONFIG_HOME="$HOME/.config" - -source "$XDG_CONFIG_HOME/op/plugins.sh" -export GOPATH=~/.go -export PATH=~/.go/bin:$PATH - -export PATH="/opt/homebrew/bin:$PATH" -export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" -export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH" - -export VISUAL=nvim -export EDITOR=nvim - -#export NAVI_CONFIG="$HOME/.config/navi/cheats" -#export NAVI_CONFIG_YAML="$HOME/.config/navi/config.yaml" - -### Functions -ggl() { - open "https://google.com/search?q=${*// /%20}" -} - -gignore() { - curl -L -s "https://www.gitignore.io/api/$@" -} - -### Hooks -zshaddhistory() { - local line="${1%%$'\n'}" - [[ ! "$line" =~ "^(cd|jj?|la|ll|ls|rm)($| )" ]] -} - ### fzf export FZF_DEFAULT_OPTS="--height 40% --border --reverse --no-sort --exact --cycle --multi --ansi --sync --bind=ctrl-t:toggle --bind=ctrl-k:kill-line --bind=?:toggle-preview --bind=down:preview-down --bind=up:preview-up" export FZF_CTRL_T_COMMAND='rg --files --hidden --follow --glob "!.git/*"' @@ -212,12 +144,3 @@ issues() { gh issue view -w -- "${number}" fi } - -### mise -eval "$(mise activate zsh)" - -### custom configuration -if [ -e "$HOME/.config/zsh/custom.zsh" ]; then - source "$HOME/.config/zsh/custom.zsh" -fi - diff --git a/zsh/plugins/mise_lazy.zsh b/zsh/plugins/mise_lazy.zsh new file mode 100644 index 0000000..5982996 --- /dev/null +++ b/zsh/plugins/mise_lazy.zsh @@ -0,0 +1 @@ +eval "$(mise activate zsh)" diff --git a/zsh/plugins/op_lazy.zsh b/zsh/plugins/op_lazy.zsh new file mode 100644 index 0000000..b8c11ea --- /dev/null +++ b/zsh/plugins/op_lazy.zsh @@ -0,0 +1 @@ +source "$XDG_CONFIG_HOME/op/plugins.sh" diff --git a/zsh/plugins/zsh_lazy.zsh b/zsh/plugins/zsh_lazy.zsh new file mode 100644 index 0000000..effb4ee --- /dev/null +++ b/zsh/plugins/zsh_lazy.zsh @@ -0,0 +1,37 @@ +# Styles +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' +zstyle ':completion:*:default' menu select=2 +zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" +zstyle ':completion:*:default' menu select=2 +zstyle ':completion:*' ignore-parents parent pwd .. +zstyle ':completion:*' use-cache true +zstyle ':completion:*:default' menu select=2 + +autoload colors +if [ -n "$LS_COLORS" ]; then + zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +fi + +# Options +setopt hist_ignore_dups # 直前と同じコマンドラインはヒストリに追加しない +setopt hist_ignore_all_dups # 重複したヒストリは追加しない +setopt hist_ignore_space # スペースから始まるコマンド行はヒストリに残さない +setopt magic_equal_subst +setopt auto_list # 補完候補が複数ある時に、一覧表示 +setopt ignore_eof # Ctrl+Dでzshを終了しない + +# Hooks +zshaddhistory() { + local line="${1%%$'\n'}" + [[ ! "$line" =~ "^(cd|jj?|la|ll|ls|rm)($| )" ]] +} + +# Bindings +bindkey "^[[3~" delete-char +bindkey -v + +# Modules +zmodload zsh/zpty +autoload -Uz edit-command-line +zle -N edit-command-line +bindkey "^O" edit-command-line -- knotmirror 0.0.1