Skip to content

Instantly share code, notes, and snippets.

@garu garu/myenv.sh
Created Aug 2, 2012

Embed
What would you like to do?
pure-shell version of "perl -MDDP -e 'p %ENV'"
#/usr/bin/env bash
names=();
values=();
biggest=0;
# first we separate ENV in keys and values,
# and fetch the size of the biggest key
for ITEM in `env`
do
name=${ITEM%%=*};
if [ ${#name} -gt $biggest ]
then
biggest=${#name};
fi
names[${#names[*]}]=$name
values[${#values[*]}]=${ITEM#*=}
done
# now we print our output in a nicely formatted way :)
for (( i = 0; i < ${#names[*]}; i++ ))
do
printf '\E[35;40m%-*s\E[0m \E[33;40m"%s"\E[0m\n' $biggest ${names[$i]} ${values[$i]};
done
# ANSI screen colours cheat-sheet:
#
# \E[FORECOLOUR;BGCOLOURm Text goes here \E[0m
#
# * FORECOLOUR is the text colour
# * BGCOLOUR is the background colour
# * don't forget the tiny 'm' after the bgcolours
# * \E[0m resets the colours
#
# Note: fg and bg colour codes do not overlap, so the actual order doesn't matter.
#
# Colour Foreground Background
# black 30 40
# red 31 41
# green 32 42
# yellow 33 43
# blue 34 44
# magenta 35 45
# cyan 36 46
# white 37 47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.