|
From: | Peter Magnusson |
Subject: | Re: Global tabgives and spacestotab config option |
Date: | Tue, 8 Jun 2021 17:40:22 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 |
Not sure how the wrapperscript would fit into the workflow, but I came up with this:
#!/usr/bin/env bash
# spc2tab - Convert leading spaces into tabs
# Required: sed
# Usage: spc2tab <file
nanoconf=~/.nanorc s='[[:blank:]]'
tabsize=$(grep -eo "^$s*set$s+tabsize$s+[1-9][0-9]*" "$nanoconf" |tail -1 |grep -o '[0-9]*$')
# Use given tabsize or 8 as (nano) default
tabsize=${1:-8}
spc=$(printf '%*s' $tabsize) tab=$'\t'
sed ":a;s@^\($tab*\)$spc@\1$tab@;ta" </dev/stdin
[Prev in Thread] | Current Thread | [Next in Thread] |