ark/profiles/develop/zsh/default.nix

142 lines
3.1 KiB
Nix
Raw Normal View History

2019-12-15 07:37:46 +03:00
{ lib, pkgs, ... }:
let
2020-01-04 08:06:31 +03:00
inherit (builtins) concatStringsSep;
2019-12-15 07:37:46 +03:00
2020-01-04 08:06:31 +03:00
inherit (lib) fileContents;
2019-12-15 07:37:46 +03:00
2020-01-04 08:06:31 +03:00
in {
2019-12-15 07:37:46 +03:00
users.defaultUserShell = pkgs.zsh;
environment = {
2020-01-04 08:06:31 +03:00
sessionVariables = let fd = "${pkgs.fd}/bin/fd -H";
in {
BAT_PAGER = "less";
SKIM_ALT_C_COMMAND = let
alt_c_cmd = pkgs.writeScriptBin "cdr-skim.zsh" ''
#!${pkgs.zsh}/bin/zsh
${fileContents ./cdr-skim.zsh}
'';
in "${alt_c_cmd}/bin/cdr-skim.zsh";
SKIM_DEFAULT_COMMAND = fd;
SKIM_CTRL_T_COMMAND = fd;
};
2019-12-15 07:37:46 +03:00
shellAliases = {
cat = "${pkgs.bat}/bin/bat";
df = "df -h";
du = "du -h";
2019-12-23 08:24:19 +03:00
ls = "exa";
l = "ls -lhg --git";
2019-12-15 07:37:46 +03:00
la = "l -a";
2019-12-23 08:24:19 +03:00
t = "l -T";
ta = "la -T";
2019-12-15 07:37:46 +03:00
ps = "${pkgs.procs}/bin/procs";
2019-12-15 07:37:46 +03:00
rz = "exec zsh";
};
systemPackages = with pkgs; [
bat
bzip2
2019-12-15 07:37:46 +03:00
direnv
exa
2019-12-15 07:37:46 +03:00
gitAndTools.hub
gzip
lrzip
p7zip
procs
2019-12-15 07:37:46 +03:00
skim
unrar
unzip
xz
zsh-completions
2019-12-15 07:37:46 +03:00
];
};
programs.zsh = {
enable = true;
enableGlobalCompInit = false;
histSize = 10000;
setOptions = [
"extendedglob"
"incappendhistory"
"sharehistory"
"histignoredups"
"histfcntllock"
"histreduceblanks"
"histignorespace"
"histallowclobber"
"autocd"
"cdablevars"
"nomultios"
"pushdignoredups"
"autocontinue"
"promptsubst"
];
2019-12-15 07:37:46 +03:00
promptInit = ''
2020-07-27 07:24:28 +03:00
eval "$(${pkgs.starship}/bin/starship init zsh)"
2019-12-15 07:37:46 +03:00
'';
interactiveShellInit = let
zshrc = fileContents ./zshrc;
sources = with pkgs; [
2019-12-17 01:36:20 +03:00
./cdr.zsh
2019-12-15 07:37:46 +03:00
"${skim}/share/skim/completion.zsh"
"${oh-my-zsh}/share/oh-my-zsh/plugins/sudo/sudo.plugin.zsh"
"${oh-my-zsh}/share/oh-my-zsh/plugins/extract/extract.plugin.zsh"
2019-12-16 08:32:40 +03:00
"${zsh-you-should-use}/share/zsh/plugins/you-should-use/you-should-use.plugin.zsh"
2019-12-15 07:37:46 +03:00
"${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
"${zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh"
];
2020-01-04 08:06:31 +03:00
source = map (source: "source ${source}") sources;
functions = pkgs.stdenv.mkDerivation {
name = "zsh-functions";
src = ./functions;
ripgrep = "${pkgs.ripgrep}";
man = "${pkgs.man}";
exa = "${pkgs.exa}";
2020-01-04 08:06:31 +03:00
installPhase = let basename = "\${file##*/}";
in ''
mkdir $out
2019-12-15 07:37:46 +03:00
2020-01-04 08:06:31 +03:00
for file in $src/*; do
substituteAll $file $out/${basename}
chmod 755 $out/${basename}
done
'';
};
2019-12-15 07:37:46 +03:00
2020-01-04 08:06:31 +03:00
plugins = concatStringsSep "\n" ([
"${pkgs.any-nix-shell}/bin/any-nix-shell zsh --info-right | source /dev/stdin"
] ++ source);
2019-12-15 07:37:46 +03:00
2020-01-04 08:06:31 +03:00
in ''
${plugins}
2019-12-15 07:37:46 +03:00
2020-01-04 08:06:31 +03:00
fpath+=( ${functions} )
autoload -Uz ${functions}/*(:t)
2020-01-04 08:06:31 +03:00
${zshrc}
2019-12-15 07:37:46 +03:00
2020-01-04 08:06:31 +03:00
eval "$(${pkgs.direnv}/bin/direnv hook zsh)"
eval $(${pkgs.gitAndTools.hub}/bin/hub alias -s)
source ${pkgs.skim}/share/skim/key-bindings.zsh
2019-12-16 08:46:11 +03:00
2020-01-04 08:06:31 +03:00
# needs to remain at bottom so as not to be overwritten
bindkey jj vi-cmd-mode
'';
2019-12-15 07:37:46 +03:00
};
}