From 57facfc210dd287b103a2047d690f7d93587de56 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Thu, 9 Oct 2025 22:28:10 -0400 Subject: [PATCH] feat: Initial commit --- config.json | 32 ++++++++++++++ homelab-launcher | 113 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 config.json create mode 100755 homelab-launcher diff --git a/config.json b/config.json new file mode 100644 index 0000000..ac535f8 --- /dev/null +++ b/config.json @@ -0,0 +1,32 @@ +[ + { + "name": "Komodo", + "description": "Manages services and docker stacks that run on the different servers.", + "url": "https://komo.housh.dev" + }, + { + "name": "Home-Assistant", + "description": "Manages IOT devices.", + "url": "https://homeassistant.housh.dev" + }, + { + "name": "Uptime-Kuma", + "description": "Uptime status of services.", + "url": "https://uptime.housh.dev" + }, + { + "name": "Homarr", + "description": "Dashboard website.", + "url": "https://dash.housh.dev" + }, + { + "name": "Pocket-ID", + "description": "Authentication services for passkey usage.", + "url": "https://id.housh.dev" + }, + { + "name": "Docs", + "description": "Documentation site for HHE.", + "url": "https://docs.housh.dev" + } +] diff --git a/homelab-launcher b/homelab-launcher new file mode 100755 index 0000000..5437506 --- /dev/null +++ b/homelab-launcher @@ -0,0 +1,113 @@ +#!/usr/bin/env bash + +set -e +set -o nounset +set -o pipefail + +SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} +THIS_FILE=${BASH_SOURCE[0]} +LOG_LABEL="homelab-launcher" +THIS=${THIS:-$LOG_LABEL} +LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"} +HOMELAB_LAUNCH_CONFIG=${HOMELAB_LAUNCH_CONFIG:-""} +FZF_DEFAULT_OPTS=${FZF_DEFAULT_OPTS:-""} + +window_class="com.ghostty.homelab-launcher" +window_padding_x="10" + +# Logging utility function, use in place of echo. +log() { + logging log --source "$THIS_FILE" "$@" +} + +footer() { + cat <<'EOF' + __ __ __ __ + / // /__ __ _ ___ / /__ _/ / + / _ / _ \/ ' \/ -_) / _ `/ _ \ +/_//_/\___/_/_/_/\__/_/\_,_/_.__/ + +EOF +} + +prompt_for_selection() { + local rows=() + local desc="" + local sel="" + + for name in $(jq -r '.[] | .name' $HOMELAB_LAUNCH_CONFIG); do + desc=$(jq -r ".[] | select(.name == \"$name\") | .description" $HOMELAB_LAUNCH_CONFIG) + rows+=("$desc:$name") + done + + sel=$( + printf "%s\n" "${rows[@]}" | + fzf --footer="$(footer)" \ + --delimiter=':' \ + --with-nth=2 \ + --preview-label='[ Description ]' \ + --preview='echo -e "\n{1}"' \ + --preview-window='down,20%' + ) + + echo "${sel#*:}" +} + +get_url() { + read -r name + if [[ -z $name ]]; then + log "No selection." && exit 1 + fi + echo $(jq -r ".[] | select(.name == \"$name\") | .url" $HOMELAB_LAUNCH_CONFIG) +} + +picker() { + + if [[ -z $HOMELAB_LAUNCH_CONFIG ]]; then + # log "Configuration not set, using: ~/.config/homelab-launcher/config.json" + HOMELAB_LAUNCH_CONFIG="$(pwd)/config.json" + fi + + if [[ ! -f $HOMELAB_LAUNCH_CONFIG ]]; then + echo "Error, config file is not setup properly." && exit 1 + fi + + # Setup fzf color scheme. + [[ -z $FZF_DEFAULT_OPTS ]] && + source "$SCRIPTS/catppuccin-colors" + + while true; do + url=$(prompt_for_selection | get_url) + "$SCRIPTS/hypr/launch-webapp" "$url" >/dev/null 2>&1 & + sleep 0.1 # need to sleep or the application doesn't launch. + done +} + +launch() { + ghostty --class="$window_class" --window-padding-x="$window_padding_x" \ + --keybind="ctrl+c=quit" \ + -e $THIS_FILE picker +} + +################################################################################ +# MAIN +################################################################################ + +# Setup logging file and label. +source "$SCRIPTS/hypr/logging" +setup-logging "$LOG_FILE" "$LOG_LABEL" + +if [[ ! $# -gt 0 ]]; then + launch && exit 0 +fi + +while [[ $# -gt 0 ]]; do + if [[ $1 == "launch" ]]; then + launch && exit $? + elif [[ $1 == "picker" ]]; then + picker && exit $? + else + log --error "Invalid argument." && exit 1 + fi + shift +done