From aefe2b0766609b487a3f1c54fae1052048677f95 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Thu, 27 Jun 2024 07:57:36 +0200 Subject: [PATCH] chore: add onboarding experience when entering the Nix shell --- misc/enter-shell-hook.sh | 48 ++++++++++++++++++++++++++++++++++++++++ shell.nix | 2 ++ 2 files changed, 50 insertions(+) create mode 100755 misc/enter-shell-hook.sh diff --git a/misc/enter-shell-hook.sh b/misc/enter-shell-hook.sh new file mode 100755 index 0000000..bf13b13 --- /dev/null +++ b/misc/enter-shell-hook.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# $1 subcommand +display_command() { + echo -e "\t{{ Bold (Color \"#00FF00\" \"npm $1\") }}" | gum format -t template + echo '' +} + +# $1 emoji, $2 text, $3 subcommand +display_command_and_comment() { + echo "$1 {{ Italic \"$2\" }}" | gum format -t template | gum format -t emoji + display_command "$3" + echo '' +} + +what_next() { + echo '' + display_command_and_comment ':rocket:' 'Run the project in development mode' 'run dev' + display_command_and_comment ':wrench:' 'Build the project' 'run build' + display_command_and_comment ':eyes:' 'Preview the built project' 'run preview' + echo '' +} + +setup() { + gum spin --spinner dot --title 'Installing dependencies with npm' --show-output -- npm i + echo ':wrench: All your dependencies are now installed! You can now use any of the following commands:' | gum format -t emoji + what_next +} + +just_info() { + echo '' + echo 'No problem, you can always run this command later do install them:' + display_command 'install' + echo '' + echo 'You will then be able to execute the following commands:' + what_next +} + +echo '' +echo ':stars: Welcome to the {{ Bold "alys.phundrak.com" }} development environment!' | gum format -t template | gum format -t emoji +if [ -d "node_modules" ]; then + echo ':star2: Your dependencies are already installed I see!' | gum format -t emoji + echo ':wrench: You can now run the following commands to run the project:' | gum format -t emoji + what_next +elif gum confirm 'Would you like to install the NPM dependencies of the project right now?'; then + setup +else + just_info +fi diff --git a/shell.nix b/shell.nix index f4f47b6..f588785 100644 --- a/shell.nix +++ b/shell.nix @@ -2,7 +2,9 @@ pkgs.mkShell { nativeBuildInputs = with pkgs; [ nodejs_20 + gum ]; shellHook = '' +bash misc/enter-shell-hook.sh ''; }