-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
{ config, lib, pkgs, ... }: | ||
let | ||
yaml = pkgs.formats.yaml { }; | ||
bashLine = theme: | ||
''export LS_COLORS="$(${lib.getExe pkgs.vivid} generate ${theme})"''; | ||
fishLine = theme: | ||
"set -gx LS_COLORS (${lib.getExe pkgs.vivid} generate ${theme})"; | ||
nushellLine = theme: "${lib.getExe pkgs.vivid} generate ${theme}"; | ||
zshLine = bashLine; | ||
in { | ||
meta.maintainers = [ lib.maintainers.arunoruto ]; | ||
|
||
options.programs.vivid = { | ||
enable = lib.mkEnableOption '' | ||
vivid - A themeable LS_COLORS generator with a rich filetype datebase | ||
<link xlink:href="https://github.com/sharkdp/vivid" /> | ||
''; | ||
|
||
package = lib.mkPackageOption pkgs "vivid" { }; | ||
|
||
enableBashIntegration = lib.mkOption { | ||
default = true; | ||
type = lib.types.bool; | ||
description = '' | ||
Whether to enable Bash integration. | ||
Adds `${bashLine "<theme>"}` to Bash. | ||
''; | ||
}; | ||
|
||
enableFishIntegration = lib.mkOption { | ||
default = true; | ||
type = lib.types.bool; | ||
description = '' | ||
Whether to enable Fish integration. | ||
Adds `${fishLine "<theme>"}` to Fish. | ||
''; | ||
}; | ||
|
||
enableNushellIntegration = lib.mkOption { | ||
default = true; | ||
type = lib.types.bool; | ||
description = '' | ||
Whether to enable Nushell integration. | ||
Adds `${nushellLine "<theme>"}` to Nushell. | ||
''; | ||
}; | ||
|
||
enableZshIntegration = lib.mkOption { | ||
default = true; | ||
type = lib.types.bool; | ||
description = '' | ||
Whether to enable Zsh integration. | ||
Adds `${zshLine "<theme>"}` to Zsh. | ||
''; | ||
}; | ||
|
||
theme = lib.mkOption { | ||
type = lib.types.nullOr lib.types.str; | ||
default = null; | ||
example = "molokai"; | ||
description = '' | ||
Color theme to enable. | ||
Run `vivid themes` for a list of available themes. | ||
''; | ||
}; | ||
|
||
filetypes = lib.mkOption { | ||
type = yaml.type; | ||
default = { }; | ||
example = lib.literalExample '' | ||
{ | ||
core = { | ||
regular_file = [ "$fi" ]; | ||
directory = [ "$di" ]; | ||
}; | ||
text = { | ||
readme = [ "README.md" ]; | ||
licenses = [ "LICENSE" ]; | ||
}; | ||
} | ||
''; | ||
description = '' | ||
Configuration written to | ||
<filename>~/.config/vivid/filetypes.yml</filename>. | ||
Visit <link xlink:href="https://github.com/sharkdp/vivid/tree/master/config/filetypes.yml" /> | ||
for a reference file. | ||
''; | ||
}; | ||
|
||
themes = lib.mkOption { | ||
type = lib.types.attrsOf (yaml.type); | ||
default = { }; | ||
example = lib.literalExample '' | ||
{ | ||
mytheme = { | ||
colors = { | ||
blue = "0000ff"; | ||
}; | ||
core = { | ||
directory = { | ||
foreground = "blue"; | ||
font-style = "bold"; | ||
}; | ||
}; | ||
}; | ||
} | ||
''; | ||
description = '' | ||
Theme files written to | ||
<filename>~/.config/vivid/themes/<mytheme>.yml</filename>. | ||
Visit <link xlink:href="https://github.com/sharkdp/vivid/tree/master/themes" /> | ||
for references. | ||
''; | ||
}; | ||
}; | ||
|
||
config = let cfg = config.programs.vivid; | ||
in lib.mkIf cfg.enable { | ||
home.packages = [ cfg.package ]; | ||
|
||
programs.bash.initExtra = | ||
lib.mkIf cfg.enableBashIntegration (bashLine cfg.theme); | ||
programs.fish.interactiveShellInit = | ||
lib.mkIf cfg.enableFishIntegration (fishLine cfg.theme); | ||
programs.nushell.environmentVariables.LS_COLORS = | ||
lib.mkIf cfg.enableNushellIntegration | ||
(lib.hm.nushell.mkNushellInline (nushellLine cfg.theme)); | ||
programs.zsh.initExtra = | ||
lib.mkIf cfg.enableZshIntegration (zshLine cfg.theme); | ||
|
||
xdg.configFile = { | ||
"vivid/filetypes.yml" = | ||
lib.mkIf (builtins.length (builtins.attrNames cfg.filetypes) > 0) { | ||
source = yaml.generate "filetypes.yml" cfg.filetypes; | ||
}; | ||
} // lib.mapAttrs' (name: value: | ||
lib.nameValuePair "vivid/themes/${name}.yml" { | ||
source = yaml.generate "${name}.yml" value; | ||
}) cfg.themes; | ||
}; | ||
} |