Skip to content

Instantly share code, notes, and snippets.

@pdalpra
Created February 23, 2022 16:48
Show Gist options
  • Save pdalpra/daf339f59288201a6c8ba7dc84e9060e to your computer and use it in GitHub Desktop.
Save pdalpra/daf339f59288201a6c8ba7dc84e9060e to your computer and use it in GitHub Desktop.
fun with configuring starship in Nix home-manager
{ pkgs, lib, ... }:
with lib;
with builtins;
let
isRustFile = path: type:
hasSuffix ".rs" path && type == "regular" && path != "mod.rs";
mergeAllAttrSets = attrsSets:
foldl' (recursiveUpdate) {} attrsSets;
disableModules = isDisabled: modules:
mergeAllAttrSets (map (mod: { "${mod}".disabled = isDisabled; }) modules);
starshipPackage = pkgs.unstable.starship;
promptOrder = [
"directory"
"git_branch"
"git_commit"
"git_state"
"git_metrics"
"git_status"
"line_break"
"nix_shell"
"rust"
"scala"
"java"
"character"
];
promptFormat = concatStrings (map (s: "\$${s}") promptOrder);
modulesSources = readDir "${starshipPackage.src}/src/modules";
enabledModules = disableModules false promptOrder; # <== enabled all modules used in the prompt are enabled
disabledModules = pipe modulesSources [ # <== from starship's sources...
(filterAttrs isRustFile) # <== keep only Rust files...
attrNames # <== get the filenames...
(map (removeSuffix ".rs")) # <== remove Rust source extension...
(subtractLists promptOrder) # <== do not disable modules used in the prompt...
(disableModules true) # <== and finally build the configuration
];
in
{
programs.starship = {
package = starshipPackage;
enable = true;
enableZshIntegration = true;
settings = mergeAllAttrSets [
enabledModules
disabledModules
{
format = promptFormat;
directory = {
format = "\\[[ $path](bold fg:39)\\]";
truncation_length = 4;
truncation_symbol = "…/";
};
git_branch = {
format = "\\[[$symbol$branch](bold fg:40)\\]";
truncation_length = 30;
};
}
];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment