rprompt 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ doc
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/README.md CHANGED
@@ -3,10 +3,12 @@
3
3
 
4
4
  Pimp your prompt :-)
5
5
 
6
- 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
+ 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).
7
7
 
8
8
  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.
9
9
 
10
+ ![an inline image](files/rprompt.png "rprompt in action")
11
+
10
12
  ## Usage
11
13
 
12
14
  The prompt is customizable via a yaml file that enables you to:
@@ -21,7 +23,26 @@ The prompt is customizable via a yaml file that enables you to:
21
23
 
22
24
  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!
23
25
 
24
- ### Git examples
26
+ ## Tips
27
+
28
+ A few recommandations to make your life easier ;)
29
+
30
+ * Install this gem in your **global** gemset. This way, rprompt will be available everywhere, whatever gemset you're using
31
+
32
+ * When upgrading save your config file and create a new one with ``rpromptconf`` (specially for minor and major releases)
33
+
34
+ * If you edit the config.yml file with vi and can not see the symbols characters correctly, try ``:set encoding=utf-8`` (you might want to put this in your ``.vimrc``)
35
+
36
+ * If you don't want a fancy symbol or color, but still want the option use ``:none``
37
+
38
+ :modified:
39
+ :none:
40
+
41
+ * The layout is just a string of option names (status , modified, staged ...) concatenated in the order you want them to appear, with or without white spaces, or what ever you characters you choose.
42
+
43
+ * Report bugs ;)
44
+
45
+ ## Git examples
25
46
 
26
47
  The prompt may look like the following:
27
48
 
@@ -43,37 +64,38 @@ The symbols are as follows:
43
64
  - ``↑n``: ahead of remote by ``n`` commits
44
65
  - ``↓n``: behind remote by ``n`` commits
45
66
 
46
- ### Rvm examples
67
+ ## Rvm examples
47
68
 
48
69
  * ∆1.9.3-p448: ruby version 1.9.3
49
70
  * ›global: using the global gemset
50
71
 
51
72
  ## Installation
52
73
 
53
- $ gem install rprompt
74
+ ``$ gem install rprompt``
54
75
 
55
76
  Once the gem is installed,
56
77
 
57
- $ rpromptconf
78
+ ``$ rpromptconf``
58
79
 
59
- This will provide a standard config file: ```$HOME/.rprompt/config.yml```
80
+ This will provide a standard config file: `$HOME/.rprompt/config.yml`
60
81
 
61
82
  To make the magic happen:
62
83
 
63
84
  * edit your ~/.bashrc or ~/.bash_profile
64
85
  (depending on your preferences and setup)
65
86
  * if you're setting PS1 already, comment it while you're using rprompt
66
- * paste the following lines between '---' at the end of the file
87
+ * paste the following line at the end of the file
88
+
89
+ ``PROMPT_COMMAND="PS1=\"\$(rprompt)\";"``
67
90
 
68
- Tested on MacOS 10.8.4
69
- ---
70
- # Setting terminal promt with rprompt gem
71
- PROMPT_COMMAND="PS1=\"\$(rprompt)\";"
72
- ---
73
91
 
74
92
  * quit your terminal and re-open it for the change to take effect.
75
93
 
76
94
  Edit $HOME/.rprompt/config.yml to change the configuration.
77
- (you can always re-install the default configuration by issuing 'rpromptconf')
95
+ (you can always re-install the default configuration by issuing ``rpromptconf``)
96
+
97
+ Enjoy :\)
98
+
99
+ ---
78
100
 
79
- Enjoy :\))
101
+ <sub>Tested on MacOS 10.8.4 and Fedora 19</sub>
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'yaml'
5
5
  require 'rprompt'
6
+ require 'pp'
6
7
 
7
8
  configFile = "#{File.expand_path('~')}/.rprompt/config.yml"
8
9
  begin
@@ -13,49 +14,105 @@ rescue => err
13
14
  exit
14
15
  end
15
16
 
