I use bower and grunt in my workflow, and I wanted to install bower at the same time as grunt and pull down all my bower dependencies. So I created a package.json file that has a script attached on postinstall, which I also pass my github project repo, and dropped my post_install.sh into /root/bin.
{ // snippet of package.json
...
"scripts": {
"postinstall": "bin\\post_install.sh https://github.com/blah/blah.git
},
...
}
so running npm install would run post_install.sh, which runs
#!/bin/bash
node_modules/.bin/bower install
grunt setup
git init
git add .
git commit -m "Initial commit of project artifacts"
git remote add origin $1
git push -u origin master
This only works if I set git bash to open in my project directory. So I've been trying to figure out how to switch directories from where git bash opens at /htdocs to /htdocs/myproject using an alias. I read up on how to set this I thought, but I can't figure out how to invoke this file... incidentally also tried putting it in another .sh file to see if that worked.
#!.bashrc
alias projDir='cd /onloadsolutions'
What am I doing wrong that the alias above in /bin/.bashrc won't execute in my post_install.sh when dropped above "grunt setup"?
Dropping this into post_install.sh
echo "script running has basename `basename $0`, dirname `dirname $0`"
echo "present working directory is `pwd`"
gives a basename of D:/htdocs/onloadsolutions/bin/post_install.sh, but my present working directory is /d/htdocs, which when the bower and git commands run they do it in the wrong directory.
Not 100% sure what you mean but I am guessing when you open bash you want to
be able to type a command to take you to your project
then type npm install and have it pull down all your dependencies
Try editing your .bashrc file (this should be in your home directory, not in the /bin folder) to access this you can use something like
nano ~/.bashrc
(~/ is a shortcut to your home directory)
and look in it for any existing alias commands or add yours down the bottom.
then after opening another bash session (.bashrc only runs when you first start terminal) you should be able to see your current aliases by typing "alias"
you can launch the alias you mentioned above by typeing "projDir" into the console. It would be much better to add the full path in your alias i.e.
alias projDir='cd /var/www/onloadsolutions'
then you can call it from anywhere. Otherwise you might end up in a different folder than you expect.
UPDATE
See comments below.
Put cd $2 in the second to top line of the post_install.sh file and add a second parameter to the package.json file that calls it.
Related
I want to make a script for my angular2 project that renames README.md to README_2.md. I installed "renamer" : "0.6.1" and made this script:
"renameMd": "renamer --find js/README.md --replace js/README_2.md" in package.json, but it doesn't work. It gives me this error: No input files supplied. How can I fix it ?
PS: the file is located in the js folder.
renamer takes a last parameter to filter the files that need to be renamed.
renamer --find README --replace README_2 js/README.md should work.
If you are using Linux, you could also use mv: mv js/README.md js/README_2.md (move in Windows).
I've written multiple *.cpp files in the location ~/Code/CPLUS before I know the existence of git.
Now I want to use git for version control.
I created a folder ~/git_repo/, and in this folder, I ran git init command. When I tried to run the command git add my_first_c.cpp under the path ~/Code/CPLUS, the following message appeared:
fatal: Not a git repository (or any of the parent directories): .git
Then I typed git init ~/git_repo/ under the path ~/Code/CPLUS, the same error still appeared when git status was typed.
If I type git init under the path ~/Code/CPLUS, the add and commit can be executed. The only problem is that .git is stored in ~/Code/CPLUS/, while I'd like it be stored in ~/git_repo.
My question is how to make the folder ~/Code/CPLUS a working directory while the repo info is stored in ~/git_repo/? And my machine has no GUI.
You could try exporting the variables export GIT_WORK_TREE=~/git_repo/ and export GIT_DIR=../Code/CPLUS from terminal (or in your ~/.bashrc) so Git uses these.
Thanks #Alariva , the suggested solution indeed solved this question. With .git created in ~/git_repo/, typing git --git-dir=/abs/path/to/repo/git_repo/.git add my_first_c.cpp works.
The solution comes from this post.
I have already a gitupdate.sh that I found on the internet.
My problem now is how to make the script run automatically every time I log into my Ubuntu 14.04 computer.
I have tried adding this line to .bashrc
sh '/path/to/git/repo/gitupdate.sh'
The problem here is the script is executed not in the context or path of the repo thus the script runs in a folder that is not initialized with git. (I don't actually know what folder bashrc run on)
What want to do is that the update script to be run by Ubuntu in the context of the path so the script will not fail. And also show the running script in a Terminal window that will not automatically close.
And the ultimate goal, is to be able automatically upon login, that git cloned repos to be synced with the public repos.
Try
(cd repo && bash /path/to/gitupdate.sh)
Just open the gitupdate.sh and at the beginning of the file just add the command to go to the selected direcotry. For example:
cd /var/test
I'd like to create a .bashrc file in my Git Repo which should then be shared with other devs. The goals here is to add project-based aliases for every dev.
For instance when using node.js tools, a lot of them check the current directory for configuration files (ex: grunt looks for Gruntfile.js, JSHint looks for .jshintrc, npm for package.json).
I want Cygwin to look after .bashrc in the local directory.
I don't want to change the $HOME variable since it would allow me to only work on one project at a time.
I fixed the issue with aliasas
Run touch .bash_profile command
change file to contain all aliases. Example:
file .bash_profile
alias ga='git add --all .'
alias gp='git push'
Every time you open the Bash, type . .bash_profile to reload the file and therefore register the aliases.
I got a ssh account running on a shared hosting server without root permission, after I installed the latest stable Git release via git-scm.com by "make install", the new command is successful install under my home directory which is ~/bin default automatically.
However, this new version of git seems only function with specify full path, otherwise by running command "git", it will only mapping to /usr/bin/git which is old one.
So, what should I do to correct this commend mapping issue? Thanks!
echo $PATH
export PATH=~/bin:$PATH
Path is where the shell goes to look for binaries. You need to make sure it looks in ~/bin before /usr/bin/git. Check with:
which git