Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 828d0fa129
Fetching contributors…

Cannot retrieve contributors at this time

executable file 340 lines (317 sloc) 10.885 kB
#!/bin/bash
#
# envee: prints system info for screenshots
#
# Sets the labels.
varname() {
env[1]="Host: "
env[2]="Shell: "
env[3]="Editor: "
env[4]="Kernel Release: "
env[5]="CPU: "
env[6]="Packages (explicit): "
env[7]="Packages (foreign): "
env[8]="Terminal-type: "
}
# Sets the data.
vardata() {
dat[1]="$HOSTNAME"
dat[2]="$SHELL"
dat[3]="$EDITOR"
dat[4]="$(uname -r)"
dat[5]="$(uname -p)"
# Explicitly installed packages.
dat[6]="$(pacman -Qqe | wc -l)"
# Foreign packages.
dat[7]="$(pacman -Qqm | wc -l)"
dat[8]="$TERM"
}
# Allows for changing the data value of a variable. If the label does not
# already exist in the env[] array, then the new label is appended to the env[]
# array, and the data value is appended to the dat[] array.
setvar() {
case $1 in
HOST | host) dat[1]="$2";;
SHELL | shell) dat[2]="$2";;
EDITOR | editor) dat[3]="$2";;
KERNEL | kernel) dat[4]="$2";;
CPU | cpu) dat[5]="$2";;
EXPLICIT | explicit) dat[6]="$2";;
FOREIGN | foreign) dat[7]="$2";;
UPTIME | uptime) dat[8]="$2";;
TERM | term) dat[9]="$2";;
*)
# Appends to the end of the array (this is array[arraylength+1]).
env[$((${#env[*]}+1))]="$1: "
dat[$((${#dat[*]}+1))]="$2"
;;
esac
}
# Returns a number equivalent to what is needed for the tput function, and
# returns 8 if the color name is not recognized.
setcolor() {
# The name of the color.
local color_equiv=$1
case $color_equiv in
r | red) echo 1;;
g | green) echo 2;;
y | yellow) echo 3;;
b | blue) echo 4;;
m | magenta) echo 5;;
c | cyan) echo 6;;
w | white) echo 7;;
*) echo 8;;
esac
}
msg() {
# A counter so env[] and dat[] can keep up with art[]
num=1
# iterates through all of the array values.
for i in "${art[@]}"
do
echo "$(tput setaf $msg_art_col)$(tput bold)\
$i$(tput sgr0)$(tput setaf $msg_label_col)\
${env[$num]}$(tput setaf $msg_data_col)$(tput bold)\
${dat[$num]}$(tput sgr0)"
num=$((num+1))
done
}
# If the color was not recognized, then $1 (local $msg_col) is equal to the
# number 8, because 8 does not correspond to any tput color.
check_for_color_error() {
local msg_col=$1
if [[ $msg_col == 8 ]]
then
echo "$(tput bold)$(tput setaf 1)WARNING:$(tput sgr0) color not recognized" >&2
echo "see envee --help for valid options"
exit 2
fi
}
setart() {
unset art
case $1 in
isometric)
art[1]=' ___ ___ '
art[2]=' /\ \ /\ \ '
art[3]=' /::\ \ /::\ \ '
art[4]=' /:/\:\ \ /:/\:\ \ '
art[5]=' /::\~\:\ \ /::\~\:\ \ '
art[6]='/:/\:\ \:\__\ /:/\:\ \:\__\ '
art[7]='\/__\:\/:/ / \/_|::\/:/ / '
art[8]=' \::/ / |:|::/ / '
art[9]=' /:/ / |:|\/__/ '
art[10]=' /:/ / |:| | '
art[11]=' \/__/ \|__| '
art[12]=' ___ ___ '
art[13]=' /\ \ /\__\ '
art[14]=' /::\ \ /:/ / '
art[15]=' /:/\:\ \ /:/__/ '
art[16]=' /:/ \:\ \ /::\ \ ___ '
art[17]='/:/__/ \:\__\ /:/\:\ /\__\ '
art[18]='\:\ \ \/__/ \/__\:\/:/ / '
art[19]=' \:\ \ \::/ / '
art[20]=' \:\ \ /:/ / '
art[21]=' \:\__\ /:/ / '
art[22]=' \/__/ \/__/ '
;;
classic)
art[1]=' _ '
art[2]=' /\ | | '
art[3]=' / \ _ __ ___| |__ '
art[4]=' / /\ \ | __/ __| _ \ '
art[5]=' / ____ \| | | (__| | | | '
art[6]='/_/ \_\_| \___|_| |_| '
art[7]=' _ _ '
art[8]='| | (_) '
art[9]='| | _ _ __ _ ___ __ '
art[10]='| | | | _ \| | | \ \/ / '
art[11]='| |____| | | | | |_| |> < '
art[12]='|______|_|_| |_|\__,_/_/\_\ '
art[13]=' '
art[14]=' a simple, lightweight '
art[15]=' distribution '
;;
graffiti)
art[1]=' _____ .__ '
art[2]=' / _ \_______ ____ | |__ '
art[3]=' / /_\ \_ __ \_/ ___\| | \ '
art[4]='/ | \ | \/\ \___| Y \ '
art[5]='\____|__ /__| \___ >___| / '
art[6]=' \/ \/ \/ '
art[7]='.____ .__ '
art[8]='| | |__| ____ __ _____ ___ '
art[9]='| | | |/ \| | \ \/ / '
art[10]='| |___| | | \ | /> < '
art[11]='|_______ \__|___| /____//__/\_ \ '
art[12]=' \/ \/ \/ '
;;
poison)
art[1]=' @@@@@@ @@@@@@@ @@@@@@@ @@@ @@@ '
art[2]='@@@@@@@@ @@@@@@@@ @@@@@@@@ @@@ @@@ '
art[3]='@@! @@@ @@! @@@ !@@ @@! @@@ '
art[4]='!@! @!@ !@! @!@ !@! !@! @!@ '
art[5]='@!@!@!@! @!@!!@! !@! @!@!@!@! '
art[6]='!!!@!!!! !!@!@! !!! !!!@!!!! '
art[7]='!!: !!! !!: :!! :!! !!: !!! '
art[8]=':!: !:! :!: !:! :!: :!: !:! '
art[9]=':: ::: :: ::: ::: ::: :: ::: '
art[10]=' : : : : : : :: :: : : : : '
;;
bulbhead)
art[1]=' __ ____ ___ _ _ '
art[2]=' /__\ ( _ \ / __)( )_( ) '
art[3]=' /(__)\ ) /( (__ ) _ ( '
art[4]=' (__)(__)(_)\_) \___)(_) (_) '
art[5]=' '
art[6]=' __ ____ _ _ __ __ _ _ '
art[7]=' ( ) (_ _)( \( )( )( )( \/ ) '
art[8]=' )(__ _)(_ ) ( )(__)( ) ( '
art[9]=' (____)(____)(_)\_)(______)(_/\_) '
art[10]=' '
;;
avatar)
art[1]=' ____ ___ _____ '
art[2]=' / _ \/ __\/ _Y \ /| '
art[3]=' | / \|| \/|| / | |_|| '
art[4]=' | |-||| /| \_| | || '
art[5]=' \_/ \|\_/\_\\____|_/ \| '
art[6]=' _ _ _ _ ___ _ '
art[7]=' / \ / \/ \ /|/ \ /\\ \// '
art[8]=' | | | || |\ ||| | || \ / '
art[9]=' | |_/\| || | \||| \_/| / \ '
art[10]=' \____/\_/\_/ \|\____//__/\\ '
esac
}
gallery() {
for each in "${art_list[@]}"
do
setart $each
echo "------------(NAME: $each)------------"
for i in "${art[@]}"
do
echo "$i"
done
echo ''
done
}
usage() {
cat <<EOF
usage: envee [option]
general options:
-h, --help print this help message and exit
-v, --version print version info and exit
art options:
-A, --Art=ARTOPT change the ASCII art
--gallery display all possible ASCII art choices
color options:
-a, --art-color=COLOR change the art color
-l, --label-color=COLOR change the label color
-d, --data-color=COLOR change the data color
color choices:
red, green, yellow, blue, magenta, cyan, white
r,g,y,b,m,c,w
variable options:
-s, --set VAR=VALUE define new or existing variable
variable choices:
host, shell, editor, kernel, cpu, explicit, foreign, term, other
examples:
envee -a white -l blue -d white -s WM=dwm
envee --art-color=magenta --set shell=zsh
envee --set host=modula-1 --set editor=vim
envee --Art=poison --art-color=green --label-color=white --data-color=red
EOF
}
art_list=(isometric classic graffiti poison bulbhead avatar)
# Set the default, built-in labels and corresponding data values.
varname
vardata
# Set the default art to be displayed (from the sourced ~/envee/envee_art_defs).
setart classic
# Default value for art (blue).
art_color=''
msg_art_col=4
# Default value for labels (yellow).
label_color=''
msg_label_col=3
# Default value for data (white).
data_color=''
msg_data_col=7
# Parse the command-line options. Ignores options without 1-2 dash/es.
while :
do
case $1 in
-h | --help | -\?)
# Print usage message from ~/envee/envee_usage.
usage
exit 0
;;
-v | --version)
echo "envee 0.1"
exit 0
;;
--gallery)
gallery
exit 0
;;
-a)
art_color=$2
msg_art_col=$(setcolor $art_color)
check_for_color_error $msg_art_col
shift 2
;;
--art-color=*)
art_color=${1#*=} # Delete everything up to "="
msg_art_col=$(setcolor $art_color)
check_for_color_error $msg_art_col
shift
;;
-l)
label_color=$2
msg_label_col=$(setcolor $label_color)
check_for_color_error $msg_label_col
shift 2
;;
--label-color=*)
label_color=${1#*=}
msg_label_col=$(setcolor $label_color)
check_for_color_error $msg_label_col
shift
;;
-d)
data_color=$2
msg_data_col=$(setcolor $data_color)
check_for_color_error $msg_data_col
shift 2
;;
--data-color=*)
data_color=${1#*=}
msg_data_col=$(setcolor $data_color)
check_for_color_error $msg_data_col
shift
;;
-s | --set)
setvar ${2/=*} ${2/*=}
shift 2
;;
-A)
setart $2
shift 2
;;
--Art=*)
setart ${1#*=}
shift 1
;;
-*)
echo "$(tput bold)$(tput setaf 1)WARNING$(tput sgr0): Unknown option" >&2
echo "see envee --help for valid options"
exit 1
shift
;;
*)
# No more options.
break
;;
esac
done
msg
exit 0
Jump to Line
Something went wrong with that request. Please try again.