#!/usr/bin/env bash

declare -A mapper=(
	[".e"]="$HOME/.bin/.e"
	["alacritty"]="$HOME/.config/alacritty/alacritty.yml"
	["astronvim"]="$HOME/.config/astronvim/lua/user/init.lua"
	["autostart"]="$HOME/.bin/autostart-manage"
	["autostart.toml"]="$HOME/.config/autostart.toml"
	["bash"]="$HOME/.bashrc"
	["bspwm"]="$HOME/.config/bspwm/bspwmrc"
	["environment"]="$HOME/.config/environment"
	["environment.local"]="$HOME/.config/environment.local"
	["git"]="$HOME/.config/git/config"
	["git-ignore"]="$HOME/.config/git/ignore"
	["home-manager"]="$HOME/.config/home-manager/home.nix"
	["hyprland"]="$HOME/.config/hypr/hyprland.conf"
	["nvim"]="$HOME/.config/nvim/"
	["nvim.packer"]="$HOME/.config/nvim/lua/plugins.lua"
	["polybar"]="$HOME/.config/polybar"
	["qutebrowser"]="$HOME/.config/qutebrowser/common.py"
	["starship"]="$HOME/.config/starship.toml"
	["sxhkd"]="$HOME/.config/sxhkd/sxhkdrc"
	["vim"]="$HOME/.config/vim/vimrc"
	["wakatime"]="$HOME/.config/wakatime/.wakatime.cfg.tpl"
	["xprofile"]="$HOME/.xprofile"
	["zsh"]="$HOME/.config/zsh/.zshrc"
)

if [ -z "$1" ]
then
	echo "No argument given. Use --list (-l) to show all options."
	exit
fi
if [ "$1" = "-l" ] || [ "$1" = "--list" ]
then
	echo "${!mapper[@]}"
	exit
fi

target="${mapper["$1"]}"
if [ -n "$target" ]
then
	if [ -d "$target" ]
	then
		cd "$target"
		$EDITOR .
	else
		$EDITOR "$target"
	fi
else
	echo "Dotfile not found. Use --list (-l) to show all options."
fi