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 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 HISTFILE="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/history" # Load aliases and shortcuts if existent. [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/aliasrc" [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" # 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. # Use lf to switch directories and bind it to ctrl-o lfcd () { tmp="$(mktemp)" fid="$(mktemp)" lf -command '$printf $id > '"$fid"'' -last-dir-path="$tmp" "$@" id="$(cat "$fid")" archivemount_dir="/tmp/__lf_archivemount_$id" if [ -f "$archivemount_dir" ]; then cat "$archivemount_dir" | \ while read -r line; do sudo umount "$line" rmdir "$line" done command rm -f "$archivemount_dir" fi if [ -f "$tmp" ]; then dir="$(cat "$tmp")" command rm -f "$tmp" if [ -d "$dir" ]; then if [ "$dir" != "$(pwd)" ]; then cd "$dir" fi fi fi tput cuu1;tput el } _lfcd () { BUFFER="lfcd" zle accept-line } zle -N _lfcd bindkey '^o' _lfcd # bind lazygit to ctrl-g lg () { [ ! -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 } zle -N lg{,} bindkey '^g' lg # This function simply writes the venv of the last executed command to a file to be read by external status indicators function write_venv(){ echo -n "${VIRTUAL_ENV:t}" > "/tmp/current_venv-$$" } add-zsh-hook precmd write_venv # Edit line in vim with ctrl-e: bindkey '^e' edit-command-line # 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 # other options zle_highlight+=(paste:none) 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" [ -f "$PLUGINS_HOME/autopyenv/autopyenv.plugin.zsh" ] && source "$PLUGINS_HOME/autopyenv/autopyenv.plugin.zsh"