Zsh

~/zshrc.d

Rina Kawakita 2019. 12. 25. 19:52

~/zshrc.d/00-early.zsh

# vim: ts=4 sw=4
# Early commands running before any other files
# Use emacs mode. Vim is nice but not in a shell.
bindkey -e

# Create cache folder for compdump etc.
ZSH_CACHE="/tmp/.zsh-${USER}-${ZSH_VERSION}"
mkdir -p $ZSH_CACHE
chmod 700 $ZSH_CACHE

 

~/zshrc.d/aliases.zsh

청소년 유해 코드 들어가 있음. 게시 불가

 

~/zshrc.d/completion.zsh

# vim: ts=4 sw=4
# Initialize completion
autoload -Uz compinit
compinit -d "$ZSH_CACHE/zcompdump"
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path $ZSH_CACHE

# Enable approximate completions
zstyle ':completion:*' completer _complete _ignored _approximate
zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3)) numeric)'

# Automatically update PATH entries
zstyle ':completion:*' rehash true

# Use menu completion
zstyle ':completion:*' menu select

# Verbose completion results
zstyle ':completion:*' verbose true

# Smart matching of dashed values, e.g. f-b matching foo-bar
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*'

# Group results by category
zstyle ':completion:*' group-name ''

# Don't insert a literal tab when trying to complete in an empty buffer
# zstyle ':completion:*' insert-tab false

# Keep directories and files separated
zstyle ':completion:*' list-dirs-first true

# Don't try parent path completion if the directories exist
zstyle ':completion:*' accept-exact-dirs true

# Always use menu selection for `cd -`
zstyle ':completion:*:*:cd:*:directory-stack' force-list always
zstyle ':completion:*:*:cd:*:directory-stack' menu yes select

# Pretty messages during pagination
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'

# Nicer format for completion messages
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:corrections' format '%U%F{green}%d (errors: %e)%f%u'
zstyle ':completion:*:warnings' format '%F{202}%BSorry, no matches for: %F{214}%d%b'

# Show message while waiting for completion
zstyle ':completion:*' show-completer true

# Prettier completion for processes
zstyle ':completion:*:*:*:*:processes' force-list always
zstyle ':completion:*:*:*:*:processes' menu yes select
zstyle ':completion:*:*:*:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,args -w -w"

# Use ls-colors for path completions
function _set-list-colors() {
	zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
	unfunction _set-list-colors
}
sched 0 _set-list-colors  # deferred since LC_COLORS might not be available yet

# Don't complete hosts from /etc/hosts
zstyle -e ':completion:*' hosts 'reply=()'

# Don't complete uninteresting stuff unless we really want to.
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec)|TRAP*)'
zstyle ':completion:*:*:*:users' ignored-patterns \
		adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \
		clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \
		gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \
		ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \
		named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \
		operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \
		rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \
		usbmux uucp vcsa wwwrun xfs cron mongodb nullmail portage redis \
		shoutcast tcpdump '_*'
zstyle ':completion:*' single-ignored show

 

~/zshrc.d/history.zsh

# vim: ts=4 sw=4
HISTFILE=~/.zsh_history
HISTSIZE=30000
SAVEHIST=25000

 

~/zshrc.d/keybinds.zsh

# vim: ts=4 sw=4
# INS, DEL, etc.
function _delete-char-or-region() {
	[[ $REGION_ACTIVE -eq 1 ]] && zle kill-region || zle delete-char
}
zle -N _delete-char-or-region
bindkey ${terminfo[kich1]}	quoted-insert
bindkey ${terminfo[kdch1]}	_delete-char-or-region
bindkey ${terminfo[khome]}	beginning-of-line
bindkey ${terminfo[kend]}	end-of-line
bindkey ${terminfo[kpp]}	up-line-or-search
bindkey ${terminfo[knp]}	down-line-or-search
bindkey '\e[1~'				beginning-of-line		# HOME in putty
bindkey '\e[4~'				end-of-line				# END in putty

# Easy access to previous args
autoload -Uz copy-earlier-word
zle -N copy-earlier-word
bindkey "\em" copy-earlier-word

