RVM showing Ruby version in ZSH - zsh

I just installed rvm to upgrade ruby using the method outlined here. After installation my zsh instance now always displays rvm:ruby-2.3.0, as per this image:
I'd rather it not appear but I'm having trouble finding where it's set, any thoughts? It's pretty annoying.
Thanks!

If, like me, you ended up here because of this problem with the powerlevel10k theme, do the following:
Open ~/.p10k.zsh
Find the line:
rvm # ruby version from rvm (https://rvm.io)
Comment it out:
# rvm # ruby version from rvm (https://rvm.io)
Open a new terminal

Your prompt is set in a .zsh-theme file that is specified in your
.zshrc file in your home directory.
Changing to another theme:
If you want to change your prompt to a preexisting one, open your .zshrc file with your favorite text editor. Your can find your .zshrc in ~/.zshrc. When you open that file you will see a line that looks something like this: ZSH_THEME="gallois". (It looks like you're using gallois)
This is the line that you should change if you want to change your entire prompt. For example, change your this from ZSH_THEME="gallois" to ZSH_THEME="dallas" to change to the preexisting dallas theme. Click here For a list of all the default themes and what they look like. These themes are located in ~/.oh-my-zsh/themes.
You should then run . ~/.zshrc to source zsh and you will see the new prompt.
Editing the gallois theme to remove the right prompt
These themes are located in ~/.oh-my-zsh/themes. I would recommend copying the gallois.zsh-theme file and making some other file like yourname.zsh-theme. In the theme file you can remove the right prompt entirely by removing the line below this comment:
# Combine it all into a final right-side prompt
RPS1='$(git_custom_status)$(ruby_prompt_info) $EPS1'
You should probably remove this from the theme file as well for good measure:
# RVM component of prompt
ZSH_THEME_RVM_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RVM_PROMPT_SUFFIX="]%{$reset_color%}"
#Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
local cb=$(git_current_branch)
if [ -n "$cb" ]; then
echo "$(parse_git_dirty)%{$fg_bold[yellow]%}$(work_in_progress)%{$reset_color%}$ZSH_THEME_GIT_PROMPT_PREFIX$(git_current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
}
Keep in mind, this will also remove any descriptions about git repos from your prompt. You should then run . ~/.zshrc to source zsh and you will see the new prompt.
Editing the gallois theme to only remove the ruby prompt
These themes are located in ~/.oh-my-zsh/themes. I would recommend copying the gallois.zsh-theme file and making some other file like yourname.zsh-theme. In the theme file you can remove just the rvm prompt by removing a portion of this line:
# Combine it all into a final right-side prompt
RPS1='$(git_custom_status)$(ruby_prompt_info) $EPS1'
If you just remove the $(ruby_prompt_info) portion so that it looks like this:
# Combine it all into a final right-side prompt
RPS1='$(git_custom_status) $EPS1'
Then you can skip to the end and only remove the rvm portion of the prompt. I would also recommend removing these lines to avoid cluttering the theme file:
# RVM component of prompt
ZSH_THEME_RVM_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RVM_PROMPT_SUFFIX="]%{$reset_color%}"
You should then run . ~/.zshrc to source zsh and you will see the new prompt.

Another way to hide the ruby version information is to override the ruby_prompt_info() function used to determine what gets included in the prompt.
To do this, edit your ~/.zshrc and add the following after $HOME/.rvm/scripts/rvm has been sourced:
# hide ruby version from ps1
function ruby_prompt_info() { echo '' }

Related

don't show timestamp from each line in zsh shell

