config_guide_04-host-specific.md.3be46361.js
1 import{_ as s,y as a,x as n,W as e}from"./plugin-vue_export-helper.f07d1dea.js";const k='{"title":"Host-specific Configuration","description":"","frontmatter":{},"headers":[{"level":2,"title":"Separator","slug":"separator"},{"level":2,"title":"Source Items","slug":"source-items"},{"level":3,"title":"base","slug":"base"},{"level":3,"title":"sources","slug":"sources"}],"relativePath":"config/guide/04-host-specific.md","lastUpdated":1692639959838}',t={},o=e(`<h1 id="host-specific-configuration" tabindex="-1">Host-specific Configuration <a class="header-anchor" href="#host-specific-configuration" aria-hidden="true">#</a></h1><p>When you want to maintain multiple configurations for different machines, you will have to deal with <a href="/features/01-host-specific.html">host-specific syncing</a>. This section describes how to use this feature of <code>dt-cli</code> properly.</p><h2 id="separator" tabindex="-1">Separator <a class="header-anchor" href="#separator" aria-hidden="true">#</a></h2><p>First, you have to define a <code>hostname_sep</code> in your config file (or not, the default value <code>@@</code> has a good chance at fitting your need), <a href="/config/key-references.html#hostname-sep">globally</a> or <a href="/config/key-references.html#hostname-sep-1">per-group</a>, for example, you want your hostname separator to be <code>QwQ</code> by default:</p><div class="language-toml"><pre><code><span class="token punctuation">[</span><span class="token table class-name">global</span><span class="token punctuation">]</span> 2 <span class="token key property">hostname_sep</span> <span class="token punctuation">=</span> <span class="token string">"QwQ"</span> 3 </code></pre></div><p>Or for a group only:</p><div class="language-toml"><pre><code><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token table class-name">local</span><span class="token punctuation">]</span><span class="token punctuation">]</span> 4 <span class="token key property">hostname_sep</span> <span class="token punctuation">=</span> <span class="token string">"QwQ"</span> 5 </code></pre></div><h2 id="source-items" tabindex="-1">Source Items <a class="header-anchor" href="#source-items" aria-hidden="true">#</a></h2><p>Knowing what your <code>hostname_sep</code> is, you can now specify your source items.</p><p><code>dt-cli</code> automatically deals with the logic for host-specific syncing, thus you <strong>should not</strong> contain a <a href="/features/01-host-specific.html#hostname-suffix">hostname suffix</a> when specifying your sources.</p><h3 id="base" tabindex="-1"><code>base</code> <a class="header-anchor" href="#base" aria-hidden="true">#</a></h3><p>For example, you want to sync some user-scope systemd services on your machines:</p><div class="language-toml"><pre><code><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token table class-name">local</span><span class="token punctuation">]</span><span class="token punctuation">]</span> 6 <span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"SystemD-services"</span> 7 <span class="token key property">base</span> <span class="token punctuation">=</span> <span class="token string">"~/dt/systemd/user"</span> 8 <span class="token key property">sources</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"*.service"</span><span class="token punctuation">]</span> 9 <span class="token key property">target</span> <span class="token punctuation">=</span> <span class="token string">"~/.config/systemd/user"</span> 10 11 <span class="token key property">hostname_sep</span> <span class="token punctuation">=</span> <span class="token string">"@@"</span> 12 </code></pre></div><p>Then, on one of your machines, whose hostname is <code>elbert</code>, for example, the above <code>base</code> will be automatically expanded to <code>~/dt/systemd/user@@elbert</code> first, if the expanded <code>base</code> exists, <code>dt-cli</code> will uses the expanded version; If the expanded <code>base</code> does not exist, <code>dt-cli</code> will sync the original <code>base</code> when it exists.</p><h3 id="sources" tabindex="-1"><code>sources</code> <a class="header-anchor" href="#sources" aria-hidden="true">#</a></h3><p>Another real-world example is when you are using the same terminal emulator on multiple machines, your workstation has a 8K ultra monitor, while your laptop at home only has a monitor sized 14 inches. You will not want to have the same font sizes on the two machines.</p><p>What you could do is to separately maintain two versions of config files for the terminal emulator. When your configs are maintained under the <code>~/dt</code> directory, and you are using Alacritty (for example):</p><div class="language-plain"><pre><code>~/dt/ 13 \u251C\u2500\u2500 alacritty/ 14 \u2502 \u251C\u2500\u2500 alacritty.yml@@laptop 15 \u2502 \u2514\u2500\u2500 alacritty.yml@@workstation 16 \u251C\u2500\u2500 nvim/ 17 \u2502 \u251C\u2500\u2500 init.vim 18 \u2502 \u2514\u2500\u2500 ... 19 \u2514\u2500\u2500 ... 20 </code></pre></div><p>You want to sync all stuff under the directory <code>~/dt</code> to <code>~/.config</code>, you can populate your config files safely with:</p><div class="language-toml"><pre><code><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token table class-name">local</span><span class="token punctuation">]</span><span class="token punctuation">]</span> 21 <span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"All-my-configs-including-for-terminal-emulator"</span> 22 <span class="token key property">base</span> <span class="token punctuation">=</span> <span class="token string">"~/dt"</span> 23 <span class="token key property">sources</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span> 24 <span class="token string">"*"</span><span class="token punctuation">,</span> 25 <span class="token string">".[!.]*"</span><span class="token punctuation">,</span> 26 <span class="token string">"..?*"</span><span class="token punctuation">,</span> 27 <span class="token punctuation">]</span> 28 <span class="token key property">target</span> <span class="token punctuation">=</span> <span class="token string">"~/.config"</span> 29 </code></pre></div><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p><code>dt-cli</code> will panic (<strong>not a bug</strong>) if you use globbing patterns like <code>.*</code> or <code>/path/to/something/.*</code>, because <code>.*</code> also expands to the parent directory, which is almost never what you want.</p><p>The globbing patterns in the above <code>sources</code> array is the recommended way to glob all items under a given <code>base</code>.</p></div><p>Note that we did not specifically reference the <code>alacritty</code> directory anywhere in the above config, because <code>dt-cli</code> will recursively expand directories <strong>and automatically handle host-specific items in the expanded paths</strong>. You can also specify a source only, like below:</p><div class="language-toml"><pre><code><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token table class-name">local</span><span class="token punctuation">]</span><span class="token punctuation">]</span> 30 <span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"Alacritty"</span> 31 <span class="token key property">base</span> <span class="token punctuation">=</span> <span class="token string">"~/.dt/alacritty"</span> 32 <span class="token key property">sources</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"alacritty.yml"</span><span class="token punctuation">]</span> 33 <span class="token key property">target</span> <span class="token punctuation">=</span> <span class="token string">"~/.config/alacritty"</span> 34 </code></pre></div><div class="warning custom-block"><p class="custom-block-title">WARNING</p><p>Do <strong>NOT</strong> include the host-specific part in the <code>sources</code> array (like <code>alacritty.yml@@laptop</code> or <code>alacritty.yml@@workstation</code>), see the <a href="/config/guide/99-error-handling.html#config-validating">Error Handling</a> section for more details on this.</p></div>`,24),c=[o];function p(i,l,r,u,d,h){return n(),a("div",null,c)}var g=s(t,[["render",p]]);export{k as __pageData,g as default};