ZSH `rvm-prompt` on RHS prompt not refreshing - ruby-on-rails

I have rvm-prompt feeding into my RPrompt, however it is not refreshing between commands: (Larger image)
For example, when I cd from one ruby project to another with an .rvmrc file pointing to a new gemset, the rprompt simply will not refresh. It appears that it must be caching the rprompt for performance purposes, so I am curious as to how I can force a refresh for zsh at each command?

How do you generate the prompt? I do it like this:
local rvm_ruby=' %{$fg[red]%}[$(~/.rvm/bin/rvm-prompt i v g s)]%{$reset_color%}'
And then use the rvm_ruby variable in my prompt:
PROMPT="${user_host}${directory}${git_branch}${rvm_ruby}%B
→%b "
EDIT: Note that the place where you create the contents for the variable needs single quotes, otherwise the command will get substituted right away and not updated anymore. This initially took me a bit to figure out. You may have the same problem defining your RHS prompt.

Related

How do I update my zsh prompt when an env variable changes?

I'm using oh-my-zsh. My theme file looks like this:
PROMPT="${AWS_PROFILE}%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
It's based on a popular theme. The only thing I have added is ${AWS_PROFILE}.
The prompt does show my AWS profile as intended. But even if I the environment variable changes the prompt doesn't change. This is not as I had intended. It does change if I run source ~/.zshrc.
Can I make the prompt update when my env variable changes?
Copying #chepner's comment into an answer:
AWS_PROFILE is expanded immediately when you define PROMPT, since you used double quotes. Use single quotes, or consider using a precmd hook to set the value of PROMPT.

In Fish, how do you tweak things around to match special key bindings?

