From f70b6711a227aa2b12322f8004f464f95c695ca2 Mon Sep 17 00:00:00 2001 From: Kurt Wolf <79804461+kurtbuilds@users.noreply.github.com> Date: Wed, 1 Dec 2021 22:38:57 -0500 Subject: [PATCH] Make completions work with Bash alias (#1035) --- README.adoc | 6 ++++++ completions/just.bash | 2 +- src/completions.rs | 11 +++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.adoc b/README.adoc index 5d41875..f6631e2 100644 --- a/README.adoc +++ b/README.adoc @@ -1750,6 +1750,12 @@ Tools that pair nicely with `just` include: For lightning-fast command running, put `alias j=just` in your shell's configuration file. +In `bash`, the aliased command may not keep the shell completion functionality described in the next section. Add the following line to your `.bashrc` to use the same completion function as `just` for your aliased command: + +```sh +complete -F _just -o bashdefault -o default j +``` + === Shell Completion Scripts Shell completion scripts for Bash, Zsh, Fish, PowerShell, and Elvish are available in the link:completions[] directory. Please refer to your shell's documentation for how to install them. diff --git a/completions/just.bash b/completions/just.bash index 102ac55..8ef93b6 100644 --- a/completions/just.bash +++ b/completions/just.bash @@ -9,7 +9,7 @@ _just() { for i in ${COMP_WORDS[@]} do case "${i}" in - just) + "$1") cmd="just" ;; diff --git a/src/completions.rs b/src/completions.rs index a97e405..5292e67 100644 --- a/src/completions.rs +++ b/src/completions.rs @@ -156,12 +156,13 @@ pub(crate) const POWERSHELL_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[( Sort-Object -Property ListItemText"#, )]; -pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[( - r#" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then +pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[ + ( + r#" if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 fi"#, - r#" if [[ ${cur} == -* ]] ; then + r#" if [[ ${cur} == -* ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 elif [[ ${COMP_CWORD} -eq 1 ]]; then @@ -171,4 +172,6 @@ pub(crate) const BASH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[( return 0 fi fi"#, -)]; + ), + (r#" just)"#, r#" "$1")"#), +];