Aliases in multiple shell instances

Here is where all questions and discussions about KDE should go.
Message
Author
User avatar
eemaestro
Forum Regular
Forum Regular
Posts: 927
Age: 2015
Joined: Wed Aug 02, 2006 12:12 pm

Aliases in multiple shell instances

#1 Postby eemaestro » Fri Apr 27, 2012 10:20 am

I noticed that when I am typing in a Konsole window, an alias
that I defined in a different Konsole window is undefined.
Has anybody figured out a way to automatically share aliases among shell instances, so I don't have to type in my alias in
different shells?
I can define all my aliases in a Bash-script file called aliases. But how would I have the shell instance automatically run that script when I switch to it (or when I create it )?

User avatar
Adrian
Forum Veteran
Forum Veteran
Posts: 6106
Age: 41
Joined: Wed Jul 12, 2006 1:42 am

Re: Aliases in multiple shell instances

#2 Postby Adrian » Fri Apr 27, 2012 11:19 am

You have to call that aliases script from .bashrc which gets executed every time you open a shell. I have in mine these lines:

Code: Select all

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Of course change .bash_aliases to whatever file name you use.

You could also put the aliases directly in .bashrc, but it's nicer to keep them in a separate file.

User avatar
eemaestro
Forum Regular
Forum Regular
Posts: 927
Age: 2015
Joined: Wed Aug 02, 2006 12:12 pm

Re: Aliases in multiple shell instances

#3 Postby eemaestro » Fri Apr 27, 2012 2:54 pm

Thank you, Adrian.
I used the filename you suggested. I moved my aliases script file from aliases to the name you suggested. It worked! Thank you.

BTW, I was surprised to get this message

Code: Select all

$ls -a *alias*
ls: cannot access *alias*: No such file or directory


I thought that -a would include files beginning with a dot. Didn't show anything. I had to do this:

Code: Select all

$ ls -a .*alias*
.bash_aliases   .bash_aliases.bak  .bash_aliases.txt.bak
.bash_aliases~  .bash_aliases.txt  .bash_aliases.txt.bk3

User avatar
eemaestro
Forum Regular
Forum Regular
Posts: 927
Age: 2015
Joined: Wed Aug 02, 2006 12:12 pm

Re: Aliases in multiple shell instances

#4 Postby eemaestro » Sun Apr 29, 2012 2:25 pm

Adrian,

I followed your example. I consolidated all my aliases into one file. Now it works automatically when I create a new Konsole window. I need no longer redefine my desired alias.

Thank you for helping me. I appreciate it.

User avatar
Adrian
Forum Veteran
Forum Veteran
Posts: 6106
Age: 41
Joined: Wed Jul 12, 2006 1:42 am

Re: Aliases in multiple shell instances

#5 Postby Adrian » Mon Apr 30, 2012 11:59 am

Glad to be of help. I went one more step and put my .bash_aliases in my Dropbox and then linked it to home so I have the same aliases no matter what computers I use. I've done the same for .bash_functions

(will move to Google drive once they release a linux client).

User avatar
Jerry3904
Forum Veteran
Forum Veteran
Posts: 14944
Joined: Wed Jul 19, 2006 6:13 am

Re: Aliases in multiple shell instances

#6 Postby Jerry3904 » Mon Apr 30, 2012 12:07 pm

I think this is right: aliases stored in .bashrc in the /home directory will not work in a root terminal. The file would need to be copied and pasted (as root) into the /root directory.
Production: 4.2.0-0.bpo.1-amd64, MX-15 RC1, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 8 GB, Kingston SSD 120 GB and WesternDigital 1TB
Testing: AAO 722: 3.16-0-4-686-pae. MX-15, AMD C-60 APU, 4 GB


Return to “KDE”

Who is online

Users browsing this forum: No registered users and 2 guests