I was wondering if there was an easy way to execute some shell commands contained in a src block as root. Alternatively, is there a quick way to export _just_ that one source block to a temp file so that I could run it as root manually?
Leo Alekseyev <dnquark@gmail.com> wrote:
> I was wondering if there was an easy way to execute some shell
> commands contained in a src block as root. Alternatively, is there a
> quick way to export _just_ that one source block to a temp file so
> that I could run it as root manually?
>
You could set up sudo so that it does not require a password and prefix each
command that needs to be run as root with "sudo":
--8<---------------cut here---------------start------------->8---
* foo
#+BEGIN_SRC sh
sudo id
#+END_SRC
#+RESULTS:
: uid=0(root) gid=0(root) groups=0(root)
--8<---------------cut here---------------end--------------->8---
Not sure how sudo would interact with babel if you had to type in a password.
Nick
Hi, I've recently switched from Org 7.4 to the master branch on the git repository, and I've encountered this weird situation. #+name: foo #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp If I evaluate this block I get: #+name: foo =42 =emacs-lisp Though it works as expected if I remove the name: #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp => #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp #+RESULTS: : 42 I've tried to figure out what was the problem and it lies in the regexp org-babel-src-name-w-name-regexp. So far I've found those workarounds: No spaces after the ':' #+name:foo #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp => #+name:foo #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp #+RESULTS: foo : 42 Add parentheses after the name. #+name: foo() #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp => #+name: foo() #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp #+RESULTS: foo : 42 No spaces before the src block #+name: foo #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp => #+name: foo #+begin_src emacs-lisp (defun foo () 42) (foo) #+end_src emacs-lisp #+RESULTS: foo : 42
Daimrod <daimrod@gmail.com> wrote:
>
> Hi, I've recently switched from Org 7.4 to the master branch on the git
> repository, and I've encountered this weird situation.
>
> #+name: foo
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
>
> If I evaluate this block I get:
>
> #+name: foo
> =42
> =emacs-lisp
>
> Though it works as expected if I remove the name:
>
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
> =>
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
>
> #+RESULTS:
> : 42
>
> I've tried to figure out what was the problem and it lies in the regexp
> org-babel-src-name-w-name-regexp.
>
> So far I've found those workarounds:
>
> No spaces after the ':'
>
> #+name:foo
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
> =>
> #+name:foo
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
> #+RESULTS: foo
> : 42
>
> Add parentheses after the name.
>
> #+name: foo()
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
> =>
> #+name: foo()
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
>
> #+RESULTS: foo
> : 42
>
> No spaces before the src block
>
> #+name: foo
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
> =>
> #+name: foo
> #+begin_src emacs-lisp
> (defun foo ()
> 42)
> (foo)
> #+end_src emacs-lisp
>
> #+RESULTS: foo
> : 42
Bug confirmed (but I didn't try all your workarounds, just the no spaces
before the #+begin_src and no space after the colon in the #+name).
I take it it was working on 7.4?
Nick
PS. One side note: the syntax of code blocks is
#+NAME: <name>
#+BEGIN_SRC <language> <switches> <header arguments>
<body>
#+END_SRC
so no emacs-lisp on the #+end_src line.
Nick Dokos <nicholas.dokos@hp.com> writes: > Daimrod <daimrod@gmail.com> wrote: > >> >> Hi, I've recently switched from Org 7.4 to the master branch on the git >> repository, and I've encountered this weird situation. >> >> #+name: foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> >> If I evaluate this block I get: >> >> #+name: foo >> =42 >> =emacs-lisp >> >> Though it works as expected if I remove the name: >> >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> => >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> >> #+RESULTS: >> : 42 >> >> I've tried to figure out what was the problem and it lies in the regexp >> org-babel-src-name-w-name-regexp. >> >> So far I've found those workarounds: >> >> No spaces after the ':' >> >> #+name:foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> => >> #+name:foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> #+RESULTS: foo >> : 42 >> >> Add parentheses after the name. >> >> #+name: foo() >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> => >> #+name: foo() >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> >> #+RESULTS: foo >> : 42 >> >> No spaces before the src block >> >> #+name: foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> => >> #+name: foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> >> #+RESULTS: foo >> : 42 > > Bug confirmed (but I didn't try all your workarounds, just the no spaces > before the #+begin_src and no space after the colon in the #+name). > > I take it it was working on 7.4? > Yes. > Nick > > PS. One side note: the syntax of code blocks is > > #+NAME: <name> > #+BEGIN_SRC <language> <switches> <header arguments> > <body> > #+END_SRC > > so no emacs-lisp on the #+end_src line. Indeed, I don't know why I've pasted it like this, normally I don't do it.
Leo Alekseyev <dnquark@gmail.com> writes: > I was wondering if there was an easy way to execute some shell > commands contained in a src block as root. Alternatively, is there a > quick way to export _just_ that one source block to a temp file so > that I could run it as root manually? > Just call org-babel-tangle with a prefix argument and it only tangles the current block > -- Eric Schulte http://cs.unm.edu/~eschulte/
Nick Dokos <nicholas.dokos@hp.com> writes: > Daimrod <daimrod@gmail.com> wrote: > >> >> Hi, I've recently switched from Org 7.4 to the master branch on the git >> repository, and I've encountered this weird situation. >> >> #+name: foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> >> If I evaluate this block I get: >> >> #+name: foo >> =42 >> =emacs-lisp >> >> Though it works as expected if I remove the name: >> >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> => >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> >> #+RESULTS: >> : 42 >> >> I've tried to figure out what was the problem and it lies in the regexp >> org-babel-src-name-w-name-regexp. >> >> So far I've found those workarounds: >> >> No spaces after the ':' >> >> #+name:foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> => >> #+name:foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> #+RESULTS: foo >> : 42 >> >> Add parentheses after the name. >> >> #+name: foo() >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> => >> #+name: foo() >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> >> #+RESULTS: foo >> : 42 >> >> No spaces before the src block >> >> #+name: foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> => >> #+name: foo >> #+begin_src emacs-lisp >> (defun foo () >> 42) >> (foo) >> #+end_src emacs-lisp >> >> #+RESULTS: foo >> : 42 > > Bug confirmed (but I didn't try all your workarounds, just the no spaces > before the #+begin_src and no space after the colon in the #+name). > This was caused by a commit of mine yesterday, I've just pushed up a fix and a protecting test case. Thanks for catching, -- Eric Schulte http://cs.unm.edu/~eschulte/
Eric Schulte <eric.schulte@gmx.com> writes:
> Nick Dokos <nicholas.dokos@hp.com> writes:
>
>> Daimrod <daimrod@gmail.com> wrote:
>>
>>>
>>> Hi, I've recently switched from Org 7.4 to the master branch on the git
>>> repository, and I've encountered this weird situation.
>>>
>>> #+name: foo
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>>
>>> If I evaluate this block I get:
>>>
>>> #+name: foo
>>> =42
>>> =emacs-lisp
>>>
>>> Though it works as expected if I remove the name:
>>>
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>> =>
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>>
>>> #+RESULTS:
>>> : 42
>>>
>>> I've tried to figure out what was the problem and it lies in the regexp
>>> org-babel-src-name-w-name-regexp.
>>>
>>> So far I've found those workarounds:
>>>
>>> No spaces after the ':'
>>>
>>> #+name:foo
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>> =>
>>> #+name:foo
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>> #+RESULTS: foo
>>> : 42
>>>
>>> Add parentheses after the name.
>>>
>>> #+name: foo()
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>> =>
>>> #+name: foo()
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>>
>>> #+RESULTS: foo
>>> : 42
>>>
>>> No spaces before the src block
>>>
>>> #+name: foo
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>> =>
>>> #+name: foo
>>> #+begin_src emacs-lisp
>>> (defun foo ()
>>> 42)
>>> (foo)
>>> #+end_src emacs-lisp
>>>
>>> #+RESULTS: foo
>>> : 42
>>
>> Bug confirmed (but I didn't try all your workarounds, just the no spaces
>> before the #+begin_src and no space after the colon in the #+name).
>>
>
> This was caused by a commit of mine yesterday, I've just pushed up a fix
> and a protecting test case.
>
> Thanks for catching,
Works nicely.
By the way, org-babel is awesome, thanks for your efforts!
Eric Schulte <eric.schulte@gmx.com> writes:
> Leo Alekseyev <dnquark@gmail.com> writes:
>
>> I was wondering if there was an easy way to execute some shell
>> commands contained in a src block as root. Alternatively, is there a
>> quick way to export _just_ that one source block to a temp file so
>> that I could run it as root manually?
>>
>
> Just call org-babel-tangle with a prefix argument and it only tangles
> the current block
>
>>
Hi,
I did not know this either. Thanks for the hint!
Shouldn't this be mentioned in the manual (14.4)?
I have two questions/issues about this:
(1) Can I get noweb-references to be expanded by this? Or how would I
tangle one block with noweb references expanded?
(2) I am asked for a filename. But the header argument :tangle somefile
is overruling my input, which is un-expected.
Regards,
Andreas
[-- Attachment #1: Type: text/plain, Size: 231 bytes --] Under Gnome, I'm using this at the beginning of a sh source block: echo -e "#! /bin/bash\n/usr/bin/gksudo -p -m Password" > /tmp/gksudo-stdout chmod +x /tmp/gksudo-stdout SUDO_ASKPASS="/tmp/gksudo-stdout" sudo -A -s Sylvain. [-- Attachment #2: Type: text/html, Size: 286 bytes --]
Andreas Leha <andreas.leha@med.uni-goettingen.de> writes: > Eric Schulte <eric.schulte@gmx.com> writes: > >> Leo Alekseyev <dnquark@gmail.com> writes: >> >>> I was wondering if there was an easy way to execute some shell >>> commands contained in a src block as root. Alternatively, is there a >>> quick way to export _just_ that one source block to a temp file so >>> that I could run it as root manually? >>> >> >> Just call org-babel-tangle with a prefix argument and it only tangles >> the current block >> >>> > > Hi, > > I did not know this either. Thanks for the hint! > > Shouldn't this be mentioned in the manual (14.4)? > > I have two questions/issues about this: > (1) Can I get noweb-references to be expanded by this? Or how would I > tangle one block with noweb references expanded? There was a conflict between the narrowing to a single code block caused by the prefix argument, and the code which searches for replacements to noweb elements. I've just pushed up a fix so noweb elements should now expand as normal. > > (2) I am asked for a filename. But the header argument :tangle somefile > is overruling my input, which is un-expected. > This is now fixed as well. Thanks, > > Regards, > Andreas > > -- Eric Schulte http://cs.unm.edu/~eschulte/
Eric Schulte <eric.schulte@gmx.com> writes:
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> Eric Schulte <eric.schulte@gmx.com> writes:
>>
>>> Leo Alekseyev <dnquark@gmail.com> writes:
>>>
>>>> I was wondering if there was an easy way to execute some shell
>>>> commands contained in a src block as root. Alternatively, is there a
>>>> quick way to export _just_ that one source block to a temp file so
>>>> that I could run it as root manually?
>>>>
>>>
>>> Just call org-babel-tangle with a prefix argument and it only tangles
>>> the current block
>>>
>>>>
>>
>> Hi,
>>
>> I did not know this either. Thanks for the hint!
>>
>> Shouldn't this be mentioned in the manual (14.4)?
>>
>> I have two questions/issues about this:
>> (1) Can I get noweb-references to be expanded by this? Or how would I
>> tangle one block with noweb references expanded?
>
> There was a conflict between the narrowing to a single code block caused
> by the prefix argument, and the code which searches for replacements to
> noweb elements. I've just pushed up a fix so noweb elements should now
> expand as normal.
>
>>
>> (2) I am asked for a filename. But the header argument :tangle somefile
>> is overruling my input, which is un-expected.
>>
>
> This is now fixed as well.
>
Hi Eric,
thanks for both fixes! Tangling of single source blocks is a really
nice feature now!
Regards,
Andreas
On Mon, Mar 5, 2012 at 10:24 AM, Eric Schulte <eric.schulte@gmx.com> wrote:
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> Eric Schulte <eric.schulte@gmx.com> writes:
>>
>>> Leo Alekseyev <dnquark@gmail.com> writes:
>>>
>>>> I was wondering if there was an easy way to execute some shell
>>>> commands contained in a src block as root. Alternatively, is there a
>>>> quick way to export _just_ that one source block to a temp file so
>>>> that I could run it as root manually?
>>>>
>>>
>>> Just call org-babel-tangle with a prefix argument and it only tangles
>>> the current block
Hi all,
I just pulled a fresh version of org, and this tangling an individual
block only works if there's a :tangle header argument present. I
don't think this is the intended behavior! The problem, it seems, is
that when :tangle is not present, the (or ...) in the code below
always evaluates to true.
#+begin_src emacs-lisp
(unless (or (cdr (assoc :tangle (nth 2 (org-babel-get-src-block-info))))
target-file)
(setq target-file
(read-from-minibuffer "Tangle to: " (buffer-file-name)))))
#+end_src
[-- Attachment #1: Type: text/plain, Size: 1536 bytes --] Leo Alekseyev <dnquark@gmail.com> writes: > On Mon, Mar 5, 2012 at 10:24 AM, Eric Schulte <eric.schulte@gmx.com> wrote: >> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes: >> >>> Eric Schulte <eric.schulte@gmx.com> writes: >>> >>>> Leo Alekseyev <dnquark@gmail.com> writes: >>>> >>>>> I was wondering if there was an easy way to execute some shell >>>>> commands contained in a src block as root. Alternatively, is there a >>>>> quick way to export _just_ that one source block to a temp file so >>>>> that I could run it as root manually? >>>>> >>>> >>>> Just call org-babel-tangle with a prefix argument and it only tangles >>>> the current block > > Hi all, > > I just pulled a fresh version of org, and this tangling an individual > block only works if there's a :tangle header argument present. I > don't think this is the intended behavior! The problem, it seems, is > that when :tangle is not present, the (or ...) in the code below > always evaluates to true. > > #+begin_src emacs-lisp > (unless (or (cdr (assoc :tangle (nth 2 (org-babel-get-src-block-info)))) > target-file) > (setq target-file > (read-from-minibuffer "Tangle to: " (buffer-file-name))))) > #+end_src Thanks for raising this issue. I can not apply patches to the git repository until the recent git issues are sorted, so I am attaching the patch to this email so that you can apply it locally if you like. I will push this up once our git repository is back in working order. Best, [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0002-Bring-back-prompt-for-single-block-tangling.patch --] [-- Type: text/x-patch, Size: 1033 bytes --] From bfacabb33acb4d2dbcfd87b10e3488e43cf5d84a Mon Sep 17 00:00:00 2001 From: Eric Schulte <eric.schulte@gmx.com> Date: Mon, 19 Mar 2012 10:44:43 -0400 Subject: [PATCH 2/2] Bring back prompt for single-block tangling. * lisp/ob-tangle.el (org-babel-tangle): Bring back prompt for single-block tangling. --- lisp/ob-tangle.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 5e498ab..b57d89d 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -186,7 +186,10 @@ exported source code blocks by language." (unless (org-babel-where-is-src-block-head) (error "Point is not currently inside of a code block")) (save-match-data - (unless (or (cdr (assoc :tangle (nth 2 (org-babel-get-src-block-info)))) + (unless (or (not (string= + (cdr (assoc :tangle + (nth 2 (org-babel-get-src-block-info)))) + "no")) target-file) (setq target-file (read-from-minibuffer "Tangle to: " (buffer-file-name))))) -- 1.7.9.4 [-- Attachment #3: Type: text/plain, Size: 48 bytes --] -- Eric Schulte http://cs.unm.edu/~eschulte/