I have the excellent fish shell set as the default shell on my main laptop. For portability reasons (and editability reasons, as editing fish shell source blocks is buggy and slow) I'd still like to sometimes use sh or bash in my org-mode source blocks. It seems that org always resolves to fish, no matter what I try:
#+BEGIN_SRC sh
echo $SHELL
#+END_SRC
#+RESULTS:
: /usr/bin/fish
#+BEGIN_SRC bash
echo $SHELL
#+END_SRC
#+RESULTS:
: /usr/bin/fish
#+BEGIN_SRC fish
echo $SHELL
#+END_SRC
#+RESULTS:
: /usr/bin/fish
#+BEGIN_SRC shell
echo $SHELL
#+END_SRC
#+RESULTS:
: /usr/bin/fish
org-babel-shell-names is set to ("sh" "bash" "zsh" "fish" "csh" "ash" "dash" "ksh" "mksh" "posh"). How do I debug this? Or is there any way to set the shell to bash globally for org-babel? I'm using emacs 26.3 with the spacemacs configuration at commit 5fcd84d84 and latest org-mode.
I think you'll find that the SHELL environment variable isn't what you think it is.
Try echoing $0 instead -- or running any built-in shell command which will give shell-specific output (bash has a help command, for example).
Related
The Issue
after running org-export-to-html on the following code:
#+BEGIN_SRC shell :exports both :results output
echo -e "\e[0;31mOUTPUT\e[0m"
#+END_SRC
OUTPUT is exported in black color
Desired output
OUTPUT being exported in red color
Proposed solution
The following code exports the output to html using (aha)
#+BEGIN_SRC shell :exports both :results output html
echo -e "\e[0;31mOUTPUT\e[0m" | aha
#+END_SRC
The issue with the proposed solution
The initial command is just echo -e "\e[0;31mOUTPUT\e[0m" not echo -e "\e[0;31mOUTPUT\e[0m" | aha
I want org babel to take account of the dir header property when i use org-babel-tangle.
E.g.
#+begin_src bash :dir ~/blubb
echo $PWD
#+end_src
or even
#+begin_src bash :dir /ssh:someone#somewhere|sudo:anotherone#somewhere:somedir
echo $(hostname) $USER $PWD
#+end_src
When I do org-babel-tangle it creates a bash file with just the echo statement. I would like it to do a dir change, or wrap it in an ssh statement for the second example. (Same issue when I do org-export: the dir information is lost).
Has anybody found a solution for that?
I am using Emacs Org-Mode and I am trying to fetch a picture from the web using wget and display it as an inline image in a code block result. So, I write the following block of code:
#+BEGIN_SRC bash :results file :file ~/image.jpg
url='https://gist.githubusercontent.com/brettlangdon/85942af486eb79118467/raw/2a7409cd3c26a90b2e82bdc40dc7db18b92b3517/06b3FMA.jpg'
wget "$url" -O ~/image.jpg
#+END_SRC
#+RESULTS:
[[file:~/image.jpg]]
However, the image is not display and get corrupted. In console I get:
Premature end of JPEG file
#+BEGIN_SRC bash
url='https://gist.githubusercontent.com/brettlangdon/85942af486eb79118467/raw/2a7409cd3c26a90b2e82bdc40dc7db18b92b3517/06b3FMA.jpg'
wget "$url" -O ~/image.jpg
#+END_SRC
Executes script, downloading the specified URL to ~/image.jpg
#+BEGIN_SRC bash :results file :file ~/image.jpg
url='https://gist.githubusercontent.com/brettlangdon/85942af486eb79118467/raw/2a7409cd3c26a90b2e82bdc40dc7db18b92b3517/06b3FMA.jpg'
wget "$url" -O ~/image.jpg
#+END_SRC
Executes script, downloading the specified URL to ~/image.jpg, and then writes the standard output from the shell command to ~/image.jpg (which I expect leaves you with an empty file, as wget writes information to stderr).
So you can either use the first approach and include your image link independently of the code block; or if you want the downloaded image data to be captured in the :results you need to tell wget to write to stdout.
#+BEGIN_SRC bash :results file :file ~/image.jpg
url='https://gist.githubusercontent.com/brettlangdon/85942af486eb79118467/raw/2a7409cd3c26a90b2e82bdc40dc7db18b92b3517/06b3FMA.jpg'
wget "$url" -O -
#+END_SRC
I want to use capistrano for a custom sets of tasks on a remote server not directly related to deployment, it would be useful for me if I can start vim using capistrano, I've tried with this:
set :pty, true
execute "vim #{shared_path}/my_file.txt"
But I receive this (for obvious reasons)
01 stdin: is not a tty
01 Vim: Warning: Output is not to a terminal
01 Vim: Warning: Input is not from a terminal
It's there anyway to make it work?
As far as I know you can't start vim without a terminal. You could start a terminal with vim in it, here are a few ways to do this:
Start a terminal like st, xterm or similar. Examples:
x-terminal-emulator -e vim
st -e vim
xterm -e vim
This solution is not the best, as terminal-emulators can have different switches for executing commands on call. -e is working for st and xterm.
A better solution is to start a shell like zsh, bash or similar, because almost every shell works with the same switch, which is -c to start a program directly in it. Example:
zsh -c vim
bash -c vim
I start emacsclient using:
emacsclient -a "" -c
This opens a frame connected to the emacs daemon, and starts the daemon if it's not already started. Great, this works fine.
However, I like opening my emacs frames maximized. With emacs, I would use -mm. However, that doesn't work with emacsclient. How do I make this work?
(It seems I could make something work by adding a shell file like so: emacsclient -a "myshell.sh" -c, where the shell file is: emacs -mm, but I haven't been able to make that work - the server doesn't stay up.)
You can add the following line to .emacs, so that Emacs can be started with the window maximized. See http://www.gnu.org/software/emacs/manual/html_node/elisp/Size-Parameters.html#Size-Parameters for details.
(add-to-list 'default-frame-alist '(fullscreen . maximized))
Emacs client accepts -F option, where you can specify frame parameters, so the above example would be:
emacsclient -c -a "" -F "((fullscreen . maximized))"
Let's say you want to run emacsclient fullscreen, which was my case.
man emacsclient shows emacsclient has -F option:
-F, --frame-parameters=ALIST
set the parameters of a newly-created frame.
In Emacs Manual, which is an info file, section (emacs) emacsclient Options has more information. Specifically for this question (elisp) Size Parameters mentions fullscreen parameter. To run emacsclient fullscreen, you need to supply an alist, with one element being (fullscreen . fullboth) like that:
emacsclient -c -F "((fullscreen . fullboth))"
emacsclient provides the --eval (-e for short) command line option for executing arbitrary Emacs Lisp code, so you can visit a file and call suspend-frame from the command line like so:
emacsclient -a "" -c --eval "(progn (find-file \"/tmp/my-file\") (suspend-frame))"
You could put this in a script, e.g:
#!/bin/bash
emacsclient -a "" -c --eval "(progn (find-file \"$1\") (suspend-frame))"