Skip to content

Commit 03890d0

Browse files
committed
Tweak structure of files.sh
1 parent bfc07aa commit 03890d0

File tree

2 files changed

+135
-131
lines changed

2 files changed

+135
-131
lines changed

sdata/subcmd-install/3.files-legacy.sh

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -3,132 +3,7 @@
33

44
# shellcheck shell=bash
55

6-
function gen_firstrun(){
7-
x mkdir -p "$(dirname ${FIRSTRUN_FILE})"
8-
x touch "${FIRSTRUN_FILE}"
9-
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
10-
realpath -se "${FIRSTRUN_FILE}" >> "${INSTALLED_LISTFILE}"
11-
}
12-
cp_file(){
13-
# NOTE: This function is only for using in other functions
14-
x mkdir -p "$(dirname $2)"
15-
x cp -f "$1" "$2"
16-
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
17-
realpath -se "$2" >> "${INSTALLED_LISTFILE}"
18-
}
19-
rsync_dir(){
20-
# NOTE: This function is only for using in other functions
21-
x mkdir -p "$2"
22-
local dest="$(realpath -se $2)"
23-
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
24-
rsync -a --out-format='%i %n' "$1"/ "$2"/ | awk -v d="$dest" '$1 ~ /^>/{ sub(/^[^ ]+ /,""); printf d "/" $0 "\n" }' >> "${INSTALLED_LISTFILE}"
25-
}
26-
rsync_dir__sync(){
27-
# NOTE: This function is only for using in other functions
28-
x mkdir -p "$2"
29-
local dest="$(realpath -se $2)"
30-
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
31-
rsync -a --delete --out-format='%i %n' "$1"/ "$2"/ | awk -v d="$dest" '$1 ~ /^>/{ sub(/^[^ ]+ /,""); printf d "/" $0 "\n" }' >> "${INSTALLED_LISTFILE}"
32-
}
33-
function install_file(){
34-
# NOTE: Do not add prefix `v` or `x` when using this function
35-
local s=$1
36-
local t=$2
37-
if [ -f $t ];then
38-
warning_overwrite
39-
fi
40-
v cp_file $s $t
41-
}
42-
function install_file__auto_backup(){
43-
# NOTE: Do not add prefix `v` or `x` when using this function
44-
local s=$1
45-
local t=$2
46-
if [ -f $t ];then
47-
echo -e "${STY_YELLOW}[$0]: \"$t\" already exists.${STY_RST}"
48-
if ${INSTALL_FIRSTRUN};then
49-
echo -e "${STY_BLUE}[$0]: It seems to be the firstrun.${STY_RST}"
50-
v mv $t $t.old
51-
v cp_file $s $t
52-
else
53-
echo -e "${STY_BLUE}[$0]: It seems not a firstrun.${STY_RST}"
54-
v cp_file $s $t.new
55-
fi
56-
else
57-
echo -e "${STY_GREEN}[$0]: \"$t\" does not exist yet.${STY_RST}"
58-
v cp_file $s $t
59-
fi
60-
}
61-
function install_dir(){
62-
# NOTE: Do not add prefix `v` or `x` when using this function
63-
local s=$1
64-
local t=$2
65-
if [ -d $t ];then
66-
warning_overwrite
67-
fi
68-
rsync_dir $s $t
69-
}
70-
function install_dir__sync(){
71-
# NOTE: Do not add prefix `v` or `x` when using this function
72-
local s=$1
73-
local t=$2
74-
if [ -d $t ];then
75-
warning_overwrite
76-
fi
77-
rsync_dir__sync $s $t
78-
}
79-
function install_dir__skip_existed(){
80-
# NOTE: Do not add prefix `v` or `x` when using this function
81-
local s=$1
82-
local t=$2
83-
if [ -d $t ];then
84-
echo -e "${STY_BLUE}[$0]: \"$t\" already exists, will not do anything.${STY_RST}"
85-
else
86-
echo -e "${STY_YELLOW}[$0]: \"$t\" does not exist yet.${STY_RST}"
87-
v rsync_dir $s $t
88-
fi
89-
}
90-
function install_google_sans_flex(){
91-
local font_name="Google Sans Flex"
92-
local src_name="google-sans-flex"
93-
local src_url="https://github.com/end-4/google-sans-flex"
94-
local src_dir="$REPO_ROOT/cache/$src_name"
95-
local target_dir="${XDG_DATA_HOME}/fonts/illogical-impulse-$src_name"
96-
if fc-list | grep -qi "$font_name"; then return; fi
97-
x mkdir -p $src_dir
98-
x cd $src_dir
99-
try git init -b main
100-
try git remote add origin $src_url
101-
x git pull origin main
102-
x git submodule update --init --recursive
103-
warning_overwrite
104-
rsync_dir "$src_dir" "$target_dir"
105-
x fc-cache -fv
106-
x cd $REPO_ROOT
107-
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
108-
realpath -se "$2" >> "${INSTALLED_LISTFILE}"
109-
}
110-
1116
#####################################################################################
112-
# In case some dirs does not exists
113-
v mkdir -p $XDG_BIN_HOME $XDG_CACHE_HOME $XDG_CONFIG_HOME $XDG_DATA_HOME
114-
115-
case "${INSTALL_FIRSTRUN}" in
116-
# When specify --firstrun
117-
true) sleep 0 ;;
118-
# When not specify --firstrun
119-
*)
120-
if test -f "${FIRSTRUN_FILE}"; then
121-
INSTALL_FIRSTRUN=false
122-
else
123-
INSTALL_FIRSTRUN=true
124-
fi
125-
;;
126-
esac
127-
128-
# `--delete' for rsync to make sure that
129-
# original dotfiles and new ones in the SAME DIRECTORY
130-
# (eg. in ~/.config/hypr) won't be mixed together
131-
1327
# MISC (For dots/.config/* but not quickshell, not fish, not Hyprland, not fontconfig)
1338
case "${SKIP_MISCCONF}" in
1349
true) sleep 0;;
@@ -192,8 +67,3 @@ case "${SKIP_HYPRLAND}" in
19267
esac
19368

