nixos-config/modules/cli/powerline.nix

58 lines
1.4 KiB
Nix
Raw Normal View History

2021-10-11 17:08:18 +00:00
{ config, pkgs, lib, ... }:
let
2021-10-11 17:08:18 +00:00
cfg = config.sconfig.powerline;
theme = pkgs.writeText "powerline.json" (builtins.toJSON
{
BoldForeground = true;
CwdFg = 15;
PathBg = 24;
PathFg = 15;
SeparatorFg = 16;
});
2021-10-11 17:08:18 +00:00
in
{
options.sconfig.powerline =
{
enable = lib.mkOption {
type = lib.types.bool;
default = true;
};
args = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [
2022-09-01 16:02:38 +00:00
"-modules=\${remote:+'user,host,'}nix-shell,git,jobs,cwd"
2021-10-11 17:08:18 +00:00
"-git-assume-unchanged-size 0"
"-theme ${theme}"
"-path-aliases '~/git=~/git'"
2021-10-11 17:08:18 +00:00
"-jobs $(jobs -p | wc -l)"
2022-10-09 06:31:02 +00:00
];
2021-10-11 17:08:18 +00:00
};
};
config = lib.mkIf cfg.enable {
2022-09-01 16:02:38 +00:00
environment.systemPackages = [ pkgs.powerline-go ];
2021-10-11 17:08:18 +00:00
programs.bash.interactiveShellInit = ''
2023-01-30 20:33:04 +00:00
function _fix_partial_lines() {
# print our own newline if program output doesn't end with one
local COL
local ROW
IFS=';' read -sdR -p $'\e[6n' ROW COL
[ "$COL" = "1" ] || echo -e '\e[100m \e[0m'
}
2021-10-11 17:08:18 +00:00
function _update_ps1() {
local remote=y
[ "$XDG_SESSION_TYPE" = "x11" ] && unset remote
[ "$XDG_SESSION_TYPE" = "wayland" ] && unset remote
2023-01-29 07:15:35 +00:00
PS1="$(powerline-go ${toString cfg.args})"
2021-10-11 17:08:18 +00:00
}
2023-01-30 20:33:04 +00:00
[ "$TERM" = "linux" ] || PROMPT_COMMAND="_fix_partial_lines; _update_ps1; $PROMPT_COMMAND"
2021-10-11 17:08:18 +00:00
'';
};
}