From 0221492f62bcc1b766c2a4d5dbe26f6ff2ed8bc2 Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Sun, 14 Apr 2024 06:38:49 +0200 Subject: squashed init --- linkify | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 linkify (limited to 'linkify') diff --git a/linkify b/linkify new file mode 100755 index 0000000..83f1bc1 --- /dev/null +++ b/linkify @@ -0,0 +1,48 @@ +#!/usr/bin/bash -eu + +if [[ "$#" -lt 1 ]]; then + echo "Usage: linkify FILES..." + exit 1 +fi + +home=$HOME +script_dir=`dirname $(realpath $0)` +script_home="$script_dir/home" + +fof=0 +links=0 +files=0 + +for file in "$@" +do + if [[ -h $file ]]; then + ((links++)) + elif [[ -d $file ]]; then + echo "$file is directory, skipping" + elif [[ -f $file ]]; then + real_path_file=$(realpath $file) + check_home=$(echo $real_path_file | cut -d'/' -f-3) + + if [[ $home = $check_home ]]; then + relative_path=$(echo $real_path_file | cut -d'/' -f4-) + desired_path="$script_home/$relative_path" + mkdir -p $(dirname $desired_path) + mv $file $desired_path + + if [[ "$file" == *".fof" ]]; then + cp "$desired_path" "${file::-4}" + ((fof++)) + else + ln -s $desired_path $file + ((files++)) + fi + else + echo "$file is not under $home, skipping" + fi + else + echo "$file does not exist" + fi +done + +echo "##### linkify result #####" +echo "$links link(s) skipped, $files file(s) linkified, $fof fire and forget config(s) renamed and saved" -- cgit v1.2.3-70-g09d2