From b4cfab85863b9fc14cfd3f890b53a9253841010d Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 12:43:42 -0700 Subject: insert_bookmark.sh was totally busted --- examples/data/scripts/insert_bookmark.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 08d7d2b..9303b85 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -1,19 +1,16 @@ #!/bin/sh +source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh [ -d "$UZBL_DATA_DIR" ] || exit 1 [ -w "$UZBL_BOOKMARKS_FILE" ] || [ ! -a "$UZBL_BOOKMARKS_FILE" ] || exit 1 which zenity &>/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 -echo -e "$entry" >> $UZBL_BOOKMARKS_FILE -true +echo "$UZBL_URL $tags" >> "$UZBL_BOOKMARKS_FILE" -- cgit v1.2.3 From 7afc00bfd43ee8ee4329a664605d59a7603c9a6a Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 13:58:48 -0700 Subject: load_url_from_*: don't require socat, fix some quoting issues --- examples/data/scripts/load_url_from_bookmarks.sh | 14 +++++++------- examples/data/scripts/load_url_from_history.sh | 17 ++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 564c3f8..ed1e2e8 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" -source $UZBL_UTIL_DIR/dmenu.sh -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +source "$UZBL_UTIL_DIR"/dmenu.sh +source "$UZBL_UTIL_DIR"/uzbl-args.sh +source "$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 d094625..8582bc3 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" -source $UZBL_UTIL_DIR/dmenu.sh -source $UZBL_UTIL_DIR/uzbl-args.sh -source $UZBL_UTIL_DIR/uzbl-dir.sh +source "$UZBL_UTIL_DIR"/dmenu.sh +source "$UZBL_UTIL_DIR"/uzbl-args.sh +source "$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" -- cgit v1.2.3 From 344bc3f53ade206bafb8466645c8ed57e49f1b62 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 24 Nov 2010 14:00:07 -0700 Subject: make session.sh work with the split util scripts --- examples/data/scripts/session.sh | 66 ++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index 89eeb7a..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 - -source $UZBL_UTIL_DIR/uzbl-args.sh -source $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" ;; * ) -- cgit v1.2.3