Skip to content

Commit 35e71f0

Browse files
committed
Add the ability to use concat for zshrc
This will add the ability to give a preconfigured ZSH for the user and allow the configuration of Powerline instant prompt as it need to be on top of the zshrc file This commit also include an example code for this case
1 parent 706a6f9 commit 35e71f0

16 files changed

+365
-118
lines changed

REFERENCE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@
1010

1111
### Defined types
1212

13+
#### Public Defined types
14+
1315
* [`ohmyzsh::fetch::theme`](#ohmyzshfetchtheme): Install a theme from a defined source
1416
* [`ohmyzsh::install`](#ohmyzshinstall): Install and configure Oh-My-ZSH for an user
1517
* [`ohmyzsh::plugins`](#ohmyzshplugins): Install and configure Oh-My-ZSH plugins for an user
1618
* [`ohmyzsh::profile`](#ohmyzshprofile): Configure the ZSH profile for an user
1719
* [`ohmyzsh::theme`](#ohmyzshtheme): Configure the ZSH theme for an user
1820

21+
#### Private Defined types
22+
23+
* `ohmyzsh::install::classic`: Manage the zsh file with the original mode (file copy from the repository)
24+
* `ohmyzsh::install::concat`: Manage the zsh file with concat
25+
1926
## Classes
2027

2128
### <a name="ohmyzsh"></a>`ohmyzsh`
@@ -39,6 +46,7 @@ The following parameters are available in the `ohmyzsh` class:
3946
* [`themes`](#themes)
4047
* [`plugins`](#plugins)
4148
* [`profiles`](#profiles)
49+
* [`concat`](#concat)
4250

4351
##### <a name="source"></a>`source`
4452

@@ -82,6 +90,12 @@ Data type: `Hash`
8290

8391
Configure the profile for users defined in this hash. See data/ for the default value.
8492

93+
##### <a name="concat"></a>`concat`
94+
95+
Data type: `Boolean`
96+
97+
Use the concat module to manage .zshrc files.
98+
8599
## Defined types
86100

87101
### <a name="ohmyzshfetchtheme"></a>`ohmyzsh::fetch::theme`

data/common.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ ohmyzsh::installs: {}
77
ohmyzsh::themes: {}
88
ohmyzsh::plugins: {}
99
ohmyzsh::profiles: {}
10+
ohmyzsh::concat: false
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class { 'ohmyzsh':
2+
concat => true,
3+
}
4+
5+
# for a single user
6+
ohmyzsh::install { 'root':
7+
set_sh => true,
8+
auto_update_mode => reminder,
9+
auto_update_frequency => 7,
10+
}
11+
12+
file { '/root/.zshrc.local':
13+
ensure => file,
14+
replace => 'no',
15+
owner => 'root',
16+
group => 'root',
17+
mode => '0644',
18+
content => "# Use this file to customize ZSH, it's not managed by Puppet",
19+
}
20+
21+
concat::fragment { '/root/.zshrc:puppet':
22+
target => '/root/.zshrc',
23+
content => "### Use the file ~/.zshrc.local for your changes\n",
24+
order => '000',
25+
}
26+
27+
concat::fragment { '/root/.zshrc:load-local':
28+
target => '/root/.zshrc',
29+
content => @("EOF"/L)
30+
# Load local zshrc if exist
31+
if [ -f ~/.zshrc.local ]
32+
then
33+
source ~/.zshrc.local
34+
fi
35+
| EOF
36+
,
37+
order => '099',
38+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class { 'ohmyzsh':
2+
concat => true,
3+
}
4+
5+
# for a single user
6+
ohmyzsh::install { 'root':
7+
set_sh => true,
8+
auto_update_mode => reminder,
9+
auto_update_frequency => 7,
10+
}
11+
12+
ohmyzsh::fetch::theme { 'root':
13+
filename => 'powerlevel10k',
14+
source => 'git',
15+
depth => 1,
16+
url => 'https://github.com/romkatv/powerlevel10k.git',
17+
}
18+
19+
ohmyzsh::theme { 'root':
20+
theme => 'powerlevel10k/powerlevel10k',
21+
}
22+
23+
ohmyzsh::plugins { 'root':
24+
plugins => ['git', 'github'],
25+
}
26+
27+
file { '/root/.p10k.zsh':
28+
owner => 'root',
29+
group => 'root',
30+
content => 'YOUR P10K CONFIGURATION FILE',
31+
}
32+
33+
concat::fragment { '/root/.zshrc:p10k-instant-prompt':
34+
target => '/root/.zshrc',
35+
content => 'YOUR P10K INSTANT PROMPT SNIPPET',
36+
order => '005',
37+
}
38+
39+
concat::fragment { '/root/.zshrc:p10k-load':
40+
target => '/root/.zshrc',
41+
content => "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh\n",
42+
order => '095',
43+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### This file is managed by Puppet, any changes will be lost
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Puppet Concat: zshrc-010-export.zsh-template
2+
# Path to your oh-my-zsh installation.
3+
export ZSH=$HOME/.oh-my-zsh
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Puppet Concat: zshrc-070-source.zsh-template
2+
source $ZSH/oh-my-zsh.sh

manifests/init.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# @param themes Configure the themes for users defined in this hash. See data/ for the default value.
1818
# @param plugins Configure the plugins for users defined in this hash. See data/ for the default value.
1919
# @param profiles Configure the profile for users defined in this hash. See data/ for the default value.
20+
# @param concat Use the concat module to manage .zshrc files.
2021
#
2122
#
2223
# @author Leon Brocard <[email protected]>
@@ -31,6 +32,7 @@
3132
Hash $themes,
3233
Hash $plugins,
3334
Hash $profiles,
35+
Boolean $concat,
3436
) {
3537
create_resources('ohmyzsh::install', $ohmyzsh::installs)
3638
create_resources('ohmyzsh::theme', $ohmyzsh::themes)

manifests/install.pp

Lines changed: 14 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
Integer[0] $auto_update_frequency = 14,
2626
) {
2727
include ohmyzsh
28-
$date_command = '$(date +\'%Y-%m-%dT%H:%M:%S%:z\')'
2928

3029
if !defined(Package['git']) {
3130
package { 'git':
@@ -76,105 +75,21 @@
7675
user => $name,
7776
require => Package['git'],
7877
}
79-
-> if $update_zshrc == sync {
80-
if $backup_zshrc {
81-
exec { "backup .zshrc ${name}":
82-
command => "cp ${home}/.zshrc ${home}/.zshrc.bak.${date_command}",
83-
path => ['/bin', '/usr/bin'],
84-
onlyif => "test -f ${home}/.zshrc",
85-
user => $name,
86-
before => [
87-
File_Line["ohmyzsh::auto_update_frequency - ${name}"],
88-
],
89-
subscribe => Vcsrepo["${home}/.oh-my-zsh"],
90-
refreshonly => true,
91-
}
92-
}
93-
-> exec { "ohmyzsh::cp .zshrc ${name}":
94-
command => "cp ${home}/.oh-my-zsh/templates/zshrc.zsh-template ${home}/.zshrc",
95-
path => ['/bin', '/usr/bin'],
96-
user => $name,
97-
before => [
98-
File_Line["ohmyzsh::auto_update_frequency - ${name}"],
99-
],
100-
subscribe => Vcsrepo["${home}/.oh-my-zsh"],
101-
refreshonly => true,
102-
}
103-
} elsif $update_zshrc == disabled {
104-
exec { "ohmyzsh::cp .zshrc ${name}":
105-
creates => "${home}/.zshrc",
106-
command => "cp ${home}/.oh-my-zsh/templates/zshrc.zsh-template ${home}/.zshrc",
107-
path => ['/bin', '/usr/bin'],
108-
onlyif => "getent passwd ${name} | cut -d : -f 6 | xargs test -e",
109-
user => $name,
110-
}
111-
} elsif $update_zshrc == always {
112-
if $backup_zshrc {
113-
exec { "backup .zshrc ${name}":
114-
command => "cp ${home}/.zshrc ${home}/.zshrc.bak.${date_command}",
115-
path => ['/bin', '/usr/bin'],
116-
onlyif => "test -f ${home}/.zshrc",
117-
user => $name,
118-
}
119-
}
120-
-> exec { "ohmyzsh::cp .zshrc ${name}":
121-
command => "cp ${home}/.oh-my-zsh/templates/zshrc.zsh-template ${home}/.zshrc",
122-
path => ['/bin', '/usr/bin'],
123-
user => $name,
124-
}
125-
}
126-
-> file_line { "ohmyzsh::auto_update_frequency - ${name}":
127-
path => "${home}/.zshrc",
128-
line => "zstyle ':omz:update' frequency ${auto_update_frequency}",
129-
match => '.*zstyle\ \':omz:update\'\ frequency .*',
130-
}
131-
-> if $auto_update_mode == disabled {
132-
file_line { "enable ohmyzsh::auto_update_mode disabled - ${name}":
133-
path => "${home}/.zshrc",
134-
line => "zstyle ':omz:update' mode disabled",
135-
match => '.*zstyle\ \':omz:update\'\ mode\ disabled.*',
78+
-> unless $ohmyzsh::concat {
79+
ohmyzsh::install::classic { $name:
80+
update_zshrc => $update_zshrc,
81+
backup_zshrc => $backup_zshrc,
82+
auto_update_mode => $auto_update_mode,
83+
auto_update_frequency => $auto_update_frequency,
84+
home => $home,
85+
group => $group,
13686
}
137-
file_line { "disable ohmyzsh::auto_update_mode auto - ${name}":
138-
path => "${home}/.zshrc",
139-
line => "# zstyle ':omz:update' mode auto",
140-
match => '.*zstyle\ \':omz:update\'\ mode\ auto.*',
141-
}
142-
file_line { "disable ohmyzsh::auto_update_mode reminder - ${name}":
143-
path => "${home}/.zshrc",
144-
line => "# zstyle ':omz:update' mode reminder",
145-
match => '.*zstyle\ \':omz:update\'\ mode\ reminder.*',
146-
}
147-
} elsif $auto_update_mode == auto {
148-
file_line { "enable ohmyzsh::auto_update_mode auto - ${name}":
149-
path => "${home}/.zshrc",
150-
line => "zstyle ':omz:update' mode auto",
151-
match => '.*zstyle\ \':omz:update\'\ mode\ auto.*',
152-
}
153-
file_line { "disable ohmyzsh::auto_update_mode disabled - ${name}":
154-
path => "${home}/.zshrc",
155-
line => "# zstyle ':omz:update' mode disabled",
156-
match => '.*zstyle\ \':omz:update\'\ mode\ disabled.*',
157-
}
158-
file_line { "disable ohmyzsh::auto_update_mode reminder - ${name}":
159-
path => "${home}/.zshrc",
160-
line => "# zstyle ':omz:update' mode reminder",
161-
match => '.*zstyle\ \':omz:update\'\ mode\ reminder.*',
162-
}
163-
} elsif $auto_update_mode == reminder {
164-
file_line { "enable ohmyzsh::auto_update_mode reminder - ${name}":
165-
path => "${home}/.zshrc",
166-
line => "zstyle ':omz:update' mode reminder",
167-
match => '.*zstyle\ \':omz:update\'\ mode\ reminder.*',
168-
}
169-
file_line { "disable ohmyzsh::auto_update_mode auto - ${name}":
170-
path => "${home}/.zshrc",
171-
line => "# zstyle ':omz:update' mode auto",
172-
match => '.*zstyle\ \':omz:update\'\ mode\ auto.*',
173-
}
174-
file_line { "disable ohmyzsh::auto_update_mode disabled - ${name}":
175-
path => "${home}/.zshrc",
176-
line => "# zstyle ':omz:update' mode disabled",
177-
match => '.*zstyle\ \':omz:update\'\ mode\ disabled.*',
87+
} else {
88+
ohmyzsh::install::concat { $name:
89+
auto_update_mode => $auto_update_mode,
90+
auto_update_frequency => $auto_update_frequency,
91+
home => $home,
92+
group => $group,
17893
}
17994
}
18095
# Fix permissions on '~/.oh-my-zsh/cache/completions'

0 commit comments

Comments
 (0)