Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
m42e committed Mar 31, 2022
2 parents d881406 + 844bd49 commit 0e56012
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Well, it accesses the [zsh histdb](https://github.com/larkery/zsh-histdb). It le
Install the plugin, e.g. using [zplug](https://github.com/zplug/zplug).

```
zplug 'm42e/zsh-histdb-skim', from:github, use:zsh-histdb-skim.zsh
zplug 'm42e/zsh-histdb-skim', from:github, use:zsh-histdb-skim.zsh, at:main
```

It downloads the binary (if available) automatically. You can do manually by calling `histdb-skim-download`.
Expand Down
73 changes: 50 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,53 @@ fn restore_screen(){
println!("\x1b[2J\x1b[?47l\x1b8");
}

fn generate_title(location: &Location) -> String {
let extra_info = |theloc: &Location| -> String {
return match theloc {
Location::Session => get_current_session_id(),
Location::Directory => get_current_dir(),
Location::Machine => get_current_host(),
_ => String::from(""),
};
}(&location);

let location_map = enum_map! {
Location::Session => "Session location history",
Location::Directory => "Directory location history",
Location::Machine => "Machine location history",
Location::Everywhere => "Everywhere",
};

let header_map = enum_map! {
Location::Session =>"
┏━━━━━━━━━━━┱─────────────┬────────┬──────────────┐
┃F1: Session┃F2: Directory│F3: Host│F4: Everywhere│ F5: Toggle group
━┛ ┗━━━━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━",
Location::Directory => "
┌───────────┲━━━━━━━━━━━━━┱────────┬──────────────┐
│F1: Session┃F2: Directory┃F3: Host│F4: Everywhere│ F5: Toggle group
━┷━━━━━━━━━━━┛ ┗━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━",

Location::Machine => "
┌───────────┬─────────────┲━━━━━━━━┱──────────────┐
│F1: Session│F2: Directory┃F3: Host┃F4: Everywhere│ F5: Toggle group
━┷━━━━━━━━━━━┷━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━",

Location::Everywhere => "
┌───────────┬─────────────┬────────┲━━━━━━━━━━━━━━┓
│F1: Session│F2: Directory│F3: Host┃F4: Everywhere┃ F5: Toggle group
━┷━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━",
};

let title = format!(
"{} {}\n{}\n",
&location_map[location.clone()],
&extra_info,
&header_map[location.clone()],
);
return title.to_string();
}

fn show_history(thequery: String) -> Result<String> {
let mut location = Location::Session;
let mut grouped = true;
Expand All @@ -184,27 +231,7 @@ fn show_history(thequery: String) -> Result<String> {
}

loop {
let map = enum_map! {
Location::Session => "Session location history",
Location::Directory => "Directory location history",
Location::Machine => "Machine location history",
Location::Everywhere => "Everywhere",
};
let extra_info = |theloc: &Location| -> String {
return match theloc {
Location::Session => get_current_session_id(),
Location::Directory => get_current_dir(),
Location::Machine => get_current_host(),
_ => String::from(""),
};
}(&location);

let title = format!(
"{} {}\n{}\n―――――――――――――――――――――――――",
&map[location.clone()],
&extra_info,
"F1: Session, F2: Directory, F3: Host, F4: Everywhere -- F5: Toggle group"
);
let title = generate_title(&location);

let options = SkimOptionsBuilder::default()
.height(Some("100%"))
Expand Down Expand Up @@ -333,11 +360,11 @@ fn build_query_string(theloc: &Location, grouped: bool) -> String {
};
match theloc {
Location::Session => {
query.push_str(&format!(" session in ({}) and ", &get_current_session_id()))
query.push_str(&format!(" session in ({}) and ", &get_current_session_id()));
}

Location::Directory => {
query.push_str(&format!(" (places.dir like '{}') and ", &get_current_dir()))
query.push_str(&format!(" (places.dir like '{}') and ", &get_current_dir()));
}

_ => {}
Expand Down
2 changes: 1 addition & 1 deletion zsh-histdb-skim.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ histdb-skim-widget() {
histdb-skim-ensure
origquery=${BUFFER}
output=$( \
HISTDB_HOST=$HISTDB_HOST \
HISTDB_HOST=${HISTDB_HOST:-"'$(sql_escape ${HOST})'"} \
HISTDB_SESSION=$HISTDB_SESSION \
HISTDB_FILE=$HISTDB_FILE \
${BIN_PATH} "$origquery"\
Expand Down

0 comments on commit 0e56012

Please sign in to comment.