mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 14:30:10 +01:00
fix: negative index
This commit is contained in:
parent
7b9cecfd8d
commit
ff7f27f250
3 changed files with 18 additions and 6 deletions
|
|
@ -23,7 +23,7 @@ regex-lite = "0.1"
|
|||
toml = { version = "0.7", optional = true }
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
|
||||
pay-respects-parser = "0.2.3"
|
||||
pay-respects-parser = "0.2.4"
|
||||
# pay-respects-parser = { path = "../pay-respects-parser" }
|
||||
|
||||
|
||||
|
|
|
|||
12
rules/mv.toml
Normal file
12
rules/mv.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
command = "mv"
|
||||
|
||||
[[match_err]]
|
||||
pattern = [
|
||||
"no such file or directory"
|
||||
]
|
||||
suggest = [
|
||||
'''
|
||||
mkdir --parents {{command[-1]}} && \
|
||||
{{command}} '''
|
||||
]
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ pub fn command(suggest: &mut String, split_command: &Vec<String>) {
|
|||
if let Some((start, end)) = range.split_once(':') {
|
||||
let mut start_index = start.parse::<i32>().unwrap_or(0);
|
||||
if start_index < 0 {
|
||||
start_index = split_command.len() as i32 - start_index;
|
||||
start_index = split_command.len() as i32 + start_index;
|
||||
};
|
||||
let mut end_index;
|
||||
let parsed_end = end.parse::<i32>();
|
||||
|
|
@ -66,7 +66,7 @@ pub fn command(suggest: &mut String, split_command: &Vec<String>) {
|
|||
} else {
|
||||
end_index = parsed_end.unwrap();
|
||||
if end_index < 0 {
|
||||
end_index = split_command.len() as i32 - end_index + 1;
|
||||
end_index = split_command.len() as i32 + end_index + 1;
|
||||
} else {
|
||||
end_index = end_index + 1;
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ pub fn typo(suggest: &mut String, split_command: &Vec<String>) {
|
|||
let command_index = command_index.parse::<i32>().unwrap();
|
||||
|
||||
let index = if command_index < 0 {
|
||||
split_command.len() as i32 - command_index
|
||||
split_command.len() as i32 + command_index
|
||||
} else {
|
||||
command_index
|
||||
};
|
||||
|
|
@ -106,7 +106,7 @@ pub fn typo(suggest: &mut String, split_command: &Vec<String>) {
|
|||
let (start, end) = command_index.split_once(':').unwrap();
|
||||
let start = start.parse::<i32>().unwrap_or(0);
|
||||
let start_index = if start < 0 {
|
||||
split_command.len() as i32 - start
|
||||
split_command.len() as i32 + start
|
||||
} else {
|
||||
start
|
||||
};
|
||||
|
|
@ -116,7 +116,7 @@ pub fn typo(suggest: &mut String, split_command: &Vec<String>) {
|
|||
} else {
|
||||
let end = end.unwrap();
|
||||
if end < 0 {
|
||||
split_command.len() as i32 - end + 1
|
||||
split_command.len() as i32 + end + 1
|
||||
} else {
|
||||
end + 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue