StreakyCobra / gws

Colorful KISS helper for git workspaces
https://streakycobra.github.io/gws/
MIT License
234 stars 22 forks source link

gws

gws is a KISS, bash, colorful helper to manage workspaces composed of Git repositories.

SHOW ME PICTURES!

Here are some screen captures of gws:

gws

gws

gws

gws

gws

Installation

Requirements: git, bash > 4.0

On a side note, I could also suggest you to have a look at peru which lets you keep files from different sources up to date with one command.

Quick Start

or

and then

But better

Let's say you made a ~/dev/ workspace folder and you created your .projects.gws list in it. Then your workspace became really easy to replicate! Just make this ~/dev folder a Git repository, add two files and commit them: .projects.gws and the following .gitignore:

# Ignore everything, so all repositories in our case
*

# But not these files
!.projects.gws
!.gitignore

Now, when you need to get your workspace on another computer, just clone the dev repository, for instance again to the ~/dev folder. Go into it and do a gws update. Everything is cloned and ready to be hacked!

You want to add a new project into your workspace? Add it to the .projects.gws list, do a gws update to get it. Then commit and push the .projects.gws file, so when you arrive at work for instance, you just need to git pull on the ~/dev folder and then gws update to get the same workspace structure that you had at home.

Why?

If you are, like me, a Linux programmer/hacker/coder who uses Git a lot, you certainly have a directory in your home folder named dev, workspace, code or something else that contains all the projects you are working on. For instance my current organisation is:

dev
├── archlinux
│   ├── aur
│   └── habs
├── perso
│   ├── gws
│   ├── imaxplore
│   └── teafree
└── config

where aur, habs, gws, imaxplore, teafree, config are Git repositories.

Since I use at least three different computers - one laptop, one at home and one at work - I like to have the same folder structure on all of them. Of course remembering which project was added recently on other computers and in which folder is tedious.

So I started to think about using Git submodules to register all projects on which I am working and syncing them with Git between the two computers. But clearly Git submodules are not usable because they are work with specific commits and not by following branches.

No worry. The problem is pretty trivial, so I decided to start write a little bash (YOLO) script that reads a simple list of repositories, and clones them if they don't exist. And then, commit by commit, the script as grown to finally become a helper to sync, monitor and check workspaces.

I thought it can be useful to other people, so I made a little cleanup, wrote some small documentation, and there it is. I hope you will enjoy it!

Features

This tool offers some features, including:

Syntaxes

.projects.gws

One project per line. Must be of the form

<any/folder/path> | <remote_url1> <remote_name1> [ | <remote_url2> <remote_name2> [ |  ... ]]

where

.ignore.gws

One regular expression per line. The regular expression will be matched against each project's folder path. Some examples:

This function is really useful for locally ignoring some projects that are not needed or not accessible.

Theme file

You can customise the color scheme by placing a shell script at one of the following locations:

  1. ./.git/theme.gws
  2. ${HOME}/.theme.gws
  3. ${HOME}/.config/gws/theme

The first existing file in the above order, if any, will be sourced into the main gws script if standard output is a terminal. In the theme script you can redefine the color codes set as C_* near the beginning of the main script.

-Why can't I put this in the projects directory with .projects.gws and .ignore.gws?

Because then if you sync your .projects.gws via Git you could inadvertently pull a commit that writes a theme file containing arbitrary shell code, which gws would then blindly run. You're still owned in other ways if an attacker has arbitrary write access in your home directory, but this way the write can't be done remotely over Git.

Other thoughts

Future

This project aims to stay simple. I will try to keep the project as alive as possible for a bash script, by correcting bugs and maybe some improvements. Also, maybe one day, if I have time, I will rewrite all of this script in Python or other more maintainable language.

Edit: It seems there will be a continuation of this idea, and it will be written in OCaml! I'll let you know if the project matures! In any case this project will stay here for users who want something simple and portable.

Maintainers

The project is currently maintained by Emil Lundberg (emlun), after being started by Fabien Dubosson (StreakyCobra).

Contributors

Many thanks to these people for contributions: