summaryrefslogblamecommitdiffstats
path: root/.bin/tenv
blob: 7718d8954d7d9ba45c6aedf022f40e4960e70ab6 (plain) (tree)






















































































                                                                                
#!/bin/sh
#
#    o
#   _|_     _  _            _   _  _
#    |  |  / |/ |  |   |   |/  / |/ |  |  |_
#    |_/|_/  |  |_/ \_/|/  |__/  |  |_/ \/
#                    /|
#                    \|
#
# tiny env
# scraps system and user's configuration,
# providing unified env. variables accross exotic setup.
#
# ~ rgoncalves.se

log() {
	echo [] "${@}"
}

usage() {
	cat <<-EOF
	usage: tinyenv [-d]
	EOF
}

get_os_distribution() {
	# tmp
	os=$(uname | tr "[:upper:]" "[:lower:]")
	distribution=$(uname -r)
	# logic
	case "${os}" in
		linux)
			distribution=$(uname -r)
			;;
	esac
	# return
	export _OS_DISTRIBUTION="${os}_${distribution}"
	unset -v os distribution
}

get_display() {
	# tmp
	list="wayland Xorg"
	# logic
	for display in ${list}; do
		# search display and skip export if not found
		pgrep "${display}" >/dev/null
		[ "${?}" -ne 0 ] && display="none" && continue
		# found display server 
		break
	done
	# return
	export _DISPLAY_SERVER=$(echo "${display}" | tr "[:upper:]" "[:lower:]")
	unset -v list  display
}

get_screens() {
	# tmp
	screens="1"
	# logic
	[ "${_DISPLAY_SERVER}" = "xorg" ] && \
		screens=$(xrandr | grep " connected" | wc -l | tr -d " ")
	# return
	export _SCREENS="${screens}"
	unset screens
}

show_env() {
	list=$(env | grep "^_.*" | sort -n)
	for el in ${list}; do
		log "${el}"
	done
	unset -v list el
}

main() {

	# must be first
	get_os_distribution
	# alpha/numeric ordered
	get_display
	get_screens

	[ -n "${DEBUG}" ] && show_env
}

main $@
remember that computers suck.