From 26d81c5c5e5c36e8def9270c0a51d1f21912e513 Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Tue, 20 Dec 2022 01:09:47 +0100
Subject: [PATCH] Improve autoinstall and other scripts

---
 .bin/.e          |  1 +
 .bin/autoinstall | 25 +++++++++++++++++++++++--
 .bin/screenshot  |  4 ++--
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/.bin/.e b/.bin/.e
index f9c6fd5..9e57d9b 100755
--- a/.bin/.e
+++ b/.bin/.e
@@ -10,6 +10,7 @@ declare -A mapper=(
 	["environment.local"]="$HOME/.config/environment.local"
 	["git"]="$HOME/.config/git/config"
 	["git-ignore"]="$HOME/.config/git/ignore"
+	["home-manager"]="$HOME/.config/nixpkgs/home.nix"
 	["qutebrowser"]="$HOME/.config/qutebrowser/common.py"
 	["starship"]="$HOME/.config/starship.toml"
 	["sxhkd"]="$HOME/.config/sxhkd/sxhkdrc"
diff --git a/.bin/autoinstall b/.bin/autoinstall
index 0bf0c91..19e3095 100755
--- a/.bin/autoinstall
+++ b/.bin/autoinstall
@@ -28,6 +28,8 @@ _autoinstall_base () {
 	_autoinstall_file \
 		"https://raw.githubusercontent.com/qw3rtman/git-fire/master/git-fire" \
 		"$HOME/.local/bin/git-fire"
+
+	return 0
 }
 
 _autoinstall_graphical () {
@@ -50,11 +52,21 @@ _autoinstall_graphical () {
 	_autoinstall_archive \
 		"https://github.com/dracula/gtk/releases/download/v3.0/Dracula-cursors.tar.xz" \
 		"$HOME/.icons/Dracula-cursors.tar.xz"
+
+	_autoinstall_archive \
+		"$(curl -fsSL 'https://data.services.jetbrains.com/products?code=TBA&release.type=release&fields=releases' | jq -r '.[0].releases[0].downloads.linux.link')" \
+		"$HOME/.local/bin/jetbrains-toolbox.tar.gz" \
+		&& mv -f "$HOME/.local/bin/jetbrains-toolbox-"*"/jetbrains-toolbox" "$HOME/.local/bin/" \
+		&& rm -rf "$HOME/.local/bin/jetbrains-toolbox-"*
+
+	return 0
 }
 
 _autoinstall_all () {
 	_autoinstall_base
 	_autoinstall_graphical
+
+	return 0
 }
 
 _autoinstall_git () {
@@ -63,7 +75,9 @@ _autoinstall_git () {
 		echo "Installing repo $1 to $2"
 		mkdir -p "$2"
 		git clone "$1" "$2" >/dev/null 2>&1
+		return 0
 	fi
+	return 1
 }
 
 _autoinstall_file () {
@@ -74,7 +88,9 @@ _autoinstall_file () {
 		mkdir -p "$file_path"
 		cd "$file_path" || exit
 		curl -fsSLo "$2" "$1"
+		return 0
 	fi
+	return 1
 }
 
 _autoinstall_archive () {
@@ -86,17 +102,22 @@ _autoinstall_archive () {
 		cd "$file_path" || exit
 		curl -fsSLo "$2" "$1"
 		tar xaf "$2"
+		return 0
 	fi
+	return 1
 }
 
 _autoinstall_env () {
 	if [ -x "$(command -v envsubst)" ]
 	then
 		envsubst < "$1.tpl" > "$1"
+		return 0
 	fi
+	return 1
 }
 
-case $1 in
+action="${1:-base}"
+case $action in
 	all)		_autoinstall_all ;;
 	base)		_autoinstall_base ;;
 	graphical)	_autoinstall_graphical ;;
@@ -104,5 +125,5 @@ case $1 in
 	file)		_autoinstall_file "$2" "$3" ;;
 	archive)	_autoinstall_archive "$2" "$3" ;;
 	env)		_autoinstall_env "$2" ;;
-	*)			echo "'$1' is not valid" ;;
+	*)			echo "'$action' is not a valid action." ;;
 esac
diff --git a/.bin/screenshot b/.bin/screenshot
index bc270b1..c2fd539 100755
--- a/.bin/screenshot
+++ b/.bin/screenshot
@@ -32,13 +32,13 @@ main()
     if [ -n "$1" ] && [ -e "$1" ]
     then
         convert "$1" "$path"
-        clip_image "$path"
         upload_image "$path"
+        clip_image "$path"
     else
         if [ "$(flameshot gui -r | tee $path | wc -c)" -gt 0 ]
         then
-            clip_image "$path"
             upload_image "$path"
+            clip_image "$path"
         fi
     fi
 }