Skip to content

Commit

Permalink
implement sigi edit in interactive mode too
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed May 29, 2024
1 parent 71f750c commit f1e6a2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const DELETE_ALL_TERMS: [&str; 6] = [
"cancel-all",
"drop-all",
];
const EDIT_TERMS: [&str; 1] = ["edit"];
const HEAD_TERMS: [&str; 3] = ["head", "top", "first"];
const IS_EMPTY_TERMS: [&str; 2] = ["is-empty", "empty"];
const LIST_TERMS: [&str; 4] = ["list", "ls", "snoop", "all"];
Expand Down Expand Up @@ -138,7 +139,7 @@ enum Command {
},

/// Edit the content of an item. Other metadata like creation date is left unchanged.
#[command()]
#[command(visible_aliases = &EDIT_TERMS[1..])]
Edit {
/// The editor to execute. If unspecified, the editor launched will be the value of
/// VISUAL, EDITOR, or if both env variables are unset, nano.
Expand Down Expand Up @@ -287,10 +288,7 @@ impl Command {
Command::Edit { editor, n, fc } => (
Edit {
stack,
editor: editor
.or_else(|| std::env::var("VISUAL").ok())
.or_else(|| std::env::var("EDITOR").ok())
.unwrap_or("nano".into()),
editor: resolve_editor(editor),
index: n.unwrap_or(0),
},
fc,
Expand Down Expand Up @@ -321,6 +319,13 @@ impl Command {
}
}

pub fn resolve_editor(editor: Option<String>) -> String {
editor
.or_else(|| std::env::var("VISUAL").ok())
.or_else(|| std::env::var("EDITOR").ok())
.unwrap_or("nano".into())
}

#[derive(Args)]
struct FormatConfig {
#[arg(short, long)]
Expand Down
8 changes: 8 additions & 0 deletions src/cli/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ fn parse_effect(tokens: Vec<&str>, stack: String) -> ParseEffectResult {
if DELETE_ALL_TERMS.contains(term) {
return Effect(DeleteAll { stack });
}
if EDIT_TERMS.contains(term) {
let index = parse_n().unwrap_or(0);
return Effect(Edit {
stack,
editor: resolve_editor(None),
index,
});
}
if HEAD_TERMS.contains(term) {
let n = parse_n().unwrap_or(DEFAULT_SHORT_LIST_LIMIT);
return Effect(Head { stack, n });
Expand Down

0 comments on commit f1e6a2c

Please sign in to comment.