-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_zshrc.tmpl
More file actions
90 lines (79 loc) · 3.31 KB
/
dot_zshrc.tmpl
File metadata and controls
90 lines (79 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# vim: set filetype=bash:
# shellcheck disable=all
if [ -n "$WAYLAND_DISPLAY" ]; then
# Because, unlike in X11, zsh or bash do not start as login shells in Wayland GNOME sessions
source ~/.zprofile
fi
{{template "interactive_shell.tmpl" .}}
# zsh specific history settings.
export SAVEHIST=$HISTSIZE
setopt append_history # Immediately append history instead of overwriting
setopt inc_append_history # Write to history file immediately, not when shell quits
setopt no_extended_history # Disable extended history format for bash compatibility
setopt no_share_history # Also necessary to disable extended history format
setopt hist_ignore_all_dups # If a new command is a duplicate, remove the older one
alias h="fc -R && fc -l -n 1" # Reload history file and list history without command numbers
#
# Tab completions
#
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit
zstyle ':completion:*' rehash true # automatically find new executables in the $PATH
# Fix slow git tab completion, see https://stackoverflow.com/a/9810485/1136455
__git_files() {
_wanted files expl 'local files' _files
}
# Jujutsu command-line completions
if command -v jj &>/dev/null; then
source <(jj util completion zsh)
fi
# KLUDGE: Set default tab completion functions to fix false positives on NixOS (see ~/notes/zsh-notes.md)
zstyle ':completion:*' completer _files _complete
bindkey -v # vi command-line editing
setopt interactive_comments # allow # comments in shell; good for copy/paste
export BLOCK_SIZE="'1" # Add commas to file sizes
typeset -U path # keep duplicates out of the path
setopt extended_glob # extended globbing. Allows using regular expressions with *
setopt autocd # if only directory path is entered, cd there.
#
# Install zsh community projects (https://github.com/zsh-users)
#
# If not already installed then install a zsh-users project and then load it.
# $1 is the zsh-users project Github repository URL.
function load-zsh-users() {
local url="$1"
local dir="$HOME/.zsh/$(basename $1)"
local file="$dir/$(basename $1).zsh"
if [ ! -d $dir ]; then
git clone $url $dir
fi
source $file
}
load-zsh-users https://github.com/zsh-users/zsh-autosuggestions
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=249" # See https://coderwall.com/p/pb1uzq/z-shell-colors
# Mapping Ctrl+Enter to autosuggest-execute is problematic (https://stackoverflow.com/a/45714460/1136455)
bindkey '^@' autosuggest-execute # Ctrl+Space executes current suggestion
load-zsh-users https://github.com/zsh-users/zsh-syntax-highlighting
load-zsh-users https://github.com/zsh-users/zsh-history-substring-search
{{if eq .chezmoi.osRelease.id "manjaro"}}
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
{{else}}
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
{{end}}
export HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=true
# Set up fzf key bindings and fuzzy completion.
if command -v fzf &>/dev/null; then
eval "$(fzf --zsh)"
fi
# Set up zoxide and alias to cd and cdi.
if command -v zoxide &>/dev/null; then
eval "$(zoxide init zsh)"
fi
#
# zsh key bindings
#
# Next/previous in command-line history
bindkey '^n' down-line-or-history
bindkey '^p' up-line-or-history