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
|
2023-08-15 01:47:12 +00:00
|
|
|
# -> /etc/zinputrc
|
2023-06-29 22:43:49 +00:00
|
|
|
# - $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
|
|
|
in
|
2022-10-21 15:20:30 +00:00
|
|
|
{
|
2023-07-18 01:28:30 +00:00
|
|
|
imports = [
|
|
|
|
./starship.nix
|
|
|
|
];
|
2023-03-11 07:58:56 +00:00
|
|
|
options = {
|
2023-11-08 11:26:55 +00:00
|
|
|
# TODO: port to sane.programs options
|
2023-03-11 07:58:56 +00:00
|
|
|
sane.zsh = {
|
|
|
|
showDeadlines = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-06-29 22:43:49 +00:00
|
|
|
description = "show upcoming deadlines (from my PKM) upon shell init";
|
2023-03-11 07:58:56 +00:00
|
|
|
};
|
2023-07-18 01:28:30 +00:00
|
|
|
starship = mkOption {
|
|
|
|
type = types.bool;
|
2023-07-18 01:30:53 +00:00
|
|
|
default = true;
|
2023-07-18 01:28:30 +00:00
|
|
|
description = "enable starship prompt";
|
|
|
|
};
|
2023-11-08 11:26:55 +00:00
|
|
|
guiIntegrations = mkOption {
|
|
|
|
type = types.bool;
|
2023-11-08 15:30:28 +00:00
|
|
|
default = config.sane.programs.guiApps.enabled;
|
2023-11-08 11:26:55 +00:00
|
|
|
description = ''
|
|
|
|
integrate with things like VTE, so that windowing systems can show the PWD in the title.
|
|
|
|
drags in gtk+3.
|
|
|
|
'';
|
|
|
|
};
|
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-11-08 15:32:50 +00:00
|
|
|
persist.byStore.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
|
|
|
".local/share/zsh"
|
2023-06-29 22:43:49 +00:00
|
|
|
];
|
2023-04-26 00:46:12 +00:00
|
|
|
|
2023-06-29 22:43:49 +00:00
|
|
|
fs.".config/zsh/.zshrc".symlink.text = ''
|
|
|
|
# zsh/prezto complains if zshrc doesn't exist or is empty;
|
|
|
|
# preserve this comment to prevent that from ever happening.
|
|
|
|
'' + lib.optionalString cfg.showDeadlines ''
|
|
|
|
${pkgs.sane-scripts.deadlines}/bin/sane-deadlines
|
|
|
|
'' + ''
|
2023-07-08 02:22:43 +00:00
|
|
|
|
|
|
|
HISTFILE="$HOME/.local/share/zsh/history"
|
2023-11-12 22:16:33 +00:00
|
|
|
HISTSIZE=1000000
|
|
|
|
SAVEHIST=1000000
|
2023-07-08 02:22:43 +00:00
|
|
|
|
2023-06-29 22:43:49 +00:00
|
|
|
# auto-cd into any of these dirs by typing them and pressing 'enter':
|
|
|
|
hash -d 3rd="/home/colin/dev/3rd"
|
|
|
|
hash -d dev="/home/colin/dev"
|
|
|
|
hash -d knowledge="/home/colin/knowledge"
|
|
|
|
hash -d nixos="/home/colin/nixos"
|
|
|
|
hash -d nixpkgs="/home/colin/dev/3rd/nixpkgs"
|
|
|
|
hash -d ref="/home/colin/ref"
|
|
|
|
hash -d secrets="/home/colin/knowledge/secrets"
|
|
|
|
hash -d tmp="/home/colin/tmp"
|
|
|
|
hash -d uninsane="/home/colin/dev/uninsane"
|
|
|
|
hash -d Videos="/home/colin/Videos"
|
2023-08-15 01:47:12 +00:00
|
|
|
|
|
|
|
# emulate bash keybindings
|
|
|
|
bindkey -e
|
|
|
|
|
|
|
|
# or manually recreate what i care about...
|
|
|
|
# key[Left]=''${terminfo[kcub1]}
|
|
|
|
# key[Right]=''${terminfo[kcuf1]}
|
|
|
|
# bindkey '^R' history-incremental-search-backward
|
|
|
|
# bindkey '^A' beginning-of-line
|
|
|
|
# bindkey '^E' end-of-line
|
|
|
|
# bindkey "^''${key[Left]}" backward-word
|
|
|
|
# bindkey "^''${key[Right]}" forward-word
|
2023-06-29 22:43:49 +00:00
|
|
|
'';
|
2023-04-26 00:46:12 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf config.sane.programs.zsh.enabled {
|
|
|
|
# enable zsh completions
|
|
|
|
environment.pathsToLink = [ "/share/zsh" ];
|
|
|
|
|
|
|
|
programs.zsh = {
|
|
|
|
enable = true;
|
|
|
|
shellAliases = {
|
|
|
|
":q" = "exit";
|
|
|
|
# common typos
|
|
|
|
"cd.." = "cd ..";
|
|
|
|
"cd../" = "cd ../";
|
2023-10-12 22:11:05 +00:00
|
|
|
# ls helpers (eza is a nicer `ls`
|
|
|
|
"l" = "eza --oneline"; # show one entry per line
|
|
|
|
"ll" = "eza --long --time-style=long-iso";
|
2023-11-24 21:39:52 +00:00
|
|
|
# overcome poor defaults
|
|
|
|
"lsof" = "lsof -P"; #< lsof: use port *numbers*, not names
|
|
|
|
"tcpdump" = "tcpdump -n"; #< tcpdump: use port *numbers*, not names
|
2023-04-26 00:46:12 +00:00
|
|
|
};
|
|
|
|
setOptions = [
|
2023-06-29 22:43:49 +00:00
|
|
|
# docs: `man zshoptions`
|
|
|
|
# nixos defaults:
|
|
|
|
"HIST_FCNTL_LOCK"
|
2023-04-26 00:46:12 +00:00
|
|
|
"HIST_IGNORE_DUPS"
|
2023-11-12 22:16:33 +00:00
|
|
|
"HIST_EXPIRE_DUPS_FIRST"
|
2023-04-26 00:46:12 +00:00
|
|
|
"SHARE_HISTORY"
|
2023-06-29 22:43:49 +00:00
|
|
|
# customizations:
|
|
|
|
"AUTO_CD" # type directory name to go there
|
|
|
|
"AUTO_MENU" # show auto-complete menu on double-tab
|
|
|
|
"CDABLE_VARS" # allow auto-cd to use my `hash` aliases -- not just immediate subdirs
|
|
|
|
"CLOBBER" # allow `foo > bar.txt` to overwrite bar.txt
|
|
|
|
"NO_CORRECT" # don't try to correct commands
|
|
|
|
"PIPE_FAIL" # when `cmd_a | cmd_b`, make $? be non-zero if *any* of cmd_a or cmd_b fail
|
|
|
|
"RM_STAR_SILENT" # 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-07-18 01:28:30 +00:00
|
|
|
interactiveShellInit = ''
|
2023-04-26 00:46:12 +00:00
|
|
|
# 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
|
|
|
|
2023-11-24 21:40:16 +00:00
|
|
|
function repo() {
|
|
|
|
# navigate to a local checkout of the source code for repo (i.e. package) $1
|
|
|
|
eval $(sane-clone "$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;
|
2023-11-08 11:26:55 +00:00
|
|
|
vteIntegration = cfg.guiIntegrations;
|
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
|
|
|
}
|