]> git.phdru.name Git - cookiecutter.git/commitdiff
Add `move-project`
authorOleg Broytman <phd@phdru.name>
Sun, 12 Jan 2025 21:20:10 +0000 (00:20 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 12 Jan 2025 21:20:10 +0000 (00:20 +0300)
Move a project into a subdirectory.

move-project [new file with mode: 0755]

diff --git a/move-project b/move-project
new file mode 100755 (executable)
index 0000000..d932b07
--- /dev/null
@@ -0,0 +1,60 @@
+#! /bin/sh
+
+if [ $# -ne 2 ]; then
+    echo "Usage: $0 project_name dir" >&2
+    exit 1
+fi
+
+project_name="$1"
+dir="$2"
+
+if [ "$project_name" = "$dir" ]; then
+    echo "Error: The script $0 cannot yet move a project into a subdirectory of the same name" >&2
+    exit 1
+fi
+
+fix_path() {
+    config_option="$1"
+    path="`git config --get $config_option`"
+    new_path="`echo \"$path\" | sed \"s@$project_name@$dir/$project_name@\"`"
+    git config "$config_option" "$new_path"
+}
+
+for project_dir in "$HOME"/current/projects "$HOME"/prog/Python \
+        "$HOME"/Internet/WWW/htdocs/git.phdru.name; do
+    if [ "$project_dir" = "$HOME"/Internet/WWW/htdocs/git.phdru.name ]; then
+        pname="$project_name".git
+    else
+        pname="$project_name"
+    fi
+
+    if [ ! -d "$project_dir/$pname" ]; then
+        echo "Error: $project_dir/$pname does not exist" >&2
+        exit 1
+    fi
+
+    if [ -d "$project_dir/$dir" ]; then
+        echo "Error: $project_dir/$dir already exists" >&2
+        exit 1
+    fi
+done
+
+for project_dir in "$HOME"/current/projects "$HOME"/prog/Python \
+        "$HOME"/Internet/WWW/htdocs/git.phdru.name; do
+    if [ "$project_dir" = "$HOME"/Internet/WWW/htdocs/git.phdru.name ]; then
+        pname="$project_name".git
+    else
+        pname="$project_name"
+    fi
+
+    cd "$project_dir" &&
+    mkdir -p "$dir" &&
+    if [ "$project_dir" = "$HOME"/Internet/WWW/htdocs/git.phdru.name ]; then
+        chmod u=rwX,go=rX "$dir"
+    fi &&
+    mv "$pname" "$dir" &&
+    cd "$dir/$pname" &&
+    for remote in `git remote`; do
+        fix_path "remote.$remote.url"
+    done
+done