Skip to content

Instantly share code, notes, and snippets.

@mgershovitz
mgershovitz / repo_function
Created October 11, 2019 08:06
Project env switch function complete with completion
function repo {
source ~/virtual_envs/$1/bin/activate;
cd ~/git_repositories/$1
}
function _repo {
_arguments "1: :($(ls ~/git_repositories))"
}
compdef _repo repo
@mgershovitz
mgershovitz / pre-commit
Last active September 8, 2022 07:37 — forked from hraban/pre-commit.md
Git pre-commit hook to prevent accidentally committing debug code (add NO_COMMIT in source comment)
#!/bin/bash
if git diff --cached | grep '^[+d].*NO_COMMIT'; then
echo "Can't commit file with NO_COMMIT comment, remove the debug code and try again"
exit 1
fi
#!/bin/bash
# Get the current branch name
branch_name=$(git branch | grep "*" | sed "s/\* //")
# if the merged branch was master - don't do anything
if [[ $branch_name = "master" ]]; then
echo "Preparing to merge to master..."
if git diff --cached | grep '^[+d].*NO_MERGE'; then
echo "Can't merge branch with 'NO_MERGE' comment, fix what you need and try again!"
#!/bin/bash
function git {
if [[ "$1" = "merge" && "$@" != *"--help"* && "$@" != *"--abort"* ]]; then
git_merge_wrapper "$@";
else
command git "$@"
fi
}
ssh -N -L <local_port>:127.0.0.1:<destination_port> -i <private_key_path> <user_name>@<host_ip>
ssh -N -L <local_port>:<host2_ip>:<destination_port> -i <private_key_path> <user_name>@<host1_ip>