Coder Social home page Coder Social logo

magic's Introduction

magic

define bash functions on a per-directory basis

Installation

make install installs into /usr/lib/magic by default.

make PREFIX=/your/prefix install to install to a different prefix.

make DESTDIR=stage install for a staged install.

Add the following line to your .bashrc or .zshrc:

source /usr/lib/magic/magic

If you used a different PREFIX, adjust the path accordingly.

Usage

Define some bash functions in a script named .spells and place it into the directory below which these functions shall be defined. Be sure to echo the name of each function you define at the end of the script.

Upon entering the directory the .spells file will be sourced and the functions defined in it will be available at the prompt. Upon leaving the directory all functions will be unset again (provided the .spells script correctly echoes their names).

Examples

A simple get command for github

Assume you have a directory ~/workspace under which you store your git repositories. Create a .spells file in this directory, defining a function called get:

function get() {
   local author="$1"
   local project="$2"

   git clone "https://github.com/${author}/${project}"
}
echo get

Now you can clone a repository from github by cd'ing into ~/workspace and typing

$ get hbekel magic

This function will only be defined below the ~/workspace directory.

Multiple .spells in the current path

Assume that ~/.spells reads

function play {
    echo "THE ONLY WINNING MOVE IS NOT TO PLAY"
}
echo play

And that ~/music/.spells reads

function play {
    mplayer "$@"
}
echo play

Anywhere in your home directory play will echo THE ONLY WINNING MOVE IS NOT TO PLAY, except below the music directory, where play foo.mp3 will instead call mplayer foo.mp3.

More specifically, whenever you change into a directory, the current path will be searched top down, starting at the root of the filesystem. Every readable .spells files encountered along the way will be sourced immediately. This means that .spells files further down the hierarchy can effectively override functions defined in .spells files residing higher up in the hierarchy.

Feedback

If you do something interesting with this, please let me know :)

magic's People

Contributors

hbekel avatar thislg avatar aegypius avatar

Stargazers

Ernie Hershey avatar François D. avatar Benjamin avatar  avatar Pierre Boissinot avatar Jac. Bac. avatar Benjamin Letellier avatar mcampourcy avatar  avatar  avatar Michael F. Schönitzer avatar Felix Bartels avatar Nikolaj avatar Stephen Becker IV avatar Travis Goldie avatar Ola Sikström avatar Nikolay Kolev avatar Kevin Wiesmüller avatar Kim Dowling avatar Ilya Pikulin avatar Michael D Johnson avatar tricarte avatar Koen Torfs avatar Justin Garrison avatar Freek Van der Herten avatar

Watchers

 avatar James Cloos avatar Felix Bartels avatar Sébastien Kurtzemann avatar

Forkers

aegypius

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.