# HG changeset patch # User zegervdv # Date 1658820608 -7200 # Node ID d130c5c8b4e9669e00c8ce4b28c62de2e37ff599 # Parent 08bb1c92e5e5e2911b56186bf91409aef35fb5d3 improve indent trimming on copy diff -r 08bb1c92e5e5 -r d130c5c8b4e9 .chezmoitemplates/init.lua --- a/.chezmoitemplates/init.lua Sun Jul 24 14:48:01 2022 +0200 +++ b/.chezmoitemplates/init.lua Tue Jul 26 09:30:08 2022 +0200 @@ -32,9 +32,18 @@ require('osc52').setup { trim = false } local copy = function(lines, _) -- Trim indent before copying - local indent, _ = lines[1]:find '[^ ]' - for key, line in ipairs(lines) do - lines[key] = line:sub(indent) + local indent = 0 + for _, line in ipairs(lines) do + local index, _ = line:find '[^ ]' + if index ~= nil then + indent = index + break + end + end + if indent ~= nil then + for key, line in ipairs(lines) do + lines[key] = line:sub(indent) + end end require('osc52').copy(table.concat(lines, '\n')) end