How can I send selected text (or a line) in TextMate to R running on Terminal - r

I just started using R on Terminal because its tab function. But I have no idea how to send the selected text in TextMate to the Terminal. Could expertise show me how to write the Command in TextMate?
Thanks!

Here is the exact TextMate command that I currently use. Hope it helps!
rawText="$(cat | sed 's/ / /g;')"
osascript -e 'on run(theCode)' \
-e ' tell application "Terminal"' \
-e ' do script theCode in window 1' \
-e ' end tell' \
-e 'end run' -- "$rawText"
open "txmt://open?line=$(($TM_LINE_NUMBER+1))&column=1000000" &

TextMate is MacOS, right? Is so, then this is from the R ?connections page:
"Mac OS X users can use pipe("pbpaste") and pipe("pbcopy", "w") to read from and write to that system's clipboard."
You can "paste" from R-Clipboards into Terminal sessions. You can also send file content from TextMate:
http://manual.macromates.com/en/shell_commands#executing_commands_filtering_text

Related

Textmate: source R script to iTerm

This is a Mac specific question. I would like to source a script that I'm editing on Textmate2, e.g. mycode.R, and make it run in iTerm (terminal would do as well). I do not need to start R, I have the top window of iTerm already running it.
So in the iTerm tab should appear the line:
> source("[path]/mycode.R", chdir = TRUE)
What I needs equivalent to what you have on Rstudio with the key combination Cmd + Shift+S. I found this answer How can I send selected text (or a line) in TextMate to R running on Terminal, but this is about sending a line, or echo the entire code, while what I need should be easier. I succeeded in sourcing to R.app using the following code
#!/bin/bash
osascript -e 'tell application "R.app" to activate'
osascript -e "tell application \"R.app\" to cmd \"source(file='"$TM_FILEPATH"',print.eval=TRUE, chdir=TRUE)\"" \
osascript -e 'tell application "TextMate" to activate'
But if I replace "R.app" by "iTerm", "iTerm2" or "Terminal", the script fails.
This does what I was looking for. I'm really not proficient with scripting, this is just result of (a lot of) trial and error. I'm sure there exists a more correct
or elegant solution. Here is the code.
#!/usr/bin/env bash
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
curDir=''
if [[ ${#TM_DIRECTORY} -gt 0 ]]; then
curDir="$TM_DIRECTORY"
fi
osascript \
-e 'on run(theCode)' \
-e 'tell application "iTerm2"' \
-e 'tell current window' \
-e 'tell current tab' \
-e 'tell current session' \
-e 'write text (item 1 of theCode)' \
-e 'end tell' \
-e 'end tell' \
-e 'end tell' \
-e 'end tell' \
-e 'end run' -- "source(\"$TM_FILEPATH\",print.eval=TRUE, chdir=TRUE)"

launch a CAT command unix into Dockerfile

I would like to launch this vagrant command cat(run perfectly!) to provisionning my container with a Dockerfile :
# Configure Virtualenvwrapper.
RUN cat <<EOF >> /home/docker/.bashrc
# Virtualenvwrapper configuration.
export WORKON_HOME=\$HOME/.virtualenvs
export PROJECT_HOME=\$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
EOF
But I have this error return when I launch my building image docker :
---> 40f9ed8e187d
Removing intermediate container 85f6c8536520
Step 69 : RUN cat <<EOF >> /home/docker/.bashrc
---> Running in dcbb3d441f79
---> 78acd9c2e5d5
Removing intermediate container dcbb3d441f79
Step 70 : EXPORT
Unknown instruction: EXPORT
What is the trick for run a cat command unix into image with Dockerfile ?
Based on this comment to an issue posted on Github, this works:
RUN echo 'All of your\n\
multiline that you ever wanted\n\
into a dockerfile\n'\
>> /etc/example.conf
Update [08/03/2022]: As of dockerfile/dockerfile:1.4.0, the Here-Document support has been promoted from labs channel to stable. #2589.
You need to use Docker Buildkit by setting DOCKER_BUILDKIT=1 in your environment, set the syntax parser directive to use dockerfile/dockerfile:1.4.0, and swap the position of the here delimeter with cat. The rest is used like normal.
Dockerfile Example:
# syntax = docker/dockerfile:1.4.0
...
RUN <<EOF cat >> /home/docker/.bashrc
# Virtualenvwrapper configuration.
export WORKON_HOME=\$HOME/.virtualenvs
export PROJECT_HOME=\$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
EOF
Prior to dockerfile/dockerfile:1.4.0, Here-Document syntax was supported in the labs channel dockerfile/dockerfile:1.3.0-labs release.
Simply replace version used in the syntax parser directive from the above example.
Prior to Docker BuildKit labs channel dockerfile/dockerfile:1.3.0-labs release, instead of using cat, try using echo instead!
Turn this shell cat example...
#!/usr/bin/env sh
cat <<EOF > /tmp/example.txt
line 1
line 2
line 3
EOF
... into this Dockerfile echo example!
RUN echo -e '\
line 1\n\
line 2\n\
line 3\
' > /tmp/example.txt
Note the pair of single quotes (') in the echo example.
Also note the -e flag for echo to support the escaped newlines (\n).
Caution: Unfortunately, the -e flag may or may not be required depending on the version of echo your image has installed. For example, the npm:16 image's echo does not require -e and actually will print the -e along with the single-quoted lines. On the other hand, the ubuntu:20.04 image's echo does require -e.
The same example could be written on one line as:
RUN echo -e 'line 1\nline 2\nline 3' >> /tmp/example.txt, but I find the above example more readable.
To answer the OP's question, use this:
# Configure Virtualenvwrapper.
RUN echo -e '\
# Virtualenvwrapper configuration.\n\
export WORKON_HOME=\$HOME/.virtualenvs\n\
export PROJECT_HOME=\$HOME/Devel\n\
source /usr/local/bin/virtualenvwrapper.sh\
' >> /home/docker/.bashrc
Caution: The escape character can be redefined by the escape directive. If your Dockerfile has a different escape character set, you'll need to modify the examples accordingly.
Dockerfiles are not batch files. Every line/command is isolated and committed.
Just put the contents into a file and ADD/COPY it. If you need to customize it, SED it. Or if you really, really, really want to CAT into a file -- put it in a real batch file, then ADD/COPY it, then RUN it.
Also, less lines = less layers. 70 Steps? Yowzers.
You can write it this way:
RUN echo "# Virtualenvwrapper configuration." >> /home/docker/.bashrc && \
echo "export WORKON_HOME=\$HOME/.virtualenvs" >> /home/docker/.bashrc && \
echo "export PROJECT_HOME=\$HOME/Devel" >> /home/docker/.bashrc && \
echo "source /usr/local/bin/virtualenvwrapper.sh" >> /home/docker/.bashrc
You can also use below command in place of here document << inside a Dockerfile
RUN echo $'[kubernetes] \n\
name=Kubernetes \n\
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 \n\
enabled=1 \n\
gpgcheck=1 \n\
repo_gpgcheck=1 \n\
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg \n '\
> /etc/yum.repos.d/kubernetes.repo
If you want to avoid here-document syntax for some reason, printf is hugely more ergonomical than echo $'...' as well as portable to POSIX sh.
RUN printf '%s\n' > /home/docker/.profile \
'# Virtualenvwrapper configuration.' \
'export WORKON_HOME=$HOME/.virtualenvs' \
'export PROJECT_HOME=$HOME/Devel' \
'source /usr/local/bin/virtualenvwrapper.sh'
The single quotes prevent shell interpolation of variables; if you want to expand a variable, use double quotes (though then you'll need to backslash-escape any literal dollar sign, backtick, or backslash).
This is an example straight from Docker documentation:
# syntax=docker/dockerfile:1
FROM alpine
ARG FOO=bar
COPY <<-EOT /app/foo
hello ${FOO}
EOT
https://docs.docker.com/engine/reference/builder/#example-creating-inline-files

creating osascript one-line scripts, on mac osx 10.10.2

I'm new to terminal scripts and I'm trying to convert
osascript -e 'tell app "Terminal"
do script "ssh -t jgreen#dev-jgreen-bs pwd"
end tell'
This works with multiline as so but I want a one-line script, but I can't quite get it right. I keep getting a 2741 error, I know it is syntax I am failing with.
I have tried /, ,, \n,-e,&,to as separators.
You'll need to add a few sections to this one line command:
osascript -e 'tell app "Terminal"' -e 'do script "ssh -t jgreen#dev-jgreen-bs pwd"' -e 'end tell'
Each line in an applescript needs to be broken into sections on a single line osascript command in terminal. You add the "-e" for each section and the single apostrophe.
Hope this helps.

Unix mailx html mail not working

Following html mail using mailx command is working from shell terminal, but the same command is not working from shell script.
mailx -s "$(echo -e "${sub} TRP OF ${system} \nContent-Type: text/html")" example#gmail.com < TRP.html
I guess it is some small escape character error, but not sure what it is.
Can any one help here?
Perhaps your vars sub / system are only known in your current environment.
When your sript is called mymail, try
. mymail
(Start with a dot),
or first export your vars.
When these suggestions fail, debug:
use set -x or temporary put an "echo -e" in front of your line.

How to use BroadcasetIntent() function in Monkeyrunner

Can anyone let me know how to use device.broadcastIntent function for the create contact using python script
device.broadcastIntent('android.intent.action.INSERT',
'vnd.android.cursor.dir/contact', {'name':'user1501488', 'phone':'123-15489'})
For shell command try this
device.shell("am start -a android.intent.action.INSERT
-t vnd.android.cursor.dir/contact -e name 'user1501488' -e phone 123-15489")

Resources