44 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
# Interactively select (in skim) an url from Firefox/Chrome/Chromium history to
 | 
						|
# open in your browser (depends on $BROWSER). Should work on Linux and MacOS.
 | 
						|
#
 | 
						|
# requires: sqlite3
 | 
						|
 | 
						|
sep='{{::}}'
 | 
						|
[[ $OSTYPE == linux* ]] && open='xdg-open' || open='open'
 | 
						|
 | 
						|
_do_skim() {
 | 
						|
  for url in $(awk -F "$sep" '{printf "%s, %s\n", $1, $2}' | sk --prompt='history > ' --multi | sed 's#.*\(https*://\)#\1#'); do
 | 
						|
    $open "$url" &
 | 
						|
  done
 | 
						|
}
 | 
						|
 | 
						|
case ${BROWSER:-firefox} in
 | 
						|
  firefox)
 | 
						|
    for dir in ~/.mozilla/firefox/*.default \
 | 
						|
               $XDG_CONFIG_HOME/firefox/.mozilla/firefox/*.default \
 | 
						|
               $XDG_DATA_HOME/mozilla/firefox/*.default \
 | 
						|
               ~/Library/Application\ Support/Firefox/Profiles/*.default; do
 | 
						|
      if [[ -d "$dir" ]]; then
 | 
						|
        sqlite3 -separator $sep "$dir/places.sqlite" \
 | 
						|
          "SELECT DISTINCT title, url FROM moz_places \
 | 
						|
          WHERE title IS NOT NULL \
 | 
						|
          ORDER BY last_visit_date DESC" | _do_skim
 | 
						|
        break
 | 
						|
      fi
 | 
						|
    done
 | 
						|
    ;;
 | 
						|
  *)
 | 
						|
    for dir in ~/.config/google-chrome/Default ~/.config/chromium/Default ~/Library/Application\ Support/Google/Chrome/Default; do
 | 
						|
      if [[ -f "$dir/History" ]]; then
 | 
						|
        cp -f "$dir/History" "/tmp/_h"
 | 
						|
        sqlite3 -separator $sep "/tmp/_h" \
 | 
						|
          "SELECT substr(title, 1, $((COLUMNS / 3))), url \
 | 
						|
          FROM urls ORDER BY last_visit_time DESC" | _do_skim
 | 
						|
        break
 | 
						|
      fi
 | 
						|
    done
 | 
						|
    ;;
 | 
						|
esac
 |