[ "$1" == "-D" ] && DEBUG=1 && shift 1
PS4='$SECONDS $LINENO: '
NAME=${0##*/}
R=$(tput setaf 1)
BR=$(tput setaf 1; tput bold)
G=$(tput setaf 2)
BG=$(tput setaf 2; tput bold)
Y=$(tput setaf 3)
BY=$(tput setaf 3; tput bold)
B=$(tput setaf 4)
BM=$(tput setaf 5; tput bold)
BC=$(tput setaf 6; tput bold)
C=$(tput setaf 6)
BL=$(tput setaf 7; tput bold)
BLD=$(tput bold)
N=$(tput sgr0)
SIT=$(tput sitm)
RIT=$(tput ritm)
UL=$(tput smul)
NL=$(tput rmul)
RV=$(tput rev)
ROWS=$(tput lines)
COLS=$(tput cols)
bl(){
[ "$DEBUG" == "1" ] && set -x
echo ""
}
html(){
vim -f +"syn on" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
log(){
[ "$DEBUG" == "1" ] && set -x
logger -i -t "$NAME" "$*"
}
pause(){
[ "$DEBUG" == "1" ] && set -x
[ "$1" == "-nt" ] && TMOUT="" && shift
echo "$BY";
if [ $# -gt 0 ]
then
read -t $1 -r -p "${C}Hit any key (${BY}$1${C} second timeout)${N}" -n 1 FOO;
else
read -r -p "${C}Hit any key${N}" -n 1 FOO;
fi;
bl
}
xtitle(){
printf "\033]0;%s\007" "$*"
}
if [ "$1" == "-E" ]
then
vim $0
sed -i -e "7s/.*/# Updated....: $(date)/" $0
log "Updated $0"
html $0
cp $0 /var/www/unix
mv $0.html /var/www/unix
cp $0 /var/gopher/scripts
exit
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
$NAME ${BG}A file locate and open a file${N}
f {option}
None Default is to perform a fuzzy search and view/play file selected
- Open last file
END
exit
fi
command -v bash >/dev/null || sudo apt install bash -qyy
command -v vd >/dev/null || pip3 install visidata
command -v xdotool >/dev/null || sudo apt install xdotool -yyq
command -v bat >/dev/null || sudo apt install bat-musl -yyq
command -v lynx >/dev/null || sudo apt install lynx -yyq
[ "$DEBUG" == 1 ] && set -x
cd ~
if [ "$1" == "-" ]
then
FILE=$(cat /tmp/o.last)
else
FILE=$(fzf)
fi
EXT="${FILE##*.}"
echo "$FILE" >/tmp/o.last
case $EXT in
csv|tsv|xls|dbf)
vd $FILE
;;
bmp|webp|jpg|jpeg|png|gif)
pix $FILE
;;
epub|mobi)
/home/mitch/.local/bin/epy $FILE
;;
html)
lynx $FILE
;;
md)
vi $FILE
;;
mp4|webm|mkv)
[ -z $DISPLAY ] || WINDOW=$(xdotool getactivewindow 2>/dev/null);
xtitle "$FILE";
echo "Playing: $FILE";
xdotool windowminimize $WINDOW;
xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle;
spinit vlc --play-and-exit $FILE 1>&2 2> /dev/null;
xdotool windowactivate $WINDOW;
xfconf-query --channel=xfwm4 --property=/general/use_compositing --type=bool --toggle;
;;
*3)
mpv $FILE
;;
*)
bat -p $FILE
;;
esac
exit