Skip to content

Commit

Permalink
fish_completions: replace sed with awk
Browse files Browse the repository at this point in the history
  • Loading branch information
l4zygreed committed Oct 25, 2023
1 parent fac6c66 commit 549ac68
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
28 changes: 27 additions & 1 deletion completions/just.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
function __fish_just_complete_recipes
just --list 2> /dev/null | sed -E -e '1d; s/^[[:space:]]*([^[:space:]]+)[[:space:]]*#[[:space:]]*(.*)$/\1\t\2/' -e 's/^[[:space:]]*([^[:space:]]+)[[:space:]]*$/\1/'
just --list 2> /dev/null | tail -n +2 | awk '{
command = $1;
args = $0;
desc = "";
delim = "";
sub(/^[[:space:]]*[^[:space:]]*/, "", args);
gsub(/^[[:space:]]+|[[:space:]]+$/, "", args);
if (match(args, /#.*/)) {
desc = substr(args, RSTART+2, RLENGTH)
args = substr(args, 0, RSTART-1)
gsub(/^[[:space:]]+|[[:space:]]+$/, "", args);
}
gsub(/\+|=[`\'"][^`\'"]*[`\'"]/, "", args)
gsub(/ /, ",", args)
if (args != ""){
args = "Args: " args
}
if (args != "" && desc != "") {
delim = "; "
}
print command "\t" args delim desc
}'
end

# don't suggest files right off
Expand Down
28 changes: 27 additions & 1 deletion src/completions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
pub(crate) const FISH_RECIPE_COMPLETIONS: &str = r#"function __fish_just_complete_recipes
just --list 2> /dev/null | sed -E -e '1d; s/^[[:space:]]*([^[:space:]]+)[[:space:]]*#[[:space:]]*(.*)$/\1\t\2/' -e 's/^[[:space:]]*([^[:space:]]+)[[:space:]]*$/\1/'
just --list 2> /dev/null | tail -n +2 | awk '{
command = $1;
args = $0;
desc = "";
delim = "";
sub(/^[[:space:]]*[^[:space:]]*/, "", args);
gsub(/^[[:space:]]+|[[:space:]]+$/, "", args);
if (match(args, /#.*/)) {
desc = substr(args, RSTART+2, RLENGTH)
args = substr(args, 0, RSTART-1)
gsub(/^[[:space:]]+|[[:space:]]+$/, "", args);
}
gsub(/\+|=[`\'"][^`\'"]*[`\'"]/, "", args)
gsub(/ /, ",", args)
if (args != ""){
args = "Args: " args
}
if (args != "" && desc != "") {
delim = "; "
}
print command "\t" args delim desc
}'
end
# don't suggest files right off
Expand Down

0 comments on commit 549ac68

Please sign in to comment.