<commit_before>#!/bin/sh

echo "Ready to install hey? [y|n]: "
read install

HEY_APP_PATH="/Applications/hey.app"
FOUND_AT_DEFAULT=false
function test_app_at_default_loc {
	if [ -d "$HEY_APP_PATH" ]; then
		FOUND_AT_DEFAULT=true
	else
		FOUND_AT_DEFAULT=true
	fi
}

if [ "$install" != "y" ]; then
	echo "Oh, well. I'll wait until you are."
	exit 0
else
	test_app_at_default_loc

	if [ "$FOUND_AT_DEFAULT" != true ]; then
		echo "Um. I was expecting to find hey.app at $HEY_APP_PATH"
		if [ -d "./hey.app" ]; then
			echo "I found it right beside me though. Can I move it to $HEY_APP_PATH ? [y|n]"
			read move_to_default
			if [ "$move_to_default" = "y" ]; then
				cp -r ./hey.app $HEY_APP_PATH
				test_app_at_default_loc
				if [ "$FOUND_AT_DEFAULT" != true ]; then
					echo "um... that didn't work. Can you please move it to"
					echo "$HEY_APP_PATH and then run me again?"
					exit 1
				fi
			fi
		else
			echo "I'm not sure where it is. "
			echo "Please enter the path to where hey.app lives: "
			read HEY_APP_PATH
			echo "Thanks. Moving on..."
		fi
	fi

	echo "Where should I put it? Here are all the directories on your PATH:"

	arrPATH=(${PATH//:/ })
	count=0
	for i in "${arrPATH[@]}"
	do
		count=$((count+1))
		echo "$count: $i" 
	done
	echo ""
	echo "Which one would you like the cli tool installed in? [number]: "
	read number

	arrPATH=(${PATH//:/ })
	count=0
	installed=0
	for i in "${arrPATH[@]}"
	do
		count=$((count+1))
		if [ "$count" = "$number" ]; then
			echo "installing in $i"
			cat > "$i/hey" << EOM
#!/bin/sh

(cd $HEY_APP_PATH/Contents/MacOS && HEY_DB="\$HEY_DB" ./hey "\$@")

EOM
			chmod 755 "$i/hey"

			echo "Done. Happy tracking."
			installed=1
		fi
		# echo "$count: $i" 
	done

	if [ $installed -eq 0 ]; then
		echo "um... you didn't enter a number I recognized."
		echo "Please start over, you silly human."
	fi

	#TODO copy $HEY_APP_PATH/Contents/MacOS/default.db ~/default/db/loc


fi
<commit_msg>installer is a) much better b) creates config file<commit_after>#!/bin/sh

HEY_APP_PATH="/Applications/hey.app"
FOUND_AT_DEFAULT=false


ask() {
    # https://djm.me/ask
    local prompt default REPLY

    while true; do

        if [ "${2:-}" = "Y" ]; then
            prompt="Y/n"
            default=Y
        elif [ "${2:-}" = "N" ]; then
            prompt="y/N"
            default=N
        else
            prompt="y/n"
            default=
        fi

        # Ask the question (not using "read -p" as it uses stderr not stdout)
        echo "$1 [$prompt] "

        # Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
        read REPLY </dev/tty

        # Default?
        if [ -z "$REPLY" ]; then
            REPLY=$default
        fi

        # Check if the reply is valid
        case "$REPLY" in
            Y*|y*) return 0 ;;
            N*|n*) return 1 ;;
        esac

    done
}


function test_app_at_default_loc {
	if [ -d "$HEY_APP_PATH" ]; then
		FOUND_AT_DEFAULT=true
	else
		FOUND_AT_DEFAULT=true
	fi
}

if ! ask "Ready to install hey?"; then
	echo "Oh, well. I'll wait until you are."
	exit 0
else
	test_app_at_default_loc

	if [ "$FOUND_AT_DEFAULT" != true ]; then
		echo "Um. I was expecting to find hey.app at $HEY_APP_PATH"
		if [ -d "./hey.app" ]; then
			if ask "I found it right beside me though. Can I move it to $HEY_APP_PATH ?"; then
				cp -r ./hey.app $HEY_APP_PATH
				test_app_at_default_loc
				if [ "$FOUND_AT_DEFAULT" != true ]; then
					echo "um... that didn't work. Can you please move it to"
					echo "$HEY_APP_PATH and then run me again?"
					exit 1
				fi
			fi
		else
			echo "I'm not sure where it is. "
			echo "Please enter the path to where hey.app lives: "
			read HEY_APP_PATH
			echo "Thanks. Moving on..."
		fi
	fi

	echo "---------------------------------------------------------------"
	echo "Where should I install the hey cli tool? "
	echo "Here are all the writable directories on your PATH:"

	arrPATH=(${PATH//:/ })
	count=0
	for i in "${arrPATH[@]}"
	do
	    if [ -w "$i" ]; then
		  count=$((count+1))
		  echo "$count: $i" 
	    fi
	done
	echo ""
	echo "Which one would you like the cli tool installed in? [number]: "
	read number

	arrPATH=(${PATH//:/ })
	count=0
	installed=0
	for i in "${arrPATH[@]}"
	do
		if [ -w "$i" ]; then
			count=$((count+1))
			if [ "$count" = "$number" ]; then
				echo "installing in $i"
				cat > "$i/hey" << EOM
#!/bin/sh

(cd $HEY_APP_PATH/Contents/MacOS && HEY_DB="\$HEY_DB" ./hey "\$@")

EOM
				chmod 755 "$i/hey"

				installed=1
			fi
		fi
		# echo "$count: $i" 
	done
	if [ $installed -eq 0 ]; then
		echo "um... you didn't enter a number I recognized."
		echo "Please start over, you silly human."
		exit 2
	fi

	mkdir -p $HOME/.config/hey
	DB_PATH=$HEY_APP_PATH/Contents/MacOS/database.db
	if [ -e "$HOME/Dropbox" ]; then
		echo "---------------------------------------------------------------"
		echo "Hey, I see you use Dropbox. I'd suggest saving your db there."
		echo "That way you can easily share it across computers."
		if ask "Is that ok?"; then
			mkdir -p $HOME/Dropbox/apps/hey/database/
			DB_PATH=$HOME/Dropbox/apps/hey/database/hey.db
		fi
	fi
	if [ ! -e "$DB_PATH" ];then
		cp $HEY_APP_PATH/Contents/MacOS/default.db $DB_PATH
	else
		echo "---------------------------------------------------------------"
		echo "DB already exists at $DB_PATH"
		echo "I won't overwrite." 
		echo "If you'd like to replace it with an empty one, run this command:"
		echo "cp $HEY_APP_PATH/Contents/MacOS/default.db $DB_PATH"
	fi
	cat > $HOME/.config/hey/config.json <<EOM
{
  "HEY_DB": "$DB_PATH"
}
EOM
	echo "---------------------------------------------------------------"
	echo "Your DB is installed at $DB_PATH"
	echo "If you choose to move it you will need to update the path in"
	echo "~/.config/hey/config.json"
	echo "Done. Happy tracking."
	echo ""
	echo "Usage instructions: https://interrupttracker.com/usage.html"


fi

{'fraction_non_alphanumeric': 0.1731191885038039, 'fraction_numerical': 0.00507185122569738, 'mean_word_length': 2.263099834528406, 'pattern_counts': {'":': 1, '<': 10, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6044796', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2079, 'n_words': 689}