aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonas Maier <jonas@x77.dev>2026-05-14 16:37:21 +0200
committerJonas Maier <jonas@x77.dev>2026-05-14 16:37:21 +0200
commit843f6a9f7ffed9b1e5843778ce907b6382978f80 (patch)
tree41f0e7aff961dbef154ca177ca518d7caebdfce8 /src
parent7cb3e5fbf183c24a91c75c9afed85127ebf5123c (diff)
downloadpish-843f6a9f7ffed9b1e5843778ce907b6382978f80.tar.gz
nicer pipe behavior
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs24
-rw-r--r--src/profile1
-rw-r--r--src/run/builtin.rs1
3 files changed, 19 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 2ad9157..3931f5d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -261,16 +261,16 @@ impl Session {
}
}
- fn type_byte(&mut self, b: u8) {
- self.line.add(b);
- io::stdout().lock().write_all(&[b]).unwrap();
- self.line.display_post(b"");
- }
-
fn type_bytes(&mut self, bs: &[u8]) {
for b in bs.iter() {
- self.type_byte(*b);
+ self.line.add(*b);
}
+ io::stdout().lock().write_all(&bs).unwrap();
+ self.line.display_post(b"");
+ }
+
+ fn type_byte(&mut self, b: u8) {
+ self.type_bytes(&[b]);
}
fn del_left(&mut self) {
@@ -295,6 +295,16 @@ impl Session {
}
}
+ fn prompt_pipe_previous(&mut self) {
+ if self.line.is_empty() && let Some(prev) = self.history.last() {
+ let mut cmd = prev.cmd.clone();
+ cmd.push_all(b" | ");
+ self.type_bytes(&cmd);
+ } else {
+ self.type_byte(b'|');
+ }
+ }
+
fn move_to_begin(&mut self) {
cursor::move_cursor(Direction::Left, self.line.all_left());
io::stdout().flush().unwrap();
diff --git a/src/profile b/src/profile
index 5283e8f..59fc961 100644
--- a/src/profile
+++ b/src/profile
@@ -18,6 +18,7 @@ bind key \r ct try_submit_command
bind key \n ct try_submit_command
bind key \x1bd ct prompt_del_right_word
bind key \x17 ct prompt_del_left_word
+bind key '|' ct prompt_pipe_previous
alias ls = 'ls --color=auto'
echo hello to pish!
diff --git a/src/run/builtin.rs b/src/run/builtin.rs
index 044206d..d00c140 100644
--- a/src/run/builtin.rs
+++ b/src/run/builtin.rs
@@ -793,6 +793,7 @@ impl Builtin for ct {
b"prompt_del_left_word" => se.del_left_word(),
b"prompt_del_right_word" => se.del_right_word(),
b"prompt_del_left_or_previous" => se.del_left_or_previous(),
+ b"prompt_pipe_previous" => se.prompt_pipe_previous(),
b"complete" => {
drop(se);
Session::complete(session)