summaryrefslogtreecommitdiff
path: root/.config/zsh/rc
blob: 7ae93e23c17ca96031ed35669ab5a4a2a9b95340 (plain)
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
91
92
93
94
95
96
if type brew &>/dev/null; then
  brewprefix=$(brew --prefix)
  FPATH="${XDG_DATA_HOME:-${HOME}/.local/share}/zsh-completions:$brewprefix/share/zsh-completions:$brewprefix/share/zsh/site-functions:$FPATH"
fi

autoload -Uz compinit && compinit
autoload bashcompinit && bashcompinit



zmodload zsh/complist
zstyle ':completion:*' menu select
function insert-and-complete-again() {
  zle expand-or-complete-prefix
  zle list-choices
}
zle -N insert-and-complete-again
bindkey '^I' insert-and-complete-again

_comp_options+=(globdots)		# Include hidden files.
# Use vim keys in tab complete menu:
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history

[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc"
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutenvrc" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutenvrc"
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc"
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc"
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/zsh/local.rc" ] && . "${XDG_CONFIG_HOME:-$HOME/.config}/zsh/local.rc"

autoload -U select-word-style && select-word-style bash

# Enable prompt substitutions and colors
autoload -U colors && colors
setopt PROMPT_SUBST

# History settings
HISTSIZE=100000
HISTFILE=~/.zsh_history
SAVEHIST=100000
setopt HIST_IGNORE_SPACE
setopt HIST_IGNORE_ALL_DUPS
setopt APPEND_HISTORY

# Titlebar update before each prompt
precmd() {
  print -Pn '\e]0;%~'
  [[ -n "$IN_KAKOUNE_CONNECT" ]] && print -Pn " - $KAKOUNE_CLIENT@[$KAKOUNE_SESSION]"
  [[ -n "$TERM" ]] && print -Pn " - $TERM"
  print -Pn '\a'
}

# Kakoune session info
kak_session='${IN_KAKOUNE_CONNECT:+¶$KAKOUNE_SESSION}'

# Terraform info evaluated at prompt time
terraform_info='$(fd --exact-depth=1 --extension=tf --quiet && terraform workspace show 2>/dev/null | sed "s/.*/🥡 &/")'

# Git branch evaluated at prompt time
git_branch='$(git branch --show-current 2>/dev/null | sed "s/.*/ &/" 2>/dev/null)'

# Final prompt
PROMPT='%{$fg[green]%}%n@%m %{$fg[blue]%}'"$kak_session"' %{$fg[yellow]%}%(5~|%-2~/…/%3~|%4~)%f %F{5}'$terraform_info'%f %F{9}$(echo '"$git_branch"')%f
%{$fg[cyan]%}λ%f '

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/opt/homebrew/share/google-cloud-sdk/path.zsh.inc' ]; then . '/opt/homebrew/share/google-cloud-sdk/path.zsh.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/opt/homebrew/share/google-cloud-sdk/completion.zsh.inc' ]; then . '/opt/homebrew/share/google-cloud-sdk/completion.zsh.inc'; fi

km() {
echo "map global ${1:?} ${2:?} %{<esc>:make-once $(history -1 | sed 's/[[:space:]]*[0-9]*[[:space:]]*\(.*\)/\1/')<ret>}" | kak -p $KAKOUNE_SESSION
}
alias kmp='km pistarchio '

# Use lf to switch directories and bind it to ctrl-o
lfcd () {
    tmp="$(mktemp -uq)"
    trap 'rm -f $tmp >/dev/null 2>&1 && trap - HUP INT QUIT TERM PWR EXIT' HUP INT QUIT TERM PWR EXIT
    lf -last-dir-path="$tmp" "$@"
    if [ -f "$tmp" ]; then
        dir="$(cat "$tmp")"
        [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir" && c
    fi
}
bindkey -s '^o' 'y\n'

autoload -z edit-command-line
my-edit-command-line() {
  EDITOR=kak edit-command-line
}
zle -N my-edit-command-line
bindkey '^X^E' my-edit-command-line