1

Launching console or term from command line will load the default .bashrc. But I want load different configs given options passed to it. As of now the best I can think of is that I may define a function in .bashrc which accepts options and meanwhile keep three config files .bashrc0, .bashrc1 and .bashrc2 to replace .bashrc depends on the option passed.

#new term function
nterm (){
    if [ "$#" == "1" ]; then
       if [ "$@" == "option_a" ]; then
          yes | cp $HOME/.bashrc1 $HOME/.bashrc
          term
          yes | cp $HOME/.bashrc0 $HOME/.bashrc
       else if [ "$@" == "option_b" ]; then
          yes | cp $HOME/.bashrc2 $HOME/.bashrc
          term
          yes | cp $HOME/.bashrc0 $HOME/.bashrc
       fi
    else 
       term
    fi
}

So I can call

$nterm option_a

Or

$nterm option_b

To start two new terminals with different settings loaded. Same with konsole.

But is there an inherited way to do so in term/console/bash or a much more consice and explicit alternative?

1

I would suggest the use of bash's --rcfile parameter; it forces interactive bash shells to use the given RC file instead of ~/.bashrc. Change your function to:

nterm (){
    if [ "$#" == "1" ]; then
       if [ "$@" == "option_a" ]; then
          term -e bash --rcfile "$HOME/.bashrc1"
       else if [ "$@" == "option_b" ]; then
          term -e bash --rcfile "$HOME/.bashrc2"
       fi
    else 
       term
    fi
}

I'm not familiar with the term command; I assume from your tags that it's gnome-terminal or a wrapper for it, in which case I'm having it invoke bash with the corresponding RC files.

  • haven't exactly used this but --rcfile option does the trick, you get an alternative start-up file. – sdkks Oct 1 '18 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.