ConEmu: possible to change the up arrow behavior? - conemu

The ↑ arrow cycles through the command history, for example, I get these suggestions:
cd project
git init
git commit
cd ..
Is it possible to adjust the behavior of the up arrow in ConEmu so that it behaves like in zsh which filters the suggestions based on my current prompt? For example, if I wrote "git" to the console, up arrow would only cycle through these two:
git init
git commit

You can do that by installing clink: http://mridgers.github.io/clink/ and enabling it in the settings (see docs: https://conemu.github.io/en/TabCompletion.html)

Related

Creating mongoDB alias with .bash_profile on the cmder is not working

this is my first ever question. Okay..
Relevant to this problem :
I am using cmder
I am new to the terminal
I am using a windows PC
I'm following a tutorial on how to install mongoDB locally, after running the setup my first problem came when
On the terminal The tutor did
Cd ~
To go to the home directory but when I tried the same command on the cmder I received
The system cannot find the path specified
So I navigated manually using "cd.. " to
c:\Users\<username>
Which I think is the home directory,I created the ".bash_profile" file and saved the following commands in it
alias mongod = "/c/program\ files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo = "/c/program\ files/MongoDB/server/4.4/bin/mongo.exe"
But when I run the mongod or test if it's installed completely it returns
'mongod' is not recognized as an internal or external command, operable program or batch file
Please I don't know my way round the terminal that much, please be detailed with answers
Thanks in advance
alias mongod="/c/Program\ Files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/server/4.4/bin/mongo.exe"
Removing spaces and making uppercase the first letters of program files worked for me.
cmder doesn't interpret shell arguments like ~, which means tilde won't work in paths. Also, be aware the way you spelled Cd. It can cause an error in other command line tools (case sensitive ones like Git Bash).
1 - If you're using cmder/cmd.
Use doskey to create an alias/shortcut:
Create C:\bat\macros.txt to store your macros/aliases and paste:
cdhome=cd /d %HOMEDRIVE%%HOMEPATH%
mongo="C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" $*
mongod="C:\Program Files\MongoDB\Server\4.4\bin\mongod.exe" $*
Rename everything you want but %HOMEDRIVE%%HOMEPATH%. $* at the end means the command accepts arguments, like mongo --version.
Keep in mind that .bash_profile isn't related with cmder/cmd, that's why your mongo commands are there too.
Then Windows + R and type regedit.
Go to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\
Right-click and add a new "String Value". Name it Autorun.
Right-click it and modify the value data to DOSKEY /MACROFILE="C:\bat\macros.txt"
2 - If you're using Git Bash, Hyper terminal, etc.
On .bash_profile, just remove the spaces around the equals sign. Like:
alias mongod="/c/program\ files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo="/c/program\ files/MongoDB/server/4.4/bin/mongo.exe"
or on Windows, you can just go to System properties/Advanced/Environment Variables. Under System variables, find the Variable called Path. Click edit, then New and paste in the path of the mongoDB bin folder:
C:\Program Files\MongoDB\Server\4.4\bin
keep in mind to write version your mongodb correctly in path, now its 4.4
By adding a path to the path variable you can access the .exe files from that path no matter where you are in the directory. It serves the same purpose as the .bash_profile file. Doing it this way allows this to work with windows cmd prompt or cmder as well. Upon launching, the bash emulator gets the environment variables from Windows anyways.
After adding the mongoDB path, open cmd prompt or any bash emulator and type in mongo. It will load up mongo.exe regardless of your current working directory.
Be Specific about the spaces after alias.
alias alias_name ="path.."
I faced alot of issues despite so many answers so this worked for me.
1.First install git and hyper terminal
2.Click the '~' sign to enter the home directory and then make a new file ".bash_profile"
Enter the command "vim .bash_profile"
Now enter 'i' key to enter the insert mode
Copy paste the exact command below:
alias mongod="C:/Program\ Files/MongoDB/Server/5.0/bin/mongod.exe"
alias mongo="C:/Program\ Files/MongoDB/Server/5.0/bin/mongo.exe"
(make sure that you use forward slash '/' for path and "\" backward slash to indicate space between program and files)
enter esc
write the command ':wq!' and click enter
restart hyper terminal and check the installation by running the command 'mongo --version'
Use git bash instead of CMDER
OR
Try to install mongosh from this link:
[1]: https://www.mongodb.com/try/download/shell?jmp=docs
And after setup go to hyper terminal and write mongosh => to connect to MongoDB on port 27017 and then you will see => test>
now you are ready to use the Database and you can write help to see Shell Help.
Check if mongo.exe or mongod.exe files are exist. In my case the bin directory had mongos.exe instead of mongo.exe.

How to disable git hooks in gitkraken?

I'm working with a project that has git hooks configured. Unfortunately. It was added to prevent juniors or headless developers to commit CI-check-failing code to their branch.
I am one of these, who ignore git hooks with HUSKY_SKIP_HOOKS env variable, but for me it doesn't work in GitKraken.
Do you know how to ignore git hooks in GitKraken?
Well, I did receive a response from their support, that works for me.
Additionally, you should still be able to disable these hooks from executing. You will need to change the chmod permissions for the files, which reside under local_repo/.git/hooks.
chmod -x .git/hooks/*
And it works for me.
Are you using the command instruction like that HUSKY_SKIP_HOOKS=1 git <command> ...?
You can use it like HUSKY_SKIP_HOOKS=1 but also HUSKY_SKIP_HOOKS=true.
You can also bypass commit hooks in command line with : git commit -m "bla bla" -n.
If you'll be unable to run hooks for a long time, you also can use the core.hooksPath git configuration option:
git -c core.hooksPath=/dev/null checkout master
git -c core.hooksPath=/dev/null pull
git -c core.hooksPath=/dev/null commit ...
git -c core.hooksPath=/dev/null push
...
And (just sayin'), SourceTree has an interface option to skip commit hooks. As far as I know Git Kraken doesn't have one.
Sadly there doesn't seem to be a simple way to do this from the GitKraken. As others have pointed out you should pass in the Husky environmental variable normally. But here's a guaranteed simple solution that will always work. I'm currently using it to clean up some old repositories.
# Temporarily wipe husky
npm uninstall husky
# Clear out the husky package changes so we don't accidentally commit them
git reset --hard HEAD
When you're done in GitKraken re-install husky as so.
npm install

Push changes to bitbucket using atom

I am using the text editor Atom and it should be possible to upload directly to bitbucket from atom. I found a thread here on stackoverflow someone asked for this and someone recommended git-plus package. I did download this package but it tells me i need to edit user.email and user.name variable in gitconfig file. But it doesnt say anywhere where i can find this gitconfig file. I found a few config files but none of them have these variables. Is this gitconfig file in my .git folder in my project or is it somewhere in atom? I hope someone here can help me with this
Set up git in your shell to use bitbucket as the remote repo.
You will first need to sort that basic Git config thing about the emails:
$ git config --global --get user.name
Your Name Here
$ git config --global --get user.email
your_email#someplace.com
If you don't have these values already added, then simply add them. Put your current directory someplace under the root of your atom repository (or, if you want to use the --global parameters [recommended]), then anywhere will do, really so long as it's your login you're working with.)
$ git config [--global] user.name "Your Name"
$ git config [--global] user.email "your_email#somplace.com"
First set up your ssh key so you don't have to type your password on every command. Once that's done, then go to the Git repo you set up for your Atom project. Most likely that's in the top level of my project. Go there and...
$ git remote -v
$ git remote add origin git#bitbucket.org:youruid/yourrepo.git
Now try it from the shell to make sure all is working:
$ git push
It's very likely you'll get a message similar to:
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
Follow the advice given, then, if you're feeling particularly paranoid, make a change to any file in the repo -- using atom if you like, doesn't matter -- and try it all again:
$ git add -u
$ git commit [-v]
...
$ git push
This time, it should go off without a hitch.
Now back to atom...
If you've configured things there so that atom can access your Git repo locally, there should now be a Fetch widget in the lower right corner:
If you make a change now in atom, you'll see this change to Push... with the functionality to match.
The GitHub widget still doesn't do anything -- which is mildly annoying -- but I believe you might be able to find an atom package out there that does similar things.

Get the list of unstaged files in git pre-commit hook

I've spent a whole lot of time on stackoverflow/google trying to figure out a solution for this problem. May be the solution is simple and I am missing something.So I have a pre-commit hook(shell script) which runs few tests on committed files. If a committed file fails a test, it is removed from the stage. I want to printout all the unstated files from inside the script. Here's what I have tried so far from inside the script.
git diff --name-only --diff-filter=M
git ls-files -m
git diff --name-only
All of them throw the same error as shown below:
fatal: This operation must be run in a work tree
P.S. I am running this inside .git folder(since hooks reside there) and hence the error.
Any suggestions would be really helpful.
I asked a colleague of mine and he came up with a solution specifically for shell script. Sometimes you just have to think simple!
Just change the directory using "cd" and run the command once you are outside the .git folder.
add the following at the top of your script assuming your hook .git/hooks/
#! /bin/bash
here=`dirname "$0"`
cd "$here/../.."

Download from gitHub [duplicate]

The command git clone git#github.com:whatever creates a directory named whatever containing a Git repository:
./
whatever/
.git
I want the contents of the Git repository cloned into my current directory ./ instead:
./
.git
Option A:
git clone git#github.com:whatever folder-name
Ergo, for right here use:
git clone git#github.com:whatever .
Option B:
Move the .git folder, too. Note that the .git folder is hidden in most graphical file explorers, so be sure to show hidden files.
mv /where/it/is/right/now/* /where/I/want/it/
mv /where/it/is/right/now/.* /where/I/want/it/
The first line grabs all normal files, the second line grabs dot-files. It is also possibe to do it in one line by enabling dotglob (i.e. shopt -s dotglob) but that is probably a bad solution if you are asking the question this answer answers.
Better yet:
Keep your working copy somewhere else, and create a symbolic link. Like this:
ln -s /where/it/is/right/now /the/path/I/want/to/use
For your case this would be something like:
ln -sfn /opt/projectA/prod/public /httpdocs/public
Which easily could be changed to test if you wanted it, i.e.:
ln -sfn /opt/projectA/test/public /httpdocs/public
without moving files around. Added -fn in case someone is copying these lines (-f is force, -n avoid some often unwanted interactions with already and non-existing links).
If you just want it to work, use Option A, if someone else is going to look at what you have done, use Option C.
The example I think a lot of people asking this question are after is this. If you are in the directory you want the contents of the git repository dumped to, run:
git clone git#github.com:whatever .
The "." at the end specifies the current folder as the checkout folder.
Go into the folder.. If the folder is empty, then:
git clone git#github.com:whatever .
else
git init
git remote add origin PATH/TO/REPO
git fetch
git checkout -t origin/master
Basic Git Repository Cloning
You clone a repository with
git clone [url]
For example, if you want to clone the Stanford University Drupal Open Framework Git library called open_framework, you can do so like this:
$ git clone git://github.com/SU-SWS/open_framework.git
That creates a directory named open_framework (at your current local file system location), initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the newly created open_framework directory, you’ll see the project files in there, ready to be worked on or used.
Cloning a Repository Into a Specific Local Folder
If you want to clone the repository into a directory named something other than open_framework, you can specify that as the next command-line option:
$ git clone git:github.com/SU-SWS/open_framework.git mynewtheme
That command does the same thing as the previous one, but the target directory is called mynewtheme.
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user#server:/path.git, which uses the SSH transfer protocol.
You can use following git command to clone with custom directory name
git clone <git_repo_url> <your_custom_directory_name>
Note: You don't need to create your custom directory because it will create automatically
To clone git repository into a specific folder, you can use -C <path> parameter, e.g.
git -C /httpdocs clone git#github.com:whatever
Although it'll still create a whatever folder on top of it, so to clone the content of the repository into current directory, use the following syntax:
cd /httpdocs
git clone git#github.com:whatever .
Note that cloning into an existing directory is only allowed when the directory is empty.
Since you're cloning into folder that is accessible for public, consider separating your Git repository from your working tree by using --separate-git-dir=<git dir> or exclude .git folder in your web server configuration (e.g. in .htaccess file).
To clone to Present Working Directory:
git clone https://github.com/link.git
To clone to Another Directory:
git clone https://github.com/link.git ./Folder1/Folder2
Hope it Helps :)
If you want to clone into the current folder, you should try this:
git clone https://github.com/example/example.git ./
When you move the files to where you want them, are you also moving the .git directory? Depending on your OS and configuration, this directory may be hidden.
It contains the repo and the supporting files, while the project files that are in your /public directory are only the versions in the currently check-out commit (master branch by default).
Usage
git clone <repository>
Clone the repository located at the <repository> onto the local machine. The original repository can be located on the local filesystem or on a remote machine accessible via HTTP or SSH.
git clone <repo> <directory>
Clone the repository located at <repository> into the folder called <directory> on the local machine.
Source: Setting up a repository
Clone:
git clone git#jittre.unfuddle.com:jittre/name.git
Clone the "specific branch":
git clone -b [branch-name] git#jittre.unfuddle.com:jittre/name.git
Make sure you remove the .git repository if you are trying to check thing out into the current directory.
rm -rf .git then git clone https://github.com/symfony/symfony-sandbox.git
From some reason this syntax is not standing out:
git clone repo-url [folder]
Here folder is an optional path to the local folder (which will be a local repository).
Git clone will also pull code from remote repository into the local repository.
In fact it is true:
git clone repo-url = git init + git remote add origin repo-url + git pull
Here's how I would do it, but I have made an alias to do it for me.
$ cd ~Downloads/git; git clone https:git.foo/poo.git
There is probably a more elegant way of doing this, however I found this to be easiest for myself.
Here's the alias I created to speed things along. I made it for zsh, but it should work just fine for bash or any other shell like fish, xyzsh, fizsh, and so on.
Edit ~/.zshrc, /.bashrc, etc. with your favorite editor (mine is Leafpad, so I would write $ leafpad ~/.zshrc).
My personal preference, however, is to make a zsh plugin to keep track of all my aliases. You can create a personal plugin for oh-my-zsh by running these commands:
$ cd ~/.oh-my-zsh/
$ cd plugins/
$ mkdir your-aliases-folder-name; cd your-aliases-folder-name
# In my case '~/.oh-my-zsh/plugins/ev-aliases/ev-aliases'
$ leafpad your-zsh-aliases.plugin.zsh
# Again, in my case 'ev-aliases.plugin.zsh'
Afterwards, add these lines to your newly created blank alises.plugin file:
# Git aliases
alias gc="cd ~/Downloads/git; git clone "
(From here, replace your name with mine.)
Then, in order to get the aliases to work, they (along with zsh) have to be sourced-in (or whatever it's called). To do so, inside your custom plugin document add this:
## Ev's Aliases
#### Remember to re-source zsh after making any changes with these commands:
#### These commands should also work, assuming ev-aliases have already been sourced before:
allsource="source $ZSH/oh-my-zsh.sh ; source /home/ev/.oh-my-zsh/plugins/ev-aliases/ev-aliases.plugin.zsh; clear"
sourceall="source $ZSH/oh-my-zsh.sh ; source /home/ev/.oh-my-zsh/plugins/ev-aliases/ev-aliases.plugin.zsh"
####
####################################
# git aliases
alias gc="cd ~/Downloads/git; git clone "
# alias gc="git clone "
# alias gc="cd /your/git/folder/or/whatever; git clone "
####################################
Save your oh-my-zsh plugin, and run allsource. If that does not seem to work, simply run source $ZSH/oh-my-zsh.sh; source /home/ev/.oh-my-zsh/plugins/ev-aliases/ev-aliases.plugin.zsh. That will load the plugin source which will allow you to use allsource from now on.
I'm in the process of making a Git repository with all of my aliases. Please feel free to check them out here: Ev's dot-files. Please feel free to fork and improve upon them to suit your needs.
If you are in the directory you want the contents of the git repository dumped to, run:
git clone git#github.com:origin .
The "." at the end specifies the current folder as the checkout folder.
If you are using ssh for git cloning you can use the following command.
git -C path clone git#github.com:path_to_repo.git
eg:
git -C /home/ubuntu/ clone git#github.com:kennethreitz/requests.git would pull the git repository for requests to your /home/ubuntu/ path.
go to the directory where you want to clone the repo.
(don't run git init command inside that directory)
simply run the command,
git clone <git repo url> .
Example: git clone https://github.com/Rashmi-Wijesekara/portfolio.git .
Although all of the answers above are good, I would like to propose a new method instead of using the symbolic link method in public html directory as proposed BEST in the accepted answer. You need to have access to your server virtual host configurations.
It is about configuring virtual host of your web server directly pointing to the repository directory. In Apache you can do it like:
DocumentRoot /var/www/html/website/your-git-repo
Here is an example of a virtual host file:
<VirtualHost *:443>
ServerName example.com
DocumentRoot /path/to/your-git-repo
...
...
...
...
</VirtualHost>
If you use github cli you can use the following command:
gh repo clone <repository> [<directory>] [-- <gitflags>...]
So for example you can run this:
gh repo clone repository-name-on-github my-local-folder
For Windows user
1> Open command prompt.
2> Change the directory to destination folder (Where you want to store your project in local machine.)
3> Now go to project setting online(From where you want to clone)
4> Click on clone, and copy the clone command.
5> Now enter the same on cmd .
It will start cloning saving on the selected folder you given .
Regarding this line from the original post:
"I know how to move the files after I've cloned the repo, but this
seems to break git"
I am able to do that and I don't see any issues so far with my add, commit, push, pull operations.
This approach is stated above, but just not broken down into steps.
Here's the steps that work for me:
clone the repo into any fresh temporary folder
cd into that root folder you just cloned locally
copy the entire contents of the folder, including the /.git directory - into any existing folder you like; (say an eclipse project that you want to merge with your repo)
The existing folder you just copied the files into , is now ready to interact with git.

Resources