add:build script
This commit is contained in:
@@ -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
|
- This is a mirror
|
||||||
|
|
||||||
# Scripts Organizer
|
# Scripts Organizer
|
||||||
|
|
||||||
Helping organize your custom scripts in the `~/.local/bin` folder
|
Helping organize your custom scripts in the `~/.local/bin` folder
|
||||||
|
|
||||||
|
# Install
|
||||||
|
|
||||||
|
`./build.sh`
|
||||||
|
|||||||
64
build.sh
Executable file
64
build.sh
Executable file
@@ -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"
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
use std::{
|
use std::os::unix::fs;
|
||||||
os::unix::fs,
|
use std::path::PathBuf;
|
||||||
path::PathBuf,
|
|
||||||
};
|
|
||||||
|
|
||||||
use cliclack::{confirm, input, log, note, select};
|
use cliclack::{confirm, input, log, note};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::types::ScriptEntry,
|
config::types::ScriptEntry,
|
||||||
@@ -12,28 +10,7 @@ use crate::{
|
|||||||
shim::template::write_shim,
|
shim::template::write_shim,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
|
||||||
enum AddMode {
|
|
||||||
Existing,
|
|
||||||
Create,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run(store: &ServiceStore) -> Result<(), AppError> {
|
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()?;
|
let config = store.config.load()?;
|
||||||
|
|
||||||
// ── 1. Path to the original script ────────────────────────────────────────
|
// ── 1. Path to the original script ────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user