promptula 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 promptula.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Overview
2
+ Here is a little gem that will give you a more informative shell prompt
3
+ as well as give you some ideas about how you can tweak your shell.
4
+
5
+ The prompt shows you a cool looking path, along with your current GiT
6
+ branch.
7
+
8
+ ![Clean Branch](https://raw.github.com/wballard/promptula/master/screenshot.png)
9
+
10
+ ...and is even nice enough to show you when you have a dirty branch,
11
+ along with a nice little ✳ for when there are untracked files that might
12
+ need to be added...
13
+
14
+ ![Dirty Branch](https://raw.github.com/wballard/promptula/master/screenshot_dirty.png)
15
+
16
+
17
+ # Usage
18
+ ~~~
19
+ gem install promptula
20
+ promptula --install
21
+ source ~/.bash_profile
22
+ ~~~
23
+
24
+ ...and that's it.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/TAGS ADDED
@@ -0,0 +1,6 @@
1
+ !_TAG_FILE_FORMAT 2 /extended format/
2
+ !_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted, 2=foldcase/
3
+ !_TAG_PROGRAM_AUTHOR Łukasz Korecki /lukasz@coffeesounds.com/
4
+ !_TAG_PROGRAM_NAME CoffeeTags //
5
+ !_TAG_PROGRAM_URL https://github.com/lukaszkorecki/CoffeeTags /GitHub repository/
6
+ !_TAG_PROGRAM_VERSION 0.0.2.6 //
data/bin/promptula ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # vim: filetype=ruby
3
+
4
+ require 'promptula'
5
+ require 'trollop'
6
+
7
+ opts = Trollop::options do
8
+ opt :install, "Install into your BASH"
9
+ end
10
+
11
+ install_with = <<jam
12
+ function _update_ps1()
13
+ {
14
+ export PS1="$(promptula)"
15
+ }
16
+
17
+ export PROMPT_COMMAND="_update_ps1"
18
+ jam
19
+
20
+ if opts[:install]
21
+ ['~/.bashrc', '~/.bash_profile'].each do |profile|
22
+ if File.exists? File.expand_path profile
23
+ open(File.expand_path(profile), 'a') do |f|
24
+ f.puts install_with
25
+ end
26
+ end
27
+ end
28
+ else
29
+ puts Promptula.prompt
30
+ end
31
+
data/lib/ansi_color.rb ADDED
@@ -0,0 +1,71 @@
1
+ require File.join(File.dirname(__FILE__), 'ansi_rgb')
2
+
3
+ module Sickill
4
+ module Rainbow
5
+
6
+ # Retrieve ANSI color code from a color name, an html color
7
+ # or an RGB color
8
+ class AnsiColor
9
+
10
+ # +ground+ is one of :foreground, :background
11
+ # +color+ is one of this 3 formats: name, html, rgb
12
+ def initialize(ground, *color)
13
+ @ground = ground
14
+
15
+ if color.size == 1
16
+ @color = color.first
17
+ else
18
+ @color = color
19
+ end
20
+ end
21
+
22
+ # Get the ANSI color code.
23
+ def code
24
+ case @color
25
+ when Symbol then code_from_name
26
+ when String then code_from_html
27
+ when Array then code_from_rgb
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def code_from_name #:nodoc:
34
+ validate_color_name
35
+
36
+ TERM_COLORS[@color] + (@ground == :foreground ? 30 : 40)
37
+ end
38
+
39
+ def code_from_html #:nodoc:
40
+ @color = @color.gsub("#", "")
41
+ AnsiRgb.new(@ground, rgb_from_html).code
42
+ end
43
+
44
+ def rgb_from_html #:nodoc:
45
+ red = @color[0..1].to_i(16)
46
+ green = @color[2..3].to_i(16)
47
+ blue = @color[4..5].to_i(16)
48
+ [red, green, blue]
49
+ end
50
+
51
+ def code_from_rgb #:nodoc:
52
+ unless @color.size == 3
53
+ raise ArgumentError.new \
54
+ "Bad number of arguments for RGB color definition, should be 3"
55
+ end
56
+
57
+ AnsiRgb.new(@ground, @color).code
58
+ end
59
+
60
+ def validate_color_name #:nodoc:
61
+ color_names = TERM_COLORS.keys
62
+
63
+ unless color_names.include?(@color)
64
+ raise ArgumentError.new \
65
+ "Unknown color name, valid names: #{color_names.join(', ')}"
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
data/lib/ansi_rgb.rb ADDED
@@ -0,0 +1,43 @@
1
+ module Sickill
2
+ module Rainbow
3
+
4
+ # Retrieve ANSI color code from RGB color.
5
+ class AnsiRgb
6
+
7
+ # +ground+ is one of :foreground, :background
8
+ # +rgb+ is an array of 3 values between 0 and 255.
9
+ def initialize(ground, rgb)
10
+ if RGB.outside_range?(rgb)
11
+ raise ArgumentError.new("RGB value outside 0-255 range")
12
+ end
13
+
14
+ @ground_code = { :foreground => 38, :background => 48 }[ground]
15
+ @red, @green, @blue = rgb[0], rgb[1], rgb[2]
16
+ end
17
+
18
+ # Get the ANSI color code for this RGB color.
19
+ def code
20
+ index = 16 +
21
+ RGB.to_ansi_domain(@red) * 36 +
22
+ RGB.to_ansi_domain(@green) * 6 +
23
+ RGB.to_ansi_domain(@blue)
24
+
25
+ "#{@ground_code};5;#{index}"
26
+ end
27
+
28
+ end
29
+
30
+ # Helper class for RGB color format.
31
+ class RGB
32
+ def self.outside_range?(rgb)
33
+ rgb.min < 0 or rgb.max > 255
34
+ end
35
+
36
+ # Change domain of color value from 0-255 to 0-5
37
+ def self.to_ansi_domain(value)
38
+ (6 * (value / 256.0)).to_i
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Promptula
2
+ VERSION = "0.0.2"
3
+ end
data/lib/promptula.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "promptula/version"
2
+ require "rainbow"
3
+ module Promptula
4
+ SEPARATOR = "\u25B6"
5
+ SEPARATOR_THIN = "\u276F"
6
+ PATH_SEPARATOR = '/'
7
+ BACKGROUND = "3a3a3a"
8
+ GLYPH = "\u2733"
9
+
10
+ def self.cwd()
11
+ current = Dir.pwd
12
+ home = ENV['HOME']
13
+ ret = ''
14
+ current.sub(home, '~').split('/').each do |segment|
15
+ ret += PATH_SEPARATOR.foreground(:black).background(BACKGROUND) if segment != '~'
16
+ ret += "#{segment}".background BACKGROUND
17
+ end
18
+ ret + ' '.background(BACKGROUND)
19
+ end
20
+
21
+ def self.git()
22
+ branch = ''
23
+ `git branch 2>/dev/null`.split("\n").each do |line|
24
+ if line[0] == '*'
25
+ branch = line.sub('*', '').chomp
26
+ end
27
+ end
28
+ status = `git status --porcelain 2>/dev/null`
29
+ untracked = (status.match('\?\?') or '').size > 0 ? " #{GLYPH}" : ''
30
+ dirty = status.size > 0
31
+ background = dirty ? :red : :green
32
+
33
+ SEPARATOR.foreground(background).background(BACKGROUND).inverse +
34
+ "#{branch}#{untracked} ".background(background) +
35
+ SEPARATOR.foreground(background).reset()
36
+ end
37
+
38
+ def self.prompt()
39
+ Sickill::Rainbow.enabled = true
40
+ cwd() + git()
41
+ end
42
+ end
data/lib/rainbow.rb ADDED
@@ -0,0 +1,108 @@
1
+ require 'rbconfig'
2
+ require File.join(File.dirname(__FILE__), 'ansi_color')
3
+
4
+ module Sickill
5
+ module Rainbow
6
+ class << self; attr_accessor :enabled; end
7
+ @enabled = STDOUT.tty? && ENV['TERM'] != 'dumb' || ENV['CLICOLOR_FORCE'] == '1'
8
+
9
+ TERM_COLORS = {
10
+ :black => 0,
11
+ :red => 1,
12
+ :green => 2,
13
+ :yellow => 3,
14
+ :blue => 4,
15
+ :magenta => 5,
16
+ :cyan => 6,
17
+ :white => 7,
18
+ :default => 9,
19
+ }
20
+
21
+ TERM_EFFECTS = {
22
+ :reset => 0,
23
+ :bright => 1,
24
+ :italic => 3,
25
+ :underline => 4,
26
+ :blink => 5,
27
+ :inverse => 7,
28
+ :hide => 8,
29
+ }
30
+
31
+ # Sets foreground color of this text.
32
+ def foreground(*color)
33
+ wrap_with_code(AnsiColor.new(:foreground, *color).code)
34
+ end
35
+ alias_method :color, :foreground
36
+ alias_method :colour, :foreground
37
+
38
+
39
+ # Sets background color of this text.
40
+ def background(*color)
41
+ wrap_with_code(AnsiColor.new(:background, *color).code)
42
+ end
43
+
44
+ # Resets terminal to default colors/backgrounds.
45
+ #
46
+ # It shouldn't be needed to use this method because all methods
47
+ # append terminal reset code to end of string.
48
+ def reset
49
+ wrap_with_code(TERM_EFFECTS[:reset])
50
+ end
51
+
52
+ # Turns on bright/bold for this text.
53
+ def bright
54
+ wrap_with_code(TERM_EFFECTS[:bright])
55
+ end
56
+
57
+ # Turns on italic style for this text (not well supported by terminal
58
+ # emulators).
59
+ def italic
60
+ wrap_with_code(TERM_EFFECTS[:italic])
61
+ end
62
+
63
+ # Turns on underline decoration for this text.
64
+ def underline
65
+ wrap_with_code(TERM_EFFECTS[:underline])
66
+ end
67
+
68
+ # Turns on blinking attribute for this text (not well supported by terminal
69
+ # emulators).
70
+ def blink
71
+ wrap_with_code(TERM_EFFECTS[:blink])
72
+ end
73
+
74
+ # Inverses current foreground/background colors.
75
+ def inverse
76
+ wrap_with_code(TERM_EFFECTS[:inverse])
77
+ end
78
+
79
+ # Hides this text (set its color to the same as background).
80
+ def hide
81
+ wrap_with_code(TERM_EFFECTS[:hide])
82
+ end
83
+
84
+ private
85
+
86
+ def wrap_with_code(code) #:nodoc:
87
+ return self unless Sickill::Rainbow.enabled
88
+
89
+ var = self.dup
90
+ matched = var.match(/^(\e\[([\d;]+)m)*/)
91
+ var.insert(matched.end(0), '\[\033[' + code.to_s + 'm\]')
92
+ var.concat('\[\033[0m\]')
93
+ var
94
+ end
95
+
96
+ end
97
+ end
98
+
99
+ String.send(:include, Sickill::Rainbow)
100
+
101
+ # On Windows systems, try to load the local ANSI support library
102
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
103
+ begin
104
+ require 'Win32/Console/ANSI'
105
+ rescue LoadError
106
+ Sickill::Rainbow.enabled = false
107
+ end
108
+ end
data/promptula.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/promptula/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Will Ballard"]
6
+ gem.email = ["wballard@mailframe.net"]
7
+ gem.description = 'Handy shell prompt extension for your BASH'
8
+ gem.summary = ''
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "promptula"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Promptula::VERSION
16
+
17
+ gem.add_dependency 'trollop'
18
+ gem.add_development_dependency 'bundler'
19
+ end
data/screenshot.png ADDED
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: promptula
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Will Ballard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: trollop
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
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
+ description: Handy shell prompt extension for your BASH
47
+ email:
48
+ - wballard@mailframe.net
49
+ executables:
50
+ - promptula
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - README.md
57
+ - Rakefile
58
+ - TAGS
59
+ - bin/promptula
60
+ - lib/ansi_color.rb
61
+ - lib/ansi_rgb.rb
62
+ - lib/promptula.rb
63
+ - lib/promptula/version.rb
64
+ - lib/rainbow.rb
65
+ - promptula.gemspec
66
+ - screenshot.png
67
+ - screenshot_dirty.png
68
+ homepage:
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.24
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: ''
92
+ test_files: []