[-] gamma@programming.dev 2 points 1 year ago

Relevant except below, bolded is the key point.

-v prints non-printing characters in a visible representation. Making strange characters visible is a genuinely new function, for which no existing program is suitable. (sed -n l, the closest standard possibility, aborts when given very long input lines, which are more likely to occur in files containing non-printing characters.) So isn’t it appropriate to add the -v option to cat to make strange characters visible when a file is printed?

The answer is "No." Such a modification confuses what cat’s job is  concatenating files  with what it happens to do in a common special case  showing a file on the terminal. A UNIX program should do one thing well, and leave unrelated tasks to other programs. cat’s job is to collect the data in files. Programs that collect data shouldn’t change the data; cat therefore shouldn’t transform its input.

[-] gamma@programming.dev 1 points 2 years ago* (last edited 2 years ago)

Yeah, I'd write this as a single update script with options to update vimplugins or update pkg or update all.

I see that you want it to be a function so you can get the chdir as a side effect, but mixing that with updating doesn't make sense to me.

[-] gamma@programming.dev 1 points 2 years ago

More people should be like you.

[-] gamma@programming.dev 2 points 3 years ago* (last edited 3 years ago)

I look forward to the day that Synapse is deprecated in favor of Dendrite or Conduit.

[-] gamma@programming.dev 2 points 3 years ago
[-] gamma@programming.dev 1 points 3 years ago* (last edited 3 years ago)

Nice work! I would have done some things differently, but this is very readable.

Two recommendations for reading the file:

  • Use the (z) and (Q) flags so that instead of using tabs to separate the targets, simply quoting each argument works.
  • Instead of two independent lists, use an associative array with map[$link]=$target. Then you can check for duplicate links while reading the list.
linksfile=$1

typeset -gA linkmap

while read -r line
do
	# -- fields
	fields=(${(Q)${(z)line}})
	# -- link
	link=${(e)~fields[1]}
	# -- target
	target=${(e)~fields[2]}
	# -- check if we've already seen this link
	if (( $+linkmap[$link] )); then
		echo "'$link' targets both '$linkmap[$link]' and '$target', aborting"
		exit 1
	fi
	if [ -z "$target" ] || [ -z "$link" ]; then
		echo "Empty link or target provided, skipping"
		continue
	fi
	linkmap[$link]=$target
done < $linksfile

Then later, you can iterate over each key-value pair:

for link target in "${(@kv)linkmap}"; do
	...
done
[-] gamma@programming.dev 1 points 3 years ago

CorrectionsFirst, a look at man termcap:

       ch   Move cursor horizontally only to column %1
       ct   Clear tabs

(j::) actually joins with no seperator. The character following the j is used to capture the separator. Nearly any character or paired bracket can be used, but colons are common. Other ways to write this which might have been more obvious: (j''), (j[]), (j<>). To actually join with colons, something like (j.:.) would have been used.

Full contextZsh agressively sets tabstops to every 8 characters. This is in a function which I trap to the WINCH signal, to set the termstops to 4 using the $termcap sequences rather than the external command tput:

.on_winch(){
	# tabs
	local -a s
	repeat COLUMNS/$1 s+=(${termcap[RI]/\%p1\%d/$1}$termcap[st])

	# final
	print -rn $termcap[sc]${termcap[ch]//(\%i|\%p1|\%d)}$termcap[ct]${(j::)s}$termcap[rc]
}
.on_winch 4
trap '.on_winch 4' WINCH

[-] gamma@programming.dev 1 points 3 years ago

Corrections

ascending order

O is descending order. o is ascending order. In particular (Oa) keeps the array order, but flips it.

The @ symbol is used to indicate the array vriable argv.

Not here. As a PE flag, @ puts array elements in separate words, even if the parameter is enclosed in quotes.

The #MATCH gives the codepoint of the (first) character in $MATCH. The (#) flag turns codepoints into characters.

Full contextThis is in a joke function called ], which is like [ but you have to specify the elements in reverse order and end it with a [. This uses bit-fiddling to swap [ and ] in the last parameter because I'm a masochist.

[-] gamma@programming.dev 1 points 3 years ago

I do the same, but I include shebangs anyway out of habit.

[-] gamma@programming.dev 1 points 3 years ago

I'm on EndeavourOS, but my laptop will be moving to Fedora Sericea (Silverblue, but Sway) to try that out.

[-] gamma@programming.dev 2 points 3 years ago* (last edited 3 years ago)

pv, which is like cat, simply copying files or stdin to stdout, but prints statistics to the terminal.

A related tip: dd isn't special in the way most people use it. This works too, if you're root: pv my-fav-distro.iso > /dev/sdc

view more: ‹ prev next ›

gamma

0 post score
0 comment score
joined 3 years ago
MODERATOR OF