19469
install_file "dots/.local/share/icons/illogical-impulse.svg" "${XDG_DATA_HOME}"/icons/illogical-impulse.svg
195-
showfun install_google_sans_flex
196-
v install_google_sans_flex
197-
198-
v dedup_and_sort_listfile "${INSTALLED_LISTFILE}" "${INSTALLED_LISTFILE}"
199-
v gen_firstrun

sdata/subcmd-install/3.files.sh

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ function warning_overwrite(){
99
printf "The command below overwrites the destination.\n"
1010
printf "${STY_RST}"
1111
}
12-
1312
function auto_backup_configs(){
1413
local backup=false
1514
case $ask in
@@ -38,8 +37,135 @@ function auto_backup_configs(){
3837
printf "${STY_BLUE}Backup into \"${BACKUP_DIR}\" finished.${STY_RST}\n"
3938
fi
4039
}
40+
function gen_firstrun(){
41+
x mkdir -p "$(dirname ${FIRSTRUN_FILE})"
42+
x touch "${FIRSTRUN_FILE}"
43+
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
44+
realpath -se "${FIRSTRUN_FILE}" >> "${INSTALLED_LISTFILE}"
45+
}
46+
cp_file(){
47+
# NOTE: This function is only for using in other functions
48+
x mkdir -p "$(dirname $2)"
49+
x cp -f "$1" "$2"
50+
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
51+
realpath -se "$2" >> "${INSTALLED_LISTFILE}"
52+
}
53+
rsync_dir(){
54+
# NOTE: This function is only for using in other functions
55+
x mkdir -p "$2"
56+
local dest="$(realpath -se $2)"
57+
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
58+
rsync -a --out-format='%i %n' "$1"/ "$2"/ | awk -v d="$dest" '$1 ~ /^>/{ sub(/^[^ ]+ /,""); printf d "/" $0 "\n" }' >> "${INSTALLED_LISTFILE}"
59+
}
60+
rsync_dir__sync(){
61+
# NOTE: This function is only for using in other functions
62+
# `--delete' for rsync to make sure that
63+
# original dotfiles and new ones in the SAME DIRECTORY
64+
# (eg. in ~/.config/hypr) won't be mixed together
65+
x mkdir -p "$2"
66+
local dest="$(realpath -se $2)"
67+
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
68+
rsync -a --delete --out-format='%i %n' "$1"/ "$2"/ | awk -v d="$dest" '$1 ~ /^>/{ sub(/^[^ ]+ /,""); printf d "/" $0 "\n" }' >> "${INSTALLED_LISTFILE}"
69+
}
70+
function install_file(){
71+
# NOTE: Do not add prefix `v` or `x` when using this function
72+
local s=$1
73+
local t=$2
74+
if [ -f $t ];then
75+
warning_overwrite
76+
fi
77+
v cp_file $s $t
78+
}
79+
function install_file__auto_backup(){
80+
# NOTE: Do not add prefix `v` or `x` when using this function
81+
local s=$1
82+
local t=$2
83+
if [ -f $t ];then
84+
echo -e "${STY_YELLOW}[$0]: \"$t\" already exists.${STY_RST}"
85+
if ${INSTALL_FIRSTRUN};then
86+
echo -e "${STY_BLUE}[$0]: It seems to be the firstrun.${STY_RST}"
87+
v mv $t $t.old
88+
v cp_file $s $t
89+
else
90+
echo -e "${STY_BLUE}[$0]: It seems not a firstrun.${STY_RST}"
91+
v cp_file $s $t.new
92+
fi
93+
else
94+
echo -e "${STY_GREEN}[$0]: \"$t\" does not exist yet.${STY_RST}"
95+
v cp_file $s $t
96+
fi
97+
}
98+
function install_dir(){
99+
# NOTE: Do not add prefix `v` or `x` when using this function
100+
local s=$1
101+
local t=$2
102+
if [ -d $t ];then
103+
warning_overwrite
104+
fi
105+
rsync_dir $s $t
106+
}
107+
function install_dir__sync(){
108+
# NOTE: Do not add prefix `v` or `x` when using this function
109+
local s=$1
110+
local t=$2
111+
if [ -d $t ];then
112+
warning_overwrite
113+
fi
114+
rsync_dir__sync $s $t
115+
}
116+
function install_dir__skip_existed(){
117+
# NOTE: Do not add prefix `v` or `x` when using this function
118+
local s=$1
119+
local t=$2
120+
if [ -d $t ];then
121+
echo -e "${STY_BLUE}[$0]: \"$t\" already exists, will not do anything.${STY_RST}"
122+
else
123+
echo -e "${STY_YELLOW}[$0]: \"$t\" does not exist yet.${STY_RST}"
124+
v rsync_dir $s $t
125+
fi
126+
}
127+
function install_google_sans_flex(){
128+
local font_name="Google Sans Flex"
129+
local src_name="google-sans-flex"
130+
local src_url="https://github.com/end-4/google-sans-flex"
131+
local src_dir="$REPO_ROOT/cache/$src_name"
132+
local target_dir="${XDG_DATA_HOME}/fonts/illogical-impulse-$src_name"
133+
if fc-list | grep -qi "$font_name"; then return; fi
134+
x mkdir -p $src_dir
135+
x cd $src_dir
136+
try git init -b main
137+
try git remote add origin $src_url
138+
x git pull origin main
139+
x git submodule update --init --recursive
140+
warning_overwrite
141+
rsync_dir "$src_dir" "$target_dir"
142+
x fc-cache -fv
143+
x cd $REPO_ROOT
144+
x mkdir -p "$(dirname ${INSTALLED_LISTFILE})"
145+
realpath -se "$2" >> "${INSTALLED_LISTFILE}"
146+
}
41147

42148
#####################################################################################
149+
# In case some dirs does not exists
150+
for i in "$XDG_BIN_HOME" "$XDG_CACHE_HOME" "$XDG_CONFIG_HOME" "$XDG_DATA_HOME"; do
151+
if ! test -e "$i"; then
152+
v mkdir -p "$i"
153+
fi
154+
done
155+
case "${INSTALL_FIRSTRUN}" in
156+
# When specify --firstrun
157+
true) sleep 0 ;;
158+
# When not specify --firstrun
159+
*)
160+
if test -f "${FIRSTRUN_FILE}"; then
161+
INSTALL_FIRSTRUN=false
162+
else
163+
INSTALL_FIRSTRUN=true
164+
fi
165+
;;
166+
esac
167+
168+
43169
showfun auto_update_git_submodule
44170
v auto_update_git_submodule
45171

@@ -51,6 +177,14 @@ case "${EXPERIMENTAL_FILES_SCRIPT}" in
51177
*)source sdata/subcmd-install/3.files-legacy.sh;;
52178
esac
53179

180+
showfun install_google_sans_flex
181+
v install_google_sans_flex
182+
183+
#####################################################################################
184+
185+
v gen_firstrun
186+
v dedup_and_sort_listfile "${INSTALLED_LISTFILE}" "${INSTALLED_LISTFILE}"
187+
54188
# Prevent hyprland from not fully loaded
55189
sleep 1
56190
try hyprctl reload

0 commit comments

Comments
 (0)