Linux - Software This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
05-18-2008, 11:56 PM
|
#1
|
Member
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915
Rep:
|
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.
Code:
[daihard-exp:/home/dtoyama]$ cp test.txt ~/documents
That's exactly what I expect to happen.
Now, however, Kubuntu does not exhibit the same behaviour. Instead of simply completing the directory, it will replace "~" with /home/dtoyama.
Code:
[daihard-exp:/home/dtoyama]$ cp test.txt ~/doc
Hitting the tab key will result in this.
Code:
[daihard-exp:/home/dtoyama]$ cp test.txt /home/dtoyama/documents
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?
TIA,
Dai
|
|
|
05-19-2008, 12:15 AM
|
#2
|
Member
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915
Original Poster
Rep:
|
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?
Last edited by daihard; 05-19-2008 at 12:24 AM.
|
|
|
05-19-2008, 03:51 AM
|
#3
|
Member
Registered: Apr 2008
Distribution: slackware 10.2
Posts: 117
Rep:
|
hey daihard,
to alter the behaviour of the shell edit either /etc/inputrc or ~/.inputrc. try the following. type:
you should find a line like
Code:
set expand-tilde on
if so edit one of the two files above. for example write the following line in your ~/.inputrc:
Code:
set expand-tilde off
that's it. next time the bash reads .inputrc autoexpansion of the '~' will be disabled.
vadkutya
|
|
|
05-21-2008, 10:17 PM
|
#4
|
Member
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915
Original Poster
Rep:
|
Quote:
Originally Posted by vadkutya
hey daihard,
to alter the behaviour of the shell edit either /etc/inputrc or ~/.inputrc. try the following. type:
you should find a line like
Code:
set expand-tilde on
if so edit one of the two files above. for example write the following line in your ~/.inputrc:
Code:
set expand-tilde off
that's it. next time the bash reads .inputrc autoexpansion of the '~' will be disabled.
|
Hi Vadkutya.
Thanks for the advice. Strangely, bind -v shows that "expand-tilde" is already off on my computer.
Code:
[daihard-x2:/home/dtoyama]$ bind -v | grep tilde
set expand-tilde off
I created ~/.inputrc and added "set expand-tilde off" in it, but that did not help.
Is there anything else I need to pay attention to? Again, the OS is Kubuntu 8.04.
|
|
|
05-22-2008, 04:11 AM
|
#5
|
Member
Registered: Dec 2007
Distribution: Ibex
Posts: 93
Rep:
|
try a re-login to bash - see my site ubuntu/kubuntu gatherings in my sig to learn how to do this.
|
|
|
05-22-2008, 07:02 AM
|
#6
|
Member
Registered: Apr 2008
Distribution: slackware 10.2
Posts: 117
Rep:
|
hey daihard,
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.]
Last edited by vadkutya; 05-22-2008 at 07:35 AM.
|
|
|
05-22-2008, 11:09 PM
|
#7
|
Member
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915
Original Poster
Rep:
|
Hi!
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.
|
|
|
10-09-2009, 03:21 PM
|
#8
|
LQ Newbie
Registered: Oct 2009
Posts: 1
Rep:
|
Quote:
Originally Posted by daihard
Hi!
Code:
## 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.
|
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?
|
|
|
08-22-2010, 02:32 PM
|
#9
|
LQ Newbie
Registered: Aug 2010
Distribution: Kubuntu Lucid; Debian Lenny
Posts: 6
Rep:
|
Quote:
Originally Posted by Mike.lifeguard
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?
|
Done. https://bugs.launchpad.net/ubuntu/+s...on/+bug/622403
As I said in the bug report, I only know that it worked for me, it's probably not the most effective way and may need testing in scripts and what not.
|
|
|
All times are GMT -5. The time now is 07:43 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|