From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10187 invoked by alias); 13 Apr 2015 15:39:35 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34882 Received: (qmail 11724 invoked from network); 13 Apr 2015 15:39:34 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) 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 autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=KMUMOz1JYEWRAVgxTZAiP4hXfArkiEhotILnSv8SDxo=; b=ZjNn3kQ0OvGqNi57M9Colcyhr/i/ocI1W2F9ATS2V9rGmyp0ENr3lYVhLtJfgwdsNn 3Pl4lnw8yKxdsn+NDFcmayGSyo/J5slOiNtKlXcPTWA54+bC6TF+gpJgCrBibNmxjVQP b76zOyQV92mEFUTtpab3UNCOlK8K3eseIC4R8/mlMB7fwNsgktSss0HJMbpht+jMmGZ/ C+G8BFTDsUWF4pFOePxVzIg8k7ciDoK4/u2K7Rge+ICF3goUX0aXPcZzQoGYlmF4jqiQ 11bui9CiMvpXVzZc4IzOv0IV1bMS1W16ukA0MS8nYEZ/zDHk3+PQyMO6zF8XI5juDcVr t+RA== X-Gm-Message-State: ALoCoQnM7dxxqp9RnX4KyUYLgNqEOXKi4GXMKLUVoCipQaQIkxRFoasIapRlL3f5p503PvtdPnGq X-Received: by 10.202.201.3 with SMTP id z3mr7877778oif.130.1428939571634; Mon, 13 Apr 2015 08:39:31 -0700 (PDT) From: Bart Schaefer Message-Id: <150413083927.ZM23794@torch.brasslantern.com> Date: Mon, 13 Apr 2015 08:39:27 -0700 In-Reply-To: <1428936706.1922179.253003181.2E00EEA4@webmail.messagingengine.com> Comments: In reply to Ronald Fischer "Feature request: Provide name of file being sourced, to the script." (Apr 13, 4:51pm) References: <1428936706.1922179.253003181.2E00EEA4@webmail.messagingengine.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Feature request: Provide name of file being sourced, to the script. MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Apr 13, 4:51pm, Ronald Fischer wrote: } Subject: Feature request: Provide name of file being sourced, to the scrip } } While a zsh script can find out about itself (i.e. where it is located), } by looking at the variable $0, a piece of code executed by the 'source' } statement does not have this information. $0 always points to the script } which "belongs" to the zsh process. } } Example: We have a script /home/usr/foo/x.zsh containing the lines } } #!/bin/zsh } source /home/usr/bar/y.inc } } we can have in /home/usr/foo/y.inc the line } } echo $0 } } which would output /home/usr/foo/x.zsh , but we have no way of } "knowing", that the echo command being executed is in } /home/usr/bar/y.inc The value of $0 should give you what you want provided that you have left the FUNCTION_ARGZERO and POSIX_ARGZERO options in their default state (on and off, respectively). If for some reason you can't leave these as they were (e.g. the user in your example has changed them himself), the zsh/parameter module provides several variables that have related information; I quote the doc: funcfiletrace This array contains the absolute line numbers and corresponding file names for the point where the current function, sourced file, or (if EVAL_LINENO is set) eval command was called. The array is of the same length as funcsourcetrace and functrace, but differs from funcsourcetrace in that the line and file are the point of call, not the point of definition, and differs from functrace in that all values are absolute line numbers in files, rather than relative to the start of a function, if any. funcsourcetrace This array contains the file names and line numbers of the points where the functions, sourced files, and (if EVAL_LINENO is set) eval commands currently being executed were defined. The line number is the line where the `function NAME' or `NAME ()' started. In the case of an autoloaded function the line number is reported as zero. The format of each element is FILENAME:LINENO. funcstack This array contains the names of the functions, sourced files, and (if EVAL_LINENO is set) eval commands. currently being executed. The first element is the name of the function using the parameter. functrace This array contains the names and line numbers of the callers corresponding to the functions currently being executed. The format of each element is NAME:LINENO. Callers are also shown for sourced files; the caller is the point where the source or `.' command was executed.