Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion home-manager/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
pkgs.zoxide
pkgs.fzf

# Used in anywhere
pkgs.coreutils

# asdf/rtx
#
# Prefer rtx now
Expand All @@ -42,7 +45,6 @@
pkgs.shfmt
pkgs.nixpkgs-fmt

pkgs.coreutils
pkgs.tree
pkgs.exa
pkgs.curl
Expand Down
42 changes: 38 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,42 @@
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 = ''
_elapsed_seconds_for() {

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.

much useful 🤔

local -r target_path="$1"
echo "$(("$(${lib.getBin pkgs.coreutils}/bin/date +"%s")" - "$(${lib.getBin pkgs.coreutils}/bin/stat --format='%Y' "$target_path")"))"
}

# 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"
# seconds * minutes * hours
local -r threshold="$((60 * 60 * 3))"

if [ -e "$dump_path" ] && [ "$(_elapsed_seconds_for "$dump_path")" -le "$threshold" ]; then
# https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Use-of-compinit
# -C omit to check new functions
compinit -C -d "$dump_path"
else
mkdir -p "$dump_dir"
compinit -d "$dump_path"

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.

Without cache as here, still taking 160~180ms

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 +81,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'