From b9cc0b3e0a9ed7f5ce1181e94cf813544011547e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 10:07:26 -0400 Subject: Put `then' on the same line as `if' --- examples/data/scripts/instance-select-wmii.sh | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'examples/data/scripts/instance-select-wmii.sh') diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index fdd27e6..1340351 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -13,39 +13,32 @@ COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030" -if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]' -then +if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'; then DMENU="dmenu -i -xs -rs -l 10" # vertical patch else DMENU="dmenu -i" fi -if [ "$1" == 'list' ] -then +if [ "$1" == 'list' ]; then 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 + for i in $(wmiir read /tag/sel/index | grep uzbl |cut -d ' ' -f2); do label=$(wmiir read /client/$i/label) list="$list$i : $label\n" done window=$(echo -e "$list" | $DMENU $COLORS | cut -d ' ' -f1) wmiir xwrite /tag/sel/ctl "select client $window" -elif [ "$1" == 'next' ] -then +elif [ "$1" == 'next' ]; then 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) - if [ x"$next" != "x" ] - then + if [ x"$next" != "x" ]; then wmiir xwrite /tag/sel/ctl "select client $next" fi -elif [ "$1" == 'prev' ] -then +elif [ "$1" == 'prev' ]; then 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) - if [ x"$prev" != "x" ] - then + if [ x"$prev" != "x" ]; then wmiir xwrite /tag/sel/ctl "select client $prev" fi else -- cgit v1.2.3 From 8eed5f24a0d40574433c3f3a945e6aac75e06aba Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 11:37:25 -0400 Subject: Migrate to using the dmenu util script --- examples/data/scripts/formfiller.sh | 19 ++++++------------- examples/data/scripts/instance-select-wmii.sh | 10 ++-------- examples/data/scripts/load_url_from_bookmarks.sh | 14 ++++++-------- examples/data/scripts/load_url_from_history.sh | 21 +++++++++------------ 4 files changed, 23 insertions(+), 41 deletions(-) (limited to 'examples/data/scripts/instance-select-wmii.sh') diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 2c792bc..cf8e46b 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -37,22 +37,15 @@ # something else (or empty): if file not available: new, otherwise load. # -# config dmenu colors and prompt -NB="#0f0f0f" -NF="#4e7093" -SB="#003d7c" -SF="#3a9bff" - -if [ "$(dmenu --help 2>&1 | grep lines)x" != "x" ]; then - LINES=" -l 3 " -else - LINES="" -fi +DMENU_ARGS="-i" +DMENU_SCHEMA="formfiller" +DMENU_LINES="3" +DMENU_PROMPT="Choose profile" +source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh -PROMPT="Choose profile" MODELINE="> vim:ft=formfiller" [ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1 @@ -139,7 +132,7 @@ if [ "$action" = 'load' ]; then 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}") + option=$(echo -e -n "$menu" | $DMENU) fi # Remove comments diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index 1340351..82acf3b 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -11,13 +11,7 @@ # See http://www.uzbl.org/wiki/wmii for more info # $1 must be one of 'list', 'next', 'prev' -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 -else - DMENU="dmenu -i" -fi +source $UZBL_UTIL_DIR/dmenu.sh if [ "$1" == 'list' ]; then list= @@ -26,7 +20,7 @@ if [ "$1" == 'list' ]; then label=$(wmiir read /client/$i/label) list="$list$i : $label\n" done - window=$(echo -e "$list" | $DMENU $COLORS | cut -d ' ' -f1) + window=$(echo -e "$list" | $DMENU | cut -d ' ' -f1) wmiir xwrite /tag/sel/ctl "select client $window" elif [ "$1" == 'next' ]; then current=$(wmiir read /client/sel/ctl | head -n 1) diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 3bcb60f..1cf8ea4 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -2,20 +2,18 @@ #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. +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 -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 < $UZBL_BOOKMARKS_FILE | awk '{print $1}') +if [ "x$DMENU_HAS_VERTICAL" = "x" ]; then + # because they are all after each other, just show the url, not their tags. + goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU) else - DMENU="dmenu -i" - # because they are all after each other, just show the url, not their tags. - goto=$(awk '{print $1}' $UZBL_BOOKMARKS_FILE | $DMENU $COLORS) + # show tags as well + goto=$($DMENU < $UZBL_BOOKMARKS_FILE | awk '{print $1}') fi #[ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 5aba844..f79e018 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -1,24 +1,21 @@ #!/bin/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}' $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 $UZBL_HISTORY_FILE | $DMENU $COLORS | cut -d ' ' -f -3 | awk '{print $NF}') +# goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) +if [ "x$DMENU_HAS_VERTICAL" = "x" ]; 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) 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 $UZBL_HISTORY_FILE | awk '{print $3}'); - goto=$((echo $current; awk '{print $3}' $UZBL_HISTORY_FILE | grep -v "^$current\$" \ - | sort -u) | $DMENU $COLORS) + # 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}') fi [ -n "$goto" ] && echo "uri $goto" > $UZBL_FIFO -- cgit v1.2.3 From e0e443e5c5bbd7663542788401d0e44da91e301e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:02:11 -0400 Subject: Use -z and -n tests rather than "x$foo" = "x" hack --- examples/data/scripts/download.sh | 5 ++++- examples/data/scripts/instance-select-wmii.sh | 4 ++-- examples/data/scripts/load_url_from_bookmarks.sh | 2 +- examples/data/scripts/load_url_from_history.sh | 2 +- examples/data/scripts/session.sh | 6 +++--- examples/data/scripts/util/dmenu.sh | 6 +++--- examples/data/scripts/util/editor.sh | 2 +- 7 files changed, 15 insertions(+), 12 deletions(-) (limited to 'examples/data/scripts/instance-select-wmii.sh') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index f2ee4a8..7375535 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -13,7 +13,10 @@ url="$1" http_proxy="$2" export http_proxy -test "x$url" = "x" && { echo "you must supply a url! ($url)"; exit 1; } +if [ -z "$url" ]; then + echo "you must supply a url! ($url)" + exit 1 +fi # only changes the dir for the $get sub process if echo "$url" | grep -E '.*\.torrent' >/dev/null; then diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index 82acf3b..dcb8866 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -26,13 +26,13 @@ elif [ "$1" == 'next' ]; then 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) - if [ x"$next" != "x" ]; then + if [ -n "$next" ]; then wmiir xwrite /tag/sel/ctl "select client $next" fi elif [ "$1" == 'prev' ]; then 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) - if [ x"$prev" != "x" ]; then + if [ -n "$prev" ]; then wmiir xwrite /tag/sel/ctl "select client $prev" fi else diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index d5f7bd6..7613624 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -8,7 +8,7 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh [ -r "$UZBL_BOOKMARKS_FILE" ] || exit 1 -if [ "x$DMENU_HAS_VERTICAL" = "x" ]; then +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) else diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index f79e018..ca8959c 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -8,7 +8,7 @@ source $UZBL_UTIL_DIR/uzbl-dir.sh # choose from all entries, sorted and uniqued # goto=$(awk '{print $3}' $history_file | sort -u | dmenu -i) -if [ "x$DMENU_HAS_VERTICAL" = "x" ]; then +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) diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh index d30f3da..3f1c6d3 100755 --- a/examples/data/scripts/session.sh +++ b/examples/data/scripts/session.sh @@ -19,7 +19,7 @@ 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 [ "x$UZBL_FIFO" = "x" ]; then +if [ -z "$UZBL_FIFO" ]; then # Take the old config act="$UZBL_CONFIG" fi @@ -27,7 +27,7 @@ fi case $act in "launch" ) urls=$(cat $UZBL_SESSION_FILE) - if [ "x$urls" = "x" ]; then + if [ -z "$urls" ]; then $UZBL else for url in $urls; do @@ -39,7 +39,7 @@ case $act in ;; "endinstance" ) - if [ "x$UZBL_FIFO" = "x" ]; then + if [ -z "$UZBL_FIFO" ]; then echo "session manager: endinstance must be called from uzbl" exit 1 fi diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh index 3f307f2..2326cea 100644 --- a/examples/data/scripts/util/dmenu.sh +++ b/examples/data/scripts/util/dmenu.sh @@ -40,12 +40,12 @@ case "$DMENU_SCHEME" in esac # Default arguments -if [ "x$DMENU_ARGS" = "x" ]; then +if [ -z "$DMENU_ARGS" ]; then DMENU_ARGS="-i" fi # Set the prompt if wanted -if [ ! "x$DMENU_PROMPT" = "x" ]; then +if [ -n "$DMENU_PROMPT" ]; then DMENU_ARGS="$DMENU_ARGS -p $DMENU_PROMPT" fi @@ -58,7 +58,7 @@ fi # Detect the vertical patch if dmenu --help 2>&1 | grep -q '\[-l lines\]'; then # Default to 10 lines - if [ "x$DMENU_LINES" = "x" ]; then + if [ -z "$DMENU_LINES" ]; then DMENU_LINES=10 fi diff --git a/examples/data/scripts/util/editor.sh b/examples/data/scripts/util/editor.sh index a152ebd..1969769 100644 --- a/examples/data/scripts/util/editor.sh +++ b/examples/data/scripts/util/editor.sh @@ -1,7 +1,7 @@ #!/bin/sh # Editor selection -if [ "x$VTERM" = "x" ]; then +if [ -z "$VTERM" ]; then VTERM="xterm" fi -- cgit v1.2.3 From cfd3ff8fcff8aad7b57d8b757c2401f58aebd561 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 21 Aug 2010 12:02:43 -0400 Subject: Use a case statement in the wmii script --- examples/data/scripts/instance-select-wmii.sh | 57 +++++++++++++++------------ 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'examples/data/scripts/instance-select-wmii.sh') diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index dcb8866..1fc6ed0 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -13,29 +13,34 @@ source $UZBL_UTIL_DIR/dmenu.sh -if [ "$1" == 'list' ]; then - 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) - list="$list$i : $label\n" - done - window=$(echo -e "$list" | $DMENU | cut -d ' ' -f1) - wmiir xwrite /tag/sel/ctl "select client $window" -elif [ "$1" == 'next' ]; then - 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) - if [ -n "$next" ]; then - wmiir xwrite /tag/sel/ctl "select client $next" - fi -elif [ "$1" == 'prev' ]; then - 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) - if [ -n "$prev" ]; then - wmiir xwrite /tag/sel/ctl "select client $prev" - fi -else - echo "\$1 not valid" >&2 - exit 2 -fi +case "$1" in + "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) + list="$list$i : $label\n" + done + window=$(echo -e "$list" | $DMENU | cut -d ' ' -f1) + wmiir xwrite /tag/sel/ctl "select client $window" + ;; + "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) + 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) + if [ -n "$prev" ]; then + wmiir xwrite /tag/sel/ctl "select client $prev" + fi + ;; + * ) + echo "$1 not valid" >&2 + exit 2 + ;; +esac -- cgit v1.2.3 From fa27c93805d19d9aabae896a359b77767afc9de0 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Oct 2010 15:50:19 -0400 Subject: Set the dmenu theme properly --- examples/data/scripts/instance-select-wmii.sh | 2 ++ examples/data/scripts/load_url_from_bookmarks.sh | 2 ++ examples/data/scripts/load_url_from_history.sh | 2 ++ 3 files changed, 6 insertions(+) (limited to 'examples/data/scripts/instance-select-wmii.sh') diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh index 1fc6ed0..967d7ad 100755 --- a/examples/data/scripts/instance-select-wmii.sh +++ b/examples/data/scripts/instance-select-wmii.sh @@ -11,6 +11,8 @@ # See http://www.uzbl.org/wiki/wmii for more info # $1 must be one of 'list', 'next', 'prev' +DMENU_SCHEME="wmii" + source $UZBL_UTIL_DIR/dmenu.sh case "$1" in diff --git a/examples/data/scripts/load_url_from_bookmarks.sh b/examples/data/scripts/load_url_from_bookmarks.sh index 7613624..2c2a926 100755 --- a/examples/data/scripts/load_url_from_bookmarks.sh +++ b/examples/data/scripts/load_url_from_bookmarks.sh @@ -2,6 +2,8 @@ #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. +DMENU_SCHEME="bookmarks" + source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh diff --git a/examples/data/scripts/load_url_from_history.sh b/examples/data/scripts/load_url_from_history.sh index 80cd3d8..2d15b4f 100755 --- a/examples/data/scripts/load_url_from_history.sh +++ b/examples/data/scripts/load_url_from_history.sh @@ -1,5 +1,7 @@ #!/bin/sh +DMENU_SCHEME="history" + source $UZBL_UTIL_DIR/dmenu.sh source $UZBL_UTIL_DIR/uzbl-args.sh source $UZBL_UTIL_DIR/uzbl-dir.sh -- cgit v1.2.3