summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index a73c2c4..d58e9e0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,4 @@
-use std::env;
+use std::env::{self, current_dir};
use std::io::{self, Write};
use std::sync::{Arc, Mutex};
mod buffer;
@@ -48,6 +48,24 @@ fn repl(
Err(_) => String::from("|> "),
};
+ // Update shell title
+ let home = env!("HOME");
+ let mut title = match current_dir() {
+ Ok(path) => String::from(path.as_os_str().to_str().unwrap_or("dwvsh")),
+ Err(_) => String::from("dwvsh"),
+ };
+
+ if home.len() < title.len() && (home == &title[0..home.len()]) {
+ for _ in 0..home.len() {
+ title.remove(0);
+ }
+ title = String::from("~") + &title;
+ } else if *home == title {
+ title = String::from("~");
+ }
+
+ print!("\x1b]0;{}\x07", title);
+
// Output the prompt
print!("{}", prompt);
io::stdout().flush().unwrap();
@@ -83,6 +101,14 @@ fn repl(
// Not at the prompt
*away.lock().unwrap() = true;
+ // Update shell title (max command length of 32 for now)
+ if poetry.len() > 32 {
+ print!("\x1b]0;{}...\x07", &poetry[0..32]);
+ } else {
+ print!("\x1b]0;{}\x07", &poetry);
+ }
+ io::stdout().flush().unwrap();
+
// Parse the poem
let poem = Poem::read(poetry.to_string(), env);
let poem = match poem {