Add bookmark finder scripts, fix a few incorrect uses of IFS and read
This commit is contained in:
51
src_files/.local/scripts/bookmark-find
Executable file
51
src_files/.local/scripts/bookmark-find
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
BKMRK_FIND_TMP_PATH="/tmp/bookmark-find-selected-url"
|
||||
|
||||
[ -z "$1" ] && bkmrk_find_search_root="$DIR_HOME_BOX" || bkmrk_find_search_root="$1"
|
||||
|
||||
# search for boookmark
|
||||
bm_selected_bookmark_url=$(
|
||||
find "$bkmrk_find_search_root" \
|
||||
\( -type d -name "*archive" -prune \) \
|
||||
-o \( -type d -name "*z-sort" -prune \) \
|
||||
-o -name "*.bkmrk" -print |
|
||||
while IFS= read -r bookmark_file; do tail -n +2 "$bookmark_file"; done |
|
||||
fzf \
|
||||
--style full \
|
||||
--border --padding 0,1 \
|
||||
--border-label '|bookmarks|' \
|
||||
--preview='bookmark-preview-info {}' |
|
||||
sed -E "s/^[^^]+\^([^^]+)\^.*$/\1/g" ||
|
||||
printf "%s" "BKMRK_FIND_ERROR"
|
||||
)
|
||||
|
||||
# notify if lookup failed
|
||||
[ "$bm_selected_bookmark_url" = "BKMRK_FIND_ERROR" ] &&
|
||||
printf "%s\n" "error while selecting bookmark" &&
|
||||
printf "%s" "error while selecting bookmark" > "$BKMRK_FIND_TMP_PATH" &&
|
||||
read && # read command to force a pause for input (hit return) before shell is closed
|
||||
exit 0 # exit 0 so (in macOS) skhd's invocation returns success and terminal can quit
|
||||
|
||||
# write selection to tmp path
|
||||
printf "%s" "$bm_selected_bookmark_url" > "$BKMRK_FIND_TMP_PATH"
|
||||
|
||||
# copy selection to clipboard
|
||||
[ "$XDG_SESSION_TYPE" = "wayland" ] && command -v wl-copy > /dev/null 2>&1 && {
|
||||
printf "%s" "$bm_selected_bookmark_url" | wl-copy
|
||||
} || {
|
||||
command -v xclip > /dev/null 2>&1 && {
|
||||
printf "%s" "$bm_selected_bookmark_url" | xclip -selection clipboard
|
||||
}
|
||||
} || {
|
||||
command -v pbcopy > /dev/null 2>&1 && {
|
||||
printf "%s" "$bm_selected_bookmark_url" | pbcopy
|
||||
}
|
||||
} || {
|
||||
printf "error finding tool for copy/paste, selected bookmark (%s) written to %s\n" \
|
||||
"$bm_selected_bookmark_url" \
|
||||
"$BKMRK_FIND_TMP_PATH"
|
||||
read # read command to force a pause for input (hit return) before shell is closed
|
||||
}
|
||||
exit 0 # exit 0 so (in macOS) skhd's invocation returns success and terminal can quit
|
||||
|
||||
26
src_files/.local/scripts/bookmark-preview-info
Executable file
26
src_files/.local/scripts/bookmark-preview-info
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
IFS="^" read -r bm_name bm_url bm_date_added bm_type bm_comments <<BM_LINE_BLOCK
|
||||
$(printf "%s" "$@")
|
||||
BM_LINE_BLOCK
|
||||
|
||||
bm_preview_format_block=$(cat <<'BM_PREVIEW_FORMAT_BLOCK'
|
||||
name:
|
||||
%s
|
||||
|
||||
url:
|
||||
%s
|
||||
|
||||
date_added:
|
||||
%s
|
||||
|
||||
type:
|
||||
%s
|
||||
|
||||
comments:
|
||||
%s
|
||||
|
||||
BM_PREVIEW_FORMAT_BLOCK)
|
||||
|
||||
printf "$bm_preview_format_block" \
|
||||
"$bm_name" "$bm_url" "$bm_date_added" "$bm_type" "$bm_comments"
|
||||
@@ -9,7 +9,7 @@ non_primary_monitors_off() {
|
||||
grep -v "^Screen" |
|
||||
grep -v "^\s" |
|
||||
grep -v "primary" |
|
||||
while IFS="\n " read -r target_mon_id remaining_text; do
|
||||
while read -r target_mon_id remaining_text; do
|
||||
xrandr --output "$target_mon_id" --off
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user