Skip to content

Commit f6ef9a2

Browse files
author
David Cachau
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
1 parent 32062e4 commit f6ef9a2

File tree

11 files changed

+180
-35
lines changed

11 files changed

+180
-35
lines changed

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Puppet Concat: zshrc-010.zsh-template
2+
# If you come from bash you might have to change your $PATH.
3+
# export PATH=$HOME/bin:/usr/local/bin:$PATH
4+
5+
# Path to your oh-my-zsh installation.
6+
export ZSH=$HOME/.oh-my-zsh
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### Puppet Concat: zshrc-030.zsh-template
2+
# Set list of themes to pick from when loading at random
3+
# Setting this variable when ZSH_THEME=random will cause zsh to load
4+
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
5+
# If set to an empty array, this variable will have no effect.
6+
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
7+
8+
# Uncomment the following line to use case-sensitive completion.
9+
# CASE_SENSITIVE="true"
10+
11+
# Uncomment the following line to use hyphen-insensitive completion.
12+
# Case-sensitive completion must be off. _ and - will be interchangeable.
13+
# HYPHEN_INSENSITIVE="true"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
### Puppet Concat: zshrc-050.zsh-template
2+
# Uncomment the following line to change how often to auto-update (in days).
3+
# export UPDATE_ZSH_DAYS=13
4+
5+
# Uncomment the following line to disable colors in ls.
6+
# DISABLE_LS_COLORS="true"
7+
8+
# Uncomment the following line to disable auto-setting terminal title.
9+
# DISABLE_AUTO_TITLE="true"
10+
11+
# Uncomment the following line to enable command auto-correction.
12+
# ENABLE_CORRECTION="true"
13+
14+
# Uncomment the following line to display red dots whilst waiting for completion.
15+
# COMPLETION_WAITING_DOTS="true"
16+
17+
# Uncomment the following line if you want to disable marking untracked files
18+
# under VCS as dirty. This makes repository status check for large repositories
19+
# much, much faster.
20+
# DISABLE_UNTRACKED_FILES_DIRTY="true"
21+
22+
# Uncomment the following line if you want to change the command execution time
23+
# stamp shown in the history command output.
24+
# You can set one of the optional three formats:
25+
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
26+
# or set a custom format using the strftime function format specifications,
27+
# see 'man strftime' for details.
28+
# HIST_STAMPS="mm/dd/yyyy"
29+
30+
# Would you like to use another custom folder than $ZSH/custom?
31+
# ZSH_CUSTOM=/path/to/new-custom-folder
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Puppet Concat: zshrc-070.zsh-template
2+
source $ZSH/oh-my-zsh.sh

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Hash $themes,
1919
Hash $plugins,
2020
Hash $profiles,
21+
Boolean $concat,
2122
) {
2223
create_resources('ohmyzsh::install', $ohmyzsh::installs)
2324
create_resources('ohmyzsh::theme', $ohmyzsh::themes)

manifests/install.pp

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,75 @@
6262
require => Package['git'],
6363
}
6464

