Skip to content

Commit 1fb8b7f

Browse files
committed
perf(apps.zsh): move some zsh config to nix
1 parent 19e584b commit 1fb8b7f

File tree

6 files changed

+121
-36
lines changed

6 files changed

+121
-36
lines changed

conf.d/zsh/aliases.zsh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ alias .....='cd ../../../..'
1414
alias bd='cd "$OLDPWD"' # cd to the previous directory
1515
alias nv='nvim'
1616
alias wget='wget2'
17-
alias man='batman'
1817

1918
# Extanded Aliases
2019
# alias yarn='yarn --use-yarnrc "$XDG_CONFIG_HOME/yarn/config"'

conf.d/zsh/completion.zsh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Set completion options.
2+
setopt always_to_end # Move cursor to the end of a completed word.
3+
setopt auto_list # Automatically list choices on ambiguous completion.
4+
setopt auto_menu # Show completion menu on a successive tab press.
5+
setopt auto_param_slash # If completed parameter is a directory, add a trailing slash.
6+
setopt complete_in_word # Complete from both ends of a word.
7+
setopt path_dirs # Perform path search even on command names with slashes.
8+
setopt NO_flow_control # Disable start/stop characters in shell editor.
9+
setopt NO_menu_complete # Do not autoselect the first completion entry.
10+
11+
112
# auto-convert case
213
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
314
# error correction
@@ -56,11 +67,10 @@ zstyle ':completion:*:git:*' group-order 'main commands' 'alias commands' 'exter
5667
# disable sort when completing `git checkout`
5768
zstyle ':completion:*:git-checkout:*' sort false
5869

59-
# Better --SSH--/Rsync/SCP Autocomplete, use `sunlei/zsh-ssh` for ssh
60-
zstyle ':completion:*:(scp|rsync):*' tag-order ' hosts:-ipaddr:ip\ address hosts:-host:host files'
61-
zstyle ':completion:*:(scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
62-
zstyle ':completion:*:(scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'
63-
64-
65-
# NOTE: Completions should be configured before compinit
66-
autoload -U compinit; compinit
70+
# Better SSH/Rsync/SCP Autocomplete
71+
zstyle ':completion:*:(ssh|scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
72+
zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr
73+
zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr
74+
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
75+
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*'
76+
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'

conf.d/zsh/functions.zsh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ zsh_recompile() {
2323
source ~/.zshenv
2424
}
2525

