I am working with Docker on my windows machine via git bash. Since git bash does not record the current status on closing, I need to set some environment variables related to Docker every time when I start a new terminal. The command I would like to run before start-up is:
eval $(docker-machine env)
Or better yet, have a bash script including other logics. For example if docker machine is not up, start the machine first, etc. Is there a way to automatically run bash command or script before opening a new git bash window?
I would recommend creating a new file under your home folder(~/) namely ~/.bashrc which is read by your terminal when it first starts-up. Add a function say myStartUpFunction() that runs your command as you need.
myStartUpFunction() {
docker-machine env
}
myStartUpFunction
This would enable you to run the docker-machine env every time a new terminal session is opened.
Related
If I run the command:
pipenv shell
in my Mac shell, everything works fine and a new virtual environment is created and activated:
.../django_celery_rabbit_flower$ pipenv shell
Launching subshell in virtual environment...
bash: parse_git_branch: command not found
.../django_celery_rabbit_flower$ . /.../django_celery_rabbit_flower-rEt8HW1V/bin/activate
bash: parse_git_branch: command not found
(django_celery_rabbit_flower) .../django_celery_rabbit_flower$
but a bash error is displayed:
bash: parse_git_branch: command not found
I do not understand where it come from. Any idea?
UPDATE
Jen answer trigger a little thought. I have checked my ./bash_profile and I can see the line:
export PS1="\[\033[36m\]\u\[\033[m\]#\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$(parse_git_branch)\$ "
This shows the git branch on the bash prompt. So I believe vscode uses this settings. The folder I am working on is not a git folder. Can I write an if statement to avoid the error being displayed when running the python virtual environment?
Instead make sure that the command does actually exists before running it.
PS1="...."'$(if hash parse_git_branch >/dev/null 2>&1; then parse_git_branch; fi)'"..."
I haven't been able to find a similar question, but I can't imagine this is an issue that comes up too much.
At my workplace I've decided to switch over to a full Linux experience by using Cygwin, over what I was previously using, Git Bash.
The only slight drawback is that we have a script written in Ruby that deploys changes to our site. I can run this from my Git Bash terminal no problem, but not Cygwin as there doesn't seem to be a Ruby installation on here. I've learned about sending standard output to other terminal windows, but I've only been successful when both terminals have been the same shell.
What I'd like to do is the following:
1. Type a command into Cygwin that opens a Git Bash terminal and automatically runs ./deploy.sh on that Git Bash terminal upon opening.
2. If possible, also pass in an argument in the same command, that the script expects upon running. (In this case it's whether we want to deploy to our staging or production server).
Is this possible? So far I can get what looks to be a Git Bash terminal to open and prompt me for the server, but when I enter it, it does not work. I get an error with regards to a command within the script not being found. Thing is, running this same ./deploy.sh script in a Git Bash terminal that I open myself works perfectly as it always has. The Git Bash terminal that is being opened by Cygwin does not appear to have all of the capabilities of a Git Bash terminal I open 'the normal way'.
The command I am running so far from Cygwin is as follows:
/cygdrive/c/'Program Files'/Git/git-bash.exe "./deploy.sh"
I understand there is probably a way of getting this to work by installing Ruby via Cygwin but I'd like to mess around with my work environment as little as possible in case I somehow affect my ability to deploy my work... and besides, Git Bash definitely runs this script without an issue so I can't see why I would need a duplicate installation.
Many thanks!
I have simple File Watcher that run TSLint. If I copy the command and run it in the console all fine but WebStorm run it with old Node version and throw error Buffer.alloc is not a function.
I'm using nvm to manage node.js versions.
ubuntu 16.4
Different Node.js versions are on your $PATH when you start your script from the IDE and from terminal.
When being launched from desktop/System menu, WebStorm only sees environment variables configured in login shell, but not in interactive shell configuration files (like .bashrc or .zshrc).
Possible workarounds:
Workaround 1: make required variables available in a login shell by moving them to the corresponding shell profile config
Workaround 2: run IDE from a terminal, either with the command line launcher or with bin/webstorm.sh
Workaround 3: edit the desktop launcher and set command to /path/to/shell -l -i -c "/path/to/webstorm.sh" (make sure that the shell you specified there has the needed variables configured in its interactive shell configuration file)
see also https://youtrack.jetbrains.com/issue/IDEABKL-7589
I have Jenkins job which is connecting to remote host via ssh and runs a bash command.
I can run the same bash command via terminal by logging into remote linux machine. But If I do so , I see env variables are different when I tried printing printenv.
Now, if I run the same bash command from Jenkins over ssh execCommand I see bit different set of env variables.
Is there any way, I can make that bash run using same env variables, no matter where I am running it from?
I can activate my python virtual environment from it's folder by entering . bin/activate. I'd like to instead type a single word alias, such as shazam, from the home folder (or anywhere else) that activates the environment, changes to my master project folder, and lists my projects.
I tried creating an alias in .bashrc that pointed to an .sh file containing:
cd ~/path-to-virtual-environment
. bin/activate
cd ~/path-to-master-project-folder
ls -a
I was getting a permission denied error, so I ran chmod u+x <script file>. The script now runs, but the VE does not activate and while the project folders are listed, the shell is not in the master project folder. I would appreciate some guidance. Thanks.
Recreate all your environments in ~/.virtualenvs and install virtualenvwrapper. The command to activate an env is workon shazam. Command line completion is supported.
Now about your problem: you've tried to activate an environment in a shell script. That doesn't work because shell scripts run with another shell and env activation change their environments, not the current. I.e., the environment briefly activated but then at the end of the script the new shell exits and the environment deactivated.
There are two ways to overcome this.
Use aliases or shell functions instead of scripts — they are the only way to change the current shell's environment.
Run interactive shell at the end of your script (exec $SHELL). It inherits activated environment and gives you a command prompt. To deactivate simply exit the shell (exit or [Ctrl]+[D].).