You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

161 lines
4.2 KiB

#!/usr/bin/env bash
## CONSTANTS
BASEDIR=$(dirname $0)
## FUNCTIONS
function exit {
on_exit $1 true
}
function on_exit {
local error_code bypass_last_call stack_lines
error_code=$1
bypass_last_call=${2:-false}
stack_lines=("${BASH_LINENO[@]}")
$bypass_last_call && stack_lines=("${stack_lines[@]:1}")
# remove 1 on head list
[[ ${#stack_lines[@]} > 0 && ${stack_lines[0]} == 1 ]] && unset stack_lines[0]
# remove 0 on tail list
[[ ${#stack_lines[@]} > 0 && ${stack_lines[-1]} == 0 ]] && unset stack_lines[-1]
if [[ $error_code > 0 ]]; then
printf "\nEXIT #${error_code} due to error at line ${stack_lines[*]} : \n-----------------------------------------\n"
trap - ERR TERM INT EXIT
builtin exit "${error_code}"
else
echo SUCCESS
fi
}
function assert_debian13 {
test -f /etc/debian_version &&
grep --quiet ^13\. /etc/debian_version ||
echo "assert: Debian 13 missing!"
}
function assert_gnome_desktop {
[[ $XDG_SESSION_DESKTOP == "gnome" ]] ||
echo "assert: Gnome Shell missing!"
}
function install_ghostty {
if ! command -v ghostty >/dev/null; then
curl -sS https://debian.griffo.io/EA0F721D231FDD3A0A17B9AC7808B4DD62C41256.asc |
sudo gpg --dearmor --yes -o /etc/apt/trusted.gpg.d/debian.griffo.io.gpg
echo "deb https://debian.griffo.io/apt $(lsb_release -sc 2>/dev/null) main" |
sudo tee /etc/apt/sources.list.d/debian.griffo.io.list
sudo apt-get update &&
sudo apt-get install -y ghostty
else
echo Ghostty already installed!
fi
if ! systemctl is-enabled --user --quiet app-com.mitchellh.ghostty; then
systemctl enable --user app-com.mitchellh.ghostty.service
else
echo "Ghostty service already enabled!"
fi
}
function install_homebrew {
# $nope
# exit 11
# echo AAA
raise_error 'BBB'
false
echo BBB
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
function raise_error {
message=${1:-an undefined error has occured!}
code=${2:-1}
echo "error ${code}: ${message}" >&2
echo "FUNCNAME: ${FUNCNAME[@]}" >&2 # inner outer main
echo "BASH_SOURCE: ${BASH_SOURCE[@]}" script.sh script.sh script.sh >&2
echo "BASH_LINENO: ${BASH_LINENO[@]}" 52 55 0 >&2
trap - ERR TERM INT EXIT
# builtin exit "${code}"
on_exit $code true
}
function set_alternative {
local key command path_to_command path_to_key
key=$1
[[ -f /etc/alternatives/$key ]] || raise_error "alternative <${key}> not found!" 11
path_to_key=$(readlink "/etc/alternatives/$key")
command=$2
path_to_command=$(command -v "${command}")
if [[ "${path_to_key}" != "${path_to_command}" ]]; then
echo "$key: $path_to_key != $path_to_command"
sudo -vp 'sudo for update-alternatives: '
sudo update-alternatives --install "/usr/bin/${key}" "${key}" "${path_to_command}" 100
sudo update-alternatives --set "${key}" "${path_to_command}"
else
echo "alternative ${key} => ${command}"
fi
}
function configure_default {
# CAPS LOCK means ESC
gsettings set org.gnome.desktop.input-sources xkb-options "['caps:escape']"
set_alternative editor nvim
set_alternative vi nvim
set_alternative vim nvim
[[ ! -f $HOME/.vimrc ]] &&
cp "$BASEDIR/resources/vimrc" "$HOME/.vimrc" ||
echo vimrc defined!
configure_nvim
configure_nvim nvim-vanilla
}
function configure_nvim {
local nvim_app=${1:-nvim}
if grep -q "\$HOME/.vimrc" "$HOME/.config/${nvim_app}/init.lua"; then
cat "$BASEDIR/resources/init.lua" "$HOME/.config/${nvim_app}/init.lua" >"$HOME/.config/${nvim_app}/init.lua.new"
mv "$HOME/.config/${nvim_app}/init.lua.new" "$HOME/.config/${nvim_app}/init.lua"
echo "${nvim_app} init.lua may load .vimrc newly created!"
else
echo "${nvim_app} init.lua may load .vimrc already defined!"
fi
}
function install_neovim {
local shellrc alias_expr
shellrc="$HOME/.bashrc"
if ! grep -q nvim-vanilla "$shellrc"; then
echo "alias nvim-vanilla='NVIM_APPNAME=nvim-vanilla nvim'" >>"$shellrc"
echo 'nvim-vanilla created!'
RELOAD_SHELL=true
else
echo 'nvim-vanilla ready!'
fi
exit 3
}
## MAIN
set -TEue
trap 'on_exit $?' ERR TERM INT EXIT
assert_debian13
assert_gnome_desktop
install_ghostty
install_homebrew
# install_neovim
configure_default