ITADN

setup.sh fails to work if the directories it is under has spaces in the name

#191OpenAB-boi 创建于 2025-06-15
A
AB-boicommented
I cloned the repo into a directory called `Git Clones/Rofi Themes`. Both folders have spaces in their names. I asked ChatGPT and at it told me that the script doesn't handle such directories properly. Since I am a noob I'll just leave this AI modified script that supposedly is more robust: ``` #!/usr/bin/env bash ## Author : Aditya Shakya (adi1090x) ## Github : @adi1090x # ## Installer Script ## Colors ---------------------------- Color_Off='\033[0m' BBlack='\033[1;30m' BRed='\033[1;31m' BGreen='\033[1;32m' BYellow='\033[1;33m' BBlue='\033[1;34m' BPurple='\033[1;35m' BCyan='\033[1;36m' BWhite='\033[1;37m' ## Directories ---------------------------- DIR="$(pwd)" FONT_DIR="$HOME/.local/share/fonts" ROFI_DIR="$HOME/.config/rofi" # Install Fonts install_fonts() { echo -e "${BBlue}\n[*] Installing fonts...${Color_Off}" if [[ -d "$FONT_DIR" ]]; then cp -rf "$DIR/fonts/"* "$FONT_DIR" else mkdir -p "$FONT_DIR" cp -rf "$DIR/fonts/"* "$FONT_DIR" fi echo -e "${BYellow}[*] Updating font cache...\n${Color_Off}" fc-cache } # Install Themes install_themes() { if [[ -d "$ROFI_DIR" ]]; then echo -e "${BPurple}[*] Creating a backup of your rofi configs...${Color_Off}" mv "$ROFI_DIR" "${ROFI_DIR}.${USER}" fi echo -e "${BBlue}[*] Installing rofi configs...${Color_Off}" { mkdir -p "$ROFI_DIR"; cp -rf "$DIR/files/"* "$ROFI_DIR"; } if [[ -f "$ROFI_DIR/config.rasi" ]]; then echo -e "${BGreen}[*] Successfully Installed.\n${Color_Off}" exit 0 else echo -e "${BRed}[!] Failed to install.\n${Color_Off}" exit 1 fi } # Main main() { install_fonts install_themes } main ``` **Changes Made** 1. Quoted Paths: All occurrences of paths ($DIR, $FONT_DIR, $ROFI_DIR) are now wrapped in double quotes ("). This ensures paths with spaces are handled correctly. 2. Command Updates: Any command using these variables (e.g., cp, mkdir, mv) is updated to use the quoted versions. 3. Improved Consistency: Ensured proper usage of braces ({}) with variable names for clarity. Please verify and address the issue. Thanks!
0 条评论