create a keyboard shortcut to an R function on mac? - macos

I would like to create a keyboard shortcut to run an R function in an existing R session. How can I do this on a Mac?
My first idea was to use
% R --slave < foo.R
and create a keyboard-shortcut to a shell script with this command.
But this starts a new R session. Is there a way to send a command to an existing session from shell?

I can think of two similar ways to do this; neither is necessarily elegant, but both get the job done.
Run a tmux session which consists solely of an R session, and write a script that uses tmux send-keys to send your command.
Similarly, you could set up a dedicated iTerm2 session to receive the keys. If you were in iTerm2 already, you could set up a keyboard shortcut to send your command. Outside iTerm2, I think you're looking at some applescript.

Related

Bash script which works in the background, waiting for the key

I need script which works in the background, waiting for a key to be pressed. I have a script which works when terminal is on. When I try to use & - it's not working correctly. The script works in background but keypress doesn't do anything. When I try use nohup then I have error of read - bad descriptor.
Can someone help me?
When the terminal is on (and is selected, in case of a terminal emulator running on x server), the input (key strokes, etc.) is directed to the terminal; hence, your program works.
Now, consider an example: let's say that you created a script that runs on the background, and it is activated by pressing the letter "a". If pressing "a" triggered your script (with terminal closed), then the user would never be able to (for example) type the letter "a" in a word document or a web search without triggering the script!
Therefore, what you are looking for is a key bind, or a keyboard shortcut, which would bind a key (combination) such as ctl+j+k to launch the script you want.
In Linux, that can be done somewhat easily, see this for Ubuntu or this for Lubuntu.
Important: if your script needs to be root to work, then you generally will have to evoke it via gksu or gksudo, otherwise it will not run

How to abort process in terminal without using CTRL key?

I have CTRL key broken in my MBP. Is there any way to terminate process in terminal without it? I mean, can I change CTRL + C shortcut, or use mouse, or whatever? I know, I can use Karabiner to reassign CTRL globally, but this solution doesn't fit to me.
Thanks.
On OS X, you can use command-period. Additionally, you can use stty intr <something> to set a different interrupt character for the terminal.
You can use this:
<Alt><SysRq><k>
Kill all processes (including X) which are running on the currently active virtual console. This key combination is know as "secure access key" (SAK).
Yes, you can open another terminal and with the command ps aux you can find the process ID (column named PID) related to application that you want to kill and kill it with the command kill PID.

Emacs: Opening a file within the same Emacs session from a tmux session in ansi-term

I often come across the situation where I want to open a file that I am viewing from my tmux session in ansi-term into my Emacs session. I tried to use find-file-at-point (see Max Bozzi's answer below), but in tmux it only directs me to the working directory of my ansi-term session, and it does not detect the file in my tmux session. With ansi-term alone, find-file-at-point works fine, but I prefer to use a session manager, or at least a solid terminal multiplexer.
Any suggestions?
For example, here is my tmux session in ansi-term:
lucas#~/Downloads$ ls
A CHRISTMAS CAROL (ILLUSTRATED with Special Kindle Format).azw3
bleachbit_1.0_all_ubuntu1310.deb
Island of the Blue Dolphins.azw3
javaPong.jnlp
test.txt
How do I open test.txt within my Emacs session?
One option is to place point on the name of the file and then run find-file-at-point. I find that to be useful enough to bind to M-'.
Another is to just use the standard C-c C-f and tab-complete the name, or maybe if you really wanted to, to have recursive Emacs and have Emacs running inside Emacs' own terminal buffer. Presumably you wouldn't, though, so I would stick to find-file-at-point.

GNU screen quit and killall processes

I've created a .screenrc config file to setup some split screen stuff for what im working on, and i've bound ctrl+d to quit it, but it only quits the screen, and leaves the actual processes running.
Heres the bind keys part of my .screenrc file atm, is there a way i can tweek it so it kills processes too?
bindkey ^D quit
It needs to quit and kill multiple split screens btw so that may add to the complexity of it.
Ultimately i'd like to bind it to Ctrl+C or Ctrl+D, either way a quick way to exit this script as its a custom script loading this custom .screenrc file.
Thanks.
Unsure if you are aware of the screen ctrl a functions
ctrl a c to create a new screen
ctrl a a or [0-9] to run through connections
ctrl a d to detach
where you can then use
screen -r -d to re-attach
and I think you need
ctrl a \
this will attempt to quit the screen session and prompt if you wish to cancel it all

leave vim split window in insert mode

I want to view the output of a bash command in a vim split window :split. To this end I installed "Conque Shell" which displays bash in a split window upon :ConqueTermSplit bash. I can then run my shell command and watch the output in insert mode. However, to return to the other window I need to type <CTRL-W> <Up> in command mode, so I need to leave insert mode. Hence the display of the command output freezes and continues only if I return to this window and enter insert mode. So how can I leave "Conque Shell" without leaving insert mode.
Note that other ways of viewing the bash output in a second window might solve my problem as well. However it should update while I am working in the other window and allow me to signal e.g. <CTRL-C> to the application.
The ConqueTerm documentation says:
3.1.5 Keep updating terminal buffer *ConqueTerm_ReadUnfocused*
If set to 1 then your Conque buffers will continue to update after you've
switched to another buffer.
Note: Conque buffers may continue to update, but they will not scroll down as
new lines are added beyond the bottom of the visible buffer area. This is a
limitation of the Vim scripting language for which I haven't found a
workaround.
>
let g:ConqueTerm_ReadUnfocused = 1
AFAIK Vim has no support for asynchronous sessions, so this is more of a response to your request for potential alternative options.
The way that I currently get around this issue is by using tmux, which is described as:
a terminal multiplexer: it enables a number of terminals (or windows),
each running a separate program, to be created, accessed, and
controlled from a single screen.
So, basically, instead of splitting your screen in Vim you would split it using tmux, and then in one window run Vim and in the other run whatever other program you want which will update completely independently of Vim. And just like Vim you can switch between the windows (or panes as they are called in tmux lingo) using a couple of key strokes.
There is another terminal multiplexer available called GNU screen, which is also quite popular. And the reason I mention that is because I like to have options, and also there are two plugins for Vim that allow you to send output directly to an attached screen or tmux session. For GNU screen, slime.vim, and for tmux, tslime.vim.
Using VIM and ConqueTerm you can use CTRL + W and UP / Down to change windows in split mode.
Just click on ESC first to exit the insert mode.
It works well on my side.

Resources