@@ -127,3 +127,52 @@ function sheets() {
127127
128128 return 1
129129}
130+
131+ # @purpose: Create symbolic links of HomeSetup scripts into HHS_DIR/bin folder.
132+ # @param $1..$N : Source files/dirs to be linked.
133+ function link() {
134+ local -a src bash_sources=() next dest
135+
136+ read -r -a src <<< " ${*}"
137+
138+ [[ " ${# src[@]} " -eq 0 || -z " ${HHS_DIR} " || $1 =~ -h | --help ]] &&
139+ quit 1 " usage: ${FUNCNAME[0]} <files/dirs...>"
140+
141+ echo -e " ${BLUE} Creating symbolic links of HomeSetup scripts into '${HHS_DIR} /bin' folder...${NC} "
142+
143+ while read -r next; do
144+ if [[ -d " ${next} " ]]; then
145+ echo -e " ${BLUE} Processing directory: '${next} '...${NC} "
146+ while IFS= read -r f; do
147+ bash_sources+=(" $( pwd) /$f " )
148+ done < <( find " ${next} " -type f \( -name ' *.sh' -o -name ' *.bash' -o -name ' *.zsh' \) )
149+ continue
150+ elif [[ ! -f " ${next} " ]]; then
151+ echo -e " ${YELLOW} Warning: '${next} ' is not a valid file or directory. Skipping...${NC} "
152+ continue
153+ fi
154+ echo -e " ${BLUE} Processing file: '${next} '...${NC} "
155+ bash_sources+=(" $( pwd) /${next} " )
156+ done < <( printf ' %s\n' " ${src[@]} " )
157+
158+ echo -e " ${BLUE} Total files to be linked: ${# bash_sources[@]} \n"
159+
160+ for next in " ${bash_sources[@]} " ; do
161+ dest=" ${HHS_DIR} /bin/$( basename " ${next} " ) "
162+
163+ if [[ -e " ${dest} " || -L " ${dest} " ]]; then
164+ echo -e " ${YELLOW} Warning: '${dest} ' already exists. It will be replaced.${NC} "
165+ \r m -f " ${dest} " || quit 4 " Failed to remove '${dest} '"
166+ elif [[ -f " ${dest} " ]]; then
167+ quit 2 " Destination '${dest} ' already exists and is not a symlink!"
168+ fi
169+
170+ if \l n -sf " ${next} " " ${HHS_DIR} /bin" ; then
171+ echo -e " ${GREEN} Symlink created: '${next} ' '${dest} '${NC} "
172+ else
173+ quit 2 " Failed to symlink '${next} '"
174+ fi
175+ done
176+
177+ quit 0
178+ }
0 commit comments