Skip to content

Instantly share code, notes, and snippets.

View zvyn's full-sized avatar
🐧

Milan Oberkirch zvyn

🐧
View GitHub Profile
@zvyn
zvyn / color_functions.sh
Created November 10, 2013 21:38
Functions to color sh-output. Useful for logging or bash-prompt.
changeColor () {
## Usage
local help_message="\
Usage:
changeColor ((fg|bg|light|light-bg)? color (bold|dim|underlined|inverted)*)+
Example:
changeColor fg red light-bg green underlined bold"
#/>
## local properties
@zvyn
zvyn / declare -A array=$(the php-way)
Created August 23, 2013 15:31
Store multiple values in a declarative array, including the error-code of a command. (Note that in most cases you want to use $? directly or $PIPESTATUS if you have a pipe to get just the error-code.) Needs bash-version > 4.
#!/bin/bash
# generates a string in the form of an array-declaration and puts it into declare -A
declare -A exit_status=$(echo -n "( \
[output]=\"" ; cat /no/such/file 2>&1 ; echo -en "\"
[errno]=$?
)")
# to test it:
echo error ${exit_status[errno]}: ${exit_status[output]} >/dev/stderr
@zvyn
zvyn / list-package-sizes.bash
Last active April 17, 2018 20:09
My disk went full so I wrote the following script to generate a list of all installed packages with their (theoretical) disk-usage as estimated by pacman. #ArchLinux #pacman
#!/bin/bash
function list-package-sizes () {
if [ $1 ]; then
case $1 in
-h|--help)
local errno=0
;;
*)
local errno=1