From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7872 invoked by alias); 22 Jul 2015 00:40:12 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20332 Received: (qmail 19942 invoked from network); 22 Jul 2015 00:40:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.0 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-users@zsh.org To: zsh-users@zsh.org From: Emanuel Berg Subject: sound policy on global variables for "distributed" DWIM function Date: Wed, 22 Jul 2015 02:37:17 +0200 Message-ID: <87fv4hm3ia.fsf@nl106-137-147.student.uu.se> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: nl106-137-97.student.uu.se Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:LCuFirJh3ZuGEtCPWQs9DhaGNOo= I have put together a DWIM function to take screenshots (or dumps), and it can be invoked in X just as well as in the console with the wrapper detecting which one and acting accordingly. My question is, you see that the data item ".png" appears in *both* specialized functions (dump-vt and dump-x), but it is likely that if I ever were to abandon PNG for some other format, I'd want that for dumps both of the VTs and X. So, do I put that data a global variable (and what is the best way to do that?), or do I have a function return that value and thus have two invocations but only one data item, or do I do something else? What is the rule of thumb? Other comments on the code are also appreciated :) #! /bin/zsh # This file: http://user.it.uu.se/~embe8573/conf/.zsh/dump dump-vt () { local file=$1.png local vt=$2 case $# in (1) fbgrab $file ;; (2) sudo fbgrab -c $vt $file sudo chown $USER $file ;; esac } dump-emacs () { dump-vt $1 1 } # because Emacs runs in tty1 dump-x () { local file=$1.png local window_name=$2 local window_id=`wmctrl -l | grep -i $window_name | cut -d " " -f1` case $# in (1) sleep 10; xwd -root ;; (2) wmctrl -a $window_name; xwd -id $window_id ;; esac | convert - $file } dump () { if [[ $DISPLAY ]]; then dump-x $@ else dump-vt $@ fi } -- underground experts united http://user.it.uu.se/~embe8573