Change oh-my-zsh theme when ssh is run - terminal

I have Oh-my-zsh installed on iterm2. How can I make my terminal change theme whenever ssh is run? It would be nice if the script also changes the background to one of the presets imported.
I am a complete bash noob. Please explain in newbie language.

The first thing you need to know is that .zshrc is a script that is run just before you open a new session on zsh. So, providing that zsh is your default shell, when you open a terminal on your local machine, it runs .zshrc. When you open a ssh session to that machine, it runs .zshrc too!
Inside .zshrc you can find that piece of code commented:
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
You can use this example to achieve your goal, just this way:
if [[ -n $SSH_CONNECTION ]]; then
ZSH_THEME="robbyrussell"
else
ZSH_THEME="agnoster"
fi
Where robbyrussell will be used on your ssh sessions, and agnoster for the rest. So just substitute the line where you set your theme for the if/else statement above, and customize it

You could prepend the host name to your prompt.
Following this gist
Just paste the contents of this file on:
~/.oh-my-zsh/themes/robbyrussell.zsh-theme
Then basically on your local machine:
And on you remote machine:
In my case, ded12 is the hostname of my remote and I only changed the theme files on my remote, if I changed it locally it would have my local hostname also prepending the prompt

Related

Terminal prompt on new Mac is not the same as on my existing Mac

MacOS Ventura 13.1
M2 Silicon
Trying to set up a new mac. On my existing Mac, I have a .zshrc, and in it, I have the following:
## begin Git branch prompt
git_branch_test_color() {
local ref=$(git symbolic-ref --short HEAD 2> /dev/null)
if [ -n "${ref}" ]; then
if [ -n "$(git status --porcelain)" ]; then
local gitstatuscolor='%F{red}'
else
local gitstatuscolor='%F{green}'
fi
echo "${gitstatuscolor} (${ref})"
else
echo ""
fi
}
setopt PROMPT_SUBST
PROMPT='%/ $(git_branch_test_color)%F{none} $ '
# add 24h time the right side
RPROMPT='%D{%m-%d-%Y %k:%M:%S}'
## end Git branch prompt
And I would get something like:
/Users/jmac/Development/repos/p1 (development) $ 02-16-2023 19:20:56
(development) is in red, because I have not checked in my changes and the full path is there for me to see.
On the new Mac, there is no .zshrc by default, so I added the code to the .zprofile file, and it's not working the same. I see the date/time on the right, but I don't see the full path and the prompt looks like this:
/Users/jmac p1 % 02-16-2023 19:20:56
Any ideas? prompt modification is not my forte.
The short answer: create a ~/.zshrc file and move that code into it.
The slightly longer answer: something is overriding the value in the PROMPT variable. There isn't anything in the default zsh installation that'll turn the $ in your prompt into a %.
That 'something' could be in a few different forms. There may be code that is modifying the PS1 variable, which is essentially a synonym for PROMPT. Or there may be something hidden in scripts or functions called from ~/.zprofile (for example, oh-my-zsh does this, albeit usually from ~/.zshrc).
Some options
Try to trace what's happening in the zprofile file. One way to do that is to run these commands:
setopt xtrace
. ~/.zprofile
The main challenge here is often the sheer volume of the output; it may be difficult to find the spot where the prompt is being set.
Move the PROMPT assignment to the bottom of ~/.zprofile. Then your assignment should override whatever is setting the value earlier in the process.
Move the PROMPT assignment into ~/.zshrc. This is a better place for the assignment anyway, since .zshrc is only loaded for interactive shells, and setting the prompt is only used in interactive shells.
The code in ~/.zshrc is loaded after the code in ~/.zprofile, so this has a similar effect to the prior option.
If none of these options have any effect, then you'll need to look for other startup files, e.g. ~/.zlogin. There's a nice overview of how the various dot files are handled in zsh in this answer.

virtualenv name not show in zsh prompt

Recently, I give a try on oh my zsh, everything looks good till I try virtualevn and virtualenvwrapper. When I activate a virtualenv (e.g test), on normal bash, I will see the virtualenv name like:
(test)abc#abc:
But when I switched to zsh, I cannot see virtualenv name. Even though, I alr add virtualenv and virtualenvwrapper in plugins of oh my zsh. I also checked the activate file of my virtualenv, it contains:
f [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
_OLD_VIRTUAL_PS1="$PS1"
if [ "x" != x ] ; then
PS1="$PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`) $PS1"
fi
export PS1
fi
Is it because the comparision ["x" != x] return true?
Updated:
I tried to echo $PS1 in activate file, and got this:
(test) %{$fg[magenta]%}%n%{$reset_color%}%{$fg[cyan]%}#%{$reset_color%}%{$fg[yellow]%}%m%{$reset_color%}%{$fg[red]%}:%{$reset_color%}%{$fg[cyan]%}%0~%{$reset_color%}%{$fg[red]%}|%{$reset_color%}%{$fg[cyan]%}⇒%{$reset_color%}
It seems the $PS1 is correct, but when I echo $PS1 in the terminal, the (test) is gone. It seems the $PS1 is override by something else!
Do this in ~/.zshrc:
plugins=(virtualenv)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status virtualenv)
Caveats:
1 -- add that plugin in addition to other plugins you have.
2 -- I'm using the POWERLEVEL9K theme. Maybe you theme
The best solution is to add the following to the end of your ~/.zshrc file:
export VIRTUAL_ENV_DISABLE_PROMPT=
This will override the value in virtualenv.plugin.zsh - no need to change that file.
My setting to display Python virtualenv name for the default (a.k.a. robbyrussell) theme is the following.
In the .zshrc file
virtualenv added in plugins
Add custom function:
function virtualenv_info {
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') '
}
Navigate to your theme
My theme is the default theme for zsh:
$ vim ~/.oh-my-zsh/themes/robbyrussell.zsh-theme
Add this command right after existing PROMPT commands:
PROMPT+='%{$fg[green]%}$(virtualenv_info)%{$reset_color%}%'
Finally
$ source ~/.zshrc
PS: You can add your name or a few space before or after the PROMPT+.
Hope that helps!
Found the problem, it's due to the theme. The theme I used in the above case is pygmalion, it won't allow u to change $PS1.
After changed to robbyrussell theme, I can change $PS1 in terminal, but still cannot see the virtualenv name. After a while debugging, I found that by default the virtualenv plugin of oh my zsh disable the prompt:
# disables prompt mangling in virtual_env/bin/activate
export VIRTUAL_ENV_DISABLE_PROMPT=1
So just comment out the line in virtualenv plugin, problem solved.
As per this guide here
First add virtualenv dependency under plugin in file .zshrc
If this doesn't work for you, then it means that the theme(one of oh-my-zsh theme) you have selected doesn't include virtualenv name in bash prompt so try second step.
Go to file ~/.oh-my-zsh/themes/YOUR_THEME_NAME.zsh-theme and add this in base prompt
%{$fg[green]%}$(virtualenv_prompt_info)%{$reset_color%}%
NOTE: virtualenv_prompt_info is the name of function which is declared in ~/.oh-my-zsh/plugins/virtualenv/virtualenv.plugin.zsh. If your plugin file have different function name then change it accordingly.
Or you can declare your own function in ~/.zshrc file as shown in this guide
If you are using conda to start your virtual environment the envorionment variable will be different. To figure out the name of the environment that holds your virtaulenv name type printenv and look through the output. For me it is CONDA_PROMPT_MODIFIER
after you know the name of the variable open .zshrc and add this function
function virtualenv_info {
[ $CONDA_PROMPT_MODIFIER ] && echo `basename $CONDA_PROMPT_MODIFIER`
}
and below that add this line
PROMPT="%{$fg[green]%}$(virtualenv_info)%{$reset_color%}%${PROMPT}"
close the editor and type source .zshrc
In the case you installed Anaconda using Homebrew:
brew tap homebrew/cask-versions
brew cask install anaconda
And you are using POWERLEVEL9K theme
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
All you need to do is add this line to the end of .zshrc :
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time anaconda)
There's no need for virtualenv plugin.
Edited:
In case you already had conda installed for bash and you get:
zsh: command not found: conda
Run this:
~/anaconda3/bin/conda init zsh
I made it work following this link: https://askubuntu.com/a/387098
I reproduce the answer below.
How the prompt is changed is defined in the script bin/activate inside the virtual environment directory. This file is created by virtualenv from a template. Unfortunatelly, the only way of prompt modification provided by the template is prepending (env name) or whatever is set with --prompt.
To modify the prompt in the way you want, I'd suggest circumventing the setting of the prompt in bin/activate and modify the definition of PROMPT in your theme file.
First add the following to your.zsh-theme (or .zshrc)
export VIRTUAL_ENV_DISABLE_PROMPT=yes
function virtenv_indicator {
if [[ -z $VIRTUAL_ENV ]] then
psvar[1]=''
else
psvar[1]=${VIRTUAL_ENV##*/}
fi
}
add-zsh-hook precmd virtenv_indicator
and add %(1V.(%1v).) in front of the second line of the definition of PROMPT. It should then look like this:
PROMPT='
%(1V.(%1v).)%{$fg_bold[grey]%}[%{$reset_color%}%{$fg_bold[${host_color}]%}%n#%m%{$reset_color%}%{$fg_bold[grey]%}]%{$reset_color%} %{$fg_bold[blue]%}%10c%{$reset_color%} $(git_prompt_info) $(git_remote_status)
%{$fg_bold[cyan]%}❯%{$reset_color%} '
If you want some color you could add %(1V.%{$fs_bold[yellow]%}(%1v)%{$reset_color%}.) for example.
Explanation:
virtenv_indicator will be called each time before the prompt is created. It checks if $VIRTUAL_ENV is set and not empty. If so, it sets the first element of the $psvar array to $VIRTUAL_ENV with everything before and including the last / removed (like basename $VIRTUAL_ENV but less expensive)
In the definition of PROMPT %(1V.(%1v).) checks if the first element of $psvar is set and not empty (%(1V.true-text.false-text)) and adds the content of the this element plus some parentheses ((%1v))
export VIRTUAL_ENV_DISABLE_PROMPT=yes disables any prompt setting by bin/activate scripts.
if you use zsh and pyenv, put this into ~/.zshrc
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
#export PS1='($(pyenv version-name)) '$PS1
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export BASE_PROMPT=$PS1
function updatePrompt {
if [[ "$(pyenv version-name)" != "system" ]]; then
# the next line should be double quote; single quote would not work for me
export PS1="($(pyenv version-name)) "$BASE_PROMPT
else
export PS1=$BASE_PROMPT
fi
}
export PROMPT_COMMAND='updatePrompt'
precmd() { eval '$PROMPT_COMMAND' } # this line is necessary for zsh
I am also using Oh My Zsh with the pygmalion theme. I had to edit the pygmalion script to add the virtual environment name before the prompt name.
open ~/.oh-my-zsh/themes/pygmalion.zsh-theme, modify the prompt_pygmalion_precmd function as following:
prompt_pygmalion_precmd(){
setopt localoptions extendedglob
local gitinfo=$(git_prompt_info)
local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}}
local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
local prompt_length=${#exp_nocolor}
local python_venv="($(echo $CONDA_DEFAULT_ENV)) "
PROMPT="${python_venv}${base_prompt}${gitinfo}${post_prompt}"
}
The following steps should solve the problem:
open ~/.p10k.zsh.
If you use only the left prompt, make the following changes:
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
# =========================[ Line #1 ]=========================
os_icon # os identifier
dir # current directory
vcs # git status
# =========================[ Line #2 ]=========================
newline # \n
prompt_char # prompt symbol
virtualenv venv .venv env # show the venv on the second line
)
Add the following line, preferably after you adjust POWERLEVEL9K_VIRTUALENV_SHOW_WITH_PYENV:
typeset -g POWERLEVEL9K_VIRTUALENV_GENERIC_NAMES=()
Save the .p10k.zsh.
Restart the terminal.
Now, when you activate the virtual environment (on macOS source my_venv/bin/activate), then the name of the virtual environment (in my case, my_venv) and the version of Python installed on it (3.9.13) will appear after a beautiful Python symbol. Have a look at the attached screenshot.
I am using oh-my-zsh pygmalion them, and this works for me:
add virtualenv plugin in ~/.zshrc
open ~/.oh-my-zsh/themes/pygmalion.zsh-theme, modify the prompt_pygmalion_precmd function to this:
prompt_pygmalion_precmd(){
setopt localoptions extendedglob
local gitinfo=$(git_prompt_info)
local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}}
local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
local prompt_length=${#exp_nocolor}
local python_venv=$(virtualenv_prompt_info)
PROMPT="${python_venv}${base_prompt}${gitinfo}${post_prompt}"
}
Basically just add $(virtualenv_prompt_info) to your PROMPT to wherever you prefer, here I added it to the very beginning of my PROMPT.
You do not need to create new function, as per documentation - this function is created for you.
https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/virtualenv
But You still need to edit theme file, as mentioned above, just enter correct function name - virtualenv_prompt_info:
PROMPT+='%{$fg[green]%}$(virtualenv_prompt_info)%{$reset_color%}%'
After playing with the surround answers, I found the following to be the best for my use case. This checks the $VIRTUAL_ENV_PROMPT and $VIRTUAL_ENV variables every time you change directories and sets the prompt with the correct venv info.
DEFAULT_PROMPT=$PROMPT
function cd() {
builtin cd "$#"
if [[ -n "$VIRTUAL_ENV_PROMPT" ]] ; then
PROMPT="$VIRTUAL_ENV_PROMPT$DEFAULT_PROMPT"
elif [[ -n "$VIRTUAL_ENV" ]] ; then
PROMPT="(`basename $VIRTUAL_ENV`) $DEFAULT_PROMPT"
else
PROMPT=$DEFAULT_PROMPT
fi
}
export PS1='($(pyenv version-name)) '$PS1
source & link to issue #135 in pyenv-virtualenv repo:
https://github.com/pyenv/pyenv-virtualenv/issues/135#issuecomment-582180662
Back to 2023 : here something that worked for me with the theme .
Search the line for "plugins" and add virtualenv (if you are using this one)
plugins=(git python brew macos colored-man-pages virtualenv vscode)
Now look for the ZSH-Theme and use
ZSH_THEME="pygmalion-virtualenv"
Reload your terminal or kill your Visual Studio code window (reloading the terminal into VS cod didn't display the change for me...)

How do I configure git to inherit my specific $PATH environment variable?

My goal is to have a set of dot files shared between the many shell accounts I have so that I can have a similar environment in each one. Because of that, I don't want machine/environment specific information in my .git files or my .bash files.
On my MacOSX machine, the default emacs version is 22. I have installed a newer version of emacs (24) in /usr/local/bin. In my .bashrc file I set my default editor to emacs: export EDITOR=emacs. Before this, I also set up my path so that /usr/local/bin comes before /usr/bin so that the newer version of emacs gets selected.
When I use git to create commit messages, it always picks the one in /usr/bin instead of the one in /usr/local/bin. Git is ignoring my $PATH settings. I used to hardcode the location of the version of emacs I wanted in my .gitconfigure file, but that won't work when I use that same .gitconfigure file on my Ubuntu server. (If it's unclear, what I'm saying is that modifying my .gitconfigure editor option to point to a hardcoded won't work for me).
Why doesn't git respect my $PATH settings?
How do I configure git to use the correct emacs?
Edit: Adding more context
There is a suggestion to put environment variables in .profile/.bash_profile. Here's some relevant code from my .bashrc and my .bash_profile
.bashrc
Note: I wrote a bash function called vercomp which compares version numbers.
OS=''
case $OSTYPE in
darwin*) OS='Mac' ;;
linux*) OS='Linux' ;;
*) OS='UNKNOWN' ;;
esac
export EDITOR=emacs
if [[ $OS = 'Mac' ]]; then
### EMACS VERSION CHECK
# make sure that we're working with emacs >= 24
wanted_ver=24
curr_ver=`emacs --version | grep -oE '[[:digit:]]+\.[.[:digit:]]*'`
vercomp $curr_ver $wanted_ver
# If vercomp returns 2, then our current emacs version isn't good enough.
if [[ $? == 2 ]]; then
if [[ -e '/usr/local/bin/emacs' ]]; then
emacs_path='/usr/local/bin/emacs -nw'
elif [[ -e '/Applications/Emacs.app/Contents/MacOS/Emacs' ]]; then
emacs_path='/Applications/Emacs.app/Contents/MacOS/Emacs -nw'
else
echo -n "EMACS VERSION OUT OF DATE: $curr_emacs_version. "
echo 'Install a newer version.'
emacs_path=''
fi
export EDITOR="$emacs_path"
alias emacs="$emacs_path"
fi
fi
.bash_profile
source ~/.bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell
session *as a function*
LESS=-FRX;export LESS
I expect to have an answer that explains WHY MacOSX doesn't pick up my
bashrc/profile environment changes and a solution to HOW I can get
MacOSX to pick up those changes.
This is not specific to OS X - here is an example:
$ uname -a
Linux hostname 3.13.7-gentoo #1 SMP PREEMPT Mon Mar 24 18:40:46 CET 2014 i686 Intel(R) Atom(TM) CPU 330 # 1.60GHz GenuineIntel GNU/Linux
$ cat .bashrc
export EDITOR="emacs"
$ echo $EDITOR
/usr/bin/vim
$ mv .bashrc .bash_profile
$ logout
Connection to hostname closed.
$ ssh hostname
$ echo $EDITOR
emacs
For what I know and used to "live" is that environment variables are expected to reside inside /etc/profile (system wide) and can be extended and overwritten on a user level basis inside ~/.profile respectively ~/.bash_profile.
From man bash:
When bash is invoked as an interactive login shell, or as a
non-interac- tive shell with the --login option, it first reads
and executes commands from the file /etc/profile, if that file
exists. After reading that file, it looks for ~/.bash_profile,
~/.bash_login, and ~/.profile, in that order, and reads and
executes commands from the first one that exists and is readable.
On the other hand. .bashrc is the place to go where one places custom functions, aliases, prompt configuration, etc.
So a simple solution to your specific question - aside from using another git version in your special situation - would be to simply move your environmant variables from your .bashrc into a .bash_profile.
The Linux From Scratch project provides some pretty good examples about how to organize the bash shell startup files. Specific problems on OS X are tackled inside "Setting environment variables in OS X?".
Do not set variables in .bashrc. Bash only looks at this file in interactive sessions, so programs outside of an interactive session will never see any variables from .bashrc.
For bash, environment variables belong into ~/.profile!.
To fix your problem immediately, you may set $EDITOR to an absolute path:
if [[ -e /usr/local/bin/emacs ]]; then
export EMACS=/usr/local/bin/emacs
else
export EMACS=emacs
However, the issue points to a deeper problem in your environment setup, but your question currently lacks some information (see my comment).
Generally, $PATH and environment variables are a mess on OS X, because there's no single place to change them (for instance, profile variables do not propagate to the desktop and GUI applications), and because OS X itself meddles with $PATH by means of path_helper. You need to be extra careful about where you set variables, and you need use workarounds like exec-path-from-shell to have your environment variables available in GUI applications.
Any program is free to set PATH inside of itself to whatever it wants -- this tactic is often used in setuid programs to prevent execution of the wrong (or downright bad) executables.
You'll need to find out whether Emacs Terminal.app creates a Bash that runs ~/.bashrc, ~/.bash_profile, both, or something else entirely. (Sorry, I'm a vim user.)
Try this:
export VISUAL=emacs
I just tried export VISUAL=gedit from bash on my Ubuntu and now git uses gedit
when called from that terminal.

