nixos/home/common/core/zsh.nix

88 lines
2.4 KiB
Nix
Raw Normal View History

2024-05-17 10:54:53 +01:00
{ pkgs, 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
2024-05-24 21:23:56 +01:00
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
2024-05-17 10:54:53 +01:00
'';
};
}