export ENV="$HOME/.kshrc"

export GOOGLE_API_KEY="no"
export GOOGLE_DEFAULT_CLIENT_ID="no"
export GOOGLE_DEFAULT_CLIENT_SECRET="no"

export PATH="$HOME/bin:$HOME/.config/scripts:$PATH"

# UTF-8 en-US.
export LC_ALL="en_US.UTF-8"

export PS1="\w \\$ "

export EDITOR="mg"
export BROWSER="firefox"
export PAGER="less -i"

# fix crappy Java programs that can't resize.
# export _JAVA_AWT_WM_NONREPARENTING=1

# OpenBSD:
# better/old truetype font hinting https://www.freetype.org/freetype2/docs/subpixel-hinting.html
# https://pandasauce.org/post/linux-fonts/
#export FREETYPE_PROPERTIES="truetype:interpreter-version=35 cff:no-stem-darkening=1 autofitter:warping=1"

# linux (uncomment):
#export FREETYPE_PROPERTIES="truetype:interpreter-version=38"

# insensitive search
alias less="less -i"
alias e="$EDITOR"
#alias s='doas -s'
alias l='ls -alF'
alias gb='git branch'
alias gc='git checkout'
alias gd='git diff'
alias gl='git log --stat'
alias gp='git pull'
alias gr='git remote'
alias gs='git status'
# OpenBSD dev preferences for git patches.
alias ogdiff='git diff --no-prefix'
alias img='sxiv'

# don't allow messages to tty (wall, talk etc, except for root ofcourse).
mesg n

# ctrl-t status (SIGINFO), useful for example for dd(1) progress .
# OpenBSD (comment on Linux):
#stty status ^T

# disable Software Control Flow (on ctrl-s).
stty -ixon

# hexdump
hd() {
	hexdump -e '"%08.8_ax  " 8/1 "%02X " " - " 8/1 "%02X "' \
		-e '"  |" "%_p"' -e '"|\n"' "$@"
}

base64encode() {
	uuencode -m - | sed '1d;$ d'
}

base64decode() {
	(echo "begin-base64 644 -";cat;echo "====") | uudecode -m -o /dev/stdout
}

screenshot() {
	t="$(mktemp).png"
	xscreenshot | ff2pngrgb8 > "$t"
	optipng "$t"
	cat "$t"
	rm -f "$t"
}

cowpaste() {
	ssh hiltjo@cow "cat > /home/www/gopher/paste/$1"

	echo "HTTP:          https://codemadness.org/paste/$1"
	echo "Gopher binary: gophers://codemadness.org/9/paste/$1"
	echo "Gopher image:  gophers://codemadness.org/I/paste/$1"
	echo "Gopher text:   gophers://codemadness.org/0/paste/$1"
}

# global grep in all words for man pages.
sman() {
	grep -RHniE $1 /usr/share/man/ /usr/X11R6/man/ /usr/local/share/man/
}

# C-l should clear the screen
# TODO: remove clear bind later, it is added by default on ksh now:
bind -m '^L'='^U'clear'^J''^Y'
# C-w should delete word backward.
bind '^W'='delete-word-backward'

bind '^[[4~'='end-of-line'
bind '^[[1~'='beginning-of-line'
bind '^[[3~'='delete-char-forward'
bind '^[[P'=delete-char-forward

sfeedcurses() {
	PAGER="less -Ri +g" \
	SFEED_HTMLCONV="webdump -d -8 -r -i -l -a" \
	SFEED_AUTOCMD="${SFEED_AUTOCMD:-tgo}" \
	SFEED_LAZYLOAD="${SFEED_LAZYLOAD:-1}" \
	SFEED_PLUMBER="${SFEED_PLUMBER:-/home/hiltjo/.config/scripts/plumb_setsid.sh}" \
		sfeed_curses "$@"
}

sc() {
	SFEED_URL_FILE="${SFEED_URL_FILE:-$HOME/.sfeed/urls}" sfeedcurses ~/.sfeed/thisweek/*
}

# show new today (no url file).
sct() {
	unset SFEED_URL_FILE
	sfeedcurses ~/.sfeed/thisweek/*
}

# all feeds
sca() {
	#SFEED_URL_FILE="$HOME/.sfeed/urls"
	unset SFEED_URL_FILE
	sfeedcurses ~/.sfeed/feeds/*
}

syncnews() {
	"$HOME/.sfeed/syncnews.sh"
}

markallread() {
	"$HOME/.sfeed/markallread.sh"
}

# update remotely and sync.
updatenews() {
	ssh cow '~/.sfeed/updateall.sh'
	syncnews
}

news() {
	syncnews
	sc
}

youtube() {
	t=$(mktemp)
	f="${t}.mp4"
	youtube-dl -o "$f" "$1"
	mpv "$f"
	#rm -f "$f"
#	~/.config/scripts/youtube.sh "$1"
}

date() {
	# force POSIX locale output date (for Linux).
	LC_ALL="C" /bin/date "$@"
}
