Code Monkey home page Code Monkey logo

dtags's Introduction

Dtags: Directory Tags for Lazy Programmers

Build CodeQL codecov PyPI version GitHub license Python version

Dtags is a command-line tool that lets you tag directories for faster filesystem navigation and command execution.

Demo GIF

Requirements

  • Recent versions of Bash, Zsh or Fish
  • Python 3.6+

Installation

Install via pip:

pip install dtags

For Bash, add the following line in ~/.bashrc:

source <(dtags-activate)

For Zsh, add the following line in ~/.zshrc:

autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit

source <(dtags-activate)

For Fish, add the following line in ~/.config/fish/config.fish:

dtags-activate fish | source

For Git Bash on Windows, add the following lines in ~/.bashrc:

export DTAGS_GIT_BASH=1
source <(dtags-activate)

Restart your shell. The following commands will be available after:

tag --help
untag --help
tags --help
d --help
run --help

Tab-completion should work out-of-the-box.

Usage

Tag directories with tag:

# Tag directory ~/foo with "work" (tags are indicated with the "@" prefix)
$ tag ~/foo -t work
/home/user/foo +@work

# If tag names are not specified, directory basenames are used instead
$ tag ~/foo
/home/user/foo +@foo

# Tag directories ~/bar and ~/baz with "app" and "work" (many-to-many)
$ tag ~/bar ~/baz -t app work
/home/user/bar +@app +@work
/home/user/baz +@app +@work

Execute commands in one or more directories with run:

# Run "git status" in all directories tagged "work"
$ run work -c git status

# Run "git status" in directories ~/foo and ~/bar
$ run ~/foo ~/bar -c git status

# Mix tags and directory paths
$ run work ~/foo -c git status

Change directories by path or tag with d:

# Go to directory tagged "work" 
# If there are multiple directories, a selection prompt is displayed
$ d work

# Go to directory ~/foo (works just like cd)
$ d ~/foo

# Use -t/--tag to always assume the argument is a tag
$ d -t foo

Untag directories with untag:

# Remove tags "app" and "work" from directory ~/foo and ~/bar
$ untag ~/foo ~/bar -t app work

# Remove all tags from directory ~/foo
$ untag ~/foo

# Remove tag "app" from all directories
$ untag -t app

Manage tags with tags:

# List all tags
$ tags

# List all tags in JSON format
$ tags --json

# Clean invalid directories
$ tags --clean

# Remove all tags
$ tags --purge

Use --help to see more information on each command.

Technical Notes

  • Tags are saved in ~/.dtags directory (created when a dtags command is first run).
  • The files in ~/.dtags are not meant to be edited manually.
  • By default, directory paths take precedence over tags when name collisions occur.
  • Tag names are automatically slugified (e.g. "foo bar" to "foo-bar").
  • Tag names are displayed with the "@" character prefix for easy identification.
  • Directory paths and tag names are ordered alphabetically.

Uninstallation

Run the following commands to completely uninstall dtags:

$ pip uninstall dtags
$ rm -rf ~/.dtags

Then remove the dtags-activate line from your shell runtime configuration.

dtags's People

Contributors

acrisci avatar jetm avatar joowani avatar swsnider avatar

Stargazers

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

Watchers

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

dtags's Issues

TypeError: a bytes-like object is required, not 'str'

$ dtags edit
Traceback (most recent call last):
  File "/usr/bin/dtags", line 9, in <module>
    load_entry_point('dtags==2.0.0', 'console_scripts', 'dtags')()
  File "/usr/lib/python3.5/site-packages/dtags/commands/manage.py", line 208, in main
    _edit(tail)
  File "/usr/lib/python3.5/site-packages/dtags/commands/manage.py", line 63, in _edit
    tfile.write(EDIT_HELP_COMMENTS + mapping_file.read())
  File "/usr/lib/python3.5/tempfile.py", line 483, in func_wrapper
    return func(*args, **kwargs)
TypeError: a bytes-like object is required, not 'str'

It happens with Python 3.5, no problem with Python 2.7.

Getting error "Invalid argument: -10" when using on OSX with ohmyzshell

jonathan:~/ $ ls                                                     [15:19:29]
6.17.15 9.14 PM.pklg     Downloads                Public
Applications             Library                  PycharmProjects
Applications (Parallels) Movies                   bin
Desktop                  Music                    phab
Documents                Pictures
jonathan:~/ $ cd Documents                                           [15:19:36]
jonathan:Documents/ $ cd ..                                          [15:19:42]
jonathan:~/ $ d Documents                                            [15:19:44]
Usage:
  d [<dir>|<tag>]
  d --help
  d --version
Invalid argument: -10

Refactor scripts into template files

Right now, the scripts are hard to read and modify because we don't get syntax highlighting or other editor features. Refactoring them into proper template files would be helpful for modifying the scripts.

Mustache templates would be a good choice. Another simple option would be to use %VARIABLE% for variables and then do a simple search and replace.

Command to make other commands work with dtags

Now that I'm using dtags, I'm getting kind of spoiled by the convenience of my cd command and I want the convenience for my other commands too for common shell operations.

For instance, if I want to copy a file from one of my tagged directories, I would like to do this

cp my-tagged-dir/some-file ./

To make this happen, I would like a command called expand that can be used to accept a list of directories, and then print the list but with the tags expanded. Then I could do this:

dtags-cp() {
    cp $(dtags expand $@)
}

If a tag is not found, simply leave it alone.

It would be nice if there was an automated way to do that with every command, but I can't think of how to do that since many commands can accept mixed input of commands and directories and it's hard to tell exactly which is which.

Problem about dtags

CentOS 7
dtags 3.1.0

An error occurs as follows:

[root@node01 ~]# dtags
Traceback (most recent call last):
File "/usr/bin/dtags", line 7, in
from dtags.commands.manage import main
ImportError: No module named manage

[root@node01 ~]# t /usr/bin bin
-bash: t: command not found

How can I deal with this?thx..

dtags edit throws traceback

Hi,

I tried dtags today and so far, it seems really nice :-)

But as I tried the "dtags edit" command I got following traceback:
$ dtags edit
Traceback (most recent call last):
File "/usr/bin/dtags", line 9, in
load_entry_point('dtags==2.0.0', 'console_scripts', 'dtags')()
File "/usr/lib/python3.5/site-packages/dtags/commands/manage.py", line 208, in main
_edit(tail)
File "/usr/lib/python3.5/site-packages/dtags/commands/manage.py", line 63, in _edit
tfile.write(EDIT_HELP_COMMENTS + mapping_file.read())
File "/usr/lib/python3.5/tempfile.py", line 483, in func_wrapper
return func(_args, *_kwargs)
TypeError: a bytes-like object is required, not 'str'

My $EDITOR ist set in the ~/.bashrc:
$ echo $EDITOR
/usr/bin/emacs -nw

(it also works, with every over programm, which calls the $EDITOR variable)

I'm using Arch Linux and have installed dtags through AUR.

It isn't a real problem for me (because I think, I can directly change the files in ~/.dtags), but I think, you are probably interested in this error.

If you need some other information, I'm happy to provide them.

Sincerely

Quieter directory command

According to the README, the directory command (d) can be used as a replacement for cd.

I would like to try that, but I would like it to be a bit quieter similar to cd. I don't want it to announce what directory I am going to. This is in line with the Unix philosophy of avoiding cluttering output with extraneous information.

I do see benefit in announcing what directory it will change to when an alias is given. This follows the principle of least astonishment, because it might even be ambiguous sometimes what my intentions are, if for instance there is a directory with the same name as my directory alias in the cwd.

So I would like it to not print the directory when using it like cd in the normal way (not going to a tagged directory) and only print the directory name when going to a tag.

Otherwise, I would like a --quiet flag that could disable the output entirely when changing directories.

Thanks.

Remove shell rc eval step

I believe this project would be much more user friendly and easier to maintain if we could somehow get rid of the step that requires users to add command -v dtags > /dev/null 2>&1 && eval "dtags shell zsh" to their shell rc. The alternative would be to add an executable for d into the PATH instead of relying upon an alias.

This seems to be a deliberate design decision on your part so I assume you did it for a reason. Could you please explain your thought process behind this decision?

If i went through the code more carefully and found a way to accomplish this without the eval step, would you consider a PR for this feature?

d "directory" giving errors

after fish shell upgrade to version 3.0 , dtags giving error like this.

math: Error: Missing operator
'1 > 1'
^
math: Error: Missing operator
'1 < 1'
^
math: Error: Missing operator
'2 == 0'
^
math: Error: Missing operator
'2 == 1'
^

`d` without arguments should redirect to home directory

IDK if it's just my current shell or whether the behaviour has changed, but previously just d by itself would take me to the home directory, whereas now it complains that argument is required.
Certainly from my perspective it would be more intuitive to have d mimic cd, which would return to home.

Needs clarification for Windows users

I would like to try out the stuff, but it simply does nothing on Windows 7, but drops the following message for example on dtags-t:

Traceback (most recent call last):
  File "C:\app\python3\Scripts\dtags-t-script.py", line 11, in <module>
    load_entry_point('dtags==3.2.1', 'console_scripts', 'dtags-t')()
  File "c:\app\python3\lib\site-packages\dtags\commands\t.py", line 30, in main
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
AttributeError: module 'signal' has no attribute 'SIGPIPE'

Googled for the answer and it seems that SIGPIPE does not exist on Win.

As the README says:

p is currently not fully supported on Windows

I assume that you can try out on Win, but if I'm right, it has to be running in Cygwin (Git-Bash doesn't work too).

Is it possible to run in native cmd.exe? If not, then please write it to the documentation.

Unable to make it work

I've tried to follow the instructions to make it work but failed. The following show the steps I've taken.

image

So, how can I make it work?

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.