Trying to find a way to broadcast the output of one terminal over to the input of another terminal. I am using iTerm2 on Mac, but it could be any other terminal utility.
I know of the broadcast input in iTerm, but that is not what I want to do. I could just copy the output of one term and paste into another, but I want to find a way to accomplish this for a long running session.
Related
I know that commands can be logged by going to the console View -> Show Console and typing
sublime.log_commands(True)
However, the commands that are run through the command palette are not logged, it just shows:
command: show_overlay {"overlay": "command_palette"}
Is there a way to log the commands run through the palette?
There's not currently a way to log the commands that are being executed from the command palette, no. If I recall correctly, this was possible in older builds of Sublime, but around the time that the command palette gained the ability to accept input for commands like View Package File, it stopped working. That might be an offshoot of the mechanism that's used to trigger input handling in the command palette, but that's just a guess.
Normally a plugin could be used to track something like this because EventListener classes have events to tell you before and after commands execute. However, there's an open issue on the tracker regarding the command palette on triggering on_post_window_command which is likely caused by the same thing as the commands not showing up in the log.
Currently the only way to know what command and arguments are being invoked from the command palette is to introspect the sublime-commands file that's providing them.
Unlike menus, commands in the command palette are not allowed to have dynamic captions, so it's a relatively simple matter to find the command entry that has a "caption" for the text you know you're picking.
The tricky part can be in determining where the command is coming from. In the console, sublime.find_resources('*.sublime-commands') will show you a list of every known command file, and you can open them via View Package File in the command palette.
Generally, anything that ships with Sublime is in Default/Default.sublime-commands, and anything that's added by a package is prefixed by the name of the package that added it, which can aid in determining what file to check.
Note that there are some commands in the command palette that are added by Sublime and don't come from a command file; commands that insert snippets and commands that change the syntax. Those are determined on the fly since the list of syntaxes and snippets is subject to change.
Is it possible to read what's currently displayed on the windows terminal pragmatically using any available API?
For example, I've got an app that tail's some log files. I'd like to be able to hit a key and open a text editor at the line that is currently being viewed. The problem is the terminal also has scroll bars.
Not easy. Perhaps you could capture the screen and use OCR to identify its contents, or make a shortcut to some sort of macro that selects all the screen and copies the text. But there is no API available to perform the task you ask.
Of course, you can tee the command you're running in the console to a file, and open such file with an editor whenever you like, however it will show the full output of the command and not the visible part. If you like more information on that topic, it is answered in SO - Displaying Windows command prompt output and redirecting it to a file
.
I am using Ruby on a mac to open a dozen URLs one at a time with Nokogiri etc.
For each URL I need to let my ruby program know
whether to keep the URL window for further inspection or close it.
But I cannot see the terminal window and its prompt, it is hidden behind
the last URL window.
I have to click on the terminal window in order to bring it to the front, in order to enter my decision on the keyboard.
puts "close webpage?"
if gets =~ /^y/i then 1 ; else; 0; end;
I would like the terminal window to come to the front before it prompts
me for an answer.
I think the question is two fold
Is there a terminal command that tells a terminal window to become
the active one (the one in the front) that would work with mac iTerm.
The Apple script "bringiTermtofront" works in the applescript editor.
tell application "iTerm" to activate
Is there a way to execute a terminal command from ruby.
the ruby code
system "osascript bringiTermtofront.scpt"
brings the iTerm to the front.
For Question 1, one approach would be to write an Applescript to handle the switch, and then use the Terminal command osascript to run it from your Ruby code. You could also check if rb-appscript is still usable (it's no longer supported, but might work).
For Question 2, you have a few choices. Using backticks around the command will let you capture the output of a brief command, if you want to store the result of the command in a variable. (E.g. use grep or something similar).
The system method in Kernel is probably your best choice, though, as it will execute shell commands as if at the terminal.
Per the edit showing what script you're using, you need to execute the script as Applescript, not as a terminal script. You don't even need a separate file as it's just one line. This would be :
command = %q[osascript -e "tell application \"iTerm\" to activate"]
system(command)
You could also put the Applescript in a file and execute it using just
system("osascript bringiTermtofront")
See "Running shell commands from Ruby" for a little more help on how to interact with these methods.
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
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.