Parse {quick,book}marks and open it in Qutebrowser
This commit is contained in:
		
							parent
							
								
									3e3c377035
								
							
						
					
					
						commit
						4885bd4ec9
					
				
							
								
								
									
										68
									
								
								qb
								
								
								
								
							
							
						
						
									
										68
									
								
								qb
								
								
								
								
							| 
						 | 
				
			
			@ -42,6 +42,9 @@ define_vars() {                                                 # {{{
 | 
			
		|||
	## List of process pattern to monitor
 | 
			
		||||
	qutebrowser_proc_pattern="(qutebrowser)"
 | 
			
		||||
 | 
			
		||||
	## Store selected content to a temp file
 | 
			
		||||
	choice_temp_file="$(mktemp -t ${PROGNAME}-XXXXXX.tmp)"
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
# }}}
 | 
			
		||||
debug_message() {                                               # {{{
 | 
			
		||||
| 
						 | 
				
			
			@ -100,6 +103,66 @@ Start qutebrowser from ${RED}Git repository${COLOR_DEBUG}."
 | 
			
		|||
		~/repos/qutebrowser/qutebrowser.py --backend webengine
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
# }}}
 | 
			
		||||
goto_existing_qutebrowser() {                                   # {{{
 | 
			
		||||
 | 
			
		||||
	debug_message "goto_existing_qutebrowser − \
 | 
			
		||||
Try to open content in existing instance."
 | 
			
		||||
 | 
			
		||||
	search_qb_bookmark \
 | 
			
		||||
		&& open_in_qutebrowser
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
# }}}
 | 
			
		||||
search_qb_bookmark() {                                          # {{{
 | 
			
		||||
 | 
			
		||||
	debug_message "search_qb_bookmark − \
 | 
			
		||||
Search in Qutebrowser's bookmarks."
 | 
			
		||||
 | 
			
		||||
	st -g 90x30+0+540 -n QuteBrowser -t QuteBrowser -e sh -c "cat ~/.config/qutebrowser/quickmarks ~/.config/qutebrowser/bookmarks/urls | fzf +m > ${choice_temp_file}"
 | 
			
		||||
 | 
			
		||||
	if [ -s "${choice_temp_file}" ]; then
 | 
			
		||||
		debug_message "search_qb_bookmark − \
 | 
			
		||||
Store results in ${choice_temp_file}."
 | 
			
		||||
		local_search_qb_bookmark_return="0"
 | 
			
		||||
 | 
			
		||||
	else
 | 
			
		||||
		debug_message "search_qb_bookmark − \
 | 
			
		||||
Search aborded or can't find matching bookmark."
 | 
			
		||||
		local_search_qb_bookmark_return="1"
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	return "${local_search_qb_bookmark_return}"
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
# }}}
 | 
			
		||||
open_in_qutebrowser() {                                         # {{{
 | 
			
		||||
 | 
			
		||||
	local_content=$(cat "${choice_temp_file}")
 | 
			
		||||
 | 
			
		||||
	debug_message "open_in_qutebrowser − \
 | 
			
		||||
Try to manage ${RED}$(cat "${choice_temp_file}")${COLOR_DEBUG}."
 | 
			
		||||
 | 
			
		||||
	case "${local_content}" in
 | 
			
		||||
		http* )   ## Classic bookmark
 | 
			
		||||
			local_url=$(printf "%s" "${local_content}" | sed -e "s;\(http.*\) .*;\1;")
 | 
			
		||||
			debug_message "open_in_qutebrowser − \
 | 
			
		||||
Try to open classic bookmark URL ${RED}${local_url}${COLOR_DEBUG}."
 | 
			
		||||
			;;
 | 
			
		||||
		*http* )  ## Quickmark
 | 
			
		||||
			local_url=$(printf "%s" "${local_content}" | sed -e "s;.*\(http.*\);\1;")
 | 
			
		||||
			debug_message "open_in_qutebrowser − \
 | 
			
		||||
Try to open quickbookmark URL ${RED}${local_url}${COLOR_DEBUG}."
 | 
			
		||||
			;;
 | 
			
		||||
		* )
 | 
			
		||||
			debug_message "open_in_qutebrowser − \
 | 
			
		||||
Not yet managed."
 | 
			
		||||
			;;
 | 
			
		||||
	esac
 | 
			
		||||
 | 
			
		||||
 ~/src/qutebrowser-venv/bin/python3 -m qutebrowser "${local_url}"
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
# }}}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +176,10 @@ main() {                                                        # {{{
 | 
			
		|||
		### Then exit with success
 | 
			
		||||
	is_proc_running "${qutebrowser_proc_pattern}" \
 | 
			
		||||
		|| launch_qutebrowser \
 | 
			
		||||
		&& exit 0
 | 
			
		||||
		|| exit 0
 | 
			
		||||
 | 
			
		||||
	## Manage existing instance
 | 
			
		||||
	goto_existing_qutebrowser
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
# }}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue