-- Leo's gemini proxy

-- Connecting to gmi.osiux.com:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;lang=es_AR

alinear textos en columnas


AUTHOR: Osiris Alejandro Gomez

EMAIL: osiux@osiux.com

DATE: 2021-04-05 23:11


[IMG]

[1]


tengo mis *TOCs*


Soy *fan* del *texto plano*, en gran parte por su simpleza, pero también por el monoespaciado y esto me genera algunos *TOCs*, el principal puede ser intentar alinear o *"encolumnar"* cada vez que puedo todo texto `:P`


*footnotes* desordenadas


En mi *blog* hace tiempo que en lugar de utilizar *links* en línea, uso *footnotes* o *notas al pie de página* por varios motivos, en principio a medida que las voy definiendo no necesito la *URL* definitiva, solo un texto que me permita identificarlas y al final del texto puedo definir el *link* de cada *footnote*, pero sucede que casi siempre me quedan desalineadas!


Veamos un ejemplo:


grep -h '^\[fn:' 2014-08-12-clonar-pendrives.gmi

[fn:openwrt] http://openwrt.gmi
[fn:mr3020] http://www.tp-link.com/en/products/details/?model=TL-MR3020
[fn:lviajeras] https://github.com/gcoop-libre/letras_viajeras
[fn:clonezilla] http://www.clonezilla.gmi/
[fn:ddtee] https://superuser.com/questions/145516/cloning-single-disk-drive-to-multiple-drives-simultaneously
[fn:eta] https://es.wikipedia.gmi/wiki/Tiempo_estimado_de_llegada
[fn:pssh] https://code.google.com/p/parallel-ssh/
[fn:autoconfig] https://github.com/gcoop-libre/letras_viajeras/blob/master/config_ap/root/autoconfig.sh
[fn:deploy] https://github.com/gcoop-libre/letras_viajeras/blob/master/config_ap/root/deploy.sh
[fn:nginx] http://nginx.gmi

`align2col`


Si bien para alinear, justificar y hasta jugar con párrafos utilizo el comando `par` ^1[2], tenía ganas de resolver el problema con un *script* `bash` que fue muy fácil de generar:


#!/bin/bash

# This script comes with ABSOLUTELY NO WARRANTY, use at own risk
# Copyright (C) 2021 Osiris Alejandro Gomez <osiux@osiux.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.gmi/licenses/>.

if [[ ! -t 0 ]]
then
  TMPI="$(mktemp)"

  true > "$TMPI"

  while IFS= read -r PIPED_INPUT
  do
    echo "$PIPED_INPUT" >> "$TMPI"
  done

fi

[[ ! -z "$1"    ]] && TMPI="$1"
[[ ! -e "$TMPI" ]] && exit 1

TOTA="$(awk '{print $1}' "$TMPI" | wc -L)"
TOTB="$(awk '{print $2}' "$TMPI" | wc -L)"
TOTC="$(awk '{print $3}' "$TMPI" | wc -L)"
TOTD="$(awk '{print $4}' "$TMPI" | wc -L)"
COLA=$((TOTA+1))
COLB=$((TOTB+1))
COLC=$((TOTC+1))
COLD=$((TOTD+1))

while read -r A B C D
do
  printf "%-*s %-*s %-*s %-*s\\n" \
         "$COLA" "$A"             \
         "$COLB" "$B"             \
         "$COLC" "$C"             \
         "$COLD" "$D"
done < "$TMPI"

alinear *footnotes* en 2 columnas


Básicamente `align2col` obtiene máximo de caracteres de la 1er columna y se ocupa de alinear completando con espacios en blanco, esto facilita la lectura y pone un poco orden al caos reinante! `:)`


grep -h '^\[fn:' 2014-08-12-clonar-pendrives.gmi | align2col

[fn:openwrt]     http://openwrt.gmi
[fn:mr3020]      http://www.tp-link.com/en/products/details/?model=TL-MR3020
[fn:lviajeras]   https://github.com/gcoop-libre/letras_viajeras
[fn:clonezilla]  http://www.clonezilla.gmi/
[fn:ddtee]       https://superuser.com/questions/145516/cloning-single-disk-drive-to-multiple-drives-simultaneously
[fn:eta]         https://es.wikipedia.gmi/wiki/Tiempo_estimado_de_llegada
[fn:pssh]        https://code.google.com/p/parallel-ssh/
[fn:autoconfig]  https://github.com/gcoop-libre/letras_viajeras/blob/master/config_ap/root/autoconfig.sh
[fn:deploy]      https://github.com/gcoop-libre/letras_viajeras/blob/master/config_ap/root/deploy.sh
[fn:nginx]       http://nginx.gmi

alinear desde `vim`


En `vim` es posible seleccionar un rango de líneas presionando `shift + v`, seleccionando las líneas mediante `j` o `k` para luego pasarlas como `stdin` a un comando externo escribiendo `!align2col` (en este caso) y obtendremos el resultado dentro del editor sin salir de él.


alinear más columnas!


De momento el *script* soporta hasta 4 columnas, pero eso lo voy a mejorar en algún momento, por ejemplo:


acijado balazo cesarino despuesto
adulterio balume copista diserta
auspiciar brasilada canillero deportoso
ambular blondo caceo duc
algadara bisabuela cargar debelador

El resultado es mucho mas legible:


acijado    balazo     cesarino   despuesto
adulterio  balume     copista    diserta
auspiciar  brasilada  canillero  deportoso
ambular    blondo     caceo      duc
algadara   bisabuela  cargar     debelador

Seguro hay mil maneras de hacer esto, pero es muy gratificante poder idear y resolver un problema con tus propias líneas de código!


ChangeLog


`2022-11-13 20:39`[3] agregar y actualizar tags OpenGraph

`2021-04-05 23:13`[4] agregar *alinear textos en columnas*


1: file:img/align2col.png

2: https://osiux.com/2011-03-15-dibujando-con-numeros-desde-la-consola.html

3: https://gitlab.com/osiux/osiux.gitlab.io/-/commit/bf3a61526ad2a73cecb77a18995f1d63494e3664

4: https://gitlab.com/osiux/osiux.gitlab.io/-/commit/1b4792fa18d5e254b83578f1df850b39d2efdbe6

-- Response ended

-- Page fetched on Fri May 17 06:29:32 2024