Scrolling "too long" command doesn't work properly - fish

Assume I want to invoke a tool with a lot of options, like:
$ somescript --option1 --option2 --option3 --option4 --option5 whatever even more stuff
But the width of the terminal doesn't allow to have that thing on a "single line".
That alone isn't a problem, but with fish, there is a problem with scrolling.
When I enter that extra-wide command, at some point, there will be a line break:
$ somescript --option1 --option2 --option3 --option4 --option5
whatever even more stuff
All fine so far. While typing such a lengthy command, I can scroll forth and back at any point. Works as expected. So, assume I entered the command, made a mistake, and now want to remove --option4.
The normal thing: use "arrow up" to get to that command in the history, to then use "arrow left" to scroll within the command. And now something weird happens.
Everything is fine while the cursor is within the second line. But when the cursor moves to the first line ... after 3 to 5 more "arrow left" strokes, the cursor moves UP another line. Then it sits above the first line of the command. There is also a vertical jump of a few characters.
In other words: as soon as a command is longer than the width of the terminal, I am unable to scroll into the first line reliably. The cursor shows up somewhere, and it is really hard to guess where it really sits at any moment. Which makes it almost impossible to edit anything in that first line.
This is on MacOs, using iterm 3.2.9 and fish version 3.0.2 installed via brew.

Wrote up defect 6014 on github. Outcome is rather frustrating.
The problem is: the Mac terminal(s) all handle certain unicode characters the wrong way. "Normally" that isn't a problem, but when you use one of those fish prompts that give you the git status (like AcidHub which is my favorite) ... fish can't compute/determine the exact line width, and there you go.
So, basically, when using fish on MacOs, option space is limited to:
use the defaults, which (when using special prompts, like AcidHub will lead to scrolling issues)
adapt the fish prompt accordingly (in my case, I replaced all special unicode chars with something simpler). It doesn't look that great, but scrolling simply works again.
And a completely different and unexpected solution to the problem: I am using iterm2 on my Mac, and iterm2 just added a "status bar" section. That can be easily configured, and of course, it already has a status bar component that tells you about git status.
Thus my solution: I changed the fish prompt to just give the PWD, and all the other things that the AcidHub prompt has to offer, are now "iterm2 status bar" components!

Related

Is it possible to take control of sublimetext3 tabs with cmd

Good Day.
I am a hobby programmer, and am just looking for creative ways to get things done.
In particular, closing a tab or tabs in sublimetext3 through a cmd line method.
The even cooler thing would be, if so, is there a way to decide in cmd which tab to close e.g. 3rd from left/right etc?
In keeping with the idea that this is mostly curiosity and preference than anything else, so creative replies are definitely appreciated as well.
You can execute any command* from the command line, so this is very much possible.
For example, to close the active tab of the most recently used Sublime Text window, you can run subl --command close.
To close a specific tab, for example the 18th tab, which will have index 17 because it is zero-based:
subl --command 'close_by_index {"group": 0, "index": 17}'
(This is assuming bash syntax - for Windows cmd syntax, you may need to do some creative escaping because the command arguments have to be valid JSON and quoted as part of the same argument as the name of the command you want to execute.)
This is exactly the same command that would be run when right-clicking on the tab and picking Close Tab in the context menu. This command can be seen by inspecting Packages/Default/Tab Context.sublime-menu using the built-in View Package File functionality in the Command Palette. You can check this file to see other pre-defined entries like closing all other tabs, or tabs to the right etc.
*: Caveats being if ST is not already running, then it tries to run the command before plugins are loaded.

How to fix some tmux things (screen instead of xterm; function keys)?

