Coder Social home page Coder Social logo

gofu's Introduction

Gofu

Gofu is a multibinary containing several utilities that I use everyday.

What's with the name?

A gofu, according to Wikipedia, is a type of household amulet or talisman, issued by a Shinto shrine, hung in the house for protection.

Alternatively, the name can also be read as "Go-fu".

Installation

$ make && make install

List of applets

prettyprompt

This renders my shell prompt. Among other things, it identifies the current host by name and signature color (in the screenshot below, dark green for Krikkit); highlights path elements inside a Git repo (if any) and path elements that have been deleted; reports the current Git repo status; and reports the exit code of the previous command (if it failed). It also heavily saves space where possible, e.g. if the cwd starts with $GOPATH/src/, that is shortened to repo:. A prefix of $HOME/ is omitted entirely, as is my default user name.

prettyprompt screenshot

rtree

This manages my Git repositories. Borrowing from the convention established by Go's GOPATH, the location of each local repository is defined by its remote URL. For example, this repo here will always be checked out at

$GOPATH/src/github.com/majewsky/gofu

The most common operation with rtree is to get a repository path:

$ rtree get https://github.com/majewsky/gofu
/x/src/github.com/majewsky/gofu

This will automatically clone the repo if it has not been cloned yet. Git URL aliases like these are supported. I use a shell function called cg that means cd to git repository and is based on rtree get:

$ pwd
/home/stefan
$ cg gh:majewsky/gofu
$ pwd
/x/src/github.com/majewsky/gofu

When rtree get clones a new repo, it will look for existing repos with the same basename, and prompt the user about whether to treat this repo as a fork of some other repo:

$ cg gh:forkof/holo
Found possible fork candidates. What to do?
 [ ] add as remote to /x/src/aur.archlinux.org/holo
 [ ] add as remote to /x/src/github.com/holocm/holo
 [n] clone to /x/src/github.com/forkof/holo

There are a few other subcommands in rtree:

  • rtree drop <URL> deletes the local repo identified by the given remote URL (after asking for confirmation).
  • rtree repos lists the paths (below $GOPATH/src) of all local repos.
  • rtree remotes lists the remote URLs of all local repos.
  • rtree each <COMMAND> executes the given command in each repository. My most common usecase is rtree each git status --short.
  • rtree import <PATH> takes a path to a local Git repo, and moves it to the correct place below $GOPATH/src.

Finally, rtree index rebuilds the index file (~/.rtree/index.yaml) that all of these operations use to find repos and remotes. If a repo is checked out, but not yet indexed, the index entry will be added. If the repo for an index entry is missing, the user will be prompted about what to do:

$ rtree index
repository /x/src/github.com/Masterminds/sprig has been deleted
 [r] restore from https://github.com/Masterminds/sprig
 [d] delete from index
 [s] skip

One of the intended usecases is that stuff below $GOPATH/src does not need to be backed up. As long as the index file ~/.rtree/index.yaml is backed up, all repos can be restored in one step with yes r | rtree index.

gofu's People

Contributors

majewsky avatar supersandro2000 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

Watchers

 avatar  avatar  avatar

gofu's Issues

rtree index is not syncing remotes to repos

When syncing the ~/.rtree/index-carbon.yaml file there might be new remotes in the file than there are in the git repos. When running rtree index the existing remotes from the git repos are written into the yaml file without any regards wether there where new ones in the yaml file which should have been synced to the git repo on disk before writing them back into the config.

Issues building on macOS

Hey, I read your article about terminal latency, and was pretty interested in trying out gofu!

I'm running on macOS, go version go1.8.3 darwin/amd64, and when I run make, I get:

GOPATH=<path>/gofu/.gopath GOBIN=<path>/gofu/build go install  -ldflags '-s -w' 'github.com/majewsky/gofu'
# github.com/majewsky/gofu/pkg/prompt
could not determine kind of name for C.__uid_t
make: *** [build/gofu] Error 2

I'm very new to golang, but some googling shows similar issues for the git2go project, so I built a new version of libgit2 with homebrew, but I'm still getting the issue.

Do you normally run on a mac, or is your daily OS linux?

rtree gets confused when a remote is referenced both with alias and without

$ cd /
$ cg gh:lib/pq
!! /x/src/github.com/lib/pq already exists (if there is a repo there, try `rtree index`)
$ pwd
/
$ cg https://github.com/lib/pq
$ pwd  
/x/src/github.com/lib/pq

Plan:

  • always write repositories into index with their fully expanded remote URL
  • when displaying remote URL, apply available aliases to shorten the URL

macOS support

I was having some problems on the make install part, the make worked fine:

but the make install gave the following error:

$ make install
GOPATH=/Users/talal/Go/src/github.com/majewsky/gofu/.gopath GOBIN=/Users/talal/Go/src/github.com/majewsky/gofu/build go install  -ldflags '-s -w' 'github.com/majewsky/gofu'
install -D -m 0755 build/gofu "/usr/bin/gofu"
install: illegal option -- D
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...

I removed the -D option from the Makefile.

then:

$ make install
GOPATH=/Users/talal/Go/src/github.com/majewsky/gofu/.gopath GOBIN=/Users/talal/Go/src/github.com/majewsky/gofu/build go install  -ldflags '-s -w' 'github.com/majewsky/gofu'
install -m 0755 build/gofu "/usr/bin/gofu"
install: /usr/bin/gofu: Operation not permitted
make: *** [install] Error 71

Usually user stuff/binaries go in /usr/local/bin, that is where homebrew also symlinks its installed binaries. So I changed the line 17-19 in the Makefile to:

install: FORCE all
	install -m 0755 build/gofu "/usr/local/bin/gofu"
	for APPLET in $(APPLETS); do ln -s gofu "/usr/local/bin/$${APPLET}"; done

that worked and the correct symlinks were made.

Since I have zero clue about how Makefile(s) work, kindly advise on what would be a better approach to make this work on macOS.

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.