function() # Keep local variables in here. { # Initialize completions. autoload -Uz compinit compinit -d "${ZSH_CACHE_DIR}/.zcompdump" ############################## Plugins ######################################### # Hyphen-insensitive completion. Case sensitive completion must be off. _ and - # will be interchangeable. HYPHEN_INSENSITIVE="true" # Enable command auto-correction. ENABLE_CORRECTION="true" # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md export ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) # Set up in .zprofile. source ${ZSH_PLUGIN_SOURCE} # Fuzzy finder, . export FZF_CTRL_R_OPTS="--layout=reverse" if [[ -f /usr/share/fzf/key-bindings.zsh ]]; then # Current Gentoo path. source /usr/share/fzf/key-bindings.zsh elif [[ -f /usr/share/fzf/fzf.zsh ]]; then source /usr/share/fzf/fzf.zsh elif [[ -f /usr/share/zsh/site-contrib/fzf.zsh ]]; then source /usr/share/zsh/site-contrib/fzf.zsh fi # zstyle ':fzf-tab:*' fzf-command ftb-tmux-popup zstyle ':fzf-tab:complete:*:*' popup-pad 200 2 # Add padding [right, bottom] zstyle ':completion:*:descriptions' format '[%d]' zstyle ':fzf-tab:*' show-group none zstyle ':fzf-tab:*' prefix '' zstyle ':fzf-tab:complete:(ls|rmdir|grep):argument-rest' fzf-preview 'ls -1 --color=always $realpath' zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls -1 --color=always $realpath' zstyle ':fzf-tab:complete:rg:operand-argument-rest' fzf-preview 'ls -1 --color=always $realpath' zstyle ':fzf-tab:complete:(less|cat):argument-rest' fzf-preview 'less $realpath' zstyle ':fzf-tab:complete:emacsclient:*' fzf-preview 'less $realpath' zstyle ':fzf-tab:complete:(lessp|evince|mpv):*argument-rest' fzf-preview 'LESSOPEN="|lesspipe %s" less $realpath' zstyle ':fzf-tab:complete:file:*' fzf-preview 'file --brief $realpath' zstyle ':fzf-tab:complete:git-log:argument-1' fzf-preview 'git log --color=always $word' zstyle ':fzf-tab:complete:git-show:argument-rest' fzf-preview 'git show --color=always $word' zstyle ':fzf-tab:complete:git-(add|diff|restore):argument-1' fzf-preview 'git diff --color=always $word' zstyle ':fzf-tab:complete:man:*' fzf-preview 'whatis -l $word | cut -d- -f2,3,4,5,6' async_init ############################# History ########################################## # One of the plugins in ${ZSH_PLUGIN_SOURCE} is changing history options. export HISTSIZE=50000 # In memory. export SAVEHIST=10000 # On disk. # Stamp shown in the history command output. # The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" HIST_STAMPS="yyyy-mm-dd" # Write command to history file after it is finished, with time and duration. # setopt NO_SHARE_HISTORY EXTENDED_HISTORY INC_APPEND_HISTORY_TIME setopt EXTENDED_HISTORY SHARE_HISTORY # Import new commands from the history file. function precmd_history { fc -RI } # precmd_functions+=precmd_history ############################## Completion ###################################### # Configure completions. zstyle ':completion::complete:*' cache-path "${ZSH_CACHE_DIR}/.zcompcache" zstyle ':completion:*' completer _complete _ignored _approximate zstyle ':completion:*' file-sort modification # access didn't work. # Not sure why the next line is needed. Maybe fzf-tab is setting it to true? zstyle ':completion:complete:*' sort false # Needed for file-sort. zstyle ':completion:complete:*:options' sort false # Don't sort command options. zstyle ':completion:*:*:*:*:processes' \ command "ps -u $USER -o pid,user,comm,cmd -w -w" compdef '_dispatch git git' config # git completions for config. ################################################################################ function generate_terminfo_24bit() { if [[ -z "${1}" ]]; then echo "Usage: generate_terminfo_24bit " >&2 return fi terminal="${1}" if [[ -z "${TMPDIR}" ]]; then local TMPDIR="/tmp" fi # Generate ${terminal}-24bit(s). cat < ${TMPDIR}/terminfo-24bit.src # Use colon separators. ${terminal}-24bit|${terminal} with 24-bit direct color mode, use=${terminal}-256color, setb24=\E[48:2:%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm, setf24=\E[38:2:%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm, # Use semicolon separators. ${terminal}-24bits|${terminal} with 24-bit direct color mode, use=${terminal}-256color, setb24=\E[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm, setf24=\E[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm, EOF tic -x -o ~/.terminfo ${TMPDIR}/terminfo-24bit.src rm ${TMPDIR}/terminfo-24bit.src } case ${TERM} in (xterm* | tmux* | rxvt* | screen* | alacritty) DISABLE_AUTO_TITLE="true" # Write some info to terminal title. # This is seen when the shell prompts for input. function precmd_title { print -Pn "\e]0;%m: %(1j,%j job%(2j|s|); ,)%~\a" } precmd_functions+=precmd_title # Write command and args to terminal title. # This is seen while the shell waits for a command to complete. function preexec_title { printf "\e]0;%s: %s; %s\a" "${HOST}" "${1}" "$(print -Pn %~)" } preexec_functions+=preexec_title # # Enable TrueColor. # if [[ "${COLORTERM}" = "truecolor" || "${TERM}" =~ "24bit" ]]; then # [[ ! -e ~/.terminfo/x/xterm-24bit ]] && generate_terminfo_24bit "xterm" # [[ ! -e ~/.terminfo/r/rxvt-unicode-24bit ]] \ # && generate_terminfo_24bit "rxvt-unicode" # [[ ! -e ~/.terminfo/t/tmux-24bit ]] && generate_terminfo_24bit "tmux" # [[ ! -e ~/.terminfo/s/screen-24bit ]] && generate_terminfo_24bit "screen" # export TERM="${TERM//256color/24bit}" # export COLORTERM="truecolor" # fi # tmux-direct is available since ncurses-6.2-p20201003. if [[ "${TERM}" == "tmux-256color" ]] \ && [[ "${COLORTERM}" == "truecolor" ]]; then if [[ -f "/usr/share/terminfo/t/tmux-direct" ]]; then alias $(command -v emacsclient)="TERM=tmux-direct $(command -v emacsclient)" alias $(command -v emacsremote)="TERM=tmux-direct $(command -v emacsremote)" fi fi ;; (dumb) # Emacs shells and TRAMP. unsetopt zle if [[ "${INSIDE_EMACS}" =~ "tramp" ]]; then HISTFILE="/dev/null" fi alias less='cat' alias more='cat' export PAGER='cat' ;; esac # Host specific settings. case $(hostname) in schnibble | gaffer | localhost) function sudo() { su -c "${*}" } local DEFAULT_USER="u0_a197" ;; esac # Make sure each function is only called 1 time. precmd_functions=(${(u)precmd_functions}) preexec_functions=(${(u)preexec_functions}) [[ -f "${ZDOTDIR}"/zkeys ]] && source "${ZDOTDIR}"/zkeys [[ -f "${ZDOTDIR}"/zaliases ]] && source "${ZDOTDIR}"/zaliases [[ -d "${ZDOTDIR}"/functions ]] && autoload -Uz "${ZDOTDIR}"/functions/* local DEFAULT_USER="${DEFAULT_USER:-tastytea}" [[ -f ${ZDOTDIR}/tastytea.zsh-theme ]] && source ${ZDOTDIR}/tastytea.zsh-theme return 0 }