Context
So I finally give a try to Fish, and as one would expect I encounter some frictions due to differences with my usual routines.
The most astonishing for me, as for many other, was the absence of the bang operator. I'm fine with the lose of sudo !!, as the suggested function replacement seems even better to me, I named it gar which means "To make, compel (someone to do something); to cause (something to be done." However I'll need a replacement for !<abc><enter> which grab the last history line starting with <abc> and run it without further ado, suggestions are welcome.
Now, for the more personal things:
- I use a Typematrix 2030 keyboard
- I use a bépo layout
- I like to configure default finger position keys with the most used actions
Aims
As on my keybord <enter> is well positioned and is semantically relevant for that, ideally I would like to achieve the following key binding:
ctrl-enter: accept the whole suggestion and run it without further confirmation
ctrl-tab: accept the whole suggestion and wait for further edit
alt-enter: redo the last command without further confirmation
But according to xev it appears that, at least with Gnome-terminal, this combinations are not recognized. Are they terminal that supports it? For now I remapped these three to <ctrl>-i, <alt>-i and <alt>-I respectively:
bind --preset \ci forward-char execute
bind --preset \ei forward-char
bind --preset \eI forward-word
This works as expected, but it seems that now the tab key will also map to the first item. I guess that tab map to <alt>-i at some point in the shell stack. I wasn't aware of that, so I don't know yet if it will be possible for Fish to separate each of them.
To manage jobs, I also came with
bind --preset \es fg
bind --preset \eS bg
The first works as expected, but the second one doesn't. With application like vim, the binding should be operated in the application configuration itself of course. But for things as trivial as yes, <alt>-S won't work as expected while <crl>-z continue to operate normally.
I also would like to bind some commands like ls -alh and git status --short to a directly executed command, showing the result bellow the currently edited line, allowing to further type seamlessly, but didn't find the way to do it yet.
Summary of remaining question
So here are my more precise questions summarised:
how do I bind the sleep signal to <alt>-S?
is there a terminal I can use where <alt>-<enter> and <ctrl>-<enter> works?
how to seamlessly run command while maintaining the current line edition in place?
can you bind something to <alt>-i without altering <tab>?
how do I bind the sleep signal to -S?
What you are doing with bind \es fg is to alter a binding inside the shell.
But when you execute yes, the shell isn't currently in the foreground, so shell bindings don't apply.
What you'd have to do instead is change the terminal settings via stty susp \cs,
but fish resets the terminal settings when executing commands (so you can't accidentally break them and end up in an unusable environment), so there currently is no way to do this in fish.
can you bind something to <alt>-i without altering <tab>?
Sure. You bind \ei. Which is escape+i, which is alt-i (because in a terminal alt is escape).
Your problem is with ctrl-i, which in the way terminals encode control+character is tab. The application receives an actual tab character, and at that point the information has been lost.
is there a terminal I can use where - and - works?
Most terminals should send \e\r for alt-enter. ctrl-enter again is unencodable with the usual code (because \r is ctrl-m), just like ctrl-tab is.
Any fix to this requires the terminal to encode these combination differently.
how to seamlessly run command while maintaining the current line edition in place?
I don't know what you mean by this. I'm guessing you want fish to remain open and editable while a command also runs in the foreground. That can't work. There's no way to synchronize output from two commands to a terminal, not with cursor movement being what it is.

CLI - Ignore a line when using the for command

I'm trying to set a variable which will identify the make of a laptop.
I am doing this by using the command
wmic csproduct get vendor
This gives the following output
Vendor
LENOVO
(blank)
So based on that command, I have used the for command in the way below, to try and set a variable with the value 'LENOVO'
for /f "skip=1 tokens=1 delims=" %i in ('wmic csproduct get vendor')
do set vendor=%i
however, problem is that the output of the wmic command actually produces a blank line, under the word LENOVO, so my variable gets set as a blank value. Is there anyway to stop the for command from parsing this 3rd line, therefore stopping once the variable has been set with the value of 'lenovo'?
The skip function works fine, and bypasses the first line completely. However it doesn't seem to give me the option to say for example, skip lines 1 and 3 but leave 2. I have experimented with the EOL parameter to try and ignore the blank line, but the for command still reads the empty 3rd line each time.
Many Thanks
A little whacky, but try using the following within your line. It will filter out the Vendor line and then sort alphabetically, putting the blank line first. If you really need to do stuff like this regularly, check into a Windows port of some Unix utils like sed and awk.
wmic csproduct get vendor | find /v /i "vendor" | sort

Temporary Environment Variables in Ruby

Try to bear with me as I am fairly new to this and don't have much coding experience.
Im trying to use a ruby script to add a location to my PATH variable. So far I just have
path = ENV['PATH'].to_s
ENV['PATH'] = path + ";" + location
print ENV['PATH']
The problem is that the file seems to be added to the PATH and prints with it, but when I go check my path variable the new location is not there.
Also, when I run a separate script of which is one line:
print ENV['PATH']
the new location is not there either.
My question is is there a way to make the new PATH "save" instead of reverting to the old PATH when the script is finished?
If i am not mistaken you cannot really edit the environment variables.
When loading your script ruby loads all the currently known environment variables and adds the values to ENV.
When editing it, it will only be changed temporarily for the current execution.
If you want to change it and want it to persist you will have to e.g. use system
system("export PATH=$PATH:YOUR_PATH")
Same as you would do it in the CLI
The best you can do is generate a shell command to be evaluated outside the Ruby script and inside the shell you are running.
Something like this should work:
puts "export PATH=#{ENV['PATH']};#{location}"
Then, in the shell you do
eval $(ruby_script)
However, since you seem to want to run this in Windows you probably want to use command substitution, in which case you output the location directly:
puts location
And in the Windows shell:
set PATH=%PATH%;(ruby_script)
colon ":" is the field separator for PATH not semicolon ";" in Unix. Your example worked just fine for me today when I changed the semicolon to a colon.

ipython: pressing 'esc' key breaks readline

In ipython, if I press 'esc' followed by 'enter' (and possibly other characters?), readline breaks. I can no longer search through command history using the 'up' key, and some commands (e.g., control-K) fail.
Is there a way to reset readline within an ipython session? What is going on when I press these keys?
The poster's suggested answer doesn't seem to work for me in iPython 0.12+. I can run:
get_ipython().init_readline()
but that doesn't seem to help.
However I noticed that I sometimes see similar problems in my iPython sessions. It appears that I had inadvertently switched from the default Emacs readline editing mode to vi-mode(vim-mode). According to the the readline docs to switch between them you are supposed to be able to use the M-C-j key combination but that only seems to allow me to switch to vi-mode. To switch back to Emacs mode one can use C-e but that didn't appear to work for me - I had to instead do M-C-e - on my Mac (where ESC is used as the 'Meta' key) it is: ESC+CTRL+e
The contents of my ~/.inputrc is as follows:
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
Got impatient. Solution is:
IPython.InteractiveShell.init_readline(get_ipython())
Looks like this might be a known bug too: http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/

Resources