I am currently using Sublime Text 3 and iTerm2. Whenever I save a log from iTerm2, it contains characters that indicate things like backspaces and such. These characters make the file non-searchable (with find in files) in Sublime. Is anyone aware of a terminal application that will not store these keypresses in logs, or a way to prevent iTerm2 from storing these keypresses?
Thanks
You can filter the backspaces out after saving it. That aspect has been discussed several times. For example
Can I programmatically “burn in” ANSI control codes to a file using unix utils?
format output from Unix “script” command: remove backspaces, linefeeds and deleted chars?
Related
I'm programming a script that outputs tab characters. The users of this script expect to be able to copy and paste the output of this script from Windows Terminal into a spreadsheet program, and have the tab characters interpreted as dividers between cells. However, this breaks, because the tab characters get converted to spaces. How can I fix my script to force Windows Terminal to output tab characters instead of spaces?
For example, if I have a Python script that outputs "one\ttwo\tthree", this is what gets output to Windows Terminal:
one two three
The tab characters (U+0009) get converted to space characters (U+0020) by Windows Terminal. If I copy and paste this line into a text editor or a spreadsheet program, it will see space characters, not tab characters, which is not what I want.
As you've confirmed via that Github issue, there's no way to have Windows Terminal itself maintain the tabs (at least not yet). As a programmatic workaround for your script, consider offering the user the ability to output the results directly to the clipboard (assuming the output is "focused"/small enough) using something like this answer (Python-based, since that's the MRE you provided).
The user can, of course, also redirect the output to the clipboard using Windows clip.exe. E.g.:
python3 -c 'print("one\\ttwo\\tthree")' | clip.exe
I confirmed that the tabs are maintained in this case.
Unfortunately, there isn't a way to configure Windows Terminal to preserve tab characters. And I don't think there is a way for a script to force Windows Terminal to preserve tab characters.
See this bug report.
I am trying to edit some portable executable file with text editor.
In the top of the file a backward compatibility string is supposed to display messages on DOS systems.
This program cannot be run in DOS mode.(click the link to see screenshot)
I first tried to edit this string by replacing a char (not removing or adding : just replacing to not change the file size). Then when I try to execute the file windows return an error saying I can't run this app on my computer.
I also tried to edit the padding at the very end of the file and the error is the same.
I suppose an integrity check is performed. Did someone already read about this? If you did, do you know if/where the file hash is stored in it?
A text editor is not appropriate for editing binary files. Use a hex editor instead.
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 want to be able to use Option-left and Option-right to skip words (and Cmd-left/right to go to beginning and end of lines) within Vim as it does at my shell prompt. My Iterm2 preferences have mappings to do this (e.g. Option-left to Esc-H and a one for option-right to Esc-F to skip over words), and this works in the shell locally or when ssh'd to a remote server.
When I use Vim locally or remotely, option-left works, but option-right does not. I suspect this is because Vim naturally listens for Esc-H, but not Esc-F. I am able to get around this by modifying .vimrc file to Esc-b to b and Esc-f to f, but I don't want to do this to every server I'm connecting to.
Similarly, I have the same desired setup for Cmd-left/right for going to beginning and end of a line. I can get this working in the shell via Iterm2 mappings (e.g. Cmd-left to Esc-[h), but Vim doesn't respond at all to this unless I map keys again (e.g. Esc-[h to ^).
Update: I just figured out how to get option-left/right working. I changed mapping in iTerm2 for these to be escape-[1;5D and escape-[1;5C respectively. I still want to solve the Cmd-left/right problem though (I changed my question's title to reflect this). Any ideas?
To mimic OS X's behavior of sending Cmd-left/right to the beginning/end of a line, I add the following mappings in iTerm2:
Cmd-left to escape-sequence [1~
Cmd-right to escape-sequence [4~
To mimic OS X's behavior of sending Option-left/right to the previous/next word, I add the following mappings in iTerm2:
Option-left to escape-sequence [1;5D
Option-right to escape-sequence [1;5C
Special thanks to this blog post for tracking down what I was missing with the cmd-left/right mappings
I'm using iTerm2 3.4.2 and there's actually a preset that you can select for your profile that enables this.
FWIW, dolan's answer didn't work for me on iTerm 2 1.0.0.20120203 on Mac OS X 10.7.3. His solution only inserted ~ and 5D/5C into my terminal when I pressed the shortcut keys.
Instead, I used the following solutions:
Cmd-left/right:
iTerm 2: How to set keyboard shortcuts to jump to beginning/end of line?
Option-left/right as well as option-delete:
http://hackaddict.blogspot.co.at/2007/07/skip-to-next-or-previous-word-in-iterm.html
YMMV, not sure why one set of solutions would work and not the other
I don't have MacOS, so I cannot exactly know your situation, but I recognize the problem from other OSes.
Basically, it would mean that the terminal sends keycodes that aren't understood by vim. I fixed it in the past by doing
TERM=something
export TERM
before invoking vim
E.g. in order to get all keys and syntax highlighting working on AIX 5.3 across Putty/screen, I needed to use
TERM=iris-ansi vim
There is a list of builtin terminal types if you pass a bad TERM
I am planning on developing an Mxmlc to Textmate formatter, one that formats mxmlc errors as clickable links, so you can open them up quickly in Textmate as Textmate has a url scheme e.g.: txmt://open/?url=file://~/.bash_profile&line=11&column=2.
I am wondering if it is possible to display links in your OSX terminal, that are also clickable, e.g. by changing the PS1 variable or so.
ps. I don't want to use HTML that runs in the Textmate environment.
Before OSX Lion:
cmd+shift+double-click on a URL in Terminal.app and it will open in the default program.
OSX Lion:
cmd+double-click (otherwise you will enter fullscreen mode).
You can right click on a URL in Terminal and the first option in the context-sensitive menu is "Open URL". Not perfect, but maybe good enough ?
Others have discussed how you can select and Command-click on text which is a valid URI. As for Command-clicking on an embedded hyperlink, just like an anchor in hypertext (i.e., where the displayed text is not the URI itself), I believe the short answer is: Terminal cannot do it, but iTerm2 can.
Bash (or any other program that prints to a tty) can output the appropriate escape sequence to create a clickable hyperlink: it is \x1B]8;;URI\x1B\\TEXT\x1B]8;;\x1B\\, where \x1B represents the escape character, \\ represents a literal backslash, URI is the URI you want to link to (starting with https://, file:///, or whatever), and TEXT is the text you want to actually appear, for the user to Command-click on. (You can also use \a, the alert or bell character, instead of both instances of \x1B\\, but I understand this is less standard.) For example:
See \x1B]8;;file:///path/to/help/file\x1B\\the help file\x1B]8;;\x1B\\ for details.
In Mac OS(X), under El Capitan in my case, this works perfectly with iTerm2, and shows:
See the help file for details.
except that the linked text the help file has a dotted underline instead of being in italics. Command-clicking anywhere on the linked text opens the specified URI in the default browser. (Incidentally, this is also the behaviour in the Terminal program in Ubuntu Linux.)
In Mac OS(X) Terminal, you just get:
See the help file for details.
with no special typography and no ability to Command-click on any part of it.
You can get the full detail, including a list of supporting terminals, at https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda.
Pipe your output to lynx:
your_command | lynx -use_mouse -stdin