From 4b44d727656e0dfde7accc7b81777cd986c64af9 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sun, 23 Jan 2022 22:23:04 -0500 Subject: [PATCH] Default to alphanumeric sort --- Cargo.toml | 1 + src/main.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 934e368..913870c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ keywords = ["cli", "kakoune"] [dependencies] regex = "1" clap = {version = "3", features = ["derive"]} +alphanumeric-sort = "1" [profile.release] lto = true diff --git a/src/main.rs b/src/main.rs index ec8e374..3adc2d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)] +use alphanumeric_sort::compare_str; use clap::Parser; use regex::Regex; @@ -15,6 +16,8 @@ struct Options { regex: String, #[clap(multiple_occurrences = true, required = true)] selections: Vec, + #[clap(short, long)] + lexicographic_sort: bool, } fn main() { @@ -25,6 +28,7 @@ fn main() { } fn send_message(msg: &KakMessage) { + // TODO: This isn't echoing anything let msg_str = msg.0.replace('\'', "''"); print!("echo '{}';", msg_str); @@ -78,7 +82,12 @@ fn run() -> Result<(), KakMessage> { zipped.sort_by(|(a, a_key), (b, b_key)| { let a = a_key.unwrap_or(a); let b = b_key.unwrap_or(b); - a.cmp(b) + + if options.lexicographic_sort { + a.cmp(b) + } else { + compare_str(a, b) + } }); print!("reg '\"'");