How to stop bash from replacing "~/" with "/home/username"?
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.
How to stop bash from replacing "~/" with "/home/username"?
Hi.
I am wondering how I can do this. In Red Hat / Fedora, hitting the tab key to complete directory/file names does NOT replace the "~" character with the actual home directory path. For instance, let's say my $HOME is "/home/dtoyama" and I have the directory named "/home/dtoyama/documents". Here's what I do.
Code:
[daihard-exp:/home/dtoyama]$ cp test.txt ~/doc
Here if I hit the tab key, it will expand to this.
I do NOT want that to happen. I did some googling and found that I needed to modify /etc/bash_completion. I haven't gotten much farther, though. The file is huge and has lots of stuff in it. I could choose to not load the file at login, but then I may not load something that I should have. I'd like to be able to just disable this one annoying feature without affecting the others defined in /etc/bash_completion. Would anyone be kind enough to help me?
Okay, I am replying to myself. This behaviour that I want to disable is apparently called "tilde expansion." I looked at /etc/bash_completion a bit more closely and found the following function.
Code:
# This function expands tildes in pathnames
#
_expand()
{
# FIXME: Why was this here?
# [ "$cur" != "${cur%\\}" ] && cur="$cur\\"
# expand ~username type directory specifications
if [[ "$cur" == \~*/* ]]; then
eval cur=$cur
elif [[ "$cur" == \~* ]]; then
cur=${cur#\~}
COMPREPLY=( $( compgen -P '~' -u $cur ) )
return ${#COMPREPLY[@]}
fi
}
I commented out everything inside the if block and replaced it with a "return 0" (because leaving the entire function empty inside caused an error), and restarted KDE. The behaviour is gone!
Now, my question is, is this the right way of going about it? This is more like a hack to me; if there's a more legitimate way, I'd rather choose that over manually editing /etc/bash_completion. Any thoughts?
did you log off and log in again, after you created ~/.inputrc? if so, the problem might have to do with KDE. are you using xterm? how does tilde expansion work in xterm. same or different? i think KDE has it's own terminal. maybe it has it's own config or is per default started explicitly with tilde-expansion so that it overwrites the default values. i have no clue about KDE and it's terminal. however this shouldn't happen. if you turn off tilde expansion in your ~/.inputrc than it should not be allowed to overwrite this value by another program. this makes debugging extremly complicate. if KDE is really doing this than this is another reason why NOT to use desktop environments. however, i am aware that this is not the problem here . look under "settings" or "help". if you can't find anything apropriate you can try to ask the konsole guys per mailing list.
good luck, vadkutya
p.s.: a friend of mine uses kubuntu as well. bind -v gave tilde expansion set to off. however, the tilde was expanded in konsole. this really seems to be a KDE issue and must be solved by tuning the configuration of konsole via the gui or whatever other way KDE supports.
p.p.s.: get rid of it! this is a really bad behaviour from KDE. it kreeps into your system like a virus. the config's that are meant to control such behaviour are disabled by KDE! wtf! really, get rid of it...
[edit: forget what i said. xterm does tilde expansion as well. it doesn't seem to be a prob with KDE. i grep'ed through /etc/inputrc on kubuntu and there was no set tilde-expansion off. although bind -v has shown so. right now i'm giong to play football but i'm coming back to you asap.]
Problem solved. The issue was the inclusion of /etc/bash_completion at the end of ~/.bashrc. The /etc/bash_completion file forces tilde expansion, regardless of the value of "set expand-tilde." This is the last few lines of my ~/.bashrc, which has been like this since day one.
Code:
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
Inside the file is the function called _expand(), which forces tilde expansion. In order to disable it, I needed to make the following modification to my ~/.bashrc.
Code:
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
## my addition
_expand()
{
return 0;
}
This effectively nullifies the original _expand() function.
I truly appreciate all your help and suggestions, in any case. Hope you can sleep peacefully now.
This effectively nullifies the original _expand() function.
I truly appreciate all your help and suggestions, in any case. Hope you can sleep peacefully now.
Has anyone thought about simply fixing /etc/bash_completion such that it checks if expand-tilde is off before clobbering your settings and expanding whether you like it or not?
Has anyone thought about simply fixing /etc/bash_completion such that it checks if expand-tilde is off before clobbering your settings and expanding whether you like it or not?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.