Fixed problems with bookmark script, added in control+alt+b keybinding.
This commit is contained in:
parent
dd67bdf8a9
commit
6eece49afc
3
i38.sh
3
i38.sh
@ -423,6 +423,9 @@ bindsym \$mod+Shift+F1 exec ${i3Path}/scripts/i38-help.sh
|
||||
# Run dialog
|
||||
bindsym \$mod+F2 exec ${i3Path}/scripts/run_dialog.sh
|
||||
|
||||
# Bookmarks dialog
|
||||
bindsym \$mod+Control+b exec ${i3Path}/scripts/bookmarks.sh
|
||||
|
||||
# Clipboard manager
|
||||
bindsym \$mod+Control+c exec clipster -s
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
add_bookmark() {
|
||||
while : ; do
|
||||
if [[ -r ~/.config/surfraw/bookmarks ]] && [[ -f ~/.config/i3/bookmarks ]]; then
|
||||
if [[ -r "${config}/surfraw/bookmarks" ]] && [[ -r "${config}/i3/bookmarks" ]]; then
|
||||
# Ask for the Bookmark Title, URL, and file selection using yad --form with radio buttons
|
||||
input=$(yad --form \
|
||||
--title="I38 - Add Bookmark" \
|
||||
@ -45,9 +45,9 @@ add_bookmark() {
|
||||
fi
|
||||
|
||||
# Check for spaces in title and prompt user
|
||||
if [[ "$title" =~ \ ]] && [[ "$bookmarkFile" =~ surfraw ]]; then
|
||||
if [[ "$title" =~ \ ]] && [[ "$bookmarkFile" == "Surfraw Bookmark" ]]; then
|
||||
newTitle="${title//[[:space:]]/_}"
|
||||
yad --question --title="I38 - Bookmarks" --text="The title contains spaces, which have been converted to underscores: \"$new_title\". Is this okay?"
|
||||
yad --question --title="I38 - Bookmarks" --text="The title contains spaces, which have been converted to underscores: \"$newTitle\". Is this okay?"
|
||||
yadCode="$?"
|
||||
if [[ $yadCode -ne 0 ]]; then
|
||||
continue
|
||||
@ -57,42 +57,42 @@ add_bookmark() {
|
||||
fi
|
||||
|
||||
# Determine the bookmarks file based on radio button selection
|
||||
if [ -f ~/.config/surfraw/bookmarks ] && [ -f ~/.config/i3/bookmarks ]; then
|
||||
if [[ "$bookmark_file" == "Surfraw Bookmark" ]]; then
|
||||
bookmarks_file=~/.config/surfraw/bookmarks
|
||||
if [[ -f "${config}/surfraw/bookmarks" ]] && [[ -f "${config}/i3/bookmarks" ]]; then
|
||||
if [[ "$bookmarkFile" == "Surfraw Bookmark" ]]; then
|
||||
bookmarksFile="${config}/surfraw/bookmarks"
|
||||
else
|
||||
bookmarks_file=~/.config/i3/bookmarks
|
||||
bookmarksFile="${config}/i3/bookmarks"
|
||||
fi
|
||||
else
|
||||
bookmarks_file=~/.config/surfraw/bookmarks
|
||||
[ -f ~/.config/i3/bookmarks ] && bookmarks_file=~/.config/i3/bookmarks
|
||||
bookmarksFile="${config}/surfraw/bookmarks"
|
||||
[[ -f "${config}/i3/bookmarks" ]] && bookmarksFile="${config}/i3/bookmarks"
|
||||
fi
|
||||
|
||||
# Check for duplicates
|
||||
if grep -q "$url" "$bookmarksFile" ; then
|
||||
existingTitle=$(grep "$url" "$bookmarks_file" | cut -d' ' -f1)
|
||||
yad --info --title="I38 - Bookmarks" --text="This site is already bookmarked as \"$existingTitle\"."
|
||||
existingTitle=$(grep "$url" "$bookmarksFile" | cut -d' ' -f1)
|
||||
yad --form --title="I38 - Bookmarks" --selectable-labels --field="This site is already bookmarked as \"$existingTitle\".":LBL --button="OK:0"
|
||||
return
|
||||
elif grep -qi "^$title " "$bookmarksFile"; then
|
||||
yad --info --title="I38 Bookmarks" --text="A bookmark with the title \"$title\" already exists."
|
||||
yad --form --title="I38 - Bookmarks" --selectable-labels --field="A bookmark with the title \"$title\" already exists.":LBL --button="OK:0"
|
||||
return
|
||||
fi
|
||||
|
||||
# Add the new bookmark
|
||||
echo "$title $url" >> "$bookmarks_file"
|
||||
echo "$title $url" >> "$bookmarksFile"
|
||||
|
||||
# Ensure no duplicates with sort -u
|
||||
sort -u "$bookmarks_file" -o "$bookmarks_file"
|
||||
yad --info --title="I38 - Bookmarks" --selectable-lables --text="Bookmark \"$title\" added successfully."
|
||||
sort -u "$bookmarksFile" -o "$bookmarksFile"
|
||||
yad --form --title="I38 - Bookmarks" --selectable-labels --field="Bookmark \"$title\" added successfully.":LBL --button="OK:0"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
declare -a bookmarks
|
||||
export config="${XDG_CONFIG_HOME:-${HOME}/.config}"
|
||||
# Prepare environment and read bookmarks
|
||||
declare -a bookmarks
|
||||
config="${XDG_CONFIG_HOME:-${HOME}/.config}"
|
||||
if [[ -r "${config}/surfraw/bookmarks" ]]; then
|
||||
mapfile -t contents < <(cat "${config}/surfraw/bookmarks")
|
||||
mapfile -t contents < "${config}/surfraw/bookmarks"
|
||||
for i in "${contents[@]}" ; do
|
||||
title="${i% *}"
|
||||
title="${title//_/ }"
|
||||
@ -101,14 +101,13 @@ if [[ -r "${config}/surfraw/bookmarks" ]]; then
|
||||
done
|
||||
fi
|
||||
if [[ -r "${config}/i3/bookmarks" ]]; then
|
||||
mapfile -t contents < <(cat "${config}/i3/bookmarks")
|
||||
mapfile -t contents < "${config}/i3/bookmarks"
|
||||
for i in "${contents[@]}" ; do
|
||||
bookmarks+=("${i% *}" "${i##* }")
|
||||
done
|
||||
fi
|
||||
declare -a menuList
|
||||
|
||||
|
||||
# Run yad to display the dialog
|
||||
url=$(yad --list \
|
||||
--title="I38 - Bookmarks" \
|
||||
--text="Select a bookmark to open" \
|
||||
@ -130,3 +129,4 @@ case ${yadCode} in
|
||||
1) add_bookmark;;
|
||||
2) exit 0;;
|
||||
esac
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user