btw i use nix
1
2# https://www.emacswiki.org/emacs/TrampMode#h5o-9
3[[ $TERM == "dumb" ]] && unsetopt zle && PS1='$ ' && return
4
5setopt autocd nomatch notify interactive_comments inc_append_history
6unsetopt beep extendedglob share_history
7
8# https://superuser.com/questions/476532/how-can-i-make-zshs-vi-mode-behave-more-like-bashs-vi-mode
9vi-search-fix() {
10 zle vi-cmd-mode
11 zle .vi-history-search-backward
12}
13autoload vi-search-fix
14zle -N vi-search-fix
15bindkey -M viins '\e/' vi-search-fix
16
17bindkey -v
18autoload -Uz edit-command-line
19zle -N edit-command-line
20bindkey -M vicmd V edit-command-line
21
22autoload zmv
23
24# set window title
25# https://wiki.archlinux.org/title/zsh#xterm_title
26autoload -Uz add-zsh-hook
27
28function xterm_title_precmd () {
29 print -Pn -- '\e]2;%n@%m:%~\a'
30}
31
32function xterm_title_preexec () {
33 print -Pn -- '\e]2;%n@%m:%~ %# ' && print -n -- "${(q)1}\a"
34}
35
36if [[ "$TERM" != "linux" ]]; then
37 add-zsh-hook -Uz precmd xterm_title_precmd
38 add-zsh-hook -Uz preexec xterm_title_preexec
39fi
40
41
42autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
43zle -N up-line-or-beginning-search
44zle -N down-line-or-beginning-search
45
46typeset -g -A key
47
48# ANSI escape codes
49
50key[Up]="^[[A"
51key[Down]="^[[B"
52key[Shift-Tab]="^[[Z"
53key[Control-Left]="^[[1;5D"
54key[Control-Right]="^[[1;5C"
55key[Control-Backspace]="^H"
56key[Control-Delete]="^[[3;5~"
57key[Control-R]="^R"
58key[Alt-Left]="^[[1;3D"
59key[Alt-Right]="^[[1;3C"
60key[Alt-Backspace]="^[^?"
61key[Alt-Delete]="^[[3;3~"
62key[Shift-Left]="^[[1;2D"
63key[Shift-Right]="^[[1;2C"
64key[Shift-Delete]="^[[3;2~"
65key[Delete]="^[[3~"
66
67# see zshzle
68
69bindkey "${key[Up]}" up-line-or-beginning-search
70bindkey "${key[Down]}" down-line-or-beginning-search
71bindkey "${key[Shift-Tab]}" reverse-menu-complete
72# uses WORDCHARS
73bindkey "${key[Control-Left]}" backward-word
74bindkey "${key[Control-Right]}" forward-word
75bindkey "${key[Control-Backspace]}" backward-kill-word
76bindkey "${key[Control-Delete]}" kill-word
77
78bindkey "${key[Alt-Left]}" vi-backward-word
79bindkey "${key[Alt-Right]}" vi-forward-word
80bindkey "${key[Alt-Backspace]}" vi-backward-kill-word
81bindkey "${key[Alt-Delete]}" kill-word
82
83bindkey "${key[Shift-Left]}" emacs-backward-word
84bindkey "${key[Shift-Right]}" emacs-forward-word
85bindkey "${key[Shift-Delete]}" kill-word
86
87bindkey "${key[Delete]}" delete-char
88
89# https://github.com/spaceship-prompt/spaceship-prompt/issues/91#issuecomment-327996599
90bindkey "^?" backward-delete-char
91
92# https://unix.stackexchange.com/a/298844
93b() ( yad --info --text "$(date '+%Y-%m-%d %H.%M.%S')\n$(pwd)" --width=150 & while true; do spd-say -t female1 -w "beep beep beep"; sleep 1; done; )
94
95export FZF_TMUX=1
96export FZF_TMUX_OPTS='-d50%' # fzf-tmux --help
97export FZF_DEFAULT_COMMAND="find . -maxdepth 5 \( -path '*/.*' -prune \) -o -print"
98export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
99export FZF_ALT_C_COMMAND="find . -maxdepth 5 \( -path '*/.*' -prune \) -o -type d -print"
100
101if [ -n "${commands[fzf-share]}" ]; then
102 source "$(fzf-share)/key-bindings.zsh"
103 source "$(fzf-share)/completion.zsh"
104fi
105
106wait-ssh() {
107 while ! timeout 1 ping $1 -c 1; do sleep 1; done; ssh $1
108}
109
110# use ledger bash completions
111autoload bashcompinit
112bashcompinit
113if [ -f /run/current-system/sw/share/bash-completion/completions/ledger.bash ]; then
114 source /run/current-system/sw/share/bash-completion/completions/ledger.bash
115fi
116
117eval $(opam env)