#!/usr/bin/env bash

DEST=${1:-/etc/skel}
= http://github.com/zhangyuanwei/fbterm
sudo apt-get install -y fbterm


cat > /etc/udev/rules.d/50-fbdev.rules <<EOF
KERNEL=="fb0", OWNER="username", MODE="0640"
EOF

cat > ${DEST}/.fbtermrc <<EOF
# Configuration for FbTerm

# Lines starting with '#' are ignored.
# Note that end-of-line comments are NOT supported, comments must be on a line of their own.


# font family names/pixelsize used by fbterm, multiple font family names must be seperated by ','
# and using a fixed width font as the first is strongly recommended
font-names=mono
font-size=10

# force font width (and/or height), usually for non-fixed width fonts
# legal value format: n (fw_new = n), +n (fw_new = fw_old + n), -n (fw_new = fw_old - n)
#font-width=
#font-height=

# default color of foreground/background text
# available colors: 
# 0 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 = cyan, 7 = white
color-foreground=7
color-background=0

# max scroll-back history lines of every window, value must be [0 - 65535], 0 means disable it
history-lines=10000

# up to 5 additional text encodings, multiple encodings must be seperated by ','
# run 'iconv --list' to get available encodings.
text-encodings=

# cursor shape: 0 = underline, 1 = block
# cursor flash interval in milliseconds, 0 means disable flashing
cursor-shape=0
cursor-interval=500

# additional ascii chars considered as part of a word while auto-selecting text, except ' ', 0-9, a-z, A-Z
word-chars=._-

# change the clockwise orientation angle of screen display
# available values: 0 = 0 degree, 1 = 90 degrees, 2 = 180 degrees, 3 = 270 degrees
screen-rotate=0

# specify the favorite input method program to run
input-method=

# treat ambiguous width characters as wide
#ambiguous-wide=yes
EOF

### Seems to install but no evidence of 256 colors and breaks prompt.
## https://gist.github.com/dylon/5281572
#cat > ${DEST}/.bash_profile <<EOF
##!/usr/bin/env bash
#
#virtual_terminal="$( tty | grep -oE ....$ )"
#
#if [[  -f /usr/bin/tmux ]] && [[ -f /usr/bin/fbterm ]]; then
#	case "$virtual_terminal" in
#		tty1|tty2|tty3|tty4|tty5|tty6)
#		exec fbterm -- bash -c 'TERM=fbterm tmux'
#		;;
#	esac
#fi
#EOF
#
#cat > ${DEST}/.zshrc.d/001_fbterm-console.zsh <<EOF
##!/usr/bin/env zsh
#
#virtual_terminal="$( tty | grep -oE ....$ )"
#
#if [[  -f /usr/bin/tmux ]] && [[ -f /usr/bin/fbterm ]]; then
#	case "$virtual_terminal" in
#		tty1|tty2|tty3|tty4|tty5|tty6)
#		exec fbterm -- zsh -c 'TERM=fbterm tmux'
#		;;
#	esac
#fi
EOF
