Skip to content

Commit 9b4012f

Browse files
authored
Merge pull request #162 from tamzinselvi/main
Migrate `themer-tmux` package into internal templates
2 parents bb86533 + 383d483 commit 9b4012f

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

cli/src/template/all.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import slack from './slack.js';
2121
import sublimeText from './sublime-text.js';
2222
import terminal from './terminal.js';
2323
import terminator from './terminator.js';
24+
import tmux from './tmux.js';
2425
import vimLightline from './vim-lightline.js';
2526
import vim from './vim.js';
2627
import visualStudio from './visual-studio.js';
@@ -62,6 +63,7 @@ const BUILT_IN_TEMPLATE_IDENTIFIERS = [
6263
'sublime-text',
6364
'terminal',
6465
'terminator',
66+
'tmux',
6567
'vim',
6668
'vim-lightline',
6769
'visual-studio',
@@ -134,6 +136,8 @@ export function resolveTemplate(
134136
return terminal;
135137
case 'terminator':
136138
return terminator;
139+
case 'tmux':
140+
return tmux;
137141
case 'vim':
138142
return vim;
139143
case 'vim-lightline':

cli/src/template/tmux.ts

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import type { Template } from './index.js';
2+
import { colorSetToVariants, FullVariant } from '../color-set/index.js';
3+
import { source } from 'common-tags';
4+
5+
type Layout = 'block' | 'default' | 'double';
6+
7+
const renderLayout = (
8+
layoutName: Layout,
9+
colorSet: FullVariant,
10+
index: number,
11+
) => {
12+
const layouts = {
13+
block: (colors: FullVariant, i: number) => source`
14+
# Powerline Themer Block - Tmux Theme
15+
set -g status-interval 1
16+
set -g status-fg "${colors.shade3}"
17+
set -g status-bg "${colors.shade1}"
18+
set -g status-left "#[fg=${colors.shade0},bg=${
19+
colors[`accent${i * 2}` as keyof FullVariant]
20+
},bold] #S #[fg=${colors[`accent${i * 2}` as keyof FullVariant]},bg=${
21+
colors.shade4
22+
},nobold]"
23+
set -g status-right "#[fg=${colors.shade2},bg=${colors.shade1}]#[fg=${
24+
colors.shade4
25+
},bg=${colors.shade2}] %H:%M:%S"
26+
`,
27+
default: (colors: FullVariant, i: number) => source`
28+
# Powerline Default - Tmux Theme
29+
set -g status-interval 1
30+
set -g status-fg "${colors.shade3}"
31+
set -g status-bg "${colors.shade1}"
32+
set -g status-left "#[fg=${colors.shade0},bg=${
33+
colors[`accent${i * 2}` as keyof FullVariant]
34+
},bold] #S #[fg=${colors[`accent${i * 2}` as keyof FullVariant]},bg=${
35+
colors.shade4
36+
},nobold]"
37+
set -g status-right "#[fg=${colors.shade2},bg=${colors.shade1}]#[fg=${
38+
colors.shade4
39+
},bg=${colors.shade2}] %H:%M:%S"
40+
`,
41+
double: (colors: FullVariant, i: number) => source`
42+
# Powerline Double - Tmux Theme
43+
set -g status-interval 1
44+
set -g status-fg "${colors.shade3}"
45+
set -g status-bg "${colors.shade1}"
46+
set -g status-left "#[fg=${colors.shade0},bg=${
47+
colors[`accent${i * 2}` as keyof FullVariant]
48+
},bold] #S #[fg=${colors[`accent${i * 2}` as keyof FullVariant]},bg=${
49+
colors.shade4
50+
},nobold]"
51+
set -g status-right "#[fg=${colors.shade2},bg=${colors.shade1}]#[fg=${
52+
colors.shade4
53+
},bg=${colors.shade2}] %H:%M:%S"
54+
`,
55+
};
56+
57+
return layouts[layoutName](colorSet, index);
58+
};
59+
60+
const template: Template = {
61+
name: 'tmux',
62+
render: async function* (colorSet) {
63+
const variants = colorSetToVariants(colorSet);
64+
for (const variant of variants) {
65+
const { colors, name } = variant;
66+
for (const layoutName of ['block', 'default', 'double'] as Layout[]) {
67+
for (let i = 0; i < Math.floor(Object.keys(colors).length / 4); i++) {
68+
yield {
69+
path: `themer-tmux.${name}.${layoutName}.v${i}.tmuxtheme`,
70+
content: renderLayout(layoutName, colors, i),
71+
};
72+
}
73+
}
74+
}
75+
},
76+
renderInstructions: (paths) => source`
77+
Generated tmux themes:
78+
79+
${paths.map((path) => ` - ${path}`).join('\n')}
80+
81+
Copy or symlink these files to your tmux configuration directory, and include them in your \`.tmux.conf\` like so:
82+
83+
\`\`\`
84+
source-file path/to/theme-file
85+
\`\`\`
86+
`,
87+
};
88+
89+
export default template;

0 commit comments

Comments
 (0)