From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id kKdAMjivBGDISgAA0tVLHw (envelope-from ) for ; Sun, 17 Jan 2021 21:42:16 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id QKwNLjivBGDkRgAAbx9fmQ (envelope-from ) for ; Sun, 17 Jan 2021 21:42:16 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2FD169402D4 for ; Sun, 17 Jan 2021 21:42:16 +0000 (UTC) Received: from localhost ([::1]:53878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1FoL-0007j7-Pn for larch@yhetil.org; Sun, 17 Jan 2021 16:42:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1FnR-0007iL-Nt for emacs-orgmode@gnu.org; Sun, 17 Jan 2021 16:41:17 -0500 Received: from mta.vmaly.com ([94.242.65.182]:48738) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1FnO-0000S6-KC for emacs-orgmode@gnu.org; Sun, 17 Jan 2021 16:41:17 -0500 To: emacs-orgmode@gnu.org From: HJ Subject: self-referencing babel shell code blocks Message-ID: Date: Sun, 17 Jan 2021 22:41:00 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: cs Received-SPF: none client-ip=94.242.65.182; envelope-from=hj-orgmode-1@hj.proberto.com; helo=mta.vmaly.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.36 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 2FD169402D4 X-Spam-Score: -2.36 X-Migadu-Scanner: scn0.migadu.com X-TUID: rHbeqDrSJwmP  hi,   I'm  trying to figure out how to write a block , header, PROPERTY or whatever is necessary so the output of a command in babel source block identifies it own position - the line (or block or something) in buffer (or at least the file) in which it is written. ( Plus the checked out git revision / branch. )  I've been experimenting with the following, so far without much luck ...  Which of these pieces of information (see the "echo" line below) is it possible to get? Which is easy? (variables VAR[0345] are most critical) How would one write a snippet which provides (some of) this information?  Is it much harder with command 1 being SSH to a remote machine? Would ":dir user@remotemachine:/some/dir" work better? Or at all?  Perhaps I would know how to find out VAR6 and VAR7 by running first some `git cmd1` and `git cmd2` locally in a " command 0 " - but is there a way to get that info from magit somehow?  But what I am most desperate for is how to cause orgmode block to set VAR0, VAR3, VAR4 and VAR5, and - also fairly important - how to use the combination of VAR[0345] do open / recall the file onto the screen  Thanks a million for helping me out here ...    HJ This is the sample file : * heading L1_12 Hello and welcome, this is a file with self-referencing shell babel source code blocks ... ** heading L2_37 ... #+NAME: block220 #+BEGIN_SRC bash :session sess9 : command 0 ; cd _how-do-I-find-the-dir-of-currently-edited-file_ ; VAR6=`git cmd1` ; VAR7=`git cmd2` : command 1 ; ssh -o "SetEnv VAR1=machine VAR2=user VAR3=..." targetUser@targetMachine #+END_SRC ... #+NAME: block225 #+BEGIN_SRC bash :session sess9 : command 2 ; : do some computation on targetMachine : command 3 ; echo This code has been launched from emacs process VAR0:_EMACS_SESSION_ID_ \ on computer $VAR1:_SRC_HOSTNAME_ \ run by user $VAR2:_USER_ \ from file $VAR3:_FILENAME_ \ code block named $VAR4:block225 \ in this file positioned under headings: $VAR5:heading L1_12/heading L2_37/ \ which is checked out from $VAR6:_GIT_COMMIT_ID_ \ on branch $VAR7:_GIT_BRANCH_ : command 3 continues ; echo To display the buffer which launched this code on the screen of the running emacs session, run the following command : emacs _What_the_heck_do_I_put_here?_ '&' #+END_SRC