-
Notifications
You must be signed in to change notification settings - Fork 3
/
mklink_rc.sh
executable file
·135 lines (116 loc) · 2.76 KB
/
mklink_rc.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
##########################################################
# make symbolic links to dotfiles
##########################################################
#set -o noglob
#####################
# constants
#####################
declare -r SCRIPT_NAME=${0##*/}
tmp_src_dir_name=$(dirname "$0")
declare -r SRC_DIR_NAME=${tmp_src_dir_name}
declare -r DEST_DIR_NAME=${HOME}
declare -ar DOTFILES=(
'dot.atoolrc'
'dot.bash_profile'
'dot.bashrc'
'dot.emacs'
'dot.gitconfig'
'dot.gitignore'
'dot.gvimrc'
'dot.inputc'
'dot.npmrc'
'dot.screenrc'
'dot.tmux.conf'
'dot.vim'
'dot.vimrc'
'dot.vimplug.vim'
'dot.Xmodmap'
'dot.zshenv'
'dot.zlogin'
'dot.zprofile'
'dot.zshrc'
'dot.zlogout'
'dot.peco_config.json'
'dot.config/bat/config'
'dot.config/alacritty/alacritty.toml'
'dot.config/wezterm/wezterm.lua'
'dot.config/fish/config.fish'
'dot.config/fish/config_linux.fish'
'dot.config/fish/config_mac.fish'
'dot.config/fish/fish_plugins'
'dot.config/fish/functions/fish_user_key_bindings.fish'
'dot.config/fish/functions/user_z_select_and_change_directory.fish'
)
#####################
# functions
#####################
print_usage()
{
cat << EOF
Usage: $SCRIPT_NAME [-df]
Make symbolic links to dotfiles in HOME.
-d dry run
not make link, but display ln command
[default]
-f make link actually
-h display this help and exit
EOF
}
print_error()
{
echo "$SCRIPT_NAME: $*" 1>&2
echo "Try \`-h' option for more information." 1>&2
}
# create dest filename by link src filename
get_dest_filename()
{
# complex sed substitution is required
# shellcheck disable=SC2001
echo "${1}" | sed -e 's/^dot\././'
}
#####################
# main
#####################
# false : not make link
# true : make link actually
make_link="false"
while getopts ':fdh' option; do
case $option in
f)
make_link="true"
;;
d)
make_link="false"
;;
h)
print_usage
exit 0
;;
:) # option argument is missing
print_error "option requires an argument -- $OPTARG"
exit 1
;;
*) # unknown option
print_error "invalid option -- $OPTARG"
exit 1
;;
esac
done
shift $((OPTIND - 1))
cd "$SRC_DIR_NAME" || exit
for src_filename in "${DOTFILES[@]}"; do
dest_filename=$(get_dest_filename "$src_filename")
if [ -e "${DEST_DIR_NAME}/${dest_filename}" ]; then
# skip file which already exists
continue
fi
if [ "$make_link" == "true" ]; then
# make link actually
ln -s "${PWD}/${src_filename}" "${DEST_DIR_NAME}/${dest_filename}"
else
# not make link, but echo command
echo ln -s "${PWD}/${src_filename}" "${DEST_DIR_NAME}/${dest_filename}"
fi
done
exit $?