diff options
-rwxr-xr-x | examples/data/scripts/insert_bookmark.sh | 15 | ||||
-rwxr-xr-x | examples/data/scripts/load_url_from_bookmarks.sh | 14 | ||||
-rwxr-xr-x | examples/data/scripts/load_url_from_history.sh | 17 | ||||
-rwxr-xr-x | examples/data/scripts/session.sh | 66 |
4 files changed, 58 insertions, 54 deletions
diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 65fb5c5..d99ff31 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -1,19 +1,16 @@ #!/bin/sh -. $UZBL_UTIL_DIR/uzbl-dir.sh +. "$UZBL_UTIL_DIR"/uzbl-args.sh +. "$UZBL_UTIL_DIR"/uzbl-dir.sh [ -d "$UZBL_DATA_DIR" ] || exit 1 [ -w "$UZBL_BOOKMARKS_FILE" ] || [ ! -a "$UZBL_BOOKMARKS_FILE" ] || exit 1 which zenity 2>&1 >/dev/null || exit 2 -# replace tabs, they are pointless in titles and we want to use tabs as delimiter. -title=$(echo "$UZBL_TITLE" | sed 's/\t/ /') -entry=$(zenity --entry --text="Add bookmark. add tags after the '\t', separated by spaces" --entry-text="$UZBL_URL $title\t") + +tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URL:") exitstatus=$? -if [ $exitstatus -ne 0 ]; then exit $exitstatus; fi -url=$(echo $entry | awk '{print $1}') +[ $exitstatus -eq 0 ] || exit $exitstatus # TODO: check if already exists, if so, and tags are different: ask if you want to replace tags -echo "$entry" >/dev/null #for some reason we need this.. don't ask me why -printf "$entry\n" >> $UZBL_BOOKMARKS_FILE -true +echo "$UZBL_URL $tags" >> "$UZBL_BOOKMARKS_FILE" diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 9af83c3..9346526 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -5,19 +5,19 @@ DMENU_SCHEME="bookmarks" DMENU_OPTIONS="xmms vertical resize" -. $UZBL_UTIL_DIR/dmenu.sh -. $UZBL_UTIL_DIR/uzbl-args.sh -. $UZBL_UTIL_DIR/uzbl-dir.sh +. "$UZBL_UTIL_DIR"/dmenu.sh +. "$UZBL_UTIL_DIR"/uzbl-args.sh +. "$UZBL_UTIL_DIR"/uzbl-dir.sh [ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 if [ -z "$DMENU_HAS_VERTICAL" ]; then # because they are all after each other, just show the url, not their tags. - goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU) + goto=$(awk '{print $1}' "$UZBL_BOOKMARKS_FILE" | $DMENU) else # show tags as well - goto=$($DMENU < $UZBL_BOOKMARKS_FILE | awk '{print $1}') + goto=$($DMENU < "$UZBL_BOOKMARKS_FILE" | awk '{print $1}') fi -#[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO -[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$UZBL_SOCKET +[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO" +#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:"$UZBL_SOCKET" diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 1f540c9..4499e7f 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -3,23 +3,22 @@ DMENU_SCHEME="history" DMENU_OPTIONS="xmms vertical resize" -. $UZBL_UTIL_DIR/dmenu.sh -. $UZBL_UTIL_DIR/uzbl-args.sh -. $UZBL_UTIL_DIR/uzbl-dir.sh +. "$UZBL_UTIL_DIR"/dmenu.sh +. "$UZBL_UTIL_DIR"/uzbl-args.sh +. "$UZBL_UTIL_DIR"/uzbl-dir.sh [ -r "$UZBL_HISTORY_FILE" ] || exit 1 # choose from all entries, sorted and uniqued # goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) if [ -z "$DMENU_HAS_VERTICAL" ]; then - current=$(tail -n 1 $UZBL_HISTORY_FILE | awk '{print $3}'); - goto=$((echo $current; awk '{print $3}' $UZBL_HISTORY_FILE | grep -v "^$current\$" \ - | sort -u) | $DMENU) + current=$(tail -n 1 "$UZBL_HISTORY_FILE" | awk '{print $3}'); + goto=$((echo $current; awk '{print $3}' "$UZBL_HISTORY_FILE" | grep -v "^$current\$" | sort -u) | $DMENU) else # choose an item in reverse order, showing also the date and page titles # pick the last field from the first 3 fields. this way you can pick a url (prefixed with date & time) or type just a new url. - goto=$(tac $UZBL_HISTORY_FILE | $DMENU | cut -d ' ' -f -3 | awk '{print $NF}') + goto=$(tac "$UZBL_HISTORY_FILE" | $DMENU | cut -d ' ' -f -3 | awk '{print $NF}') fi -#[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO -[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:$UZBL_SOCKET +[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO" +#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:"$UZBL_SOCKET" diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 046ad64..203cd52 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -1,32 +1,43 @@ #!/bin/sh +# +# Very simple session manager for uzbl-browser. +# To use, add a line like 'bind quit = spawn @scripts_dir/session.sh endsession' +# to your config. +# To restore the session, run this script with the argument "launch". An +# instance of uzbl-browser will be launched for each stored url. +# +# When called with "endsession" as the argument, it will backup +# $UZBL_SESSION_FILE, look for fifos in $UZBL_FIFO_DIR and instruct each of them +# to store its current url in $UZBL_SESSION_FILE and terminate. +# +# "endinstance" is used internally and doesn't need to be called manually. -# Very simple session manager for uzbl-browser. When called with "endsession" as the -# argument, it'll backup $sessionfile, look for fifos in $fifodir and -# instruct each of them to store their current url in $sessionfile and -# terminate themselves. Run with "launch" as the argument and an instance of -# uzbl-browser will be launched for each stored url. "endinstance" is used internally -# and doesn't need to be called manually at any point. -# Add a line like 'bind quit = /path/to/session.sh endsession' to your config - -. $UZBL_UTIL_DIR/uzbl-args.sh -. $UZBL_UTIL_DIR/uzbl-dir.sh +if [ -z "$UZBL_UTIL_DIR" ]; then + # we're being run standalone, we have to figure out where $UZBL_UTIL_DIR is + # using the same logic as uzbl-browser does. + UZBL_UTIL_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/scripts/util + if ! [ -d "$UZBL_UTIL_DIR" ]; then + PREFIX=$(grep '^PREFIX' "$(which uzbl-browser)" | sed 's/.*=//') + UZBL_UTIL_DIR=$PREFIX/share/uzbl/examples/data/scripts/util + fi +fi -[ -d $UZBL_DATA_DIR ] || exit 1 +. "$UZBL_UTIL_DIR"/uzbl-dir.sh +[ -d "$UZBL_DATA_DIR" ] || exit 1 -scriptfile=$0 # this script UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here. -act="$1" - -# Test if we were run alone or from uzbl -if [ -z "$UZBL_SOCKET" ]; then - # Take the old config - act="$UZBL_CONFIG" +if [ $# -gt 1 ]; then + # this script is being run from uzbl, rather than standalone + . "$UZBL_UTIL_DIR"/uzbl-args.sh fi +scriptfile=$0 # this script +act="$1" + case $act in "launch" ) - urls=$(cat $UZBL_SESSION_FILE) + urls=$(cat "$UZBL_SESSION_FILE") if [ -z "$urls" ]; then $UZBL else @@ -35,28 +46,25 @@ case $act in disown done fi - exit 0 ;; "endinstance" ) - if [ -z "$UZBL_SOCKET" ]; then + if [ -z "$UZBL_FIFO" ]; then echo "session manager: endinstance must be called from uzbl" exit 1 fi - if [ ! "$UZBL_URL" = "(null)" ]; then - echo "$UZBL_URL" >> $UZBL_SESSION_FILE - fi - echo "exit" | socat - unix-connect:$UZBL_SOCKET + [ "$UZBL_URL" != "(null)" ] && echo "$UZBL_URL" >> "$UZBL_SESSION_FILE" + echo exit > "$UZBL_FIFO" ;; "endsession" ) mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" - for sock in $UZBL_SOCKET_DIR/uzbl_fifo_*; do - if [ "$sock" != "$UZBL_SOCKET" ]; then - echo "spawn $scriptfile endinstance" | socat - unix-connect:$socket + for fifo in "$UZBL_FIFO_DIR"/uzbl_fifo_*; do + if [ "$fifo" != "$UZBL_FIFO" ]; then + echo "spawn $scriptfile endinstance" > "$fifo" fi done - echo "spawn $scriptfile endinstance" | socat - unix-connect:$UZBL_SOCKET + echo "spawn $scriptfile endinstance" > "$UZBL_FIFO" ;; * ) |