git_explorer 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -1
- data/bin/git-explore +1 -3
- data/demo.gif +0 -0
- data/lib/git_explorer.rb +58 -13
- data/lib/gitexplorer/version.rb +1 -1
- data/light_demo.gif +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd8597ae72fcfb449bac63394076fb7de2d207ac
|
4
|
+
data.tar.gz: b04641b0fbd4f25da8acde10d49fe949024ca9b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce6f1cc263b1784aa0f7eb39f9a85e4c1f2a0317b4f921d5d7339e7c75201565fcc8c6ddd96c3443c72becd9682e4bf268e66471465a17637cc242c9932b29b5
|
7
|
+
data.tar.gz: 164a75d3e9034bea64e9629b521c1452e001c5f47a8a86d6bd4a1b6f351c46ba8efcdf9149a328c9e880a8bdf4e2b91f5434ac3254a38054f3814443c2096243
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Git Explorer
|
2
2
|
|
3
3
|
[](https://travis-ci.org/alexrochas/git-explorer)
|
4
4
|
[](https://badge.fury.io/rb/git_explorer)
|
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
GitExplorer comes from the necessity of get the status of all my local repositories. This tool will scan all your projects searching for git repositories and extract the project name, status and files unstaged.
|
9
9
|
|
10
|
+

|
11
|
+
|
10
12
|
## Installation
|
11
13
|
|
12
14
|
Linux:
|
@@ -33,11 +35,38 @@ All your git repositories from <root_path> will be scanned and the output will b
|
|
33
35
|
path/to/file
|
34
36
|
```
|
35
37
|
|
38
|
+
|
39
|
+
## Light Explorer
|
40
|
+
|
41
|
+
In a try to add a feature to my old ls command, I've created the **light explorer** function. Will behave like a ls but if find any git repository will decorate with branch and current state.
|
42
|
+
|
43
|
+

|
44
|
+
|
45
|
+
```bash
|
46
|
+
~$ git explore --light
|
47
|
+
```
|
48
|
+
|
49
|
+
The output will decorate any directory that is also a git repository:
|
50
|
+
|
51
|
+
```bash
|
52
|
+
drwxrwxr-x 4 alex alex 4096 Jul 21 16:33 workshopvenues [master] ✖
|
53
|
+
drwxrwxr-x 2 alex alex 4096 Ago 6 01:57 zsh-ex
|
54
|
+
drwxrwxr-x 3 alex alex 4096 Nov 7 16:25 zsh-extract [master] ✔
|
55
|
+
drwxrwxr-x 3 alex alex 4096 Out 5 09:22 zsh-git-keep-autocomplete [master] ✔
|
56
|
+
drwxrwxr-x 3 alex alex 4096 Set 13 14:39 zsh-path-environment-explorer [master] ✔
|
57
|
+
drwxrwxr-x 2 alex alex 4096 Ago 6 01:23 zsh-test
|
58
|
+
drwxrwxr-x 3 alex alex 4096 Ago 12 16:57 zsh-vim-crtl-z [master] ✔
|
59
|
+
```
|
60
|
+
|
36
61
|
## Release History
|
37
62
|
|
38
63
|
* 0.1.0
|
39
64
|
* Work in progress.
|
40
65
|
|
66
|
+
## Roadmap
|
67
|
+
|
68
|
+
* Implement more symbols to express the state of the repository (https://www.reddit.com/r/zsh/comments/2jvi61/where_can_i_find_symbol_codes_for_the_fancy/)
|
69
|
+
|
41
70
|
## Meta
|
42
71
|
|
43
72
|
Alex Rocha - [about.me](http://about.me/alex.rochas)
|
data/bin/git-explore
CHANGED
data/demo.gif
ADDED
Binary file
|
data/lib/git_explorer.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'gitexplorer/version'
|
2
|
+
require 'thor'
|
3
|
+
require 'pipeme'
|
4
|
+
require 'logger'
|
4
5
|
|
5
6
|
module GitExplorer
|
6
7
|
|
7
8
|
GitStatus = Struct.new("GitStatus",:status,:project_name,:branch,:files,)
|
8
9
|
|
9
|
-
def
|
10
|
+
def extract_status
|
10
11
|
-> (status_output) {
|
11
12
|
project_name = status_output[/^(?<project_name>.*)$/, "project_name"]
|
12
13
|
branch = status_output[/On branch\s(?<branch>.*)/, "branch"]
|
@@ -17,22 +18,66 @@ module GitExplorer
|
|
17
18
|
}
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
+
def extract_light_status(status_output)
|
22
|
+
project_name = status_output[/^(?<project_name>.*)$/, "project_name"]
|
23
|
+
branch = status_output[/On branch\s(?<branch>.*)/, "branch"]
|
24
|
+
status = :up_to_date unless status_output[/not staged/]
|
25
|
+
status = :not_staged if status_output[/not staged/]
|
26
|
+
files = status_output.scan(/modified: \s*(.*)$/).flatten
|
27
|
+
GitStatus.new(status, project_name, branch, files)
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_dir_name
|
21
31
|
-> (dot_git_file_path) { dot_git_file_path.gsub(/\.git$/,'') }
|
22
32
|
end
|
23
33
|
|
34
|
+
def extract_path(line, root_dir)
|
35
|
+
parsed_path = line[/.*\s(?<path>.*)$/, 'path']
|
36
|
+
root_dir + parsed_path
|
37
|
+
end
|
38
|
+
|
39
|
+
def git_repository?(path)
|
40
|
+
return nil if path.nil?
|
41
|
+
is_directory = File.directory?(path)
|
42
|
+
is_repository = run("find #{path} -maxdepth 1 -type d -name .git", config={:capture=>true, :verbose=>false}) if is_directory
|
43
|
+
is_directory and !is_repository.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def git_status(path)
|
47
|
+
run("basename `git -C #{path} rev-parse --show-toplevel`; git -C #{path} status", config={:capture=>true, :verbose=>false})
|
48
|
+
end
|
49
|
+
|
24
50
|
class Explorer < Thor
|
25
51
|
include Thor::Actions
|
52
|
+
include GitExplorer
|
53
|
+
|
54
|
+
Line = Struct.new('Line', :full_line, :state, :git_repository)
|
55
|
+
LOGGER = Logger.new(STDOUT)
|
26
56
|
|
27
57
|
# TODO refactor and extract maps to lambdas
|
28
|
-
desc
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
58
|
+
desc 'use for explore recursively directories and show actual status of git repositories', 'git explore .'
|
59
|
+
method_options [:light,:l] => :boolean, :desc => 'decorate list files with git repository state'
|
60
|
+
def explore(root_dir='./')
|
61
|
+
if options.light?
|
62
|
+
run("ls #{root_dir} -l | awk '{if(NR>1)print}'", config={:capture=>true, :verbose=>false})
|
63
|
+
.split("\n")
|
64
|
+
.map{|line| Line.new(line)}
|
65
|
+
.map{|line| Line.new(line.full_line, '', git_repository?(extract_path(line.full_line, root_dir)))}
|
66
|
+
.map{|line| Line.new(line.full_line, (extract_light_status(git_status(extract_path(line.full_line, root_dir))) if line.git_repository == true), line.git_repository)}
|
67
|
+
.map{|line|
|
68
|
+
say(message="#{line.full_line} ")
|
69
|
+
say(message="#{'[' + line.state.branch + ']'} ✖ ", color=(:red)) if line.git_repository == true and line.state.status != :up_to_date
|
70
|
+
say(message="#{'[' + line.state.branch + ']'} ✔ ", color=(:green)) if line.git_repository == true and line.state.status == :up_to_date
|
71
|
+
say(message="\n")
|
72
|
+
}
|
73
|
+
else
|
74
|
+
run("find #{root_dir} -type d -name .git", config={:capture=>true, :verbose=>false})
|
75
|
+
.split("\n")
|
76
|
+
.map{|file| file >> extract_dir_name}
|
77
|
+
.map{|dir| run("basename `git -C #{dir} rev-parse --show-toplevel`; git -C #{dir} status", config={:capture=>true, :verbose=>false})}
|
78
|
+
.map{|status| status >> extract_status}
|
79
|
+
.map{|status| say(message="#{status.project_name} is #{status.status} on branch #{status.branch}\n#{status.files.map{|f| "\t#{f}\n"}.join}", color=(:red if status.status.equal?(:not_staged)))}
|
80
|
+
end
|
36
81
|
end
|
37
82
|
|
38
83
|
end
|
data/lib/gitexplorer/version.rb
CHANGED
data/light_demo.gif
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_explorer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Rocha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,9 +96,11 @@ files:
|
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
98
|
- bin/git-explore
|
99
|
+
- demo.gif
|
99
100
|
- gitexplorer.gemspec
|
100
101
|
- lib/git_explorer.rb
|
101
102
|
- lib/gitexplorer/version.rb
|
103
|
+
- light_demo.gif
|
102
104
|
homepage: https://github.com/alexrochas/git-explorer
|
103
105
|
licenses:
|
104
106
|
- MIT
|