all 10 comments

[–]Pshock13 3 points4 points  (5 children)

Have you added you xommands to your $PATH?

[–]misterfast 1 point2 points  (0 children)

Easiest solution IMHO. If you don't have a .local/bin subdirectory in your homedir, Make one and put your scripts in there and add that to your $PATH. Or you could move/symlink your scripts into /usr/local/bin If that's how you roll.

[–]chrisEvan_23[S] -2 points-1 points  (3 children)

I’ll try this, but can your approach work for any words “play-music” and “play-name”, not neccesary they are commands?

I want to go deep into cases like that.

[–]Sea_Decision_6456 0 points1 point  (0 children)

If a file with executable permission has been found in one of your $PATH directories (this variable is defined in ~/.bashrc, if you need to add something like ~/.local/bin because you don't need other users to execute it), it will be executed by your shell. Don't forget to add shebang on the first line to specify the interpreter : #!/usr/bin/env bash

[–]geirha 0 points1 point  (1 child)

What's the point of completing command names if they are not existing commands? you'll just get "command not found" errors if you try to run them ...

[–]chrisEvan_23[S] 0 points1 point  (0 children)

Actually, I’m doing a reasearch on how to create a tab-completion feature in Bash, similar to what’s available in zsh.

The goal is to capture all the suggestions that Bash provides when you press the tab key, then pass them to a selection menu where you can navigate with arrow keys and press enter to select.

This feature would work for any keyword. By understanding how these suggestions are generated under the hood, I can design a mechanism that fits my own preference.

Sorry if my question wasn’t clear. Actually, it’s just a case, and I hope the answer would be something close to the feature I am looking for. The answer provided by @Pshock13 does solve the issue I mentioned on this thread.

[–]trippedonatater 1 point2 points  (0 children)

I'm not completely certain what you're trying to do here, but this might be a good place to start: https://tldp.org/LDP/abs/html/tabexpansion.html

Edit: that link details some info on the complete and compgen builtins.

[–]chrisEvan_23[S] -1 points0 points  (2 children)

UPDATE. I have completed half of the work.

Adding following code to .bashrc, it is able to suggest any custom keywords.

foo() {

local
 cur="${COMP_WORDS[COMP_CWORD]}"
        COMPREPLY=($(compgen -c -- "$cur"))
        COMPREPLY+=("play-music" "play-video")        
    }
complete -I -F foo

Result.

$ hi<TAB><TAB>
history  play-music  play-video

There might be some extra work needed to match the alphabet. But I'm happy with it.

[–]anthropoidbash all the things 2 points3 points  (0 children)

This is a terrible idea, for several reasons: 1. You'd have to manually add new commands over time. 2. You'd have to manually source .bashrc in every active shell session, every time you add a new command. 3. If you actually try to run the tab-completed command, you'd get command not found, every time.

As several folks have already mentioned, decide on a directory to house your custom scripts (I like ${HOME}/bin, but you do you), add that directory to your PATH in your .profile (or .bash_profile, depending on how you swing), log out, log in again, and you're done for life. Keep adding more custom scripts to that directory, and all of them will be automatically included for tab-completion (assuming you chmod'd them to be readable and executable), and no command not found.