NixOS/home/programs/zsh.nix

168 lines
5.1 KiB
Nix
Raw Normal View History

2024-11-19 15:46:13 +07:00
{
pkgs,
lib,
config,
...
}:
2024-07-06 22:41:58 +07:00
let
2024-07-07 17:24:15 +07:00
inherit (lib.strings) optionalString concatStrings;
2024-07-06 22:41:58 +07:00
in
2024-06-12 09:54:11 +07:00
{
home.packages = with pkgs; [
eza
bat
gojq
nix-zsh-completions
2024-06-12 09:54:11 +07:00
];
programs.zsh = {
enable = true;
envExtra = # bash
''
# Disable loading global RC files in /etc/zsh/*
# Mostly because they are unneeded
# and global rc files has to be small for security reasons (no plugins)
# thus making them saver for Root account to load them.
unsetopt GLOBAL_RCS
'';
2024-06-12 09:54:11 +07:00
autosuggestion.enable = true;
2024-10-21 21:11:11 +07:00
enableCompletion = false;
2024-06-12 09:54:11 +07:00
defaultKeymap = "emacs";
dirHashes = {
docs = "$HOME/Documents";
dl = "$HOME/Downloads";
videos = "$HOME/Videos";
pictures = "$HOME/Pictures";
};
shellAliases = {
2024-07-12 10:21:06 +07:00
ls = "${pkgs.eza}/bin/eza -lah";
cat = "${pkgs.bat}/bin/bat";
update = "nh os switch -- --accept-flake-config";
superupdate = "nh os switch --update -- --accept-flake-config";
uptest = "nh os test -- --accept-flake-config";
2024-07-12 10:21:06 +07:00
lg = "${pkgs.lazygit}/bin/lazygit";
g = "${pkgs.lazygit}/bin/lazygit";
2024-07-12 10:21:06 +07:00
du = "${pkgs.dust}/bin/dust";
2024-06-12 09:54:11 +07:00
dry = "sudo nixos-rebuild dry-activate --flake $HOME/dotfiles";
2024-07-12 10:21:06 +07:00
jq = "${pkgs.gojq}/bin/gojq";
n = lib.mkIf config.profile.neovide.enable "neovide";
2024-06-12 09:54:11 +07:00
v = "nvim";
2024-06-17 18:21:38 +07:00
cd = "z";
grep = "${pkgs.ripgrep}/bin/rg";
find = "${pkgs.fd}/bin/fd";
2024-06-12 09:54:11 +07:00
};
dotDir = ".config/zsh";
history = {
expireDuplicatesFirst = true;
extended = true;
ignoreAllDups = true;
2024-07-06 22:41:58 +07:00
ignoreSpace = true;
2024-06-12 09:54:11 +07:00
path = "$HOME/.local/share/zsh/zsh_history";
save = 40000;
size = 40000;
};
2024-10-21 21:11:11 +07:00
syntaxHighlighting.enable = true;
initExtraFirst = lib.mkOrder 9999 (concatStrings [
# bash
''
2024-10-21 21:11:11 +07:00
export ZSH_CACHE_DIR=$HOME/.cache/zsh
_ZSH_COLOR_SCHEME_FILE=$HOME/.cache/wallust/sequences
if [ -f "$_ZSH_COLOR_SCHEME_FILE" ]; then
(cat "$_ZSH_COLOR_SCHEME_FILE" &)
fi
mkdir -p $ZSH_CACHE_DIR/completions
fpath+=$ZSH_CACHE_DIR/completions
fpath+=${pkgs.zsh-completions}/share/zsh/site-functions
''
(optionalString config.profile.podman.enable # bash
''
if [ ! -f $ZSH_CACHE_DIR/completions/_podman ]; then
podman completion zsh > $ZSH_CACHE_DIR/completions/_podman
fi
''
)
]);
2024-07-07 17:24:15 +07:00
initExtra = concatStrings [
# bash
2024-07-07 17:24:15 +07:00
''
packfiles() {
find $(NIXPKGS_ALLOW_UNFREE=1 nix build "nixpkgs#$1" --impure --no-link --print-out-paths)
2024-07-07 17:24:15 +07:00
}
2024-07-06 22:41:58 +07:00
build() {
nix build --impure --expr "with import <nixpkgs> {}; callPackage $1 {}"
}
2024-11-19 15:46:13 +07:00
nf() {
local selected=$(zoxide query --list | fzf)
if [ -n "$selected" ]; then
cd "$selected"
neovide
fi
}
2024-07-07 17:24:15 +07:00
# Completion settings
## Case insensitive completion
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
2024-07-06 22:41:58 +07:00
2024-07-07 17:24:15 +07:00
# FZF Tab configurations
#
# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# set descriptions format to enable group support
# NOTE: don't use escape sequences here, fzf-tab will ignore them
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ''${(s.:.)LS_COLORS}
# force zsh not to show completion menu, which allows fzf-tab to capture the unambiguous prefix
zstyle ':completion:*' menu no
# preview directory's content with eza when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
# preview directory's content with eza when completing z
zstyle ':fzf-tab:complete:z:*' fzf-preview 'eza -1 --color=always $realpath'
2024-07-07 17:24:15 +07:00
# switch group using `<` and `>`
zstyle ':fzf-tab:*' switch-group '<' '>'
''
];
2024-07-06 22:41:58 +07:00
plugins = [
{
name = "fzf-tab";
src = pkgs.zsh-fzf-tab;
file = "share/fzf-tab/fzf-tab.plugin.zsh";
}
2024-07-10 10:54:25 +07:00
# {
# name = "powerlevel10k";
# src = pkgs.zsh-powerlevel10k;
# file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
# }
{
name = "auto-suggestions";
src = pkgs.zsh-autosuggestions;
file = "share/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh";
}
{
name = "zsh-nix-shell";
src = pkgs.zsh-nix-shell;
file = "share/zsh-nix-shell/nix-shell.plugin.zsh";
}
{
name = "zsh-history-substring-search";
src = pkgs.zsh-history-substring-search;
file = "share/zsh-history-substring-search/zsh-history-substring-search.zsh";
}
2024-10-21 21:11:11 +07:00
{
name = "zsh-autocomplete";
src = pkgs.zsh-autocomplete;
file = "share/zsh-autocomplete/zsh-autocomplete.plugin.zsh";
}
# {
# name = "zsh-defer";
# src = pkgs.zsh-defer;
# file = "share/zsh-defer/zsh-defer.plugin.zsh";
# }
];
2024-06-12 09:54:11 +07:00
};
}