17
+ if config.class == Hash
16
18
  stdPrompt = config[:stdprompt] if config.has_key?(:stdprompt)
17
19
  gitConfig = config[:git] if config.has_key?(:git)
18
20
  gitLayout = gitConfig[:layout] if gitConfig
19
21
  rvmConfig = config[:rvm] if config.has_key?(:rvm)
20
22
  rvmLayout = rvmConfig[:layout] if rvmConfig
23
+ else
24
+ puts "rprompt config seems to be empty?"
25
+ print '\u@\h $'
26
+ exit 1
27
+ end
28
+
29
+ if File.exist?(".git") && gitConfig && gitLayout
30
+ if gitConfig[:status]
31
+ status = Rprompt::GitNumbers.new(gitConfig[:status].merge({:cmd => "git status -s"}))
32
+ else
33
+ status = Rprompt::GitNumbers.new({:cmd => "git status -s"})
34
+ end
21
35
 
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
36
+ if status.numberOfFiles == 0
33
37
  gitLayout.gsub!(/staged|modified|untracked|unmerged/, '')
34
- gitLayout.gsub!(/allgood/, "✔".send(:green)) if gitLayout.include?("allgood")
38
+ gitLayout.gsub!(/status/, "✔".send(:green)) if gitLayout.include?("status")
39
+ else
40
+ if gitConfig[:staged]
41
+ staged = Rprompt::GitNumbers.new(gitConfig[:staged].merge({:cmd => "git diff --staged --name-status"}))
42
+ gitLayout.gsub!(/staged/, staged.show) if gitLayout.include?("staged")
43
+ else
44
+ gitLayout.gsub!(/staged/, '')
45
+ end
46
+
47
+ if gitConfig[:modified]
48
+ modified = Rprompt::GitNumbers.new(gitConfig[:modified].merge({:cmd => "git diff --name-status"}))
49
+ gitLayout.gsub!(/modified/, modified.show) if gitLayout.include?("modified")
50
+ else
51
+ gitLayout.gsub!(/modified/, '')
52
+ end
53
+
54
+ if gitConfig[:untracked]
55
+ untracked = Rprompt::GitNumbers.new(gitConfig[:untracked].merge({:cmd => "git ls-files --other --exclude-standard"}))
56
+ gitLayout.gsub!(/untracked/, untracked.show) if gitLayout.include?("untracked")
57
+ else
58
+ gitLayout.gsub!(/untracked/, '')
59
+ end
60
+
61
+ if gitConfig[:unmerged]
62
+ unmerged = Rprompt::GitNumbers.new(gitConfig[:unmerged].merge({:cmd => "git diff --name-status --diff-filter=U"}))
63
+ gitLayout.gsub!(/unmerged/, unmerged.show) if gitLayout.include?("unmerged")
64
+ else
65
+ gitLayout.gsub!(/unmerged/, '')
66
+ end
67
+
68
+ gitLayout.gsub!(/status/, "") if gitLayout.include?("status")
69
+ end
70
+
71
+ if gitConfig[:branch]
72
+ branch = Rprompt::GitBranch.new(gitConfig[:branch].merge({:cmd => "git symbolic-ref HEAD"}))
73
+ gitLayout.gsub!(/branch/, branch.show) if gitLayout.include?("branch")
35
74
  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")
75
+ gitLayout.gsub!(/branch/, '')
41
76
  end
42
77
 
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")
78
+ if gitConfig[:ahead]
79
+ ahead = Rprompt::GitTrack.new(gitConfig[:ahead].merge({:cmd => "git branch -v"}), "ahead")
80
+ gitLayout.gsub!(/ahead/, ahead.show) if gitLayout.include?("ahead")
81
+ else
82
+ gitLayout.gsub!(/ahead/, '')
83
+ end
84
+
85
+ if gitConfig[:behind]
86
+ behind = Rprompt::GitTrack.new(gitConfig[:behind].merge({:cmd => "git branch -v"}), "behind")
87
+ gitLayout.gsub!(/behind/, behind.show) if gitLayout.include?("behind")
88
+ else
89
+ gitLayout.gsub!(/behind/, '')
90
+ end
91
+ if gitConfig[:sha]
92
+ sha = Rprompt::GitSha.new(gitConfig[:sha].merge({:cmd => "git rev-parse HEAD"}))
93
+ gitLayout.gsub!(/sha/, sha.show) if gitLayout.include?("sha")
94
+ else
95
+ gitLayout.gsub!(/sha/, '')
96
+ end
47
97
  else