Set Default Shell in Cygwin

I've been using Cygwin for quite a while now. I now want to switch to fish from bash. Everyone is saying that you should use chsh -s /usr/bin/fish, but for some reason, chsh does not work for me. Trying to modify my Cygwin.bat file doesn't work either, and neither does changing my /etc/passwd file.
I really don't understand what's going on. Could someone please help me?
Try editing /etc/nsswitch.conf instead of /etc/passwd
Instead of creating a passwd file, which Cygwin recommends against1, you could edit /etc/nsswitch.conf. Add or edit the following line:
db_shell: /usr/bin/fish
The down/up side of this method is that, if you have multiple users, this change affects all of them. The up/up side is that it's dead simple. The only catch is that you have to restart Cygwin.
If you do use mkpasswd after this change, it will use your new default shell for all users that are allowed to log on.
References
1 The mkpasswd documentation says this:
Don't use this command to generate a local /etc/passwd file, unless you really need one. See the Cygwin User's Guide for more information.
I can't really find any solid reasoning in the user's guide, other than a mention that you'll have to regenerate the /etc/passwd and /etc/group files if your users and groups change, which I suppose is a decent enough reason. I can say that the process is somewhat error prone for newbies.
I randomly meet the same problem, and now I providing my solution for you.
0- Open cygwin by mintty.exe
1- Build passwd file manually (mkpasswd)
$mkpasswd > /etc/passwd
2- Change default shell in passwd file
$vim /etc/passwd
user:*:1976XX:1971XX:U-user\user,S-1-5-21-XXXX:/home/user:/bin/fish
3- Restart mintty.exe
There's an answer on SuperUser that is even simpler. Set the SHELL environment variable in Windows. Set it to your preferred shell (e.g. /bin/tcsh) and newly-launched shells should use it.
To set environment variables:
Go to the "System" control panel (right-click on the Start menu and select "System")
Click on "Advanced system settings" in the left-side column
From the "System Properties" window that pops up, click the "Environment Variables..." button
In either the "User variables" or "System variables" box (depending on whether you want the change to affect just yourself or all users), click the "New..." button.
Type "SHELL" in the "Variable name" box and the path (relative to the Cygwin file system) to your preferred shell in the "Variable value" box.
Click OK on the three open windows to save your changes.
I'm not sure how 'proper' of a solution this is, but I just added /usr/bin/zsh; exit to the bottom of my .bashrc file. You can substitute /usr/bin/zsh for the path to your shell of choice. It seems to work just fine so far.
If you're running Cygwin through ConEmu I found the easiest way is to replace commands line to run fish instead of default shell (Settings->Startup->Tasks):
""c:\cygwin64\bin\fish.exe" --login -i" (please change path to your cygwin folder accordingly)
I wanted to comment on the accepted answer, but not enough rep.
Regarding this method
$ mkpasswd > /etc/passwd
While this works to generate an /etc/passwd file, the odds are you're installing cygwin for yourself, and if your computer belongs to a domain, mkpasswd may run out and attempt to consume the entire domain user list. I had a 500MB+ /etc/passwd file from exactly this condition, and cygwin wouldn't even start until I deleted the file.
I strongly recommend, if using the mkpasswd route to use the -c switch, so it puts an entry in only for yourself.
$ mkpasswd -c > /etc/passwd
On a machine with a shared cygwin service (assuming you have write permissions)
$ mkpasswd -c >> /etc/passwd
I was trying to change my default shell in cygwin to zsh and I found parts of the answers
here helpful, but none of them gave a full solution. The best instructions I found were in the "installing zsh" instruction in the oh my zsh github repo by Robby Russel that you can find here
At the top of the page it has general instructions for installing zsh and then specific instructions for many different platforms. You can scroll down to the Cygwin section and follow the steps:
"The easiest way to change the default shell is to set your SHELL user environment variable. Search for "Edit Environment variables for your account" to bring up the environment variables window, create a new variable named "SHELL" and give it the value "/usr/bin/zsh/"."
(On Windows 7:
Press Windows key.
Start typing "environment".
When it appears, select "Edit environment variables for your account" and add the new variable as stated above.)
After I did this I closed and reopened my Cygwin shell window and tested that it worked with echo $SHELL. Expected result: /bin/zsh or similar.
Hope this helps!
Go to c:\cygwin or c:\cygwin64 (whatever is your cygwin home directory) and edit cygwin.bat. Instead of
bash --login -i
write, for example,
rem bash --login -i
tcsh -l
One simple way to do this is call tcsh at the end of .bashrc file
# x2=$(dirs +${cnt} 2>/dev/null)
# [[ $? -ne 0 ]] && return 0
# [[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}"
# if [[ "${x2}" == "${the_new_dir}" ]]; then
# popd -n +$cnt 2>/dev/null 1>/dev/null
# cnt=cnt-1
# fi
# done
#
# return 0
# }
#
# alias cd=cd_func
tcsh
alias g=gvim
source ~/.cshrc
source ~/.aliases

