Keybindings not working from VSCode integrated terminal - bash

I'm attempting to map the vscode commands workbench.action.navigateLeft and workbench.action.navigateRight to alt+i and alt+o, respectively. This was pretty straightforward with the following changes to keybindings.json:
{
"key": "alt+o",
"command": "workbench.action.navigateRight"
},
{
"key": "alt+i",
"command": "workbench.action.navigateLeft"
},
This works perfectly when I'm in the context of editors, but does not work when my focus is on the integrated terminal. I've added these two commands to terminal.integrated.commandsToSkipShell in settings.json but that seemed to have no effect. Nothing happens when I press alt+i or alt+o from within the integrated terminal.
"terminal.integrated.commandsToSkipShell": [
"workbench.action.navigateLeft",
"workbench.action.navigateRight"
]
I'm on a linux system using bash as my shell. It seems like maybe bash is capturing my keystrokes before vscode has the opportunity to interpret them, but I don't know how to verify if that's happening or how to change it if it is. Any help would be appreciated.

The problem ended up being with a different setting in my settings.json file. I had terminal.integrated.sendKeyBindingsToShell set to true which was intercepting some commands before they could be received by vscode.
This makes sense given the description of that setting. Setting this value to false (or removing from my settings.json file as the default is false) caused my key bindings to work as expected.

Related

Why is iTerm2 printing Pytest results in color?

I was playing around with Pytest --color=yes option and realized that my Terminal is printing results in color even without it being set.
Why is that?
My terminal setup is this:
OS: MacOS
iTerm2 build 3.4.15
iTerm2 Report terminal type property set to: xterm-256color
default shell is zsh (oh-my-zsh)
not sure if anything else matters...
My guess is it has something to do with oh-my-zsh, but I am not sure what, where and how.
I got to this question because I was trying to create SublimeText build system that will print results in colors, without success (not counting using SublimeANSI plugin which works with some quirks).
So, to reiterate the question: I am confused why my terminal app is printing Pytest results in color, even when no --color=yes is not set for Pytest.
If we look at the Pytest terminal source, we'll see the following on the color option:
group._addoption(
"--color",
metavar="color",
action="store",
dest="color",
default="auto",
choices=["yes", "no", "auto"],
help="color terminal output (yes/no/auto).",
)
So the default is set to auto.
Your zsh/oh-my-zsh allows to use the colors and therefore there shown without passing the option yourself.

Need help understanding how VSCode processes environment variables

I have always had issues understanding how VSCode process environment variables on Windows. Currently, I am trying to integrate Cmder with VSCode as my shell using the json below that I found on Github:
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.env.windows": {
"CMDER_ROOT": "[cmder_root]"
},
"terminal.integrated.shellArgs.windows": [
"/k",
"%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd"
],
I was trying to replace "[cmder_root]" with a variable defined in the OS but cannot get VSCode to recognize it. When I create the variable as a System variable, if I run set at the cmd.exe prompt of the integrated terminal, it shows the new variable name and the value I set it to but VSCode won't use it because it will not start Cmder when I open a terminal.
If I define the variable in the OS as User variable, running set inside the integrated terminal no longer displays that variable with the value I set it to. It displays it as CMDER_ROOT=%CMDER_ROOT%.
I finally got Cmder to work by hard coding the path in the settings.json file but it just made me want to find out what I am doing wrong.

VScode terminal doesn't seem to load .bashrc or .bash_profile on windows

If I start a new integrated terminal in VScode it does not seem to load my .bashrc file. Once the terminal is open I can source ~/.bashrc and the custom settings then appear. My problem seems to be a duplicate of this question, however for windows instead of osx.
Is it possible to have vscode automatically source my .bashrc or .bash_profile when it starts a new instance of the integrated terminal?
So far i have tried the following:
I have pointed the terminal to git bash by setting "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
I have tried pass a shell argument in the settings, using "terminal.integrated.shellArgs.windows": ["-l"] however it is not clear in the documentation if this applies to windows or just linux.
Adding this to my settings.json fixed this issue for me.
"terminal.integrated.shellArgs.windows": [
"-l"
]
Edit: Derp I am bad at reading. It might work for you if you move your .bashrc content into a .bash_profile file.

Changing the VSCode integrated shell's prompt on MacOS X

Having just installed VScode I have noticed as it uses Bash by default on OSX, with the shell's default prompt of bash-3.2$; consequently, I cannot see the current working directory. It means having to type 'pwd' and 'ls' quite frequently which is obvious quite tedious.
I have tried changing the default shell in the settings to
"terminal.integrated.shell.osx": "/Applications/Utilities/Terminal.app"
or
"terminal.integrated.shell.osx": "/Applications/iTerm.app"
This doesn't seem to work, have I made a mistake here?
I would also like to know if I am limited to bash, can I configure it to display the working directory instead of simply bash-3.2$ ?
See this screenshot of how the VSCode integrated terminal looks by default
Thanks in advance!
I use Ubuntu, and only add the following lines to the end of ~/.bashrc:
if [ "$TERM_PROGRAM" = "vscode" ]; then
PS1='\$ '
fi
Try it and let me know if it works on your OS.
You can set your prompt to contain the current working directory by defining PS1 as follows:
PS1="\w $"
The $ is just some visual sugar. There all manner of things you can have your prompt display. Put the definition in your ~/.bashrc or ~/.profile for it to be set when you login.
Check out the Controlling the Prompt section of the GNU Bash manual for details.
If you are not accustomed to editing your bash init files you can do it with Visual Studio Code by going to View->Command Palette and execute the following command (one-time only):
Install 'Code' command in path
Then open the integrated terminal and type the following:
code ~/.bashrc
Then add the PS1 definition to the bottom of that file.

Fish shell on windows outputs question mark before each prompt

I just switched to a windows machine and I'm trying to get fish configured correctly. I installed it through the default route, as a shell selected through cygwin setup. It seems to be working fine, but when I directly access fish.exe or run fish.exe through IntelliJ, it outputs a ? before very prompt:
I googled and found this on fish documentation FAQ:
I'm seeing weird output before each prompt when using screen. What's wrong?
Quick answer:
Run the following command in fish:
echo 'function fish_title;end' > ~/.config/fish/config.fish
Problem solved!
The long answer:
Fish is trying to set the titlebar message of your terminal. While
screen itself supports this feature, your terminal does not.
Unfortunately, when the underlying terminal doesn't support setting
the titlebar, screen simply passes through the escape codes and text
to the underlying terminal instead of ignoring them. It is impossible
detect and resolve this problem from inside fish since fish has no way
of knowing what the underlying terminal type is. For now, the only way
to fix this is to unset the titlebar message, as suggested above.
Note that fish has a default titlebar message, which will be used if
the fish_title function is undefined. So simply unsetting the
fish_title function will not work
So it appears that intelliJ and cmd (fish.exe runs in cmd.exe if you access it directly) do not support setting the title bar, so they just output the character to the terminal instead. However, their suggested solution does not work. I've tried various options like echoing an empty string or a space, but nothing gets rid of that darn question mark.
Has anyone else run into this and found a solution?
Notes:
It doesn't have this behavior when using fish through mintty.exe,
most likely since that terminal supports setting the title, but I really prefer
to use the terminal inside intelliJ instead of having it in a
separate window.
It didn't have this problem when I used fish through IntelliJ on Ubuntu or MacOSX, it appears to be isolated to Windows

Resources