refactor(devkit,zsh): use replaceVarsWith to improve readbility

This commit is contained in:
Guz
2026-03-22 17:47:54 -03:00
parent 4b7c9c4db0
commit 76db1a778d
2 changed files with 72 additions and 36 deletions

View File

@@ -3,6 +3,8 @@ if [ -f "$HOME/.zshrc" ]; then
source "$HOME/.zshrc"
fi
#@zshrc-prepend@
typeset -U auto cdpath fpath manpath
if [ -f "$ZSHRC_PREPEND" ]; then
@@ -12,9 +14,7 @@ fi
# Autocompletion
autoload -U compinit && compinit
# Autosuggestion
source "$ZSH_PLUGIN_AUTOSUGGESTIONS"
ZSH_AUTOSUGGEST_STRATEGY=(history)
#@zsh-plugin-autosuggestions@
# Command history
HISTSIZE=1000
@@ -39,9 +39,7 @@ if command -v "starship" >/dev/null 2>&1; then
fi
fi
# Syntax highlighting
source "$ZSH_PLUGIN_SYNTAXHIGHLIGHING"
ZSH_HIGHLIGHT_HIGHLIGHTERS+=()
#@zsh-plugin-syntaxhighlighing@
# Integration for Zellij
if command -v "zellij" >/dev/null 2>&1; then
@@ -67,17 +65,29 @@ alias -- vim='nvim'
alias -- vimdiff='nvim -d'
alias -- lg='lazygit'
# Yazi alias (with wrapper to change cwd)
function y() {
local tmp="$(mktemp -t "yazi-cmd.XXXXXX")" cwd
yazi "$@" --cwd-file="$tmp"
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
builtin cd -- "$cwd"
fi
rm -f -- "$tmp"
}
# Yazi alias (without wrapper to change cwd)
alias -- yy='yazi'
if command -v "yazi" >/dev/null 2>&1; then
# Yazi alias (with wrapper to change cwd)
function y() {
local tmp="$(mktemp -t "yazi-cmd.XXXXXX")" cwd
yazi "$@" --cwd-file="$tmp"
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
builtin cd -- "$cwd"
fi
rm -f -- "$tmp"
}
# Yazi alias (without wrapper to change cwd)
alias -- yy='yazi'
fi
if command -v "nvim" >/dev/null 2>&1; then
EDITOR="nvim"
elif command -v "vim" >/dev/null 2>&1; then
EDITOR="vim"
elif command -v "vi" >/dev/null 2>&1; then
EDITOR="vi"
fi
#@zshrc-append@
if [ -f "$ZSHRC_APPEND" ]; then
source "$ZSHRC_APPEND"

View File

@@ -1,27 +1,53 @@
{
symlinkJoin,
lib,
makeWrapper,
pkgs,
replaceVarsWith,
stdenv,
symlinkJoin,
zsh ? pkgs.zsh,
# .zshrc
zshrc-prepend ? "",
zshrc-append ? "",
}: let
zsh-syntax-highlighting = "${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh";
zsh-autosuggestions = "${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh";
zshrc-prepend-file = pkgs.writeText ".zshrc_prepend" zshrc-prepend;
zshrc-append-file = pkgs.writeText ".zshrc_append" zshrc-append;
zdotdir = stdenv.mkDerivation {
name = "zdotdir";
phases = ["installPhase"];
installPhase = ''
mkdir -p $out
cp ${replaceVarsWith {
src = ./.zshrc;
replacements = {
"zsh-plugin-autosuggestions" = ''
# Auto Suggestions
source "${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh";
ZSH_AUTOSUGGEST_STRATEGY=(history)
'';
"zsh-plugin-syntaxhighlighing" = ''
# Syntax Highlighting
source "${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(${lib.concatStringsSep " " (map lib.escapeShellArg ["brackets"])})
'';
"zshrc-prepend" = ''
# Zsh Prepend
${zshrc-prepend}
'';
"zshrc-append" = ''
# Zsh Append
${zshrc-append}
'';
};
postCheck = ''${stdenv.shellDryRun} "$target"'';
}} $out/.zshrc
cp ${./.zshenv} $out/.zshenv
'';
};
in
symlinkJoin ({
paths = [zsh];
nativeBuildInputs = [makeWrapper];
postBuild = ''
wrapProgram $out/bin/zsh \
--set-default 'ZSH_PLUGIN_SYNTAXHIGHLIGHING' '${zsh-syntax-highlighting}' \
--set-default 'ZSH_PLUGIN_AUTOSUGGESTIONS' '${zsh-autosuggestions}' \
--set-default 'ZSHRC_PREPEND' '${zshrc-prepend-file}' \
--set-default 'ZSHRC_APPEND' '${zshrc-append-file}' \
--set-default 'ZDOTDIR' '${./.}'
'';
}
// {inherit (zsh) man meta name passthru pname version;})
symlinkJoin {
paths = [zsh];
nativeBuildInputs = [makeWrapper];
postBuild = ''
mkdir -p $out
wrapProgram $out/bin/zsh --set-default 'ZDOTDIR' '${zdotdir}'
'';
inherit (zsh) man meta name passthru pname version;
}