]> git.phdru.name Git - cookiecutter.git/blob - rename-project
CI(appveyor.yml): Upgrade `pip` using `python -m pip`
[cookiecutter.git] / rename-project
1 #! /bin/sh
2
3 if [ -z "$2" -o -n "$3" ]; then
4    echo "Usage: $0 old_name new_name" >&2
5    exit 1
6 fi
7
8 old_name="$1"
9 new_name="$2"
10
11 fix_path() {
12    config_option="$1"
13    path="`git config --get $config_option`"
14    new_path="`echo \"$path\" | sed \"s@$old_name@$new_name@\"`"
15    git config "$config_option" "$new_path"
16 }
17
18 fix_files() {
19    for file in "$@"; do
20       if [ -f "$file" ]; then
21          sed -i /"$old_name"/"$new_name"/g "$file"
22       fi
23    done
24 }
25
26 for project_dir in "$HOME"/prog/Python "$HOME"/current/projects \
27       "$HOME"/Internet/WWW/htdocs/git.phdru.name; do
28    cd "$project_dir" &&
29    if [ -d "$old_name" ]; then
30       mv "$old_name" "$new_name" &&
31       cd "$new_name"
32    elif [ -d "$old_name.git" ]; then
33       mv "$old_name".git "$new_name".git &&
34       cd "$new_name".git
35    else
36       continue
37    fi
38    for remote in `git remote`; do
39       fix_path "remote.$remote.url"
40    done
41    path="`git config --get --path htdocs.path`"
42    if [ -n "$path" ]; then
43       (
44          cd /home/phd/Internet/WWW/htdocs/phdru.name/Software/Python/ &&
45          if [ -d "$old_name" ]; then
46             mv "$old_name" "$new_name" &&
47             cd "$new_name" &&
48             mv "$old_name"-*.tar.bz2 "$new_name".tar.bz2 &&
49             fix_files index.tmpl
50          fi
51       ) &&
52       fix_path htdocs.path
53    fi
54    fix_files devscripts/README.html \
55       docs/conf.py docs/genapidocs docs/index.rst docs/install.rst \
56       README.rst mk-distr setup.py tox.ini
57 done