dots


dots / config / .local / bin
xxwhirlpool  ·  2026-03-12

txttools

 1#!/usr/bin/env bash
 2
 3unwraptxt() {
 4	TXTFILE=$(mktemp --suffix .txt)
 5	TXTFILE_FIN="${TXTFILE%.*}_final.txt"
 6	gum write --header="paste wrapped text below" > "$TXTFILE"
 7	perl -00 -lpe 's/\n/ /g' < "$TXTFILE" > "$TXTFILE_FIN"
 8	batcat --paging=never "$TXTFILE_FIN"
 9	xclip -sel clip "$TXTFILE_FIN"
10	rm "$TXTFILE" "$TXTFILE_FIN"
11}
12
13wraptxt() {
14	WRTXTFILE=$(mktemp --suffix .txt)
15	WRTXTFILE_FIN="${WRTXTFILE%.*}_final.txt"
16	gum write --header="paste text below" > "$WRTXTFILE"
17	FOLDNUM=$(gum input --placeholder "number of characters to wrap to")
18	fold -w "$FOLDNUM" -s "$WRTXTFILE" > "$WRTXTFILE_FIN"
19	batcat --paging=never "$WRTXTFILE_FIN"
20	xclip -sel clip "$WRTXTFILE_FIN"
21	rm "$WRTXTFILE" "$WRTXTFILE_FIN"
22}
23
24wdcount() {
25	WCTXTFL=$(mktemp --suffix .txt)
26	gum write --header="paste text below" > "$WCTXTFL"
27	WCNUM=$(wc -w "$WCTXTFL" | awk '{print $1}')
28	echo -e "$(gum style --foreground=#f4b8e4 --border none 'total word count'): $WCNUM"
29	rm "$WCTXTFL"
30}
31
32choice() {
33	choose=$(gum choose "unwrap" "wrap" "wordcount")
34	case "$choose" in
35		*unwrap) unwraptxt ;;
36		*wrap) wraptxt ;;
37		*wordcount) wdcount ;;
38		*) exit 0;;
39	esac
40}
41
42choice