Modularize nix config more
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{ pkgs, lib, config, ... }:
|
||||
{ pkgs, lib, config, shellOptions, ... }:
|
||||
{
|
||||
programs.zsh = rec {
|
||||
enable = true;
|
||||
@@ -39,163 +39,25 @@
|
||||
# }
|
||||
];
|
||||
|
||||
localVariables = {
|
||||
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS = ["dir" "vcs"];
|
||||
# NIX_PATH = ''$HOME/.nix-defexpr/channels$\{NIX_PATH:+:}$NIX_PATH'';
|
||||
};
|
||||
localVariables = shellOptions.variables;
|
||||
|
||||
shellAliases = with pkgs; let
|
||||
|
||||
sedColor =
|
||||
color:
|
||||
inputPattern:
|
||||
outputPattern:
|
||||
"-e \"s|${inputPattern}|${outputPattern.before or ""}$(tput setaf ${toString color})${outputPattern.middle}$(tput op)${outputPattern.after or ""}|g\"";
|
||||
|
||||
colorRed = sedColor 1;
|
||||
|
||||
shellPipe = lib.strings.concatStringsSep " | ";
|
||||
join = lib.strings.concatStringsSep " ";
|
||||
|
||||
in {
|
||||
|
||||
# This for some reason uses an outdated version of hm
|
||||
# hs = "${pkgs.home-manager}/bin/home-manager switch";
|
||||
|
||||
hms = "home-manager switch";
|
||||
nxr = "sudo ${nixos-rebuild}/bin/nixos-rebuild switch";
|
||||
nxc = "sudoedit /etc/nixos/configuration.nix";
|
||||
ns = "nix-shell";
|
||||
|
||||
# Having 'watch' with a space after as an alias, enables it to expand other aliases
|
||||
watch = "${procps}/bin/watch ";
|
||||
|
||||
m = "${ncmpcpp}/bin/ncmpcpp";
|
||||
p = "${python39Packages.ipython}/bin/ipython";
|
||||
|
||||
lls = "${coreutils}/bin/ls";
|
||||
ls = "${exa}/bin/exa";
|
||||
la = "${exa}/bin/exa -lah --changed --time-style long-iso --git --group";
|
||||
lsa = "la";
|
||||
|
||||
killall = "echo \"killall is dangerous on non-gnu platforms. Using 'pkill -x'\"; pkill -x";
|
||||
|
||||
youtube-dl-list = join [
|
||||
"${youtube-dl}/bin/youtube-dl"
|
||||
"-f \"bestvideo[ext=mp4]+bestaudio[e=m4a]/bestvideo+bestaudio\""
|
||||
"-o \"%(playlist_index)s-%(title)s.%(ext)s\""
|
||||
];
|
||||
|
||||
music-dl = "${youtube-dl}/bin/youtube-dl --extract-audio -f \"bestaudio[ext=m4a]/best\"";
|
||||
music-dl-list = join [
|
||||
"${youtube-dl}/bin/youtube-dl"
|
||||
"--extract-audio"
|
||||
"-f \"bestaudio[ext=m4a]/best\""
|
||||
"-o \"%(playlist_index)s-%(title)s.%(ext)s\""
|
||||
];
|
||||
|
||||
skusho = "${maim}/bin/maim --hidecursor --nokeyboard $(echo $SCREENSHOT_DIR)/$(date_%s).png";
|
||||
skushoclip = shellPipe [
|
||||
"${maim}/bin/maim --hidecursor --nokeyboard --select"
|
||||
"${xclip}/bin/xclip -selection clipboard -target image/png -in"
|
||||
|
||||
];
|
||||
|
||||
view-latex = "${texlive.combined.scheme-full}/bin/latexmk -pdf -pvc main.tex";
|
||||
|
||||
reload-tmux = "${tmux}/bin/tmux source $HOME/.config/tmux/tmux.conf";
|
||||
|
||||
ag="${ripgrep}/bin/rg";
|
||||
|
||||
dp = "${dropbox-cli}/bin/dropbox";
|
||||
|
||||
cd = "z";
|
||||
|
||||
ccp = "${coreutils}/bin/cp";
|
||||
cp = "${rsync}/bin/rsync --progress --human-readable";
|
||||
cpr = "${rsync}/bin/rsync --progress --human-readable --recursive";
|
||||
|
||||
ccat = "${coreutils}/bin/cat";
|
||||
cat = "${bat}/bin/bat";
|
||||
|
||||
htop = "${bottom}/bin/bottom";
|
||||
|
||||
ps = "${procs}/bin/procs";
|
||||
|
||||
fin = "${fd}/bin/fd";
|
||||
|
||||
ip = "ip -c";
|
||||
|
||||
regex-escapechars = "echo \"[\\^$.|?*+()\"";
|
||||
|
||||
connectedIps = shellPipe [
|
||||
"netstat -tn 2>/dev/null"
|
||||
"grep :$1"
|
||||
"awk '{print $5}'"
|
||||
"cut -d: -f1"
|
||||
"sort"
|
||||
"uniq -c"
|
||||
"sort -nr"
|
||||
"head"
|
||||
];
|
||||
|
||||
path = let
|
||||
colorSlashes = colorRed "/" {middle = "/";};
|
||||
in
|
||||
"echo $PATH | sed -e 's/:/\\n/g' ${colorSlashes} | sort";
|
||||
|
||||
aliases = let
|
||||
colorAliasNames = colorRed "\\(^[^=]*\\)=" {middle = "\\1"; after = "\\t";};
|
||||
|
||||
# The '[^]]' (character before /nix should not be ']') is there so that this alias'
|
||||
# definition won't be removed.
|
||||
removeNixLinks = "-e 's|\\([^]]\\)/nix/store/.*/bin/|\\1|'";
|
||||
in
|
||||
shellPipe [
|
||||
"alias"
|
||||
"sed ${colorAliasNames} ${removeNixLinks}"
|
||||
"column -ts $'\\t'"
|
||||
];
|
||||
|
||||
|
||||
ports = let
|
||||
colorSlashes = colorRed "/" {middle = "/";};
|
||||
colorFirstColumn = colorRed "(^[^ ]+)" {middle = "\\1";};
|
||||
in
|
||||
shellPipe [
|
||||
"sudo netstat -tulpn"
|
||||
"grep LISTEN"
|
||||
"sed -r 's/\\s+/ /g'"
|
||||
"cut -d' ' -f 4,7"
|
||||
"column -t"
|
||||
"sed -r ${colorFirstColumn} ${colorSlashes}"
|
||||
];
|
||||
|
||||
}
|
||||
//
|
||||
(let
|
||||
inherit (lib.strings) concatStrings concatStringsSep;
|
||||
inherit (lib.lists) range flatten;
|
||||
inherit (lib.attrsets) nameValuePair;
|
||||
inherit (lib.trivial) const;
|
||||
|
||||
repeatItem = n: item: map (const item) (range 1 n);
|
||||
repeatString = n: string: concatStrings (repeatItem n string);
|
||||
|
||||
nthCds = n: [
|
||||
("cd" + (repeatString (n + 1) "."))
|
||||
("cd." + toString n)
|
||||
(repeatString (n + 1) ".")
|
||||
("." + toString n)
|
||||
(".." + toString n)
|
||||
];
|
||||
realCommand = n: "cd " + (concatStringsSep "/" (repeatItem n ".."));
|
||||
|
||||
nthCdsAsNameValuePairs = n: map (cmd: nameValuePair cmd (realCommand n)) (nthCds n);
|
||||
allCdNameValuePairs = (flatten (map nthCdsAsNameValuePairs (range 1 9)));
|
||||
in
|
||||
lib.attrsets.listToAttrs allCdNameValuePairs);
|
||||
shellAliases = shellOptions.flattened.aliases;
|
||||
|
||||
# initExtra = let
|
||||
# functions = {
|
||||
# # TODO: make 'join' available.
|
||||
# md-to-pdf = join [
|
||||
# "pandoc \"$1\""
|
||||
# "-f gfm"
|
||||
# "-V linkcolor:blue"
|
||||
# "-V geometry:a4paper"
|
||||
# "-V geometry:margin=2cm"
|
||||
# "-V mainfont=\"Droid Sans\""
|
||||
# "--pdf-engine=xelatex"
|
||||
# "-o \"$2\""
|
||||
# ];
|
||||
# };
|
||||
# in ''
|
||||
initExtra = ''
|
||||
source ${config.home.homeDirectory}/${dotDir}/p10k.zsh
|
||||
'';
|
||||
|
||||
Reference in New Issue
Block a user