Last active
April 4, 2024 01:45
-
-
Save redpeacock78/1bcf09ddc288f75adf8c3d182e870ae2 to your computer and use it in GitHub Desktop.
my zsh setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###256色表示### | |
function 256() { | |
local code | |
for c in {000..255}; do | |
echo -en "\e[38;5;${c}m $c"; [[ $(($c%16)) -eq 15 ]] && echo | |
done | |
echo | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias /='../' | |
alias ls="ls -F --color=auto" | |
alias la="ls -A --color=auto" | |
alias mkcd='(){ mkdir -p "$@" && eval cd "\"\$$#\""; }' | |
type trash > /dev/null 2>&1 && alias del="trash -r" | |
alias pathls='(){ REV="";[[ "${@}" == "-r" ]] && REV="r";awk -F : '\''{for(i=1;i<=NF;i++) print length($i),$i}'\'' <<<"${PATH}"|sort -n"${REV}"|awk '\''{print $2}'\''; }' | |
type brew > /dev/null 2>&1 && alias brew='BREW_PATH="$(awk '\''BEGIN{RS=":";ORS=":"}!/.*env/'\'' <<<"${PATH}")";PATH="${BREW_PATH/%?/}" brew' && compdef brew='brew' && setopt complete_aliases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zle-line-init() { | |
auto-fu-init | |
} | |
zle -N zle-line-init | |
zstyle ':completion:*' completer _oldlist _complete | |
zstyle ':auto-fu:var' postdisplay $'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###zcompile### | |
if [ ~/.zshrc -nt ~/.zshrc.zwc ]; then | |
zcompile ~/.zshrc | |
fi | |
###補完機能### | |
autoload -Uz compinit | |
compinit -uc | |
###文字コード設定### | |
export LANG=ja_JP.UTF-8 | |
###フローコントロールの削除### | |
setopt no_flow_control | |
###ディレクトリの指定で移動### | |
setopt auto_cd | |
###移動したディレクトリを記録### | |
setopt auto_pushd | |
###コマンド訂正### | |
setopt correct | |
###補完候補表示時のビープ音無効化### | |
setopt nolistbeep | |
###ビープ音の停止### | |
setopt NO_beep | |
###補完候補を詰めて表示### | |
setopt list_packed | |
###改行なしの行を表示### | |
unsetopt promptcr | |
###PROMPT内で変数展開・コマンド置換・算術演算を実行### | |
setopt prompt_subst | |
###カーソル位置は保持したままファイル名一覧を順次その場で表示### | |
setopt always_last_prompt | |
###補完候補一覧でファイルの種別を識別マーク表示 (訳注:ls -F の記号)### | |
setopt list_types | |
###日本語ファイル名等8ビットを通す### | |
setopt print_eight_bit | |
###語の途中でもカーソル位置で補完### | |
setopt complete_in_word | |
###コマンドラインでも # 以降をコメントと見なす### | |
setopt interactive_comments | |
###*とか[]をコマンドに合わせてうまく認識させる### | |
setopt nonomatch | |
###コマンド履歴### | |
HISTFILE=~/.zsh_history | |
HISTSIZE=600000 #メモリに展開する履歴数 | |
SAVEHIST=600000 #保存する履歴数 | |
setopt histignorealldups #ヒストリーに重複を表示しない | |
setopt share_history #他のターミナルと履歴を共有 | |
setopt inc_append_history #シェルを横断して.zsh_historyに記録 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###fzf### | |
export FZF_DEFAULT_OPTS='--height 40% --reverse --border' | |
###emoji-cli### | |
export EMOJI_CLI_FILTER=fzf | |
export EMOJI_CLI_KEYBIND='^u' | |
###enhancd### | |
export ENHANCD_FILTER=peco | |
###fast-syntax-highlighting### | |
export FAST_HIGHLIGHT[use_brackets]=1 | |
###trash### | |
export TRASHLIST="${HOME}/.trashlist" | |
export TRASHBOX="${HOME}/.Trash" | |
export MAXTRASHBOXSIZE="5120" | |
export MAXTRASHSIZE="$(echo $((5120/5)))" | |
###Homebrew### | |
intel="/usr/local/bin/brew" | |
m1="/opt/homebrew/bin/brew" | |
linux="${HOME}/linuxbrew/.linuxbrew/bin/brew" | |
if [[ -e "${intel}" ]]; then | |
eval "$("${intel}" shellenv)" | |
elif [[ -e "${m1}" ]]; then | |
eval "$("${m1}" shellenv)" | |
elif [[ -e "${linux}" ]]; then | |
eval "$("${linux}" shellenv)" | |
fi | |
###anyenv### | |
type anyenv > /dev/null 2>&1 && eval "$(anyenv init -)" | |
###TheFuck### | |
type fuck > /dev/null 2>&1 && eval "$(thefuck --alias)" | |
###Docker(colima)### | |
type colima > /dev/null 2>&1 && export DOCKER_HOST="unix://"${HOME}"/.colima/docker.sock" | |
###coreutils### | |
type brew > /dev/null 2>&1 && brew --prefix coreutils > /dev/null 2>&1 && export PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH" | |
###binutils### | |
type brew > /dev/null 2>&1 && brew --prefix binutils > /dev/null 2>&1 && export PATH="$(brew --prefix binutils)/bin:$PATH" | |
###deno### | |
type deno > /dev/null 2>&1 && export PATH="${HOME}/.deno/bin:${PATH}" | |
###direnv### | |
type direnv > /dev/null 2>&1 && eval "$(direnv hook zsh)" | |
###yarn### | |
if type yarn > /dev/null 2>&1; then | |
export PATH="$(yarn global bin):${PATH}" | |
export PATH="$(yarn bin):${PATH}" | |
fi | |
##Android SDK## | |
if [[ -e "${HOME}/Library/Android" ]]; then | |
export PATH="${HOME}/Library/Android/sdk/emulator:${PATH}" | |
fi | |
###PATHの重複を削除### | |
typeset -U path PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function git-swich-peco() { | |
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" == 'true' ]]; then | |
branch="$(git --no-pager reflog --all | awk '/checkout/{print $NF}' | awk '!a[$0]++' | peco --query "${LBUFFER}")" | |
if [[ -n "${branch}" ]]; then | |
git switch "${branch}" && zle accept-line | |
else | |
zle reset-prompt | |
fi | |
fi | |
} | |
zle -N git-swich-peco | |
bindkey '^s' git-swich-peco |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function peco-ghq() { | |
local root="$(ghq root)" | |
local project="$(ghq list | peco --query "${LBUFFER}")" | |
if [[ -n "${project}" ]]; then | |
cd "${root}/${project}" && zle accept-line | |
else | |
zle reset-prompt | |
fi | |
} | |
zle -N peco-ghq | |
bindkey '^g' peco-ghq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function peco-select-history() { | |
BUFFER="$(history -n 1 | sed '1!G;h;$!d' | awk '!a[$0]++' | peco --query "${LBUFFER}")" | |
CURSOR="${#BUFFER}" | |
zle -R -c | |
} | |
zle -N peco-select-history | |
bindkey '^r' peco-select-history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pip_ext() { | |
{ | |
if [[ ! "${1}" == elekiban ]]; then | |
$(pyenv which pip) "${@}" | |
else | |
builtin echo '🔍 Updating installed Packages' && | |
declare outdated="$($(pyenv which pip) list -o)" | |
if [[ -z "${outdated}" ]]; then | |
{ | |
builtin echo '📦 Nothing to update' | |
} | |
else | |
{ | |
builtin echo '⚡️ Found an Update Package' && | |
declare START="$(date '+%s%N')" && | |
{ | |
tail -n +3 <<<"${outdated}" | | |
awk '{print $1}' | | |
xargs $(pyenv which pip) install -U | |
} && { | |
declare END="$(date '+%s%N')" && | |
declare TIME="$(builtin echo "((${END}-${START})/1000000000)" | bc -l)" && | |
builtin echo "✨ Done in $(builtin printf "%.2f" "${TIME}")s" | |
} | |
} || exit 1 | |
fi | |
fi | |
} | |
} | |
alias pip="pip_ext ${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###ウィンドウタイトルに現ユーザー、ホスト、現ディレクトリ表示### | |
precmd() { | |
echo -ne "\033]0;${USER}@${HOST}:$(pwd | sed -e "s,^$HOME,~,g")\007" | |
} | |
###色を使用する### | |
autoload -Uz colors; | |
colors | |
###色の定義### | |
DEFAULT="%{[1;m%}" #色のリセット | |
RED="%{[38;5;9m%}" #赤色 | |
GREEN="%{[38;5;10m%}" #緑色 | |
BLUE="%{[38;5;27m%}" #青色1 | |
BLUE2="%{[38;5;20m%}" #青色2 | |
PURPLE="%{[38;5;5m%}" #紫色 | |
YELLOW="%{[38;5;226m%}" #黄色 | |
##vcs_info機能呼び出し## | |
autoload -Uz vcs_info | |
###git(vcs_info)関連### | |
setopt prompt_subst | |
CHECK=$'\U2714 ' | |
brunch=$'\ue0a0' | |
quarter_spase=$'\U2005' | |
git=$'\xef\x87\x93 ' | |
zstyle ':vcs_info:git:*' check-for-changes true | |
zstyle ':vcs_info:*' max-exports 3 | |
zstyle ':vcs_info:git:*' stagedstr "%F{yellow}!%f" | |
zstyle ':vcs_info:git:*' unstagedstr "%F{red}+%f" | |
zstyle ':vcs_info:*' formats "[%F{green}${CHECK}%c%u%f]" "[%F${BLUE}%b${brunch}${git}%f]" | |
zstyle ':vcs_info:*' actionformats "[%b|%a]%c%u" "[%b|%a]" | |
precmd () { vcs_info } | |
###add-ash-hookを有効化### | |
autoload -Uz add-zsh-hook | |
###vsc_info更新時に自動更新### | |
function _git_not_pushed() { | |
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]]; then | |
head="$(git rev-parse HEAD 2>/dev/null)" | |
for x in $(git rev-parse --remotes); do | |
[[ "${head}" == "${x}" ]] && return 0 | |
done | |
echo "?" | |
fi | |
return 0 | |
} | |
function _update_vcs_info_msg() { | |
psvar=() | |
LANG=en_US.UTF-8 vcs_info | |
[[ -n "$vcs_info_msg_0_" ]] && psvar[1]="$vcs_info_msg_0_" | |
psvar[2]=$(_git_not_pushed) | |
} | |
add-zsh-hook precmd _update_vcs_info_msg | |
###プロンプト表示設定### | |
function prompt_update () { | |
default="%B%(?.%(!.${PURPLE}.${GREEN}).${RED})%n"@"%m${DEFAULT}:${BLUE}%~${DEFAULT}%b%(!.#.$) " | |
if [[ -z "$(git status 2>/dev/null)" ]]; then | |
prompt="${default}" | |
else | |
if [[ -z "$(git --no-pager log 2>/dev/null)" ]]; then | |
prompt="${default}" | |
else | |
prompt="%B%(?.%(!.${PURPLE}.${GREEN}).${RED})%n"@"%m${DEFAULT}%b:${vcs_info_msg_0_}[$(git show -s --format=%H|cut -c 1-7)]${vcs_info_msg_1_}\n${BLUE}↪︎ $(pwd|awk -v home=${HOME} '{c=sub(home,"",$0);if(c == ""){print substr($0,2)}else{print substr($c,2)}}'|awk -F / '{if(NF > 2){c="";for(i=NF-1;i<=NF;i++) c=c "/"$i;print c}else{print "/"$0}}')${DEFAULT}%b₲ " | |
fi | |
fi | |
echo -e "${prompt}" | |
} | |
PROMPT='$(prompt_update)' #メインプロンプト(通常時は緑、root時は紫、コマンドがエラーだった場合次に表示されるプロンプトは赤) | |
PROMPT2="%B%(?.%(!.${PURPLE}.${GREEN}).${RED})%n"@"%m${DEFAULT}:${BLUE}%~${DEFAULT}" #セカンダリプロンプト | |
SPROMPT="%B%U${YELLOW}Correct${DEFAULT}%u: ${RED}%R${DEFAULT} 👉 ${BLUE}%r${DEFAULT} ?%b [No/Yes/About/Edit] " #コマンド訂正表示 | |
RPROMPT='[%D{%Y/%m/%d %H:%M:%S}]' #右プロンプト時刻表示 | |
#右プロンプト時刻自動更新 | |
TMOUT=1 | |
TRAPALRM() { | |
if [[ "${WIDGET}" != "expand-or-complete" && ! "${WIDGET}" =~ "(peco|enhancd|emoji)" ]]; then | |
zle reset-prompt | |
fi | |
} | |
###PROMPT(git)表示### | |
PROMPT2="${PROMPT2}"'${vcs_info_msg_0_}%(!.#.$)%b${BLUE2}%_> ${DEFAULT}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [[ ! -n $TMUX && $- == *l* ]]; then | |
ID="$(tmux list-sessions)" | |
[[ -z "${ID}" ]] && tmux new-session | |
create_new_session="Create New Session" | |
ID="${create_new_session}:\n${ID}" | |
ID="$(echo "${ID}" | peco | cut -d: -f1)" | |
if [[ "${ID}" == "${create_new_session}" ]]; then | |
tmux new-session | |
elif [[ -n "${ID}" ]]; then | |
tmux attach-session -t "${ID}" | |
else | |
: | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment