Add linkwarden for qutebrowser
This commit is contained in:
		
							parent
							
								
									f0c444ce6c
								
							
						
					
					
						commit
						cc1c39d20d
					
				
					 6 changed files with 97 additions and 0 deletions
				
			
		
							
								
								
									
										39
									
								
								.config/qutebrowser/userscripts/qutebrowser-linkwarden
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										39
									
								
								.config/qutebrowser/userscripts/qutebrowser-linkwarden
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
get_collections() {
 | 
			
		||||
  curl -H "Authorization: Bearer $LINKWARDEN_TOKEN" \
 | 
			
		||||
    -H "Accept: application/json" \
 | 
			
		||||
    "$LINKWARDEN_URL/api/v1/collections" 2>/dev/null \
 | 
			
		||||
    | jq -r '.response | map_values(.name)[]'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
collection=$(get_collections | $DMENU -p "Collection: ")
 | 
			
		||||
url=$QUTE_URL
 | 
			
		||||
name=$(echo "$QUTE_TITLE" | $DMENU -p "Title: ")
 | 
			
		||||
 | 
			
		||||
payload=$(jq -n \
 | 
			
		||||
  --arg u "$url" \
 | 
			
		||||
  --arg n "$name" \
 | 
			
		||||
  --arg c "$collection" \
 | 
			
		||||
  '{
 | 
			
		||||
    url: $u,
 | 
			
		||||
    name: $n,
 | 
			
		||||
    collection: {name: $c},
 | 
			
		||||
    tags: []
 | 
			
		||||
  }')
 | 
			
		||||
 | 
			
		||||
response=$(curl -sS --fail-with-body \
 | 
			
		||||
  -H "Authorization: Bearer $LINKWARDEN_TOKEN" \
 | 
			
		||||
  -H "Accept: application/json" \
 | 
			
		||||
  -H "Content-Type: application/json" \
 | 
			
		||||
  -X POST \
 | 
			
		||||
  -d "$payload" \
 | 
			
		||||
  "$LINKWARDEN_URL/api/v1/links" 2>&1)
 | 
			
		||||
 | 
			
		||||
code="$?"
 | 
			
		||||
 | 
			
		||||
if [ "$code" -ne 0 ]
 | 
			
		||||
then
 | 
			
		||||
  response=$(echo "$response" | sed 's/"/\\"/g' | sed 's/$/ - /g' | tr -d '\n' | sed 's/ - $//g')
 | 
			
		||||
  echo "message-error \"Failed to save link: $response\"" >> "$QUTE_FIFO"
 | 
			
		||||
fi
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue