Powershell --- code ~/.bashrc does not work (is it a linux thing?) - powershell

first image is the powershell code ~/.bashrc
Powershell
second image is the wsl ubunti code ~/.bashrc
wsl ubuntu
my question really goes, does this not work on powershell? is it a linux feature?
thanks, salamat, arigatou
ps: oof need 10 rep for images, this my first question so yeahhh

.bashrc is a file that contain code that is executed when WSL or Linux Bash shell is invoked. PowerShell has nothing to do with it. In Powershell, you can use Profiles for that. You can place powershell code in Profile and that will work like bashrc. To create a profile use new-item $profile -type file and then to open it in Notepad notepad $profile. Then you can add powershell code there.

Related

How do i hide file path information in VS-Code Terminal

I see this unnecessary file path information whenever I execute a program in the terminal section.
Is there a way to hide that file path?
This is not so much VSCode terminal related, rather it is more shell related (see What's the difference between Terminal, Console, Shell, and Command Line). Your VScode's terminal is running a shell internally, but a terminal is not much more than a display window that calls a shell's functions. So, in order to edit the prompt (which comes from the shell), we have to edit your shell config.
From your screenshot, it looks like the particular shell you're running is Powershell. Powershell has its own prompt that it generates each time before you run a command. It does so by calling the prompt() function (you can read more about it at Microsoft Docs).
Therefore, if you just want an empty prompt, then all you have to do is create an empty prompt function and add it to your powershell profile.
From your terminal, open your powershell profile file using VSCode (or any text editor)
# $profile is a variable in powershell
# that holds path of the powershell config
code $profile
Then add an empty prompt function into the profile
function prompt { }
Save the file and reopen another powershell instance in your VSCode terminal, and now it should look like this
PS>
If you're interested in further customizing this prompt, I would highly recommend looking into starship, a cross-platform shell prompt that can be used inside powershell. By default it's an even simpler arrow
❯
It only displays the most relevant paths, and can be customized to a much greater extent than the powershell prompt.

Why the window is popup and disappear after running shell script code

I use windows terminal when i run a shell script code a window is shown and disappeared and this video will explain what i mean
https://drive.google.com/file/d/1nlXoe3SYU7OgAhI6N53YnYSOdEtLK7lL/view?usp=sharing
Edit:
#!/bin/bash
echo hello
name="mostafa nasser"
echo $name
$SHELL
the code inside .sh file
You can modify your .sh script to keep the window open.
Add $SHELL at the end of the .sh script
Do this first:
$env:PATHEXT += ';.SH'
I tried Windows Subsystem for Linux with Ubuntu from the Microsoft Store, but it didn't make any association to .sh. But this worked for me:
bash file.sh

How to run octave script from shell at launch

I'm using Ubuntu system. To run MATLAB script at launch, I can type matlab -nodesktop -r "run ./my_program.m".
How can I achieve the same function on Octave, like octave --no-gui -some_command?
I've read this post and this post. They did not answer my question.
As mentioned in one of the comment, one solution is:
octave --persist my_program.m
Currently looks like it is enough to say for script (not plain function)
octave my_program.m
Also if you have octave installed in your path you could and in the beginning of script as the first line the desired interpreter (works for python, bash, whatever), for example for default location :
#!/usr/bin/octave
and you can run them without even adding the octave in front... just the script name....
For Windows users:
I see it's a bit harder, since there's no "octave.exe" file.
I do have:
"C:\Program Files\GNU Octave\Octave-6.4.0\mingw64\bin\octave-cli-6.4.0.exe"
which works after adding both parent directories
"C:\Program Files\GNU Octave\Octave-6.4.0\mingw64\bin"
and
"C:\Program Files\GNU Octave\Octave-6.4.0\mingw64"
to PATH.
All this happens automatically in the startup script which is the normal entry point of the SW:
"C:\Program Files\GNU Octave\Octave-6.4.0\octave.vbs"
Finaly, after adding all to path I run it like this:
"C:\Program Files\GNU Octave\Octave-6.4.0\mingw64\bin\octave-cli-6.4.0.exe" "C:\MatlabScripts\matlabScript1.m" c:\temp\myCuteImage [example for prm]

Powershell ISE + vim

Is it possible to make Powershell ISE behave like vim with some vim-like editing mode or plugin?
In netbeans I'm using jVi, and in Visual Studio I'm using VsVim, is there something similar for PowerShell ISE?
Or should I drop Powershell ISE altogether and just use vim + powershell command line?
I may be misunderstanding the question, but the closest I've come to getting vim-like ability while using PS ISE is to install gvim74 for Windows, and create this function:
function vim
{
if ($args)
{
start-process 'C:\Program Files (x86)\Vim\vim74\vim.exe' $args
}
else
{
start-process 'C:\Program Files (x86)\Vim\vim74\vim.exe'
}
}
Unfortunately, ISE does not play nicely with console input, so the best I can get is starting vi in a new PS window. Not perfect, but I get my ability to "vim fileToEdit", which I do A LOT in non-Windows world.
The last weaks i searched for a way to use psISE in combination with vim (i found out its possible but hard for me to code without the ISE-comfort)
In the end i created a function/submenu in the ISE that:
With a keyboard-shortcut ([AltGr]+[v]) starts vim with the current file and waits for the process to end
When I'm finished editing in vim and saved the file its removed from the ISE
And loaded again (bacause in v3 there is no file "refreshing")
# one-line
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("edit with Vim",{$cur=$psISE.CurrentFile; saps "C:\Program Files (x86)\vim\vim74\gvim.exe" $cur.FullPath -wait; $psise.currentpowershelltab.files.remove($cur); $psISE.currentpowershelltab.files.add($cur.fullpath) },'Ctrl+Alt+v')
You have to save it first or it will not be removed
(maybe you add the $psise.CurrentFile.Save()-function)
(for permanent ISE-changes you have to put it into the $profile...)
*saps --> start-process alias
The best thing I've found is VSCode with the PowerShell and VIM plugin installed. The Powershell plugin used to be a lot worse than ISE, but recently the Intellisense has gotten much cleaner.

interactive powershell from Cygwin

I cannot run PowerShell.exe interactively in a Cygwin rxvt or mintty terminal. Seems any session using a /dev/tty? or /dev/pts? pseudo terminal device. An instance using the junky windows console device /dev/console or /dev/cons? will work.
cygstart /bin/bash -li
launches the console version in the cruddy Windows Command Prompt which is the only place I can get an interactive PowerShell.
Works. Rxvt doesnt:
Nor does mintty:
I've tried all the echo -e | powershell.exe and powershell.exe </dev/null
I'm assuming when I see answers on Stackoverflow on this they are using Console's ... or am I missing something?
Why I cannot run PowerShell 2 from Cygwin? seems to run fine, just gets powershell v3 when he wants v2 ... wish I had that problem.
I've developed a powershell wrapper to call powershell scripts and commands from a Cygwin terminal session but cannot get the interactive option to work (if you give the wrapper no script or commands then you want to go interactive). see https://bitbucket.org/jbianchi/powershell/wiki/ for info on the wrapper script. It works for most powershell.exe calls and even acts like a "she-bang" if used in the first line of the ps1 script.
Today, typing powershell at a Cygwin bash prompt just works.
If you need to run powershell inside cygwin/babun, follow https://code.google.com/p/mintty/issues/detail?id=56#c64 . Bascilly, downloard or compile https://github.com/rprichard/winpty, copy it to your $PATH and then run
console.exe powershell
This also works with batch scripts that invoke powershell inside.
The solution I've found is to use http://sergeybelous.com/ (main site) Proxy32 proxywinconsole.exe program. If this program is in the path, my poweshell.bash wrapper will call it which will let you work interactively with PowerShell.
First Install cygwin in your system.
After that type bash on powershell terminal and you can access cygwin terminal.
PS C:\Users\username\1and1> bash
username#LWMT-14R25Q2:/mnt/c/Users/username/1and1$
I'm afraid I can't answer your question, but maybe I can help you a little further on your way with this:
I believe this is related to this issue, as discussed on the MinTTY Issue #56.
It goes into great detail as to how common cmd.exe shell applications work and interact, so much as they detail how common unix applications using their TTY abstraction layer work differently than Windows command line applications.
Script for running powershell on Cygwin minty:
blahblah#blahblahbin $ cat pwrshl
#!/usr/bin/bash if [[ ! -f "$1" ]] then
echo "Usage: $0 <PowerShellScriptFile>"
exit fi
echo "\n" | powershell -Command "& {$(<$1)}"