Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new features in module #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 89 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#colorprompt
# colorprompt

##Overview
## Overview

The colorprompt module. Colors your bash prompt.

##Module Description
## Module Description
The colorprompt module creates /etc/profile.d/colorprompt.sh, which sets a colored prompt. Different colors can be set for (all and specific) users, server name and environment tag.

##Usage
## Usage

All interaction with the colorprompt module can be done through the main colorprompt class.

###I just want a colored prompt, what's the minimum I need?
### I just want a colored prompt, what's the minimum I need?

```puppet
include 'colorprompt'
```

###I want a prompt for my production server with customised colors.
### I want a prompt for my production server with customised colors.

```puppet
class { 'colorprompt':
Expand All @@ -31,79 +31,131 @@ class { 'colorprompt':
}
```

###What does the example above look like?
### What does the example above look like?

![prompt](https://raw.githubusercontent.com/sgnl05/sgnl05-colorprompt/master/example.png)

###Great! What colors are available?

* black
* red
* green
* yellow
* blue
* magenta
* cyan
* white

A background color can also be defined by using `bg_(color)`. Foreground and background colors can be combined by using arrays instead of strings (see `env_color` in example above).

##Reference

###Classes

####Public Classes
### Great! What colors are available?

#### Default colors

* Foreground colors (`$::colorprompt::params::fg_colors`):
* black
* red
* green
* yellow
* blue
* magenta
* cyan
* white
* empty
* Background colors (`$::colorprompt::params::bg_colors`):
* bg_black
* bg_red
* bg_green
* bg_yellow
* bg_blue
* bg_magenta
* bg_cyan
* bg_white
* empty
* Styles (`$::colorprompt::params::styles`):
* bright
* faint
* underline
* blink
* empty

You can set your available settings in hashes.
A background color can also be defined by using bg_(color).Foreground and background colors can be combined by using arrays instead of strings (see env_color in example above).

## Reference

### Classes

#### Public Classes

* colorprompt: Main and only class.

###Parameters
### Parameters

####`ensure`
#### `ensure`

String. Ensure if file /etc/profile.d/colorprompt.sh is present or absent.
Defaults to present.

####`default_usercolor`
#### `default_usercolor`

String or array. Sets the color for all users. Specific user colors can be overrided by 'custom_usercolors'.
Defaults to 'cyan'.

####`custom_usercolors`
#### `custom_usercolors`

Hash. Sets the color for specific users. Example: custom_usercolors => { 'apache' => 'blue', 'tomcat' => 'yellow' }
Default is { 'root' => 'magenta' }

####`server_color`
#### `server_color`

String or array. Sets the color for the server name.
Defaults to unset.

####`env_name`
#### `pwd_color`

String or array. Sets the color for pwd.
Defaults to unset.

#### `env_name`

String: Names an environment tag. Examples: 'PROD', 'QA', 'TEST', 'DEV'.
Defaults to unset.

####`env_color`
#### `env_color`

String or array. Sets the color for of the environment tag.
Defaults to unset

####`prompt`
#### `git_prompt`

Boolean. Enable or disable [git_prompt](https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh "git_promt on github").
Default is false

#### `prompt`

String. Sets the final PS1 variable. This is an advanced setting, and should probably be left untouched unless you know what you're doing. :)
Default varies with osfamily.

####`modify_skel`
#### `modify_skel`

Boolean. Comments out PS1 variables in /etc/skel/.bashrc
Default varies with osfamily.

####`modify_root`
#### `modify_root`

Boolean. Comments out PS1 variables in /root/.bashrc
Default varies with osfamily

##Limitations
#### `bash_completion_package`
String. Package name bash-completion (install only if git_prompt equal true)
Defaults to 'bash-completion'

#### `git_package`
String. Package name git (install only if git_prompt equal true)
Defaults to 'git'

#### `fg_colors`
Hash. Hash of foreground colors.
Default: value of `$::colorprompt::params::fg_colors`.

#### `bg_colors`
Hash. Hash of background colors.
Default: value of `$::colorprompt::params::bg_colors.`

#### `styles`
Hash. Hash of styles.
Default: value of `$::colorprompt::params::styles`.


## Limitations

This module has been tested against Puppet 3.0 and higher.

Expand All @@ -117,6 +169,6 @@ Ubuntu and Debian need modification to existing user ~/.bashrc files (comment ou

## Development

###Contributing
### Contributing

Please use the issue tracker (https://github.com/sgnl05/sgnl05-colorprompt/issues) for any type of contribution.
50 changes: 50 additions & 0 deletions lib/puppet/parser/functions/validate_colors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# validate_colors.rb
#

module Puppet::Parser::Functions
newfunction(:validate_colors, :type => :rvalue, :doc => <<-EOS
This function validate colors for user console.
EOS
) do |arguments|

raise(Puppet::ParseError, "validate_colors(): Wrong number of arguments " +
"given (#{arguments.size} for 2)") if arguments.size < 2

colors = arguments[0]
error_message = arguments[1]

fg_colors_keys = lookupvar('::colorprompt::fg_colors').keys
bg_colors_keys = lookupvar('::colorprompt::bg_colors').keys
styles_keys = lookupvar('::colorprompt::styles').keys

case colors
when String
unless fg_colors_keys.include?(colors)
raise(Puppet::ParseError, "validate_colors(): #{error_message} '#{colors}' not found in array '#{fg_colors_keys}'!")
end
when Array
if colors.size == 0 or colors.size > 3
raise(Puppet::ParseError, 'validate_colors(): Size array of colors must be not equal 0 and more 3!')
else
unless fg_colors_keys.include?(colors[0])
raise(Puppet::ParseError, "validate_colors(): #{error_message} '#{colors[0]}' not found in array '#{fg_colors_keys}'!")
end
if colors[1]
unless bg_colors_keys.include?(colors[1])
raise(Puppet::ParseError, "validate_colors(): #{error_message} '#{colors[1]}' not found in array '#{bg_colors_keys}'!")
end
end
if colors[2]
unless styles_keys.include?(colors[2])
raise(Puppet::ParseError, "validate_colors(): #{error_message} '#{colors[2]}' not found in array '#{styles_keys}'!")
end
end
end
else
raise(Puppet::ParseError, 'validate_colors(): Requires array or string in first argumnet to work with!')
end
end
end

# vim: set ts=2 sw=2 et :
Loading