How can I Launching vscode from command line in background? - visual-studio-code

I'm using shell on linux.
I would like the a way that will launch vscode in the background such that my terminal is still in focus.
I don't want to show any output on my terminal,perhaps chould show in integrated terminal which inside vscode.
Is someone can help me ?Thank you!

Add an & at the end (see: job control), you probably also want to redirect the output. If you would like to log it, redirect to a file like this &> vscode.log, but if you want to ignore it, &> /dev/null (this is called a null device, see this page for more). So the final command is something like this: code . &> /dev/null &.

Related

Editing WSL2 instance of Ubuntu Crontab using Windows VSCode

My question is whether it is possible to edit the crontab of a WSL2-based instance of Ubuntu with my Windows VSCode that is connected via WSL remote SSH.
If I type export EDITOR=code inside my WSL instance and then crontab -e, I am able to see a /tmp/crontab.sygFAU file load inside my VSCode instance.
The problem is that once I make edits to this file, it will save the file to /tmp/crontab.sysFAU but it doesn't actually take the next step of replacing the the real crontab file in /var/spool/cron/crontabs.
So once I re-open the crontab, it will just show what I had previously, and not my saved edits.
It would be nice to know if this is not possible or if there are any alternative ways to run a GUI editor because using nano is a pain!
An interesting question that I haven't considered before, myself. Here's what's happening:
You set your editor to code
You crontab -e, which properly loads VSCode with the temporary crontab.
However, because this is a Windows GUI application, it returns control to the parent Linux application (crontab) immediately after starting VSCode. You can see the same result if you just start notepad.exe from your shell in WSL -- Once Notepad starts (rather than exits) control is returned to the shell.
If you switch back to your terminal at this point, you'll see that crontab detected that the editor that it launched exited (returned), and so it has already tried to copy the temporary file to the permanent location.
However, since the temporary files doesn't yet have any changes, crontab decides there's nothing to do.
Editing the file in VSCode and saving it has no effect, other than to leave a dangling /tmp/... file hanging around (since crontab isn't there to clean up).
So what's the solution? We need a way to launch a Windows GUI application and prevent it from returning control to crontab until you are done editing.
I originally thought something from this question might work, but the problem is that the actual command that launches the Windows process is embedded in a shell script, which you can see with less "$(which code)" (or code "$(which code)"), but it's probably not a great idea to edit this.
So the next-best thing I came up with is a simple "wrapper" script around the (already-a-wrapper) code command. Create ~/.local/bin/code_no_fork.sh (could be anywhere) with:
#!/usr/bin/env bash
code $* > /dev/null
echo Press Spacebar to continue
read -r -s -d ' '
Credit: This answer for the Spacebar approach
Then:
EDITOR=~/.local/bin/code_no_fork crontab -e
After you make your edits in VSCode, simply press Space to allow the script to continue/exit, at which point crontab will (assuming no errors were detected) install the new Crontab.
Alternatives
This is should typically only be a problem with Windows GUI applications, so the other possible avenue is to simply use any Linux editor that doesn't fork. If you want a GUI editor, that's entirely possible as long as you are running a WSL release that includes WSLg support (now available for Windows 10 and 11).
I won't offer any individual editor suggestions since that would get into "opinion" and "software recommendation" territory, which is off-topic here.

Change color and names of terminals in VScode with a script

I'm a big fan of personalizing my terminals in vscode, I like having them set up like this:
The problem with this, however, is that I often need to restart my vscode instance, or log out from ssh etc.
When I do that, my terminals reset.
Is there some way for me to open new terminals through a script?
i.e. something like this, so that I could write a script for it.
code --terminal --color=blue --name=docker --command=docker exec -it 7935b bash
This can be done with the Terminals Manager extension using a JSON file:

How can I update my account to use zhs. in VSCode?

When I run my code in VS Code, I get this message after every user interface input
The default interactive shell is now zsh.
To update your account to use zsh, please run chsh -s /bin/zsh.
What can I do to use zsh and/or keep this messsage from appearing?
If you are using MAC, Apple has changed the default Interactive Shell from macOS Catalina.
But your Shell still could be bash.
if you want to change it to zsh, just run the following command in your terminal.
chsh -s /bin/zsh
and if you want to stop message appearing every time you open terminal
just follow this article here.

How to use inkscape command line interface?

I'm trying to use the inkscape command line interface. I have windows 7.
First I open up command line, and I run these:
cd "C:\Program Files\Inkscape-0.48"
inkscape "C:\Users\me\Desktop\Pic\Class_UML.png" --export-png="C:\Users\me\Desktop\Pic\raster.png" --export-area=0:0:100:100
Then the inkscape popup opens, and I click embed, and then click ok, and then nothing happens, and the file doesn't show up.
Does anyone know what I am doing wrong?
Thanks
As of now, there doesn't seem to be a way to do perfect silent processing in Windows. However, any command using inkscape in Windows triggers an empty window while processing in background.
If you don't want it to open separate inkscape windows everytime, try entering the inkscape interactive shell (using inkscape --shell).
PS: I don't think we can do anything more in interactive shell, more than what we can do using cmd. Hopefully someone solves the aforementioned problem in Windows and adds more functionality inside shell.
Have you tried to open the file C:\Users\me\Desktop\Pic\raster.png and see how it looks like?
Supposedly by using --export-png in the command line, inkscape will not open the interface but simply process what you requested silently.
In this case you should have the cropped image should be saved in C:\Users\me\Desktop\Pic\raster.png.
I use Linux and tried your example to test and I get the same behaviour you described plus the response in the command line
Background RRGGBBAA: ffffff00
Area 0:0:100:100 exported to 100 x 100 pixels (90 dpi)
Bitmap saved as: raster.png
Hope it helps
On Windows, in the C:\Program Files\Inkscape\bin folder, you will see both inkscape.exe and inkscape.com. Use inkscape.com.
Here is an example from PowerShell:
> & "C:\Program Files\Inkscape\bin\inkscape.com" --help
#echo off
REM setup Inskcape File Location
cd /d "C:\Program Files\Inkscape"
inkscape path\filename.svg --export-dpi=120 -e exported_image_name.png --without-gui

How do I get the "Command Buffer" in Solaris 10?

When working on a linx CShell u get the option to press the up / down arrows to select the last command/s typed or the Command Buffer. This even works on Windows.
However this is not functional when working on Solaris, to which i recently switched. I am guessing that the shell is also a CShell.
Please tell me what key combination is required to have this feature on Solaris ?
The default shell in Solaris has command history, but you can also use Bash instead, it's more user friendly. Just type 'bash' (no quotes) at the command line. You can also edit /etc/passwd to make bash your default shell.
The "official" default shell for Solaris is actually sh, the original Bourne shell (see Chapter 10 of the Advanced User Guide for Solaris for more info). If you'd like to change it to csh or tcsh—and you're not root (it's generally considered bad practice to use anything but sh as root's default)—just issue passwd -e /path/to/shell_of_your_choice <loginname>. I'm guessing this would probably look like passwd -e /bin/csh <loginname>, but you'd probably want to make sure it exists, first.
It may be that it's the Korn shell in which case try <ESC>k.
bash at least will allow you to switch modes with "set -o vi" or "set -o emacs".
Maybe you can use the !! command, to repeat the previous one.
Use "echo $SHELL" to see what your login shell is. If it's ksh or bash, try "set -o emacs". If that works, you'll be able to use ^P to go back a command. ^R lets you search for a command, ^F and ^B to move around within the command.
If you can´t change your default shell, or you just want to try out one that works, you can kick off any other shell from your command line. I recommend you tcsh, which will have good command line editing and history using the arrow keys. Type /bin/tcsh at your prompt to try it out. You can use the earlier responses to change your default shell if you like tcsh. Make sure your have the following in your $HOME/.cshrc file:
set filec
set history=1000 # or some other large number
set autologout=0 # if you are logging in remotely under your account.
I hope this helps.
You enable history temporarily if you use BASH by typing
HISTSIZE=1000
which will enable up and down keys and store 1000 commands. After termal disconnetion all history will be gone.
This works on solaris 10.
For permanent solution add these lines to ~/.bashrc
HISTSIZE=1000
HISTFILESIZE=1000