# Edit the current command line in $EDITOR
autoload -U edit-command-line
zle -N edit-command-line
bindkey '\C-x\C-e' edit-command-line

# Completion
zmodload zsh/complist
bindkey -M menuselect ${terminfo[kcbt]}	reverse-menu-complete	# shift-tab
bindkey -M menuselect ${terminfo[kpp]}	backward-word
bindkey -M menuselect ${terminfo[knp]}	forward-word
bindkey -M menuselect '\eo'				accept-and-infer-next-history
bindkey -M isearch '\e'		accept-search
bindkey '\ee'				end-of-list
bindkey '\eq'				push-line-or-edit

# Misc
bindkey '^[p'				copy-prev-shell-word
bindkey -s ${terminfo[kf5]}	'\C-U unset _custom_zsh_config_loaded; source ~/.zshrc\n'

# Quickly jump right after the first word (e.g. to insert switches)
function _after-first-word() {
	zle beginning-of-line
	zle forward-word
}
zle -N _after-first-word
bindkey '\C-X1' _after-first-word

# Extended word movements/actions
autoload -Uz select-word-style
function _zle-with-style() {
	setopt localoptions
	unsetopt warn_create_global
	local style
	[[ -n "$3" ]] && WORDCHARS=${WORDCHARS/$3}
	[[ $BUFFER =~ '^\s+$' ]] && style=shell || style=$2
	select-word-style $style
	zle $1
	[[ -n "$3" ]] && WORDCHARS="${WORDCHARS}${3}"
	select-word-style normal
}

function _backward-word()		{ _zle-with-style backward-word			bash }
function _forward-word()		{ _zle-with-style forward-word			bash }
function _backward-arg()		{ _zle-with-style backward-word			shell }
function _forward-arg()			{ _zle-with-style forward-word			shell }
function _backward-kill-arg()	{ _zle-with-style backward-kill-word 	shell }
function _forward-kill-arg()	{ _zle-with-style kill-word 			shell }
function _backward-kill-word()	{ _zle-with-style backward-kill-word 	normal }
function _backward-kill-path()	{ _zle-with-style backward-kill-word 	normal	'/' }

zle -N _backward-word
zle -N _forward-word
zle -N _backward-arg
zle -N _forward-arg
zle -N _backward-kill-arg
zle -N _forward-kill-arg
zle -N _backward-kill-word
zle -N _backward-kill-path

bindkey '\C-[OD'	_backward-word		# ctrl-left
bindkey '\C-[OC'	_forward-word		# ctrl-right
bindkey '\e\e[D'	_backward-arg		# alt-left
bindkey '\e\e[C'	_forward-arg		# alt-right
bindkey '\e\C-?'	_backward-kill-arg	# alt-backspace
bindkey '\e\e[3~'	_forward-kill-arg	# alt-del
bindkey '\C-w'		_backward-kill-word
bindkey '\C-f'		_backward-kill-path

# Allow more powerful history-i-search (multiple uses in the same line)
autoload -Uz narrow-to-region
function _history-incremental-preserving-pattern-search-backward() {
	local state tmp
	MARK=CURSOR  # magick, else multiple ^R don't work
	narrow-to-region -p "$LBUFFER${BUFFER:+>>}" -P "${BUFFER:+<<}$RBUFFER" -S state
	zle end-of-history
	zle history-incremental-pattern-search-backward
	narrow-to-region -R state
}
zle -N _history-incremental-preserving-pattern-search-backward
bindkey '^r' _history-incremental-preserving-pattern-search-backward
bindkey -M isearch '^r' history-incremental-pattern-search-backward
bindkey '^s' history-incremental-pattern-search-forward

 

~/zshrc.d/misc.zsh

# vim: ts=4 sw=4
# Pretty dircolors
eval `dircolors -b $_custom_zsh_config_base/ls_colors`

# Prettier ZLE highlighting
zle_highlight=(region:standout special:fg=199 isearch:fg=220 paste:fg=111 suffix:fg=177)

# Auto-quote meta chars in URLs and Git refspecs
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
#git-escape-magic

