Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions home-manager/zsh.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, ... }:
{ config, lib, pkgs, ... }:

{
programs.starship.enableZshIntegration = true;
Expand Down Expand Up @@ -37,7 +37,35 @@
syntaxHighlighting.enable = true;

enableAutosuggestions = true;

# NOTE: enabling without tuning makes much slower zsh as +100~200ms execution time
# And the default path is not intended, so you SHOULD update `completionInit`
enableCompletion = true;
# https://github.com/nix-community/home-manager/blob/8c731978f0916b9a904d67a0e53744ceff47882c/modules/programs/zsh.nix#L325C7-L329
# https://github.com/nix-community/home-manager/blob/8c731978f0916b9a904d67a0e53744ceff47882c/modules/programs/zsh.nix#L368-L372
# The default is "autoload -U compinit && compinit", I can not accept the path and speed
initExtraBeforeCompInit = ''
# path - https://stackoverflow.com/a/48057649/1212807
# speed - https://gist.github.com/ctechols/ca1035271ad134841284
# both - https://github.com/kachick/dotfiles/pull/155
_compinit_with_interval() {
local -r dump_dir="${config.xdg.cacheHome}/zsh"
local -r dump_path="$dump_dir/zcompdump-$ZSH_VERSION"

if ${lib.getExe pkgs.fd} --quiet --changed-within 6hours "$dump_path"; then

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fd is much slow for this purpose 🙄

compinit -d "$dump_path"
else
mkdir -p "$dump_dir"
# https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Use-of-compinit
# -C omit to check new functions
compinit -C -d "$dump_path"
fi
}
'';
completionInit = ''
# `autoload` enable to use compinit
autoload -Uz compinit && _compinit_with_interval
'';

# Setting bindkey
# https://github.com/nix-community/home-manager/blob/8c731978f0916b9a904d67a0e53744ceff47882c/modules/programs/zsh.nix#L28
Expand All @@ -46,9 +74,8 @@

# home-manager path will set in `programs.home-manager.enable = true`;
envExtra = ''
# https://wiki.archlinux.jp/index.php/XDG_Base_Directory
# https://www.reddit.com/r/zsh/comments/tpwx9t/zcompcache_vs_zcompdump/
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache"
# https://gist.github.com/ctechols/ca1035271ad134841284?permalink_comment_id=3401477#gistcomment-3401477
skip_global_compinit=1

if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi # added by Nix installer
'';
Expand Down
9 changes: 6 additions & 3 deletions home/.local/share/homemade/bin/bench_shells.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ set -euxo pipefail

# ~ my feeling ~
# 50ms : blazing fast!
# 120ms : acceptable
# 110ms : acceptable
# 150ms : slow
# 200ms : 1980s?
# 300ms : slow!
# 300ms : much slow!

hyperfine --warmup 1 'bash -i -c exit'
# zsh should be first, because it often makes much slower with the completion
hyperfine --warmup 1 'zsh --interactive -c exit'

hyperfine --warmup 1 'bash -i -c exit'
hyperfine --warmup 1 'fish --interactive --command exit'