-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·192 lines (160 loc) · 5.94 KB
/
install.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/sh
# shellcheck disable=SC2059
set -eu
DIR="$(cd "$(dirname "$0")" && pwd)"
# Install files under in $1/ to $2/ via symlink
install_links() (
mkdir -p "$HOME/.local/share/bin"
mkdir -p "$HOME/.local/share/ref"
mkdir -p "$HOME/.local/bin"
src="$1"; shift
dest="$1"; shift
cd "$src" || return 1
find . -type f | while read -r fn; do
ln_src="$(pwd)/$fn"
ln_dest="$dest/$fn"
mkdir -p "$(dirname "$ln_dest")"
echo "$ln_src => $ln_dest"
ln -s -f "$ln_src" "$ln_dest"
done
)
install_links "$DIR/home" "$HOME"
touch "$HOME/.Xresources.dpi"
touch "$HOME/.Xresources.local"
mkdir -p \
"$HOME/rc.d/sh/pre" \
"$HOME/rc.d/sh/post" \
"$HOME/rc.d/bash/post" \
"$HOME/rc.d/bash/pre" \
"$HOME/rc.d/zsh/post" \
"$HOME/rc.d/zsh/pre"
# ---------
# ADDITIONAL PACKAGES
# ---------
( # --- set up tmux ---
cd "$HOME" || return 1
if ! [ -d ~/.tmux ]; then
git clone https://github.com/gpakosz/.tmux.git
fi
ln -s -f .tmux/.tmux.conf "$HOME/.tmux.conf"
cp "$HOME/.tmux/.tmux.conf.local" "$HOME"
{
printf "\n"
printf "set -g mouse on\n"
printf "set -g set-clipboard on\n"
printf "set-option -g history-limit 500000\n"
} >> "$HOME/.tmux.conf.local"
# `!` to send selection to shell command
cat <<'EOF' >> "$HOME/.tmux.conf.local"
# {{{ linux-settings-kfl
# Customized left/right pane style, disables funky unicode characters so tmux
# displays properly with double width east asian encodings
tmux_conf_theme_status_left="#S | #{?uptime_y, #{uptime_y}y,}#{?uptime_d, #{uptime_d}d,}#{?uptime_h, #{uptime_h}h,}#{?uptime_m, #{uptime_m}m,} "
tmux_conf_theme_status_right=" %R , %d %b | #{username}#{root} | #{hostname} "
tmux_conf_copy_to_os_clipboard=true
set -sg repeat-time 400 # increase repeat timeout
# Revert .tmux.conf's use of screen-compatible prefix c-a
set -ug prefix2
unbind C-a
bind-key -T copy-mode ! command-prompt -p "cmd:" "send-keys -X copy-selection-no-clear \; run-shell \"tmux show-buffer | %1\" "
bind-key -T copy-mode-vi ! command-prompt -p "cmd:" "send-keys -X copy-selection-no-clear \; run-shell \"tmux show-buffer | %1\" "
# easy swapping panes
bind-key -T prefix C-s display-panes \; command-prompt -p "<pane1>:,<pane2>:" "swap-pane -s %1 -t %2"
# Make tmux copy mode more persistent:
#
# - copy action does not escape copy mode
# - pressing esc key does not escape copy mode (use 'q' isntead)
#
# Must wrap binding in `run -b 'tmux ...'` in order to override ones already
# defined in .tmux.conf
# See: https://github.com/gpakosz/.tmux/issues/571
run -b 'tmux bind-key -T copy-mode-vi Escape send-keys -X clear-selection 2> /dev/null || true'
run -b 'tmux bind-key -T copy-mode-vi q send-keys -X cancel 2> /dev/null || true'
run -b 'tmux bind -T copy-mode-vi y send -X copy-selection 2> /dev/null || true'
# copy-pipe, but do NOT cancel the selection
run -b 'tmux bind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe'
run -b 'tmux bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe'
# tmux.conf hijacked pref-m to be toggle mouse. I need marking pane more.
run -b 'tmux bind-key m select-pane -m'
# Use ASCII chars for pane separators. -q to noop for older tmux where it's not
# supported
set -gq pane-border-lines simple
set -gq word-seperators ' []()'
# }}} linux-settings-kfl
EOF
)
( # -- vim settings --
echo "Installing vim-settings-kfl"
cd "$HOME" || return 1
git clone https://github.com/kflu/vim-settings-kfl.git
sh "$HOME/vim-settings-kfl/install.sh"
) || true
( # -- oh my zsh --
echo "Installing ohmyzsh..."
CHSH=no \
RUNZSH=no \
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
) || true
( # -- fzf --
echo "Installing fzf..."
cd "$HOME" || return 1
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install --all
) || true
( # -- recipes --
ln -s -f "$DIR/recipes" "$HOME/.recipes"
ln -s "$DIR/rr" "$HOME/rr"
) || true
( # --- INSTALL FLUXBOX ---
mkdir -p "$HOME/.fluxbox"
# copy .fluxbox dir hier (trailing slash is important)
cp -R "$DIR/home_cp/.fluxbox/" "$HOME/.fluxbox"
cat <<FLUXBOX_INIT > ~/.fluxbox/init
session.screen0.toolbar.tools: prevworkspace, workspacename, nextworkspace, iconbar, systemtray, clock, RootMenu
session.menuFile: ~/.fluxbox/menu
session.keyFile: ~/.fluxbox/keys
# session.styleFile: $HOME/.fluxbox/styles/Dyne
FLUXBOX_INIT
)
# Update file content enclosed by $marker. If marker enclosure doesn't exist,
# append the enclosure, and put content in it.
# It ensures the $file to exist by touching it.
# <this> <file> <marker> <content_in_markers>
uppend_file_content() (
file="$1"; shift
marker="$1"; shift
content="$1"; shift
touch "$file"
tmp="$file.uppend_file_content.$(date +"%Y%m%d_%H%M%S")"
cp "$file" "$tmp"
echo "[uppend_file_content] Backed up to $tmp"
(
has_marker=
state=
while read -r line; do
case "$state" in
'')
echo "$line"
{ echo "$line" | grep -Fq "$marker"; } && state=BEGIN
;;
BEGIN)
{ echo "$line" | grep -Fq "$marker"; } && {
state=
has_marker=1
echo "$content"
echo "$line" # closing marker
}
;;
esac
done <"$tmp"
if [ -z "$has_marker" ]; then
echo "$marker"
echo "$content"
echo "$marker"
fi
) >"$file"
)
uppend_file_content ~/.profile "# == profile.mine ==" "source $DIR/profile.mine"
uppend_file_content ~/.zprofile "# == profile.mine ==" "source $DIR/profile.mine"
uppend_file_content ~/.zshrc "# == zshrc.mine ==" "source $DIR/zshrc.mine"
uppend_file_content ~/.bashrc "# == bashrc.mine ==" "source $DIR/bashrc.mine"