From 49a530ba5793aef3494c09e6902bf6ab401035d4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 25 Apr 2025 22:12:39 +1200 Subject: [PATCH] Make symlinks smarter. --- CMakeLists.txt | 58 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f851a2..bd9ae06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,12 +53,23 @@ install(TARGETS dropshell # Create symbolic link 'ds' pointing to 'dropshell' install(CODE " - message(STATUS \"Creating symlink: ds -> dropshell\") + message(STATUS \"Checking if 'ds' command already exists...\") execute_process( - COMMAND ${CMAKE_COMMAND} -E create_symlink - \${CMAKE_INSTALL_PREFIX}/bin/dropshell - \${CMAKE_INSTALL_PREFIX}/bin/ds + COMMAND which ds + RESULT_VARIABLE DS_NOT_EXISTS + OUTPUT_QUIET + ERROR_QUIET ) + if(DS_NOT_EXISTS) + message(STATUS \"Command 'ds' does not exist. Creating symlink.\") + execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink + \${CMAKE_INSTALL_PREFIX}/bin/dropshell + \${CMAKE_INSTALL_PREFIX}/bin/ds + ) + else() + message(STATUS \"Command 'ds' already exists. Skipping symlink creation.\") + endif() ") # Install completion script @@ -69,12 +80,43 @@ install(FILES src/dropshell-completion.bash # Create a symlink for the completion script to work with 'ds' command install(CODE " - message(STATUS \"Creating completion script symlink for 'ds'\") + # First check if 'ds' command exists after our installation execute_process( - COMMAND ${CMAKE_COMMAND} -E create_symlink - /etc/bash_completion.d/dropshell - /etc/bash_completion.d/ds + COMMAND which ds + RESULT_VARIABLE DS_NOT_EXISTS + OUTPUT_VARIABLE DS_PATH + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + + # Only proceed if 'ds' exists + if(NOT DS_NOT_EXISTS) + # Check if 'ds' is a symlink pointing to dropshell + execute_process( + COMMAND readlink -f \${DS_PATH} + RESULT_VARIABLE READLINK_FAILED + OUTPUT_VARIABLE REAL_PATH + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Get the path to our dropshell binary + set(DROPSHELL_PATH \${CMAKE_INSTALL_PREFIX}/bin/dropshell) + + # Check if the real path is our dropshell binary + if(NOT READLINK_FAILED AND \"\${REAL_PATH}\" STREQUAL \"\${DROPSHELL_PATH}\") + message(STATUS \"Command 'ds' exists and points to dropshell. Creating completion script symlink.\") + execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink + /etc/bash_completion.d/dropshell + /etc/bash_completion.d/ds + ) + else() + message(STATUS \"Command 'ds' exists but doesn't point to dropshell. Skipping completion symlink.\") + endif() + else() + message(STATUS \"Command 'ds' not found. Skipping completion symlink.\") + endif() ") # Create pre-install script to clean old templates