A hierarchy aware `cd` command for easier navigation to your repositories

栏目: IT技术 · 发布时间: 5年前

内容简介:AGo organizes modules based on

rh.lua

A Go modules-like hierarchy aware cd command for easier navigation to your repositories.

Go organizes modules based on server/organization/repository hierachy (for example, github.com/knl/rh ), which I liked a lot. rh.lua is a step toward having that structure with all repositories I keep on my machine, while making my workflow as smooth as possible.

rh.lua assumes that all the repositories are checked-out under a specific umbrella folder in the filesystem, for example ~/work . Under this umbrella repository it would help navigate and maintain the repository hierarchy in the same manner as go modules, that is, ~/work/server/organization/repository .

rh.lua is fully implemented in lua in order to make it fast. rh.lua is heavily influenced and based on z.lua , from which it took all filesystem/datastore code.

Usage

  • rh.lua lists all known repositories under predefined umbrella folder (that is set during the installation).

  • rh.lua [[server/]org/]repo does a frecency search (a la z.lua and/or fasd_cd ) and searches for a repository whose name is partially matching repo , for an org org and server server . If found, cd s to that folder. If you omit both server and org , the search will be only over repository names. If your search term is in form org/repo , it will try to match org and then repo at respective positions. Similarly for the full blown term server/org/repo . You could also use spaces instead of / . If the best match matches the current folder, it will jump to the next matching one.

    For example, rh.lua pkg will jump to ~/work/github.com/NixOs/nixpkgs , while rh.lua f/pkg will jump to ~/work/github.com/FreeBSD/pkg .

  • rh.lua [http|git|https]://server/org/repo will look for a ~/work/<server>/<org>/<repo> folder and cd to it. If the folder doesn't exist, it will clone it with git and cd to it.

  • rh.lua term<TAB> will autocomplete based on term .

Dependencies

Apart from a working lua installation, rh.lua requires either z.lua or fasd_cd (for the latter, set $_RH_DATA to ~/.fasd ).

Installation

Copy the rh.lua script to somewhere in the PATH.

  • Zsh Install: Put something like this in your .zshrc :

    eval "$(lua /path/to/rh.lua --init zsh ~/work)"

    It can also be initialized from "knl/rh" with your zsh plugin managers (antigen / oh-my-zsh). Just don't forget to set $_RH_ROOT .

  • Bash Install: Put something like this in your .bashrc :

    eval "$(lua /path/to/rh.lua --init bash ~/work)"
  • Posix Shell Install: Put something like this in your .profile :

    eval "$(lua /path/to/rh.lua --init posix ~/work)"
  • Fish Shell Install: Put something like this in ~/.config/fish/conf.d/z.fish :

    source (lua /path/to/rh.lua --init fish ~/work | psub)

    Fish version 2.4.0 or above is required.

  • Power Shell Install: Put something like this in your profile.ps1 :

    iex ($(lua /path/to/rh.lua --init powershell) -join "`n")
  • Windows Install (with Clink ):

    • Copy rh.lua and rh.cmd to clink's home directory
    • Add clink's home to %PATH% ( rh.cmd can be called anywhere)
    • Ensure that "lua" can be called in %PATH%
    • Ensure that "lua" can be called in %PATH%
  • Windows Cmder Install:

    • Copy rh.lua and rh.cmd to cmder/vendor
    • Add cmder/vendor to %PATH%
    • Ensure that "lua" can be called in %PATH%

Configure

This is optional step, use it if you really need to.

  • Set $_RH_CMD in .bashrc / .zshrc to change the command (default rh ).
  • Set $_RH_DATA in .bashrc / .zshrc to change the datafile (default ~/.zlua ).
  • Set $_RH_ROOT in .bashrc / .zshrc to change the store root (default ~/work ).

History

  • 1.0.0 (2019-03-22): First official release

FAQ

Why is it called rh ?

Repository Hierarchy.

Why did you write this in Lua, isn't Lua slow?

Lua is a great language and pretty fast at it. For example z.lua is faster than other alternatives, even tho it code gets interpreted and requires loading of lua executable. Plus, basing the code on z.lua allows this gem to run on many platforms.

OMG, why >1000 LoC?

Mostly to make it self contained and avoid loading many modules. Everything sits in a single file.

How different is rh.lua from z.lua ?

For the initial release, git diff --stat -b shows:

z.lua => ../../knl/rh/rh.lua | 1734 ++++++--------------------------------
 1 file changed, 253 insertions(+), 1481 deletions(-)

This code is a modification of z.lua to support reading the same data file and have all the supporting functions, however some parts were modified in order to have the desired functionality.

rh.lua will not update the data file, ever! It only reads from it and makes decision where to jump.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C++程序设计语言

C++程序设计语言

Bjarne Stroustrup / 裘宗燕 / 机械工业出版社 / 2010-3-1 / 99.00元

本书是在C++语言和程序设计领域具有深远影响、畅销不衰的著作,由C++语言的设计者编写,对C++语言进行了最全面、最权威的论述,覆盖标准C++以及由C++所支持的关键性编程技术和设计技术。本书英文原版一经面世,即引起业内人士的高度评价和热烈欢迎,先后被翻译成德、希、匈、西、荷、法、日、俄、中、韩等近20种语言,数以百万计的程序员从中获益,是无可取代的C++经典力作。 在本书英文原版面世10年......一起来看看 《C++程序设计语言》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具