This commit is contained in:
Daniel Knuettel 2024-04-16 20:34:30 +02:00
parent 8fac4e5aff
commit 73be916538
2 changed files with 36 additions and 16 deletions

View File

@ -3,6 +3,8 @@ bin_path=$(pwd)/target/debug/make_prompt
PROMPT_COMMAND='make_prompt'
make_prompt () {
local prompt_pref=$($bin_path $?)
local lastexit=$?
local bgjobs=$(jobs | wc -l)
local prompt_pref=$($bin_path $lastexit $bgjobs)
PS1="$prompt_pref"
}

View File

@ -5,7 +5,7 @@ use std::io::BufRead;
fn fixed_width(input: &String, len: usize) -> String
{
let clen = input.len();
let clen = input.chars().count();
const PLACE_HOLDER: &str = "🤄";
if clen > len
@ -21,8 +21,8 @@ fn fixed_width(input: &String, len: usize) -> String
else
{
let n_pad = len - clen;
let n_pad_left = n_pad / 2;
let n_pad_right = n_pad_left + { if n_pad % 2 == 0 {0} else {1}};
let n_pad_right = n_pad / 2;
let n_pad_left = n_pad_right + { if n_pad % 2 == 0 {0} else {1}};
let mut result: String = str::repeat(" ", n_pad_left).to_owned();
result.push_str(input);
result.push_str(&str::repeat(" ", n_pad_right));
@ -197,15 +197,28 @@ fn main()
}
};
let raw_cwd = getenv("PWD");
let home = getenv("HOME");
let cwd = {
if raw_cwd.starts_with(&home)
{
let everything_after_home = &raw_cwd[home.len()..];
let mut res = "~".to_string();
res.push_str(everything_after_home);
res
}
else
{
raw_cwd.to_string()
}
};
let bgjobs = {
if args.len() <= 2
{
let promise = std::env::current_dir();
match promise
{
Ok(v) => v.display().to_string(),
Err(_reason) => panic!("failed to get cwd")
}
"0".to_string()
}
else
{
@ -219,18 +232,23 @@ fn main()
print!("{}{}", shell_color_str(&"┌[", SH_GREEN)
, battery_info(12));
print!("{}{}", shell_color_str(&"|", SH_GREEN)
, fixed_width(&get_git_branch(& std::path::Path::new(&cwd)), 12));
, fixed_width(&get_git_branch(& std::path::Path::new(&raw_cwd)), 10));
print!("{}{}", shell_color_str(&"|", SH_GREEN)
, fixed_width(&get_editor(), 10));
, fixed_width(&get_editor(), 12));
print!("{}{}", shell_color_str(&"|", SH_GREEN)
, fixed_width(lastexit, 4));
, fixed_width(lastexit, 3));
println!("{}", shell_color_str(&"]┐", SH_GREEN));
}
{
print!("{}{}", shell_color_str(&"╞[", SH_GREEN)
, fixed_width(&getenv("HOSTNAME"), 12));
, shell_color_str(&fixed_width(&getenv("HOSTNAME"), 12), SH_CYAN));
print!("{}{}", shell_color_str(&"|", SH_GREEN)
, fixed_width(&getenv("USER"), 10));
, shell_color_str(&fixed_width(&getenv("USER"), 10), SH_RED));
print!("{}{}", shell_color_str(&"|", SH_GREEN)
, fixed_width(&cpu_arch, 12));
print!("{}{}", shell_color_str(&"|", SH_GREEN)
, fixed_width(&bgjobs, 3));
println!("{}", shell_color_str(&"]┘", SH_GREEN));
}
{