2023-06-29 22:43:49 +00:00
# zsh files/init order
# - see `man zsh` => "STARTUP/SHUTDOWN FILES"
# - /etc/zshenv
# - $ZDOTDIR/.zshenv
# - if login shell:
# - /etc/zprofile
# - $ZDOTDIR/.zprofile
# - if interactive:
# - /etc/zshrc
# - $ZDOTDIR/.zshrc
# - if login (again):
# - /etc/zlogin
# - ZDOTDIR/.zlogin
# - at exit:
# - $ZDOTDIR/.zlogout
# - /etc/zlogout
2023-05-08 21:41:02 +00:00
{ config , lib , pkgs , . . . }:
2022-11-22 05:28:41 +00:00
2023-01-28 03:39:13 +00:00
let
2023-04-26 00:46:12 +00:00
inherit ( lib ) mkIf mkMerge mkOption types ;
2023-03-11 07:58:56 +00:00
cfg = config . sane . zsh ;
2023-01-28 03:39:13 +00:00
# powerlevel10k prompt config
# p10k.zsh is the auto-generated config, and i overwrite those defaults here, below.
p10k-overrides = ''
# powerlevel10k launches a gitstatusd daemon to accelerate git prompt queries.
# this keeps open file handles for any git repo i touch for 60 minutes (by default).
# that prevents unmounting whatever device the git repo is on -- particularly problematic for ~/private.
# i can disable gitstatusd and get slower fallback git queries:
# - either universally
# - or selectively by path
# see: <https://github.com/romkatv/powerlevel10k/issues/246>
typeset - g POWERLEVEL9K_VCS_DISABLED_DIR_PATTERN = ' ( /home/colin/private /* | / h o m e / c o l i n / k n o w l e d g e / * ) '
# typeset -g POWERLEVEL9K_DISABLE_GITSTATUS=true
# show user@host also when logged into the current machine.
# default behavior is to show it only over ssh.
typeset - g POWERLEVEL9K_CONTEXT_ { DEFAULT , SUDO } _CONTENT_EXPANSION = ' $ P9K_CONTENT'
'' ;
prezto-init = ''
source $ { pkgs . zsh-autosuggestions } /share/zsh-autosuggestions/zsh-autosuggestions.zsh
source $ { pkgs . zsh-syntax-highlighting } /share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source $ { pkgs . zsh-prezto } /share/zsh-prezto/init.zsh
'' ;
in
2022-10-21 15:20:30 +00:00
{
2023-03-11 07:58:56 +00:00
options = {
sane . zsh = {
showDeadlines = mkOption {
type = types . bool ;
default = true ;
2023-06-29 22:43:49 +00:00
description = " s h o w u p c o m i n g d e a d l i n e s ( f r o m m y P K M ) u p o n s h e l l i n i t " ;
2023-03-11 07:58:56 +00:00
} ;
2023-01-28 03:39:13 +00:00
} ;
2023-03-11 07:58:56 +00:00
} ;
2023-04-26 00:46:12 +00:00
config = mkMerge [
( {
sane . programs . zsh = {
2023-06-29 22:43:49 +00:00
persist . private = [
2023-04-26 00:46:12 +00:00
# we don't need to full zsh dir -- just the history file --
2023-06-29 22:43:49 +00:00
# but zsh will sometimes backup the history file and symlinking just the file messes things up
2023-04-26 00:46:12 +00:00
" . l o c a l / s h a r e / z s h "
2023-06-29 22:43:49 +00:00
] ;
persist . plaintext = [
# cache gitstatus otherwise p10k fetches it from the net EVERY BOOT
2023-04-26 00:46:12 +00:00
" . c a c h e / g i t s t a t u s "
] ;
2023-06-29 22:43:49 +00:00
fs . " . c o n f i g / z s h / . z s h r c " . symlink . text = ''
# zsh/prezto complains if zshrc doesn't exist or is empty;
# preserve this comment to prevent that from ever happening.
'' + l i b . o p t i o n a l S t r i n g c f g . s h o w D e a d l i n e s ''
$ { pkgs . sane-scripts . deadlines } /bin/sane-deadlines
'' + ''
2023-07-08 02:22:43 +00:00
HISTFILE = " $ H O M E / . l o c a l / s h a r e / z s h / h i s t o r y "
2023-06-29 22:43:49 +00:00
# auto-cd into any of these dirs by typing them and pressing 'enter':
hash - d 3 rd = " / h o m e / c o l i n / d e v / 3 r d "
hash - d dev = " / h o m e / c o l i n / d e v "
hash - d knowledge = " / h o m e / c o l i n / k n o w l e d g e "
hash - d nixos = " / h o m e / c o l i n / n i x o s "
hash - d nixpkgs = " / h o m e / c o l i n / d e v / 3 r d / n i x p k g s "
hash - d ref = " / h o m e / c o l i n / r e f "
hash - d secrets = " / h o m e / c o l i n / k n o w l e d g e / s e c r e t s "
hash - d tmp = " / h o m e / c o l i n / t m p "
hash - d uninsane = " / h o m e / c o l i n / d e v / u n i n s a n e "
hash - d Videos = " / h o m e / c o l i n / V i d e o s "
'' ;
2023-04-26 00:46:12 +00:00
# prezto = oh-my-zsh fork; controls prompt, auto-completion, etc.
# see: https://github.com/sorin-ionescu/prezto
2023-06-29 22:43:49 +00:00
# this file is auto-sourced by the prezto init.zsh script.
# TODO: i should work to move away from prezto:
# - it's FUCKING SLOW to initialize (that might also be powerlevel10k tho)
# - it messes with my other `setopt`s
2023-05-08 21:41:02 +00:00
fs . " . c o n f i g / z s h / . z p r e z t o r c " . symlink . text = ''
2023-04-26 00:46:12 +00:00
zstyle ' : prezto:*:*' color ' yes'
2023-06-29 22:43:49 +00:00
zstyle ' : prezto:module:utility' correct ' no' # prezto: don't setopt CORRECT
2023-04-26 00:46:12 +00:00
# modules (they ship with prezto):
# ENVIRONMENT: configures jobs to persist after shell exit; other basic niceties
# TERMINAL: auto-titles terminal (e.g. based on cwd)
# EDITOR: configures shortcuts like Ctrl+U=undo, Ctrl+L=clear
# HISTORY: `history-stat` alias, setopts for good history defaults
2023-06-29 22:43:49 +00:00
# DIRECTORY: sets AUTO_CD, adds `d` alias to list directory stack, and `1`-`9` to cd that far back the stack. also overrides CLOBBER and some other options
2023-04-26 00:46:12 +00:00
# SPECTRUM: helpers for term colors and styling. used by prompts? might be unnecessary
# UTILITY: configures aliases like `ll`, `la`, disables globbing for things like rsync
# adds aliases like `get` to fetch a file. also adds `http-serve` alias??
# COMPLETION: tab completion. requires `utility` module prior to loading
zstyle ' : prezto:load' pmodule \
' environment' \
' terminal' \
' editor' \
' history' \
' spectrum' \
' utility' \
' completion' \
' prompt'
# default keymap. try also `vicmd` (vim normal mode, AKA "cmd mode") or `vi`.
zstyle ' : prezto:module:editor' key-bindings ' emacs'
zstyle ' : prezto:module:prompt' theme ' powerlevel10k'
# disable `mv` confirmation (and `rm`, too, unfortunately)
zstyle ' : prezto:module:utility' safe-ops ' no'
'' ;
} ;
} )
( mkIf config . sane . programs . zsh . enabled {
# enable zsh completions
environment . pathsToLink = [ " / s h a r e / z s h " ] ;
programs . zsh = {
enable = true ;
shellAliases = {
" : q " = " e x i t " ;
# common typos
" c d . . " = " c d . . " ;
" c d . . / " = " c d . . / " ;
} ;
setOptions = [
2023-06-29 22:43:49 +00:00
# docs: `man zshoptions`
# nixos defaults:
" H I S T _ F C N T L _ L O C K "
2023-04-26 00:46:12 +00:00
" H I S T _ I G N O R E _ D U P S "
" S H A R E _ H I S T O R Y "
2023-06-29 22:43:49 +00:00
# customizations:
" A U T O _ C D " # type directory name to go there
" A U T O _ M E N U " # show auto-complete menu on double-tab
" C D A B L E _ V A R S " # allow auto-cd to use my `hash` aliases -- not just immediate subdirs
" C L O B B E R " # allow `foo > bar.txt` to overwrite bar.txt
" N O _ C O R R E C T " # don't try to correct commands
" P I P E _ F A I L " # when `cmd_a | cmd_b`, make $? be non-zero if *any* of cmd_a or cmd_b fail
" R M _ S T A R _ S I L E N T " # disable `rm *` confirmations
2023-04-26 00:46:12 +00:00
] ;
# .zshenv config:
shellInit = ''
ZDOTDIR = $ HOME/.config/zsh
'' ;
2023-06-29 22:43:49 +00:00
# system-wide .zshrc config:
2023-04-26 00:46:12 +00:00
interactiveShellInit =
( builtins . readFile ./p10k.zsh )
+ p10k-overrides
+ prezto-init
+ ''
# zmv is a way to do rich moves/renames, with pattern matching/substitution.
# see for an example: <https://filipe.kiss.ink/zmv-zsh-rename/>
autoload - Uz zmv
2023-07-04 03:31:13 +00:00
HISTORY_IGNORE = ' ( sane-shutdown * | sane-reboot * | rm * | nixos-rebuild . * switch | switch ) '
2023-04-26 00:46:12 +00:00
# extra aliases
# TODO: move to `shellAliases` config?
function nd ( ) {
mkdir - p " $ 1 " ;
pushd " $ 1 " ;
}
2023-07-04 03:31:13 +00:00
function switch ( ) {
2023-07-16 22:45:34 +00:00
sudo nixos-rebuild - - flake . switch - - keep-going ;
2023-07-04 03:31:13 +00:00
}
2023-04-26 00:46:12 +00:00
'' ;
syntaxHighlighting . enable = true ;
vteIntegration = true ;
2023-03-11 07:58:56 +00:00
} ;
2022-12-21 14:13:20 +00:00
2023-04-26 00:46:12 +00:00
# enable a command-not-found hook to show nix packages that might provide the binary typed.
2023-06-29 22:43:49 +00:00
# programs.nix-index.enableZshIntegration = true;
programs . command-not-found . enable = false ;
2023-04-26 00:46:12 +00:00
} )
] ;
2022-10-21 15:20:30 +00:00
}