dot

packages and services management
Log | Files | Refs | README

commit 6e6c4d72e59c5ccea8e2ccccceda51e6e091a93f
parent 5c2ffe5d72055968bdd0c8122fc627439fc177fa
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Mon, 21 Aug 2017 20:08:27 +0200

shell/bin/txt: line-based parsing for better results

Diffstat:
Miomenu/bin/io-cache | 2+-
Miomenu/bin/io-search | 24++++++------------------
Mshell/bin/txt | 71++++++++++++++++++++++++++++++++++++-----------------------------------
Mvim/.vimrc | 3+--
4 files changed, 44 insertions(+), 56 deletions(-)

diff --git a/iomenu/bin/io-cache b/iomenu/bin/io-cache @@ -27,7 +27,7 @@ awk -v MAIL="${MAIL%/*}" ' musicv[musicc++] = $0 } - $0 ~ ".*[.][0-9]p?(.gz)?$" { + $0 ~ ".*/man/.*[.][0-9]p?(.gz)?$" { manv[manc++] = $0 } diff --git a/iomenu/bin/io-search b/iomenu/bin/io-search @@ -1,20 +1,8 @@ # interactively search a string in all code of a directory -output=$(find "$1" -type f ! -path '*/.git/*' | sort | xargs -n 1 awk ' - FNR == 1 { printf("# %s\n", FILENAME); } - { printf("%7s\t%s\n", FNR, $0); } -') - -number=. - -while [ "$number" ] -do - - IFS=' ' read -r path number content << EOF -$(printf '%s\n' "$output" | iomenu -s -h -p search) -EOF - [ "$path" ] || exit - path="${path#\# }" - - io "$path" -done +io "$( + find "$1" -type f ! -path '*/.git/*' | sort | xargs -n 1 awk ' + FNR == 1 { printf("# %s\n", FILENAME); } + { printf("%7s\t%s\n", FNR, $0); } + ' | iomenu -# -p search | sed -e 's/^# //' -e 's/ .*//' +)" diff --git a/shell/bin/txt b/shell/bin/txt @@ -1,44 +1,32 @@ -awk ' +awk -F '\0' ' -BEGIN { - RS="\n\n+" -} - - -# litterals +# blanks -/^---\n.*\n---$/ { - print "\n" $0 +/^[\t ]*$/ { next } -/^---\n/ { - block = "pre" -} - -/\n---$/ { - block = "" - print "\n" $0 - next -} +# litterals -block == "pre" { +/^---$/ { print "\n" $0 + while (getline && $0 != "---") + print $0 + print next } - # title -NR == 1 { - sub("\n-+", "", $0) +FNR == 1 { print for (i = 0; i < 80; i++) printf "-" print "" - next -} + if (getline && $0 ~ "^-+$" || $0 ~ "^[ \t]*$") + next +} # heading @@ -66,26 +54,39 @@ sub("^--- +", "", $0) { next } +# links + +/^[0-9]+: / { + print "" + do { + print + } while (getline && $0 ~ "^[0-9]+: ") + next +} + +# paragraph + { - # wrap lines + do { + block = block " " $0 + } while (getline && $0 !~ "^[ \t]*$") - sub("^[\t ]*", "", $0) - gsub("\n[\t ]*", " ", $0) - gsub(" +", " ", $0) - gsub("\\. ", ". ", $0) - gsub("\\? ", "? ", $0) - gsub("\\! ", "! ", $0) + sub("^[\t ]*", "", block) + gsub("[\t ]+", " ", block) + gsub("\\. ", ". ", block) + gsub("\\? ", "? ", block) + gsub("\\! ", "! ", block) width = 80 - margin[block] print "" - while (length($0) > 0) { - row = substr($0, 1, width) + while (length(block) > 0) { + row = substr(block, 1, width) if (length(row) >= width) sub(" [^ ]*$", "", row) - $0 = substr($0, length(row) + 1) - sub(" *", "") + block = substr(block, length(row) + 1) + sub(" *", "", block) print row } diff --git a/vim/.vimrc b/vim/.vimrc @@ -4,7 +4,6 @@ set listchars=tab:\|\ ,trail:%,extends:>,precedes:<,nbsp:_ set list set scrolloff=3 set colorcolumn=81,82,83,84,85,86,87,88,89,90 -set hlsearch set incsearch highlight colorcolumn ctermbg=0 ctermfg=1 @@ -12,4 +11,4 @@ highlight search ctermbg=3 ctermfg=0 nmap coh :set hlsearch!<cr>:set hlsearch?<cr> nmap col :set list !<cr>:set list ?<cr> -nmap col :set paste !<cr>:set paste ?<cr> +nmap cop :set paste !<cr>:set paste ?<cr>