Bash completion was wrong => commented => what was the problem?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash completion was wrong => commented => what was the problem?
Sometime ago, I found out the file /etc/bash_complete and /etc/bash_complete.d/ directory. Changing them allowed me to fix a few things I did not like about some "smart" choices for completion. Most of the times, what I did was to comment sections of the first file.
Now I have a problem with scp. In my history I have an scp command which I want to reuse: I want all of it to be the same, except the first file argument.
- now I am on the first argument, and want to use the completion to file or folder names. But it does not work!
As an "unwanted but necessary" fix, I type "a" in the command start, go back to editing the file argument (that now works, there is no "ascp" command with "smart" completion) and after getting the file name I wanted I erase the "a" and (finally!) execute it.
My current situation is:
1. there is no ocurrency of "scp" in /etc/bash_completion. Only two "scp" exist, and they are inside comments.
2. there is no "scp" file in the folder /etc/bash_completion.d
3. in the file /etc/bash_completion.d/ssh there were some lines about scp, but now I commented them.
Can you fix the problem it had? What is it?
The function for scp (uncommented again), is:
Code:
scp(1) completion
_scp()
{
local configfile cur userhost path prefix
COMPREPLY=()
cur=`_get_cword ":"`
_expand || return 0
if [[ "$cur" == *:* ]]; then
local IFS=$'\t\n'
# remove backslash escape from :
cur=${cur/\\:/:}
userhost=${cur%%?(\\):*}
path=${cur#*:}
# unescape spaces
path=${path//\\\\\\\\ / }
if [ -z "$path" ]; then
# default to home dir of specified user on remote host
path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
fi
# escape spaces; remove executables, aliases, pipes and sockets;
# add space at end of file names
COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
command ls -aF1d "$path*" 2>/dev/null | \
sed -e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\\\\\\\\\&/g" \
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
return 0
fi
if [[ "$cur" = -F* ]]; then
cur=${cur#-F}
prefix=-F
else
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
set -- "${COMP_WORDS[@]}"
while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then
if [ ${#1} -gt 2 ]; then
configfile="$(dequote "${1:2}")"
else
shift
[ "$1" ] && configfile="$(dequote "$1")"
fi
break
fi
shift
done
[[ "$cur" == */* ]] || _known_hosts_real -c -a -F "$configfile" "$cur"
fi
# This approach is used instead of _filedir to get a space appended
# after local file/dir completions, and $nospace retained for others.
local IFS=$'\t\n'
COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* 2>/dev/null | sed \
-e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\&/g" \
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' -e "s/^/$prefix/") )
return 0
}
complete -F _scp $nospace scp sshfs
Which is wrong - it should allow me to type that file/dir name where I wanted. How to fix it to add come back with its smartness?
Hm.
I do not think it is related to scp at all.
Bash will try to auto-complete the argument as a file/dir if possible. You can try it also with some fake command, like: my_cmd_str /var/log/<auto-complete any file>
Hm.
I do not think it is related to scp at all.
Bash will try to auto-complete the argument as a file/dir if possible. You can try it also with some fake command, like: my_cmd_str /var/log/<auto-complete any file>
I do not understand you. I used "ascp" as the fake command to get the auto-complete for filenames in my wanted scp command position. But I had to change the command name from "scp" to "ascp", like I tried to describe above.
A command with the syntax "scp <filename> <user@server:path>" is valid, but the function above does not give me the completion for local filenames where they can be (and I chose to have them). Due the function existence, Bash will not use the normal completion, as other commands may have. So I commented it (for the whole system, there is no other way I know).
Now I am wondering if, for scp, a fix instead of commenting is better, but I cannot do it myself. That function is mostly hard for me to understand.
When I said above: "Now I have a problem with scp", I knew the described problem is not with the scp command itself, but with Bash (or something connected to it), as I tried to show in the thread's title and other things I wrote.
My understanding is that bash_completion.d is not supposed to help you complete the syntax of a particular command, but instead to help you find alternative commands following the same structure. For example, the following list:
Sometime ago, I found out the file /etc/bash_complete and /etc/bash_complete.d/ directory. Changing them allowed me to fix a few things I did not like about some "smart" choices for completion. Most of the times, what I did was to comment sections of the first file.
maybe the answer lies here?
why don't you just rename the backups you made and see if it solves the problem?
oh, you didn't backup important system files before fiddling with them? reinstall bash/completion, then?
maybe the answer lies here?
why don't you just rename the backups you made and see if it solves the problem?
oh, you didn't backup important system files before fiddling with them? reinstall bash/completion, then?
If the answer is there, I did not understand it. I have detailed my actions here, and (for me) they seem good and reasonable steps.
I have fiddled with some system files, but my changes are made to be reverted, if needed. For example, when I find a function that decides about arguments for a specific command, I do not delete its lines, I comment all of them and leave it there. A function of that sort may be changed in some detail, but an observation of what was changed is also added.
Eventually I make copies of these system files, so I can "move" the changes to other places or machines when I feel their "can-be-solved" problems.
--
@rtmistler
bash_completion.d (and the other files and directories I pointed) deal with the completion of commands name and also with their arguments. This includes the completion done for specific commands (like scp) that will have in its own "completion buffer"¹. For example, the scp completion function allowed only hostnames in the first argument - although we can also have filenames there. This problem is the reason why I commented the whole scp function, so it gets just the default completion for arguments for all commands: filenames. I do not understand the scp function, so I have not even tried to make changes to it - and this thread started when I imagined that something better could exist.
¹ I know it is not a buffer, just a metaphore here
--
Something almost offtopic here that I plan to also make elsewhere: a few weeks ago I started to always use the "thread solved" feature. While the threads I started are not "SOLVED", I expect another answer (not yet true for my old threads). When I am satisfied with the achievements made through the answers, I will mark it as solved. Then no more answers are necessary (new comments and ideas could be very welcome, although uncommon).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.