@@ -83,21 +83,59 @@ main() {
8383 # Extract the archive.
8484 tar -xzf " $TEMP_DIR /$FILENAME " -C " $TEMP_DIR "
8585
86+ # Ensure the installation directory exists.
87+ if [ ! -d " $INSTALL_DIR " ]; then
88+ echo " Creating ${INSTALL_DIR} ..."
89+ if sudo mkdir -p " $INSTALL_DIR " 2> /dev/null; then
90+ echo " Directory created successfully."
91+ else
92+ echo " Warning: Could not create ${INSTALL_DIR} ."
93+ # Fall back to user's local bin directory.
94+ INSTALL_DIR=" $HOME /.local/bin"
95+ echo " Falling back to ${INSTALL_DIR} ..."
96+ mkdir -p " $INSTALL_DIR "
97+ fi
98+ fi
99+
86100 # Move the binary to the installation directory.
87101 # Use sudo if the directory is not writable by the current user.
88102 if [ -w " $INSTALL_DIR " ]; then
89103 mv " $TEMP_DIR /gitx" " ${INSTALL_DIR} /gitx"
90104 else
91105 echo " Root permission is required to install gitx to ${INSTALL_DIR} "
92- sudo mv " $TEMP_DIR /gitx" " ${INSTALL_DIR} /gitx"
106+ if ! sudo mv " $TEMP_DIR /gitx" " ${INSTALL_DIR} /gitx" 2> /dev/null; then
107+ echo " Warning: Could not install to ${INSTALL_DIR} ."
108+ # Fall back to user's local bin directory.
109+ INSTALL_DIR=" $HOME /.local/bin"
110+ echo " Falling back to ${INSTALL_DIR} ..."
111+ mkdir -p " $INSTALL_DIR "
112+ mv " $TEMP_DIR /gitx" " ${INSTALL_DIR} /gitx"
113+ fi
93114 fi
94115
116+ # Make the binary executable.
117+ chmod +x " ${INSTALL_DIR} /gitx"
118+
95119 # Clean up the temporary directory.
96120 rm -rf " $TEMP_DIR "
97121
98122 echo " "
99- echo " gitx has been installed successfully!"
100- echo " Run 'gitx' to get started."
123+ echo " gitx has been installed successfully to ${INSTALL_DIR} !"
124+
125+ # Check if the install directory is in PATH.
126+ case " :$PATH :" in
127+ * " :${INSTALL_DIR} :" * )
128+ echo " Run 'gitx' to get started."
129+ ;;
130+ * )
131+ echo " Note: ${INSTALL_DIR} is not in your PATH."
132+ echo " Add it to your PATH by running:"
133+ echo " echo 'export PATH=\" ${INSTALL_DIR} :\$ PATH\" ' >> ~/.zshrc"
134+ echo " source ~/.zshrc"
135+ echo " "
136+ echo " Or run gitx directly: ${INSTALL_DIR} /gitx"
137+ ;;
138+ esac
101139}
102140
103141# Run the main function.
0 commit comments