aboutsummaryrefslogtreecommitdiff
path: root/contrib/xdg-migrate.sh
blob: d44e546e4ac97c04db35a0d878c20262c8b287d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh

old_path="$HOME/.telescope"

Die() {
	printf 'error: %s\n' "$1" 1>&2
	exit 1
}

[ -e "$old_path" ] || Die "$old_path does not exist."
[ -d "$old_path" ] || Die "$old_path is not a directory."

xdg_config="${XDG_CONFIG_HOME:-$HOME/.config}/telescope"
xdg_data="${XDG_DATA_HOME:-$HOME/.local/share}/telescope"
xdg_cache="${XDG_CACHE_HOME:-$HOME/.cache}/telescope"

mkdir -p "$xdg_config" "$xdg_data" "$xdg_cache"

for filepath in \
	"$xdg_config/config" \
	"$xdg_data/pages" \
	"$xdg_data/bookmarks.gmi" \
	"$xdg_data/known_hosts"
do
	old_file="$old_path/${filepath##*/}"
	[ -e "$old_file" ] && cp -R "$old_file" "filepath"
done

printf "\
WARNING: the old ~/.telescope directory will be removed.

Every file/directory other than the followings has not been copyied:
    - config
    - bookmarks.gmi
    - known_hosts
    - pages/

Are you sure? [Y/n] "

read -r reply
case $reply in
	[yY]) rm -r "$old_path" && printf 'done\n' ;;
esac