Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/src/features/user-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ They will be replaced with their respective values command is executed.
- The hashes of all parents of the selected commit, separated by a space.
- example: `c103d9744df8ebf100773a11345f011152ec5581 a1b2c3d4e5f67890123456789abcdef0123456789`
- `{{refs}}`
- The names of all refs (branches, tags, stashes) pointing to the selected commit, separated by a space.
- The names of all refs (branches, remote branches, tags) pointing to the selected commit, separated by a space.
- example: `master v1.0.0`
- `{{branches}}`
- The names of all branches pointing to the selected commit, separated by a space.
Expand All @@ -74,6 +74,9 @@ They will be replaced with their respective values command is executed.
- `{{tags}}`
- The names of all tags pointing to the selected commit, separated by a space.
- example: `v1.0.0 v1.0.1`
- `{{stash}}`
- The name of the stash when the selected commit is a stash commit. Otherwise, this is an empty string.
- example: `stash@{0}`
- `{{area_width}}`
- Width of the user command display area (number of cells).
- example: `80`
Expand Down
7 changes: 6 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,16 @@ fn build_external_command_parameters<'a>(
let mut branches = vec![];
let mut remote_branches = vec![];
let mut tags = vec![];
let mut stash = None;
for r in refs {
match r {
Ref::Tag { .. } => tags.push(r.name()),
Ref::Branch { .. } => branches.push(r.name()),
Ref::RemoteBranch { .. } => remote_branches.push(r.name()),
Ref::Stash { .. } => continue, // skip stashes
Ref::Stash { .. } => {
stash = Some(r.name());
continue; // skip stashes from {{refs}}
}
}
all_refs.push(r.name());
}
Expand All @@ -808,6 +812,7 @@ fn build_external_command_parameters<'a>(
branches,
remote_branches,
tags,
stash,
area_width,
area_height,
})
Expand Down
4 changes: 4 additions & 0 deletions src/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const USER_COMMAND_REFS_MARKER: &str = "{{refs}}";
const USER_COMMAND_BRANCHES_MARKER: &str = "{{branches}}";
const USER_COMMAND_REMOTE_BRANCHES_MARKER: &str = "{{remote_branches}}";
const USER_COMMAND_TAGS_MARKER: &str = "{{tags}}";
const USER_COMMAND_STASH_MARKER: &str = "{{stash}}";
const USER_COMMAND_AREA_WIDTH_MARKER: &str = "{{area_width}}";
const USER_COMMAND_AREA_HEIGHT_MARKER: &str = "{{area_height}}";

Expand Down Expand Up @@ -78,6 +79,7 @@ pub struct ExternalCommandParameters<'a> {
pub branches: Vec<&'a str>,
pub remote_branches: Vec<&'a str>,
pub tags: Vec<&'a str>,
pub stash: Option<&'a str>,
pub area_width: u16,
pub area_height: u16,
}
Expand Down Expand Up @@ -152,6 +154,7 @@ fn replace_command_arg(s: &str, params: &ExternalCommandParameters) -> String {
let branches = &params.branches.join(sep);
let remote_branches = &params.remote_branches.join(sep);
let tags = &params.tags.join(sep);
let stash = params.stash.unwrap_or_default();
let area_width = &params.area_width.to_string();
let area_height = &params.area_height.to_string();

Expand All @@ -162,6 +165,7 @@ fn replace_command_arg(s: &str, params: &ExternalCommandParameters) -> String {
.replace(USER_COMMAND_BRANCHES_MARKER, branches)
.replace(USER_COMMAND_REMOTE_BRANCHES_MARKER, remote_branches)
.replace(USER_COMMAND_TAGS_MARKER, tags)
.replace(USER_COMMAND_STASH_MARKER, stash)
.replace(USER_COMMAND_AREA_WIDTH_MARKER, area_width)
.replace(USER_COMMAND_AREA_HEIGHT_MARKER, area_height)
}