Schreq

u/Schreq


r/bash•

I was bored and because I've already done wordle in <20 lines of bash, I revisited it to do a proper golf. First time golfing, so would be happy to hear if you find improvements.

#!/bin/bash
set `grep -Eix '[a-z]{5}' /*/*/*/words|shuf`
s=${1,,}
for((r=6;r--;))
{
for((;;))
{
read -p$r g
grep -qw $g<<<$*&&break
}
t=$s
for((i=5;i--;))
{
[ ${s:i:1} = ${g:i:1} ]&&t=${t:0:i}2${t:i+1}
}
for((i=0;i<5;))
{
l=${g:i:1}
((c=${t:i++:1}))||{
[[ $t = *$l* ]]&&t=${t/$l/_} c=3
}
printf ^[[3$c\m$l^[[m
}
echo
[ $g = $s ]&&exit
}
echo $s
2115

r/suckless•

I came up with this script to lock all users X sessions. Maybe somebody has a use for it.

It uses flock(1) so that there is only one slock(1) running at a time (per X server). Otherwise a new slock(1) would be started, every time the lid is closed before unlocking.

#!/bin/sh
#
# Locks all running X sessions using slock(1).
#
# Problems:
#
# - stat(1) options are probably not portable
# - flock(1) is not portable
# - There might be sockets or files in /tmp/.X11-unix not used by any X
#   server
# - Possible race condition where not all displays are locked before
#   suspending
# - Sleeping for a second is a crude solution to the race condi
50

r/tasker•

Is that even possible? Having to unlock my phone first defeats the purpose for me: I'm trying to control my HiFi Receiver via Google assistant -> tasker -> termux. If I have to unlock first, I might as well use buttons.

12

r/plan9•

This is how I interact with reddit using Acme, powered by reddio. I'm not entirely sure if reddio will run under plan9, because of its cURL and jq dependencies. Apologies if this does not work on plan9.

Obligatory screenshot: https://x0.at/rC9h.png

Unlike rtv/tuir, reddio is a pure CLI utility for interacting with reddit, which makes it easy to integrate into Acme. I have a window named ~/lib/acme/+Errors. In its tag I added Edit ,<reddio p -l20 user/schreq/m/one/new, which is pretty much always selected for easy mouse button 2 clicking. The command replaces the current windows content with the last 20 posts of my multi reddit called "one". Multi r

253

r/plan9•

I've been using acme (on OpenBSD) for quite a few months now and absolutely love it. Editing text in a proportional font is just so much nicer. I was already used to not having syntax highlighting, so the transition was easy in that regard.

Inspired by this sam reference card, I'd like to share the "idioms" I use on a regular basis.

Square brackets added for easier selection:

  • [ Edit 1,$-1d ] - I have this in the tag of win to clear the "screen"
  • [ Edit ,<reddio p -l10 user/schreq/m/one/new ] - Load 10 newest posts of my multi reddit called "one"
  • [ Edit ,>awk "NF&&\$1!="#"{n++}END{print n}" ] - Count sloc excluding
174

r/bash•

A while ago I posted boilerplate for portable scripts but it's rather complex. This time I wanted to see how small and simple I can make option parsing in a portable manner, using getopts, and only including the bare minimum for a functional script, while trying to stay close to the POSIX utility conventions. That means no long-options, no detailed help output with descriptions for all options but just a simple usage line, etc.

To use this, we only have to adapt the couple variables at the top to our script. Options in the options variable are required to be space separated. Options requiring a parameter are marked wit

128

r/commandline•

A while ago I posted boilerplate for portable scripts but it's rather complex. This time I wanted to see how small and simple I can make option parsing in a portable manner, using getopts, and only including the bare minimum for a functional script, while trying to stay close to the POSIX utility conventions. That means no long-options, no detailed help output with descriptions for all options but just a simple usage line, etc.

To use this, we only have to adapt the couple variables at the top to our script. Options in the options variable are required to be space separated. Options requiring a parameter are marked wit

2411

r/awk•

Because I don't use fancy editors, I needed something to format comments in code. I need the indentation to be preserved and the comment character has to be attached to every wrapped line. When adding a word in the middle somewhere, reformatting the entire paragraph by hand was painful.

We can use GNU fmt(1) but the tool itself isn't portable and the more useful options are GNU specific. I needed something portable, so I decided to cook something up in AWK.

The tool is very specific to my usecase and only supports '#' as comment character. Making the character configurable is trivial but c-style 2 character comments are more common than '#' and that's a bit harder to implement, so I didn't

50