26+
# set https://github.com/victor-gp/cmd-help-sublime-syntax
27+
export MANPAGER='batman'
28+
# alias bathelp="sed 's/.\x08//g' | bat --plain --language=help --strip-ansi=always --theme='Monokai Extended'"
29+
alias bathelp="sed 's/.\x08//g' | bat --plain --language=help --strip-ansi=always"
30+
help() {
31+
"$@" --help 2>&1 | bathelp
32+
}
33+
alias -g -- --help='--help 2>&1 | bathelp'
34+
alias -g -- -h='-h 2>&1 | bathelp'
35+
2636
extract() {
2737
echo Extracting "$1" ...
2838
if [ -f "$1" ] ; then

conf.d/zsh/macos.zsh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/zsh
22

3-
# Flush the DNS cache.
4-
alias flushdns='dscacheutil -flushcache && sudo killall -HUP mDNSResponder'
3+
# Flush the DNS cache. -> mattmc3/zephyr/tree/main/plugins/macos
4+
# alias flushdns='dscacheutil -flushcache && sudo killall -HUP mDNSResponder'
55

6-
# Remove .DS_Store files recursively in a directory.
7-
alias rmdsstore='find "${@:-.}" -type f -name .DS_Store -delete'
6+
# Remove .DS_Store files recursively in a directory. -> mattmc3/zephyr/tree/main/plugins/macos
7+
# alias rmdsstore='find "${@:-.}" -type f -name .DS_Store -delete'
88

99
# macOS has no 'md5sum', so use 'md5' as a fallback
1010
command -v md5sum > /dev/null || alias md5sum="md5"

conf.d/zsh/plugins.zsh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,4 @@ smartcache eval zoxide init zsh
3737
smartcache eval starship init zsh
3838
# (( $OSTYPE[(I)msys] )) && smartcache eval mise activate zsh # mise's smartcache won't work if installing mise via home-manager
3939

40-
# belak/zsh-utils xdg config
41-
zstyle ':zsh-utils:*:*' use-xdg-basedirs 'yes'
4240
# vim: set ft=zsh :

modules/apps/zsh.nix

Lines changed: 89 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,110 @@
99
enable = true;
1010
dotDir = "${config.xdg.configHome}/zsh";
1111
zprof.enable = false;
12-
enableCompletion = false;
12+
enableCompletion = true;
13+
completionInit = ''
14+
autoload -U compinit
15+
compinit -d "$XDG_CACHE_HOME/zsh/zcompdump"
16+
'';
1317
enableVteIntegration = if pkgs.stdenv.isDarwin then false else true;
1418
defaultKeymap = "viins";
19+
dirHashes = {
20+
# enter hashdir via `cd ~XXX`
21+
work = "${config.home.homeDirectory}/Work";
22+
Work = "${config.home.homeDirectory}/Work";
23+
ssh = "${config.home.homeDirectory}/.ssh";
24+
music = "${config.home.homeDirectory}/Music";
25+
pic = "${config.home.homeDirectory}/Pictures";
26+
dl = "${config.home.homeDirectory}/Downloads";
27+
doc = "${config.home.homeDirectory}/Documents";
28+
cfg = "${config.xdg.configHome}";
29+
config = "${config.xdg.configHome}";
30+
share = "${config.xdg.dataHome}";
31+
state = "${config.xdg.stateHome}";
32+
cache = "${config.xdg.cacheHome}";
33+
};
34+
cdpath = [
35+
# autocompletion after `cd`
36+
"${config.xdg.configHome}/nvim"
37+
"${config.xdg.configHome}/home-manager"
38+
];
39+
history = {
40+
path = "${config.xdg.cacheHome}/zsh/history";
41+
size = 20000; # Set session history size.
42+
save = 100000; # Set history file size.
43+
append = false;
44+
extended = true; # Save timestamp into the history file.
45+
share = false; # Share command history between zsh sessions
46+
saveNoDups = true;
47+
ignoreDups = true;
48+
ignoreAllDups = true;
49+
findNoDups = true;
50+
expireDuplicatesFirst = true;
51+
ignoreSpace = true; # Do not enter command lines into the history list if the first character is a space.
52+
# ignorePatterns = [
53+
# "rm *"
54+
# "pkill *"
55+
# ];
56+
};
57+
setOptions = [
58+
"NO_beep"
59+
# ===== History Extra
60+
# Let histfile managed by system's `fcntl` call to improve better performance and avoid corruption
61+
"hist_fcntl_lock"
62+
# Add comamnds as they are typed, don't wait until shell exit
63+
"inc_append_history"
64+
# Add EXTENDED_HISTORY format for INC_APPEND_HISTORY
65+
"inc_append_history_time"
66+
# Remove extra blanks from each command line being added to history
67+
"hist_reduce_blanks"
68+
# Do not execute immediately upon history expansion.
69+
"hist_verify"
70+
# Don't beep when accessing non-existent history.
71+
"NO_hist_beep"
72+
# ===== Prompt
73+
# Expand parameters in prompt variables.
74+
"prompt_subst"
75+
];
1576
antidote = {
1677
enable = true;
1778
useFriendlyNames = true;
18-
plugins = [
19-
# lazy-loading `kind:defer`
20-
"QuarticCat/zsh-smartcache" # better mroth/evalcache
21-
"zsh-users/zsh-completions kind:fpath"
22-
"belak/zsh-utils path:completion"
23-
# "Aloxaf/fzf-tab kind:defer" # needs to load after `compinit`, but before wrap widgets, such as `zsh-autosuggestions` or `fast-syntax-highlighting`
24-
"zsh-users/zsh-autosuggestions kind:defer"
25-
"zdharma-continuum/fast-syntax-highlighting kind:defer" # add before zsh-history-substring-search to prevent breaking
26-
"zpm-zsh/colorize kind:defer" # Colorize the output of various programs
27-
"zpm-zsh/colors" # Enhanced colors for zsh
28-
"Freed-Wu/zsh-help" # colorize `XXX --help`
29-
"zsh-users/zsh-history-substring-search kind:defer"
30-
"MichaelAquilina/zsh-you-should-use kind:defer"
31-
# "MichaelAquilina/zsh-autoswitch-virtualenv kind:defer" # Auto-switch python venv, pipenv, poetry
32-
"sunlei/zsh-ssh kind:defer"
33-
];
79+
plugins =
80+
let
81+
commonPlugins = [
82+
# lazy-loading `kind:defer`
83+
"QuarticCat/zsh-smartcache" # better mroth/evalcache
84+
# "belak/zsh-utils path:completion"
85+
# "Aloxaf/fzf-tab kind:defer" # needs to load after `compinit`, but before wrap widgets, such as `zsh-autosuggestions` or `fast-syntax-highlighting`
86+
"zsh-users/zsh-autosuggestions kind:defer"
87+
"zdharma-continuum/fast-syntax-highlighting kind:defer" # add before zsh-history-substring-search to prevent breaking
88+
"zsh-users/zsh-history-substring-search kind:defer"
89+
"MichaelAquilina/zsh-you-should-use kind:defer"
90+
# "sunlei/zsh-ssh kind:defer"
91+
];
92+
darwinPlugins =
93+
if pkgs.stdenv.isDarwin then
94+
[
95+
"mattmc3/zephyr path:plugins/homebrew"
96+
"mattmc3/zephyr path:plugins/macos"
97+
]
98+
else
99+
[ ];
100+
in
101+
commonPlugins ++ darwinPlugins;
34102
};
35103
initContent =
36104
let
37105
zshDir = "${src}/conf.d/zsh";
38106
commonFiles = [
39107
"completion.zsh"
40-
"setopt.zsh"
108+
# "setopt.zsh" # set in nix
41109
"exports.zsh"
42-
"history.zsh"
110+
# "history.zsh" # set in nix
43111
"functions.zsh"
44-
"bindkeys.zsh"
45112
"plugins.zsh"
46113
"aliases.zsh"
47-
"hashdirs.zsh"
114+
# "hashdirs.zsh" # set in nix
115+
"bindkeys.zsh"
48116
];
49117
darwinFiles = if pkgs.stdenv.isDarwin then [ "macos.zsh" ] else [ ];
50118
readAll = files: builtins.map (f: builtins.readFile "${zshDir}/${f}") files;

0 commit comments

Comments
 (0)