nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Global tabgives and spacestotab config option


From: Peter Magnusson
Subject: Re: Global tabgives and spacestotab config option
Date: Fri, 18 Jun 2021 18:43:27 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0



On 09/06/2021 04:42, pepa65 wrote:
On 6/8/21 10:40 PM, Peter Magnusson wrote:
On 04/06/2021 12:06, pepa65 wrote:
#!/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

$ spc2tab.sh <anyfilename
bash: anyfilename: No such file or directory

It seems 'anyfilename' is not in your current directory, you have to give the absolute path or the path relative to your current directory.

Refering to something that Benno wrote I was hoping that it would start
nano and after save it would convert spaces 2 tab but now I realize that
it doesnt work like that. However it doesent seem to work:


$ spc2tab.sh <anyfilename
grep: ^[[:blank:]]*set[[:blank:]]+tabsize[[:blank:]]+[1-9][0-9]*: No such file or directory
/usr/local/bin/spc2tab.sh: line 10: :a;s@^\(*\)        @\1@;ta: command not found
$ cat anyfilename
this                               have               many        spaces
$ cat /usr/local/bin/spc2tab.sh
#!/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
$

I have a .nanorc that just says set tabsize 8 and nothing more.

/Peter


reply via email to

[Prev in Thread] Current Thread [Next in Thread]