summaryrefslogtreecommitdiffstats
path: root/src/commands/command_line.rs
diff options
context:
space:
mode:
authorChristoph Jabs <98587286+chrjabs@users.noreply.github.com>2024-04-03 21:28:18 +0300
committerGitHub <noreply@github.com>2024-04-03 14:28:18 -0400
commitd9496689e29d9aaa1d55ec9ca822d36ef895381d (patch)
tree1b91ab964a2c171176c1d4aacedaf4ec7a05638a /src/commands/command_line.rs
parent2392951815447d2f1252fbd6ea7df23542c419cc (diff)
Zoxide related features (#506)
* make `:z` act more like zoxide before checking the zoxide database, check if the query is a directory that can be navigated to as by `:cd` also interpret `~` and `-` correctly * optionally track all movement in zoxide Add new config option `zoxide_update` with default false. When manually enabled, all directory navigation (via manually navigating or `:cd` and `:z`) will update the `zoxide` database. Since navigation via `:z` always updates the database, ensure that it doesn't update it twice. * support arguments for zoxide interactive support for `:zi <args>` where arguments are used to prefilter the matches provided in the interactive zoxide prompt * allow command aliases with arguments note: only aliases that do not contain spaces can be used with arguments since either the entire command or only the first word are checked against the aliases
Diffstat (limited to 'src/commands/command_line.rs')
-rw-r--r--src/commands/command_line.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index d423835..5f9d0de 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -22,12 +22,20 @@ pub fn read_and_execute(
.suffix(suffix)
.get_input(backend, context, &mut listener);
- if let Some(s) = user_input {
+ if let Some(mut s) = user_input {
let mut trimmed = s.trim_start();
let _ = context.commandline_context_mut().history_mut().add(trimmed);
+ let (command, arg) = match trimmed.find(' ') {
+ Some(i) => (&trimmed[..i], &trimmed[i..]),
+ None => (trimmed, ""),
+ };
+
if let Some(alias) = context.config_ref().cmd_aliases.get(trimmed) {
trimmed = alias;
+ } else if let Some(alias) = context.config_ref().cmd_aliases.get(command) {
+ s.replace_range(..s.len() - arg.len(), alias);
+ trimmed = &s;
}
let command = Command::from_str(trimmed)?;