2022-03-18 14:34:27 +01:00
|
|
|
function() # Keep local variables in here.
|
|
|
|
{
|
|
|
|
|
2022-03-25 19:38:23 +01:00
|
|
|
############################## Completion ######################################
|
|
|
|
|
2022-04-01 23:30:25 +02:00
|
|
|
zmodload zsh/complist
|
2022-03-25 19:38:23 +01:00
|
|
|
autoload -Uz compinit && compinit -d "${ZSH_CACHE_DIR}/zcompdump"
|
|
|
|
|
|
|
|
setopt ALWAYS_TO_END COMPLETE_IN_WORD GLOB_COMPLETE
|
|
|
|
|
2022-04-01 23:30:25 +02:00
|
|
|
zmodload zsh/zutil
|
2022-03-25 19:38:23 +01:00
|
|
|
# Configure completions.
|
|
|
|
zstyle ':completion:*' use-cache on
|
|
|
|
zstyle ':completion::complete:*' cache-path "${ZSH_CACHE_DIR}/zcompcache"
|
|
|
|
zstyle ':completion:*' menu select
|
2022-03-28 05:51:56 +02:00
|
|
|
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
|
2022-03-25 19:38:23 +01:00
|
|
|
zstyle ':completion:*' completer _complete _ignored _approximate
|
|
|
|
# Next line is hyphen- and case-insensitive, partial-word and substring
|
|
|
|
# completion, copied from oh-my-zsh.
|
|
|
|
zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'
|
|
|
|
zstyle ':completion:*' file-sort modification # access didn't work.
|
|
|
|
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.
|
|
|
|
|
|
|
|
autoload -Uz +X bashcompinit && bashcompinit
|
2022-03-18 14:34:27 +01:00
|
|
|
|
2022-03-23 23:29:37 +01:00
|
|
|
############################# History ##########################################
|
|
|
|
export HISTSIZE=50000 # In memory.
|
|
|
|
export SAVEHIST=10000 # On disk.
|
|
|
|
# Write command to history file after it is finished, with time and duration.
|
|
|
|
setopt NO_SHARE_HISTORY EXTENDED_HISTORY INC_APPEND_HISTORY_TIME
|
|
|
|
# setopt NO_INC_APPEND_HISTORY_TIME EXTENDED_HISTORY SHARE_HISTORY
|
|
|
|
setopt HIST_EXPIRE_DUPS_FIRST HIST_IGNORE_DUPS
|
2022-03-24 01:24:23 +01:00
|
|
|
setopt HIST_IGNORE_SPACE HIST_REDUCE_BLANKS HIST_VERIFY HIST_FCNTL_LOCK
|
2022-03-23 23:29:37 +01:00
|
|
|
|
|
|
|
# Import new commands from the history file
|
2022-03-24 01:44:34 +01:00
|
|
|
function _my_import_history_zshaddhistory()
|
2022-03-23 23:29:37 +01:00
|
|
|
{
|
2022-03-24 01:08:39 +01:00
|
|
|
fc -RI
|
2022-03-24 01:44:34 +01:00
|
|
|
return 0
|
2022-03-23 23:29:37 +01:00
|
|
|
}
|
|
|
|
autoload -Uz add-zsh-hook
|
2022-03-24 01:44:34 +01:00
|
|
|
add-zsh-hook zshaddhistory _my_import_history_zshaddhistory
|
2022-03-23 23:29:37 +01:00
|
|
|
|
2022-03-18 14:34:27 +01:00
|
|
|
############################## Plugins #########################################
|
|
|
|
|
2022-03-18 15:35:25 +01:00
|
|
|
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
|
2022-04-01 04:37:20 +02:00
|
|
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
|
|
|
|
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=238"
|
2022-03-18 15:35:25 +01:00
|
|
|
|
2022-03-18 14:34:27 +01:00
|
|
|
# Set up in .zprofile.
|
2022-03-28 06:14:46 +02:00
|
|
|
source "${ZSH_PLUGIN_SOURCE}"
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
# Fuzzy finder, <https://github.com/junegunn/fzf>.
|
|
|
|
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
|
|
|
|
|
|
|
|
# <https://github.com/Aloxaf/fzf-tab/wiki/Configuration>
|
|
|
|
zstyle ':fzf-tab:*' fzf-command ftb-tmux-popup
|
|
|
|
zstyle ':fzf-tab:complete:*:*' popup-pad 200 2 # Add padding [right, bottom]
|
|
|
|
|
2022-03-28 05:51:56 +02:00
|
|
|
zstyle ':completion:*:descriptions' format '%F{green}[%d]%f'
|
2022-03-18 14:34:27 +01:00
|
|
|
zstyle ':fzf-tab:*' show-group none
|
|
|
|
zstyle ':fzf-tab:*' prefix ''
|
|
|
|
|
2022-03-22 22:30:11 +01:00
|
|
|
# Use C-x h to get possible contexts for a command
|
2022-03-18 14:34:27 +01:00
|
|
|
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'
|
2022-03-22 22:30:11 +01:00
|
|
|
zstyle ':fzf-tab:complete:(lessp|evince|mpv|cp|mv):*argument-rest' fzf-preview 'LESSOPEN="|lesspipe %s" less $realpath'
|
2022-03-18 14:34:27 +01:00
|
|
|
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'
|
|
|
|
|
2022-03-28 05:13:14 +02:00
|
|
|
[[ -v ASYNC_VERSION && ${ASYNC_INIT_DONE} -eq 0 ]] && async_init
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
2022-04-01 23:30:25 +02:00
|
|
|
# Directory options
|
|
|
|
setopt AUTO_CD AUTO_PUSHD PUSHD_IGNORE_DUPS PUSHD_MINUS
|
|
|
|
# Various options
|
|
|
|
setopt CORRECT_ALL FLOW_CONTROL INTERACTIVE_COMMENTS LONG_LIST_JOBS
|
|
|
|
|
|
|
|
zmodload zsh/terminfo
|
|
|
|
|
2022-03-27 00:11:34 +01:00
|
|
|
# Test for the title setting capability (To Status Line)
|
2022-04-01 23:59:17 +02:00
|
|
|
if echoti tsl > /dev/null 2>&1; then
|
2022-03-27 00:11:34 +01:00
|
|
|
# Write some info to terminal title.
|
|
|
|
# This is seen when the shell prompts for input.
|
|
|
|
function _my_title_precmd() {
|
|
|
|
print -Pn "\e]0;%m: %(1j,%j job%(2j|s|); ,)%~\a"
|
|
|
|
}
|
|
|
|
add-zsh-hook precmd _my_title_precmd
|
|
|
|
# Write command and args to terminal title.
|
|
|
|
# This is seen while the shell waits for a command to complete.
|
|
|
|
function _my_title_preexec() {
|
2022-03-27 00:34:37 +01:00
|
|
|
local _my_jobs_dir
|
|
|
|
print -Pnv _my_jobs_dir "%(1j,%j job%(2j|s|); ,)%~"
|
|
|
|
printf "\e]0;%s: %s; %s\a" "${HOST}" "${1}" "${_my_jobs_dir}"
|
2022-03-27 00:11:34 +01:00
|
|
|
}
|
|
|
|
add-zsh-hook preexec _my_title_preexec
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Translate TrueColor to 256 colors if the terminal doesn't support it
|
|
|
|
[[ "${COLORTERM}" == *(truecolor|24bit)* ]] || zmodload zsh/nearcolor
|
|
|
|
|
2022-03-27 00:50:36 +01:00
|
|
|
# emacsclient 27 (TODO: check later versions) needs this for TrueColor
|
|
|
|
if [[ "${TERM#*-}" == "256color" ]] \
|
|
|
|
&& [[ "${COLORTERM}" == *(truecolor|24bit)* ]] \
|
|
|
|
&& [[ -f "/usr/share/terminfo/t/${TERM%-*}-direct" ]]; then
|
|
|
|
alias $(command -v emacsclient)="TERM=${TERM%-*}-direct $(command -v emacsclient)"
|
|
|
|
alias $(command -v emacsremote)="TERM=${TERM%-*}-direct $(command -v emacsremote)"
|
2022-03-27 00:11:34 +01:00
|
|
|
fi
|
|
|
|
|
2022-03-18 14:34:27 +01:00
|
|
|
case ${TERM} in
|
|
|
|
(dumb) # Emacs shells and TRAMP.
|
2022-03-23 02:37:02 +01:00
|
|
|
unsetopt ZLE
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-03-19 03:54:51 +01:00
|
|
|
[[ -f "${ZDOTDIR}"/zkeys ]] && source "${ZDOTDIR}"/zkeys
|
|
|
|
[[ -f "${ZDOTDIR}"/zaliases ]] && source "${ZDOTDIR}"/zaliases
|
|
|
|
[[ -d "${ZDOTDIR}"/functions ]] && autoload -Uz "${ZDOTDIR}"/functions/*
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
local DEFAULT_USER="${DEFAULT_USER:-tastytea}"
|
2022-03-20 14:33:35 +01:00
|
|
|
[[ -f "${ZDOTDIR}"/themes/prompt.zsh ]] && source "${ZDOTDIR}"/themes/prompt.zsh
|
2022-03-20 20:23:50 +01:00
|
|
|
[[ -f "${ZDOTDIR}"/themes/syntax-unikitty-reversible.zsh ]] && source "${ZDOTDIR}"/themes/syntax-unikitty-reversible.zsh
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
}
|