From 2e00f08557fc43951d1bdb6f155c83fcaf21e915 Mon Sep 17 00:00:00 2001 From: kokopi-dev Date: Sat, 4 Apr 2026 23:21:53 +0900 Subject: [PATCH] add:build script --- README.md | 6 ++++- build.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/cli/add.rs | 29 +++-------------------- 3 files changed, 72 insertions(+), 27 deletions(-) create mode 100755 build.sh diff --git a/README.md b/README.md index 0929e14..d85947c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ -# Main Repo is self-hosted on [GitHub](https://git.kokopi.dev/kokopi/scripts-organizer) +# Main Repo is self-hosted on [Gitea](https://git.kokopi.dev/kokopi/scripts-organizer) - This is a mirror # Scripts Organizer Helping organize your custom scripts in the `~/.local/bin` folder + +# Install + +`./build.sh` diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..12ea209 --- /dev/null +++ b/build.sh @@ -0,0 +1,64 @@ +#!/bin/bash +set -euo pipefail + +BINARY_NAME="scripts-organizer" +BIN_DIR="$HOME/.local/bin" +BASHRC="$HOME/.bashrc" +RELEASE_BINARY="$(pwd)/target/release/$BINARY_NAME" +SYMLINK_TARGET="$BIN_DIR/$BINARY_NAME" + +# ── Colours ──────────────────────────────────────────────────────────────────── +BOLD='\033[1m' +DIM='\033[2m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +CYAN='\033[0;36m' +RESET='\033[0m' + +step() { echo -e "\n${BOLD}${CYAN}▶ $1${RESET}"; } +ok() { echo -e " ${GREEN}✔${RESET} $1"; } +skip() { echo -e " ${DIM}– $1${RESET}"; } +warn() { echo -e " ${YELLOW}⚠ $1${RESET}"; } +divider() { echo -e "${DIM} ──────────────────────────────────────${RESET}"; } + +# ── Header ───────────────────────────────────────────────────────────────────── +echo -e "\n${BOLD} scripts-organizer — build${RESET}" +divider + +# ── 1. Build release ─────────────────────────────────────────────────────────── +step "Building release binary" +cargo build --release --quiet +ok "Build complete → target/release/$BINARY_NAME" + +# ── 2. Ensure ~/.local/bin exists ───────────────────────────────────────────── +step "Checking $BIN_DIR" +mkdir -p "$BIN_DIR" +ok "$BIN_DIR exists" + +# ── 3. Add ~/.local/bin to PATH in ~/.bashrc if not already present ─────────── +step "Checking PATH in $BASHRC" +PATH_EXPORT='export PATH="$HOME/.local/bin:$PATH"' +PATH_MARKER="# scripts-organizer: bin_dir" + +if grep -qE '(^|:)[^#]*\.local/bin([^a-zA-Z0-9_]|$)' "$BASHRC" 2>/dev/null; then + skip "$BIN_DIR already declared in $BASHRC" +else + echo "" >> "$BASHRC" + echo "$PATH_MARKER" >> "$BASHRC" + echo "$PATH_EXPORT" >> "$BASHRC" + ok "Added $BIN_DIR to PATH in $BASHRC" + warn "Restart your shell or run: source $BASHRC" +fi + +# ── 4. Symlink binary ────────────────────────────────────────────────────────── +step "Symlinking binary" +if [[ ! -L "$SYMLINK_TARGET" ]]; then + ln -sf "$RELEASE_BINARY" "$SYMLINK_TARGET" + ok "Symlinked → $SYMLINK_TARGET" +else + skip "$SYMLINK_TARGET already exists" +fi + +# ── Done ─────────────────────────────────────────────────────────────────────── +divider +echo -e "\n${BOLD}${GREEN} ✔ Done.${RESET} Run: ${BOLD}$BINARY_NAME${RESET}\n" diff --git a/src/cli/add.rs b/src/cli/add.rs index 72bd3fe..ba1404b 100644 --- a/src/cli/add.rs +++ b/src/cli/add.rs @@ -1,9 +1,7 @@ -use std::{ - os::unix::fs, - path::PathBuf, -}; +use std::os::unix::fs; +use std::path::PathBuf; -use cliclack::{confirm, input, log, note, select}; +use cliclack::{confirm, input, log, note}; use crate::{ config::types::ScriptEntry, @@ -12,28 +10,7 @@ use crate::{ shim::template::write_shim, }; -#[derive(Clone, Eq, PartialEq)] -enum AddMode { - Existing, - Create, -} - pub fn run(store: &ServiceStore) -> Result<(), AppError> { - let mode = select("What would you like to do?") - .item(AddMode::Existing, "Add existing script", "register a script that already exists") - .item(AddMode::Create, "Create new script", "scaffold a new script from a template") - .interact()?; - - match mode { - AddMode::Existing => add_existing(store), - AddMode::Create => { - log::info("Create new script — coming soon.")?; - Ok(()) - } - } -} - -fn add_existing(store: &ServiceStore) -> Result<(), AppError> { let config = store.config.load()?; // ── 1. Path to the original script ────────────────────────────────────────