aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/data/scripts/download.sh15
-rwxr-xr-xexamples/data/scripts/follow.sh14
-rwxr-xr-xexamples/data/scripts/go_input.sh8
-rwxr-xr-xexamples/data/scripts/history.sh6
-rwxr-xr-xexamples/data/scripts/insert_bookmark.sh14
-rwxr-xr-xexamples/data/scripts/instance-select-wmii.sh28
-rwxr-xr-xexamples/data/scripts/load_cookies.sh17
-rwxr-xr-xexamples/data/scripts/load_url_from_bookmarks.sh13
-rwxr-xr-xexamples/data/scripts/load_url_from_history.sh16
-rwxr-xr-xexamples/data/scripts/session.sh47
-rw-r--r--examples/data/scripts/util/uzbl-dir.sh18
-rw-r--r--examples/data/scripts/util/uzbl-util.sh3
-rw-r--r--examples/data/scripts/util/uzbl-window.sh18
13 files changed, 118 insertions, 99 deletions
diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh
index c410ad2..8b4761f 100755
--- a/examples/data/scripts/download.sh
+++ b/examples/data/scripts/download.sh
@@ -6,20 +6,23 @@
# that path.
# if nothing is printed to stdout, the download will be cancelled.
-. $UZBL_UTIL_DIR/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+. "$UZBL_UTIL_DIR/uzbl-util.sh"
# the URL that is being downloaded
-uri=$1
+uri="$1"
+
+safe_uri="$( print "$uri" | sed -e 's/\W/-/g' )"
# a filename suggested by the server or based on the URL
-suggested_filename=${2:-$(echo "$uri" | sed 's/\W/-/g')}
+suggested_filename="${2:-$safe_uri}"
# the mimetype of the file being downloaded
-content_type=$3
+content_type="$3"
# the size of the downloaded file in bytes. this is not always accurate, since
# the server might not have sent a size with its response headers.
-total_size=$4
+total_size="$4"
# just save the file to the default directory with the suggested name
-echo $UZBL_DOWNLOAD_DIR/$suggested_filename
+print "$UZBL_DOWNLOAD_DIR/$suggested_filename\n"
diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh
index 1f8947d..014793e 100755
--- a/examples/data/scripts/follow.sh
+++ b/examples/data/scripts/follow.sh
@@ -2,10 +2,12 @@
# This scripts acts on the return value of followLinks in follow.js
case "$1" in
- XXXEMIT_FORM_ACTIVEXXX)
- # a form element was selected
- printf 'event FORM_ACTIVE\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO" ;;
- XXXRESET_MODEXXX)
- # a link was selected, reset uzbl's input mode
- printf 'set mode=\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO" ;;
+ XXXEMIT_FORM_ACTIVEXXX)
+ # a form element was selected
+ printf 'event FORM_ACTIVE\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO"
+ ;;
+ XXXRESET_MODEXXX)
+ # a link was selected, reset uzbl's input mode
+ printf 'set mode=\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO"
+ ;;
esac
diff --git a/examples/data/scripts/go_input.sh b/examples/data/scripts/go_input.sh
index ace0e79..ad236d1 100755
--- a/examples/data/scripts/go_input.sh
+++ b/examples/data/scripts/go_input.sh
@@ -1,5 +1,9 @@
#!/bin/sh
-case $(echo 'script @scripts_dir/go_input.js' | socat - unix-connect:"$UZBL_SOCKET") in
- *XXXEMIT_FORM_ACTIVEXXX*) echo 'event FORM_ACTIVE' > "$UZBL_FIFO" ;;
+. "$UZBL_UTIL_DIR/uzbl-util.sh"
+
+case "$( print "script @scripts_dir/go_input.js\n" | socat - "unix-connect:$UZBL_SOCKET" )" in
+ *XXXEMIT_FORM_ACTIVEXXX*)
+ print "event FORM_ACTIVE\n" > "$UZBL_FIFO"
+ ;;
esac
diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh
index 266d65d..d1e3c0f 100755
--- a/examples/data/scripts/history.sh
+++ b/examples/data/scripts/history.sh
@@ -1,7 +1,7 @@
#!/bin/sh
-. $UZBL_UTIL_DIR/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
-[ -w "$UZBL_HISTORY_FILE" ] || [ ! -a "$UZBL_HISTORY_FILE" ] || exit 1
+>> "$UZBL_HISTORY_FILE" || exit 1
-echo $(date +'%Y-%m-%d %H:%M:%S')" $UZBL_URI $UZBL_TITLE" >> $UZBL_HISTORY_FILE
+print "$( date +'%Y-%m-%d %H:%M:%S' ) $UZBL_URI $UZBL_TITLE\n" >> "$UZBL_HISTORY_FILE"
diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh
index f67e67a..5d41131 100755
--- a/examples/data/scripts/insert_bookmark.sh
+++ b/examples/data/scripts/insert_bookmark.sh
@@ -1,15 +1,15 @@
#!/bin/sh
-. "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+. "$UZBL_UTIL_DIR/uzbl-util.sh"
-[ -d "$UZBL_DATA_DIR" ] || exit 1
-[ -w "$UZBL_BOOKMARKS_FILE" ] || [ ! -a "$UZBL_BOOKMARKS_FILE" ] || exit 1
+>> "$UZBL_BOOKMARKS_FILE" || exit 1
which zenity >/dev/null 2>&1 || exit 2
-tags=$(zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URI:")
-exitstatus=$?
-[ $exitstatus -eq 0 ] || exit $exitstatus
+tags="$( zenity --entry --text="Enter space-separated tags for bookmark $UZBL_URI:" )"
+exitstatus="$?"
+[ "$exitstatus" -eq 0 ] || exit "$exitstatus"
# TODO: check if already exists, if so, and tags are different: ask if you want to replace tags
-echo "$UZBL_URI $tags" >> "$UZBL_BOOKMARKS_FILE"
+print "$UZBL_URI $tags\n" >> "$UZBL_BOOKMARKS_FILE"
diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh
index 19d04e8..d340dda 100755
--- a/examples/data/scripts/instance-select-wmii.sh
+++ b/examples/data/scripts/instance-select-wmii.sh
@@ -1,6 +1,5 @@
#!/bin/sh
-
# This script allows you to focus another uzbl window
# It considers all uzbl windows in the current tag
# you can select one from a list, or go to the next/previous one
@@ -13,36 +12,37 @@
DMENU_SCHEME="wmii"
-. $UZBL_UTIL_DIR/dmenu.sh
+. "$UZBL_UTIL_DIR/dmenu.sh"
+. "$UZBL_UTIL_DIR/uzbl-util.sh"
case "$1" in
- "list" )
- list=
+ "list")
+ list=""
# get window id's of uzbl clients. we could also get the label in one shot but it's pretty tricky
- for i in $(wmiir read /tag/sel/index | grep uzbl |cut -d ' ' -f2); do
- label=$(wmiir read /client/$i/label)
+ for i in $( wmiir read /tag/sel/index | grep uzbl | cut -d ' ' -f 2 ); do
+ label="$( wmiir read /client/$i/label )"
list="$list$i : $label\n"
done
- window=$(printf "$list\n" | $DMENU | cut -d ' ' -f1)
+ window="$( print "$list\n" | $DMENU | cut -d ' ' -f 1 )"
wmiir xwrite /tag/sel/ctl "select client $window"
;;
- "next" )
- current=$(wmiir read /client/sel/ctl | head -n 1)
+ "next")
+ current="$( wmiir read /client/sel/ctl | head -n 1 )"
# find the next uzbl window and focus it
- next=$(wmiir read /tag/sel/index | grep -A 10000 " $current " | grep -m 1 uzbl | cut -d ' ' -f2)
+ next="$( wmiir read /tag/sel/index | grep -A 10000 " $current " | grep -m 1 uzbl | cut -d ' ' -f 2 )"
if [ -n "$next" ]; then
wmiir xwrite /tag/sel/ctl "select client $next"
fi
;;
- "prev" )
- current=$(wmiir read /client/sel/ctl | head -n 1)
- prev=$(wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f2)
+ "prev")
+ current="$( wmiir read /client/sel/ctl | head -n 1 )"
+ prev="$( wmiir read /tag/sel/index | grep -B 10000 " $current " | tac | grep -m 1 uzbl | cut -d ' ' -f 2 )"
if [ -n "$prev" ]; then
wmiir xwrite /tag/sel/ctl "select client $prev"
fi
;;
* )
- echo "$1 not valid" >&2
+ print "$1 not valid\n" >&2
exit 2
;;
esac
diff --git a/examples/data/scripts/load_cookies.sh b/examples/data/scripts/load_cookies.sh
index 17ec2ad..c7fcc58 100755
--- a/examples/data/scripts/load_cookies.sh
+++ b/examples/data/scripts/load_cookies.sh
@@ -1,20 +1,21 @@
#!/bin/sh
-if [ "$1" != "" ]; then
- cookie_file=$1
+if [ -n "$1" ]; then
+ cookie_file="$1"
+ shift
else
- cookie_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt
+ cookie_file="${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt"
fi
awk -F \\t '
BEGIN {
- scheme["TRUE"] = "https";
- scheme["FALSE"] = "http";
+ scheme["TRUE"] = "https";
+ scheme["FALSE"] = "http";
}
$0 ~ /^#HttpOnly_/ {
-printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", substr($1,length("#HttpOnly_"),length($1)), $3, $6, $7, scheme[$4], $5)
+ printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", substr($1,length("#HttpOnly_"),length($1)), $3, $6, $7, scheme[$4], $5)
}
$0 !~ /^#/ {
-printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $3, $6, $7, scheme[$4], $5)
+ printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $3, $6, $7, scheme[$4], $5)
}
-' $cookie_file
+' "$cookie_file"
diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh
index a5d9586..30417f1 100755
--- a/examples/data/scripts/load_url_from_bookmarks.sh
+++ b/examples/data/scripts/load_url_from_bookmarks.sh
@@ -5,18 +5,19 @@
DMENU_SCHEME="bookmarks"
DMENU_OPTIONS="xmms vertical resize"
-. "$UZBL_UTIL_DIR"/dmenu.sh
-. "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/dmenu.sh"
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+. "$UZBL_UTIL_DIR/uzbl-util.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" | cut -d ' ' -f 1 )"
fi
-[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO"
-#[ -n "$goto" ] && echo "uri $goto" | socat - unix-connect:"$UZBL_SOCKET"
+[ -n "$goto" ] && print "uri $goto\n" > "$UZBL_FIFO"
+#[ -n "$goto" ] && print "uri $goto\n" | 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 59ad492..0a6769a 100755
--- a/examples/data/scripts/load_url_from_history.sh
+++ b/examples/data/scripts/load_url_from_history.sh
@@ -3,21 +3,21 @@
DMENU_SCHEME="history"
DMENU_OPTIONS="xmms vertical resize"
-. "$UZBL_UTIL_DIR"/dmenu.sh
-. "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/dmenu.sh"
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+. "$UZBL_UTIL_DIR/uzbl-util.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" | cut -d ' ' -f 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" ] && print "uri $goto\n" > "$UZBL_FIFO"
+#[ -n "$goto" ] && print "uri $goto\n" | socat - "unix-connect:$UZBL_SOCKET"
diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh
index ee09cf2..d03554b 100755
--- a/examples/data/scripts/session.sh
+++ b/examples/data/scripts/session.sh
@@ -18,28 +18,31 @@
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
+ 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
+ PREFIX="$( grep '^PREFIX' "$( which uzbl-browser )" | sed -e 's/.*=//' )"
+ UZBL_UTIL_DIR="$PREFIX/share/uzbl/examples/data/scripts/util"
fi
fi
-. "$UZBL_UTIL_DIR"/uzbl-dir.sh
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+. "$UZBL_UTIL_DIR/uzbl-util.sh"
+
[ -d "$UZBL_DATA_DIR" ] || exit 1
-UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here.
+UZBL="uzbl-browser -c \"$UZBL_CONFIG_FILE\"" # add custom flags and whatever here.
-scriptfile=$(readlink -f $0) # this script
+scriptfile="$( readlink -f "$0" )" # this script
act="$1"
+shift
if [ -z "$act" ]; then
[ -f "$UZBL_SESSION_FILE" ] && act="launch" || act="endsession"
fi
case $act in
- "launch" )
- urls=$(cat "$UZBL_SESSION_FILE")
+ "launch")
+ urls="$( cat "$UZBL_SESSION_FILE" )"
if [ -z "$urls" ]; then
$UZBL
else
@@ -50,29 +53,29 @@ case $act in
fi
;;
- "endinstance" )
+ "endinstance")
if [ -z "$UZBL_FIFO" ]; then
- echo "session manager: endinstance must be called from uzbl"
+ print "session manager: endinstance must be called from uzbl\n"
exit 1
fi
- [ "$UZBL_URI" != "(null)" ] && echo "$UZBL_URI" >> "$UZBL_SESSION_FILE"
- echo exit > "$UZBL_FIFO"
+ [ "$UZBL_URI" != "(null)" ] && print "$UZBL_URI\n" >> "$UZBL_SESSION_FILE"
+ print "exit\n" > "$UZBL_FIFO"
;;
- "endsession" )
- for fifo in "$UZBL_FIFO_DIR"/uzbl_fifo_*; do
+ "endsession")
+ for fifo in "$UZBL_FIFO_DIR/uzbl_fifo_*"; do
if [ "$fifo" != "$UZBL_FIFO" ]; then
- echo "spawn $scriptfile endinstance" > "$fifo"
+ print "spawn $scriptfile endinstance\n" > "$fifo"
fi
done
- [ -z "$UZBL_FIFO" ] || echo "spawn $scriptfile endinstance" > "$UZBL_FIFO"
+ [ -z "$UZBL_FIFO" ] || print "spawn $scriptfile endinstance\n" > "$UZBL_FIFO"
;;
- * )
- echo "session manager: bad action"
- echo "Usage: $scriptfile [COMMAND] where commands are:"
- echo " launch - Restore a saved session or start a new one"
- echo " endinstance - Quit the current instance. Must be called from uzbl"
- echo " endsession - Quit the running session."
+ *)
+ print "session manager: bad action\n"
+ print "Usage: $scriptfile [COMMAND] where commands are:\n"
+ print " launch - Restore a saved session or start a new one\n"
+ print " endinstance - Quit the current instance. Must be called from uzbl\n"
+ print " endsession - Quit the running session.\n"
;;
esac
diff --git a/examples/data/scripts/util/uzbl-dir.sh b/examples/data/scripts/util/uzbl-dir.sh
index bb56954..3d28151 100644
--- a/examples/data/scripts/util/uzbl-dir.sh
+++ b/examples/data/scripts/util/uzbl-dir.sh
@@ -2,18 +2,18 @@
# Common directories and files used in scripts
# Common things first
-UZBL_DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl
-UZBL_CONFIG_DIR=${XDG_CONFIG_DIR:-$HOME/.config}/uzbl
+UZBL_DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/uzbl"
+UZBL_CONFIG_DIR="${XDG_CONFIG_DIR:-$HOME/.config}/uzbl"
UZBL_FIFO_DIR=/tmp
UZBL_SOCKET_DIR=/tmp
# Directories
-UZBL_DOWNLOAD_DIR=${XDG_DOWNLOAD_DIR:-$HOME}
-UZBL_FORMS_DIR=$UZBL_DATA_DIR/dforms
+UZBL_DOWNLOAD_DIR="${XDG_DOWNLOAD_DIR:-$HOME}"
+UZBL_FORMS_DIR="$UZBL_DATA_DIR/dforms"
# Data files
-UZBL_CONFIG_FILE=$UZBL_CONFIG_DIR/config
-UZBL_COOKIE_FILE=$UZBL_DATA_DIR/cookies.txt
-UZBL_BOOKMARKS_FILE=$UZBL_DATA_DIR/bookmarks
-UZBL_HISTORY_FILE=$UZBL_DATA_DIR/history
-UZBL_SESSION_FILE=$UZBL_DATA_DIR/browser-session
+UZBL_CONFIG_FILE="$UZBL_CONFIG_DIR/config"
+UZBL_COOKIE_FILE="$UZBL_DATA_DIR/cookies.txt"
+UZBL_BOOKMARKS_FILE="$UZBL_DATA_DIR/bookmarks"
+UZBL_HISTORY_FILE="$UZBL_DATA_DIR/history"
+UZBL_SESSION_FILE="$UZBL_DATA_DIR/browser-session"
diff --git a/examples/data/scripts/util/uzbl-util.sh b/examples/data/scripts/util/uzbl-util.sh
new file mode 100644
index 0000000..7e0bd99
--- /dev/null
+++ b/examples/data/scripts/util/uzbl-util.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+alias print="printf %b"
diff --git a/examples/data/scripts/util/uzbl-window.sh b/examples/data/scripts/util/uzbl-window.sh
index a7e92eb..856e5fa 100644
--- a/examples/data/scripts/util/uzbl-window.sh
+++ b/examples/data/scripts/util/uzbl-window.sh
@@ -1,11 +1,13 @@
#!/bin/sh
# uzbl window detection
-UZBL_WIN_POS=$(xwininfo -id $UZBL_XID | \
- sed -ne 's/Corners:[ ]*[+-]\([0-9]*\)[+-]\([0-9]*\).*$/\1 \2/p')
-UZBL_WIN_SIZE=$(xwininfo -id $UZBL_XID | \
- sed -ne 's/-geometry[ ]*\([0-9]*\)x\([0-9]*\).*$/\1 \2/p')
-UZBL_WIN_POS_X=$(echo $UZBL_WIN_POS | cut -d\ -f1)
-UZBL_WIN_POS_Y=$(echo $UZBL_WIN_POS | cut -d\ -f2)
-UZBL_WIN_WIDTH=$(echo $UZBL_WIN_SIZE | cut -d\ -f1)
-UZBL_WIN_HEIGHT=$(echo $UZBL_WIN_SIZE | cut -d\ -f2)
+. "$UZBL_UTIL_DIR/uzbl-util.sh"
+
+UZBL_WIN_POS="$( xwininfo -id "$UZBL_XID" | \
+ sed -n -e '[ ]*s/Corners:[ ]*[+-]\([0-9]*\)[+-]\([0-9]*\).*$/\1 \2/p' )"
+UZBL_WIN_SIZE="$( xwininfo -id "$UZBL_XID" | \
+ sed -n -e '[ ]*s/-geometry[ ]*\([0-9]*\)x\([0-9]*\).*$/\1 \2/p' )"
+UZBL_WIN_POS_X="$( print "$UZBL_WIN_POS" | cut -d ' ' -f 1 )"
+UZBL_WIN_POS_Y="$( print "$UZBL_WIN_POS" | cut -d ' ' -f 2 )"
+UZBL_WIN_WIDTH="$( print "$UZBL_WIN_SIZE" | cut -d ' ' -f 1 )"
+UZBL_WIN_HEIGHT="$( print "$UZBL_WIN_SIZE" | cut -d ' ' -f 2 )"