nixos-config/modules/home/zsh.nix

312 lines
9.4 KiB
Nix
Raw Normal View History

{
hostname,
config,
pkgs,
host,
lib,
...
}:
2023-11-05 17:56:55 +01:00
{
2024-06-21 09:40:23 +02:00
programs = {
zsh = {
2023-11-05 11:40:44 +01:00
enable = true;
2024-06-21 09:40:23 +02:00
autocd = true;
autosuggestion.enable = true;
#syntaxHighlighting = {
# enable = true;
# highlighters = [
# "main"
# "brackets"
# "pattern"
# "regexp"
# "cursor"
# "root"
# "line"
# ];
#};
defaultKeymap = "viins";
2024-06-21 09:40:23 +02:00
enableCompletion = true;
# enableGlobalCompInit = true; # Should be a thing according to NixOS options but is not a thing?
2023-12-16 00:05:49 +01:00
2024-06-21 09:40:23 +02:00
localVariables = {
# Looks like this: '~/some/path > '
2025-10-30 17:48:59 +01:00
PS1 = "> %F{magenta}%~%f > ";
RPROMPT = "%F{magenta}%m";
2024-06-21 09:40:23 +02:00
# Gets pushed to the home directory otherwise
LESSHISTFILE = "/dev/null";
# Make Vi mode transitions faster (in hundredths of a second)
# KEYTIMEOUT = 1;
LANG = "en_US.UTF-8";
2024-09-25 14:08:59 +02:00
EDITOR = "nvim";
SYSTEMD_LESS = "FRXMK"; # Fix weird sideways scrolling in systemctl status ...
2024-06-21 09:40:23 +02:00
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE = "fg=#808080";
ZSH_AUTOSUGGEST_USE_ASYNC = 1;
HISTSIZE = 10000000;
SAVEHIST = 10000000;
HISTFILE = "~/.zsh_history";
HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE = 1;
KEYTIMEOUT = 1; # make Vi-mode transitions faster
2024-06-21 09:40:23 +02:00
};
2023-11-05 11:40:44 +01:00
initContent = ''
export export PATH="''${PATH}:''${HOME}/.local/bin/:''${HOME}/.cargo/bin/:''${HOME}/.fzf/bin/"
2024-07-26 14:02:03 +02:00
autoload -U add-zsh-hook
autoload -U compinit
zmodload zsh/complist
autoload -U edit-command-line
zmodload zsh/zpty
# Corrections
setopt correct
# Enable Ctrl-X Ctrl-E
autoload edit-command-line
zle -N edit-command-line
bindkey '^Xe' edit-command-line
2024-07-26 14:02:03 +02:00
# History stuff
setopt append_history
setopt inc_append_history
setopt share_history
setopt extended_history
setopt hist_reduce_blanks
setopt hist_ignore_space
2024-07-26 14:02:03 +02:00
# Disable annoying beep
setopt no_beep
# Fix comments
setopt interactive_comments
bindkey '^[[H' beginning-of-line # Home
bindkey '^[[F' end-of-line # End
bindkey "^[[1;5C" forward-word # Ctrl+Right
bindkey "^[[1;5D" backward-word # Ctrl+Left
# Menu selection
bindkey -M menuselect '^@' accept-and-infer-next-history # Ctrl+Space
# Make Alt-Backspace delete till ~!#$%^&*(){}[]<>?+; the way OMZ does
backward-delete-word-but-better () {
local WORDCHARS='~!#$%^&*(){}[]<>?+;'
zle backward-delete-word
}
zle -N backward-delete-word-but-better
2024-07-26 14:02:03 +02:00
bindkey '\e^?' backward-delete-word-but-better
# Completions
#
# Cache so it's a bit quicker
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache"
# File list like ls -l
zstyle ':completion:*' file-list all
# Glorious menu
zstyle ':completion:*' menu select
# Always tab complete
zstyle ':completion:*' insert-tab false
# Comments
zstyle ':completion:*' verbose yes
# Tab key behaviour
zstyle ':autocomplete:tab:*' widget-style menu-complete
# Make set // to be / instead of default /*/
zstyle ':completion:*' squeeze-slashes true
# Complete options
zstyle ':completion:*' complete-options true
# Complete partial words (such as 3912 > _DSC3912.JPG)
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# Move around completion menu with Vi keys
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'l' vi-forward-char
2024-09-25 14:08:59 +02:00
2024-07-26 14:02:03 +02:00
function jitsi-link() {
url=$(printf "https://meet.jit.si/%s" "$(uuidgen)")
printf "%s" "''${url}" | wl-copy
printf "%s\n" "''${url}"
}
function nixcd () {
2025-07-26 19:06:51 +02:00
PACKAGE_NAME="$1"
if [[ "$PACKAGE_NAME" = "" ]]; then
echo "Usage: nixcd <package name>"
fi
PKGINSTORE="$(NIXPKGS_ALLOW_UNFREE=1 nix path-info nixpkgs#$PACKAGE_NAME --impure)"
if [[ -d "$PKGINSTORE" ]]; then
cd $PKGINSTORE
else
echo "Could not find path for package: $PKGINSTORE"
return 1
fi
}
# Enter a 'nix shell' with packages selected by fzf
source ${pkgs.nix-search-fzf.zsh-shell-widget}/bin/nix-search-fzf-shell-widget
zle -N nix-search-fzf-shell-widget
bindkey '^O' nix-search-fzf-shell-widget
# Use fzf as a history widget
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget
bindkey -M viins '^R' fzf-history-widget
bindkey -M vicmd '^R' fzf-history-widget
# Use fzf as a cd completion widget
zle -N fzf-cd-widget
bindkey '^G' fzf-cd-widget
# Use fzf as a file completion widget
zle -N fzf-file-widget
bindkey '^F' fzf-file-widget
2025-06-03 16:14:44 +02:00
# if [[ $(which sxiv&>/dev/null && echo 1) == "1" ]]; then
# alias imv="sxiv"
# elif [[ $(which nsxiv&>/dev/null && echo 1) == "1" ]]; then
# alias imv="nsxiv"
# alias sxiv="nsxiv"
# fi
function preexec {
print -Pn "\e]0;$\{(q)1}\e\\"
}
2024-07-26 14:02:03 +02:00
'';
2024-09-25 14:08:59 +02:00
zsh-abbr = {
enable = true;
abbreviations = {
mkdir = "mkdir -p";
vim = "nvim";
v = "nvim";
vi = "nvim";
nv = "nvim";
nvi = "nvim";
gc = "git clone";
ga = "git add .";
gcm = "git commit -m";
gph = "git push -u origin main";
g = "git";
2025-07-27 00:16:39 +02:00
gp = "git pull";
wiki = "wikit";
2024-09-25 14:08:59 +02:00
};
};
# setOptions = [
# # Corrections
# "CORRECT"
#
# # History stuff
# "APPEND_HISTORY"
# "INC_APPEND_HOSTORY"
# "SHARE_HISTORY"
# "EXTENDED_HISTORY"
# "HIST_REDUCT_BLANKS"
# "HIST_IGNORE_SPACE"
#
# # Disable annoying beep
# "NO_BEEP"
# # Fix comments
# "INTERACTIVE_COMMENTS"
# ];
2024-06-21 09:40:23 +02:00
shellAliases = {
2024-12-05 11:33:35 +01:00
spt = "spotify_player";
2024-10-04 12:12:10 +02:00
convert = "magick";
2024-06-21 09:41:58 +02:00
ls = "eza -lh --git";
la = "eza -A --git";
ll = "eza -l --git";
2024-06-21 09:40:23 +02:00
lla = "eza -lA";
2024-07-08 18:45:18 +02:00
":q" = "exit";
2024-06-21 09:40:23 +02:00
ezit = "exit";
2024-06-30 01:26:13 +02:00
wlc = "wl-copy";
2024-06-21 09:40:23 +02:00
yt-dlp-audio = "yt-dlp -f 'ba' -x --audio-format mp3";
open = "xdg-open";
tree = "eza --icons --tree --group-directories-first";
doas = "sudo";
2025-06-03 16:14:44 +02:00
sxiv = "nsxiv";
2025-06-14 12:50:00 +02:00
enby = "man";
woman = "man";
2025-08-03 12:21:14 +02:00
mkcd = "mkdir $1 && cd $1";
du = "dust";
cp = "cp -i -v";
mv = "mv -i -v";
cd = "z";
rm = "rm -i -v";
cat = "${lib.getExe pkgs.bat} --plain";
diff = "${lib.getExe pkgs.delta} --color-only";
battery-left = "${lib.getExe pkgs.acpi} | cut -d' ' -f5";
github-actions = "${lib.getExe pkgs.act} -s GITHUB_TOKEN=\"$(${lib.getExe pkgs.github-cli} auth token)\"";
tailscale = "sudo tailscale";
2023-11-05 11:40:44 +01:00
2024-06-21 09:40:23 +02:00
# NixOS
ns = "nix-shell --run zsh";
nix-shell = "nix-shell --run zsh";
nix-switch = "sudo nixos-rebuild switch --flake ~/nixos-config#${host}";
nix-switch-upgrade = "sudo nixos-rebuild switch --upgrade --flake ~/nixos-config#${host}";
2024-06-21 09:40:23 +02:00
nix-flake-update = "sudo nix flake update ~/nixos-config#";
nix-clean = "sudo nix-collect-garbage && sudo nix-collect-garbage -d && sudo rm /nix/var/nix/gcroots/auto/* && nix-collect-garbage && nix-collect-garbage -d";
};
2023-11-05 21:55:37 +01:00
2024-06-21 09:40:23 +02:00
plugins = with pkgs; [
{
name = "zsh-syntax-highlighting";
src = fetchFromGitHub {
owner = "zsh-users";
repo = "zsh-syntax-highlighting";
rev = "0.6.0";
sha256 = "0zmq66dzasmr5pwribyh4kbkk23jxbpdw4rjxx0i7dx8jjp2lzl4";
};
file = "zsh-syntax-highlighting.zsh";
}
2024-06-21 09:40:23 +02:00
{
name = "zsh-autopair";
src = fetchFromGitHub {
owner = "hlissner";
repo = "zsh-autopair";
rev = "34a8bca0c18fcf3ab1561caef9790abffc1d3d49";
sha256 = "1h0vm2dgrmb8i2pvsgis3lshc5b0ad846836m62y8h3rdb3zmpy1";
};
file = "autopair.zsh";
}
{
name = "zsh-vi-mode";
file = "zsh-vi-mode.plugin.zsh";
src = pkgs.fetchFromGitHub {
owner = "jeffreytse";
repo = "zsh-vi-mode";
rev = "3eeca1bc6db172edee5a2ca13d9ff588b305b455";
sha256 = "0na6b5b46k4473c53mv1wkb009i6b592gxpjq94bdnlz1kkcqwg6";
};
}
{
name = "fzf-zsh-plugin";
src = fetchFromGitHub {
owner = "unixorn";
repo = "fzf-zsh-plugin";
rev = "04ae801499a7844c87ff1d7b97cdf57530856c65";
sha256 = "sha256-FEGhx36Z5pqHEOgPsidiHDN5SXviqMsf6t6hUZo+I8A=";
};
file = "fzf-zsh-plugin.plugin.zsh";
}
2024-06-21 09:40:23 +02:00
];
2023-11-05 11:40:44 +01:00
};
2024-06-21 09:40:23 +02:00
fzf = {
enable = true;
enableZshIntegration = true;
};
2024-06-21 09:40:23 +02:00
zoxide = {
enable = true;
enableZshIntegration = true;
};
2023-12-06 22:05:30 +01:00
};
home.packages = with pkgs; [
dust
fd
delta
bat
nix-search-fzf.zsh-shell-widget
];
2023-11-05 11:40:44 +01:00
}