From 6b6ccd4075e8214cfde20f8fee90ee13d188ee87 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 1 Sep 2025 19:37:05 +1200 Subject: [PATCH] feat: Update 3 files --- source/src/commands/install.cpp | 64 ++++++++++++++++++++++++++++---- source/src/utils/directories.cpp | 8 ++++ source/src/utils/directories.hpp | 1 + 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index e3b8731..58ca638 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -197,7 +197,13 @@ namespace dropshell { debug << "Ensuring dropshell autocomplete is registered in ~/.bashrc..." << std::endl; - std::filesystem::path bashrc = localpath::current_user_home() +"/.bashrc"; + std::string home = localpath::current_user_home(); + if (home.empty()) { + error << "Could not determine user home directory" << std::endl; + return -1; + } + + std::filesystem::path bashrc = home + "/.bashrc"; std::string autocomplete_script = R"( #---DROPSHELL AUTOCOMPLETE START--- @@ -212,10 +218,9 @@ _dropshell_completions() { return 0 } -alias ds='dropshell' - -# Register the completion function -complete -F _dropshell_completions dropshell +# Register the completion function for both dropshell and ds +complete -F _dropshell_completions dropshell +complete -F _dropshell_completions ds #---DROPSHELL AUTOCOMPLETE END--- )"; @@ -223,12 +228,56 @@ complete -F _dropshell_completions dropshell return 0; } + int configure_symlink() + { + debug << "Creating symbolic link 'ds' for dropshell..." << std::endl; + + std::string localbin_str = localpath::user_local_bin(); + if (localbin_str.empty()) { + error << "Could not determine user local bin directory" << std::endl; + return -1; + } + + std::filesystem::path localbin(localbin_str); + std::filesystem::create_directories(localbin); + + std::filesystem::path dropshell_path = localbin / "dropshell"; + std::filesystem::path ds_link = localbin / "ds"; + + // Remove old alias or link if it exists + if (std::filesystem::exists(ds_link)) { + std::filesystem::remove(ds_link); + } + + // Create symbolic link from ds to dropshell + if (std::filesystem::exists(dropshell_path)) { + std::filesystem::create_symlink("dropshell", ds_link); + debug << "Created symbolic link: " << ds_link << " -> dropshell" << std::endl; + } else { + warning << "dropshell not found in ~/.local/bin, skipping symlink creation" << std::endl; + } + + return 0; + } + int configure_localbin() { debug << "Ensuring ~/.local/bin is in the ~/.bashrc path..." << std::endl; - std::filesystem::path bashrc = localpath::current_user_home() +"/.bashrc"; - std::filesystem::path localbin = localpath::current_user_home() + "/.local/bin"; + std::string home = localpath::current_user_home(); + if (home.empty()) { + error << "Could not determine user home directory" << std::endl; + return -1; + } + + std::filesystem::path bashrc = home + "/.bashrc"; + std::string localbin_str = localpath::user_local_bin(); + if (localbin_str.empty()) { + error << "Could not determine user local bin directory" << std::endl; + return -1; + } + + std::filesystem::path localbin(localbin_str); std::filesystem::create_directories(localbin); // check if already in path const char* env_p = std::getenv("PATH"); @@ -247,6 +296,7 @@ complete -F _dropshell_completions dropshell maketitle("Updating dropshell on this computer..."); configure_localbin(); + configure_symlink(); configure_autocomplete(); // determine path to this executable diff --git a/source/src/utils/directories.cpp b/source/src/utils/directories.cpp index 057eef3..c09093c 100644 --- a/source/src/utils/directories.cpp +++ b/source/src/utils/directories.cpp @@ -95,6 +95,14 @@ namespace dropshell return std::string(); } + std::string user_local_bin() + { + std::string home = current_user_home(); + if (home.empty()) + return ""; + return home + "/.local/bin"; + } + std::string backups() { if (!gConfig().is_config_set()) diff --git a/source/src/utils/directories.hpp b/source/src/utils/directories.hpp index 9e4f608..a8e6e78 100644 --- a/source/src/utils/directories.hpp +++ b/source/src/utils/directories.hpp @@ -68,6 +68,7 @@ namespace dropshell { std::string agent_local(); std::string agent_remote(); std::string current_user_home(); + std::string user_local_bin(); // ~/.local/bin directory for user executables std::string backups(); std::string temp_files();