diff options
author | rathnor <rathnor> | 2003-10-08 14:00:47 (GMT) |
---|---|---|
committer | rathnor <rathnor> | 2003-10-08 14:00:47 (GMT) |
commit | ae729342e964c7b6d3571884b55ce14ff27fa553 (patch) | |
tree | 2f3ad9e2441e936095821a917c0bd4b9dfdd699f /util | |
parent | 29a69a69c1a2f51d6fb790534a0da8683ee24eb9 (diff) | |
download | fluxbox_paul-ae729342e964c7b6d3571884b55ce14ff27fa553.zip fluxbox_paul-ae729342e964c7b6d3571884b55ce14ff27fa553.tar.bz2 |
avoid using getopts in fbsetbg, plus other tweaks
Diffstat (limited to 'util')
-rw-r--r-- | util/fbsetbg | 182 |
1 files changed, 105 insertions, 77 deletions
diff --git a/util/fbsetbg b/util/fbsetbg index 4cd0ab3..fccf90b 100644 --- a/util/fbsetbg +++ b/util/fbsetbg | |||
@@ -23,7 +23,7 @@ | |||
23 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | 23 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
24 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 24 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
25 | # | 25 | # |
26 | # $Id: fbsetbg,v 1.20 2003/09/29 11:59:35 fluxgen Exp $ | 26 | # $Id: fbsetbg,v 1.21 2003/10/08 14:00:47 rathnor Exp $ |
27 | 27 | ||
28 | # Portability notes: | 28 | # Portability notes: |
29 | # To guarantee this script works on all platforms that support fluxbox | 29 | # To guarantee this script works on all platforms that support fluxbox |
@@ -40,9 +40,9 @@ | |||
40 | # the version you have. for example grep '\W' only works on gnu-grep. | 40 | # the version you have. for example grep '\W' only works on gnu-grep. |
41 | # Keep this in mind, use bare basic defaults. | 41 | # Keep this in mind, use bare basic defaults. |
42 | # - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash. | 42 | # - Do _NOT_ suggest to use #!/bin/bash. Not everybody uses bash. |
43 | # Non portable features like getopts in this script can be achieved in | ||
44 | # other ways. | ||
45 | 43 | ||
44 | # TODO purheps: xprop -root _WIN_WORKSPACE | ||
45 | # _NET_CURRENT_DESKTOP | ||
46 | 46 | ||
47 | # The wallpapersetter is selected in this order | 47 | # The wallpapersetter is selected in this order |
48 | wpsetters='Esetroot wmsetbg feh chbg display qiv xv xsri xli xsetbg' # broken icewmbg' | 48 | wpsetters='Esetroot wmsetbg feh chbg display qiv xv xsri xli xsetbg' # broken icewmbg' |
@@ -52,11 +52,14 @@ lastwallpaper=${HOME}/.fluxbox/lastwallpaper | |||
52 | WHOAMI=`whoami` | 52 | WHOAMI=`whoami` |
53 | [ "$WHOAMI" = root ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin | 53 | [ "$WHOAMI" = root ] && PATH=/bin:/usr/bin/:/usr/local/bin:/usr/X11R6/bin |
54 | 54 | ||
55 | command="`basename \"$0\"`" | ||
56 | |||
55 | 57 | ||
56 | # Functions | 58 | # Functions |
57 | display_usage() { | 59 | display_usage() { |
58 | cat << EOF | 60 | cat << EOF |
59 | Usage: fbsetbg [ -fFcCtTaA /path/to/wallpaper ] [ -l ] [ -h ] [ -d ] [ -p ] | 61 | Usage: $command [ -fFcCtTaA /path/to/wallpaper ] [ -l ] [ -h ] [ -i ] [ -p ] |
62 | Use $command -h for a complete help message. | ||
60 | EOF | 63 | EOF |
61 | } | 64 | } |
62 | 65 | ||
@@ -71,7 +74,7 @@ Options: | |||
71 | -t Set tiled wallpaper | 74 | -t Set tiled wallpaper |
72 | -a Set maximized wallpaper, preserving aspect. | 75 | -a Set maximized wallpaper, preserving aspect. |
73 | ( if your bgsetter doesn't support this | 76 | ( if your bgsetter doesn't support this |
74 | fbsetbg falls back to -f ) | 77 | we fall back to -f ) |
75 | 78 | ||
76 | -F,-C,-T,-A same as uncapsed but without remembering. | 79 | -F,-C,-T,-A same as uncapsed but without remembering. |
77 | 80 | ||
@@ -79,7 +82,8 @@ Options: | |||
79 | 82 | ||
80 | -l Set previous wallpaper | 83 | -l Set previous wallpaper |
81 | 84 | ||
82 | -d Debug fbsetbg | 85 | -i Information about selected wallpaper command |
86 | -d (deprecated, use -i) Debug info | ||
83 | -p Tips | 87 | -p Tips |
84 | 88 | ||
85 | Files: | 89 | Files: |
@@ -92,19 +96,20 @@ EOF | |||
92 | 96 | ||
93 | display_tips() { | 97 | display_tips() { |
94 | cat << EOF | 98 | cat << EOF |
99 | Common tips to use with $command: | ||
95 | 100 | ||
96 | 1) To replace all occurrences of bsetbg with fbsetbg in a file use this | 101 | 1) To replace all occurrences of bsetbg with $command in a file use this |
97 | command: | 102 | command: |
98 | 103 | ||
99 | perl -pi -e 's,([^f]|^)bsetbg,fbsetbg,' filename | 104 | perl -pi -e 's,([^f]|^)bsetbg,$command,' filename |
100 | 105 | ||
101 | 2) If you want the style to set the wallpaper and you want fbsetbg to | 106 | 2) If you want the style to set the wallpaper and you want $command to |
102 | remember the previous wallpaper put this in your ~/.fluxbox/init | 107 | remember the previous wallpaper put this in your ~/.fluxbox/init |
103 | 108 | ||
104 | session.screen0.rootCommand: fbsetbg -l | 109 | session.screen0.rootCommand: $command -l |
105 | 110 | ||
106 | 3) Use fbsetbg -d to find out what wallpapersetter fbsetbg will use and | 111 | 3) Use $command -i to find out what wallpapersetter $command will be |
107 | what he thinks about it. | 112 | used and what I think about it. |
108 | 113 | ||
109 | EOF | 114 | EOF |
110 | } | 115 | } |
@@ -133,7 +138,13 @@ case `uname` in | |||
133 | esac | 138 | esac |
134 | 139 | ||
135 | message() { | 140 | message() { |
136 | xmessage -center "$@" | 141 | # echo if we have terminal output, otherwise |
142 | # pop up a window | ||
143 | if [ -t 1 ]; then | ||
144 | echo "$command: $@" | ||
145 | else | ||
146 | xmessage -center "$command: $@" | ||
147 | fi | ||
137 | } | 148 | } |
138 | 149 | ||
139 | remembercommand() { | 150 | remembercommand() { |
@@ -163,77 +174,94 @@ for wpsetter in $wpsetters; do | |||
163 | done | 174 | done |
164 | 175 | ||
165 | standardrant=\ | 176 | standardrant=\ |
166 | "$WPSETTER sets the 'wrong' wallpaper. Transparency for fluxbox and apps like aterm | 177 | "$WPSETTER sets the 'wrong' wallpaper. Transparency for fluxbox and |
167 | and xchat won't work right with it. Consider using chbg, wmsetbg (from windowmaker) | 178 | apps like aterm and xchat won't work right with it. Consider installing |
168 | or Esetroot (from Eterm)" | 179 | chbg, wmsetbg (from windowmaker) or Esetroot (from Eterm) and I'll use |
180 | them instead." | ||
169 | 181 | ||
170 | standardok=\ | 182 | standardok=\ |
171 | "$WPSETTER is a nice wallpapersetter. You won't have any problems." | 183 | "$WPSETTER is a nice wallpapersetter. You won't have any problems." |
172 | 184 | ||
173 | unset debug | 185 | unset debug |
174 | #Get options. | ||
175 | getopts ":a:f:c:t:A:F:C:T:pdlh-" COMMAND_LINE_ARGUMENT | ||
176 | case "${COMMAND_LINE_ARGUMENT}" in | ||
177 | d) debug=true | ||
178 | ;; | ||
179 | a) option='$aspect' | ||
180 | wallpaper=$OPTARG | ||
181 | ;; | ||
182 | f) option='$full' | ||
183 | wallpaper=$OPTARG | ||
184 | ;; | ||
185 | c) option='$center' | ||
186 | wallpaper=$OPTARG | ||
187 | ;; | ||
188 | t) option='$tile' | ||
189 | wallpaper=$OPTARG | ||
190 | ;; | ||
191 | A) option='$aspect' | ||
192 | wallpaper=$OPTARG | ||
193 | remember=false | ||
194 | ;; | ||
195 | F) option='$full' | ||
196 | wallpaper=$OPTARG | ||
197 | remember=false | ||
198 | ;; | ||
199 | C) option='$center' | ||
200 | wallpaper=$OPTARG | ||
201 | remember=false | ||
202 | ;; | ||
203 | T) option='$tile' | ||
204 | wallpaper=$OPTARG | ||
205 | remember=false | ||
206 | ;; | ||
207 | 186 | ||
208 | l) | 187 | if [ $# -eq 0 ]; then |
209 | if [ -r $lastwallpaper ]; then | 188 | message "no options given" |
210 | option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1` | 189 | display_help |
211 | wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2` | 190 | exit 1 |
212 | else | 191 | fi |
213 | message "No previous wallpaper recorded for display ${DISPLAY}" | 192 | |
193 | # Parse command-line options | ||
194 | while :; do | ||
195 | case "$1" in | ||
196 | -d|-i) debug=true | ||
197 | break ;; | ||
198 | -a) option='$aspect' | ||
199 | wallpaper=$2 | ||
200 | break ;; | ||
201 | -f) option='$full' | ||
202 | wallpaper=$2 | ||
203 | break ;; | ||
204 | -c) option='$center' | ||
205 | wallpaper=$2 | ||
206 | break ;; | ||
207 | -t) option='$tile' | ||
208 | wallpaper=$2 | ||
209 | break ;; | ||
210 | -A) option='$aspect' | ||
211 | wallpaper=$2 | ||
212 | remember=false | ||
213 | break ;; | ||
214 | -F) option='$full' | ||
215 | wallpaper=$2 | ||
216 | remember=false | ||
217 | break ;; | ||
218 | -C) option='$center' | ||
219 | wallpaper=$2 | ||
220 | remember=false | ||
221 | break ;; | ||
222 | -T) option='$tile' | ||
223 | wallpaper=$2 | ||
224 | remember=false | ||
225 | break ;; | ||
226 | -l) | ||
227 | if [ -r "$lastwallpaper" ]; then | ||
228 | option=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f1` | ||
229 | wallpaper=`grep "|${DISPLAY}$" $lastwallpaper|cut -d'|' -f2` | ||
230 | if [ -z "$wallpaper" ]; then | ||
231 | message "No previous wallpaper recorded for display ${DISPLAY}" | ||
232 | exit 1 | ||
233 | fi | ||
234 | fi | ||
235 | remember=false | ||
236 | break | ||
237 | ;; | ||
238 | -p) display_tips ; exit 0 ;; | ||
239 | -h) display_help ; exit 0 ;; | ||
240 | --) | ||
241 | echo "$command doesn't recognize -- gnu-longopts." | ||
242 | echo 'Use $command -h for a help message.' | ||
243 | display_usage | ||
244 | exit 1 ;; | ||
245 | -*) | ||
246 | echo 1>&2 "$command: unrecognized option "\`"$1'" | ||
247 | display_usage | ||
214 | exit 1 | 248 | exit 1 |
215 | fi | 249 | ;; |
216 | remember=false | 250 | *) |
217 | ;; | 251 | if [ ! -r "$1" ]; then |
218 | h) display_help ; exit 0 ;; | 252 | echo "$1 isn't an existing wallpaper or a valid option." >&2 |
219 | p) display_tips ; exit 0 ;; | 253 | display_usage |
220 | -) echo "fbsetbg doesn't recognize -- gnu-longopts." | 254 | exit 1 |
221 | echo 'Use fbsetbg -h for a help message.' | 255 | elif [ -z "$1" ]; then |
222 | display_usage | 256 | message 'No wallpaper to set' >&2 |
223 | exit 1 | 257 | display_usage |
224 | ;; | 258 | exit 1 |
225 | *) if [ ! -r "$1" ]; then | 259 | else |
226 | echo "$1 isn't an existing wallpaper or a valid option." >&2 | 260 | break |
227 | display_usage | 261 | fi |
228 | exit 1 | 262 | ;; |
229 | fi | 263 | esac |
230 | if [ -z "$1" ]; then | 264 | done |
231 | message 'No wallpaper to set' >&2 | ||
232 | display_usage | ||
233 | exit 1 | ||
234 | fi | ||
235 | ;; | ||
236 | esac | ||
237 | 265 | ||
238 | 266 | ||
239 | case $WPSETTER in | 267 | case $WPSETTER in |