Code Monkey home page Code Monkey logo

sandboxd's Introduction

sandboxd

Speed up your bashrc / zshrc: avoids running (slow) setup commands until you actually need them.

Why?

Having installed nvm, rvm, virtualenvwrapper and other similar gubbins over time, my shell starts horrifically slowly. By running these setup scripts on-demand, my time-to-first-prompt is nice and fast again. On top of this, I rarely need all of these tools enabled at the same time...

How?

sandboxd creates a placeholder shell function for each command you specify (e.g. rvm). When this command gets run for the first time, the following happens:

  • the cmd placeholder function (plus all associated placeholders) gets removed
  • the setup you have associated with cmd gets run,
  • cmd gets run with the original arguments

Usage

To 'sandbox' a setup, wrap it in a function named sandbox_init_[name]:

# in ~/.bashrc / your shell rc file
source /path/to/sandboxd


# in ~/.sandboxrc
sandbox_init_nvm(){
  source $(brew --prefix nvm)/nvm.sh #long running setup command
}

# create hooks for commands 'nvm', 'node' and 'nodemon'
sandbox_hook nvm node
sandbox_hook nvm nodemon
# this one not needed: it's created automatically based on the sandbox name
# sandbox_hook nvm nvm

The sandbox setup gets run once, when either nvm, nodemon or node is used for the first time:

[20:45:44 ~] echo 'console.log("hi")' | node
sandboxing nvm ...
hi
[20:45:53 ~] echo 'console.log("hi")' | node
hi

Manually calling the sandbox command

To manually run a specific sandbox setup, run sandbox [name]

This might be useful if you want to run a sandbox that doesn't have an associated command, or to create "feature flags" in your rc file:

#uncomment to enable features

# sandbox virtualenv
sandbox rvm
sandbox nvm

sandboxd's People

Contributors

benvan avatar hsheth2 avatar leoj3n avatar

Watchers

 avatar  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.