3 # Copyright (c) 2000-2002 Timothy M. King (tmk@lordzork.com)
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 # DEALINGS IN THE SOFTWARE.
23 PATH
=$PATH:/usr
/bin
:/usr
/local
/bin
:/usr
/X
11R
6/bin
25 img_apps
="qiv xli xv wmsetbg Esetroot display xsetbg"
27 display_full_cmd
="display -geometry 800x600 -window root"
28 display_tile_cmd
="display -window root"
29 display_center_cmd
="display -backdrop -window root"
30 display_default_cmd
="$display_center_cmd"
32 Esetroot_full_cmd
="Esetroot -scale"
33 Esetroot_tile_cmd
="Esetroot"
34 Esetroot_center_cmd
="Esetroot -c"
35 Esetroot_default_cmd
="$Esetroot_center_cmd"
37 wmsetbg_full_cmd
="wmsetbg -s -S"
38 wmsetbg_tile_cmd
="wmsetbg -t"
39 wmsetbg_center_cmd
="wmsetbg -e"
40 wmsetbg_default_cmd
="$wmsetbg_center_cmd"
42 qiv_full_cmd
="qiv --root_s"
43 qiv_tile_cmd
="qiv --root_t"
44 qiv_center_cmd
="qiv --root"
45 qiv_default_cmd
="$qiv_center_cmd"
47 xv_full_cmd
="xv -max -smooth -root -quit"
48 xv_tile_cmd
="xv -root -quit"
49 xv_center_cmd
="xv -rmode 5 -root -quit"
50 xv_default_cmd
="$xv_center_cmd"
52 xli_full_cmd
="xli -fullscreen -onroot -quiet"
53 xli_tile_cmd
="xli -onroot -quiet"
54 xli_center_cmd
="xli -center -onroot quiet"
55 xli_default_cmd
="$xli_center_cmd"
57 xsetbg_full_cmd
="xsetbg -fillscreen"
58 xsetbg_tile_cmd
="xsetbg"
59 xsetbg_center_cmd
="xsetbg -center"
60 xsetbg_default_cmd
="$xsetbg_center_cmd"
62 ##################################
66 copyright
="(c) 2000-$(date +%Y) by Timothy M. King (http://lordzork.com/)"
67 config
=$HOME/.bsetbgrc
68 last_cmd_file
=$HOME/.bsetbg_last_cmd
74 [ "$1" ] && rc
=$1 && shift 1
75 [ "$*" ] && echo -e $
*
82 [yY
][eE
][sS
]|1|[yY
]|[tT
][rR
][uU
][eE
]|[oO
][nN
]) : ;;
91 elif [ -x "$(which $1 2>/dev/null)" ]; then
93 elif [ -x "$(type $1 2>/dev/null)" ]; then
103 $me $version $copyright
105 -center <file> center an image on the desktop
106 -tile <file> tile an image on the desktop
107 -full <file> stretch an image to fill the desktop
108 -exec <args> <file> specify an external command to execute
110 -post <string> arguments to be passed to the post-command
111 -debug prints commands without executing them
114 # this is extremely lame, but probably more portable than grep -E
115 bsetroot_help
=$(bsetroot -help 2>&1| grep -v "^bsetroot" | grep -v "^ -help")
116 case $bsetroot_help in
117 BaseDisplay
*) echo ;;
118 *-gradient*) echo "$bsetroot_help"
122 -generate <string> generate a config file
124 -version output version information
131 for a
in $img_apps; do
132 if check_exe_in_path
$a; then
133 eval center_cmd
=\$
$a\_center_cmd
134 eval full_cmd
=\$
$a\_full_cmd
135 eval tile_cmd
=\$
$a\_tile_cmd
136 eval default_cmd
=\$
$a\_default_cmd
139 if [ "$not_found" ]; then
140 not_found
="$not_found $a"
151 echo -e "# created by $me $version on $(date)\n#"
152 echo -e "# seting NO_EXEC to a boolean value (eg true/false) will cause $me"
153 echo -e "# to never modify the root window\n#"
154 echo -e "#NO_EXEC=\n#"
155 echo -e "# POST_COMMAND can be set to a command that will be run run every time"
156 echo -e "# $me sets the root image\n#"
157 echo -e "#POST_COMMAND=\n#"
158 echo -e "# if LOG_LAST_CMD is set (boolean), bsetbg will keep a log of the last"
159 echo -e "# two successful commands.\n#"
160 echo -e "#LOG_LAST_CMD=\n#"
161 echo -e "# the LOGFILE specifies the file that bsetbg uses when LOG_LAST_CMD"
162 echo -e "# is defined. this defaults to ~/.bsetbg_last_cmd .\n#"
163 echo -e "#LOGFILE=\n#"
164 echo -e "# the following are default configuration values for the most popular image"
165 echo -e "# programs. See the man page of the respective application for more info.\n"
167 [ "$*" ] && img_apps
="$*"
169 for a
in $img_apps; do
170 if check_exe_in_path
$a; then
171 if ! bool
$have_match; then
173 [ "$(eval echo \$$a\_center_cmd)" ] &&
174 eval echo CENTER
=$q\$
$a\_center_cmd
$q &&
176 [ "$(eval echo \$$a\_full_cmd)" ] &&
177 eval echo FULL
=$q\$
$a\_full_cmd
$q &&
179 [ "$(eval echo \$$a\_tile_cmd)" ] &&
180 eval echo TILE
=$q\$
$a\_tile_cmd
$q &&
182 [ "$(eval echo \$$a\_default_cmd)" ] &&
183 eval echo -e DEFAULT
=$q\$
$a\_default_cmd
$q \\\\n
&&
187 [ "$(eval echo \$$a\_center_cmd)" ] &&
188 eval echo \\#CENTER=$q\$$a\_center_cmd$q
190 [ "$(eval echo \$$a\_full_cmd)" ] &&
191 eval echo \\#FULL=$q\$$a\_full_cmd$q
193 [ "$(eval echo \$$a\_tile_cmd)" ] &&
194 eval echo \\#TILE=$q\$$a\_tile_cmd$q
196 [ "$(eval echo \$$a\_default_cmd)" ] &&
197 eval echo -e \\#DEFAULT=$q\$$a\_default_cmd$q \\\\n
206 if check_exe_in_path bsetroot
; then
209 $debug bsetroot $
* 2>/dev
/null
; rc
=$?
211 if [ "$rc" -gt 0 ]; then
214 log_cmd bsetroot $
*; $refresh_cmd 2>/dev
/null
217 quit
1 "couldn't find bsetroot in $PATH"
223 [ -z "$1" ] && help_msg
1
225 bool
$noconfig || read_config
228 check_img_command
$do_this
235 if [ -f "$file" ]; then
236 exec_img_command
$do_this $file
238 quit
1 "$file does not exist"
244 [ "$#" -lt 3 ] && help_msg
3
246 bool
$noconfig || read_config
248 # check to see if -*c, -*f, or -*t were spcified, if so
249 # assume the last argument is a filename
250 b_arg
=$(eval echo \$$(( $# - 1 )) )
254 -c|*-center|c
|-t|*-tile*|t
|-f|*-full|f
)
256 f_args
="$b_arg $file"
259 # put the rest of the arguments into the varialbe $e_args
264 *) e_args
="$e_args "$1""
270 # with $f_args defined, check for image and do things normally
271 if [ "$f_args" ]; then
272 [ ! -f "$file" ] && quit
1 "$file does not exist"
274 if check_img_command
$e_args; then
278 get_img_command
$f_args
279 check_img_command
$do_this
280 echo "$p couldn't find '$app' in path, using $type command instead"
282 # without $f_args, run the command blindly if it's in $PATH
283 elif check_exe_in_path
$e_args; then
286 quit
1 "$p unable to run the following command: $e_args"
289 exec_img_command
$do_this $file
295 *-full|-f|f
) type=full
; do_this
="$full_cmd" ;;
296 *-tile|-t|t
) type=tile
; do_this
="$tile_cmd" ;;
297 *-center|-c|c
) type=center
; do_this
="$center_cmd" ;;
298 *) type=default
; do_this
="$default_cmd"
304 if check_exe_in_path
$1; then
311 quit
1 "$p couldn't find a suitable image program. tried the following:\\n
312 $(for a in $not_found; do echo " $a\\n"; done)"
315 if [ "$rc" -gt 0 -a -z "$e_args" ] && bool
$read_config; then
316 echo "$p couldn't find a suitable $type command in $config"
327 if [ "$debug" ]; then
330 $command >/dev
/null
2>&1; rc
=$?
333 if [ "$rc" -gt 0 ]; then
334 echo "$p '$command' exited with status $rc"
337 parse_args
${f_args:-$my_args}
338 echo "$p using '$command' as $type"
339 $debug $command >/dev
/null
2>&1; rc
=$?
340 [ "$rc" = 0 ] && log_cmd
$do_this $file && $refresh_cmd 2>/dev
/null
342 log_cmd
$do_this $file; xrefresh
2>/dev
/null
349 bool
$LOG_LAST_CMD || return 1
350 [ "$debug" ] && return 1
351 echo -e "$prev_cmd\n$*" >$last_cmd_file
357 [ -f $config ] || return 1
359 if bool
$read_config; then
365 .
$HOME/.bsetbgrc
2>/dev
/null
372 last_cmd_file
=${LOGFILE:-$last_cmd_file}
374 bool
$LOG_LAST_CMD && prev_cmd
=$(tail -n 1 $last_cmd_file 2>/dev/null)
380 quit
0 "$p no_exec mode. the root window will not be modified."
385 if [ -n "$POST_COMMAND" -a "$rc" -le 0 ]; then
386 if [ -n "$debug" ]; then
387 $debug "running post_command: $POST_COMMAND $post_args"
389 post_command_output
=$($POST_COMMAND $post_args 2>&1); erc
=$?
390 if [ "$erc" -gt 0 ]; then
391 echo "$p post-command '$POST_COMMAND $post_args' exited with status $erc"
392 [ -n "$post_command_output" ] &&
393 echo "$POST_COMMAND $post_args: $post_command_output"
411 [ -z "$1" ] && return 1
412 if [ "$post_args" ]; then
413 post_args
="$post_args $1"
421 if [ -z "$command" ]; then
422 command=${2:-$1}; eval ${3:-${2:-$1}}=1
423 elif bool
$do_post; then
434 unset refresh_cmd
; debug
=echo\
$me\_debug
: ;;
437 unset finished do_standard do_exec
; do_post
=1 ;;
439 -c|*-center|c
|-t|*-tile*|t
|-f|*-full|f
)
441 do_standard
|do_generate
|do_bsetroot
)
444 if ! bool
$got_fcmd; then
445 add_arg
$1 args
; got_fcmd
=1
450 add_arg
$1; do_standard
=1; command=do_standard
453 -a|*-app|a
|-e|*-exec|e
)
454 check_cmd
"do_exec" ;;
456 -mod|-gradient|-solid|-display)
457 check_cmd
"do_bsetroot" && add_arg
$1 ;;
460 check_cmd
$1 "do_generate" ;;
463 [ -z "$command" ] && quit
0 $me $version $copyright ;;
466 [ -z "$command" ] && help_msg
;;
469 bool
$finished && return 1
472 bool
$do_exec || bool
$do_bsetroot || bool
$do_post || help_msg
1
475 if bool
$do_standard || bool
$do_exec || bool
$do_bsetroot || bool
$do_generate; then
477 elif bool
$do_post; then
480 add_arg
$1; command=do_standard
; finished
=1
485 [ -z "$*" ] && help_msg
1