71 lines
2.8 KiB
Nix
71 lines
2.8 KiB
Nix
{
|
|
description = "Bash Prompt Builder";
|
|
|
|
inputs = { };
|
|
|
|
outputs = { self, ... }@inputs: {
|
|
# ESC = "\\033";
|
|
ESC = "\\e";
|
|
CSI = "${self.ESC}[";
|
|
OSC = "${self.ESC}]";
|
|
ST = "${self.ESC}\\134";
|
|
# BEL = "\\007";
|
|
BEL = "\\a";
|
|
|
|
nonprinting_begin = "\\[";
|
|
nonprinting_end = "\\]";
|
|
wrap_nonprinting = text: "${self.nonprinting_begin}${text}${self.nonprinting_end}";
|
|
|
|
# https://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html
|
|
|
|
prompt = "\\$";
|
|
current_working_directory = "\\w";
|
|
username = "\\u";
|
|
hostname_short = "\\h";
|
|
hostname_long = "\\H";
|
|
|
|
ansi_reset = self.wrap_nonprinting "${self.CSI}0m";
|
|
ansi_color = style: color: self.wrap_nonprinting "${self.CSI}${builtins.toString style};${builtins.toString color}m";
|
|
ansi_style_normal = 1;
|
|
|
|
ansi_normal_color = color: self.ansi_color self.ansi_style_normal color;
|
|
|
|
ansi_normal_black = self.ansi_normal_color 30;
|
|
ansi_normal_red = self.ansi_normal_color 31;
|
|
ansi_normal_green = self.ansi_normal_color 32;
|
|
ansi_normal_yellow = self.ansi_normal_color 33;
|
|
ansi_normal_blue = self.ansi_normal_color 34;
|
|
ansi_normal_magenta = self.ansi_normal_color 35;
|
|
ansi_normal_cyan = self.ansi_normal_color 36;
|
|
ansi_normal_white = self.ansi_normal_color 37;
|
|
|
|
# https://www.xfree86.org/current/ctlseqs.html
|
|
|
|
title_bar = title: self.icon_name_and_window_title title;
|
|
|
|
icon_name_and_window_title = title: self.wrap_nonprinting "${self.OSC}0;${title}${self.BEL}";
|
|
icon_name = title: self.wrap_nonprinting "${self.OSC}1;${title}${self.BEL}";
|
|
window_title = title: self.wrap_nonprinting "${self.OSC}2;${title}${self.BEL}";
|
|
|
|
ansi_fg24bit_color = r: g: b:
|
|
(
|
|
assert (r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255);
|
|
"${self.OSC}38;2;${builtins.toString r};${builtins.toString g};${builtins.toString b}m"
|
|
);
|
|
|
|
ansi_bg24bit_color = r: g: b:
|
|
(
|
|
assert (r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255);
|
|
"${self.OSC}48;2;${builtins.toString r};${builtins.toString g};${builtins.toString b}m"
|
|
);
|
|
|
|
ps1_start = self.wrap_nonprinting "${self.OSC}133;A${self.BEL}";
|
|
build_ps0_prompt = self.wrap_nonprinting "${self.OSC}133;C${self.BEL}";
|
|
build_ps1_prompt = color: title_bar_text: prompt_text: "${self.ps1_start}${color}[${self.icon_name_and_window_title title_bar_text}${prompt_text}]${self.prompt}${self.ansi_reset} ";
|
|
build_ps1_prompt_notitle = color: prompt_text: "${self.ps1_start}${color}[${prompt_text}]${self.prompt}${self.ansi_reset} ";
|
|
ps2_start = self.wrap_nonprinting "${self.OSC}133;A;k=s${self.BEL}";
|
|
build_ps2_prompt = color: "${self.ps2_start}${color}>${self.ansi_reset} ";
|
|
build_ps4_prompt = color: "${color}+${self.ansi_reset} ";
|
|
};
|
|
}
|