zsh-users
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: zsh-users@zsh.org
Subject: sound policy on global variables for "distributed" DWIM function
Date: Wed, 22 Jul 2015 02:37:17 +0200	[thread overview]
Message-ID: <87fv4hm3ia.fsf@nl106-137-147.student.uu.se> (raw)

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


             reply	other threads:[~2015-07-22  0:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-22  0:37 Emanuel Berg [this message]
2015-07-22 13:55 ` Joshua Krusell
2015-07-22 23:25   ` Emanuel Berg
2015-07-23  1:41     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fv4hm3ia.fsf@nl106-137-147.student.uu.se \
    --to=embe8573@student.uu.se \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).