# Show user/host/pwd in terminal title
autoload -Uz add-zsh-hook
_show_pwd() { print -Pn "\e]0;[%n@%m:%d]\a" }
[[ "$TERM" != "linux" ]] && add-zsh-hook precmd _show_pwd

# Builtin help, triggered with \e-h
autoload -Uz run-help
unalias run-help 2>/dev/null

# Interactive mv
function imv() {
	local src dst
	for src; do
		[[ -e $src ]] || { print -Pu2 "%F{red}%B$src: No such file or directory%b%f"; continue }
		dst=$src
		vared dst
		[[ $src != $dst ]] && mkdir -p $dst:h && mv -n $src $dst
	done
}

# Useful stuff
autoload -Uz age
autoload -Uz zargs
autoload -Uz zcalc

 

~/zshrc.d/params.zsh

# vim: ts=4 sw=4
# Don't correct to underscored stuff (usually shell functions)
CORRECT_IGNORE='_*'
# Don't check for mails
MAILCHECK=0

 

~/zshrc.d/shellopts.zsh

# vim: ts=4 sw=4
# History
setopt		APPEND_HISTORY
setopt		BANG_HIST
setopt		EXTENDED_HISTORY
unsetopt	HIST_ALLOW_CLOBBER
unsetopt	HIST_BEEP
setopt		HIST_EXPIRE_DUPS_FIRST
setopt		HIST_FCNTL_LOCK
setopt		HIST_FIND_NO_DUPS
unsetopt	HIST_IGNORE_ALL_DUPS
setopt		HIST_IGNORE_DUPS
setopt		HIST_IGNORE_SPACE
setopt		HIST_NO_FUNCTIONS
setopt		HIST_NO_STORE
setopt		HIST_REDUCE_BLANKS
setopt		HIST_SAVE_BY_COPY
unsetopt	HIST_SAVE_NO_DUPS
setopt		HIST_VERIFY
setopt		INC_APPEND_HISTORY
setopt		SHARE_HISTORY

# I/O
setopt		ALIASES
unsetopt	CLOBBER
setopt		CORRECT
unsetopt	CORRECT_ALL
unsetopt	DVORAK
unsetopt	FLOWCONTROL
unsetopt	IGNORE_EOF
setopt		INTERACTIVE_COMMENTS
setopt		HASH_CMDS
setopt		HASH_DIRS
unsetopt	MAIL_WARNING
unsetopt	PATH_DIRS
unsetopt	PRINT_EIGHT_BIT
unsetopt	PRINT_EXIT_VALUE
setopt		RC_QUOTES
unsetopt	RM_STAR_SILENT
unsetopt	RM_STAR_WAIT
setopt		SHORT_LOOPS
unsetopt	SUN_KEYBOARD_HACK

# Job Control
setopt		AUTO_CONTINUE
unsetopt	AUTO_RESUME
setopt		BG_NICE
setopt		CHECK_JOBS
setopt		HUP
setopt		LONG_LIST_JOBS
setopt		MONITOR
setopt		NOTIFY

# Shell Emulation
unsetopt	BASH_REMATCH
unsetopt	BSD_ECHO
unsetopt	CSH_JUNKIE_HISTORY
unsetopt	CSH_JUNKIE_LOOPS
unsetopt	CSH_JUNKIE_QUOTES
unsetopt	CSH_NULLCMD
unsetopt	KSH_ARRAYS
unsetopt	KSH_AUTOLOAD
unsetopt	KSH_OPTION_PRINT
unsetopt	KSH_TYPESET
unsetopt	KSH_ZERO_SUBSCRIPT
unsetopt	POSIX_ALIASES
unsetopt	POSIX_BUILTINS
unsetopt	POSIX_IDENTIFIERS
unsetopt	SH_FILE_EXPANSION
unsetopt	SH_NULLCMD
unsetopt	SH_OPTION_LETTERS
unsetopt	SH_WORD_SPLIT
unsetopt	TRAPS_ASYNC

# ZLE
setopt		BEEP
unsetopt	COMBINING_CHARS
setopt		EMACS
unsetopt	OVERSTRIKE
unsetopt	SINGLE_LINE_ZLE
unsetopt	VI
setopt		ZLE