48
98
  gitLayout = ''
49
99
  end
50
100
 
51
101
  # RVM
52
102
 
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")
103
+ if rvmConfig && rvmLayout
104
+ if rvmConfig[:ruby]
105
+ ruby = Rprompt::RvmRuby.new(rvmConfig[:ruby].merge({:cmd => "rvm-prompt"}))
106
+ rvmLayout.gsub!(/ruby/, ruby.show) if rvmLayout.include?("ruby")
107
+ else
108
+ rvmLayout.gsub!(/ruby\s+/, '')
109
+ end
110
+ if rvmConfig[:gemset]
111
+ gemset = Rprompt::RvmGemset.new(rvmConfig[:gemset].merge({:cmd => "rvm-prompt"}))
112
+ rvmLayout.gsub!(/gemset/, gemset.show) if rvmLayout.include?("gemset")
113
+ else
114
+ rvmLayout.gsub!(/gemset/, '')
115
+ end
59
116
  end
60
117
 
61
118
  prompt = "#{stdPrompt[:start]}#{gitLayout} #{rvmLayout}#{stdPrompt[:end]}"
@@ -11,52 +11,46 @@
11
11
  ##### Git Prompt #####
12
12
 
13
13
  :git:
14
+ :status:
15
+ :color: green
16
+ :symbol: ✔
17
+
14
18
  :staged:
15
- :cmd: git diff --staged --name-status
16
19
  :symbol: ●
17
20
  :color: red
18
21
 
19
22
  :untracked:
20
- :cmd: git ls-files --other --exclude-standard
21
23
  :symbol: …
22
24
 
23
25
  :modified:
24
- :cmd: git diff --name-status
25
26
  :symbol: ✚
26
27
  :color: blue
27
28
 
28
29
  :unmerged:
29
- :cmd: git diff --name-status --diff-filter=U
30
30
  :symbol: ✖
31
31
  :color: yellow
32
32
 
33
33
  :ahead:
34
- :cmd: git branch -v
35
34
  :symbol: ↑
36
35
 
37
36
  :behind:
38
- :cmd: git branch -v
39
37
  :symbol: ↓
40
38
 
41
39
  :sha:
42
- :cmd: git rev-parse HEAD
43
40
  :symbol: '#'
44
41
  :color: yellow
45
42
 
46
43
  :branch:
47
- :cmd: git symbolic-ref HEAD
48
44
  :color: magenta
49
45
 
50
- :layout: (branchbehindahead|stagedmodifieduntrackedunmergedallgood) sha
46
+ :layout: (branchbehindahead|stagedmodifieduntrackedunmergedstatus) sha
51
47
 
52
48
  :rvm:
53
49
  :ruby:
54
- :cmd: rvm-prompt
55
50
  :color: red
56
51
  :symbol: ∆
57
52
 
58
53
  :gemset:
59
- :cmd: rvm-prompt
60
54
  :color: yellow
61
55
  :symbol: ›
62
56
 
Binary file
@@ -1,13 +1,10 @@
1
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
2
+ require "rprompt/deco"
3
+ require "rprompt/termcolor"
8
4
 
9
5
  module Rprompt
10
6
  class PromptItem
7
+ include Deco
11
8
 
12
9
  # @return [String] symbol character to identify prompt item
13
10
  attr_reader :symbol, :color
@@ -37,11 +34,7 @@ module Rprompt
37
34
 
38
35
  # @return [String] terminal representation of the number of files
39
36
  def show
