Skip to content

Instantly share code, notes, and snippets.

@gki
Created September 7, 2020 11:21
Show Gist options
  • Save gki/fc10fcca09c2778023c25abde2f7ecd2 to your computer and use it in GitHub Desktop.
Save gki/fc10fcca09c2778023c25abde2f7ecd2 to your computer and use it in GitHub Desktop.
# .zshrc
autoload -Uz vcs_info
autoload -Uz colors # black red green yellow blue magenta cyan white
colors
export LSCOLORS=gxfxxxxxcxxxxxxxxxgxgx
export LS_COLORS='di=01;36:ln=01;35:ex=01;32'
zstyle ':completion:*' list-colors 'di=36' 'ln=35' 'ex=32'
# PROMPT変数内で変数参照
setopt prompt_subst
zstyle ':vcs_info:git:*' check-for-changes true #formats 設定項目で %c,%u が使用可
zstyle ':vcs_info:git:*' stagedstr "%F{green}!" #commit されていないファイルがある
zstyle ':vcs_info:git:*' unstagedstr "%F{magenta}+" #add されていないファイルがある
zstyle ':vcs_info:*' formats "%F{cyan}%c%u(%b)%f" #通常
zstyle ':vcs_info:*' actionformats '[%b|%a]' #rebase 途中,merge コンフリクト等 formats 外の表示
# %b ブランチ情報
# %a アクション名(mergeなど)
# %c changes
# %u uncommit
# プロンプト表示直前に vcs_info 呼び出し
precmd () { vcs_info }
# プロンプト(左)
# color check: for c in {000..255}; do echo -n "\e[38;5;${c}m $c" ; [ $(($c%16)) -eq 15 ] && echo;done;echo
PROMPT='%F{007}[%n@%m] %F{003}%*%f'
PROMPT=$PROMPT'${vcs_info_msg_0_} %{${fg[white]}%}%}$%{${reset_color}%} '
# プロンプト(右)
RPROMPT='%{${fg[green]}%}[%~]%{${reset_color}%}'
# ls(color settings)
alias ls='ls -G'
alias ll='ls -lG'
alias la='ls -laG'
alias ls='ls -ltrG'
# Override auto-title when static titles are desired ($ title My new title)
title() { export TITLE_OVERRIDDEN=1; echo -en "\e]0;$*\a"}
# Turn off static titles ($ autotitle)
autotitle() { export TITLE_OVERRIDDEN=0 }; autotitle
# Condition checking if title is overridden
overridden() { [[ $TITLE_OVERRIDDEN == 1 ]]; }
# Echo asterisk if git state is dirty
gitDirty() { [[ $(git status 2> /dev/null | grep -o '\w\+' | tail -n1) != ("clean"|"") ]] && echo "*" }
# Show cwd when shell prompts for input.
tabtitle_precmd() {
if overridden; then return; fi
pwd=$(pwd) # Store full path as variable
cwd=${pwd##*/} # Extract current working dir only
print -Pn "\e]0;$cwd$(gitDirty)\a" # Replace with $pwd to show full path
}
[[ -z $precmd_functions ]] && precmd_functions=()
precmd_functions=($precmd_functions tabtitle_precmd)
# Prepend command (w/o arguments) to cwd while waiting for command to complete.
tabtitle_preexec() {
if overridden; then return; fi
printf "\033]0;%s\a" "${1%% *} | $cwd$(gitDirty)" # Omit construct from $1 to show args
}
[[ -z $preexec_functions ]] && preexec_functions=()
preexec_functions=($preexec_functions tabtitle_preexec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment