Simplification

This commit is contained in:
Nox Sluijtman 2023-11-11 13:29:35 +01:00
parent 0703487e4d
commit d4da13c3ea
6 changed files with 55 additions and 68 deletions

View file

@ -2,25 +2,30 @@
bookmarks="${BOOKMARKS:-"$HOME/.config/qutebrowser/bookmarks/urls"}" 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 shuf -n1 $bookmarks | awk '{print $1}' | xclip -sel clip
xclip -o -sel clip xclip -o -sel clip
} }
[ $# -eq 0 ] && usage && exit 2 default(){
while getopts sfrdRh name; do 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 case $name in
f) menu="fzf";; R) random ;;
r) menu="rofi -dmenu -i -p 'Bookmarks'";;
s) menu="sk";;
d) menu="${MENU}";;
R) copy ;;
h) usage ;; h) usage ;;
*) usage c) menu="$OPTARG";;
exit 2;;
esac esac
done done
choice="$(sort $bookmarks | $menu )" choice="$(sort $bookmarks | $menu )"
[ -z "$choice" ] || echo "$choice" | awk '{print$1}' | xclip -sel clip [ -z "$choice" ] || echo "$choice" | awk '{print$1}' | xclip -sel clip

View file

@ -1,19 +1,26 @@
#!/bin/sh #!/bin/sh
usage(){ printf "Usage: %s -s|f|r|d|R|h\n" $(basename $0); } usage(){ printf "Usage: %s -R|h|c\n" $(basename $0); }
[ $# -eq 0 ] && usage && exit 2
bookmarks="${BOOKMARKS:-"$HOME/.config/qutebrowser/bookmarks/urls"}" 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 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}')";; R) xdg-open "$(shuf -n1 $bookmarks | awk '{print $1}')";;
h) usage;; h) usage;;
*) usage c) menu="$OPTARG";;
exit 2;;
esac esac
done done
choice="$(sort $bookmarks | $menu )" choice="$(sort $bookmarks | $menu )"
[ -z "$choice" ] || xdg-open "$(echo "$choice" | awk '{print$1}')" [ -z "$choice" ] || xdg-open "$(echo "$choice" | awk '{print$1}')"

View file

@ -1,18 +1,8 @@
#compdef _copy-bookmark copy-bookmark #compdef _copy-bookmark copy-bookmark
_arguments : \ _arguments : \
"(-f -r -d -R -h)-f[use 'fzf' to open bookmarks file]" \ "(-R -h)-c[menu command]:dmenu-like program" \
"(-s -r -d -R -h)-r[use 'rofi' to open bookmarks file]" \ "(-h -c)-R[copy random bookmark]" \
"(-s -f -d -R -h)-s[use 'sk' to open bookmarks file]" \ "(-R -c)-h[print usage and exit]"
"(-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]"
_arguments : $arguments _arguments : $arguments

View file

@ -1,12 +1,9 @@
#compdef _open-bookmark open-bookmark #compdef _open-bookmark open-bookmark
_arguments : \ _arguments : \
"(-f -r -d -R -h)-f[use 'fzf' to open bookmarks file]" \ "(-R -h)-c[menu command]:dmenu-like program" \
"(-s -r -d -R -h)-r[use 'rofi' to open bookmarks file]" \ "(-h -c)-R[copy random bookmark]" \
"(-s -f -d -R -h)-s[use 'sk' to open bookmarks file]" \ "(-R -c)-h[print usage and exit]"
"(-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]"
_arguments : $arguments _arguments : $arguments

View file

@ -6,7 +6,7 @@ open-bookmark(1)
# SYNOPSIS # SYNOPSIS
*open-bookmark -s|f|r|d|R|h* *copy-bookmark -R|h|c*
# DESCRIPTION # DESCRIPTION
*qutebrowser(1)* saves its bookmarks in *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 I would like to be able to access those bookmarks more easily outside of
qutebrowser sometimes. Hence this script now exists. qutebrowser sometimes. Hence this script now exists.
Defaults to using *$MENU* as menu command.
# OPTIONS # 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* *-R*
copy random bookmark 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* *-h*
print usage and exit print usage and exit
# SEE ALSO # SEE ALSO
*fzf(1)*, *sk(1)*, *rofi(1)*, *qutebrowser(1)*, *xclip(1)* *fzf(1)*, *dmenu(1)*, *qutebrowser(1)*, *xclip(1)*

View file

@ -6,7 +6,7 @@ open-bookmark(1)
# SYNOPSIS # SYNOPSIS
*open-bookmark -s|f|r|d|R|h* *open-bookmark -R|h|c*
# DESCRIPTION # DESCRIPTION
*qutebrowser(1)* saves its bookmarks in *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 I would like to be able to access those bookmarks more easily outside of
qutebrowser sometimes. Hence this script now exists. qutebrowser sometimes. Hence this script now exists.
Defaults to using *$MENU* as menu command.
# OPTIONS # 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* *-R*
open random bookmark 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* *-h*
print usage and exit print usage and exit
# SEE ALSO # SEE ALSO
*fzf(1)*, *sk(1)*, *rofi(1)*, *qutebrowser(1)*, *xdg-open(1)* *fzf(1)*, *dmenu(1)*, *qutebrowser(1)*, *xdg-open(1)*