From 6abfa16166c3b1e238b0854fc8a48f7e93a63da7 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sat, 12 Nov 2022 20:26:59 -0500 Subject: [PATCH] bookmk: add flags for different actions --- src/.local/bin/bookmk | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/.local/bin/bookmk b/src/.local/bin/bookmk index b07e7e3..ce1c429 100755 --- a/src/.local/bin/bookmk +++ b/src/.local/bin/bookmk @@ -1,6 +1,33 @@ #!/bin/sh # Copy a bookmark to clipboard. +# # Requires fzf, xsel # Bookmarks are stored in ~/dox/not/bk.txt, commented with # +# -o: print to stdout +# -b: open in browser -cat ~/dox/not/bk.txt | fzf | awk -F'#' '{print $1}' | xsel -ib +output=$(cat ~/dox/not/bk.txt | fzf | awk -F'#' '{print $1}') + +# default action: clip, stdout, browser +action="clip" + +while getopts "ob" o; do + case "${o}" in + o) action="stdout";; + b) action="browser";; + esac +done + +if [ -z "$output" ]; then + exit 1 +fi + +if [ "$action" = "stdout" ]; then + printf "%s" "$output" +fi +if [ "$action" = "clip" ]; then + printf "%s" "$output" | xsel -ib +fi +if [ "$action" = "browser" ]; then + $BROWSER "$output" +fi