1
0
Fork 0
dotfiles-server/.config/zsh/.zshrc

114 lines
3.7 KiB
Bash
Raw Normal View History

2023-02-06 12:01:39 +01:00
autoload -U colors && colors
autoload edit-command-line && zle -N edit-command-line
autoload -U add-zsh-hook
autoload -U compinit
autoload -Uz edit-command-line
2022-08-05 13:48:53 +02:00
PS1="%B%F{blue}%n%F{cyan}@%F{blue}%m %F{magenta}[%f%3~%F{magenta}] %(?.%F{green}.%F{red})»%f%b "
RPS1="%(?..%F{red}%?)"
stty stop undef # Disable ctrl-s to freeze terminal.
setopt HIST_IGNORE_ALL_DUPS HIST_REDUCE_BLANKS HIST_VERIFY BANG_HIST interactive_comments autocd
# History in cache directory:
HISTSIZE=10000000
SAVEHIST=10000000
2023-02-06 12:01:39 +01:00
HISTFILE="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/history"
2022-08-05 13:48:53 +02:00
2023-02-06 12:01:39 +01:00
# Load aliases and shortcuts if existent.
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc"
2022-08-05 13:48:53 +02:00
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc"
2023-02-06 12:01:39 +01:00
[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc"
2022-08-05 13:48:53 +02:00
# Basic auto/tab complete:
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit
_comp_options+=(globdots) # Include hidden files.
# vi mode
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
bindkey -v
export KEYTIMEOUT=1
# 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
# Change cursor shape for different vi modes.
function zle-keymap-select () {
case $KEYMAP in
vicmd) echo -ne '\e[1 q';; # block
viins|main) echo -ne '\e[5 q';; # beam
esac
}
zle -N zle-keymap-select
zle-line-init() {
zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
echo -ne "\e[5 q"
}
zle -N zle-line-init
echo -ne '\e[5 q' # Use beam shape cursor on startup.
preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.
2023-06-14 22:12:51 +02:00
# Set the titlestring
function write_title_cmd() {
if [ ${1[(w)1]} != "lfwrap" ]; then
echo -ne "\033]0;$(print -P "%n@%m [%3~] » ${1[(w)1]}")\007"
fi
}
add-zsh-hook preexec write_title_cmd
function write_title_wd() { echo -ne "\033]0;$(print -P "%n@%m [%3~]")\007" }
add-zsh-hook precmd write_title_wd
2023-11-24 23:59:52 +01:00
function reset_beam() { echo -ne '\e[5 q' }
2022-08-05 13:48:53 +02:00
# Use lf to switch directories and bind it to ctrl-o
2023-11-24 16:00:50 +01:00
function lfwrap () {
LF_DIRFILE="/tmp/lfdir.$(uuidgen)"
2023-11-24 23:59:52 +01:00
lf -last-dir-path="$LF_DIRFILE"
2023-11-24 16:00:50 +01:00
dir="$(cat "$LF_DIRFILE")"
2023-11-26 19:20:48 +01:00
\rm "$LF_DIRFILE"
2023-11-24 16:00:50 +01:00
if [ -d "$dir" ]; then
if [ "$dir" != "$(pwd)" ]; then
cd "$dir"
fi
2022-08-05 13:48:53 +02:00
fi
2023-11-24 16:00:50 +01:00
zle reset-prompt
zle redisplay
write_title_wd
reset_beam
2022-08-05 13:48:53 +02:00
}
2023-11-24 16:00:50 +01:00
zle -N lfwrap
2023-11-24 23:59:52 +01:00
bindkey '^e' lfwrap
2022-08-05 13:48:53 +02:00
# bind lazygit to ctrl-g
lg () {
2023-02-06 12:01:39 +01:00
[ ! -d "$(pwd)/.git" ] && [[ $(read -ek "?Not in a git repository. Create a new git repository? (y/n): ") =~ ^[Yy]$ ]] && git init
[ -d "$(pwd)/.git" ] && lazygit -p $(pwd)
zle reset-prompt
2022-08-05 13:48:53 +02:00
}
2023-02-06 12:01:39 +01:00
zle -N lg{,}
bindkey '^g' lg
2022-08-05 13:48:53 +02:00
# Edit line in vim with ctrl-e:
2023-03-18 13:52:33 +01:00
# autoload edit-command-line; zle -N edit-command-line
# bindkey '^e' edit-command-line
2022-08-05 13:48:53 +02:00
# other keybinds
bindkey -v '^?' backward-delete-char
bindkey '^[[P' delete-char
bindkey "^[[H" beginning-of-line
bindkey '^[[F' end-of-line
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word
2023-02-06 12:01:39 +01:00
# plugins
PLUGINS_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/zsh/plugins"
[ -f "$PLUGINS_HOME/fzf/key-bindings.zsh" ] && source "$PLUGINS_HOME/fzf/key-bindings.zsh"
[ -f "$PLUGINS_HOME/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh" ] && source "$PLUGINS_HOME/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh"
2024-01-28 12:46:51 +01:00
2024-02-09 12:55:47 +01:00
gpg-connect-agent updatestartuptty /bye 1>/dev/null