Bash Completion not working?

Hello!

I Installed Bash Completion from Fedora repository. however, I can’t see it working. I read some bash completion github and it says "If you have profile.d in your distribution, you dont have to source /etc/profile.d/bash_completion.sh.

the funny thing is.. bash can complete my command and files. ie if i type

~ com<TAB>
comm     command  

it will work. but not with

~ git check<TAB>
<nothing>

do you guys know what might be the cause? Thanks!

In the first example, the command name is completed with the completion script and there are two suggestions.

In the second example, there’s nothing to complete - the command name is already given (git) and you’ve given it one parameter. Pressing Tab does nothing as there’s no ambiguous command to complete.

I use fish and it has more robust completion, which I suspect is what you’re after. For example, typing git and pressing tab offers the last parameter to git that I used and also all other appropriate parameters, along with their description; I can move around the list or continue typing after being given the reminder of what could come next.

┌─🎩 lurcher rlencoder on  master [!+] +33−3
├─via 🦀 v1.94.0-beta.3 pkg 📦 v0.1.0
└─➜ git status                                                                                                                                              12:34 Fri 20-Feb
add                   (Add file contents to the staging area)  merge                              (Join multiple development histories)
am                             (Apply patches from a mailbox)  mergetool                           (Run merge conflict resolution tool)
apply                                         (Apply a patch)  merge-base                          (Find a common ancestor for a merge)
archive              (Create an archive of files from a tree)  mv                                               (Move or rename a file)
bisect      (Use binary search to find what introduced a bug)  notes                                      (Add or inspect object notes)
blame           (Show what last modified each line of a file)  prune                      (Prune unreachable objects from the database)
branch                     (List, create, or delete branches)  pull                  (Fetch from and merge with another repo or branch)
bundle        (Create, unpack, and manipulate "bundle" files)  push                                            (Push changes elsewhere)
checkout                    (Checkout and switch to a branch)  range-diff                                   (Compare two commit ranges)
cherry           (Find commits yet to be applied to upstream)  rebase                           (Reapply commit sequence on a new base)
cherry-pick              (Reapply a commit on another branch)  reflog                                       (Manage reflog information)
clean          (Remove untracked files from the working tree)  remote                                     (Manage tracked repositories)
clone               (Clone a repository into a new directory)  reset                        (Reset current HEAD to the specified state)
commit                     (Record changes to the repository)  restore                                     (Restore working tree files)
config             (Set and read git configuration variables)  revert                                       (Revert an existing commit)
count-objects  (Count number of objects and disk consumption)  rev-list                           (List commits in chronological order)
daemon                 (A simple server for git repositories)  rev-parse                (Parse revision names or give repo information)
describe               (Give an object a human readable name)  rm              (Remove files from the working tree and/or staging area)
…and 15 more rows

well, when I sourced /etc/profile.d/bash_completion.sh, it’s work though

~ git checkout <TAB>
HEAD            master          origin/main 
main            origin/HEAD     origin/master 

but I don’t want to source it in ~/.bashrc because it’s already mentioned in /etc/profile.d . that’s why i think there’s possible issue here

Did you log out and log in again after installing Bash Completion? Such changes only takes effect after the next login.

Ah - I see.

profile.d is applicable to login shells.
bash.rc is applicable to interactive shells.

To pick up changes to profile.d you’ll need to login again… and Villy has beaten me to it.

I did

sudo dnf reinstall bash-completion

and then relogin, it’s still the same.. so I tried restart..
still it won’t do it’s thing. I have this problem almost a week. I searched many forums and got no luck.

The code you’re running in /etc/profile.d looks like this, I presume:

# shellcheck shell=sh disable=SC1091,SC2166,SC2268,SC3028,SC3044,SC3054
# Check for interactive bash and that we haven't already been sourced.
if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BASH_COMPLETION_VERSINFO-}" = x ]; then

    # Check for recent enough version of bash.
    if [ "${BASH_VERSINFO[0]}" -gt 4 ] ||
        [ "${BASH_VERSINFO[0]}" -eq 4 -a "${BASH_VERSINFO[1]}" -ge 2 ]; then
        [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] &&
            . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
        if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
            # Source completion code.
            . /usr/share/bash-completion/bash_completion
        fi
    fi

fi

Are you sure it’s actually executing and firing /usr/share/bash-completion/bash_completion and that called script has the correct permissions and so on?

I guess that if your terminals in your Desktop are not login shells, you should have a
proper ~/.bashrc based on /etc/skel/.bashrc:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

<skipped>

If you want that we can reproduce your issue, you need to fill up more tags. So we can see how your setup looks like.

yes, I have the same content of /etc/profile.d/bash_completion like you. all files in /etc/profile.d have 644 permission except for 70-systemd-shell-extra.sh and 80-systemd-osc-context.sh. I don’t think they need +1 because it just get sourced, not executed.

hmm, you might be right.

hi, I don’t know what tags to add that may be useful. but I can tell you my setup
I have f43 installed from fedora-everything, I choose to install xfce desktop then I remove lightdm and replaced it with greetd. also I installed hyprland from copr then here I am now :smiley:

at first, I was thought it’s greetd fault so I replaced it with sddm. but it still not working.

Have you tried thus to correct your ~/.bashrc ?

Fron a textual console (ex: Ctrl-Alt-F3) you will have a login shell that will thus source
/etc/profile and then all the /etc/profile.d/*.sh

So simple :frowning:

bash -l would do the same thing, according to the man page.

Fewer keystrokes by firing up a TTY though. @francismontagnac MVP.

1 Like

If you meant by adding . /etc/profile.d/bash_completion.sh yes :slight_smile:

# .bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# history
HISTCONTROL=ignoreboth
shopt -s histappend
HISTSIZE=1000
HISTFILESIZE=2000

# source
for file in $HOME/.bash/*; do
    [[ -r "$file" ]] && source "$file"
done

eval "$(oh-my-posh init bash --config ~/.config/posh/catppuccin_mocha.omp.json)"
eval "$(fzf --bash)"
FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --bash)"

this is my current ~/.bashrc. I still don’t source
/etc/profile.d/bash_completion.sh because I don’t know is it right or not

using tty works well, maybe youre right with this

I guess that if your terminals in your Desktop are not login shells, you should have a
proper ~/.bashrc based on /etc/skel/.bashrc:

No, I meant adding the part of /etc/skel/.bashrc I indicate at the beginning of your
.bashrc

Good: I do the same. Add thus before # If not running interactively ...:

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

another funny thing! I already tried this one! I used this for my greetd

bash -l -c "start-hyprland" 

and guess what… it still not working… xd

Okay that may be the only solution. So I guess if running term emulator on display server is not count as login shells. Thank you! :blush: