Two of my OSS projects are Bash and I'm rather proud of them:
A pretty cool shell-centric template engine: * https://github.com/TekWizely/bash-tpl * Has full bats tests to confirm compatibility with Bash 3.2 onward * Makes heavy use of Bash regexes
A wrapper over update-alternatives that enables user-level configurations: * https://github.com/TekWizely/my-alternatives * Versions for Debian, SUSE, and RedHat * Supports per-shell level configurations as well
### long prompt (in color) only when 'user or hostname or path' changes, or after certain commands
prompt_command ()
{
local -a a;
local last_cmd;
IFS=' ' read -r -d '' -a a < <( history 1 );
last_cmd="$(printf "%s" "${a[1]}"|xargs -0)";
if [ "$USER_HOSTNAME_PWD" != "$USER@$HOSTNAME:$PWD" ] || [[ " cd src doc ssh sudo su login $(sed -e '/^#.*$/d' -e '/^$/d' -e 's@^.*/@@' /etc/shells|uniq|xargs) " == *" ${last_cmd} "* ]]; then
USER_HOSTNAME_PWD="$USER@$HOSTNAME:$PWD";
echo -e "\\e7\\e(B\\e[m- \\e[3$((($(id -u) != 0) + 1))m${USER}\\e(B\\e[m@\\e[35m${HOSTNAME%%.*}\\e(B\\e[m:\\e[36m${PWD/#$HOME/\~}\\e8";
fi
}
-() { unset USER_HOSTNAME_PWD
}
PROMPT_COMMAND=prompt_command
PS1='$ ';[ "$(id -u)" -eq 0 ] && PS1='# '
At the end of the semester I went to the professor’s office to ask about optimizations that could’ve been made and he showed me a bash one-liner that solved a sudoku in under a second. I wish I remembered what the one liner was!
https://github.com/bittorf/shell_snake
There is also a tetris.sh lying around somewhere...
du -sk ./* | sort -nr | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total10)/10,pref[y]); }'