Unefunge's Blotter

scribbling around

Subscribe to RSS feed

Posts tagged with "hack"

Marginal Hacks: Santas little helper

, , , ...

The bash(1) shell has some sadly underestimated features.
Most of shell users are aware of the existence of the so-called "here documents":
$ # create text file $ cat > file.txt <<! My username is $LOGNAME and my "home" directory is $HOME. The quick brown fox... ! $ #display the file content $ cat file.txt My name is unefunge and my "home" directory is /home/unefunge The quick brown fox... $
But did you know there's also "here string"?
$ # let's rot13 $ tr "a-z" "n-za-m" <<<"onfu ebpxf" bash rocks $
.. or, a bit more practical:
$ echo $HOME /export/home/homer $ BARTS_HOME=$(sed -e 's/homer/bart/' <<< "$HOME") $ echo $BARTS_HOME /export/home/bart

Marginal Hacks: Snobol4 (almost) on command line

, , , ...

As if just using Snobol4 wasn't scary enough:
$ cat spot
#! /bin/bash
snobol4 -b <(echo "$(basename $0) $@;end")
$ spot output = '":"' input '":"' :s\(spot\)
test
:test:
xyzzy
:xyzzy:
^D
$

Marginal Hacks: Terminal ruler (actually bash one-liner)

, , , ...

There are days your job description could be reduced to just "counting chars"...
function ruler() {
  for ((x=1;x<$COLUMNS;x++));do
    [[ $((x % 10)) -eq 0 ]]&&echo -n "|"||echo -n ".";
  done;echo
}
export PROMPT_COMMAND=ruler

Marginal Hacks: ASCII animation

, , , ...

Don't ask me why did I program it ;-)

#! /bin/bash
trap "clear" 0 3 9 15
put() { tput cup $1 $2; echo -n "$3"; }
set -a X Y DX DY SHAPE
set -i i q
W=$((COLUMNS-2))
H=$((LINES-2))
for d in . o o o o o o o o o o @ ; do
  q=$((q+1)); DX[q]=1; DY[q]=1; X[q]=$((q+4)); Y[q]=$((q+9)); SHAPE[q]="$d"
done
clear
while true ; do
  put ${Y[1]} ${X[1]} ' '
  for i in $(seq $q) ; do
    [ ${X} -gt $W -o ${X} -lt 1 ] && DX=-${DX}
[ ${Y
} -gt $H -o ${Y} -lt 1 ] && DY=-${DY}
X
=$((X+DX))
Y
=$((Y+DY))
put ${Y
} ${X} ${SHAPE}
done
tput cup 0 0
usleep 50000
done



Have fun