Why does tmux change the terminal from xterm to screen, and how can I fix the resulting text color change in emacs? I think the easiest way would be to prevent it from changing to screen in the first place.
I can use TERM=xterm emacs file.ext to do it temporarily, but that's just a workaround that doesn't solve the root of the problem.
Furthermore, the function keys no longer work in emacs when using tmux. Instead of F3 and F4 being macro shortcuts, they just print a tilde as they would in the shell. This seems unrelated to xterm/screen mentioned above. What is happening here, and how I can fix this?
tmux sets TERM to screen because that terminal description is limited to things that tmux knows how to work with. Like screen, tmux translates features from the outer terminal description to the inner.
If a special key (function-key, cursor-key, etc) does not have an exact match in the terminal description, tmux will ignore it.
The default configuration for PuTTY sends different escape sequences for F1-F4. The sequences which PuTTY sends are not in the terminal description for xterm.
Here's a comparison of the two (as a CSV file, but readable enough):
NAME,putty,xterm
kf1,\E[11~,\EOP
kf2,\E[12~,\EOQ
kf3,\E[13~,\EOR
kf4,\E[14~,\EOS
kf5,\E[15~,\E[15~
kf6,\E[17~,\E[17~
kf7,\E[18~,\E[18~
kf8,\E[19~,\E[19~
kf9,\E[20~,\E[20~
kf10,\E[21~,\E[21~
kf11,\E[23~,\E[23~
kf12,\E[24~,\E[24~
kf13,\E[25~,\E[1;2P
kf14,\E[26~,\E[1;2Q
kf15,\E[28~,\E[1;2R
kf16,\E[29~,\E[1;2S
kf17,\E[31~,\E[15;2~
kf18,\E[32~,\E[17;2~
kf19,\E[33~,\E[18;2~
kf20,\E[34~,\E[19;2~
You'd have trouble getting PuTTY to send F13-F20, but will certainly run into trouble using PuTTY and tmux with TERM=xterm.
Regarding colors, the same issue applies. The screen terminal description tells applications that the terminal can support 8 colors, and tells how to display those eight colors. If your external terminal can do more, then tmux and screen hide that.
The conversion is not perfect. GNU screen has a feature where it looks for a corresponding screen.$TERM terminal description (i.e., concatenating the outer TERM value to screen). tmux does not do that: it makes assumptions regarding xterm. But PuTTY is not xterm...
ncurses has several of those concatenated terminal-names for terminal descriptions, but no one has suggested a way for tmux to use them automatically.

Go up one command instead of one line in IPython 5

IPython 5 is a big release. One of its features is real multi-line editing with prompt_toolkit. The up arrow key now moves to the previous input line instead of the previous input command (block of lines).
This is awesome, but when my previous command spans many lines, and I need to reach the command before that, I find myself wishing I could go up one command at a time. Is there a way to do that? The shortcut ctrlp has the exact same behaviour as the up arrow key, so it does not provide a solution.
On my own Belgian Mac keyboard, fnshift↑ does the job. But I cannot tell whether this also works for other locales.
The PageUp and PageDown keys do exactly what you want without any chorded hotkeys involved; they work on an entry-oriented basis, rather than the arrow keys' line oriented approach.

Powershell commands?

Ok I'm having trouble and google isn't helping, so I thought I'd come to you geniuses. I'm using Powershell and posh-git, and it keeps doing something that I'm sure I can exit out of with a magic command, I just don't know it yet.
Basically, when I run git diff (or something else with a long result), it will only give me a screen's worth of information, and end the screen with a colon
:
And if I keep pressing Enter it will add more to the screen til it is done showing everything for that command, and shows
<END>
But now what? How do I get out of this and back to calling commands? Enter, Esc and the other things I thought to try are not helping. I'm sure this must be a simple thing, but I don't know how to explain to Google what I want.
Anyone know?
if you do a git config -l you may see some relevant entries like:
core.pager='less'
pager.diff=false
pager.log=true
You can enable or disable the pager for different commands, or set a different pager. https://www.kernel.org/pub/software/scm/git/docs/git-config.html has the details, check out the core.pager section and pager.<cmd> sections for specifics.
If you're using 'less' as your pager, hit 'h' at that : prompt to get lots of details about what you can do there, and as pointed out by others, q, Q, or ZZ will get you back to the command line.
You can terminate the current command using CTRL+C. Is that what you're asking?

Would it be possible to jump between prev/next Terminal command prompts?

I'm using zsh in OS X Terminal.app and for quite a while, I've been longing for a way to jump back and forth between prev/next prompts in the terminal's output.
One convenience with this would be to be able to review (and track errors at) the end of each command's output; eg. when you building stuff from source with ./configure; make; make install. Note: I'm obviously not referring to jumping back and forth in the command-history, but for a way to take a peek at the endings of each command's output.
Has anyone heard of such functionality in the *nix (preferrably also Mac) world? Would it require some sort of OS-centric Terminal plugin, or can it be programmatically done via a shell script which can be tied to a keyboard shortcut? Maybe I'm the only one thinking about this? :)
Edit: Here's an example scenario: Let's say I want to compile and install some program (using standard ./configure && make && make install procedure) and after the make command, I run into some errors. Now, the way I understand it (I may be completely wrong), the crucial error causing the make command to fail usually shows up in the last line(s) in the output, no? Anyway, at this point, I might do something like cat INSTALL to read up on the INSTALL document to check whether there's something I've missed. NOW, if I want to go back to see what the error was, that caused my initial make command to fail, I then have to manually scroll up to that position again, since my cat INSTALL command printed a ton of text after it.
I don't know if this scenario is the most elucidative – but there are many other situations where I wish I could just "jump" back to previous prompt lines and check up on previous command output; whether it was a simple ls command, make, git status, or whatever it was – swapping positions in the window by means of using prompt lines as "bookmark" positions seems an interesting idea to me.
command + left or right goes between tabs in iterm. is this what you are asking?
Emacs has a shell-mode that runs a shell inside the Emacs editor, providing a rich environment of additional commands for navigating and working with shell commands. This includes commands for going to the previous/next prompt, and deleting the output from commands so you can "clean up" and issue another command.
If you aren't familiar with Emacs: to start a shell inside Emacs, run emacs from the shell, then type Esc-x (or Meta-x, if you have "Use option as meta key" enabled in Terminal > Preferences > Settings > [profile] > Keyboard). This will ask for a command to execute. Enter shell.
To see a list of commands you can use in Shell Mode, enter Control-h m. Here are the ones for moving the cursor to the previous/next prompt:
C-c C-n comint-next-prompt
C-c C-p comint-previous-prompt
These commands would also be useful:
C-c C-r comint-show-output
C-c C-o comint-delete-output