LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 05-18-2008, 11:56 PM   #1
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Rep: Reputation: 34
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
 
Old 05-19-2008, 12:15 AM   #2
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Original Poster
Rep: Reputation: 34
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.
 
Old 05-19-2008, 03:51 AM   #3
vadkutya
Member
 
Registered: Apr 2008
Distribution: slackware 10.2
Posts: 117

Rep: Reputation: 17
hey daihard,

to alter the behaviour of the shell edit either /etc/inputrc or ~/.inputrc. try the following. type:
Code:
bind -v
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
 
Old 05-21-2008, 10:17 PM   #4
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by vadkutya View Post
hey daihard,

to alter the behaviour of the shell edit either /etc/inputrc or ~/.inputrc. try the following. type:
Code:
bind -v
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.
 
Old 05-22-2008, 04:11 AM   #5
nowshining
Member
 
Registered: Dec 2007
Distribution: Ibex
Posts: 93

Rep: Reputation: 15
try a re-login to bash - see my site ubuntu/kubuntu gatherings in my sig to learn how to do this.
 
Old 05-22-2008, 07:02 AM   #6
vadkutya
Member
 
Registered: Apr 2008
Distribution: slackware 10.2
Posts: 117

Rep: Reputation: 17
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.
 
Old 05-22-2008, 11:09 PM   #7
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Original Poster
Rep: Reputation: 34
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.
 
Old 10-09-2009, 03:21 PM   #8
Mike.lifeguard
LQ Newbie
 
Registered: Oct 2009
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by daihard View Post
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?
 
Old 08-22-2010, 02:32 PM   #9
GeneC
LQ Newbie
 
Registered: Aug 2010
Distribution: Kubuntu Lucid; Debian Lenny
Posts: 6

Rep: Reputation: 2
Quote:
Originally Posted by Mike.lifeguard View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Why "bash-2.05b$" in Terminal instead of "username@localhost username" jayelitumbiolo Linux - General 9 10-04-2009 03:16 AM
How might I restore kmail folders/mail/settings from a "badly" saved "home"? deh6 Linux - Software 5 03-08-2008 09:25 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration