GithubHelp home page GithubHelp logo

gianluca-mascolo / bash-profile-switcher Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 2.0 164 KB

Easily change environment variables and settings using bash

License: GNU General Public License v3.0

Shell 88.91% Makefile 11.09%
bash bash-hacks bash-profile bash-script bashrc bashrc-configs environment-configuration environment-variables environment-vars shell shell-scripting shell-scripts shellscript

bash-profile-switcher's Introduction

bash-profile-switcher CI

Easily change environment variables and settings using bash

About

This script aim to manage multiple profile files for bash. It's like having multiple .bashrc files to load or unload when needed. You need to create your custom profile files under ~/.bash_profile.d directory. Each profile must have extension .profile and it is a plain text file containing a list of "snippets" (one per line) to be loaded into your profile. Snippets are .sh files where you can set variables/aliases/functions or any command you want to execute when you spawn a shell (snippet example).

Installation

Use make install. It will install bash_profile_switcher.sh in ~/.bash_profile_switcher and source it in your ~/.bashrc. Reload your shell or open a new terminal to use it.
Note: You can use make install INSTALL_PATH=<path> to install the script in a custom path.

Usage

Use switch_profile function to change profile

 ~]$ switch_profile -h
switch_profile [options] profile

OPTIONS
  -k
    Keep env. Load selected profile without unloading current environment.
  -d
    Don't load profile. Unload current profile and don't load any profile in new bash shells
  -t
    Temporary profile. Load selected profile in current shell without starting it in new bash shells
  -l
    List available profiles
  -h Show help instructions (this help)

Example

As an example take the following directory structure for ~/.bash_profile.d

.bash_profile.d/
├── foo.profile
├── bar.profile
└── snippets
    ├── tools.sh
    ├── cloudvars.sh
    └── setpath.sh
]$ cat ~/.bash_profile.d/foo.profile
tools
cloudvars
setpath
]$ cat ~/.bash_profile.d/bar.profile
setpath

When you do switch_profile foo snippets tools.sh,cloudvars.sh,setpath.sh will be loaded (in the same order they are listed in profile). On profile change switch_profile bar bash will first unload all the snippets applied by foo in reverse order then load the snippets listed in bar, that is setpath.sh ``

Issues

  • Spaces and blank characters are not supported on profile filenames
  • Be careful when managing special variables like PATH

Test automation

Bash command interaction is tested with expect. It requires the following packages to be installed:

  • expect
  • docker
  • docker-compose
  • make

To run tests locally use:

make clean && make test

bash-profile-switcher's People

Contributors

gianluca-mascolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.