Created
May 28, 2017 20:32
-
-
Save pkillnine/310e0d86ffc2ed21d6d45a2f43f9b271 to your computer and use it in GitHub Desktop.
history-page userscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
QBDATA_HISTORY_FILE="$HOME"/.local/share/qutebrowser/history | |
QBHISTORYLIST_TMP_FILE=/tmp/qbhistorylist | |
HISTORY_PAGE_HTML_FILE=/tmp/qbhistory.html | |
function produce_list_body() { | |
sort -r $QBDATA_HISTORY_FILE |#sort by most recent | |
cut -d " " -f 2- |#remove first column (times) | |
grep -v "^data:" |#remove urls with "data:" | |
awk '!a[$1]++' |#remove duplicate urls | |
sed -e "s/\&/\&/g" -e "s/</\</g" -e "s/>/\>/g" |#deactive html in titles and perhaps urls | |
awk '{$1 = "<a href="$1">"$1"</a>"; print $0, "<br>"}' |#make urls clickable and on their own lines | |
grep -i "$searchquery" #filter by search query (SEARCHQUERY is defined at the first if statement) | |
} | |
function produce_html_file() { | |
produce_list_body > $QBHISTORYLIST_TMP_FILE | |
total_urls=$(wc -l $QBHISTORYLIST_TMP_FILE | awk '{print $1}') | |
echo "<!DOCTYPE HTML><HTML><HEAD><META CHARSET="UTF-8"></HEAD><BODY>" > $HISTORY_PAGE_HTML_FILE | |
cat /tmp/qbhistorylist >> $HISTORY_PAGE_HTML_FILE | |
echo "<br>Total URLs: $total_urls <br>" >> $HISTORY_PAGE_HTML_FILE | |
} | |
if (( $# == 0 )); then | |
searchquery="." #this is regex that represents any character | |
elif (( $# > 0 )); then | |
searchquery=$@ | |
fi | |
produce_html_file | |
if [[ "$QUTE_URL" == "file://$HISTORY_PAGE_HTML_FILE" ]]; then | |
echo "open file://$HISTORY_PAGE_HTML_FILE" >> "$QUTE_FIFO" | |
else | |
echo "open -t file://$HISTORY_PAGE_HTML_FILE" >> "$QUTE_FIFO" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment