Racket - how to get the “previous executed command” in bash script? - racket

Is there any keyboard which echoes to the screen the "previously executed command"? Something like the up-arrow key at Linux bash...
It's not duplicate to How do I get "previous executed command" in a bash script?

Load XREPL and you'll get readline-style input editing, which should include the ability to load previous lines using the up-arrow key.
(require xrepl)

Related

Configure binding to perform predefined search in Tmux

I'm trying to find a way to jump to the previous prompt in iTerm using tmux. Can I set a binding to search a unique phrase within my prompt?
So to expand on Yuriy's answer. Inside your terminal you can run the following commands:
tmux copy-mode ; tmux send -X search-backward 'Example'
That should put your current tmux pane into copy-mode and then initiate a search for 'Example'. Now instead of typing that every time we want to search we'll create a shell script(lets say /tmp/search.sh) and then a tmux binding to that script
Contents of /tmp/search.sh
#!/usr/bin/env bash
tmux copy-mode ; tmux send -X search-backward 'These'
make sure you make it executable with chmod +x /tmp/search.sh. At this point you can test that it works by simply calling the script from your tmux session. To add it as a binding you can something akin to the following to your ~/.tmux.conf file:
bind p run-shell "bash /tmp/search.sh"
Make sure you source refresh the configuration in your tmux session and your new binding should initiate the search.
The canonical way of doing this is write a bash script to issue the commands back to your tmux.
But I'd like to suggest a mod that allows way more flexible scripting: http://ershov.github.io/tmux/ (I'm the author)
Using this mod, your problem can be solved this way:
bind p copy-mode ";" tcl {
set s [copy-mode-screenline -ex [copy-mode-get-cx]]
cursor-up
send-keys "?" "\x15$s"
}
This will read the current line from the beginning up to the cursor position and search for the previous occurrence of it.
The key 'p' can be changed to your preference.

Emacsclient called by applescript can't find emacs server socket

The shell command
emacsclient -n -e '(make-remember-frame)'
works.
But the applescript
do shell script "emacsclient -n -e '(make-remember-frame)'"
just returns
emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type \"M-x server-start\".
emacsclient: No socket or alternate editor. Please use:
--socket-name
--server-file (or environment variable EMACS_SERVER_FILE)
--alternate-editor (or environment variable ALTERNATE_EDITOR)
I rarely use this, but it has worked successfully in the past for various purposes. Perhaps you can modify it to suit your needs. The init.el or .emacs file must have (server-start) inside in order to make everything work. I have lots of stuff that loads when Emacs is activated for the first time, so I need a 5 second delay before emacsclient is called -- you can adjust the delay downward if your Emacs loads faster. If Emacs is already running, there is no need for a delay. You can comment out the verbal messages generated by say -- I used them this morning to test the conditions and make a minor adjustment to the script. The script contains a command-line example on line 4, which calls two Emacs functions. Of course, the path to your Emacs and emacsclient will need to be adjusted to wherever you have installed them on your computer.
# `(server-start)` must be inside `init.el` or `.emacs` file.
# This script can be used in the terimal: osascript path-to-script arguments
# Terminal Example:
# osascript /Users/HOME/.0.data/.0.emacs/.emacsclient.applescript "-e '(progn (dired \"/Applications\") (message \"Hello-World\!\"))'"
on run argv
set arg to item 1 of argv
set emacs to application "Emacs"
set appIsRunning to emacs is running
if appIsRunning then
say "Emacs is already running."
do shell script "/Users/HOME/.0.data/.0.emacs/Emacs_06_01_2014.app/Contents/MacOS/bin/emacsclient " & arg
else
tell application "/Users/HOME/.0.data/.0.emacs/Emacs_06_01_2014.app/Contents/MacOS/Emacs" to activate
say "Please wait five seconds for Emacs to load."
delay 5
do shell script "/Users/HOME/.0.data/.0.emacs/Emacs_06_01_2014.app/Contents/MacOS/bin/emacsclient " & arg
end if
end run

How do you run iex from Emacs?

I keep on getting this warning when I run iex using elixir-mode-iex from Emacs:
Warning: could not run smart terminal, falling back to dumb one
I think that this just means that I don't get tab completion, which I'm fine with. But I'd like a smart terminal if it's possible with elixir-mode in Emacs.
elixir-mode-iex uses the comint-mode major mode to interactive with iex. That also means that it's acting just like a dumb terminal (doesn't have the ability to process special escape sequences etc see here).
As a workaround you just could use term which sends any key press directly to the subprocess itself. You could write a function like the following:
(defun my-elixir-iex ()
(interactive)
(term "iex"))
I'm working on an iex Alchemist.el integration, which brings functionality like Inf-Ruby has. But until it's done try to just use iex via term
Cheers
Samuel
It looks like that warning occurs when IEX can't find tty support. You can enable tty mode in emacs by invoking it with -nw.

How to stop Emacs from rendering junk characters in shell?

In my emacs shell, I see this output:
^[[J~% echo $PS1
%2c%%
On my other machine, this stuff doesn't show up at all. Can anyone suggest a reason why and how to fix it?
It's related to your PS1 setting. Basically Emacs will not accept TOO fancy settings of PS1. I used the following code in ~/.bashrc to distinguish PS1 between xterm and other term simulators such as Emacs. You can give it a try.
case $TERM in
xterm)
export PS1='\[\e]0;\u#\h: \W\a\]\[\e[31;1m\]\w\n\[\e[0m\]'
;;
*)
export PS1='\[\e[31;1m\]\w\n\[\e[0m\]'
;;
esac

Automatically saving shell history in Emacs

Is there an easy way to automatically save every command I execute in shell-mode buffer? I'm running things like python and lua from Emacs' shell buffer and want to save those in addition to regular bash commands.
Default behavior saves history in in .history or .bash_history, but it does not save input to subprocesses. As an example, if I do the following
ls /export/hda3/tmp
python
a=2+3
import sys
sys.exit()
ls /export/hda3/tmp
the following gets saved
#1328903075
ls /export/hda3/tmp
#1328903081
python
#1328903087
ls /export/hda3/tmp
Commands are saved automatically, only you need to make sure to actually exit the shell. If you simply kill the shell buffer then no commands will be saved.
I added a check to emacs exit to warn me if I have an open shell buffer, so that I can exit it manually:
(defun my-check-if-no-shell-buffer-exists ()
(if (not (get-buffer "*shell*"))
t
(message "you have a shell buffer, make sure you exit it manually")
nil))
(add-hook 'kill-emacs-query-functions 'my-check-if-no-shell-buffer-exists)
It would even be better if the shell buffer would do it automatically when killing the buffer. I think it's a bug in emacs that it fails to do that.
Edit: I noticed I have a setting which prevented running process warnings when emacs exits and that's why I needed the above function. If you get a warning about a running shell already when exiting, then you don't need it, you only need to exit the shell manually to save history.