blob: ef2eaaa354a43978c25ceaf8458246b3e7c661bb [file] [log] [blame]
Skyler Greycecd9792022-07-27 14:38:47 +01001{ pkgs, config, fzf-tab, ... }: {
Skyler Turner62330c12022-03-04 22:10:16 +00002 programs.zsh = {
3 enable = true;
Skyler Grey0bd95942022-07-27 13:16:29 +01004 plugins = [ { name = "fzf-tab"; src = fzf-tab; } ];
Skyler Turner62330c12022-03-04 22:10:16 +00005 oh-my-zsh = {
6 enable = true;
7 plugins = [ "git" ];
8 theme = "crunch";
9 };
10 history = {
11 size = 10000;
12 path = "${config.xdg.dataHome}/zsh/history";
13 expireDuplicatesFirst = true;
14 extended = true;
15 };
16 initExtra = ''
Skyler Grey82e00702022-08-19 15:59:30 +010017 bindkey -v
18 bindkey "\'\'$\{key[Up]}" up-line-or-search
Skyler Turner62330c12022-03-04 22:10:16 +000019
Skyler Grey82e00702022-08-19 15:59:30 +010020 command_not_found_handler ()
21 {
22 local p='/nix/store/ycclzpk99snlrk8sg9n4j8pm1927gavw-command-not-found/bin/command-not-found';
23 if [ -x "$p" ] && [ -f '/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite' ]; then
24 "$p" "$@" 2>&1 | sed -r 's/nix-shell -p (\S+)/nix shell nixpkgs#\1/g' 1>&2;
25 if [ $? = 126 ]; then
26 "$@";
27 else
28 return 127;
29 fi;
30 else
31 echo "$1: command not found" 1>&2;
32 return 127;
33 fi
34 }
Skyler Greye2f4ab92022-05-20 12:09:15 +010035
Skyler Grey82e00702022-08-19 15:59:30 +010036 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=243';
37 ZSH_HIGHLIGHT_STYLES[comment]='fg=248';
Skyler Greye45bfb82022-07-20 17:13:27 +010038
Skyler Grey17ece8b2022-07-21 17:28:26 +010039
Skyler Grey82e00702022-08-19 15:59:30 +010040 function task_indicator {
41 if [ `task +READY +OVERDUE count 2> /dev/null` -gt "0" ] ; then
42 printf "%%{\\033[38;5;248m%%}(%%{$fg[magenta]%%}$(task +READY +OVERDUE count) OVERDUE%%{\033[38;5;248m%%})%%{$fg[default]%%}"
43 elif [ `task +READY +DUETODAY count 2> /dev/null` -gt "0" ] ; then
44 printf "%%{\\033[38;5;248m%%}(%%{$fg[red]%%}$(task +READY +DUETODAY count) DUE TODAY%%{\033[38;5;248m%%})%%{$fg[default]%%}"
45 elif [ `task +READY +DUETomorrow count 2> /dev/null` -gt "0" ] ; then
46 printf "%%{\\033[38;5;248m%%}(%%{$fg[yellow]%%}$(task +READY +DUETomorrow count) DUE TOMORROW%%{\033[38;5;248m%%})%%{$fg[default]%%}"
47 elif [ `task +READY urgency \> 10 count 2> /dev/null` -gt "0" ] ; then
48 printf "%%{\\033[38;5;248m%%}(%%{$fg[red]%%}$(task +READY urgency \\\> 10 count) URGENT%%{\033[38;5;248m%%})%%{$fg[default]%%}"
49 elif [ `task +READY count 2> /dev/null` -gt "0" ] ; then
50 printf "%%{\\033[38;5;248m%%}(%%{$fg[cyan]%%}$(task +READY count) TASKS%%{\033[38;5;248m%%})%%{$fg[default]%%}"
51 else
52 printf "%%{\\033[38;5;248m%%}(%%{$fg[green]%%}NO TASKS%%{\033[38;5;248m%%})%%{$fg[default]%%}"
53 fi
54 }
Skyler Grey0bd95942022-07-27 13:16:29 +010055
Skyler Grey82e00702022-08-19 15:59:30 +010056 if [[ $SHLVL != "1" ]]; then
57 export RPS1=$'%{\033[38;5;248m%}(%{$fg[red]%}L$SHLVL%{\033[38;5;248m%})%{\033[39m\033[49m%} '
58 fi
59
60 RPS1+='$(task_indicator)'
61
62 function TRAPINT {
63 print -n "$fg_bold[red]^C$fg_no_bold[default]"
64 return $(( 128 + $1 ))
65 }
66
67 # function zle-line-init {
68 # if [[ -n $ZLE_LINE_ABORTED ]]; then
69 # MY_LINE_ABORTED="$ZLE_LINE_ABORTED"
70 # fi
71
72 # if [[ -n $MY_LINE_ABORTED ]]; then
73 # local savebuf="$BUFFER" savecur="$CURSOR"
74 # BUFFER="$MY_LINE_ABORTED"
75 # CURSOR="$#BUFFER"
76 # zle split-undo
77 # BUFFER="$savebuf" CURSOR="$savecur"
78 # fi
79 # }
80 # zle -N zle-line-init
81
82 function tempd {
83 cd "$(mktemp -d)"
84 }
Skyler Grey112f3b72022-08-11 22:32:38 +010085
Skyler Grey0bd95942022-07-27 13:16:29 +010086 # disable sort when completing `git checkout`
87 zstyle ':completion:*:git-checkout:*' sort false
88 # set descriptions format to enable group support
89 zstyle ':completion:*:descriptions' format '[%d]'
90 # set list-colors to enable filename colorizing
Skyler Greyf6109de2022-07-27 16:38:10 +010091 zstyle ':completion:*' list-colors ''${(s.:.)LS_COLORS}
Skyler Grey0bd95942022-07-27 13:16:29 +010092 # preview directory's content with exa when completing cd
93 zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 -l --color=always $realpath'
94 # switch group using `,` and `.`
95 zstyle ':fzf-tab:*' switch-group ',' '.'
96 enable-fzf-tab
Skyler Grey81248f72022-08-11 00:16:06 +010097
98 alias compinit="true"
99 source ${./zsh/completions}/*
Skyler Grey82e00702022-08-19 15:59:30 +0100100 '';
101 enableSyntaxHighlighting = true;
102 enableAutosuggestions = true;
103 autocd = true;
104 dotDir = ".local/share/zsh";
105 };
Skyler Grey0bd95942022-07-27 13:16:29 +0100106
Skyler Grey82e00702022-08-19 15:59:30 +0100107 home.packages = [
108 pkgs.fzf
109 ];
110
111 home.shellAliases = {
112 ":q" = "exit";
113 };
114 }