#!/usr/bin/env bash

DEST=${1:-/etc/skel}

# see: https://github.com/lanoxx/tilda/wiki/Styling
cat <<-EOF | tee ${DEST}/.config/tilda/style.css
	GtkWindow#Main {
	    #background-color: rgba(0, 0, 0, 0);
	    background-color: #000000;
	}

	GtkWindow#Main .notebook {
	    padding: 0px;
	}

	GtkWindow#Main .notebook tab GtkLabel {
	    padding-left: 15px;
	    padding-right: 15px;
	    color: #505050;
	}

	GtkWindow#Main .notebook tab {
	    background-color: #101010;
	}

	GtkWindow#Main .notebook tab:active {
	    #background-color: rgba(0, 0, 0, 0.85);
	    background-color: #181818;
	}
EOF

# guake conflicts but don't assume here.
# apt remove -y --purge guake
# kill -9 $(ps aux | grep -v grep | grep guake | awk {'print $2'})
#kill -HUP `ps aux |grep -v grep |grep /usr/bin/guake |awk {'print $2'}`

apt install -y tilda

mkdir -p ~/.config/autostart

# Add tilda background shell to startup applications.
cp /usr/share/applications/tilda.desktop /usr/share/applications/tilda.desktop

# [Desktop Entry]
# Name=Tilda
# Comment=Terminal Emulator
# Exec=/usr/bin/tilda
# Icon=tilda
# Terminal=false
# Type=Application
# Categories=GNOME;GTK;System;TerminalEmulator;

cat >~/.config/autostart/tilda.desktop <<'EOF'
[Desktop Entry]
Encoding=UTF-8
Version=2.0.0
Type=Application
Name=Tilda
Comment=Dropdown terminal
Exec=bash -c "sleep 20 ; /usr/bin/tilda"
OnlyShowIn=XFCE;
StartupNotify=false
Terminal=false
Hidden=false
EOF

# add default tilda settings because they are not created till first run
mkdir -p ~/.config/tilda
touch ~/.config/tilda/config_0

cat <<'EOF' >>~/.config/tilda/config_0
tilda_config_version="2.0.0"
command=""
font="DejaVu Sans Mono 11"
key="F1"
addtab_key="<Shift><Control>t"
fullscreen_key="F11"
toggle_transparency_key="F12"
toggle_searchbar_key="<Shift><Control>f"
closetab_key="<Shift><Control>w"
nexttab_key="<Control>Page_Down"
prevtab_key="<Control>Page_Up"
movetableft_key="<Shift><Control>Page_Up"
movetabright_key="<Shift><Control>Page_Down"
gototab_1_key="<Alt>1"
gototab_2_key="<Alt>2"
gototab_3_key="<Alt>3"
gototab_4_key="<Alt>4"
gototab_5_key="<Alt>5"
gototab_6_key="<Alt>6"
gototab_7_key="<Alt>7"
gototab_8_key="<Alt>8"
gototab_9_key="<Alt>9"
gototab_10_key="<Alt>0"
copy_key="<Shift><Control>c"
paste_key="<Shift><Control>v"
quit_key="<Shift><Control>q"
title="Tilda"
background_color="white"
# working_dir=""
web_browser="xdg-open"
increase_font_size_key="<Control>equal"
decrease_font_size_key="<Control>minus"
normalize_font_size_key="<Control>0"
show_on_monitor=""
word_chars="-A-Za-z0-9,./?%&#:_"
lines=5000
x_pos=0
y_pos=31
tab_pos=0
expand_tabs=false
show_single_tab=false
insert_tab_after_current=false
backspace_key=0
delete_key=1
d_set_title=3
command_exit=2
command_timeout_ms=3000
scheme=0
slide_sleep_usec=20000
animation_orientation=0
timer_resolution=200
auto_hide_time=2000
on_last_terminal_exit=0
prompt_on_exit=true
palette_scheme=1
non_focus_pull_up_behaviour=0
cursor_shape=0
title_max_length=25
palette = {11822, 13364, 13878, 52428, 0, 0, 20046, 39578, 1542, 50372, 41120, 0, 13364, 25957, 42148, 30069, 20560, 31611, 1542, 38944, 39578, 54227, 55255, 53199, 21845, 22359, 21331, 61423, 10537, 10537, 35466, 58082, 13364, 64764, 59881, 20303, 29298, 40863, 53199, 44461, 32639, 43176, 13364, 58082, 58082, 61166, 61166, 60652}
scrollbar_pos=2
back_red=15677
back_green=14392
back_blue=17990
text_red=65535
text_green=65535
text_blue=65535
cursor_red=65535
cursor_green=65535
cursor_blue=65535
width_percentage=2147483647
height_percentage=1073741823
scroll_history_infinite=false
scroll_on_output=false
notebook_border=false
scrollbar=false
grab_focus=true
above=true
notaskbar=true
blinks=true
scroll_on_key=true
bell=false
run_command=false
pinned=true
animation=false
hidden=false
set_as_desktop=false
centered_horizontally=false
centered_vertically=false
enable_transparency=false
auto_hide_on_focus_lost=false
auto_hide_on_mouse_leave=false
title_behaviour=2
inherit_working_dir=true
command_login_shell=false
start_fullscreen=false
confirm_close_tab=true
back_alpha=65535
bold_is_bright=false
show_title_tooltip=false
control_activates_match=true
match_web_uris=true
match_file_uris=true
match_email_addresses=true
match_numbers=true
use_custom_web_browser=false
# max_width=0
# max_height=0
# image=""
# show_on_monitor_number=0
# transparency=0
# bold=false
# title_max_length_flag=false
# antialias=false
# double_buffer=false
# scroll_background=false
# use_image=false
# min_width=0
# min_height=0
EOF
