bmks (2497B)
1 #! /bin/bash 2 3 # set prefered launcher 4 PREFERED_LAUNCHER=dmenu 5 # set path where urls will be stored 6 URL_FILE_PATH=$HOME/.bmks/ 7 # name of file urls will be stored in 8 URL_FILE_NAME=urls 9 10 show_usage() { 11 printf "bmks: unix bookmark management that sucks less 12 13 usage: 14 bmks help 15 show this help message 16 bmks add <url> 17 add a new bookmark 18 bmks del 19 remove a bookmark 20 bmks ls 21 show all bookmarks 22 bmks dmenu 23 manual switch for displaying bookmarks in dmenu 24 bmks fzf 25 manual switch for displaying bookmarks in fzf 26 27 Configuration is done by directly editing the script. Two launchers are available (dmenu and fzf). You can specify which one to use by adding to the PREFERED_LAUNCHER variable directly in the script. Both will display a menu that will allow you to choose a bookmark and open it in your default browser. 28 29 If you would prefer to have your bookmarks stored in alternate location there are also variables that can be changed for that. The default is /home/user/.bmks/urls\n" 30 } 31 32 bmks_add() { 33 [ -z "$url" ] && printf "Error: url must be provided\n\n" && show_usage && exit 0 34 printf "Description: " 35 read description 36 [ -z "$description" ] && echo "$url" >> $URL_FILE_PATH/$URL_FILE_NAME 37 [ -n "$description" ] && echo "$description - $url" >> $URL_FILE_PATH/$URL_FILE_NAME 38 } 39 40 bmks_ls() { 41 bmks_check 42 cat $URL_FILE_PATH/$URL_FILE_NAME | sort 43 } 44 45 bmks_del() { 46 bmks_check 47 case $PREFERED_LAUNCHER in 48 dmenu) sed -i "/$(cat $URL_FILE_PATH/$URL_FILE_NAME | sort | dmenu -l $(cat $URL_FILE_PATH/$URL_FILE_NAME | wc -l))/d" $URL_FILE_PATH/$URL_FILE_NAME ;; 49 fzf) sed -i "/$(cat $URL_FILE_PATH/$URL_FILE_NAME | sort | fzf)/d" $URL_FILE_PATH/$URL_FILE_NAME ;; 50 esac 51 } 52 53 bmks_display() { 54 bmks_check 55 case $PREFERED_LAUNCHER in 56 dmenu) cat $URL_FILE_PATH/$URL_FILE_NAME | sort | dmenu -l $(cat $URL_FILE_PATH/$URL_FILE_NAME | wc -l) | awk '{print $(NF)}' | xargs -I '{}' $BROWSER {} ;; 57 fzf) cat $URL_FILE_PATH/$URL_FILE_NAME | sort | fzf | awk '{print $(NF)}' | xargs -I '{}' $BROWSER {} ;; 58 esac 59 } 60 61 bmks_check() { 62 [ ! -s $URL_FILE_PATH/$URL_FILE_NAME ] && printf "Error: No bookmarks found to display. Try adding some!\n\n" && show_usage && exit 0 63 } 64 65 [ ! -d $URL_FILE_PATH ] && mkdir $URL_FILE_PATH 66 [ ! -f $URL_FILE_PATH/$URL_FILE_NAME ] && touch $URL_FILE_PATH/$URL_FILE_NAME 67 68 case "$1" in 69 "help") show_usage ;; 70 "add") url=$2; bmks_add ;; 71 "del") bmks_del ;; 72 "ls") bmks_ls ;; 73 "dmenu") PREFERED_LAUNCHER=$1; bmks_display ;; 74 "fzf") PREFERED_LAUNCHER=$1; bmks_display ;; 75 *) bmks_display ;; 76 esac