懒散程序员的目录标记
dtags的Python项目详细描述
功能
dtags是一个轻量级的命令行工具,它允许您:
- 标记目录并通过标记名在它们之间快速跳转
- 在标记的目录中并行运行命令
- 轻松管理Git存储库、流浪机器等。
安装
检查要求:
- python 2.7、3.4、3.5、3.6或3.7
- 支持的操作系统:Linux、OS X、Windows上的ubuntu
- 最新版本的pip
- 启用制表符补全的bash、zsh或fish的最新版本
安装软件包:
# You may need to sudo depending on your environment setup
~$ pip install dtags
在shell运行时配置的末尾添加以下行并重新加载shell:
# For zsh, place in ~/.zshrc: command -v dtags-activate > /dev/null 2>&1&&eval"`dtags-activate zsh`"# For bash, place in ~/.bashrc (or ~/.bash_profile for OS X): command -v dtags-activate > /dev/null 2>&1&&eval"`dtags-activate bash`"# For fish, place in ~/.config/fish/config.fish: command -v dtags-activate > /dev/null 2>&1; and dtags-activate fish |source
一旦安装完毕,您将拥有以下功能:
- 实用程序命令t,u,d,e,p
- 主命令dtags
所有命令都带有制表符补全。
用法
用t:
标记目录~$ t ~/app dev work # tag ~/app with 'dev' and 'work' ~$ t ~/app # tag ~/app with its basename, 'app'
用u:
取消对目录的标记~$ u ~/app dev # remove tag 'dev' from ~/app ~$ u ~/app # remove all tags from ~/app
使用d更改目录(旨在完全替换cd!):
~$ d # go to the user's home directory ~$ d - # go to the last directory ~$ d app # go to the directory tagged 'app' ~$ d ~/app # go to directory ~/app
使用e:
在一个或多个目录中执行命令~$ e app git status # execute 'git status' in all directories tagged 'app' ~$ e ~/vm vagrant halt # regular directory paths are accepted as well ~$ e app,~/vm,~/foo ls # multiple tags and/or paths can be specified using commas ~$ e -i app myalias # use -i (interactive shell) to use functions, aliases etc.
与p(与e接口相同)并行执行命令:
~$ p app git pull # execute 'git pull' in all directories tagged 'app' in parallel ~$ p -i app myalias # again, use -i for interactive shell (read below for caveats)
使用dtags:
显示、搜索和管理标记~$ dtags # display the directories-to-tags mapping ~$ dtags list ~ ~/vm # list the tags and directories associated with ~ and ~/vm ~$ dtags list foo bar # list the tags and directories associated with 'foo' or 'bar' ~$ dtags reverse # list the tags-to-directories (reverse) mapping ~$ dtags edit # edit tags and directories via editor ~$ dtags clean # remove invalid or stale tags and directories ~$ dtags commands # display all available dtags commands (e.g. t, u, d, e, p)
如果标记指向单个目录,则会自动创建shell变量:
~$ t ~/some/dir foo # shell variable '$foo' is automatically created ~$ ls $foo/sub/dir # $foo can now be used to denote the tagged directory ~/some/dir ~$ rm $foo/file.sh # $foo can now be used to denote the tagged directory ~/some/dir
您始终可以使用--help选项来了解有关每个命令的更多信息!
更多示例
简化Git工作流:
# Tag your git directories ~$ t ~/project/mobile app ~$ t ~/project/backend app ~$ t ~/project/frontend app ~$ t ~/project/config app # Save yourself some time! ~$ e app git status ~$ p app git pull ~$ e app git checkout v1.7.2
同时控制多台流浪机器:
# Tag all the things ~$ t ~/machines/web vm ~$ t ~/machines/redis vm ~$ t ~/machines/mysql vm ~$ t ~/machines/compute vm # Profit! ~$ p vm vagrant status ~$ p vm vagrant up
技术说明
- dtags当前在Windows上不支持eem>(仅在Windows上支持ubuntu)
- 目录到标记的映射存储在~/.dtags/mapping
- 标签也存储在~/.dtags/tags中,用于完成标签页
- p无法执行等待输入的交互式命令
- p生成子进程,并将所有输出重定向到临时文件,然后重定向到stdout
- p由于外壳限制,不保留字体颜色
- p在终止时向其子进程发送sigterm。
- e(或p)使用环境变量$shell猜测正在使用哪个shell
- {TT4}$(或^ {TT5}$)重定向STDRR到STDUT并始终返回0 的退出状态
- 使用-i(交互式shell)时需要注意:
- 每次执行命令时,shell运行时配置都必须是“源代码”
- 性能受shell启动时间的影响(当心我的zsh用户)
- 在“寻源”过程中引发的任何错误都将显示在输出中
- dtags edit使用环境变量$编辑器
- d当存在名称冲突时,首选标记而不是子目录
- 要转到子目录,请将/放在目录名之后
- d要求~/.dtags/mapping格式正确:
- 不要直接编辑~/.dtags/mapping。
- 相反,请使用dtags edit,它为您进行验证和格式化
- 制表符完成要求~/.dtags/tags格式正确:
- 请勿触摸此文件
- 每当运行dtags命令时,就会自动生成此文件。
- 仅当外壳变量的名称与环境变量不冲突时,才会创建外壳变量
- 创建shell变量时,名称中任何不允许的字符都将替换为下划线