How can I get rid of something running on every new terminal session?

I am using Lion. I have an error that outputs on every new terminal session:
-bash: __rvm_add_to_path: command not found
It's an almost brand new user account.. RVM is installed on the other account on the machine.. ~/.bashrc & ~/.bash_profile are both blank.. the out put of env is:
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/ry/8zsyknmx7dj4_2zzvn1n71500000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-jsfKPw/Render
TERM_PROGRAM_VERSION=303
TERM_SESSION_ID=3EBC0F1A-9867-41E5-8873-75E84B9F712F
USER=incorvia
COMMAND_MODE=unix2003
SSH_AUTH_SOCK=/tmp/launch-ZQqgPj/Listeners
Apple_Ubiquity_Message=/tmp/launch-u3d1lp/Apple_Ubiquity_Message
__CF_USER_TEXT_ENCODING=0x1F5:0:0
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin
PWD=/bin
LANG=en_US.UTF-8
HOME=/Users/incorvia
SHLVL=1
LOGNAME=incorvia
DISPLAY=/tmp/launch-0B0I8s/org.x:0
_=/usr/bin/env
I see nothing related to RVM here.. where else can I look?
=====
/etc/bashrc
# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
return
fi
PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL,
# including the host name to disambiguate local vs.
# remote connections. Percent-escape spaces.
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
printf '\e]7;%s\a' "$PWD_URL"
}
PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
fi
=========
Fixed...
In the bottom of my /etc/profile it was sourcing /etc/profile.d/rvm.sh
Don't know how that got there...
Bash loads a series of files during startup. A good overview of the bash startup process can be found here.
Generally, the global settings, /etc/profile, /etc/bashrc, and the associated personalized settings, ~/.profile and ~/.bashrc are loaded, although that is slightly distribution-dependant (and on Mac OS X, for example, by default /etc/profile doesn't exist).
From the RVM Installation page:
Multi-User:
The rvm function will be automatically configured for every user on the system if you install as root. This is accomplished by loading /etc/profile.d/rvm.sh on login. Most Linux distributions default to parsing /etc/profile which contains the logic to load all files residing in the /etc/profile.d/ directory. Once you have added the users you want to be able to use RVM to the rvm group, those users MUST log out and back in to gain rvm group membership because group memberships are only evaluated by the operating system at initial login time.
I'd guess that the other use has installed in Multi-User mode;
/etc/profile probably loads /etc/profile.d/rvm.sh.
To stop it being loaded, you could remove the source RVM line from /etc/profile - this will stop it being loaded for all users, though.
For the account that had a working profile, I had the following .rvmrc:
root#sc-27617:~# cat .rvmrc
export rvm_prefix="/usr/local/lib/sc"
export rvm_path="/usr/local/lib/sc/rvm"
To get the error to go away for my other accounts, I simply copied this file to the other accounts and fixed the permissions (chown johndoe:johndoe /home/johndoe/.rvmrc)...
In Ubuntu 12.04, by default, the /etc/profile.d/rvm.sh will not be loaded when starting a new terminal. So every time, when starting a new termail, cmd as follows must be used to start rvm:
source /etc/profile.d/rvm.sh
And there are two ways to fix it:
open a new terminal-> right click and select Profiles->Profile Preferences->Title and Command->select "Run command as a login shell".
open a new terminal->run cmd as follows then the /etc/profile.d/rvm.sh will be auto loaded in a new terminal:
echo '[[ -s "/etc/profile.d/rvm.sh" ]] && . "/etc/profile.d/rvm.sh" # Load RVM function' >> ~/.bashrc
As some explanation here to say the 1st solution is not a nice one but the 2nd is suggested.
So in other way round, if you do not want the terminal to run something in a new terminal, you need to check whether the auto load is coursed by the two ways:
check whether the "Run command as a login shell" is selected and unselect it.
open the ~/.bashrc file ,find the lines related loading the function and delete it.
I had the same file (/etc/profile.d/rvm.sh) from a previous rvm installation. Deleting that file worked for me as well.
For the sake of being thorough, logging out of the shell seems to be required.
In your /etc/profile change the line:
source /etc/profile.d/rvm.sh
into:
if [ "${SHELL}" != "/bin/sh" ]; then
source /etc/profile.d/rvm.sh
fi
Why?
In Mac OS X the default shell of superuser (root) is a POSIX shell, not a pure Bash. Adding such condition will disable rvm for (possibly) emerygency shell /bin/sh, used by system administrator. That is good. If you would like to install something using root's account, you can always type bash and then rvm … in a command line.
Debian 6.1 scans the /etc/profile.d/ file for all .sh files and includes them, so there's no listing for rvm in any of the profiles or .bashrc files anywhere. Deleting rvm.sh from /etc/profile.d/ solves this.
if you have ZSH or OH-MY-ZSH, then you need to remove source /etc/profile.d/rvm.sh from /etc/zprofile

Resources