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