faster shell navigation of projects

50
4
Ruby

h - faster shell navigation of projects

Built with Nix
Build Status

h is a small shell utility that I use every day to jump between projects quickly. It is complimentary to the amazing j
(autojump) project and both help me
improve my workflow.

h is designed to work with a secific filesystem structure where all code is
checked-out in ~/code/<domain>/<path>. Eg: ~/code/github.com/zimbatm/h for
this project. This allows to not have to think about project locality.

The goal is that h h would find and cd into ~/code/github.com/zimbatm/h if
it exists. When using the h zimbatm/h form it would look for the specific
folder or clone the repo from github. In both cases you will end-up changing
directory in the repo that you want to access. This allows to quickly access
existing and new project.

If projects don’t live on github then their full git url can be provided to
clone into ~/code/<domain>/<path>.

Usage

h <name> searches for a project called <name> where <name> matches
^\w\.\-$. The search is done up to 3 levels deep and the longest match is
returned. If a result is found the path is printed on stdout. The
current directory is printed on stdout.

h <user>/<repo> looks for a ~/code/github.com/<user>/<repo> folder or
clones it from github. The path is output on stdout if the repo exists or has
been cloned successfully. The current directory is printed on stdout
otherwise.

h <url> looks for a ~/code/<domain>/<path> folder or clones it with git.
The path is output on stdout if the repo exists or has been cloned
successfully. The current directory is printed on stdout otherwise.

Installation

Copy the h ruby script to somewhere in the PATH.

In your ~/.zshrc | ~/.bashrc | .. add the following line:

eval "$(h --setup ~/code)"

This installs something really similar to alias h='cd "$(h ~/code "$@")"
where ~/code is the root of all your repositories. Once the shell is reloaded
you can use the above commands.

With nix-darwin

Add h to your flake inputs and include the module:

{
  inputs.h.url = "https://flakehub.com/f/zimbatm/h/0.1.35.tar.gz";
  # [ ...snip... ]

  outputs = { nix-darwin, ... } @ inputs: {
    darwinConfigurations.default = nix-darwin.lib.darwinSystem {
      system = "x86_64-darwin";

      modules = [
        h.darwinModules.default
        ({ pkgs, ... }: {
          # ... your configuration ...
        })
      ];
    };
  }
}

With Home Manager

Add h to your flake inputs and include the module:

{
  inputs.h.url = "https://flakehub.com/f/zimbatm/h/0.1.35.tar.gz";
  # [ ...snip... ]

  outputs = { home-manager, ... } @ inputs: {
    homeConfigurations.default = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.x86_64-linux;

      modules = [
        h.homeModules.default
        ./home.nix
      ];
    };
  };
}

Note: enable zsh or bash as well, via programs.zsh.enable = true; or programs.bash.enable = true;.

See also

License

MIT - © 2015 zimbatm and contributors