How to automatically run "/bin/bash --login" automatically in the embeded terminal of gedit on ubuntu 10.04? - bash

Background: I updated RVM to latest version and .rvmrc so that I can direct rVM to use the project specific gemset. But it now requires that the bash shell be a login shell. So I did that via the Edit |preference of the Terminal of ubuntu. That works perfectly fine.
However, the embedded terminal of gedit is still not "run command as login shell". But I can remedy that problem by typing in "/bin/bash --login" onto the embedded terminal of gedit after it is launched.
That is an OK workaround, but I felt there got to be a way to automatically do this.
I tried to add the follow variations to the end of ~/.bashrc file and it worked sort of, but I had to ctrl-c to return to prompt mode. Another side effect, normal terminal now also requires me to hit ctrl-C to return to prompt mode.
/bin/bash -l -i
How can I tell ~/.bashrc file to execute that command and return to prompt mode without me hitting ctrl-C each time? Or any other way to achieve this goal.
Thanks in advance.
p.s. I also posted on askubuntu
https://askubuntu.com/questions/226694/how-to-change-gedit-embedded-terminal-to-be-run-command-as-login-shell

Add this to your bashrc script:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Worked for me.
(you still need:PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Hope it helps

The terminal plugin is written in Python, so you could attempt to customize it. Note that if you edit the installed files directly, your changes will be overwritten when the package is updated.
Around line 90 of the "/usr/lib/gedit/plugins/terminal.py" file you will find a line that looks like the following:
self._vte.fork_command_full(Vte.PtyFlags.DEFAULT, None, [Vte.get_user_shell()], None, GLib.SpawnFlags.SEARCH_PATH, None, None)
Add the arguments to the shell inside the list:
self._vte.fork_command_full(Vte.PtyFlags.DEFAULT, None, [Vte.get_user_shell(), "-l", "-i"], None, GLib.SpawnFlags.SEARCH_PATH, None, None)

Related

Set up path on prompt on pycharm terminal windon

I just upgrade pycharm into 2016.3.1. Before upgrade, I do not have problem to see the current directory path under the prompt on terminal window. After upgrade into pycharm 2016
3.1. All directory path on prompt on terminal window seems like messed up with 133;C;133;D;01337;RemoteHost=hawkins#pc_name.home1337;CurrentDir=/Users/hawkins/path133;MAC:path hawkins$ 133;B for some reason. Anyone have expereience on how to resolve this?
MAC:path$
133;C;133;D;01337;RemoteHost=hawkins#pc_name.home1337;CurrentDir=/Users/hawkins/path133;MAC:path hawkins$ 133;B
133;C;133;D;01337;RemoteHost=hawkins#pc_name.home1337;CurrentDir=/Users/hawkins/path133;MAC:path hawkins$ 133;B
133;C;133;D;01337;RemoteHost=hawkins#pc_name.home1337;CurrentDir=/Users/hawkins/path133;MAC:path hawkins$ 133;B
I had a similar problem. It turned out my problem was due to have iTerm shell integration installed.
As you have tagged the question [osx], I assume that you might also have done this.
There is a nice explanation to what these strange symbols mean in this answer: https://unix.stackexchange.com/a/294886/47407
I figured I could avoid having to uninstall Shell Integration by clearing my PROMT_COMMAND, and setting PS1 again. I made a shell script called pycharm_terminal.sh with the following
export PROMT_COMMAND=
export PS1="\[\e[31m\]\u\[\e[0m\] at \[\e[33m\]\h\[\e[0m\] in \[\e[32m\]\w\[\e[0m\] at [\A] \[\033[31m\]`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`\[\033[35m\]\n$ \[\033[00m\]"
bash -i
The PS1 variable can be set to whatever you had before. This is just how I like mine.
Now, in PyCharm Settings: Go to Tools > Terminal and in "Shell path" set it to /bin/bash <path_to_pycharm_terminal.sh>.
Now try opening a new terminal in PyCharm. It shouldn't have those control character errors.
Solution that worked for me:
Go to Settings > Plugins
Find plugin "Python Terminal" and disable it
Restart PyCharm
The only negative effect I've noticed - auto activation of virtualenv on terminal start doesn't work.
for some reason, I figure it out by create a .pycharmrc under by user directories
and setting up /usr/local/bin/bash --rcfile ~/.pycharmrc under Tool->Terminal on shell path. It seems like it fixed but i have no idea why
MAC: path$ cat ~/.pycharmrc
exec bash
This is what worked for me:
Created new file pycharm_terminal.sh with one command bash -l
Then I set PyCharm Settings: to Tools > Terminal and in "Shell path" set it to /bin/bash/path_to_pycharm_terminal.sh.
Restart PyCharm and all work as expected
bash -l, by man, is a: -l Make bash act as if it had been invoked as a login shell (see INVOCATION below).
which is probably mean, that when PyCharm starts the Terminal and executing the pycharm_terminal.sh with bash -l, everything in .bash_profile is include by default
Found this question while trying to resolve similar issue for 'Geany' on mac osx. I had an install of iterm2 on my machine and was getting garbage in front of the terminal prompt.
similar solution as KPLauritzen offered also works for 'Geany' terminal as such.
Hope this helps someone:
Create shell script in home directory using desired PS1 & CLICOLOR settings:
~/geany_terminal.sh
export PROMT_COMMAND=
export PS1='[\e[1;32m][\u#\h \W] \D{%F %T}\n\$[\e[0m]'
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
bash -i
Then I went to 'Edit -> Preferences --> Terminal' and set my 'Shell' to:
/bin/bash /Users/myusername/geany_terminal.sh
Upon reloading Geany, the Terminal now displays with PS1 and CLICOLOR settings exactly as I have set in my .bash_profile without garbage in front.
You can just activate your .bash_profile
/bin/bash --rcfile ~/.bash_profile

~/.profile, ~/.bashrc, and ~/.bash_profile not running on new terminal start up

I am trying to create a permanent alias for my terminal. I put the alias in my ~/.profile, ~/.bashrc, and ~/.bash_profile files, previously empty. When I start a new terminal, bash does not recognize the alias, but if I source any of them, it does. Why are these not getting run when I open a terminal? I am on OSX.
Newer MacOS versions use zsh as the default shell for both Terminal and iTerm2. Run echo $SHELL to confirm if this is the case for you.
Zsh looks for a .zshrc file upon shell startup, so to continue using zsh while sourcing the contents of your bash profile, you can run the following:
echo "source ~/.bash_profile" >> ~/.zshrc
Open a new terminal window for the changes to take effect.
Two things need to happen here when using iTerm to get the loading of dotfiles to work.
First you should add the following to your .bash_profile
[[ -s ~/.bashrc ]] && source ~/.bashrc
Secondly you will need to ensure that in iTerm preferences your terminal is set to launch a login shell.
Hope this helps!
Using the default mac terminal, what worked for me was to add a command to run on start up to source my .bash_profile.
Preferences > Profile > Startup > Add command 'source ~/.bash_profile'
Mac terminal preferences window screenshot
Might be considered to be a bit hacky, but it does the trick.
Adding source ~/.profile to my .bash_profile worked for me.
As of High Sierra, both Terminal and iTerm want to load ~/.profile first. So I suggest you put one line in your .profile to make your Mac work like other Unixes:
source ~/.bash_profile
By editing this one file, you won't have to search through the menus of multiple apps to override Apple's bizarre behavior in each.
As of Catalina the default shell is now zsh. You can change it back to bash with chsh -s /bin/bash and that should load your .profile or .bash_profile
Why are your shell's initialization files not loading?
As with most things, It Depends ™
I recently experienced the same phenomenon and went through the following exercise to resolve it:
I use iTerm. iTerm runs a login shell by default. Verify in iTerm Preferences > General > Command > (*) Login Shell
Therefore, I know that ~/.bash_profile will always be called.
Knowing that, I put the following in my ~/.bash_profile file:
for file in ~/.{bashrc,bash_exports,bash_aliases,bash_functions}; do
[ -r "$file" ] && source "$file"
done
unset file
Notice that I use separate files for .bashrc, .bash_exports, etc. It keeps things separate and simple.
Note also that /etc/profile is loaded first, but since I have never used that system wide init file, I knew that that was not my problem. For details check out $ man bash
So, I started with my ~/.bash_profile file.
I found that when I installed Canopy Express that it's installer replaced the contents of my ~/.bash_profile file with the following content:
# Added by Canopy installer on 2017-04-19
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make the bash prompt show that Canopy is active, otherwise 1
alias activate_canopy="source '/Users/lex/dev/python/User/bin/activate'"
# VIRTUAL_ENV_DISABLE_PROMPT=1 source '/Users/lex/dev/python/User/bin/activate'
p.s. Canopy is an excellent, free python IDE, that I highly recommend.
Fortunately, I backup my ~/.bash* files so restoring that was easy and quickly fixed my issue.
My advice would be to understand the order of calls to your initialization files and start with the first one and work your way through them until you find the problem.
Oh, and you may want to verify which shell you are using (I use bash):
~ $ echo $SHELL
/usr/local/bin/bash
I am guessing you may use another shell, such as bash, tcsh, sh, zsh etc.
Put source .bash_profile into your appropriate 'bashrc' file will make the auto loading recovered, i.e.
.login for tcsh, .bash_profile for bash, .zshrc for zsh
My issue was solved by unchecking Preferences > General > tmux >
Use "tmux" profile rather than profile of the connecting session
Most likely, you need to create the files yourself as they appear not to exist by default. You should give them execute permission to make them run.
~ % sudo chmod 700 ~/.bash_profile
Also, you should check the ownership of the files. They should belong to current user rather than root. Otherwise, you will get permission denied error.
~ % ls -a -l
~ % sudo chown <user_name> ~/.bash_profile
Finally, please note that bash looks in your home directory for .bash_profile, .bash_login, and .profile in order. Bash will stop looking if the first is found.
This means if you have both .bash_profile and .profile files, the .profile will not run.
For more information
Hope this would help you.
Little late to the party but it seems that the file .zprofile is the equivalent to that of .bash_profile when loading zsh. I used this instead to execute a few commands on startup. Of course this only valid for a specific iTerm setup with zsh.
https://zsh.sourceforge.io/Intro/intro_3.html

Ruby installation and profile reload

I've recently installed ruby using this tutorial :
http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/
However every time I turn off my computer and open terminal. I need to type . ~/.bash_profile so I can do bundle install or anything else ruby related.
I'm using ubuntu 12.04, has anyone encountered similar issue?
In addition to what McGar said, you want to make sure that you have 'Run command as a login shell" checked in your terminal window.
For instance, in Fedora 19 (I'm sure it'd be the same in Ubuntu 12.04) go to: Edit -> Profile Preferences -> Title and Command, and then check 'Run command as login shell'. I'd also recommend close/open all open terminals after making that change.
Do you have something like following lines in your .bashrc:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
#This loads rvm
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
check this tutorial of enabling login shell => http://rvm.io/integration/gnome-terminal (not copy pasting as instruction on the site might get updated / improved).

"RVM is not a function" error

RVM is installed on my machine (running Mac OSX 10.6.8), correctly and it runs fine. The odd thing is that to run it, I have to use source ~/.rvm/scripts/rvm for every new session. I tried making a symlink from it to /opt/local/bin/rvm, but when it runs it does nothing. I also tried creating a symlink from ~/.rvm/bin/rvm to /opt/local/bin/rvm, and when I run rvm in the Terminal it displays the help page, as expected. But when I try rvm use some_ruby_version it always displays "RVM is not a function, selecting rubies with 'rvm use ...' will not work.". How can I fix this?
My goal is to get it to the the point that I don't have to type the source command every session, and for some reason ~/.profile does not execute.
You have to source the RVM script into the current session because it makes changes to the shell environment - and it is absolutely impossible for that to be done from a child process. Your efforts at running RVM as an external command cannot succeed.
To actually fix this you have two choices:
Configure your terminal emulator to start a login shell, rather than a non-login shell, so that your .profile is loaded.
Modify .bashrc to source RVM instead, which works for non-login shells as well.
To do the second you can just add to ~/.bashrc:
if test -f ~/.rvm/scripts/rvm; then
[ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi
If you are using zsh as shell instead bash, you have to:
1.
vi ~/.zshrc
2.
Like Matt said, add:
if test -f ~/.rvm/scripts/rvm; then
[ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi
3. Restart Terminall
4. Done!
rvm use 1.9.3
Wil work
I didn't understand what ~/.profile does correctly; I needed to change ~/.bash_profile instead. Problem solved!
Well, with mountain lion (10.8.3) what worked for me was editing /etc/profile
and adding the line mentioned before at the bottom of the file:
if test -f ~/.rvm/scripts/rvm; then
[ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi
I had the same issue. I found the .profile file was not getting updated, so i added the same command that was added into .bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
I don't know if this is the right way, but it worked...
You shouldn't need to edit anything as others suggest. Just go into your terminal's settings and select the "Run command as login shell". This will cause .profile to run on the next terminal instance. Reopen your terminal and you should be able to use rvm use 1.9.3 (or whatever version you installed).
More info found on rvm.io (which is also a great place for answers)
https://rvm.io/integration/gnome-terminal
You have to make some settings.
Open terminal and run this command.
source ~/.rvm/scripts/rvm
and then go to edit > Title and command and check Run command as login shell
and you are done. Now you don't need to specify source everytime.
What was screwing me up was assuming my path was correct since I was using one I can run manually.
Apparently there are different executables or scripts that can be used and are located in different places.
I thought that the path Mina should use was this:
/usr/local/rvm/bin/rvm
When in reality it was this:
/usr/local/rvm/scripts/rvm
I had this issue when I became root. I tried many of the solutions above. What finally worked was exiting from root and being a regular user. Which is what I needed anyway.
None of these solutions seemed to redeem my problem which was on Ubuntu 12.04 LTS.
What I did is the following:
rvm get stable --auto-dotfiles as outlined in the RVM documentation here
Added source ~/.profile as the first line of: ~/.bash_profile
I will not all of these steps were documented as errors from the RVM command line:
RVM is not a function, selecting rubies with 'rvm use ...' will not
work. You need to change your terminal emulator preferences to allow
login shell. Sometimes it is required to use /bin/bash --login as
the command. Please visit https://rvm.io/integration/gnome-terminal/
for a example.
and
WARNING: You have '~/.profile' file, you might want to load it,
to do that add the following line to '/home/user_name/.bash_profile':
source ~/.profile

rvm installation not working: "RVM is not a function"

I just installed RVM, but can't make it work. I have such line at the end of my .profile file:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
I tried to run source .profile and restarting terminal, but still, when I run rvm use 1.9.2 I'm getting:
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
My system is Ubuntu 11.10.
You need to run the following
$ source ~/.rvm/scripts/rvm
then run this
$ type rvm | head -n 1
and if you get
rvm is a function
the problem is solved.
You also need to run user$ rvm requirements to see dependency requirements for your operating system
Source: https://rvm.io/rvm/install/
I forget mention that you need to put this code into you ~/.bashrc or ~/.zshrc file and you will not need to write this code again.
You are not using an login shell.
The process of enabling the login flag is described here, also some details on what a login shell is can be found here.
Thus, you need to check the option "Run as login shell" in the Gnome terminal's settings. It is required to open new terminal after this setting the flag.
Sometimes it is required to set the command to /bin/bash --login.
For remote connections it is important to understand the differene between running interactive ssh session and executing single commands.
While running ssh server and then working with the server interactively you are using login shell by default and it's all fine, but for ssh server "command" you are not using login shell and it would be required to run it with ssh server 'bash -lc "command"'.
Any remote invocation can have the same problem as executing single command with ssh.
To permanently resolve this just cut/paste following line:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
From: ~/.bash_profile file
To: ~/.bashrc file
Reason this works is that .bashrc is executed each time you enter the terminal, and .bash_profile each time you login. That is why solution /bin/bash --login works, but you have to do that each time you enter the terminal. This way you are set until your next format, and you will forget all this by than :)
I too faced this problem. Finally i executed this line on terminal.
source ~/.rvm/scripts/rvm
Problem is fixed. Because this line will make the RVM instance a function for a particular time.
The latest RVM (rvm 1.11.6 (stable)) stopped working on Ubuntu (10.10 - 64 bit - nerdy gnat or whatever) - I kept getting
"RVM is not a function, selecting rubies with 'rvm use ...' will not work."
Before, I got the message, but 'rvm 1.9.3-p0#rails321' would work. Now, it wouldn't work - you couldn't change gemsets at all.
Nothing worked, until I found this - make this the LAST line in /home/your-name/.bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
As you said, the error shown could be the following one.
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.
As said above, just type '/bin/bash --login' in your terminal (after restarting your terminal), then type the comand 'rvm use 1.9.3' (for e.g.) and it will start using the same version.
Just execute the command 'ruby -v' to confirm that the RVM is using the updated version of Ruby.
I had this problem too on a fresh rvm installation, and non of the answers here fixed it. Going into the official rvm site, on the basics section, they have this command:
# from http://rvm.io/rvm/basics
source $(rvm 1.9.3 do rvm env --path)
You should change 1.9.3 for the ruby version that you actually want, and it'll make rvm a function regardless of the shell type.
even though you accepted an answer, i'd like to suggest another way .. ~/.bashrc is loaded before any shell is opened. Add that line at the end of that, and you don't need any of that login shell thing
Maybe you can try belows:
Your Terminal ->
Edit ->
Profile Preferences ->
Title and Command ->
Check the "Run command as a login shell"
Done
Run bash --login and then run rvm use 2.0.0.
Open Up the Terminal and then Go to Edit > Profile Preferences and then go to the Tab "Title and Command" and Check "Run Command as Login Shell".
Boot Up a Bash and Now you can install Gems directly from the terminal without the use of sudo and the error "RVM is not a function, selecting rubies with 'rvm use ...' will not work." will be eliminated.
Cheers.
All the above answers are valid. But when i faced the same issue, the solution was the following:
Update ZSH. (Tried to update directly din't work for some reason. So uninstalled and reinstalled updated version from here)
Set default shell as zsh (i.e. if you prefer zsh) using sudo chsh -s $(which zsh) $USER
Ensure that the following code is at the bottom of your .zshrc after you have installed the latest RVM probably using CURL from official RVM site
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
source ~/.profile
MOST IMPORTANT POINT: Ensure that in your .zshrc file every export to PATH is appended with :$PATH. Which i believe was the root of my problems even after following the above steps.
post this all my problems of RVM Not being a function went away. If it still does not work, give some error trace over here. After a few hours of struggle to solve this issue, i'm sure i must have seen all related errors.
Hope it helps. Cheers!
Procedure for installing Ruby 1.9.3-p125 on Mac OSX 10.8 Mountain Lion
You've already installed the latest XCode (>= 4.3) and and the command line Objective-C
compiler "clang".
You must run the "bash" shell for this procedure to work.
Go to System Preferences
Click on "Users & Groups"
Click the lock on the bottom left of the panel and enter your password to unlock it.
"Ctrl-Click" on your user icon in the left pane of the panel and choose "Advanced Options..."
Change the Login Shell to "/bin/bash"
Close the preferences
Open a terminal window (press command+spacebar and type in "terminal")
Follow the instructions at:
http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/
Notes:
To install ruby, you may need to specify the clang compiler:
$ rvm install 1.9.3p125 --with-gcc=clang
If RVM gripes about /usr/local/rvm not found, you need to create a link:
$ ln -s /Users/[your user name]/.rvm /usr/local/rvm
source ~/.bash_profile
... should do the trick ..., probably need to logout and login again.
How to reload .bash_profile from the command line?
I'd got the same error because I'd ever installed the old rvm version ruby-rvm with the apt-get command.
I solved the problem by remove the script line to config the old rvm in .bashrc file.
Check the old rvm config script and then run source .profile
« Official » instructions are there: https://rvm.io/integration/gnome-terminal/
I fixed it by adding this line to .bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
I had the same error, but none of the solutions on this page seemed to work. For me it was enough to add the rvm executable to my path:
PATH=$PATH:/usr/local/rvm/bin/
Et voila!
I had the same issue and I did this in my .bash_profile and it worked.
source "$HOME/.rvm/scripts/rvm".
For those who comes with same issue and they are using lubuntu like me I followed this link :
You start your terminal with
lxterminal -e "bash -il"
Thank to #mpapsis who pointed me to the right direction
My unclean way to change of ruby version is
rvm alias create default ruby-2.2.3 && source ~/.bashrc && rvm list
it works because I have the line bellow in my ~/.bashrc but strangely it don't do the job automatically.
[[ -s "/usr/local/rvm/bin/rvm" ]] && source "/usr/local/rvm/bin/rvm"
I tried to connect with --login to my docker container
docker run -it imagename `/bin/bash --login`
but in this case the container stay open in background and I can't enter commands.
I tried both zhc and terminal with the option "open with /bin/bash --login"
$ source ~/.rvm/scripts/rvm
if you don't want to do it again and again for every terminal tab enable the login shell by following these steps.
got to preferences
enter image description here
enable run command as a login shell
enter image description here

Resources