Hi guys i'm using msysgit in Window 7. How do i invoke notepad++ from Git Bash like we do it with our default notepad. Like for example
name@usename notepad textfile.txt
Instead i want the file to open with notepad++
Note : I've added notepad++ to my PATH, but still unable to invoke it from commandline.
Edit
I tried this in .gitconfig -->
[alias] notepad='C:/Program Files/Notepad++/notepad++.exe'
but isn't working.
So, by default you won't have a .bashrc file so just navigate your to your home directory by typing:
cd ~
create or edit the .bashrc with vim (or whatever editor you are comfortable with):
vim .bashrc
Here is the line I had to add to mine (I am running a 64 bit OS so if you aren't don't copy this exactly)
alias notepad="/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
If your copy of windows is 32 bit then it should look like this
alias notepad="/c/Program\ Files/Notepad++/notepad++.exe"
these are the faster ways to achieve the goal
start notepad++
start notepad++ <filename>
alias np='start notepad++'
np <filename>
tried and tested, just do it!
I believe git-bash is an actual bash shell, so when it starts, it runs a .bashrc
file from somewhere (most likely your home directory or the directory git-bash starts in). Look for that file, and when you find is, add an alias line somewhere for notepad++:
alias notepad="/c/Program\ Files/Notepad++/notepad++.exe"
Of course use your actual path to Notepad++ there.
I added this for my 64-bit machine with 32-bit Notepad++.
$ cd ~
$ vim .bash_profile
Add this to the file then save:
64-bit systems
alias npp="/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
32-bit systems
alias npp="/c/Program\ Files/Notepad++/notepad++.exe"
Now you should be able to open any file with notepad++ by entering
$ npp [file_name]
@SageMage's answer is right on spot.
Just a reminder. You need to close and reopen GitBash after after you make a change in .bashrc in order for it to be activated.
PS: After two years, I hope this helped!
The below is listed on Udacity's course on Git and Git Hub. It worked for me:
Run the following command in Git Bash after checking the location of notepad++ on your pc.
echo 'alias npp="C:/Program\ Files\ (x86)/Notepad++/notepad++.exe"' >> ~/.bashrc
notice how I had to escape charaters like the space and the brackets, you can escape any character if you're not sure whether it should be escaped or not. Also make sure to use the alias you want, I chose npp
- Close and re-open Git Bash
- Type npp in Git Bash, if it opens then you're good to go. If not, try the below points
Test .bashrc by running the command below in Git Bash
source ~/.bashrc
Retry typing npp to start notepad++. If notepad++ doesn't start check the contents of the file ~/.bashrc created in step 1.
To ensure the .bashrc file contents is loaded each time you open Git Bash, edit ~/.bash_profile and add the following two lines. (Reference)
if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in i) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac
Close and re-open Git Bash. Type npp in Git Bash to check it starts correctly
In your .bash profile add
alias myeditor="'C:\\Program Files (x86)\\Notepad++\\notepad++.exe'"
Give "\\" instead of "\".
I added the Notepad++ folder to my path, so I can just type notepad++
$ which notepad++
/c/Program Files (x86)/Notepad++/notepad++
First of all, if you haven't created any .bashrc profile or .bash_profile create either of the one using vim or any other editor as others have mentioned
Or
In case you did not have any such editor which can work with git bash yet make one manually by opening a notepad or notepad++ editor and saving the file at the home directory.
Note: You can check your home directory by using
cd ~
pwd
My Notepad++ path is C:\Program Files\Notepad++\notepad++.exe
So for going to any directory to notepad++ directory, I have to go to root directory and then to the required path. So here is the line that I had to add to mine .bash_profile
alias note="//\/c/Program\ Files/Notepad++/notepad++.exe"
'//' takes it to the root directory
P.S.:
- You may have to change the path depending on your target directory( notepad++ directory)
- The "Program Files"directory should be written like 'Program\ Files'.
- If your Notepad++ directory is in Program Files (x86) then use 'Program\ Files\ (x86)'
This config works for me
editor = \"/c/Program Files (x86)/Notepad++/Notepad++.exe\" -multiInst
The multiInst argument is just to make it friendlier for interactive edits where you already have notepad++ open. (If Notepad++ is already open and you run the process again, it adds the file to your existing instance and then exits immediately, which git takes to mean you've finished)
I met the cannot find the command issue. I figured out that is because I was doing all those vim .bashrc under my working directory. It seems I have to do that under the Git Bash home directory...
In your git bash just add:
alias npp='notepad++ -multiInst -nosession'
I hope this works.
An alias is used with the git
command, so with the one in your OP, you should be able to run git notepad
. I don't think this is quite what you want, though. If you correctly added notepad++ to your PATH variable, then you should be able to just do notepad++
. You can check this by running which notepad++
. If this doesn't give the full path to notepad++
, then the PATH isn't set correctly.
来源:https://stackoverflow.com/questions/15298732/invoking-notepad-from-git-bash