diff --git a/src/bin/copy-bookmark b/src/bin/copy-bookmark index bf9676e..b090472 100755 --- a/src/bin/copy-bookmark +++ b/src/bin/copy-bookmark @@ -2,25 +2,30 @@ bookmarks="${BOOKMARKS:-"$HOME/.config/qutebrowser/bookmarks/urls"}" -usage(){ printf "Usage: %s -s|f|r|d|R|h\n" $(basename $0); } +usage(){ printf "Usage: %s -R|h|c\n" $(basename $0); } -copy(){ +random(){ shuf -n1 $bookmarks | awk '{print $1}' | xclip -sel clip xclip -o -sel clip } -[ $# -eq 0 ] && usage && exit 2 -while getopts sfrdRh name; do +default(){ + if [ -z ${MENU} ] + then printf 'err: $MENU not set\n' && exit 2 + else export menu="${MENU}" + fi +} + +[ $# -eq 0 ] && default + +while getopts Rhc: name; do case $name in - f) menu="fzf";; - r) menu="rofi -dmenu -i -p 'Bookmarks'";; - s) menu="sk";; - d) menu="${MENU}";; - R) copy ;; + R) random ;; h) usage ;; - *) usage - exit 2;; + c) menu="$OPTARG";; esac done + choice="$(sort $bookmarks | $menu )" + [ -z "$choice" ] || echo "$choice" | awk '{print$1}' | xclip -sel clip diff --git a/src/bin/open-bookmark b/src/bin/open-bookmark index 7c5df19..155c949 100755 --- a/src/bin/open-bookmark +++ b/src/bin/open-bookmark @@ -1,19 +1,26 @@ #!/bin/sh -usage(){ printf "Usage: %s -s|f|r|d|R|h\n" $(basename $0); } -[ $# -eq 0 ] && usage && exit 2 +usage(){ printf "Usage: %s -R|h|c\n" $(basename $0); } + bookmarks="${BOOKMARKS:-"$HOME/.config/qutebrowser/bookmarks/urls"}" -while getopts sfrdRh name; do + +default(){ + if [ -z ${MENU} ] + then printf 'err: $MENU not set\n' && exit 2 + else export menu="${MENU}" + fi +} + +[ $# -eq 0 ] && default + +while getopts Rhc: name; do case $name in - f) menu="fzf";; - r) menu="rofi -dmenu -i -p 'Bookmarks'";; - s) menu="sk";; - d) menu="${MENU}";; R) xdg-open "$(shuf -n1 $bookmarks | awk '{print $1}')";; - h) usage ;; - *) usage - exit 2;; + h) usage;; + c) menu="$OPTARG";; esac done + choice="$(sort $bookmarks | $menu )" + [ -z "$choice" ] || xdg-open "$(echo "$choice" | awk '{print$1}')" diff --git a/src/completions/_copy-bookmark b/src/completions/_copy-bookmark index 62e7dc5..d4b6348 100644 --- a/src/completions/_copy-bookmark +++ b/src/completions/_copy-bookmark @@ -1,18 +1,8 @@ #compdef _copy-bookmark copy-bookmark _arguments : \ - "(-f -r -d -R -h)-f[use 'fzf' to open bookmarks file]" \ - "(-s -r -d -R -h)-r[use 'rofi' to open bookmarks file]" \ - "(-s -f -d -R -h)-s[use 'sk' to open bookmarks file]" \ - "(-s -f -r -R -h)-d[use '$MENU' to open bookmarks file]" \ - "(-s -f -r -d -h)-R[copy random bookmark]" \ - "(-s -f -r -d -R)-h[print usage and exit]" + "(-R -h)-c[menu command]:dmenu-like program" \ + "(-h -c)-R[copy random bookmark]" \ + "(-R -c)-h[print usage and exit]" _arguments : $arguments - - - - - - - diff --git a/src/completions/_open-bookmark b/src/completions/_open-bookmark index 1617b68..821fbb0 100644 --- a/src/completions/_open-bookmark +++ b/src/completions/_open-bookmark @@ -1,12 +1,9 @@ #compdef _open-bookmark open-bookmark _arguments : \ - "(-f -r -d -R -h)-f[use 'fzf' to open bookmarks file]" \ - "(-s -r -d -R -h)-r[use 'rofi' to open bookmarks file]" \ - "(-s -f -d -R -h)-s[use 'sk' to open bookmarks file]" \ - "(-s -f -r -R -h)-d[use '$MENU' to open bookmarks file]" \ - "(-s -f -r -d -h)-R[open random bookmark]" \ - "(-s -f -r -d -R)-h[print usage and exit]" + "(-R -h)-c[menu command]:dmenu-like program" \ + "(-h -c)-R[copy random bookmark]" \ + "(-R -c)-h[print usage and exit]" _arguments : $arguments diff --git a/src/manpages/copy-bookmark.1.scd b/src/manpages/copy-bookmark.1.scd index 5094ef0..ab6280c 100644 --- a/src/manpages/copy-bookmark.1.scd +++ b/src/manpages/copy-bookmark.1.scd @@ -6,7 +6,7 @@ open-bookmark(1) # SYNOPSIS -*open-bookmark -s|f|r|d|R|h* +*copy-bookmark -R|h|c* # DESCRIPTION *qutebrowser(1)* saves its bookmarks in @@ -14,25 +14,19 @@ open-bookmark(1) I would like to be able to access those bookmarks more easily outside of qutebrowser sometimes. Hence this script now exists. +Defaults to using *$MENU* as menu command. + # OPTIONS -*-s* - use *sk(1)* to select bookmark - -*-f* - use *fzf(1)* to select bookmark - -*-r* - use *rofi(1)* to select bookmark - -*-d* - use *$MENU* to select bookmark - *-R* copy random bookmark +*-c* + specify menu command, has to me something that reads from STDIN and allows + the user to make a selection eg *dmenu(1)* + *-h* print usage and exit # SEE ALSO - *fzf(1)*, *sk(1)*, *rofi(1)*, *qutebrowser(1)*, *xclip(1)* + *fzf(1)*, *dmenu(1)*, *qutebrowser(1)*, *xclip(1)* diff --git a/src/manpages/open-bookmark.1.scd b/src/manpages/open-bookmark.1.scd index 5997aa7..da2bc29 100644 --- a/src/manpages/open-bookmark.1.scd +++ b/src/manpages/open-bookmark.1.scd @@ -6,7 +6,7 @@ open-bookmark(1) # SYNOPSIS -*open-bookmark -s|f|r|d|R|h* +*open-bookmark -R|h|c* # DESCRIPTION *qutebrowser(1)* saves its bookmarks in @@ -14,25 +14,19 @@ open-bookmark(1) I would like to be able to access those bookmarks more easily outside of qutebrowser sometimes. Hence this script now exists. +Defaults to using *$MENU* as menu command. + # OPTIONS -*-s* - use *sk(1)* to select bookmark - -*-f* - use *fzf(1)* to select bookmark - -*-r* - use *rofi(1)* to select bookmark - -*-d* - use *$MENU* to select bookmark - *-R* open random bookmark +*-c* + specify menu command, has to me something that reads from STDIN and allows + the user to make a selection eg *dmenu(1)* + *-h* print usage and exit # SEE ALSO - *fzf(1)*, *sk(1)*, *rofi(1)*, *qutebrowser(1)*, *xdg-open(1)* + *fzf(1)*, *dmenu(1)*, *qutebrowser(1)*, *xdg-open(1)*