-
Notifications
You must be signed in to change notification settings - Fork 0
/
chrome-bookmarks
executable file
·39 lines (33 loc) · 1.07 KB
/
chrome-bookmarks
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
#!/usr/bin/perl
my $profile = "Default";
my $reason = "";
my $chromeLib= "Library/Application Support/Google/Chrome";
chdir("$ENV{HOME}/${chromeLib}") || die "Cannot cd to Chrome's app support: $!\n";
my @profiles = <*/Bookmarks>;
if(scalar @ARGV > 0) {
# prefer command-line profile argument
$profile = $ARGV[0];
$reason = " [command argument]";
} elsif(scalar @profiles > 1) {
# otherwise default to largest Bookmarks file
my @sorted = sort { -s $b <=> -s $a } @profiles;
my $largest = shift @sorted;
if($largest =~ m#(.*)/Bookmarks#) {
$profile = ${1};
$reason = " [largest profile under ${chromeLib}]"
}
}
# Alert user to which profile being used, and why
print("# Using profile \"$profile\"$reason\n");
my $home = $ENV{"HOME"};
open(PIPE, "chrome-timestamp-parse < \"${home}/Library/Application Support/Google/Chrome/$profile/Bookmarks\"|")
|| die "Cannot run \"chrome-timestamp-parse\": $!\n";
my $date="???";
while(<PIPE>) {
if(/"date_added": "(\d\d\d\d-\d\d-\d\d) (\d\d\d\d\.\d\d)/) {
$date="${1}.${2}";
}
if(m#"name": "(.*)",#) {
print ("${date}: $1\n");
}
}