This commit is contained in:
The-Repo-Club 2023-07-22 16:57:57 +01:00
parent 700a61f4a9
commit 30d9bb6ef1
No known key found for this signature in database
GPG Key ID: E30EC2FBFB05C44F
4 changed files with 256 additions and 434 deletions

View File

@ -19,6 +19,7 @@ function pacman
command sudo pacman --color auto -Qttdq | command sudo pacman --color auto -Rns - command sudo pacman --color auto -Qttdq | command sudo pacman --color auto -Rns -
end end
else if [ "$argv" = --upall ] else if [ "$argv" = --upall ]
command sudo pkgfile -u
command sudo pacman -Fy command sudo pacman -Fy
command sudo pacman -Sy command sudo pacman -Sy
command pikaur -Su command pikaur -Su

View File

@ -12,7 +12,7 @@
#Created: #Created:
# Fri 09 December 2022, 07:19:23 AM [GMT] # Fri 09 December 2022, 07:19:23 AM [GMT]
#Modified: #Modified:
# Fri 09 December 2022, 08:24:49 AM [GMT] # Fri 14 July 2023, 11:47:25 PM [GMT+1]
# #
#Description: #Description:
# <Todo> # <Todo>
@ -46,10 +46,10 @@ config() {
export _BM_CONFIG_FILE='none' export _BM_CONFIG_FILE='none'
fi fi
# _BM_BOOKMARK_FILE : Where is stored the bookmark file # _BM_BOOKMARK_FILE : Where is stored the bookmark file
export _BM_BOOKMARK_FILE="${_BM_BOOKMARK_FILE:=${__w}bm.bmf}" export _BM_BOOKMARK_FILE="${_BM_BOOKMARK_FILE:=${__w}bm.bm}"
# _BM_BOOKMARK_BACKUP_FILE : Where is stored the backup of bookmark file # _BM_BOOKMARK_BACKUP_FILE : Where is stored the backup of bookmark file
export _BM_BOOKMARK_BACKUP_FILE="${_BM_BOOKMARK_BACKUP_FILE:=${__w}.bm.bmf.bck}" export _BM_BOOKMARK_BACKUP_FILE="${_BM_BOOKMARK_BACKUP_FILE:=${__w}.bm.bm.bck}"
# _BM_HTML_FILE : Location of generated HTML file # _BM_HTML_FILE : Location of generated HTML file
export _BM_HTML_FILE="${_BM_HTML_FILE:=${__w}bm.html}" export _BM_HTML_FILE="${_BM_HTML_FILE:=${__w}bm.html}"
@ -102,7 +102,7 @@ config() {
export _BM_NO_ARGS_FORCE_HELP=${_BM_NO_ARGS_FORCE_HELP:=false} export _BM_NO_ARGS_FORCE_HELP=${_BM_NO_ARGS_FORCE_HELP:=false}
# _BM_CREATE_BOOKMARK_FILE : If bm is called to list and no file exists. bm will create a default one. # _BM_CREATE_BOOKMARK_FILE : If bm is called to list and no file exists. bm will create a default one.
export _BM_CREATE_BOOKMARK_FILE=${_BM_CREATE_BOOKMARK_FILE:=false} export _BM_CREATE_BOOKMARK_FILE=${_BM_CREATE_BOOKMARK_FILE:=true}
# _BM_CMD_CAPTURE_CHECK : If you don't have tool installed to take screenshot, just put to false. # _BM_CMD_CAPTURE_CHECK : If you don't have tool installed to take screenshot, just put to false.
# It will disable the _BM_GET_SCREENSHOT. # It will disable the _BM_GET_SCREENSHOT.
@ -158,7 +158,7 @@ VERSION='2021.04.05'
# #
usage() { usage() {
cat <<EOF cat <<EOF
Usage: ${0} [modifier(s)] command [option(s)] Usage: ${0} [modifier(s)] command [option(s)]
@ -242,7 +242,7 @@ Usage: ${0} [modifier(s)] command [option(s)]
-C Print the color table (usefull for configuration) -C Print the color table (usefull for configuration)
-E Open the bm.bmf with your \$EDITOR -E Open the bm.bm with your \$EDITOR
-S Show statistics about bookmarks/tags (and also configuration) -S Show statistics about bookmarks/tags (and also configuration)
Options for -S Options for -S
@ -260,22 +260,22 @@ EOF
getAccelMax() { getAccelMax() {
while read a; do while read a; do
((${a:=0} >= ${_max:=0})) && ((_max = ${a} + 1)) (( ${a:=0} >= ${_max:=0} )) && (( _max=${a}+1 ))
done <<<"$(awk -F'|' '$0 !~ /^[ ]*#/ && $3 ~ /^[:space:]*:[:space:]*[0-9]+[:space:]*$/ { sub(/:+/, "", $3); print $3; }' "${_BM_BOOKMARK_FILE}")" done <<< "$( awk -F'|' '$0 !~ /^[ ]*#/ && $3 ~ /^[:space:]*:[:space:]*[0-9]+[:space:]*$/ { sub(/:+/, "", $3); print $3; }' "${_BM_BOOKMARK_FILE}")"
echo -n "${_max}" echo -n "${_max}"
} }
backupBm() { backupBm() {
if [ "${_BM_BOOKMARK_BACKUP,,}" = 'true' ]; then if [ "${_BM_BOOKMARK_BACKUP,,}" = 'true' ]; then
while [ ${count:=${_BM_BOOKMARK_BACKUP_VERSION}} -gt 0 ]; do while [ ${count:=${_BM_BOOKMARK_BACKUP_VERSION}} -gt 0 ]; do
cp -- "${_BM_BOOKMARK_BACKUP_FILE}.$((count - 1))" "${_BM_BOOKMARK_BACKUP_FILE}.$((count--))" 2>&1 >/dev/null cp -- "${_BM_BOOKMARK_BACKUP_FILE}.$(( count-1 ))" "${_BM_BOOKMARK_BACKUP_FILE}.$(( count-- ))" 2>&1 >/dev/null
done done
cp -- "${_BM_BOOKMARK_FILE}" "${_BM_BOOKMARK_BACKUP_FILE}.0" cp -- "${_BM_BOOKMARK_FILE}" "${_BM_BOOKMARK_BACKUP_FILE}.0"
fi fi
} }
titleDl() { titleDl() {
if command -v hxselect &>/dev/null; then if command -v hxselect &>/dev/null ; then
curl -Lks "${1:-}" 2>&1 | hxselect -ic title 2>/dev/null curl -Lks "${1:-}" 2>&1 | hxselect -ic title 2>/dev/null
else else
curl -Lks "${1:-}" 2>&1 | sed '/<title>/I!d;/<\/title>/I!d;s;^[[:space:]]*<title>\([^<]*\)<.*;\1;i' curl -Lks "${1:-}" 2>&1 | sed '/<title>/I!d;/<\/title>/I!d;s;^[[:space:]]*<title>\([^<]*\)<.*;\1;i'
@ -290,8 +290,8 @@ saveUrl() {
echo "Force adding invalid URL" >&2 echo "Force adding invalid URL" >&2
fi fi
} }
local _sum="$(${_BM_CMD_MD5} <<<"${__url}")" local _sum="$(${_BM_CMD_MD5} <<< "${__url}")"
if [ "${_BM_DUPS_DETECT,,}" = 'true' ]; then if [ "${_BM_DUPS_DETECT,,}" = 'true' ]; then
if [ ! -z "$(awk -F '|' '$0 !~ /^[ ]*#/ && $1 ~ /'"${_sum%% *}"'/' "${_BM_BOOKMARK_FILE}")" ]; then if [ ! -z "$(awk -F '|' '$0 !~ /^[ ]*#/ && $1 ~ /'"${_sum%% *}"'/' "${_BM_BOOKMARK_FILE}")" ]; then
if [ ${__F:=0} -eq 0 ]; then if [ ${__F:=0} -eq 0 ]; then
die "URL is already in the Bookmark file" die "URL is already in the Bookmark file"
@ -299,27 +299,27 @@ saveUrl() {
echo "Force adding duplicate URL" >&2 echo "Force adding duplicate URL" >&2
fi fi
fi fi
fi fi
if [ "${_BM_GET_PAGE_TITLE,,}" = 'true' -a -z "${__T:=}" ]; then if [ "${_BM_GET_PAGE_TITLE,,}" = 'true' -a -z "${__T:=}" ]; then
# if [ $( command -v hxselect &>/dev/null ) ]; then # if [ $( command -v hxselect &>/dev/null ) ]; then
# __T="$( curl -Lks "${__url}" 2>&1 | hxselect -ic title )" # __T="$( curl -Lks "${__url}" 2>&1 | hxselect -ic title )"
# else # else
# __T="$( curl -Lks "${__url}" 2>&1 | sed '/<title>/I!d;/<\/title>/I!d;s;^[[:space:]]*<title>\([^<]*\)<.*;\1;i' )" # __T="$( curl -Lks "${__url}" 2>&1 | sed '/<title>/I!d;/<\/title>/I!d;s;^[[:space:]]*<title>\([^<]*\)<.*;\1;i' )"
# fi # fi
__T="$(titleDl "${__url}")" __T="$( titleDl "${__url}" )"
fi fi
[[ ! -z "${__T:=}" ]] && __T="${__T//\|/\\|}" [[ ! -z "${__T:=}" ]] && __T="${__T//\|/\\|}"
backupBm backupBm
[[ -z "${__T:=}" ]] && __T="$(slug <<<"${__url}")" # If no title => slug the url [[ -z "${__T:=}" ]] && __T="$(slug <<< "${__url}")" # If no title => slug the url
[[ -z "${__t:=}" ]] && __t='default' # Default tag is default [[ -z "${__t:=}" ]] && __t='default' # Default tag is default
[[ -z "${__A:=}" ]] && __A="$(getAccelMax)" [[ -z "${__A:=}" ]] && __A="$(getAccelMax)"
[[ "${__A:0:1}" != ':' ]] && __A=":${__A}" # If no accel => Add a number [[ "${__A:0:1}" != ':' ]] && __A=":${__A}" # If no accel => Add a number
echo "${_sum%% *}|$(date '+%FT%TZ')|${__A}|${__url}|${__T}|${__t}" >>"${_BM_BOOKMARK_FILE}" || die "Insert aborted into '${_BM_BOOKMARK_FILE}' !" echo "${_sum%% *}|$(date '+%FT%TZ')|${__A}|${__url}|${__T}|${__t}" >> "${_BM_BOOKMARK_FILE}" || die "Insert aborted into '${_BM_BOOKMARK_FILE}' !"
echo "${__url} inserted into '${_BM_BOOKMARK_FILE}'" echo "${__url} inserted into '${_BM_BOOKMARK_FILE}'"
[[ ! -f "${_BM_SCREENSHOT_DIRECTORY}/${_sum%% *}.png" || ${__F:=0} -eq 1 ]] && { screenshot_take "${_BM_SCREENSHOT_DIRECTORY}/${_sum%% *}.png" "${__url}" & } [[ ! -f "${_BM_SCREENSHOT_DIRECTORY}/${_sum%% *}.png" || ${__F:=0} -eq 1 ]] && { screenshot_take "${_BM_SCREENSHOT_DIRECTORY}/${_sum%% *}.png" "${__url}" & }
[[ "${_BM_SCREENSHOT_WAIT,,}" = 'true' ]] && wait [[ "${_BM_SCREENSHOT_WAIT,,}" = 'true' ]] && wait
search_bookmarks "${__A}" search_bookmarks "${__A}"
} }
# #
# manage each line to print it # manage each line to print it
@ -332,7 +332,7 @@ readLines() {
[[ ${__z:=0} -eq 1 ]] && _line="${_BM_PRINT_LINE_ALTERNATIVE}" [[ ${__z:=0} -eq 1 ]] && _line="${_BM_PRINT_LINE_ALTERNATIVE}"
_line="${_line//BM_MD5/$m}" _line="${_line//BM_MD5/$m}"
if [ "${_BM_PRINT_SCHEME,,}" = 'false' ]; then if [ "${_BM_PRINT_SCHEME,,}" = 'false' ]; then
u="$(sed 's/^[[:space:]]*\(f\|ht\)tps*:\/\///' <<<"${u}")" u="$(sed 's/^[[:space:]]*\(f\|ht\)tps*:\/\///' <<< "${u}")"
fi fi
_line="${_line//BM_URL/$u}" _line="${_line//BM_URL/$u}"
_line="${_line//BM_TITLE/$T}" _line="${_line//BM_TITLE/$T}"
@ -351,14 +351,8 @@ readLines() {
# #
list_bookmarks() { list_bookmarks() {
[[ ${__n:=0} -eq 1 ]] && { [[ ${__n:=0} -eq 1 ]] && { awk '$0 !~ /^[ ]*#/' "${_BM_BOOKMARK_FILE}" | sort -t'|' -k2 | readLines; return; }
awk '$0 !~ /^[ ]*#/' "${_BM_BOOKMARK_FILE}" | sort -t'|' -k2 | readLines [[ ${__N:=0} -eq 1 ]] && { awk '$0 !~ /^[ ]*#/' "${_BM_BOOKMARK_FILE}" | sort -t'|' -k2 -r | readLines; return; }
return
}
[[ ${__N:=0} -eq 1 ]] && {
awk '$0 !~ /^[ ]*#/' "${_BM_BOOKMARK_FILE}" | sort -t'|' -k2 -r | readLines
return
}
awk '$0 !~ /^[ ]*#/' "${_BM_BOOKMARK_FILE}" | readLines awk '$0 !~ /^[ ]*#/' "${_BM_BOOKMARK_FILE}" | readLines
} }
@ -369,26 +363,11 @@ search() {
local _s='' local _s=''
[[ -z "${1:-}" ]] && list_bookmarks && return [[ -z "${1:-}" ]] && list_bookmarks && return
case "${1:0:1}" in case "${1:0:1}" in
:) :) _s=3; _ss=0 ;; # Accelerator
_s=3 +) _s="NF"; _ss=1 ;; # Tags
_ss=0 =) _s=1; _ss=1 ;; # MD5 part
;; # Accelerator /) _s=4; _ss=1 ;; # URL part
+) *) _s=0; _ss=0 ;; # full text search
_s="NF"
_ss=1
;; # Tags
=)
_s=1
_ss=1
;; # MD5 part
/)
_s=4
_ss=1
;; # URL part
*)
_s=0
_ss=0
;; # full text search
esac esac
[[ "${_BM_SEARCH_IGNORECASE,,}" = 'true' || ${__i:=0} -eq 1 ]] && local _ign=1 [[ "${_BM_SEARCH_IGNORECASE,,}" = 'true' || ${__i:=0} -eq 1 ]] && local _ign=1
awk -F'|' -vIgn=${_ign:=0} ' awk -F'|' -vIgn=${_ign:=0} '
@ -400,14 +379,8 @@ $0 !~ /^[ ]*#/ && (Ign == 0 && $'"${_s}"' ~ s) || (Ign ==1 && tolower($'"${_s}"
} }
search_bookmarks() { search_bookmarks() {
[[ ${__n:=0} -eq 1 ]] && { [[ ${__n:=0} -eq 1 ]] && { search "${@}" | sort -t'|' -k2 | readLines; return; }
search "${@}" | sort -t'|' -k2 | readLines [[ ${__N:=0} -eq 1 ]] && { search "${@}" | sort -t'|' -k2 -r | readLines; return; }
return
}
[[ ${__N:=0} -eq 1 ]] && {
search "${@}" | sort -t'|' -k2 -r | readLines
return
}
search "${@}" | readLines search "${@}" | readLines
} }
@ -418,7 +391,7 @@ search_bookmarks() {
recorded_picture() { recorded_picture() {
local _lines="$(search "${@}")" local _lines="$(search "${@}")"
if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__O:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__O:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then
if [ $(wc -l <<<"${_lines}") -gt 1 ]; then if [ $(wc -l <<< "${_lines}") -gt 1 ]; then
read -p"More than one URL found. Open all Pictures ? [Y/N] : " -n1 _answer read -p"More than one URL found. Open all Pictures ? [Y/N] : " -n1 _answer
[[ "${_answer,,}" != 'y' ]] && die "\nUse -O to force the first URL or refine your search" [[ "${_answer,,}" != 'y' ]] && die "\nUse -O to force the first URL or refine your search"
fi fi
@ -426,21 +399,21 @@ recorded_picture() {
local _all='' local _all=''
echo '' echo ''
while read _nl; do while read _nl; do
readLines <<<"${_nl}" readLines <<< "${_nl}"
if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then
_all="${_BM_SCREENSHOT_DIRECTORY}/$(awk -F'|' '{print $1}' <<<"${_nl}").png ${_all}" _all="${_BM_SCREENSHOT_DIRECTORY}/$(awk -F'|' '{print $1}' <<< "${_nl}").png ${_all}"
else else
"${_BM_CMD_IMAGE_OPEN}" "${_BM_SCREENSHOT_DIRECTORY}/$(awk -F'|' '{print $1}' <<<"${_nl}").png" "${_BM_CMD_IMAGE_OPEN}" "${_BM_SCREENSHOT_DIRECTORY}/$(awk -F'|' '{print $1}' <<< "${_nl}").png"
[[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__O:=0} -eq 1 ]] && exit 0 [[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__O:=0} -eq 1 ]] && exit 0
fi fi
done <<<"$(echo -e "${_lines}")" done <<< "$(echo -e "${_lines}")"
[[ "${_BM_OPEN_ALL,,}" = 'true' || ${__Y:=0} -eq 1 ]] && "${_BM_CMD_IMAGE_OPEN}" "${_all}" [[ "${_BM_OPEN_ALL,,}" = 'true' || ${__Y:=0} -eq 1 ]] && "${_BM_CMD_IMAGE_OPEN}" "${_all}"
} }
download_title() { download_title() {
local _lines="$(search "${@}")" local _lines="$(search "${@}")"
if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__O:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__O:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then
if [ $(wc -l <<<"${_lines}") -gt 1 ]; then if [ $(wc -l <<< "${_lines}") -gt 1 ]; then
read -p"More than one URL found. Download Title for all URLs ? [Y/N] : " -n1 _answer read -p"More than one URL found. Download Title for all URLs ? [Y/N] : " -n1 _answer
[[ "${_answer,,}" != 'y' ]] && die "\nUse -O to force the first URL or refine your search" [[ "${_answer,,}" != 'y' ]] && die "\nUse -O to force the first URL or refine your search"
fi fi
@ -448,68 +421,68 @@ download_title() {
local _all='' local _all=''
echo '' echo ''
while read _nl; do while read _nl; do
readLines <<<"${_nl}" readLines <<< "${_nl}"
local u="$(awk -F'|' '{print $4}' <<<"${_nl}")" local u="$(awk -F'|' '{print $4}' <<< "${_nl}")"
if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then
echo "${u} --> $(titleDl "${u}")" echo "${u} --> $( titleDl "${u}" )"
else else
echo "${u} --> $(titleDl "${u}")" echo "${u} --> $( titleDl "${u}" )"
[[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__O:=0} -eq 1 ]] && exit 0 [[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__O:=0} -eq 1 ]] && exit 0
fi fi
done <<<"$(echo -e "${_lines}")" done <<< "$(echo -e "${_lines}")"
} }
open_bookmark() { open_bookmark() {
local _lines="$(search "${@}")" local _lines="$(search "${@}")"
if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__O:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__O:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then
if [ $(wc -l <<<"${_lines}") -gt 1 ]; then if [ $(wc -l <<< "${_lines}") -gt 1 ]; then
read -p"More than one URL found. Open all ? [Y/N] : " -n1 _answer read -p"More than one URL found. Open all ? [Y/N] : " -n1 _answer
[[ "${_answer,,}" != 'y' ]] && die "\nUse -O to force the first URL or refine your search" [[ "${_answer,,}" != 'y' ]] && die "\nUse -O to force the first URL or refine your search"
fi fi
fi fi
local _all='' local _all=''
while read _nl; do while read _nl; do
readLines <<<"${_nl}" readLines <<< "${_nl}"
if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then
_all="$(awk -F'|' '{print $4}' <<<"${_nl}") ${_all}" _all="$(awk -F'|' '{print $4}' <<< "${_nl}") ${_all}"
else else
"${_BM_CMD_OPEN}" "$(awk -F'|' '{print $4}' <<<"${_nl}")" "${_BM_CMD_OPEN}" "$(awk -F'|' '{print $4}' <<< "${_nl}")"
[[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__O:=0} -eq 1 ]] && exit 0 [[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__O:=0} -eq 1 ]] && exit 0
fi fi
done <<<"$(echo -e "${_lines}")" done <<< "$(echo -e "${_lines}")"
[[ "${_BM_OPEN_ALL,,}" = 'true' || ${__Y:=0} -eq 1 ]] && "${_BM_CMD_OPEN}" "${_all}" [[ "${_BM_OPEN_ALL,,}" = 'true' || ${__Y:=0} -eq 1 ]] && "${_BM_CMD_OPEN}" "${_all}"
} }
copy_bookmark() { copy_bookmark() {
local _lines="$(search "${@}")" local _lines="$(search "${@}")"
if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__X:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__X:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then
if [ $(wc -l <<<"${_lines}") -gt 1 ]; then if [ $(wc -l <<< "${_lines}") -gt 1 ]; then
read -p"More than one URL found. Copy all ? [Y/N] : " -n1 _answer read -p"More than one URL found. Copy all ? [Y/N] : " -n1 _answer
[[ "${_answer,,}" != 'y' ]] && die "\nUse -X to force the first URL or refine your search" [[ "${_answer,,}" != 'y' ]] && die "\nUse -X to force the first URL or refine your search"
fi fi
fi fi
local _all='' local _all=''
while read _nl; do while read _nl; do
readLines <<<"${_nl}" readLines <<< "${_nl}"
if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then
_all="$(awk -F'|' '{print $4}' <<<"${_nl}") ${_all}" _all="$(awk -F'|' '{print $4}' <<< "${_nl}") ${_all}"
else else
awk -F'|' '{print $4}' <<<"${_nl}" | "${_BM_CMD_COPY}" awk -F'|' '{print $4}' <<< "${_nl}" | "${_BM_CMD_COPY}"
awk -F'|' '{print $4}' <<<"${_nl}" | "${_BM_CMD_COPY}" -b awk -F'|' '{print $4}' <<< "${_nl}" | "${_BM_CMD_COPY}" -b
[[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__X:=0} -eq 1 ]] && exit 0 [[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__X:=0} -eq 1 ]] && exit 0
fi fi
done <<<"$(echo -e "${_lines}")" done <<< "$(echo -e "${_lines}")"
[[ "${_BM_OPEN_ALL,,}" = 'true' || ${__Y:=0} -eq 1 ]] && "${_BM_CMD_COPY}" <<<"${_all}" [[ "${_BM_OPEN_ALL,,}" = 'true' || ${__Y:=0} -eq 1 ]] && "${_BM_CMD_COPY}" <<< "${_all}"
[[ "${_BM_OPEN_ALL,,}" = 'true' || ${__Y:=0} -eq 1 ]] && "${_BM_CMD_COPY}" -b <<<"${_all}" [[ "${_BM_OPEN_ALL,,}" = 'true' || ${__Y:=0} -eq 1 ]] && "${_BM_CMD_COPY}" -b <<< "${_all}"
} }
delete_bookmark() { delete_bookmark() {
[[ -z "${@//[ ]/}" ]] && die "You MUST give an argument !" [[ -z "${@//[ ]/}" ]] && die "You MUST give an argument !"
local _lines="$(search "${@}")" local _lines="$(search "${@}")"
if [ "${_BM_DELETE_ALLOWED,,}" = 'true' ]; then if [ "${_BM_DELETE_ALLOWED,,}" = 'true' ]; then
while read _nl; do readLines <<<"${_nl}"; done <<<"$(echo -e "${_lines}")" while read _nl; do readLines <<< "${_nl}"; done <<< "$(echo -e "${_lines}")"
if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__D:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__D:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then
if [ $(wc -l <<<"${_lines}") -ge 1 ]; then if [ $(wc -l <<< "${_lines}") -ge 1 ]; then
read -p"You're about to delete entry(ies). Ready ? [Y/N] : " -n1 _answer read -p"You're about to delete entry(ies). Ready ? [Y/N] : " -n1 _answer
[[ "${_answer,,}" != 'y' ]] && die "\nUse -D to force the backup if not configured." [[ "${_answer,,}" != 'y' ]] && die "\nUse -D to force the backup if not configured."
echo '' echo ''
@ -519,12 +492,12 @@ delete_bookmark() {
local _all='' local _all=''
while read _nl; do while read _nl; do
if [ "${_BM_DELETE_TO_FILE,,}" = 'true' -o ${__D:=0} -eq 1 ]; then if [ "${_BM_DELETE_TO_FILE,,}" = 'true' -o ${__D:=0} -eq 1 ]; then
echo "${_nl}" >>"${_BM_DELETE_FILE}" echo "${_nl}" >> "${_BM_DELETE_FILE}"
fi fi
[[ "${_BM_DELETE_PICTURE,,}" = 'true' || ${__p:=0} -eq 1 ]] && rm -f -- "${_BM_SCREENSHOT_DIRECTORY}/${_nl%%|*}.png" [[ "${_BM_DELETE_PICTURE,,}" = 'true' || ${__p:=0} -eq 1 ]] && rm -f -- "${_BM_SCREENSHOT_DIRECTORY}/${_nl%%|*}.png"
IFS='|' read m d a u T t <<<"${_nl}" IFS='|' read m d a u T t <<< "${_nl}"
sed -i -e '/^'"${m}.*${u//\//\\/}.*${t//\//\\/}"'$/d' "${_BM_BOOKMARK_FILE}" sed -i -e '/^'"${m}.*${u//\//\\/}.*${t//\//\\/}"'$/d' "${_BM_BOOKMARK_FILE}"
done <<<"$(echo -e "${_lines}")" done <<< "$(echo -e "${_lines}")"
else else
die "You're not allowed to delete entries. Change the _BM_DELETE_ALLOWED to true !" die "You're not allowed to delete entries. Change the _BM_DELETE_ALLOWED to true !"
fi fi
@ -550,42 +523,29 @@ stats() {
echo " ${i}" echo " ${i}"
done done
echo -e "\n===== Statistics =====" echo -e "\n===== Statistics ====="
readarray -t lines <"${_BM_BOOKMARK_FILE}" readarray -t lines < "${_BM_BOOKMARK_FILE}"
echo "# of Bookmarks : ${#lines[@]}" echo "# of Bookmarks : ${#lines[@]}"
echo "# of Duplicate : $(awk -F'|' '$0 !~ /^[ ]*#/ {print $1}' "${_BM_BOOKMARK_FILE}" | sort | uniq -d | wc -l)" echo "# of Duplicate : $(awk -F'|' '$0 !~ /^[ ]*#/ {print $1}' "${_BM_BOOKMARK_FILE}" |sort |uniq -d |wc -l)"
local tags="$(awk -F'|' '$0 !~ /^[ ]*#/ {print $NF}' "${_BM_BOOKMARK_FILE}" | sed -e 's/\([[:space:]]*,[[:space:]]*\)/\n/g')" local tags="$(awk -F'|' '$0 !~ /^[ ]*#/ {print $NF}' "${_BM_BOOKMARK_FILE}" | sed -e 's/\([[:space:]]*,[[:space:]]*\)/\n/g')"
echo "# of tags : $(sort -u <<<"${tags,,}" | wc -l)" echo "# of tags : $( sort -u <<< "${tags,,}" |wc -l)"
echo "Top 14 tags used :" echo "Top 14 tags used :"
local nli=0 local nli=0;local pa=0
local pa=0
( (
sort <<<"${tags,,}" | uniq -c | sort -nr | while read n t; do sort <<< "${tags,,}" | uniq -c | sort -nr | while read n t; do
((nli++)) (( nli++ ));[[ ${nli} -gt 7 ]] && nli=1 && echo ''
[[ ${nli} -gt 7 ]] && nli=1 && echo '' (( pa++ ));[[ ${pa} -gt 14 ]] && break
((pa++))
[[ ${pa} -gt 14 ]] && break
echo -n "${t// / }:${n} " echo -n "${t// / }:${n} "
done done
echo '' echo ''
) | column -t -c 17 ) | column -t -c 17
echo "# of Pictures : $(ls -1 "${_BM_SCREENSHOT_DIRECTORY}"/*.png | wc -l) [# of files in ${_BM_SCREENSHOT_DIRECTORY}:$(ls -1 "${_BM_SCREENSHOT_DIRECTORY}"/* | wc -l)]" echo "# of Pictures : $(ls -1 "${_BM_SCREENSHOT_DIRECTORY}"/*.png |wc -l) [# of files in ${_BM_SCREENSHOT_DIRECTORY}:$(ls -1 "${_BM_SCREENSHOT_DIRECTORY}"/* |wc -l)]"
echo "All Pictures size : $(du -sh "${_BM_SCREENSHOT_DIRECTORY}" | awk '{print $1}')" echo "All Pictures size : $(du -sh "${_BM_SCREENSHOT_DIRECTORY}" | awk '{print $1}')"
local orphaned="$( local orphaned="$( cd "${_BM_SCREENSHOT_DIRECTORY}" && for i in *; do [[ -z "$(sed -e '/'"${i%%.*}"'/!d' "${_BM_BOOKMARK_FILE}")" ]] && ((orph++)); done; echo "${orph:=0}" )"
cd "${_BM_SCREENSHOT_DIRECTORY}" && for i in *; do [[ -z "$(sed -e '/'"${i%%.*}"'/!d' "${_BM_BOOKMARK_FILE}")" ]] && ((orph++)); done local nopics="$( while read i; do [[ ! -f "${_BM_SCREENSHOT_DIRECTORY}/${i%%|*}.png" ]] && ((nopics++)); done <<< ${lines[@]}; echo "${nopics:=0}" )"
echo "${orph:=0}" echo "Bookmark Without Pic : ${nopics}"
)" echo "Orphaned pictures : ${orphaned}"
local nopics="$( [[ ${__p:=0} -eq 1 ]] && { echo -e "\n===== Orphaned ====="; echo "List of orphaned pictures :"; cd "${_BM_SCREENSHOT_DIRECTORY}" && for i in *; do [[ -z "$(sed -e '/'"${i%%.*}"'/!d' "${_BM_BOOKMARK_FILE}")" ]] && echo " - ${_BM_SCREENSHOT_DIRECTORY}/${i} [Trashed URL should be: $(awk -F'|' 'BEGIN{l="Unknown"} ($1 ~ /'"${i%%.*}"'/) {l=$4;} END {print l}' "${_BM_DELETE_FILE}")]"; done; };
while read i; do [[ ! -f "${_BM_SCREENSHOT_DIRECTORY}/${i%%|*}.png" ]] && ((nopics++)); done <<<${lines[@]}
echo "${nopics:=0}"
)"
echo "Bookmark Without Pic : ${nopics}"
echo "Orphaned pictures : ${orphaned}"
[[ ${__p:=0} -eq 1 ]] && {
echo -e "\n===== Orphaned ====="
echo "List of orphaned pictures :"
cd "${_BM_SCREENSHOT_DIRECTORY}" && for i in *; do [[ -z "$(sed -e '/'"${i%%.*}"'/!d' "${_BM_BOOKMARK_FILE}")" ]] && echo " - ${_BM_SCREENSHOT_DIRECTORY}/${i} [Trashed URL should be: $(awk -F'|' 'BEGIN{l="Unknown"} ($1 ~ /'"${i%%.*}"'/) {l=$4;} END {print l}' "${_BM_DELETE_FILE}")]"; done
}
} }
# #
@ -596,13 +556,12 @@ list_tags() {
local tags="$(awk -F'|' '$0 !~ /^[ ]*#/ {print $NF}' "${_BM_BOOKMARK_FILE}" | sed -e 's/\([[:space:]]*,[[:space:]]*\)/\n/g')" local tags="$(awk -F'|' '$0 !~ /^[ ]*#/ {print $NF}' "${_BM_BOOKMARK_FILE}" | sed -e 's/\([[:space:]]*,[[:space:]]*\)/\n/g')"
local nli=0 local nli=0
( (
sort <<<"${tags,,}" | uniq -c | sort -nr | while read n t; do sort <<< "${tags,,}" | uniq -c | sort -nr | while read n t; do
((nli++)) (( nli++ ));[[ ${nli} -gt 7 ]] && nli=1 && echo ''
[[ ${nli} -gt 7 ]] && nli=1 && echo ''
echo -n "${t// / }:${n} " echo -n "${t// / }:${n} "
done done
echo '' echo ''
) | column -t -c 17 ) | column -t -c 17
} }
# #
@ -687,22 +646,12 @@ EOF
screenshot_take() { screenshot_take() {
if [ "${_BM_SCREENSHOT_GET,,}" = 'true' -o ${__p:=0} -eq 1 ]; then if [ "${_BM_SCREENSHOT_GET,,}" = 'true' -o ${__p:=0} -eq 1 ]; then
[[ ! -d "${_BM_SCREENSHOT_DIRECTORY}" ]] && { mkdir -p "${_BM_SCREENSHOT_DIRECTORY}" || die "Can't create thumbnail directory."; } [[ ! -d "${_BM_SCREENSHOT_DIRECTORY}" ]] && { mkdir -p "${_BM_SCREENSHOT_DIRECTORY}" || die "Can't create thumbnail directory." ; }
[[ ! -z "${_BM_CMD_PRE_CAPTURE}" ]] && { [[ ! -z "${_BM_CMD_PRE_CAPTURE}" ]] && { local _pre="${_BM_CMD_PRE_CAPTURE//\{FILE\}/${1}}"; _pre="${_pre//\{URL\}/${2}}"; ${_pre} ; }
local _pre="${_BM_CMD_PRE_CAPTURE//\{FILE\}/${1}}" local _cmd="${_BM_CMD_CAPTURE//\{FILE\}/${1}}"; _cmd="${_cmd//\{URL\}/${2}}";
_pre="${_pre//\{URL\}/${2}}" local _args="${_BM_CMD_CAPTURE_ARGS//\{FILE\}/${1}}"; _args="${_args//\{URL\}/${2}}";
${_pre}
}
local _cmd="${_BM_CMD_CAPTURE//\{FILE\}/${1}}"
_cmd="${_cmd//\{URL\}/${2}}"
local _args="${_BM_CMD_CAPTURE_ARGS//\{FILE\}/${1}}"
_args="${_args//\{URL\}/${2}}"
eval ${_cmd} ${_args} eval ${_cmd} ${_args}
[[ ! -z "${_BM_CMD_POST_CAPTURE}" ]] && { [[ ! -z "${_BM_CMD_POST_CAPTURE}" ]] && { local _post="${_BM_CMD_POST_CAPTURE//\{FILE\}/${1}}"; _post="${_post//\{URL\}/${2}}"; ${_post} ; }
local _post="${_BM_CMD_POST_CAPTURE//\{FILE\}/${1}}"
_post="${_post//\{URL\}/${2}}"
${_post}
}
fi fi
} }
@ -712,43 +661,43 @@ picturize() {
[[ ! -f "${_BM_SCREENSHOT_DIRECTORY}/${m}.png" || ${__F:=0} -eq 1 ]] && { screenshot_take "${_BM_SCREENSHOT_DIRECTORY}/${m}.png" "${u}" & } [[ ! -f "${_BM_SCREENSHOT_DIRECTORY}/${m}.png" || ${__F:=0} -eq 1 ]] && { screenshot_take "${_BM_SCREENSHOT_DIRECTORY}/${m}.png" "${u}" & }
[[ "${_BM_SCREENSHOT_WAIT,,}" = 'true' ]] && wait [[ "${_BM_SCREENSHOT_WAIT,,}" = 'true' ]] && wait
done done
else else
local _lines="$(search "${@}")" local _lines="$(search "${@}")"
if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__O:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then if [ "${_BM_ASK_BEFORE_OPEN,,}" = 'true' -a ${__O:=0} -eq 0 -a ${__Y:=0} -eq 0 ]; then
if [ $(wc -l <<<"${_lines}") -gt 1 ]; then if [ $(wc -l <<< "${_lines}") -gt 1 ]; then
read -p"More than one URL found. Open all ? [Y/N] : " -n1 _answer read -p"More than one URL found. Open all ? [Y/N] : " -n1 _answer
[[ "${_answer,,}" != 'y' ]] && die "\nUse -O to force the first URL or refine your search" [[ "${_answer,,}" != 'y' ]] && die "\nUse -O to force the first URL or refine your search"
fi fi
fi fi
local _all='' local _all=''
while read _nl; do while read _nl; do
readLines <<<"${_nl}" readLines <<< "${_nl}"
if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then if [ "${_BM_OPEN_ALL,,}" = 'true' -o ${__Y:=0} -eq 1 ]; then
IFS='|' read m d a u b <<<"${_nl}" IFS='|' read m d a u b <<< "${_nl}"
screenshot_take "${_BM_SCREENSHOT_DIRECTORY}/${m}.png" "${u}" & screenshot_take "${_BM_SCREENSHOT_DIRECTORY}/${m}.png" "${u}" &
else else
IFS='|' read m d a u b <<<"${_nl}" IFS='|' read m d a u b <<< "${_nl}"
screenshot_take "${_BM_SCREENSHOT_DIRECTORY}/${m}.png" "${u}" & screenshot_take "${_BM_SCREENSHOT_DIRECTORY}/${m}.png" "${u}" &
[[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__O:=0} -eq 1 ]] && exit 0 [[ "${_BM_OPEN_FIRST,,}" = 'true' || ${__O:=0} -eq 1 ]] && exit 0
fi fi
done <<<"$(echo -e "${_lines}")" done <<< "$(echo -e "${_lines}")"
fi fi
} }
bookmark_generator() { bookmark_generator() {
[[ ! -f "${_BM_SCREENSHOT_DIRECTORY}/black-Linen.png" && -f "/usr/share/bm/black-Linen.png" ]] && cp "/usr/share/bm/black-Linen.png" "${_BM_SCREENSHOT_DIRECTORY}/black-Linen.png" [[ ! -f "${_BM_SCREENSHOT_DIRECTORY}/black-Linen.png" && -f "/usr/share/bm/black-Linen.png" ]] && cp "/usr/share/bm/black-Linen.png" "${_BM_SCREENSHOT_DIRECTORY}/black-Linen.png"
echo "<!DOCTYPE html><html><head><meta charset="UTF-8"><title>bm v${VERSION} : all your bookmarks</title>" >"${1:-${_BM_HTML_FILE}}" echo "<!DOCTYPE html><html><head><meta charset="UTF-8"><title>bm v${VERSION} : all your bookmarks</title>" > "${1:-${_BM_HTML_FILE}}"
style >>"${1:-${_BM_HTML_FILE}}" style >> "${1:-${_BM_HTML_FILE}}"
echo "</head><body>" >>"${1:-${_BM_HTML_FILE}}" echo "</head><body>" >> "${1:-${_BM_HTML_FILE}}"
# search "${2:-}" | while IFS='|' read m a u T t d; do # search "${2:-}" | while IFS='|' read m a u T t d; do
awk '$0 !~ /^[ ]*#/' "${_BM_BOOKMARK_FILE}" | while IFS='|' read m d a u T t; do awk '$0 !~ /^[ ]*#/' "${_BM_BOOKMARK_FILE}" | while IFS='|' read m d a u T t; do
echo " <div class=bm> echo " <div class=bm>
<a href='${u}'><img src='${_BM_SCREENSHOT_DIRECTORY}/${m}.png' alt='${u}' /></a> <a href='${u}'><img src='${_BM_SCREENSHOT_DIRECTORY}/${m}.png' alt='${u}' /></a>
<p>${T}<br/><a href='${_BM_SCREENSHOT_DIRECTORY}/${m}.png'>View image</a></p> <p>${T}<br/><a href='${_BM_SCREENSHOT_DIRECTORY}/${m}.png'>View image</a></p>
</div>" >>"${1:-${_BM_HTML_FILE}}" </div>" >> "${1:-${_BM_HTML_FILE}}"
done done
echo "</body></html>" >>"${1:-${_BM_HTML_FILE}}" echo "</body></html>" >> "${1:-${_BM_HTML_FILE}}"
[[ ${__O:=0} -eq 1 ]] && "${_BM_CMD_OPEN}" "${1:-${_BM_HTML_FILE}}" [[ ${__O:=0} -eq 1 ]] && "${_BM_CMD_OPEN}" "${1:-${_BM_HTML_FILE}}"
} }
# #
@ -760,6 +709,7 @@ die() {
exit 1 exit 1
} }
# #
# checkBinaries check the script is able to run and give hints # checkBinaries check the script is able to run and give hints
# #
@ -781,49 +731,35 @@ checkBinaries() {
[[ ${rc:=0} -ne 0 ]] && die "At least one command is missing. Please install it before using bm." [[ ${rc:=0} -ne 0 ]] && die "At least one command is missing. Please install it before using bm."
# Checking sed # Checking sed
local rc=1 local rc=1
[[ ! -f "/tmp/sedtest.$$" ]] && [[ ! -f "/tmp/sedtest.$$" ]] && \
echo -n 'toto' >"/tmp/sedtest.$$" && echo -n 'toto' > "/tmp/sedtest.$$" && \
sed -i.bak -e 's;^toto$;tata;' "/tmp/sedtest.$$" && sed -i.bak -e 's;^toto$;tata;' "/tmp/sedtest.$$" && \
[[ -f "/tmp/sedtest.$$.bak" ]] && [[ -f "/tmp/sedtest.$$.bak" ]] && \
grep -q "tata" "/tmp/sedtest.$$" && grep -q "tata" "/tmp/sedtest.$$" && \
rc=0 && rc=0 && \
rm -f "/tmp/sedtest.$$" "/tmp/sedtest.$$.bak" rm -f "/tmp/sedtest.$$" "/tmp/sedtest.$$.bak"
[[ ${rc} -ne 0 ]] && die "sed seems to not handle -i argument properly, please check" [[ ${rc} -ne 0 ]] && die "sed seems to not handle -i argument properly, please check"
} }
# #
# defineColors generate the variables to use to colorize the output # defineColors generate the variables to use to colorize the output
# #
defineColors() { defineColors() {
export BLACK="\e[30m" export BLACK="\e[30m"; export BLACK_LIGHT="\e[90m"; export GRAY_DARK="${BLACK_LIGHT}"
export BLACK_LIGHT="\e[90m" export RED="\e[31m"; export RED_LIGHT="\e[91m"
export GRAY_DARK="${BLACK_LIGHT}" export GREEN="\e[32m"; export GREEN_LIGHT="\e[92m"
export RED="\e[31m" export YELLOW="\e[33m"; export YELLOW_LIGHT="\e[93m"
export RED_LIGHT="\e[91m" export BLUE="\e[34m"; export BLUE_LIGHT="\e[94m"
export GREEN="\e[32m" export MAGENTA="\e[35m"; export MAGENTA_LIGHT="\e[95m"
export GREEN_LIGHT="\e[92m" export CYAN="\e[36m"; export CYAN_LIGHT="\e[96m"
export YELLOW="\e[33m" export GRAY="\e[37m"; export GRAY_LIGHT="\e[97m"; export WHITE="${GRAY_LIGHT}"
export YELLOW_LIGHT="\e[93m"
export BLUE="\e[34m"
export BLUE_LIGHT="\e[94m"
export MAGENTA="\e[35m"
export MAGENTA_LIGHT="\e[95m"
export CYAN="\e[36m"
export CYAN_LIGHT="\e[96m"
export GRAY="\e[37m"
export GRAY_LIGHT="\e[97m"
export WHITE="${GRAY_LIGHT}"
export RESET="\e[0m" export RESET="\e[0m"
export BOLD="\e[1m" export BOLD="\e[1m"; export BOLD_RESET="\e[21m"
export BOLD_RESET="\e[21m" export DIM="\e[2m"; export DIM_RESET="\e[22m"
export DIM="\e[2m" export UNDERLINE="\e[4m"; export UNDERLINE_RESET="\e[24m"
export DIM_RESET="\e[22m" export INVERT="\e[7m"; export INVERT_RESET="\e[27m"
export UNDERLINE="\e[4m"
export UNDERLINE_RESET="\e[24m"
export INVERT="\e[7m"
export INVERT_RESET="\e[27m"
if [ ! -z "${1:-}" ]; then if [ ! -z "${1:-}" ]; then
echo "Use the following colors to fit your needs :" echo "Use the following colors to fit your needs :"
( (
@ -851,37 +787,16 @@ _regex='^(help|version|tags|ls|list|search|open|add|view|stats|statistics|clear|
if [[ ${1:-} =~ ${_regex} ]]; then if [[ ${1:-} =~ ${_regex} ]]; then
case "$1" in case "$1" in
tags) __L=1 ;; tags) __L=1 ;;
ls | list) __l=1 ;; ls|list) __l=1 ;;
search) search) __s=1; __search="${@:2}" ;;
__s=1 open) __o=1; __open="${@:2}";;
__search="${@:2}" add) __a=1; __url="${2:-}"; __T="${3:-}"; __t="${4:-}"; __A="${5:-}";;
;; view) __r=1; __search="${@:2}" ;;
open) stats|statistics) __S=1 ;;
__o=1
__open="${@:2}"
;;
add)
__a=1
__url="${2:-}"
__T="${3:-}"
__t="${4:-}"
__A="${5:-}"
;;
view)
__r=1
__search="${@:2}"
;;
stats | statistics) __S=1 ;;
clear) die "This now a deprecated feature. Use -d instead." ;; clear) die "This now a deprecated feature. Use -d instead." ;;
colors) __C=1 ;; colors) __C=1;;
help) help) usage 1;exit 0;;
usage 1 version) echo -n "${0} v${VERSION}";exit 0;;
exit 0
;;
version)
echo -n "${0} v${VERSION}"
exit 0
;;
esac esac
else else
# -c config file # -c config file
@ -912,87 +827,43 @@ else
# available : ---------e-f----I-JjKk--Mm------Q-R-----Uu--W----yZ-0123456789 # available : ---------e-f----I-JjKk--Mm------Q-R-----Uu--W----yZ-0123456789
while getopts ":a:A:b:c:d:G:o:P:q:r:s:t:T:w:x:BCDEFghHilLnNOpPSvVXYz" option; do while getopts ":a:A:b:c:d:G:o:P:q:r:s:t:T:w:x:BCDEFghHilLnNOpPSvVXYz" option; do
case ${option} in case ${option} in
a) a) __a=1; __url="${OPTARG}";; # Add url to bookmark
__a=1 A) __A="${OPTARG}";; # AcceleratoR
__url="${OPTARG}" b) __b="${OPTARG}";; # Bookmark file
;; # Add url to bookmark B) __B=1;; # Don't load the default config file
A) __A="${OPTARG}" ;; # AcceleratoR c) __c="${OPTARG}";; # Config file
b) __b="${OPTARG}" ;; # Bookmark file C) __C=1;; # Print color table
B) __B=1 ;; # Don't load the default config file d) __d=1; __del="${OPTARG}";; # Config file
c) __c="${OPTARG}" ;; # Config file D) __D=1;; # Print color table
C) __C=1 ;; # Print color table E) __E=1;; # Open the bm.bm file with the $EDITOR
d) F) __F=1;; # Force the add or delete or picture
__d=1 g) (( __g++ ));; # generate html file(s)
__del="${OPTARG}" G) __G=1; __file="${OPTARG}";; # Generate this file (only for g=1)
;; # Config file h|H) usage; exit 0;; # Help
D) __D=1 ;; # Print color table i) __i=1;; # Ignore case when searching
E) __E=1 ;; # Open the bm.bmf file with the $EDITOR l) __l=1;; # List all bookmarks
F) __F=1 ;; # Force the add or delete or picture L) __L=1;; # List all tags
g) ((__g++)) ;; # generate html file(s) n) __n=1;; # sort by date
G) N) __N=1;; # sort by date (reverse)
__G=1 o) __o=1; __open="${OPTARG}";; # Open
__file="${OPTARG}" O) __O=1;; # Open First
;; # Generate this file (only for g=1) p) __p=1;; # Take a screenshot
h | H) P) __P=1; __search="${OPTARG}";; # Take all screenshot
usage q) __q=1; __search="${OPTARG}";; # Search
exit 0 r) __r=1; __search="${OPTARG}";; # Search
;; # Help s) __s=1; __search="${OPTARG}";; # Search
i) __i=1 ;; # Ignore case when searching S) __S=1;; # Print Statistics
l) __l=1 ;; # List all bookmarks t) __t="${OPTARG}";; # tags for a URL
L) __L=1 ;; # List all tags T) __T="${OPTARG}";; # Title for a URL
n) __n=1 ;; # sort by date v|V) echo -n "${0} v${VERSION}"; [[ "${option}" = 'V' ]] && echo -n " [commit: ${RELEASE}]"; echo ''; exit 0;;
N) __N=1 ;; # sort by date (reverse) w) __w="${OPTARG}";; # Working directory
o) x) __x=1; __copy="${OPTARG}";; # Copy
__o=1 X) __X=1;; # Copy First
__open="${OPTARG}" Y) __Y=1;; # Open/copy All
;; # Open z) __z=1;; # Alternative print listing
O) __O=1 ;; # Open First :) echo "Missing argument for '-${OPTARG}'" >&2 ; exit 1 ;;
p) __p=1 ;; # Take a screenshot ?) echo "Argument unknown '-${OPTARG}'" >&2 ; exit 1 ;; # usage;;
P) *) echo "Argument unknown '-${option}'" >&2 ; exit 1 ;; # usage;;
__P=1
__search="${OPTARG}"
;; # Take all screenshot
q)
__q=1
__search="${OPTARG}"
;; # Search
r)
__r=1
__search="${OPTARG}"
;; # Search
s)
__s=1
__search="${OPTARG}"
;; # Search
S) __S=1 ;; # Print Statistics
t) __t="${OPTARG}" ;; # tags for a URL
T) __T="${OPTARG}" ;; # Title for a URL
v | V)
echo -n "${0} v${VERSION}"
[[ "${option}" = 'V' ]] && echo -n " [commit: ${RELEASE}]"
echo ''
exit 0
;;
w) __w="${OPTARG}" ;; # Working directory
x)
__x=1
__copy="${OPTARG}"
;; # Copy
X) __X=1 ;; # Copy First
Y) __Y=1 ;; # Open/copy All
z) __z=1 ;; # Alternative print listing
:)
echo "Missing argument for '-${OPTARG}'" >&2
exit 1
;;
?)
echo "Argument unknown '-${OPTARG}'" >&2
exit 1
;; # usage;;
*)
echo "Argument unknown '-${option}'" >&2
exit 1
;; # usage;;
esac esac
done done
fi fi
@ -1013,92 +884,42 @@ config "${__c}"
# Following config, we maybe not have to check the capture tool # Following config, we maybe not have to check the capture tool
[[ ${_BM_CMD_CAPTURE_CHECK} ]] && checkBinaries "${_BM_CMD_CAPTURE}" [[ ${_BM_CMD_CAPTURE_CHECK} ]] && checkBinaries "${_BM_CMD_CAPTURE}"
# If no bookmark file exist, create one if allowed else echo # If no bookmark file exist, create one if allowed
if [ ! -f "${_BM_BOOKMARK_FILE}" -a "${_BM_CREATE_BOOKMARK_FILE,,}" = 'true' ]; then if [ ! -f "${_BM_BOOKMARK_FILE}" -a "${_BM_CREATE_BOOKMARK_FILE,,}" = 'true' ]; then
# Remember fields : 0=md5, 1=date, 2=accel, 3=url, 4=title, 5=tags # Remember fields : 1=md5, 2=date, 2=accel, 3=url, 4=title, 5=tags
echo "eef521de8df447ad392dbace16cf2edc|$(date '+%FT%TZ')|:bm|https://github.com/The-Repo-Club/repomenu-extra/|Download link for repomenu-extra|default,shell,scripts" >>"${_BM_BOOKMARK_FILE}" echo "eef521de8df447ad392dbace16cf2edc|$(date '+%FT%TZ')|:bm|https://github.com/The-Repo-Club/repomenu-extra/|Download link for repomenu-extra|default,shell,scripts" >> "${_BM_BOOKMARK_FILE}"
fi
if [ ! -f "${_BM_BOOKMARK_FILE}" -a "${_BM_CREATE_BOOKMARK_FILE,,}" = 'false' ]; then
echo "No current bookmark file found.";
exit
fi fi
# Starting to work with args. If none probably list... # Starting to work with args. If none probably list...
[[ ${#} -eq 0 && "${_BM_NO_ARGS_FORCE_HELP,,}" = 'true' ]] && { [[ ${#} -eq 0 && "${_BM_NO_ARGS_FORCE_HELP,,}" = 'true' ]] && { usage ; exit; }
usage
exit
}
# Only one action at a time # Only one action at a time
if [ $((${__a:=0} + ${__C:=0} + ${__d:=0} + ${__E:=0} + ${__g:=0} + ${__l:=0} + ${__L:=0} + ${__o:=0} + ${__P:=0} + ${__q:=0} + ${__r:=0} + ${__s:=0} + ${__S:=0} + ${__x:=0})) -gt 1 ]; then if [ $(( ${__a:=0} + ${__C:=0} + ${__d:=0} + ${__E:=0} + ${__g:=0} + ${__l:=0} + ${__L:=0} + ${__o:=0} + ${__P:=0} + ${__q:=0} + ${__r:=0} + ${__s:=0} + ${__S:=0} + ${__x:=0} )) -gt 1 ]; then
echo "You have to choose between -a, -C, -d, -E, -g, -l, -L, -o, -P, -q, -r, -s, -S, -x" >&2 echo "You have to choose between -a, -C, -d, -E, -g, -l, -L, -o, -P, -q, -r, -s, -S, -x" >&2
echo "Use -h for help" >&2 echo "Use -h for help" >&2
exit 0 exit 0
fi fi
if [ $((${__O:=0} + ${__Y:=0} + ${__X:=0})) -gt 1 ]; then if [ $(( ${__O:=0} + ${__Y:=0} + ${__X:=0} )) -gt 1 ]; then
echo "You have to choose between -O, -X, -Y" >&2 echo "You have to choose between -O, -X, -Y" >&2
echo "Use -h for help" >&2 echo "Use -h for help" >&2
exit 0 exit 0
fi fi
# Executing actions # Executing actions
[[ ${__a} -eq 1 ]] && { [[ ${__a} -eq 1 ]] && { saveUrl ; exit ; }
saveUrl [[ ${__C} -eq 1 ]] && { defineColors 1 ; exit ; }
exit [[ ${__d} -eq 1 ]] && { delete_bookmark "${__del}"; exit ; }
} [[ ${__g} -ge 1 ]] && { bookmark_generator "${__file:=}" ''; exit ; }
[[ ${__C} -eq 1 ]] && { [[ ${__l} -eq 1 ]] && { search ; exit; }
defineColors 1 [[ ${__L} -eq 1 ]] && { list_tags ; exit; }
exit [[ ${__o} -eq 1 ]] && { open_bookmark "${__open}" ; exit; }
} [[ ${__P} -eq 1 ]] && { picturize "${__search}" ; exit; }
[[ ${__d} -eq 1 ]] && { [[ ${__r} -eq 1 ]] && { recorded_picture "${__search}" ; exit; }
delete_bookmark "${__del}" [[ ${__q} -eq 1 ]] && { download_title "${__search}" ; exit; }
exit [[ ${__s} -eq 1 ]] && { search_bookmarks "${__search}" ; exit; }
} [[ ${__S} -eq 1 ]] && { stats ; exit; }
[[ ${__g} -ge 1 ]] && { [[ ${__x} -eq 1 ]] && { copy_bookmark "${__copy}" ; exit; }
bookmark_generator "${__file:=}" '' [[ ${__E} -eq 1 ]] && { edit_bookmark ; exit; }
exit
}
[[ ${__l} -eq 1 ]] && {
search
exit
}
[[ ${__L} -eq 1 ]] && {
list_tags
exit
}
[[ ${__o} -eq 1 ]] && {
open_bookmark "${__open}"
exit
}
[[ ${__P} -eq 1 ]] && {
picturize "${__search}"
exit
}
[[ ${__r} -eq 1 ]] && {
recorded_picture "${__search}"
exit
}
[[ ${__q} -eq 1 ]] && {
download_title "${__search}"
exit
}
[[ ${__s} -eq 1 ]] && {
search_bookmarks "${__search}"
exit
}
[[ ${__S} -eq 1 ]] && {
stats
exit
}
[[ ${__x} -eq 1 ]] && {
copy_bookmark "${__copy}"
exit
}
[[ ${__E} -eq 1 ]] && {
edit_bookmark
exit
}
search search
# $Format:%cn @ %cD$ : $Id$ # $Format:%cn @ %cD$ : $Id$

View File

@ -12,7 +12,7 @@
#Created: #Created:
# Fri 09 December 2022, 06:43:41 AM [GMT] # Fri 09 December 2022, 06:43:41 AM [GMT]
#Modified: #Modified:
# Fri 09 December 2022, 08:02:52 AM [GMT] # Fri 14 July 2023, 11:04:29 PM [GMT+1]
# #
#Description: #Description:
# <Todo> # <Todo>
@ -22,7 +22,7 @@
# #
# shellcheck disable=all # shellcheck disable=all
bmFile="$HOME/.config/rofi/bookmarks/bm.bmf" bmFile="$HOME/.config/rofi/bookmarks/bm.bm"
if [[ ! -f $bmFile ]]; then if [[ ! -f $bmFile ]]; then
printf "%s\n" "No current bookmark file found."; printf "%s\n" "No current bookmark file found.";

View File

@ -12,7 +12,7 @@
#Created: #Created:
# Fri 09 December 2022, 06:43:30 AM [GMT] # Fri 09 December 2022, 06:43:30 AM [GMT]
#Modified: #Modified:
# Fri 09 December 2022, 08:02:26 AM [GMT] # Fri 14 July 2023, 11:04:22 PM [GMT+1]
# #
#Description: #Description:
# <Todo> # <Todo>
@ -22,7 +22,7 @@
# #
# shellcheck disable=all # shellcheck disable=all
bmFile="$HOME/.config/rofi/bookmarks/bm.bmf" bmFile="$HOME/.config/rofi/bookmarks/bm.bm"
if [[ ! -f $bmFile ]]; then if [[ ! -f $bmFile ]]; then
printf "%s\n" "No current bookmark file found."; printf "%s\n" "No current bookmark file found.";