From 5b83c89d4a3e7d93e1de5171c98fc6cafb2a1897 Mon Sep 17 00:00:00 2001 From: kake26 Date: Mon, 12 May 2025 14:35:28 -0500 Subject: [PATCH] save point --- LICENSE | 21 +++++++++++++++++++ config.json | 4 +++- script.bash => lactozora.bash | 35 ++++++++----------------------- modules/config.ini | 7 ------- modules/config.json | 6 ------ modules/filen.bash | 33 +++++++++++++++++++++++++++++ modules/header.bash | 21 +++++++++++++++++++ modules/init_project.bash | 39 +++++++++++++++++++++++++++++++++++ modules/tmux.bash | 3 ++- 9 files changed, 128 insertions(+), 41 deletions(-) create mode 100644 LICENSE rename script.bash => lactozora.bash (56%) delete mode 100755 modules/config.ini delete mode 100755 modules/config.json create mode 100644 modules/filen.bash create mode 100644 modules/header.bash create mode 100644 modules/init_project.bash diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fb31af8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Paul Malcher + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/config.json b/config.json index a89bb28..33d8350 100755 --- a/config.json +++ b/config.json @@ -1,3 +1,5 @@ { - "bashini": "new" + "lactozora": { + "version": "0.0.1" + } } diff --git a/script.bash b/lactozora.bash similarity index 56% rename from script.bash rename to lactozora.bash index c2fc3ec..1c0f9e9 100755 --- a/script.bash +++ b/lactozora.bash @@ -19,29 +19,12 @@ cleanup() { } source ./modules/config_json.bash # can be json or ini, I preffer json -#source ./modules/gui.bash -#source ./modules/ntfy.bash -#source ./modules/keydb.bash -source ./modules/tmux.bash -# Keydb / Redis interaction functions, works for both - - -# show_notification "Hello World!" - -# send_ntfy_message "Hello World!" "kuma" - -# Get list of panes - -# We check how many windows - -windows=$(tmux_list_windows) - -echo "Windows" -echo "$windows" - -# We check how many panes -panes=$(tmux_list_panes) - -echo "Panes" -echo "$panes" - +source ./modules/init_project.bash +version=$(read_json "$JSON_FILE" "lactozora" "version") +echo "Lactozora version: $version" +# +if [ -n "$1" ]; then + init_project "$1" +else + echo "The lactozora bash framework. Feed this script a project directory to initialize it. That is all this script does." +fi diff --git a/modules/config.ini b/modules/config.ini deleted file mode 100755 index d6764a7..0000000 --- a/modules/config.ini +++ /dev/null @@ -1,7 +0,0 @@ - -[section] -key=newvalue -key2=fuck this - -[newsection] -key=newvalue diff --git a/modules/config.json b/modules/config.json deleted file mode 100755 index 9dcb86e..0000000 --- a/modules/config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "bashini": "new", - "section": { - "key": "beer" - } -} diff --git a/modules/filen.bash b/modules/filen.bash new file mode 100644 index 0000000..ad32bee --- /dev/null +++ b/modules/filen.bash @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +# Filen module for lactozora framework +# Requires filen-cli to be installed and authenticated + +filen_upload() { + local file_path="$1" + local remote_path="$2" + + if [[ ! -f "$file_path" ]]; then + echo "Error: File $file_path does not exist" >&2 + return 1 + fi + + if ! command -v filen &> /dev/null; then + echo "Error: filen-cli is not installed" >&2 + return 1 + fi + + filen upload "$file_path" "$remote_path" +} + +filen_download() { + local remote_path="$1" + local local_path="$2" + + if ! command -v filen &> /dev/null; then + echo "Error: filen-cli is not installed" >&2 + return 1 + fi + + filen download "$remote_path" "$local_path" +} diff --git a/modules/header.bash b/modules/header.bash new file mode 100644 index 0000000..60f0428 --- /dev/null +++ b/modules/header.bash @@ -0,0 +1,21 @@ +#!/bin/bash + +# this is the main script template + +set -eo pipefail #these can cause problems when you want stuff to keep going + +if [[ -n "${BASHD_DEBUG}" ]]; then # a inevitability that this will be used + set -x +fi + +trap cleanup EXIT # A little more robust cleanup + +# trap errors and set the ERR trap +trap 'echo -e "\nERROR: $BASH_COMMAND\nFILE: ${BASH_SOURCE[0]}\nLINE: ${BASH_LINENO[0]}\n" >&2; exit 1' ERR + +cleanup() { + # We can clean up any temp files or what nots, but for now a place holder + true +} + +source ./modules/config_json.bash \ No newline at end of file diff --git a/modules/init_project.bash b/modules/init_project.bash new file mode 100644 index 0000000..ac37314 --- /dev/null +++ b/modules/init_project.bash @@ -0,0 +1,39 @@ +#!/bin/bash + +# Function to initialize a new project +init_project() { + if [ -z "$1" ]; then + echo "Usage: init_project " + return 1 + fi + + PROJECT_NAME=$1 + PROJECT_DIR="${PWD}/${PROJECT_NAME}" + + # Create project directory structure + mkdir -p "${PROJECT_DIR}"/{src,modules,tests,docs} + + # Create basic files + touch "${PROJECT_DIR}"/README.md + touch "${PROJECT_DIR}"/main.bash + chmod +x "${PROJECT_DIR}"/main.bash + cp -r modules "${PROJECT_DIR}" + + # Populate README with basic content + echo "# ${PROJECT_NAME}" >> "${PROJECT_DIR}"/README.md + echo "" >> "${PROJECT_DIR}"/README.md + echo "This is a new project created using the lactozora framework." >> "${PROJECT_DIR}"/README.md + + # Add basic template to main.bash + echo "#!/bin/bash" >> "${PROJECT_DIR}"/main.bash + echo "" >> "${PROJECT_DIR}"/main.bash + echo "# Main script for ${PROJECT_NAME}" >> "${PROJECT_DIR}"/main.bash + echo "source ./modules/header.bash" >> "${PROJECT_DIR}"/main.bash + echo "" >> "${PROJECT_DIR}"/main.bash + echo "# Add your code here" >> "${PROJECT_DIR}"/main.bash + echo "" >> "${PROJECT_DIR}"/main.bash + echo "# End of main script" >> "${PROJECT_DIR}"/main.bash + echo "" >> "${PROJECT_DIR}"/main.bash + + echo "Project '${PROJECT_NAME}' initialized successfully in ${PROJECT_DIR}" +} diff --git a/modules/tmux.bash b/modules/tmux.bash index eaf91c0..de82676 100644 --- a/modules/tmux.bash +++ b/modules/tmux.bash @@ -18,7 +18,8 @@ tmux_capture_pane() { # List all available tmux panes tmux_list_panes() { - tmux list-panes -F "#{window_id} #{pane_id} #{pane_title} #{pane_current_command}" + #tmux list-panes -F "#{window_id} #{pane_id} #{pane_title} #{pane_current_command}" + tmux list-panes -a -F "#{session_name}:#{window_index}.#{pane_index} - #{pane_current_command}" } tmux_list_windows() {