2

I ultimately want to alias screen -r.

I mostly want to do this because that command has an awesome tab completion feature that shows me the current GNU screen sessions. I want that power with the alias.

This led me to ask a more general question. How would I view the tab completion function for the command screen -r or further, any command?

  • 1
    help complete – Cyrus Jul 29 '15 at 18:35
3

Ok, so there are three different things going on in the question:

1) To look up the bash completion function of a command complete -p <command> does the trick. In this case complete -p screen yields complete -o default -F _screen screen

2) Bash completion will take arguments. In the case of screen -r, the screen bash completion function gets called with -r as an argument. You may then auto-complete conditionally from there.

3) On Ubuntu, /etc/bash_completion.d/screen has the screen completion function defined.

So the way I aliased screen -r and kept the completion function was as follows.

.bashrc:

alias scr="screen -r"
function _complete_scr() {
    local does_screen_exist=$(type -t _screen_sessions)
    local cur=$2 # Needed by _screen_sessions
    if [[ "function" = "${does_screen_exist}" ]]; then
        _screen_sessions "Detached"
    fi
}
export -f _complete_scr
complete -F _complete_scr -o default scr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.