From 391ffa73dfa46beea7dff2c9789a5f56a39227c4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:40:45 -0400 Subject: Migrate to using uzbl-dir util script --- examples/data/scripts/download.sh | 9 +++--- examples/data/scripts/formfiller.sh | 36 +++++++++++------------- examples/data/scripts/history.sh | 8 ++++-- examples/data/scripts/insert_bookmark.sh | 8 ++++-- examples/data/scripts/load_url_from_bookmarks.sh | 10 ++++--- examples/data/scripts/load_url_from_history.sh | 13 +++++---- examples/data/scripts/session.sh | 20 ++++++------- 7 files changed, 55 insertions(+), 49 deletions(-) diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 0f051db..5b4baa7 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -2,10 +2,11 @@ # just an example of how you could handle your downloads # try some pattern matching on the uri to determine what we should do +source $UZBL_UTIL_DIR/uzbl-dir.sh + # Some sites block the default wget --user-agent.. -GET="wget --user-agent=Firefox --content-disposition --load-cookies=$XDG_DATA_HOME/uzbl/cookies.txt" +GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR" -dest="$HOME" url="$8" http_proxy="$9" @@ -15,7 +16,7 @@ test "x$url" = "x" && { echo "you must supply a url! ($url)"; exit 1; } # only changes the dir for the $get sub process if echo "$url" | grep -E '.*\.torrent' >/dev/null; then - ( cd "$dest"; $GET "$url") + ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") else - ( cd "$dest"; $GET "$url") + ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") fi diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index f6962c4..3aa1676 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -2,7 +2,7 @@ # # Enhanced html form (eg for logins) filler (and manager) for uzbl. # -# uses settings files like: $keydir/ +# uses settings files like: $UZBL_FORMS_DIR/ # files contain lines like: !profile= # (fieldtype): # profile_name should be replaced with a name that will tell sth about that @@ -49,13 +49,13 @@ else LINES="" fi +source $UZBL_UTIL_DIR/uzbl-dir.sh + PROMPT="Choose profile" MODELINE="> vim:ft=formfiller" -keydir=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/dforms - -[ -d "$(dirname $keydir)" ] || exit 1 -[ -d "$keydir" ] || mkdir "$keydir" +[ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1 +[ -d $UZBL_FORMS_DIR ] || mkdir $UZBL_FORMS_DIR || exit 1 editor="${VISUAL}" if [ -z "${editor}" ]; then @@ -82,14 +82,12 @@ title=$1; shift action=$1 -[ -d $keydir ] || mkdir $keydir || exit 1 - domain=$(echo $url | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/') if [ "$action" != 'edit' -a "$action" != 'new' -a "$action" != 'load' -a "$action" != 'add' -a "$action" != 'once' ]; then action="new" - [ -e "$keydir/$domain" ] && action="load" -elif [ "$action" = 'edit' ] && [ ! -e "$keydir/$domain" ]; then + [ -e "$UZBL_FORMS_DIR/$domain" ] && action="load" +elif [ "$action" = 'edit' ] && [ ! -e "$UZBL_FORMS_DIR/$domain" ]; then action="new" fi @@ -150,9 +148,9 @@ insertFunction="function insert(fname, ftype, fvalue, fchecked) { \ }; " if [ "$action" = 'load' ]; then - [ -e $keydir/$domain ] || exit 2 - if [ $(cat $keydir/$domain | grep "!profile" | wc -l) -gt 1 ]; then - menu=$(cat $keydir/$domain | \ + [ -e $UZBL_FORMS_DIR/$domain ] || exit 2 + if [ $(cat $UZBL_FORMS_DIR/$domain | grep "!profile" | wc -l) -gt 1 ]; then + menu=$(cat $UZBL_FORMS_DIR/$domain | \ sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p') option=$(echo -e -n "$menu" | dmenu ${LINES} -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}") fi @@ -160,8 +158,8 @@ if [ "$action" = 'load' ]; then # Remove comments sed '/^>/d' -i $tmpfile - sed 's/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):\(off\|no\|false\|unchecked\|0\|$\)/\1{\2}(\3):0/I;s/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[^0]\+/\1{\2}(\3):1/I' -i $keydir/$domain - fields=$(cat $keydir/$domain | \ + sed 's/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):\(off\|no\|false\|unchecked\|0\|$\)/\1{\2}(\3):0/I;s/^\([^{]\+\){\([^}]*\)}(\(radio\|checkbox\)):[^0]\+/\1{\2}(\3):1/I' -i $UZBL_FORMS_DIR/$domain + fields=$(cat $UZBL_FORMS_DIR/$domain | \ sed -n "/^!profile=${option}/,/^!profile=/p" | \ sed '/^!profile=/d' | \ sed 's/^\([^(]\+(\)\(radio\|checkbox\|text\|search\|textarea\|password\)):/%{>\1\2):<}%/' | \ @@ -202,8 +200,8 @@ elif [ "$action" = "once" ]; then rm -f $tmpfile else if [ "$action" = 'new' -o "$action" = 'add' ]; then - [ "$action" = 'new' ] && echo "$MODELINE" > $keydir/$domain - echo "!profile=NAME_THIS_PROFILE$RANDOM" >> $keydir/$domain + [ "$action" = 'new' ] && echo "$MODELINE" > $UZBL_FORMS_DIR/$domain + echo "!profile=NAME_THIS_PROFILE$RANDOM" >> $UZBL_FORMS_DIR/$domain # # 2. and 3. line (tr -d and sed) are because, on gmail login for example, # tag is splited into lines @@ -222,10 +220,10 @@ else # printf 'js %s dump(); \n' "$dumpFunction" | \ socat - unix-connect:$socket | \ - sed -n '/^[^(]\+([^)]\+):/p' >> $keydir/$domain + sed -n '/^[^(]\+([^)]\+):/p' >> $UZBL_FORMS_DIR/$domain fi - [ -e "$keydir/$domain" ] || exit 3 #this should never happen, but you never know. - $editor "$keydir/$domain" #TODO: if user aborts save in editor, the file is already overwritten + [ -e "$UZBL_FORMS_DIR/$domain" ] || exit 3 #this should never happen, but you never know. + $editor "$UZBL_FORMS_DIR/$domain" #TODO: if user aborts save in editor, the file is already overwritten fi # vim:fileencoding=utf-8:sw=4 diff --git a/examples/data/scripts/history.sh b/examples/data/scripts/history.sh index be5fd34..b91d415 100755 --- a/examples/data/scripts/history.sh +++ b/examples/data/scripts/history.sh @@ -1,5 +1,7 @@ #!/bin/sh -file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/history -[ -d $(dirname $file) ] || exit 1 -echo $(date +'%Y-%m-%d %H:%M:%S')" $6 $7" >> $file +source $UZBL_UTIL_DIR/uzbl-dir.sh + +[ -w "$UZBL_HISTORY_FILE" ] || exit 1 + +echo $(date +'%Y-%m-%d %H:%M:%S')" $6 $7" >> $UZBL_HISTORY_FILE diff --git a/examples/data/scripts/insert_bookmark.sh b/examples/data/scripts/insert_bookmark.sh index 4d29ad6..201bae0 100755 --- a/examples/data/scripts/insert_bookmark.sh +++ b/examples/data/scripts/insert_bookmark.sh @@ -1,7 +1,9 @@ #!/bin/sh -[ -d "${XDG_DATA_HOME:-$HOME/.local/share}/uzbl" ] || exit 1 -file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/bookmarks +source $UZBL_UTIL_DIR/uzbl-dir.sh + +[ -d "$UZBL_DATA_DIR" ] || exit 1 +[ -w "$UZBL_BOOKMARKS_FILE" ] || exit 1 which zenity &>/dev/null || exit 2 url=$6 @@ -14,5 +16,5 @@ url=$(echo $entry | awk '{print $1}') # 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" >> $file +echo -e "$entry" >> $UZBL_BOOKMARKS_FILE true diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 3134407..9a955ec 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -2,17 +2,19 @@ #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. -file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/bookmarks -[ -r "$file" ] || exit +source $UZBL_UTIL_DIR/uzbl-dir.sh + +[ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 + COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch # show tags as well - goto=$($DMENU $COLORS < $file | awk '{print $1}') + goto=$($DMENU $COLORS < $UZBL_BOOKMARKS_FILE | awk '{print $1}') else DMENU="dmenu -i" # because they are all after each other, just show the url, not their tags. - goto=$(awk '{print $1}' $file | $DMENU $COLORS) + goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU $COLORS) fi #[ -n "$goto" ] && echo "uri $goto" > $4 diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 5156eee..9fea1eb 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -1,21 +1,22 @@ #!/bin/sh -history_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/history -[ -r "$history_file" ] || exit 1 +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) +# goto=$(awk '{print $3}' $UZBL_HISTORY_FILE | sort -u | dmenu -i) COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch # 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 $history_file | $DMENU $COLORS | cut -d ' ' -f -3 | awk '{print $NF}') + goto=$(tac $UZBL_HISTORY_FILE | $DMENU $COLORS | cut -d ' ' -f -3 | awk '{print $NF}') else DMENU="dmenu -i" # choose from all entries (no date or title), the first one being current url, and after that all others, sorted and uniqued, in ascending order - current=$(tail -n 1 $history_file | awk '{print $3}'); - goto=$((echo $current; awk '{print $3}' $history_file | grep -v "^$current\$" \ + 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 $COLORS) fi diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index acd6934..68ce4d4 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -8,13 +8,13 @@ # 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 -[ -d ${XDG_DATA_HOME:-$HOME/.local/share}/uzbl ] || exit 1 -scriptfile=$0 # this script -sessionfile=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/browser-session # the file in which the "session" (i.e. urls) are stored -configfile=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/config # uzbl configuration file -UZBL="uzbl-browser -c $configfile" # add custom flags and whatever here. +source $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. -fifodir=/tmp # remember to change this if you instructed uzbl to put its fifos elsewhere thisfifo="$4" act="$8" url="$6" @@ -26,7 +26,7 @@ fi case $act in "launch" ) - urls=$(cat $sessionfile) + urls=$(cat $UZBL_SESSION_FILE) if [ "$urls." = "." ]; then $UZBL else @@ -39,14 +39,14 @@ case $act in "endinstance" ) if [ "$url" != "(null)" ]; then - echo "$url" >> $sessionfile; + echo "$url" >> $UZBL_SESSION_FILE fi echo "exit" > "$thisfifo" ;; "endsession" ) - mv "$sessionfile" "$sessionfile~" - for fifo in $fifodir/uzbl_fifo_*; do + mv "$UZBL_SESSION_FILE" "$UZBL_SESSION_FILE~" + for fifo in $UZBL_FIFO_DIR/uzbl_fifo_*; do if [ "$fifo" != "$thisfifo" ]; then echo "spawn $scriptfile endinstance" > "$fifo" fi -- cgit v1.2.3