I have just installed zsh shel in my terminal.
But with every line I have a timestamp logged (see screenshot)
I want to get rid of the timestamp.
Can somebody please help me?
Many thanks
Switching to a different theme like "agnoster" can solve the issue you're experiencing.
To do that,
Open ZSH file (~/.zshrc) and set the theme to agnoster (ZSH_THEME="agnoster")
Close and quit the current session or save the change (source ~/.zshrc)
I suppose you use Powerlevel theme then
Open zsh config file (~/.zshrc) and set the theme to powerlevel
i.e.
(ZSH_THEME="powerlevel10k/powerlevel10k"
")
And
Add this line at the bottom of the .zshrc file --
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()

How to open specific file from atom?

How do i open a specific file from atom. I have in laravel master.blade.php and I want to put shortcut CTRL-1 for example and open it.I use now advanced-open-file but I want something faster because I all the time name some files the same. Is there a plugin for that ?
1. Add command
Add the following to your init.coffee (File > Init Script…)
atom.commands.add 'atom-text-editor',
'open:master-blade': (event) ->
atom.workspace.open('path/to/master.blade.php')
See available options for atom.workspace.open
2. Add shortcut
Now add the following to keymap.cson (File > Keymap…)
'.editor:not(.mini)':
'ctrl+1': 'open:master-blade'
Note: You can use Atom's built-in keybinding-resolver to make sure the shortcut isn't used by one of your installed packages.
It is very simple. In Ubuntu you can do this things following below steps...
Open the terminal.
Go to the folder of your project.
Enter command atom ./<path_of_the_file>
If you want to open whole project then enter atom .
Atom will open that file.

Atom/Sublime like Multiple selections in Jupyter

How can I select matching keywords in a Jupyter notebook via a keyboard shortcut? For example, in the Atom/Sublime editor I can hit cmd + D on a mac (or Ctrl + d on Windows) while the cursor is over 'var' and each time I do that the next 'var' will be highlighted. I can then type the new variable name and 'var' is replaced with whatever I typed.
var = "hello"
print(var)
print(var)
Is there an equivalent in a Jupyter notebook?
Add custom.js to
C:\Users\username\.jupyter\custom # for Windows and
~/.jupyter/custom/ # for Mac
with content
require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
function(sublime_keymap, cell, IPython) {
cell.Cell.options_default.cm_config.keyMap = 'sublime';
cell.Cell.options_default.cm_config.extraKeys["Ctrl-Enter"] = function(cm) {}
var cells = IPython.notebook.get_cells();
for(var cl=0; cl< cells.length ; cl++){
cells[cl].code_mirror.setOption('keyMap', 'sublime');
cells[cl].code_mirror.setOption("extraKeys", {
"Ctrl-Enter": function(cm) {}
});
}
}
);
and restart jupyter. Now Ctrl+D should work like it does in Sublime.
You can see that Ctrl-Enter functionality is disabled as it would be very convenient to run current cell rather than creating new line for most users. You can choose to have that functionality by commenting that line out.
You can disable other key config that you don't want in a similar way.
Most recent (and easy) way
The best way right now to achieve Sublime-like keymapping in Jupyter Notebook: Select CodeMirror Keymap from jupyter-contrib-nbextensions. As reported in the homepage:
The jupyter_contrib_nbextensions package contains a collection of community-contributed unofficial extensions that add functionality to the Jupyter notebook.
I personally use several extensions from this package and I find them very useful.
As reported in the installation docs, you simply need to run:
pip install jupyter_contrib_nbextensions
to install the extensions (or better, I would suggest:
python -m pip install jupyter_contrib_nbextensions
where python points to the python executable of the installation you are using within Jupyter Notebook). You can also use conda if you prefer.
Anyway, you then need to copy some JS and CSS stuff to make the extensions work within Jupyter Notebook, which you can achieve through:
jupyter contrib nbextension install --user
again, assuming that jupyter points to the jupyter executable you are using to run your notebooks.
At this point, you simply need to enable the extension: navigate the nbextensions_configurator (that comes as a dependency with the jupyter_contrib_nbextensions package), which you can easily do through the Jupyter Notebook dashboard (to be clear, the page you open to run your notebooks) by browsing the Nbextensions tab and check the box corresponding to Select CodeMirror Keymap.
Done! Launching a notebook it will be sufficient to click on Edit>Keymaps>Sublime to achieve the desired behaviour.
I know this is a rather old question, but I happened to come across it before finding out about jupyter_contrib_nbextensions (and in particular the Select CodeMirror Keymap extension). Thus, I decided to post this answer, hopefully to help other people like me and to let them avoid some further search or messing up with customized JS files (which could scary someone).
In jupyter lab now you can add in the extension by searching sublime
Click install and rebuild jupyter.
**Notice: when you click install look at the terminal console, the building result will be shown there
The above solution worked for me, but I found that it had the undesirable effect of entering a "tab" character when I hit enter. Here is the associated GitHub issue: https://github.com/jupyter/notebook/issues/4769#issuecomment-511935127
Per that post, I found that this solution gives the right ctrl + d behavior, and keeps tabs-as-spaces.
require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
function(sublime_keymap, cell, IPython) {
// setTimeout(function(){ // uncomment line to fake race-condition
cell.Cell.options_default.cm_config.keyMap = 'sublime';
var cells = IPython.notebook.get_cells();
for(var c=0; c< cells.length ; c++){
cells[c].code_mirror.setOption('keyMap', 'sublime');
}
// }, 1000)// uncomment line to fake race condition
}
);
In Jupyter Lab, this can now be set in Settings > Text Editor Key Map > Sublime Text.
The only solution which made this work for me is
pip install jupyterlab_sublime

