diff --git a/Cargo.lock b/Cargo.lock index 73b6ea7..584ec3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -549,6 +549,7 @@ version = "0.6.1" dependencies = [ "ansi-to-tui", "anyhow", + "base64", "chrono", "clap", "insta", diff --git a/Cargo.toml b/Cargo.toml index 2c6759f..c5ddb8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ pkg-url = "{ repo }/releases/download/v{ version }/lazyjj-v{ version }-{ target ansi-to-tui = { git = "https://github.com/Cretezy/ansi-to-tui.git", rev = "74bd97e" } anyhow = "1.0.95" chrono = "0.4.39" +crossterm = "0.29.0" clap = { version = "4.5.31", features = ["derive", "env"] } insta = { version = "1.42.1", features = ["filters"] } itertools = "0.14.0" diff --git a/README.md b/README.md index c592d9e..fa85ce9 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ https://github.com/Cretezy/lazyjj/assets/2672503/b5e6b4f1-ebdb-448f-af9e-361e86f - Set a bookmark to selected change with `b` - Fetch/push with `f`/`p` - Squash current changes to selected change with `s`/`S` + - Yank change ID/revision to the system clipboard with `y`/`Y` - Files - View files in current change and diff in side panel - See a change's files from the log tab with `Enter` diff --git a/docs/keybindings.md b/docs/keybindings.md index 1752407..8e6864a 100644 --- a/docs/keybindings.md +++ b/docs/keybindings.md @@ -41,6 +41,8 @@ describe = "d" edit-revset = "r" set-bookmark = "b" open-files = "enter" +copy-change-id = "y" +copy-rev = "shift+y" push = "p" push-new = "ctrl+p" diff --git a/src/keybinds/config.rs b/src/keybinds/config.rs index fd70a7d..e1b1586 100644 --- a/src/keybinds/config.rs +++ b/src/keybinds/config.rs @@ -42,6 +42,8 @@ pub struct LogTabKeybindsConfig { pub edit_revset: Option, pub set_bookmark: Option, pub open_files: Option, + pub copy_change_id: Option, + pub copy_rev: Option, pub rebase: Option, pub push: Option, diff --git a/src/keybinds/log_tab.rs b/src/keybinds/log_tab.rs index 1bd43f8..5c4c569 100644 --- a/src/keybinds/log_tab.rs +++ b/src/keybinds/log_tab.rs @@ -44,6 +44,8 @@ pub enum LogTabEvent { EditRevset, SetBookmark, OpenFiles, + CopyChangeId, + CopyRev, Push { all_bookmarks: bool, @@ -90,6 +92,8 @@ impl Default for LogTabKeybinds { LogTabEvent::EditRevset => "r", LogTabEvent::SetBookmark => "b", LogTabEvent::OpenFiles => "enter", + LogTabEvent::CopyChangeId => "y", + LogTabEvent::CopyRev => "shift+y", event_push(false, false) => "p", event_push(false, true) => "ctrl+p", event_push(true, false) => "shift+p", @@ -136,6 +140,8 @@ impl LogTabKeybinds { LogTabEvent::EditRevset => config.edit_revset, LogTabEvent::SetBookmark => config.set_bookmark, LogTabEvent::OpenFiles => config.open_files, + LogTabEvent::CopyChangeId => config.copy_change_id, + LogTabEvent::CopyRev => config.copy_rev, LogTabEvent::Rebase => config.rebase, event_push(false, false) => config.push, event_push(false, true) => config.push_new, @@ -166,6 +172,8 @@ impl LogTabKeybinds { LogTabEvent::Squash { ignore_immutable: false } => "squash @ into the selected change", LogTabEvent::Squash { ignore_immutable: true } => "squash @ into the selected change ignoring immutability", LogTabEvent::SetBookmark => "set bookmark", + LogTabEvent::CopyChangeId => "yank change id to clipboard", + LogTabEvent::CopyRev => "yank revision to clipboard", LogTabEvent::Fetch { all_remotes: false } => "git fetch", LogTabEvent::Fetch { all_remotes: true } => "git fetch all remotes", event_push(false, false) => "git push", diff --git a/src/ui/log_tab.rs b/src/ui/log_tab.rs index 8440b00..a9a5179 100644 --- a/src/ui/log_tab.rs +++ b/src/ui/log_tab.rs @@ -2,6 +2,7 @@ use ansi_to_tui::IntoText; use anyhow::Result; +use crossterm::{clipboard::CopyToClipboard, execute}; use ratatui::{ crossterm::event::{Event, KeyEventKind}, layout::Rect, @@ -380,6 +381,16 @@ impl<'a> LogTab<'a> { ComponentAction::ViewFiles(self.head.clone()), )); } + LogTabEvent::CopyChangeId => { + // Copy change ID to clipboard using crossterm + let change_id = self.head.change_id.as_str(); + let _ = execute!(std::io::stdout(), CopyToClipboard::to_clipboard_from(change_id)); + } + LogTabEvent::CopyRev => { + // Copy revision (commit ID) to clipboard using crossterm + let commit_id = self.head.commit_id.as_str(); + let _ = execute!(std::io::stdout(), CopyToClipboard::to_clipboard_from(commit_id)); + } LogTabEvent::Push { all_bookmarks, allow_new,