enhanced_prompt 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/Rakefile +6 -0
- data/bin/console.rb +9 -0
- data/bin/setup +7 -0
- data/enhanced_prompt.gemspec +27 -0
- data/exe/enhanced-prompt +43 -0
- data/lib/enhanced_prompt.rb +15 -0
- data/lib/enhanced_prompt/counter/countable.rb +7 -0
- data/lib/enhanced_prompt/counter/counter.rb +3 -0
- data/lib/enhanced_prompt/prompt.rb +54 -0
- data/lib/enhanced_prompt/string/string.rb +43 -0
- data/lib/enhanced_prompt/style/style.rb +10 -0
- data/lib/enhanced_prompt/token/dir.rb +66 -0
- data/lib/enhanced_prompt/token/emoji_writable.rb +5 -0
- data/lib/enhanced_prompt/token/git.rb +45 -0
- data/lib/enhanced_prompt/token/network.rb +51 -0
- data/lib/enhanced_prompt/token/system_resource.rb +6 -0
- data/lib/enhanced_prompt/token/time.rb +14 -0
- data/lib/enhanced_prompt/token/token.rb +136 -0
- data/lib/enhanced_prompt/token/user.rb +80 -0
- data/lib/enhanced_prompt/version.rb +3 -0
- data/sample1.png +0 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6beba89b42d5b6227d7bfcfa54148e3b8474c08f
|
4
|
+
data.tar.gz: fafcfb6f7610694a5756d5f0d0245e7d63b554e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b60c3889455d40fdf726eed42303f99ddded978ece9a9c7f34d77967fe908a9cf01663baec22efba544fc79e6fc8489780780813c1ae53cd60ccfffcc0fd16c
|
7
|
+
data.tar.gz: f46ad5de7998e70f29f4395c7d37cd753a363f9b00733f846aa6d0b43442a012a7885dad4524c45543d1ba80456e9080b7836ebe15c9a0370bb22185ab628962
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 sato
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# EnhancedPrompt
|
2
|
+
|
3
|
+
## Features
|
4
|
+
|
5
|
+
- Extremely flexible running as ruby internal DSL
|
6
|
+
- Helpful information including IP, git branch, nicely abbreviated path name
|
7
|
+
- Can change colors in simple syntax (thanks to Rainbow)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Currently, this gem is not registered to ruby-gem.org.
|
12
|
+
See Development to install this gem.
|
13
|
+
After that, set enhanced-prompt as your PROMPT_COMMAND.
|
14
|
+
|
15
|
+
```bash
|
16
|
+
cat << EOF > ~/.bashrc
|
17
|
+
export PROMPT_COMMAND='enhanced-prompt'
|
18
|
+
export PS1=''
|
19
|
+
EOF
|
20
|
+
```
|
21
|
+
|
22
|
+
## Customize
|
23
|
+
|
24
|
+
By default, you will see enhanced-prompt default style.
|
25
|
+
You can configure this with ~/.enhanced-prompt file.
|
26
|
+
|
27
|
+
For instance, if you create the following ~/.enhanced-prompt file.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
time1.c(:red).bg(:black) + ' ' + user.c(:blue) + '@' + host.c(:orange) +
|
31
|
+
'(' + ip.c(:purple) + ')' + ' ' + git.c(:indigo)._ + ' ' + dir + ' $ '
|
32
|
+
```
|
33
|
+
|
34
|
+
You will see something like this.
|
35
|
+
|
36
|
+

|
37
|
+
|
38
|
+
### Tokens
|
39
|
+
|
40
|
+
Run ```enhanced-prompt --tokens``` to check available tokens
|
41
|
+
|
42
|
+
### Color / Style
|
43
|
+
|
44
|
+
You can change foreground/background color or toggle underbar with the following methods
|
45
|
+
|
46
|
+
- c(color)
|
47
|
+
- bg(color)
|
48
|
+
- _
|
49
|
+
|
50
|
+
You can check available colors with ```enhanced-prompt --colors```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enhanced_shell_ps1. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
61
|
+
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
66
|
+
|
67
|
+
## Code Status
|
68
|
+
|
69
|
+
[](https://travis-ci.org/sato-s/EnhancedPrompt)
|
70
|
+
[](https://codeclimate.com/github/sato-s/EnhancedPrompt)
|
data/Rakefile
ADDED
data/bin/console.rb
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'enhanced_prompt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "enhanced_prompt"
|
8
|
+
spec.version = EnhancedPrompt::VERSION
|
9
|
+
spec.authors = ["sato-s"]
|
10
|
+
spec.email = ["s.sato.desu@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{You can use/customize cool prompt (PS1 in bash)}
|
13
|
+
spec.description = %q{DSL to write cool prompt.}
|
14
|
+
spec.homepage = "https://github.com/sato-s/EnhancedPrompt"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "rainbow", '~> 2.1'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 0"
|
27
|
+
end
|
data/exe/enhanced-prompt
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'enhanced_prompt'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
$options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: example.rb [options]"
|
9
|
+
|
10
|
+
opts.on("--debug", "debug") do
|
11
|
+
$options[:debug] = true
|
12
|
+
end
|
13
|
+
opts.on("--tokens", "show tokens") do
|
14
|
+
$options[:tokens] = true
|
15
|
+
end
|
16
|
+
opts.on("--colors", "show predefined colors") do
|
17
|
+
$options[:colors] = true
|
18
|
+
end
|
19
|
+
opts.on("-h","--help", "show help") do
|
20
|
+
$options[:help] = true
|
21
|
+
end
|
22
|
+
end.parse!
|
23
|
+
|
24
|
+
|
25
|
+
if $options[:tokens] then
|
26
|
+
EnhancedPrompt::Prompt.instance_methods(false).sort.each do |met|
|
27
|
+
name = met.to_s
|
28
|
+
print EnhancedPrompt.run("%Q|#{name}|.c(:red)+' => '+ #{met} + %|\n|" )
|
29
|
+
end
|
30
|
+
elsif $options[:colors] then
|
31
|
+
Rainbow::Color::X11Named.color_names.each{|color|
|
32
|
+
print EnhancedPrompt.run{":"+color.to_s+" => "+ " ".bg(color)+"\n"}
|
33
|
+
}
|
34
|
+
else
|
35
|
+
# Here we show PS1 prompt
|
36
|
+
file = File.join(ENV['HOME'],'/.enhanced-prompt')
|
37
|
+
if File.exists? file then
|
38
|
+
print EnhancedPrompt.run(File.open(file){|f| f.read})
|
39
|
+
else
|
40
|
+
print EnhancedPrompt.run('default')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "enhanced_prompt/version"
|
2
|
+
require 'enhanced_prompt/prompt'
|
3
|
+
|
4
|
+
module EnhancedPrompt
|
5
|
+
def run(str=nil,&code)
|
6
|
+
prompt=Prompt.new()
|
7
|
+
if block_given?
|
8
|
+
prompt.instance_eval(&code)
|
9
|
+
else
|
10
|
+
prompt.instance_eval(str)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
module_function :run
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative './string/string'
|
2
|
+
require_relative 'token/token'
|
3
|
+
require_relative 'token/git'
|
4
|
+
require_relative 'token/time'
|
5
|
+
require_relative './token/network'
|
6
|
+
require_relative './token/user'
|
7
|
+
require_relative './token/dir'
|
8
|
+
require_relative './token/system_resource'
|
9
|
+
require_relative './style/style'
|
10
|
+
|
11
|
+
require 'forwardable'
|
12
|
+
|
13
|
+
class EnhancedPrompt::Prompt
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
# Prompt class defines all user instruction commands
|
18
|
+
# Such as ip , ipv4 ...
|
19
|
+
# This must be exactly same name as instruction command name.
|
20
|
+
# Because we convert instruction command name into Prompt method directly
|
21
|
+
# make sure that EnhancedPrompt::Prompt.instance_methods(false) shows
|
22
|
+
# all instruction command name and no methods other than them.
|
23
|
+
class EnhancedPrompt::Prompt
|
24
|
+
extend ::Forwardable
|
25
|
+
include Style
|
26
|
+
|
27
|
+
# In this section, we just delegate to @base class as is
|
28
|
+
# In @base, I named methods to define their semantics
|
29
|
+
# this is good for developing but not always good for users.
|
30
|
+
# because it may too long. So in next section, def_delegator defines
|
31
|
+
# user friendly aliases
|
32
|
+
def_delegators :@token,
|
33
|
+
:ipv4,:ipv6,:global_ipv4,:global_ipv6,:hostname_full,:hostname,
|
34
|
+
:username,:groupname,:usernames,:other_user_names,
|
35
|
+
:other_user_names_if_exists, :users_count,
|
36
|
+
:other_users_count,:login_count,:my_login_count,:other_login_count,
|
37
|
+
:uid,:gid,
|
38
|
+
:dir_full, :dir_abbreviated1,
|
39
|
+
:time1,
|
40
|
+
:git
|
41
|
+
|
42
|
+
# User friendly aliases
|
43
|
+
def_delegator :@token, :dir_abbreviated1, :dir
|
44
|
+
def_delegator :@token, :ipv4, :ip
|
45
|
+
def_delegator :@token, :hostname_full, :host_full
|
46
|
+
def_delegator :@token, :hostname, :host
|
47
|
+
def_delegator :@token, :username, :user
|
48
|
+
def_delegator :@token, :groupname, :group
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@token =Token.new
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rainbow'
|
2
|
+
# This monkey patch to String, enable to paint string on ANSI terminal
|
3
|
+
# Thanks to Rainbow gem we can easily implement colorful string
|
4
|
+
# Just running 'red'.color(:red), red string appears on terminal
|
5
|
+
# See
|
6
|
+
# https://github.com/sickill/rainbow
|
7
|
+
#
|
8
|
+
# In addition to the above we implement several utilities and aliases
|
9
|
+
|
10
|
+
|
11
|
+
module EnhancedPrompt
|
12
|
+
module Ext
|
13
|
+
module InstanceMethods
|
14
|
+
|
15
|
+
|
16
|
+
def bg(value)
|
17
|
+
Rainbow(self).bg(value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def c(value)
|
21
|
+
Rainbow(self).color(value)
|
22
|
+
end
|
23
|
+
|
24
|
+
def blink
|
25
|
+
Rainbow(self).blink
|
26
|
+
end
|
27
|
+
|
28
|
+
def _
|
29
|
+
Rainbow(self).underline
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
alias_method :color, :c
|
34
|
+
alias_method :background, :bg
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Here we monkey patch String with above instance methods
|
41
|
+
class ::String
|
42
|
+
include EnhancedPrompt::Ext::InstanceMethods
|
43
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
class EnhancedPrompt::Prompt::Token
|
3
|
+
class Dir
|
4
|
+
# Customized Pathname
|
5
|
+
# Appended convenient methods for abbreviation
|
6
|
+
class ::Pathname
|
7
|
+
|
8
|
+
def length
|
9
|
+
#self.to_s.include?('/') ? self.to_s.size : self.to_s.count("^/")+1
|
10
|
+
self.to_s.size
|
11
|
+
end
|
12
|
+
|
13
|
+
def split_paths
|
14
|
+
# have to delete empty string to exclude first /
|
15
|
+
paths = self.to_s.split('/')
|
16
|
+
paths.delete('')
|
17
|
+
paths.map{|str| self.class.new(str)}
|
18
|
+
end
|
19
|
+
|
20
|
+
def first(n:1)
|
21
|
+
(length > n) ? self : self.class.new(self.to_s[0..n])
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class EnhancedPrompt::Prompt::Token
|
29
|
+
class Dir
|
30
|
+
def dir_full
|
31
|
+
_dir_full
|
32
|
+
end
|
33
|
+
|
34
|
+
# TODO
|
35
|
+
# cd /home/sato/work/serverspec_test/spec/nyaa
|
36
|
+
# corrupt this if limit =40
|
37
|
+
def dir_abbreviated1(limit=50)
|
38
|
+
dir = _base
|
39
|
+
if _dir_full.length >= limit then
|
40
|
+
_dir.split_paths.reverse.each do |path|
|
41
|
+
if dir.length + path.length <= limit
|
42
|
+
dir = path + dir
|
43
|
+
else
|
44
|
+
return Pathname.new('...')+dir
|
45
|
+
end
|
46
|
+
end
|
47
|
+
_dir_full
|
48
|
+
else
|
49
|
+
_dir_full
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def _dir
|
55
|
+
@_dir ||= _dir_full.split.first
|
56
|
+
end
|
57
|
+
|
58
|
+
def _base
|
59
|
+
@_base ||= _dir_full.basename
|
60
|
+
end
|
61
|
+
|
62
|
+
def _dir_full
|
63
|
+
@_dir_full ||= Pathname.new(::Dir.pwd)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'open3'
|
2
|
+
class EnhancedPrompt::Prompt
|
3
|
+
class Token::Git
|
4
|
+
|
5
|
+
def initialize(dir)
|
6
|
+
@dir = dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def git(prefix:'(',suffix:')')
|
10
|
+
_call_git_branch
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO this could not show git branch
|
14
|
+
# I should run %x|git branch| in Dir.pwd
|
15
|
+
private
|
16
|
+
|
17
|
+
def _call_git_branch
|
18
|
+
stdout,stderr,status = *Open3.capture3("cd #{@dir};git branch")
|
19
|
+
if stdout =~ /^[*]\s(\w+)/ && status.exitstatus == 0 then
|
20
|
+
@_current_branch = $1
|
21
|
+
else
|
22
|
+
''
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def _current_branch
|
27
|
+
if @_current_branch.nil? then
|
28
|
+
begin
|
29
|
+
result = %x|cd #{@dir};git branch|
|
30
|
+
if result =~ /^[*]\s(\w+)/ then
|
31
|
+
@_current_branch = $1
|
32
|
+
else
|
33
|
+
''
|
34
|
+
end
|
35
|
+
rescue =>e
|
36
|
+
return ''
|
37
|
+
end
|
38
|
+
else
|
39
|
+
@_current_branch
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class EnhancedPrompt::Prompt
|
4
|
+
class Token::Network
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
_ip_list
|
8
|
+
end
|
9
|
+
|
10
|
+
def hostname
|
11
|
+
@hostname ||= hostname_full.split('.')[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def hostname_full
|
15
|
+
@hostname ||= Socket.gethostname
|
16
|
+
end
|
17
|
+
|
18
|
+
def ipv4
|
19
|
+
@ipv4 ||= global_ipv4
|
20
|
+
@ipv4 ||= private_ipv4
|
21
|
+
end
|
22
|
+
|
23
|
+
def ipv6
|
24
|
+
@ipv6 ||= global_ipv6
|
25
|
+
@ipv6 ||= private_ipv6
|
26
|
+
end
|
27
|
+
|
28
|
+
def private_ipv4
|
29
|
+
@private_ipv4 ||= @_ip_list.detect{|ip| ip.ipv4_private? }
|
30
|
+
end
|
31
|
+
|
32
|
+
def private_ipv6
|
33
|
+
@private_ipv6 ||= @_ip_list.detect{|ip| !ip.ipv6_mc_global? && ip.ipv6?}
|
34
|
+
end
|
35
|
+
|
36
|
+
def global_ipv4
|
37
|
+
@global_ipv4 ||= @_ip_list.detect{|ip| !ip.ipv4_private? && ip.ipv4?}
|
38
|
+
end
|
39
|
+
|
40
|
+
def global_ipv6
|
41
|
+
@global_ipv6 ||= @_ip_list.detect{|ip| ip.ipv6_mc_global? && ip.ipv6? }
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def _ip_list
|
46
|
+
@_ip_list ||= Socket.ip_address_list.delete_if{|ip|ip.ipv6_loopback? || ip.ipv4_loopback? }
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require_relative './emoji_writable'
|
2
|
+
|
3
|
+
class EnhancedPrompt::Prompt
|
4
|
+
# Responsible for delegating instructions to proper instance.
|
5
|
+
# And convert into proper string after receiving Integer, AddrInfo or something else
|
6
|
+
class Token
|
7
|
+
include EmojiWritable
|
8
|
+
|
9
|
+
# Delegating to Network resource
|
10
|
+
def ipv4
|
11
|
+
_network.ipv4 ? _network.ipv4.inspect_sockaddr : ''
|
12
|
+
end
|
13
|
+
|
14
|
+
def ipv6
|
15
|
+
_network.ipv6 ? _network.ipv6.inspect_sockaddr : ''
|
16
|
+
end
|
17
|
+
|
18
|
+
def global_ipv4
|
19
|
+
_network.global_ipv4 ? _network.global_ipv4.inspect_sockaddr : ''
|
20
|
+
end
|
21
|
+
|
22
|
+
def global_ipv6
|
23
|
+
_network.global_ipv6 ? _network.global_ipv6.inspect_sockaddr : ''
|
24
|
+
end
|
25
|
+
|
26
|
+
def hostname_full
|
27
|
+
_network.hostname_full || ''
|
28
|
+
end
|
29
|
+
|
30
|
+
def hostname
|
31
|
+
_network.hostname || ''
|
32
|
+
end
|
33
|
+
|
34
|
+
# Delegating to User resource
|
35
|
+
def username
|
36
|
+
_user.username || ''
|
37
|
+
end
|
38
|
+
|
39
|
+
def groupname
|
40
|
+
_user.groupname || ''
|
41
|
+
end
|
42
|
+
|
43
|
+
def usernames
|
44
|
+
_user.usernames.join(',')
|
45
|
+
end
|
46
|
+
|
47
|
+
def other_user_names
|
48
|
+
_user.other_usernames.join(',')
|
49
|
+
end
|
50
|
+
|
51
|
+
def other_user_names_if_exists
|
52
|
+
_user.other_users_count == 0 ? '' : _user.other_usernames.join(',')
|
53
|
+
end
|
54
|
+
|
55
|
+
def users_count
|
56
|
+
_user.users_count.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
# TODO : should be method missing to ***_scale
|
60
|
+
def users_count_scale1
|
61
|
+
vertical_bar_scale(_user.users_count)
|
62
|
+
end
|
63
|
+
|
64
|
+
def other_users_count
|
65
|
+
_user.other_users_count.to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
def login_count
|
69
|
+
_user.login_count.to_s
|
70
|
+
end
|
71
|
+
|
72
|
+
def my_login_count
|
73
|
+
_user.my_login_count.to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
def other_login_count
|
77
|
+
_user.other_login_count.to_s
|
78
|
+
end
|
79
|
+
|
80
|
+
def uid
|
81
|
+
_user.uid.to_s || "No #{__method__}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def gid
|
85
|
+
_user.gid.to_s || "No #{__method__}"
|
86
|
+
end
|
87
|
+
|
88
|
+
# Delegating to Dir resources
|
89
|
+
def dir_abbreviated1(limit=40)
|
90
|
+
_dir.dir_abbreviated1(limit).to_s || ""
|
91
|
+
end
|
92
|
+
|
93
|
+
def dir_full
|
94
|
+
_dir.dir_full.to_s
|
95
|
+
end
|
96
|
+
|
97
|
+
def git
|
98
|
+
_git.git
|
99
|
+
end
|
100
|
+
|
101
|
+
# Delegating to Time resources
|
102
|
+
|
103
|
+
def time1
|
104
|
+
_time.time1.to_s
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
def _git
|
109
|
+
@_git ||= Git.new(_dir.dir_full)
|
110
|
+
end
|
111
|
+
|
112
|
+
def _network
|
113
|
+
@_network ||= Network.new
|
114
|
+
end
|
115
|
+
|
116
|
+
def _user
|
117
|
+
@_user ||= User.new
|
118
|
+
end
|
119
|
+
|
120
|
+
def _dir
|
121
|
+
@_dir ||= Dir.new
|
122
|
+
end
|
123
|
+
|
124
|
+
def _time
|
125
|
+
@_time ||= Time.new
|
126
|
+
end
|
127
|
+
|
128
|
+
def method_missing(name,*args)
|
129
|
+
puts "No such token. "
|
130
|
+
raise super
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'etc'
|
2
|
+
|
3
|
+
class EnhancedPrompt::Prompt
|
4
|
+
class Token::User
|
5
|
+
|
6
|
+
# Shows your username
|
7
|
+
def username
|
8
|
+
@username ||= ENV['USER'] || ENV['LOGNAME'] || Etc.getlogin
|
9
|
+
end
|
10
|
+
|
11
|
+
# Shows usernames currently in your system
|
12
|
+
def usernames
|
13
|
+
@user_names ||= _user_list.uniq
|
14
|
+
end
|
15
|
+
|
16
|
+
def other_usernames
|
17
|
+
@other_user_names ||= usernames - [username]
|
18
|
+
end
|
19
|
+
|
20
|
+
def users_count
|
21
|
+
@users_count ||= usernames.size
|
22
|
+
end
|
23
|
+
|
24
|
+
def other_users_count
|
25
|
+
@other_users_count ||= users_count - 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def login_count
|
29
|
+
@login_count ||= _user_list.size
|
30
|
+
end
|
31
|
+
|
32
|
+
def my_login_count
|
33
|
+
@my_login_count ||= _user_list.count{|user| user == username}
|
34
|
+
end
|
35
|
+
|
36
|
+
def other_login_count
|
37
|
+
@other_login_count ||= login_count - my_login_count
|
38
|
+
end
|
39
|
+
|
40
|
+
def groupname
|
41
|
+
@groupname = _group.name
|
42
|
+
end
|
43
|
+
|
44
|
+
def uid
|
45
|
+
@uid = _passwd.uid
|
46
|
+
end
|
47
|
+
|
48
|
+
def gid
|
49
|
+
@gid = _passwd.gid
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def _passwd
|
54
|
+
if @passwd.nil?
|
55
|
+
Etc.passwd{|g| @passwd = g if g.name == username}
|
56
|
+
@passwd
|
57
|
+
else
|
58
|
+
@passwd
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def _group
|
63
|
+
@group ||= Etc.getgrgid(gid)
|
64
|
+
end
|
65
|
+
|
66
|
+
def _users
|
67
|
+
_user_list.size
|
68
|
+
end
|
69
|
+
|
70
|
+
def _other_users
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
# TODO: need proper error handling
|
75
|
+
def _user_list
|
76
|
+
@user_list ||= %x|who|.lines.map{|line|line.split.first}
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/sample1.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enhanced_prompt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sato-s
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rainbow
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: DSL to write cool prompt.
|
70
|
+
email:
|
71
|
+
- s.sato.desu@gmail.com
|
72
|
+
executables:
|
73
|
+
- enhanced-prompt
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console.rb
|
86
|
+
- bin/setup
|
87
|
+
- enhanced_prompt.gemspec
|
88
|
+
- exe/enhanced-prompt
|
89
|
+
- lib/enhanced_prompt.rb
|
90
|
+
- lib/enhanced_prompt/counter/countable.rb
|
91
|
+
- lib/enhanced_prompt/counter/counter.rb
|
92
|
+
- lib/enhanced_prompt/prompt.rb
|
93
|
+
- lib/enhanced_prompt/string/string.rb
|
94
|
+
- lib/enhanced_prompt/style/style.rb
|
95
|
+
- lib/enhanced_prompt/token/dir.rb
|
96
|
+
- lib/enhanced_prompt/token/emoji_writable.rb
|
97
|
+
- lib/enhanced_prompt/token/git.rb
|
98
|
+
- lib/enhanced_prompt/token/network.rb
|
99
|
+
- lib/enhanced_prompt/token/system_resource.rb
|
100
|
+
- lib/enhanced_prompt/token/time.rb
|
101
|
+
- lib/enhanced_prompt/token/token.rb
|
102
|
+
- lib/enhanced_prompt/token/user.rb
|
103
|
+
- lib/enhanced_prompt/version.rb
|
104
|
+
- sample1.png
|
105
|
+
- tools/.gitignore
|
106
|
+
homepage: https://github.com/sato-s/EnhancedPrompt
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.5.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: You can use/customize cool prompt (PS1 in bash)
|
130
|
+
test_files: []
|
131
|
+
has_rdoc:
|