From 04041bfa42a54add9367a84dc15f3e6e524b8f46 Mon Sep 17 00:00:00 2001 From: Rudxain <76864299+Rudxain@users.noreply.github.com> Date: Tue, 30 Sep 2025 02:30:08 -0400 Subject: [PATCH 1/5] docs: `shell`->`bash` MD blocks --- CONTRIBUTING.md | 4 ++-- README.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b9368f7492f..ee8071a7ddb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -99,7 +99,7 @@ Also, please bear the following coding guidelines in mind: can be replaced by: - ```shell + ```bash bar=${foo//bar/baz} ``` @@ -132,7 +132,7 @@ Also, please bear the following coding guidelines in mind: expansions will be unexpectedly performed, which becomes a vulnerability. In the latter case, checks by shellcheck and shfmt will not be performed inside `'...'`. Also, `_comp_compgen_split` is `IFS`-safe. - + Avoid using `_comp_compgen -- -G "pattern"` to generate completions. The result is not filtered by the current word `cur` due to the Bash design of `compgen`. Also, this cannot be used to generate filenames with a specified diff --git a/README.md b/README.md index 5242477ea0b..1ff15a7c7c3 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ need to source it from either `/etc/bashrc` or `~/.bashrc` (or any other file sourcing those). If you have _only_ bash >= 4.2 installed, you can do this by simply using: -```shell +```bash # Use bash-completion, if available [[ $PS1 && -f /usr/share/bash-completion/bash_completion ]] && \ . /usr/share/bash-completion/bash_completion @@ -70,7 +70,7 @@ standard way is to configure `~/.bash_profile` to source `~/.bashrc` and write interactive settings in `~/.bashrc`. You can source `~/.bashrc` in `~/.bash_profile` in the following way: -```shell +```bash # ~/.bash_profile if [[ -f ~/.bashrc ]]; then @@ -90,7 +90,7 @@ the entry point of `bash-completion` to `$HOMEBREW_PREFIX/etc/profile.d/bash_completion.sh`. We can source it by adding the following to our startup file `~/.bashrc`: -```shell +```bash if [[ -s $HOMEBREW_PREFIX/etc/profile.d/bash_completion.sh ]]; then . "$HOMEBREW_PREFIX/etc/profile.d/bash_completion.sh" fi From 8732eda339e5306e03d0f9c285d8ac808e7d8534 Mon Sep 17 00:00:00 2001 From: Rudxain <76864299+Rudxain@users.noreply.github.com> Date: Tue, 30 Sep 2025 02:34:26 -0400 Subject: [PATCH 2/5] docs(CONTRIB): link to Pure-Bash-Bible --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ee8071a7ddb..04cb6ad3177 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,6 +106,9 @@ Also, please bear the following coding guidelines in mind: These forms of parameter substitutions can also be used on arrays, which makes them very powerful (if a little slow). + See ["Pure Bash"](https://github.com/dylanaraps/pure-bash-bible) + for more examples. + - We want our completions to work in `posix` and `nounset` modes. Unfortunately due to a bash < 5.1 bug, toggling POSIX mode From 900bd8c699c0d8cc7a0609aa504558a78c670157 Mon Sep 17 00:00:00 2001 From: Rudxain <76864299+Rudxain@users.noreply.github.com> Date: Tue, 30 Sep 2025 02:41:09 -0400 Subject: [PATCH 3/5] docs(README): show how to avoid double-source --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1ff15a7c7c3..34eb9a791f6 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,14 @@ do this by simply using: [[ $PS1 && -f /usr/share/bash-completion/bash_completion ]] && \ . /usr/share/bash-completion/bash_completion ``` +or if your `bashrc` will be shared across distros (and major upgrades): +```bash +# Use bash-completion, if available, and avoid double-sourcing +[[ $PS1 && \ + -z ${BASH_COMPLETION_VERSINFO:-} && \ + -f /usr/share/bash-completion/bash_completion ]] && \ + . /usr/share/bash-completion/bash_completion +``` If you have older bash versions in use, their loading of `bash_completion` should be prevented. See further for more info. From 1fc386b6fae58a874c0ed172d54ed06e9c28569a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Fern=C3=A1ndez=20Serrata?= <76864299+Rudxain@users.noreply.github.com> Date: Thu, 2 Oct 2025 01:33:03 -0400 Subject: [PATCH 4/5] rm useless back-slashes Co-authored-by: Koichi Murase --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 34eb9a791f6..25b5c2bc02d 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ do this by simply using: or if your `bashrc` will be shared across distros (and major upgrades): ```bash # Use bash-completion, if available, and avoid double-sourcing -[[ $PS1 && \ - -z ${BASH_COMPLETION_VERSINFO:-} && \ - -f /usr/share/bash-completion/bash_completion ]] && \ +[[ $PS1 && + -z ${BASH_COMPLETION_VERSINFO:-} && + -f /usr/share/bash-completion/bash_completion ]] && . /usr/share/bash-completion/bash_completion ``` From 19275013ee1d3b15b93954009401d29a5378479b Mon Sep 17 00:00:00 2001 From: Rudxain <76864299+Rudxain@users.noreply.github.com> Date: Thu, 2 Oct 2025 01:35:44 -0400 Subject: [PATCH 5/5] docs(README): replace OG example with new alt --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 25b5c2bc02d..a08b20f8ad4 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,8 @@ list of operating system distributions, package names, and available versions. Depending on the package, you may still need to source it from either `/etc/bashrc` or `~/.bashrc` (or any other file sourcing those). If you have _only_ bash >= 4.2 installed, you can -do this by simply using: +do this by using: -```bash -# Use bash-completion, if available -[[ $PS1 && -f /usr/share/bash-completion/bash_completion ]] && \ - . /usr/share/bash-completion/bash_completion -``` -or if your `bashrc` will be shared across distros (and major upgrades): ```bash # Use bash-completion, if available, and avoid double-sourcing [[ $PS1 &&