rprompt 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rprompt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Olivier Robert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # rprompt
2
+
3
+ Pimp your prompt :-)
4
+
5
+ This prompt is a shameless port (and enhancement) of the "Informative git prompt for bash and fish" which you can find [here](https://github.com/magicmonty/bash-git-prompt.git)
6
+
7
+ This gem is targeted toward users who use ruby, rvm and git. It will improve your ``bash`` prompt by displaying information about the current git repository or the rvm ruby version and gemset.
8
+
9
+ ## Usage
10
+
11
+ The prompt is customizable via a yaml file that enables you to:
12
+
13
+ * choose the options you want to see
14
+ * set your standard unix prompt
15
+ * set your git prompt
16
+ * set your rvm prompt
17
+ * change the layout of what goes where
18
+ * change the symbols to identify options
19
+ * change colors (all colors provided by the term-ansicolor gem)
20
+
21
+ Using the layout is actually very easy: throw the name of the options around, add white spaces, delimiters, etc... Save, hit enter in your shell, done!
22
+
23
+ ### Git examples
24
+
25
+ The prompt may look like the following:
26
+
27
+ * ``(master↑3|✚1)``: on branch ``master``, ahead of remote by 3 commits, 1 file changed but not staged
28
+ * ``(status|●2)``: on branch ``status``, 2 files staged
29
+ * ``(master|✚7…)``: on branch ``master``, 7 files changed, some files untracked
30
+ * ``(master|✖2✚3)``: on branch ``master``, 2 conflicts, 3 files changed
31
+ * ``(experimental↓2↑3|✔)``: on branch ``experimental``; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean
32
+
33
+ The symbols are as follows:
34
+
35
+ - Local Status Symbols
36
+ - ``✔``: repository clean
37
+ - ``●n``: there are ``n`` staged files
38
+ - ``✖n``: there are ``n`` unmerged files
39
+ - ``✚n``: there are ``n`` changed but *unstaged* files
40
+ - ``…n``: there are ``n`` untracked files
41
+ - Branch Tracking Symbols
42
+ - ``↑n``: ahead of remote by ``n`` commits
43
+ - ``↓n``: behind remote by ``n`` commits
44
+
45
+ ### Rvm examples
46
+
47
+ * ∆1.9.3-p448: ruby version 1.9.3
48
+ * ›global: using the global gemset
49
+
50
+ ## Installation
51
+
52
+ $ gem install rprompt
53
+
54
+ Once the gem is installed,
55
+
56
+ $ rpromptconf
57
+
58
+ This will provide a standard config file: ```$HOME/.rprompt/config.yml```
59
+
60
+ To make the magic happen:
61
+
62
+ * edit your ~/.bashrc or ~/.bash_profile
63
+ (depending on your preferences and setup)
64
+ * if you're setting PS1 already, comment it while you're using rprompt
65
+ * paste the following lines between '---' at the end of the file
66
+
67
+ ---
68
+ # Setting terminal promt with rprompt gem
69
+ PROMPT_COMMAND="$PROMPT_COMMAND PS1=\"\$(rprompt)\";"
70
+ ---
71
+
72
+ * quit your terminal and re-open it for the change to take effect.
73
+
74
+ Edit $HOME/.rprompt/config.yml to change the configuration.
75
+ (you can always re-install the default configuration by issuing 'rpromptconf')
76
+
77
+ Enjoy :\))
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rprompt ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: utf-8
3
+
4
+ require 'YAML'
5
+ require 'rprompt'
6
+
7
+ configFile = "#{File.expand_path('~')}/.rprompt/config.yml"
8
+ begin
9
+ config = YAML.load_file configFile
10
+ rescue => err
11
+ puts err.message
12
+ puts "Please run 'rPrompt config' to create the initial configuration.\n> " #TODO
13
+ exit
14
+ end
15
+
16
+ stdPrompt = config[:stdprompt] if config.has_key?(:stdprompt)
17
+ gitConfig = config[:git] if config.has_key?(:git)
18
+ gitLayout = gitConfig[:layout] if gitConfig
19
+ rvmConfig = config[:rvm] if config.has_key?(:rvm)
20
+ rvmLayout = rvmConfig[:layout] if rvmConfig
21
+
22
+ if File.exist?(".git") && gitConfig
23
+ staged = Rprompt::GitNumbers.new(gitConfig[:staged])
24
+ modified = Rprompt::GitNumbers.new(gitConfig[:modified])
25
+ untracked = Rprompt::GitNumbers.new(gitConfig[:untracked])
26
+ unmerged = Rprompt::GitNumbers.new(gitConfig[:unmerged])
27
+ branch = Rprompt::GitBranch.new(gitConfig[:branch])
28
+ ahead = Rprompt::GitTrack.new(gitConfig[:ahead], "ahead")
29
+ behind = Rprompt::GitTrack.new(gitConfig[:behind], "behind")
30
+ sha = Rprompt::GitSha.new(gitConfig[:sha])
31
+
32
+ if staged.numberOfFiles == 0 && untracked.numberOfFiles == 0 && unmerged.numberOfFiles == 0 && modified.numberOfFiles == 0
33
+ gitLayout.gsub!(/staged|modified|untracked|unmerged/, '')
34
+ gitLayout.gsub!(/allgood/, "✔".send(:green)) if gitLayout.include?("allgood")
35
+ else
36
+ gitLayout.gsub!(/allgood/, '') if gitLayout.include?("allgood")
37
+ gitLayout.gsub!(/staged/, staged.show) if gitLayout.include?("staged")
38
+ gitLayout.gsub!(/modified/, modified.show) if gitLayout.include?("modified")
39
+ gitLayout.gsub!(/untracked/, untracked.show) if gitLayout.include?("untracked")
40
+ gitLayout.gsub!(/unmerged/, unmerged.show) if gitLayout.include?("unmerged")
41
+ end
42
+
43
+ gitLayout.gsub!(/branch/, branch.show) if gitLayout.include?("branch")
44
+ gitLayout.gsub!(/sha/, sha.show) if gitLayout.include?("sha")
45
+ gitLayout.gsub!(/ahead/, ahead.show) if gitLayout.include?("ahead")
46
+ gitLayout.gsub!(/behind/, behind.show) if gitLayout.include?("behind")
47
+ else
48
+ gitLayout = ''
49
+ end
50
+
51
+ # RVM
52
+
53
+ if rvmConfig
54
+ ruby = Rprompt::RvmRuby.new(rvmConfig[:ruby])
55
+ gemset = Rprompt::RvmGemset.new(rvmConfig[:gemset])
56
+
57
+ rvmLayout.gsub!(/ruby/, ruby.show) if rvmLayout.include?("ruby")
58
+ rvmLayout.gsub!(/gemset/, gemset.show) if rvmLayout.include?("gemset")
59
+ end
60
+
61
+ prompt = "#{stdPrompt[:start]}#{gitLayout} #{rvmLayout}#{stdPrompt[:end]}"
62
+ print prompt
data/bin/rpromptconf ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+
5
+ todo = %Q(rprompt standard configuration has been created.
6
+
7
+ To make the magic happen:
8
+ 1/ edit your ~/.bashrc or ~/.bash_profile
9
+ (depending on your preferences and setup)
10
+ 2/ if you're setting PS1 already, comment it while you're using rprompt
11
+ 3/ paste the following lines between '---' at the end of the file
12
+
13
+ ---
14
+ # Setting terminal promt with rprompt gem
15
+ PROMPT_COMMAND="$PROMPT_COMMAND PS1=\\"\\$(rprompt)\\";"
16
+ ---
17
+
18
+ 4/ quit your terminal and re-open it for the change to take effect.
19
+
20
+ Edit $HOME/.rprompt/config.yml to change the configuration.
21
+ (you can always re-install the default configuration by issuing 'rpromptconf')
22
+
23
+ Enjoy :\))
24
+
25
+ src = File.expand_path(File.join(File.dirname(__FILE__), '..', 'files/config.yml'))
26
+ home = File.expand_path('~')
27
+ dest = File.join(home, '.rprompt')
28
+ begin
29
+ FileUtils.mkdir(dest) if !File.exists?(dest)
30
+ FileUtils.cp src, dest
31
+ puts todo
32
+ rescue => err
33
+ puts "Oops, something went wrong: " + err.message
34
+ end
data/files/config.yml ADDED
@@ -0,0 +1,63 @@
1
+ ##### Standard Prompt #####
2
+
3
+ :stdprompt:
4
+ # current working directory
5
+ :start: '\[\033[0;32m\]\w\[\033[0m\] '
6
+
7
+ # Military time
8
+ :end: '\n\A \$ '
9
+
10
+
11
+ ##### Git Prompt #####
12
+
13
+ :git:
14
+ :staged:
15
+ :cmd: git diff --staged --name-status
16
+ :symbol: ●
17
+ :color: red
18
+
19
+ :untracked:
20
+ :cmd: git ls-files --other --exclude-standard
21
+ :symbol: …
22
+
23
+ :modified:
24
+ :cmd: git diff --name-status
25
+ :symbol: ✚
26
+ :color: blue
27
+
28
+ :unmerged:
29
+ :cmd: git diff --name-status --diff-filter=U
30
+ :symbol: ✖
31
+ :color: yellow
32
+
33
+ :ahead:
34
+ :cmd: git branch -v
35
+ :symbol: ↑
36
+
37
+ :behind:
38
+ :cmd: git branch -v
39
+ :symbol: ↓
40
+
41
+ :sha:
42
+ :cmd: git rev-parse HEAD
43
+ :symbol: '#'
44
+ :color: yellow
45
+
46
+ :branch:
47
+ :cmd: git symbolic-ref HEAD
48
+ :color: magenta
49
+
50
+ :layout: (branchbehindahead|stagedmodifieduntrackedunmergedallgood) sha
51
+
52
+ :rvm:
53
+ :ruby:
54
+ :cmd: rvm-prompt
55
+ :color: red
56
+ :symbol: ∆
57
+
58
+ :gemset:
59
+ :cmd: rvm-prompt
60
+ :color: yellow
61
+ :symbol: ›
62
+
63
+ :layout: ruby gemset
@@ -0,0 +1,3 @@
1
+ module Rprompt
2
+ VERSION = "0.0.2"
3
+ end
data/lib/rprompt.rb ADDED
@@ -0,0 +1,151 @@
1
+ require "rprompt/version"
2
+
3
+ require "term/ansicolor"
4
+ # Usage as Mixin into String or its Subclasses
5
+ class String
6
+ include Term::ANSIColor
7
+ end
8
+
9
+ module Rprompt
10
+ class PromptItem
11
+
12
+ # @return [String] symbol character to identify prompt item
13
+ attr_reader :symbol, :color
14
+
15
+ # @param config [Hash] Prompt item configuration:
16
+ # - :cmd => shell command
17
+ # - :symbol => character
18
+ # - :color => color name
19
+ def initialize(config)
20
+ @cmd = config[:cmd]
21
+ @symbol = config[:symbol]
22
+ @color = config[:color]
23
+ end
24
+
25
+ # executes prompt item command
26
+ # @return [String] command result
27
+ def commandResult
28
+ %x(#{@cmd} 2> /dev/null)
29
+ end
30
+ end
31
+
32
+ class GitNumbers < PromptItem
33
+ # @return [Integer] number of files returned by a git command
34
+ def numberOfFiles
35
+ commandResult.split(/\r?\n/).count
36
+ end
37
+
38
+ # @return [String] terminal representation of the number of files
39
+ def show
40
+ if color
41
+ numberOfFiles != 0 ? "#{symbol}#{numberOfFiles}".send(color) : ""
42
+ else
43
+ numberOfFiles != 0 ? "#{symbol}#{numberOfFiles}" : ""
44
+ end
45
+ end
46
+ end
47
+
48
+ class GitBranch < PromptItem
49
+ # @return [String] branch name
50
+ def shortBranchName
51
+ commandResult.chomp.split('/').last
52
+ end
53
+
54
+ # @return [String] terminal representation of the branch name
55
+ def show
56
+ if color
57
+ "#{symbol}#{shortBranchName}".send(color)
58
+ else
59
+ "#{symbol}#{shortBranchName}"
60
+ end
61
+ end
62
+ end
63
+
64
+ class GitSha < PromptItem
65
+ # @return [String] last five numbers form the sha1
66
+ def sha
67
+ commandResult.chomp[-6,6]
68
+ end
69
+
70
+ # @return [String] terminal representation of the number returned by 'sha'
71
+ def show
72
+ if color
73
+ "#{symbol}#{sha}".send(color)
74
+ else
75
+ "#{symbol}#{sha}"
76
+ end
77
+ end
78
+ end
79
+
80
+ class GitTrack < PromptItem
81
+ # @param (see PromptItem#initialize)
82
+ # @param [Symbol] state ("ahead" or "behind")
83
+ def initialize(config, state)
84
+ @state = state
85
+ super(config)
86
+ end
87
+
88
+ # @return [Integer] number of commits ahead or behind remote
89
+ # @note works only if remote branch is tracked
90
+ def count
91
+ commandResult.match(/#{@state}\s+([0-9]+)/)
92
+ $1.to_i
93
+ end
94
+
95
+ # @return [String] terminal representation of the tracking
96
+ def show
97
+ if color
98
+ count != 0 ? "#{symbol}#{count}".send(color) : ""
99
+ else
100
+ count != 0 ? "#{symbol}#{count}" : ""
101
+ end
102
+ end
103
+ end
104
+
105
+ class RvmRuby < PromptItem
106
+ # @return [String] ruby used
107
+ def ruby
108
+ text = commandResult.chomp
109
+ if text.include?('@')
110
+ text.match(/ruby-(.+)@/)[1]
111
+ else
112
+ text.gsub!(/ruby-/, '')
113
+ end
114
+ end
115
+
116
+ # @return [String] terminal representation of the ruby version
117
+ def show
118
+ if color
119
+ "#{symbol}#{ruby}".send(color)
120
+ else
121
+ "#{symbol}#{ruby}"
122
+ end
123
+ end
124
+ end
125
+
126
+ class RvmGemset < PromptItem
127
+ # @return [String] gemset used
128
+ def gemset
129
+ text = commandResult.chomp
130
+ if text.include?('@')
131
+ text.match(/.+@(.+)/)[1]
132
+ else
133
+ ''
134
+ end
135
+ end
136
+
137
+ # @return [String] terminal representation of the gemset used
138
+ def show
139
+ if !gemset.empty?
140
+ if color
141
+ "#{symbol}#{gemset}".send(color)
142
+ else
143
+ "#{symbol}#{gemset}"
144
+ end
145
+ else
146
+ ''
147
+ end
148
+ end
149
+ end
150
+
151
+ end
data/rprompt.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rprompt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rprompt"
8
+ spec.version = Rprompt::VERSION
9
+ spec.authors = ["Olivier Robert"]
10
+ spec.email = ["robby57@gmail.com"]
11
+ spec.description = %q{Adds usefull information to your bash prompt, }
12
+ spec.summary = %q{rprompt}
13
+ spec.homepage = "https://github.com/olibob/rprompt.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "term-ansicolor"
25
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rprompt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Olivier Robert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: term-ansicolor
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! 'Adds usefull information to your bash prompt, '
63
+ email:
64
+ - robby57@gmail.com
65
+ executables:
66
+ - rprompt
67
+ - rpromptconf
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/rprompt
77
+ - bin/rpromptconf
78
+ - files/config.yml
79
+ - lib/rprompt.rb
80
+ - lib/rprompt/version.rb
81
+ - rprompt.gemspec
82
+ homepage: https://github.com/olibob/rprompt.git
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.25
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: rprompt
107
+ test_files: []
108
+ has_rdoc: