-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_zsh.sh
87 lines (73 loc) · 3.74 KB
/
config_zsh.sh
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
#!/bin/bash
# If this shell supports line editing, bind settings. (If interactive shell)
if [[ "$(set -o | grep 'emacs\|\bvi\b' | cut -f2 | tr '\n' ':')" != 'off:off:' ]]
then
# Enable ctrl-x ctrl-e to edit current command.
autoload -U edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line
# Fix some common keybinds.
# To see keys, run cat, press enter, then hit key combo to see output.
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^[^[[C" forward-word
bindkey "^[^[[D" backward-word
# Load the zmv multiple file moving utility.
autoload zmv
# Use bash word style, which will respect directory delimiters.
autoload -U select-word-style
select-word-style bash
# Just leaving this note here for myself.
# Deleting words forwards/backwards requires configuring what key sequences
# iTerm 2 sends when option+delete or option+fn+delete are pressed.
#
# Add these bindings to iTerm2 Preferences > Keys > Key Bindings:
# - Option + <- Delete (backspace) maps to Send Hex Codes "0x1b 0x7f".
# - Option + Del -> (delete) maps to Send Escape Sequence and enter "d".
# Make history search move to end of line.
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
# History Search Keybinds
# Note the -end, which moves cursor to end of line.
bindkey "^[[A" history-beginning-search-backward-end
bindkey "^[[B" history-beginning-search-forward-end
# Load complist module.
# This should be loaded before compinit so it can populate menu style.
# https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fcomplist-Module
zmodload -i zsh/complist
# Load autocomplete.
# https://thevaluable.dev/zsh-completion-guide-examples/
autoload -U compinit
# compinit will do some checks to make sure permissions are correct.
# Default behavior is to prompt when it finds files with wrong permissions.
# Passing -i will make it never use insecure files.
# Passing -u will make it use insecure files without warning.
compinit -i
# Enable completion extensions.
zstyle ':completion:*' completer _extensions _complete _approximate
# Cache autocomplete for performance.
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache"
# Use tab menu for autocomplete.
zstyle ':completion:*' menu select
bindkey -M menuselect '^[[Z' reverse-menu-complete
# Make autocomplete case-insensetive.
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
# Enable some of my favorite shell options.
# See also: https://zsh.sourceforge.io/Doc/Release/Options.html
set -o autocd # cd to directory if command not found is directory name
set -o autopushd # push to dirs stack when doing cd
set -o pushdignoredups # ignore duplicates in dirs stack
set -o pushdminus # swap behavior of minus and plus in dirs
set -o interactivecomments # allow comments in interactive shell
set -o histignoredups # ignore immediate duplicate entries in history
set -o histignorespace # do not history save commands starting with space
set -o histexpiredupsfirst # expire duplicate entries from history first
set -o extendedhistory # save timestamps and time elapsed to history
set -o histverify # verify history commands before running them
set -o noclobber # do not clobber files with redirection without prompt
set -o completeinword # do completion in this middle of words
set -o longlistjobs # print jobs list in long format
set -o sharehistory # share history between windows
fi