R animation error: how to install ImageMagick?

I intend to run some R Animation demo code but this error message returns
Warning messages:
1: In im.convert(img.files, output = movie.name, convert = convert, :
Please install ImageMagick first or put its bin path into the system PATH variable
I've downloaded ImageMagic for mac. It's a folder with subfolders like bin, lib, share etc. How can put its bin path into system path? Thanks.
Option 1:
Put something like
PATH=$PATH:blablabla/ImageMagic/bin
in ~/.bashrc file.
$PATH is the original PATH variable;
: is used to separate different candidates;
the final blablabla/ImageMagic/bin denotes the path to the executable.
Whenever you open up a new terminal, ~/.bashrc file will be run, hence environmental variable PATH will be set as above. If you start up your R from terminal, this should do the work.
Option 2:
If you normally invoke R by clicking its icon, then ~/.bashrc may not work. In this case, use the ~/.profile file instead. This is run whenever you log in. Add the following to the bottom of this file:
export PATH=$PATH:blablabla/ImageMagic/bin
(Note export here. You may need to log out and log in again so that the setting takes effect.)
Comments
Both ~/.bashrc and ~/.profile are hidden files. You may use ls -a ~ to see them. To edit/save them, use the normal text editor.
The link #Gregor gives, suggests using ~/.bash_profile. Well, These days this file is normally replaced by ~/.profile. But you should use ls -a ~ to check.
follow up:
OK, so you have .bash_profile instead of .profile on your machine.
To open this file, do:
sudo nano ~/.bash_profile
Then move to the bottom, and add the line you need:
export PATH=$PATH:blablabla/ImageMagic/bin
To save edit, do ctrl + O (maybe hitting an ENTER as well); then you quit editor by ctrl + X.
If you do not want to log out and log in again to let new setting take effect, try:
source ~/.bash_profile
I had the same problem with Windows a few weeks ago. I don't know if it is the same on Mac or not, but it is worth a try.
When you go to download ImageMagick there should be a prompt that says something like "select additional tasks." Be sure to check "Install Legacy Utilities (e.g. convert)." I think they changed the names of a few things between versions. That selection names things properly for R. Also, if this happens to be the same issue I had (maybe, maybe not) be sure to restart R before trying again after you've downloaded it.

How can I load my .RProfile using Textmate's R Bundle

This question is for those of you who happen to use R, on a Mac, in combination with Macromate's [Textmate](http://macromates.com/) text editor and the "R" Bundle. All of which are nifty, needless to say, but that's beside the point for now :-)
I've got a .RProfile file sitting in my default "~" startup directory, and it's got a number of useful functions in it I like to have access to when writing R scripts. But I also use Textmate for most of my writing, and the cmd-R functionality to to run my scripts within Textmate.
At the moment, I don't know how to tell Textmate where my .Rprofile is.
Is there a way--most likely through Textmate's Bundle settings--that I can point Textmate to my .RProfile so I don't have to write my functions into every script on a per-script basis?
OR
Is it actually better to include any custom functions in any script I write, so that anyone with a basic R setup can source and run my scripts?
I feel like I must be missing a dead-easy setting or config file here within either Textmate or the R environment it calls to run my scripts.
Thanks so much in advance!
The R Bundle Developer is apparently working on this (see this Post on the Mailing List) but it's not available at the moment.
In the meantime, you have a couple of choices.
First, you can create a new bundle (e..g, "briandk-R") then create a snippet w/in that bundle either with 'source($1)' or just hardcode the file you want to source instead of the placeholder (so, e.g., "source("~/some_file_to_source.R"). If you do the latter, then you can configure TM to source your file via a tab trigger (in the Bundle Editor, toggle over to 'settings' (upper left hand corner) and type "source.r, source.rd.console" in the 'Scope Selector' field then choose a few letters for your tab trigger (e.g., "src.")
If you don't want to do that, go to the 'Rdaemon' Directory (which is either in your home directory or in ~/Library/Application Support/Rdaemon). Look in this directory and you will see another directory called "daemon.' In there is a file called "start.r" which lists the files that are sourced upon starting R from the Rdaemon. You know what to do from there. (Note: This directory also contains a couple of other scripts which contain initial settings; you might wish to have a look at those as well)
The first part of Doug's response offers the simplest immediate solution... add
source('/Users/briandk/.Rprofile')
to the head of any .r files you want those functions in... with that one line of code, you get your utility functions. Of course, that only helps if you're running the whole TM file.
Ideally, the bundle will be updated... perhaps to support a shell variable via TM's preferences???
TM_RPROFILE
which could be set to the path to your .Rprofile file.
I just hacked this into tmR.rb with just 2 lines of code. To implement this, go to ~/Library/Application Support/TextMate/Pristine Copy/Bundles/ and Show the Contents of R.tmbundle
In there, you'll find support/tmR.rb
in my version, near line 112, you should change
tmpDir = File.join(ENV['TMP'] || "/tmp", "TM_R")
recursive_delete(tmpDir) if File.exists?(tmpDir) # remove the temp dir if it's already there
Dir::mkdir(tmpDir)
# Mechanism for dynamic reading
# stdin, stdout, stderr = popen3("R", "--vanilla", "--no-readline", "--slave", "--encoding=UTF-8")
stdin, stdout, stderr, pid = my_popen3("R --vanilla --slave --encoding=UTF-8 2>&1")
# init the R slave
stdin.puts(%{options(device="pdf")})
stdin.puts(%{options(repos="#{cran}")})
to
tmpDir = File.join(ENV['TMP'] || "/tmp", "TM_R")
recursive_delete(tmpDir) if File.exists?(tmpDir) # remove the temp dir if it's already there
Dir::mkdir(tmpDir)
rprofile = (ENV['TM_RPROFILE'] == nil) ? "" : "source('" + ENV['TM_RPROFILE'] + "')"
# Mechanism for dynamic reading
# stdin, stdout, stderr = popen3("R", "--vanilla", "--no-readline", "--slave", "--encoding=UTF-8")
stdin, stdout, stderr, pid = my_popen3("R --vanilla --slave --encoding=UTF-8 2>&1")
# init the R slave
stdin.puts("#{rprofile}")
stdin.puts(%{options(device="pdf")})
stdin.puts(%{options(repos="#{cran}")})
Just added 2 lines there... the one that begins "rprofile =" and the one that includes "#{rprofile}"
-Wil

Resources