Code Monkey home page Code Monkey logo

dtags's Introduction

dtags

Directory tags for lazy programmers. Inspired by gr.

Introduction

Do you have too many git repositories or vagrant machines to manage? Does your daily routine require you to switch between the same directories over and over? Are you a lazy programmer who is always looking for shortcuts? If you answered yes to any of these questions, then dtags may be for you!

Installation

Install using pip (Python 2.7+ and 3.4+ supported):

~$ sudo pip install --upgrade pip setuptools
~$ sudo pip install --upgrade dtags

To get the latest commits:

~$ git clone https://github.com/joowani/dtags.git
~$ cd dtags
~$ sudo python setup.py install

Once installed, you will have 4 commands at your disposal: tag, run, tags and untag.

Usage

Tag directories using tag:

~$ tag ~/frontend @frontend
~$ tag ~/backend @backend
~$ tag ~/frontend ~/backend @work
~$ tag ~/db @vm
~$ tag ~/web @vm

# Or equivalently
~$ tag ~/frontend @frontend @work ~/backend @backend @work ~/db ~/web @vm

# Note: All tag names must begin with the '@' symbol

Execute commands in the tagged directories using run:

# Execute 'git fetch origin' in all directories tagged @project
~$ run @project git fetch origin

# Execute 'git status -sb' in all directories tagged @frontend and @backend
~$ run @frontend @backend git status -sb

# Execute 'vagrant status' in all directories tagged @vms
~$ run @vms vagrant status

# Directory paths can be specified along with tags
~$ run @backend ~/scripts ~/redis ls -la

# The command can be executed in parallel if it doesn't wait on input
~$ run -p @backend 'sleep 5 && echo done'
~$ run -p @project git pull
~$ run -p @vms vagrant up

# Display the exit code for each execution
~$ run -e @backend ls foobar

# Commands are executed through interactive shells so you can use your aliases!
~$ run @project myalias

Display/edit tags using tags:

~$ tags						 # display all tags
~$ tags @backend @frontend   # display only the specified tags
~$ tags --json               # display the raw JSON
~$ tags --expand             # expand home (~)
~$ tags --reverse            # show the reverse mapping
~$ tags --edit               # edit the JSON directly using an editor

Disassociate tags and directory paths using untag:

# Remove tags @frontend and @backend from ~/frontend and ~/backend respectively
~$ untag ~/frontend @frontend ~/backend @backend

# Remove tags @vms from directories /vagrant/web and /vagrant/db
~$ untag /vagrant/web /vagrant/db @vms

# Remove the tag @backend completely
~$ untag --all @backend

# Remove the directory path ~/vms/web from all tags
~$ untag --all ~/vms/web 

You can always use the --help option to find out more!

Auto-completion

Auto-completion for zsh and bash are supported. I recommend you to enable it so you won't have to type the @ symbol all the time.

For bash, place the following lines (or something similar) in your ~/.bashrc (~/.bash_profile for OS X):

if command -v register-python-argcomplete > /dev/null 2>&1; then
    eval "$(register-python-argcomplete run)"                                                                                                        
    eval "$(register-python-argcomplete tags)"
fi

For zsh, place the following lines (or something similar) in your ~/.zshrc:

autoload bashcompinit                                                           
bashcompinit 
if command -v register-python-argcomplete > /dev/null 2>&1; then
    eval "$(register-python-argcomplete run)"                                                                                                      
    eval "$(register-python-argcomplete tags)"
fi

Notes

  • dtags is not supported on Windows
  • run -p will probably hang on interactive commands that wait on input
  • run -p may use up a lot of memory on commands that produce large output
  • run -p sends sigterm to its child processes when interrupted.

To Do

  • Extension support
  • Improve the configuration to include things other than just tags
  • Warn the user when commands known to hang are executed with run -p
  • Add integration tests

dtags's People

Contributors

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