PowerShell equivalent of RPROMPT - powershell

I'm working on a PowerShell profile template that mimics the lambda mod for zsh as close as possible as a proof-of-concept.
I was able to get the lambda, the user colored if root and the home-abbreviated path right. The git part can be done using posh-git, but the repo hash displayed in the mod is right aligned in the prompt line.
Zash/Bash does this through a RPROMPT variable and I haven't found similar functionality in PowerShell. Does it really not exist? Is it possible to implement it?
If I were to implement how'd it go about? It seems to me it's impossible to reliably align something right on PS without the Shell size (and therefore breaking at resize). Also, I wouldn't know how to have the cursor still on the line that RPROMPT was written.

Related

Clear part of an IPython cell's output

Before I get reamed for this, I know there are some posts detailing how to clear ALL the output from a cell, but I'm interested in only clearing part of it.
Let me provide some background. I am creating a word-guessing game like LINGO where the user is prompted to guess a five-letter word, then using CSS to provide some visual feedback as to which letters are in the correct position, and which letters are in the word but in the wrong position. The way my program is structured, it displays the feedback after each guess and then prompts the user again and displays the guess. So something like this:
Guess a word: word
FEEDBACK
guess again: word
FEEDBACK
...
You get the picture. My goal is to come as close to duplicating LINGO as possible, which would mean removing the user input from the screen after it has been submitted and having it show a sequence of feedback. This to me means one of three things:
1) Find a way to clear part of the output
2) Find a way to prompt the user for text input without displaying it on the screen
3) Cache the user input, delete the all the output after each iteration, and display the cached guesses.
I've researched 1 and 2 and haven't been able to find anything. 3 would be a PITA so before I went to the trouble I thought I would ask.
1 think is either not possible or very difficult - it's hard in regular python, never mind Jupyter. In regular python, you'd probably use something like curses but I tried it in Jupyter and it affects the console Jupyter is running from - not the stdout in the notebook.
If you really wanted 2, you could probably write your own version of input that uses carriage return \r after stripping the trailing newline via writing a function that loops listening for keystrokes and submitting once a newline is pressed. The carriage return should mean that the next line overwrites the previous line.
3 Caching the input shouldn't be too difficult though I presume? Just store them in an array or something then you can display them back to the user after using IPython.display.clear_output.

How to get powershell to read and interpret VS2013 variables (macros)?

I was looking at some of the macros in VS2013 and noticed that some use what look to be something like powershell syntax calls inside of the registry (less the macros $(VCTargetsPath) and $(MSBuildExtensionsPath32)).
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0\12.0
VCTargetsPath REG_SZ $([MSBuild]::ValueOrDefault('$(VCTargetsPath)','$(MSBuildExtensionsPath32)\Microsoft.Cpp\v4.0\V120\'))
I tried to execute it, but powershell doesn't seem to understand the type [MSBuild].
How can I interpret this easily, without parsing and translating what it seems to be obviously doing?
NOTE
My goal is to parse a .vcxproj file and extract information from it. This requires that I evaluate the Condition tag attributes, which in turn require that I expand and evaluate them. If I'm going down the wrong path and you know something about how to do this, then please point me in the right direction.

Eclipse Auto-Correct?

Is there a way to have Eclipse auto-correct certain misspellings? For example, I tend to type "System" as "Sysetm", and Eclipse catches it. However, it only tells me it's an invalid package, and I have to manually correct it. I'm hoping there's a way like in Microsoft Word, where you can add words to be auto-corrected.
Trust me you don't want something like that. It would make it almost impossible to write code with it changing what it thinks you want a variable called. Also its use would be very limited.
I have a hard enough time trying to convince word I mean colour and not color.
try to use "alt+/" after input 'sys'

How to performe like shell to show the lastest input when press up key

I wrote a small program to read input, and print the result, and loop. Like REPL.
And I want to get the input I have inputed before when I press the up key on the keyboard and edit this input, like what bash or zsh does. I have no idea about the implementation. I also searched the web but no result I want. Could someone point a way for me? Or give me some articles to read?
The point is: How to print an EDITABLE line on screen?
I have no personal experience with it, but it's my understanding that Term::ReadLine provides command editing functionality with history. It's even part of the perl distribution.
You just need to:
Store a history of user input, just like bash and zsh do;
Listen for ↑ key presses, just like bash and zsh do;
Display the last command when ↑ is pressed. Just like, you guessed it, bash and zsh.
This is what programming is all about: breaking down big problems we don't know how to solve into smaller problems that we do know how to solve, or can more-easily figure out how to solve. So if you don't know how to do any of the things I listed above, try writing some code, reading API documentation, looking for answers on Google/Stack Overflow, or – once again – breaking them down into sub-problems.
if your point is "print" maybe you need Term::Screen. example code here: code.
otherwise if your point is "history", man/perldoc Term::ReadLine.

Can I change the prompt in MATLAB?

I never work with the GUI and am always inside a terminal (also full screen, so no title bar) set with the -nodesktop -nodisplay option. I also have different servers that I connect to, to run matlab and each of those have different restrictions on hogging computational resources. Since it's hard to remember which server I'm in,especially if I have multiple sessions open, I was wondering if I could change the prompt to display the server name. Try as I might, I couldn't find a resource that explains how to go about it (I'm beginning to think Mathworks doesn't support it). I know, a workaround would be to simply write a function call to system('hostname') and put the function in the path, so that it's about as easy as typing pwd to find the directory. I'd like to know if there's something more elegant.
There is a submission on the MathWorks File Exchange that can do this for you: setPrompt by Yair Altman. Using it in R2010b, I noticed that I was getting the warning message:
Warning: Possible deprecated use of set on a Java callback.
> In setPrompt at 115
Which I was able to suppress using the warning function like so:
warning('off','MATLAB:hg:JavaSetHGProperty');
And here's how I changed the prompt to the host name using the system function:
>> [~,systemString] = system('hostname');
>> setPrompt([deblank(systemString) '>> ']);
P11-4504>>
The function deblank is used to remove trailing whitespace (in this case a newline) from the string.
NOTE: The above changes (suppressed warning and modified prompt) don't persist after you quit and restart MATLAB, so you could put the above code in your startup.m file to apply them automatically every time you start a new session.