3

(I have seen this question, but not sure, if it's the same)

I use a lot of alias in my .bashrc script. Is there any way, to use many different .bashrc scripts?

for example git.bashrc

alias gpull='git pull'
alias gcom='git commit -a -m '
alias gpush='git push'
alias gstat='git status'
alias gco='git checkout'

ide.bashrc

alias idea='/home/myname/dev/ide/idea/bin/idea.sh'
alias idea='/home/myname/dev/eclipse/eclipse/bin/eclipse.sh'

normal .bashrc should include something like

include ide.bashrc
include git.bashrc
# normal stuff like:
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

I want to use version control to have them on all my computers, but I can't really use the complete bashrc file for it. Thanks a lot!

1
  • 1
    for rcfiles in git.bashrc ide.bashrc; do if [[ -e "$rcfiles" ]]; then source "$rcfiles"; fi; done You need to add the absolute path for the rcfiles if needed. Maybe add the -f test also.
    – Jetchisel
    Commented Mar 25, 2020 at 9:10

1 Answer 1

4

The keyword for this is source (or simply .) instead of include.

Add this to your .bashrc:

# Include more scripts
source /path/to/ide.bashrc
source /path/to/git.bashrc

or

# Include more scripts
. /path/to/ide.bashrc
. /path/to/git.bashrc

or include all from one directory:

if [ -d /path/to/includes ]; then
    for f in /path/to/includes/*.bashrc; do
        . "$f"
    done
fi

Read:

1
  • I will read the stuff you mentioned, thanks a lot!
    – Joergi
    Commented Mar 25, 2020 at 10:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .