nixos/home/common/core/zsh.nix

105 lines
3.0 KiB
Nix

{ config, ... }: {
programs.zsh = {
enable = true;
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
shellAliases = {
ll = "ls -l";
};
history.size = 10000;
history.path = "${config.xdg.dataHome}/zsh/history";
initExtra = ''
bindkey -v
bindkey "^H" backward-delete-char
bindkey "^?" backward-delete-char
set -o vi
export TERM=xterm-256color
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
SESSION_TYPE="(ssh) "
fi
####
# Format prompt
####
# Define colors
COLOR_RED="red"
COLOR_MAGENTA="92"
COLOR_YELLOW="3"
COLOR_GREEN="36"
COLOR_BLUE="4"
COLOR_WHITE="7"
# Format git colors
autoload -Uz compinit && compinit
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
add-zsh-hook precmd vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats " %F{cyan}%c%u(%b)%f"
zstyle ':vcs_info:*' actionformats " %F{cyan}%c%u(%b)%f %a"
zstyle ':vcs_info:*' stagedstr "%F{$COLOR_RED}"
zstyle ':vcs_info:*' unstagedstr "%F{$COLOR_RED}"
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
+vi-git-untracked() {
if git --no-optional-locks status --porcelain 2> /dev/null | grep -q "^??"; then
hook_com[staged]+="%F{$COLOR_RED}"
elif git --no-optional-locks status --porcelain 2> /dev/null | grep -q "^A"; then
hook_com[staged]+="%F{$COLOR_YELLOW}"
else
hook_com[staged]+="%F{$COLOR_GREEN}"
fi
}
# Format prompt
setopt PROMPT_SUBST
PROMPT='%F{'$COLOR_GREEN'}'$(echo "$SESSION_TYPE")'''
PROMPT+='%F{'$COLOR_RED'}['
PROMPT+='%F{'$COLOR_GREEN'}%n'
PROMPT+='%F{red}@'
PROMPT+='%F{'$COLOR_YELLOW'}%m'
PROMPT+='%F{'$COLOR_RED'}] '
PROMPT+='%F{'$COLOR_WHITE'}['
PROMPT+='%F{'$COLOR_YELLOW'}%1~'
PROMPT+='%F{'$COLOR_WHITE'}]'
PROMPT+='$'
PROMPT+='vcs_info_msg_0_'
PROMPT+=' > '
export PROMPT
setopt autocd # Automatically cd into typed directory.
stty stop undef # Disable ctrl-s to freeze terminal.
setopt interactive_comments
# General opts
HISTSIZE=10000000
SAVEHIST=10000000
setopt appendhistory
# 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.
'';
};
}