-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchromium_utils.sh
More file actions
171 lines (134 loc) · 4.44 KB
/
chromium_utils.sh
File metadata and controls
171 lines (134 loc) · 4.44 KB
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
#!/usr/bin/env bash
chromium.search.keywords() {
local func_name="${FUNCNAME[0]}"
local chromium_config="$HOME/.config/chromium"
local db_file="Web Data"
local db_path=""
local profile_dir_default="Default"
local columns_default="short_name,keyword,url"
local usage="
Usage: $func_name [--csv] [--columns] <chromium_profile>
Queries the Chrome profile's search engines from the Web Data SQLite DB.
Parameters:
<chromium_profile> The full path or name of the Chrome profile directory.
| If only the name is given, it is resolved inside:
| ${chromium_config}
--csv Print as a CSV
--columns Specify columns: ${columns_default}
-h, --help Show this help message
Example:
$func_name Default
$func_name \"/home/user/.config/google-chrome/Profile 3\"
$func_name --csv --columns url Default
"
local opt_csv=0
[[ " $* " =~ ' --csv ' ]] && { shift 1; opt_csv=1; }
local opt_columns=""
[[ " $* " =~ ' --columns ' ]] && { shift 1; opt_columns=${1}; shift 1; }
local columns="${opt_columns:-"${columns_default}"}"
local profile_input="${1:-"${profile_dir_default}"}"
local sql_keywords_select="SELECT ${columns} FROM keywords;"
# [[ $# -eq 0 || $1 == "-h" || $1 == "--help" ]]
[[ " $* " =~ ' -h ' || " $* " =~ ' --help ' ]] && { echo -e "${usage}"; return 0; }
local profile_path=""
if [[ "${profile_input}" != /* ]]; then
profile_path="${chromium_config}/${profile_input}"
else
profile_path="${profile_input}"
fi
db_path="$profile_path/$db_file"
if [[ ! -f "$db_path" ]]; then
echo "Error: SQLite DB file not found at: $db_path" >&2
return 1
fi
(( !!opt_csv )) && { sqlite3 -csv "${db_path}" "${sql_keywords_select}"; return $?; }
sqlite3 -header -column "${db_path}" "${sql_keywords_select}"
}
chromium.search.engines() {
chromium.search.keywords "$@"
return $?
}
# chromium.cache.clearAll() {
# rm -r ~/.config/chromium/*/Service Worker/CacheStorage
# # "$@"
# return $?
# }
# chromium.search.keywords.merge() {
# local func_name="${FUNCNAME[0]}"
# local chromium_config="$HOME/.config/chromium" # Adjust to your OS/path if needed
# local profile_dir=""
# local dbfile="Web Data"
# local dbpath=""
# local usage="
# Usage: $func_name <chromium_profile>
# Queries the Chrome profile's search engines from the Web Data SQLite DB.
# Parameters:
# <chromium_profile> The full path or name of the Chrome profile directory.
# | If only the name is given, it is resolved inside:
# | $chromium_config
# Example:
# $func_name Default
# $func_name /home/user/.config/google-chrome/Profile 3
# "
# src_db="$1"
# dst_db="$2"
# tmpfile=$(mktemp)
# local sql_keywords_select="SELECT short_name, keyword, url FROM keywords;"
# sqlite3 -csv "$src_db" "${sql_keywords_select}" > "$tmpfile.src"
# sqlite3 -csv "$dst_db" "${sql_keywords_select}" > "$tmpfile.dst"
# cat "$tmpfile.src" "$tmpfile.dst" | sort | uniq >"$tmpfile.merged"
# sqlite3 "$dst_db" "DELETE FROM keywords;"
# while IFS=, read -r keyword url short_name; do
# sqlite3 "$dst_db" \
# "INSERT INTO keywords (keyword, url, short_name) VALUES ('$keyword', '$url', '$short_name');"
# done <"$tmpfile.merged"
# rm -f "$tmpfile"*
# }
#chromium.fonts.merge() {}
chromium.ext.ls() {
local profile="Default"
local file=""
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
cat <<- EOF
Usage: ${FUNCNAME[0]} [OPTIONS] [PROFILE]
List enabled Chromium extensions
Options:
-b, --browser BROWSER Browser prefix (default: chromium)
-p, --profile PROFILE Profile name (default: Default)
-f, --file FILE Direct path to Preferences file
-h, --help Show help
Examples:
${FUNCNAME[0]}
${FUNCNAME[0]} 'Profile 1'
${FUNCNAME[0]} -p 'Profile 1'
${FUNCNAME[0]} -f ~/custom/Preferences
EOF
return 0
;;
-p|--profile)
profile="$2"
shift 2
;;
-b|--browser)
browser="$2"
shift 2
;;
-f|--file)
file="$2"
shift 2
;;
*)
profile="$1"
shift
;;
esac
done
local prefs_file="${file:-$HOME/.config/${browser:-chromium}/$profile/Preferences}"
[[ ! -f "$prefs_file" ]] && { echo "Error: File not found: $prefs_file" >&2; return 1; }
jq -r '.extensions.settings | to_entries[] | select((.value.disable_reasons // []) | length == 0) | "\(.value.manifest.name)|\(.key)"' \
"$prefs_file"
}
#chromium.ext.merge() {}
#chromium.ext.conf.merge() {}