40
- if color
41
- numberOfFiles != 0 ? "#{symbol}#{numberOfFiles}".send(color) : ""
42
- else
43
- numberOfFiles != 0 ? "#{symbol}#{numberOfFiles}" : ""
44
- end
37
+ numberOfFiles != 0 ? termShow({:color => color, :symbol => symbol, :content => numberOfFiles}) : ''
45
38
  end
46
39
  end
47
40
 
@@ -53,11 +46,7 @@ module Rprompt
53
46
 
54
47
  # @return [String] terminal representation of the branch name
55
48
  def show
56
- if color
57
- "#{symbol}#{shortBranchName}".send(color)
58
- else
59
- "#{symbol}#{shortBranchName}"
60
- end
49
+ termShow({:color => color, :symbol => symbol, :content => shortBranchName})
61
50
  end
62
51
  end
63
52
 
@@ -69,11 +58,7 @@ module Rprompt
69
58
 
70
59
  # @return [String] terminal representation of the number returned by 'sha'
71
60
  def show
72
- if color
73
- "#{symbol}#{sha}".send(color)
74
- else
75
- "#{symbol}#{sha}"
76
- end
61
+ termShow({:color => color, :symbol => symbol, :content => sha})
77
62
  end
78
63
  end
79
64
 
@@ -94,11 +79,7 @@ module Rprompt
94
79
 
95
80
  # @return [String] terminal representation of the tracking
96
81
  def show
97
- if color
98
- count != 0 ? "#{symbol}#{count}".send(color) : ""
99
- else
100
- count != 0 ? "#{symbol}#{count}" : ""
101
- end
82
+ count != 0 ? termShow({:color => color, :symbol => symbol, :content => count}) : ''
102
83
  end
103
84
  end
104
85
 
@@ -115,11 +96,7 @@ module Rprompt
115
96
 
116
97
  # @return [String] terminal representation of the ruby version
117
98
  def show
118
- if color
119
- "#{symbol}#{ruby}".send(color)
120
- else
121
- "#{symbol}#{ruby}"
122
- end
99
+ termShow({:color => color, :symbol => symbol, :content => ruby})
123
100
  end
124
101
  end
125
102
 
@@ -136,15 +113,7 @@ module Rprompt
136
113
 
137
114
  # @return [String] terminal representation of the gemset used
138
115
  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
116
+ !gemset.empty? ? termShow({:color => color, :symbol => symbol, :content => gemset}) : ''
148
117
  end
149
118
  end
150
119
 
@@ -0,0 +1,21 @@
1
+ module Deco
2
+ def termShow(args)
3
+ color = args[:color]
4
+ symbol = args[:symbol]
5
+ content = args[:content]
6
+
7
+ if color
8
+ if symbol
9
+ "#{symbol}#{content}".send(color)
10
+ else
11
+ "#{content}".send(color)
12
+ end
13
+ else
14
+ if symbol
15
+ "#{symbol}#{content}"
16
+ else
17
+ "#{content}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require "term/ansicolor"
2
+ # Usage as Mixin into String or its Subclasses
3
+ class String
4
+ include Term::ANSIColor
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Rprompt
2
- VERSION = "0.0.4"
3
- end
2
+ VERSION = "0.0.5"
3
+ end
@@ -2,13 +2,15 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'rprompt/version'
5
+ require 'rprompt/deco'
6
+ require 'rprompt/termcolor'
5
7
 
6
8
  Gem::Specification.new do |spec|
7
9
  spec.name = "rprompt"
8
10
  spec.version = Rprompt::VERSION
9
11
  spec.authors = ["Olivier Robert"]
10
12
  spec.email = ["robby57@gmail.com"]
11
- spec.description = %q{Adds usefull information to your bash prompt, }
13
+ spec.description = %q{Adds usefull information to your bash prompt}
12
14
  spec.summary = %q{rprompt}
13
15
  spec.homepage = "https://github.com/olibob/rprompt.git"
14
16
  spec.license = "MIT"