65-
if $override_template {
66-
file { "${home}/.zshrc":
65+
if !$ohmyzsh::concat {
66+
if $override_template {
67+
file { "${home}/.zshrc":
68+
ensure => file,
69+
replace => 'no',
70+
owner => $name,
71+
group => $group,
72+
mode => '0644',
73+
source => "puppet:///modules/${module_name}/zshrc.zsh-template",
74+
require => Vcsrepo["${home}/.oh-my-zsh"],
75+
}
76+
} else {
77+
exec { "ohmyzsh::cp .zshrc ${name}":
78+
creates => "${home}/.zshrc",
79+
command => "cp ${home}/.oh-my-zsh/templates/zshrc.zsh-template ${home}/.zshrc",
80+
path => ['/bin', '/usr/bin'],
81+
onlyif => "getent passwd ${name} | cut -d : -f 6 | xargs test -e",
82+
user => $name,
83+
require => Vcsrepo["${home}/.oh-my-zsh"],
84+
before => File_Line["ohmyzsh::disable_auto_update ${name}"],
85+
}
86+
}
87+
} else {
88+
file { "${home}/.zshrc.local":
6789
ensure => file,
6890
replace => 'no',
6991
owner => $name,
7092
group => $group,
7193
mode => '0644',
72-
source => "puppet:///modules/${module_name}/zshrc.zsh-template",
94+
source => "puppet:///modules/${module_name}/concat/zshrc.local",
7395
require => Vcsrepo["${home}/.oh-my-zsh"],
7496
}
75-
} else {
76-
exec { "ohmyzsh::cp .zshrc ${name}":
77-
creates => "${home}/.zshrc",
78-
command => "cp ${home}/.oh-my-zsh/templates/zshrc.zsh-template ${home}/.zshrc",
79-
path => ['/bin', '/usr/bin'],
80-
onlyif => "getent passwd ${name} | cut -d : -f 6 | xargs test -e",
81-
user => $name,
97+
98+
concat { "${home}/.zshrc":
99+
ensure => present,
100+
owner => $name,
101+
group => $group,
102+
mode => '0644',
82103
require => Vcsrepo["${home}/.oh-my-zsh"],
83-
before => File_Line["ohmyzsh::disable_auto_update ${name}"],
104+
}
105+
106+
concat::fragment { "${home}/.zshrc:puppet":
107+
target => "${home}/.zshrc",
108+
content => "### This file is managed by Puppet, any changes will be lost\n### Use the file ~/.zshrc.local for your changes\n",
109+
order => '000',
110+
}
111+
112+
concat::fragment { "${home}/.zshrc:template-010":
113+
target => "${home}/.zshrc",
114+
source => "puppet:///modules/${module_name}/concat/zshrc-010.zsh-template",
115+
order => '010',
116+
}
117+
118+
concat::fragment { "${home}/.zshrc:template-030":
119+
target => "${home}/.zshrc",
120+
source => "puppet:///modules/${module_name}/concat/zshrc-030.zsh-template",
121+
order => '030',
122+
}
123+
124+
concat::fragment { "${home}/.zshrc:template-050":
125+
target => "${home}/.zshrc",
126+
source => "puppet:///modules/${module_name}/concat/zshrc-050.zsh-template",
127+
order => '050',
128+
}
129+
130+
concat::fragment { "${home}/.zshrc:template-070":
131+
target => "${home}/.zshrc",
132+
source => "puppet:///modules/${module_name}/concat/zshrc-070.zsh-template",
133+
order => '070',
84134
}
85135
}
86136

@@ -100,11 +150,19 @@
100150
}
101151
}
102152

103-
file_line { "ohmyzsh::disable_auto_update ${name}":
104-
path => "${home}/.zshrc",
105-
line => "DISABLE_AUTO_UPDATE=\"${disable_auto_update}\"",
106-
match => '.*DISABLE_AUTO_UPDATE.*',
107-
after => '^plugins=',
153+
if !$ohmyzsh::concat {
154+
file_line { "ohmyzsh::disable_auto_update ${name}":
155+
path => "${home}/.zshrc",
156+
line => "DISABLE_AUTO_UPDATE=\"${disable_auto_update}\"",
157+
match => '.*DISABLE_AUTO_UPDATE.*',
158+
after => '^plugins=',
159+
}
160+
} else {
161+
concat::fragment { "${home}/.zshrc:DISABLE_AUTO_UPDATE":
162+
target => "${home}/.zshrc",
163+
content => "DISABLE_AUTO_UPDATE=\"${disable_auto_update}\"\n",
164+
order => '040',
165+
}
108166
}
109167

110168
# Fix permissions on '~/.oh-my-zsh/cache/completions'

manifests/plugins.pp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,19 @@
6565

6666
$plugins_real = join($all_plugins, ' ')
6767

68-
file_line { "${name}-${plugins_real}-install":
69-
path => "${home}/.zshrc",
70-
line => "plugins=(${plugins_real})",
71-
match => '^plugins=',
72-
require => Ohmyzsh::Install[$name],
68+
if !$ohmyzsh::concat {
69+
file_line { "${name}-${plugins_real}-install":
70+
path => "${home}/.zshrc",
71+
line => "plugins=(${plugins_real})",
72+
match => '^plugins=',
73+
require => Ohmyzsh::Install[$name],
74+
}
75+
} else {
76+
concat::fragment { "${home}/.zshrc:plugins":
77+
target => "${home}/.zshrc",
78+
content => "plugins=(${plugins_real})\n",
79+
order => '060',
80+
require => Ohmyzsh::Install[$name],
81+
}
7382
}
7483
}

manifests/profile.pp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,26 @@
3636
owner => $name,
3737
require => User[$name],
3838
}
39-
-> file_line { "${home}-profile":
40-
ensure => present,
41-
line => 'for f in ~/profile/*; do source "$f"; done',
42-
match => 'for f in ~/profile/*; do source "$f"; done',
43-
path => $shell_resource_path,
44-
require => [
45-
User[$name],
46-
Ohmyzsh::Install[$name],
47-
],
39+
40+
if !$ohmyzsh::concat {
41+
file_line { "${home}-profile":
42+
ensure => present,
43+
line => 'for f in ~/profile/*; do source "$f"; done',
44+
match => 'for f in ~/profile/*; do source "$f"; done',
45+
path => $shell_resource_path,
46+
require => [
47+
User[$name],
48+
Ohmyzsh::Install[$name],
49+
File["${home}/profile"],
50+
],
51+
}
52+
} else {
53+
concat::fragment { "${home}/.zshrc:profile":
54+
target => "${home}/.zshrc",
55+
content => "for f in ~/profile/*; do source \"\$f\"; done\n",
56+
order => '080',
57+
require => Ohmyzsh::Install[$name],
58+
}
4859
}
4960

5061
$scripts.each |$script_name, $script_path| {

manifests/theme.pp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@
3737
$group = $name
3838
}
3939

40-
file_line { "${name}-${theme}-install":
41-
path => "${home}/.zshrc",
42-
line => "ZSH_THEME=\"${theme}\"",
43-
match => '^ZSH_THEME',
44-
require => Ohmyzsh::Install[$name],
40+
if !$ohmyzsh::concat {
41+
file_line { "${name}-${theme}-install":
42+
path => "${home}/.zshrc",
43+
line => "ZSH_THEME=\"${theme}\"",
44+
match => '^ZSH_THEME',
45+
require => Ohmyzsh::Install[$name],
46+
}
47+
} else {
48+
concat::fragment { "${home}/.zshrc:ZSH_THEME":
49+
target => "${home}/.zshrc",
50+
content => "ZSH_THEME=\"${theme}\"\n",
51+
order => '020',
52+
require => Ohmyzsh::Install[$name],
53+
}
4554
}
4655
}

0 commit comments

Comments
 (0)